1 /**
2 * Copyright 2005-2006 the original author or authors.
3 *
4 * Licensed under the Gnu General Pubic License, Version 2.0 (the
5 * "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/gpl-license.php
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the Gnu General Public License for more details.
14 */
15 package org.figure8.join.businessobjects.artifact.persistence;
16
17 import org.figure8.join.util.SpringTestCase;
18 import org.figure8.join.businessobjects.commons.Release;
19 import org.figure8.join.businessobjects.commons.persistence.ReleaseDao;
20 import org.figure8.join.businessobjects.artifact.Deliverable;
21 import org.figure8.join.businessobjects.artifact.DeliverableType;
22
23 import java.util.Date;
24 import java.util.List;
25 /**
26 * JUnit test case for testing DeliverableDao implementation.
27 * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
28 * @version $Revision: 1.2 $
29 */
30 public class DeliverableDaoTest extends SpringTestCase{
31
32
33
34 /** Spring configuration files */
35 private String[] configLocations = new String[]{
36 "classpath:/org/figure8/join/businessobjects/artifact/persistence/spring.xml"};
37
38
39
40
41 /** A ReleaseDao implementation that we need */
42 protected ReleaseDao releDao = null;
43 /** The DeliverableDao implementation to test */
44 protected DeliverableDao dao = null;
45 /** A DeliverableTypeDao implementation that we need */
46 protected DeliverableTypeDao typeDao = null;
47
48
49
50
51 /** Retrieve deliverable daos after having initialized the context */
52 public void setUp(){
53 super.setUp();
54
55 releDao = (ReleaseDao)context.getBean("releaseDao");
56 dao = (DeliverableDao)context.getBean("deliverableDao");
57 typeDao = (DeliverableTypeDao)context.getBean("deliverableTypeDao");
58 }
59
60
61
62
63 /** Test deliverable creation */
64 public void testDeliverableCreation(){
65
66 Release release = new Release("10.0", 10, 0, new Date());
67 DeliverableType type = new DeliverableType("typeCreation4D", "Type Creation Label 4D", "typeCreation4D-{0}.{1}", true, true);
68 Deliverable deliverable = new Deliverable("01", "comments", "supplierId", release, type);
69 int size = getDeliverableListSize();
70 typeDao.save(type);
71 releDao.save(release);
72 dao.save(deliverable);
73
74 assertEquals("Deliverable is successfully created", size + 1, dao.findAll().size());
75
76
77 Deliverable found = dao.getDeliverable("typeCreation4D-10.0.01");
78 assertNotNull("Found a Deliverable", found);
79 assertEquals("Found the correct Deliverable", found.getId(), deliverable.getId());
80 }
81
82 /** Test the retrieval using type and release */
83 public void testFindByTypeAndRelease(){
84
85 Release release = new Release("2.0", 2, 0, new Date());
86 DeliverableType type = new DeliverableType("typeFindBy", "Type FindBy Label", "typeFindBy-{0}.{1}", true, true);
87 Deliverable deliverable1 = new Deliverable("01", "comments", "supplierId", release, type);
88 Deliverable deliverable2 = new Deliverable("02", "comments", "supplierId", release, type);
89 int size = getDeliverableListSize();
90 typeDao.save(type);
91 releDao.save(release);
92 dao.save(deliverable1);
93 dao.save(deliverable2);
94
95 assertEquals("Deliverables are successfully created", size + 2, dao.findAll().size());
96
97 List result = dao.getDeliverablesByRelease(type, release);
98 assertNotNull("Deliverables list is not null", result);
99 assertEquals("Deliverables list has 2 elements", 2, result.size());
100 assertEquals("First deliverable is correct", "typeFindBy-2.0.01", ((Deliverable)result.get(0)).getKey());
101 assertEquals("Second deliverable is correct", "typeFindBy-2.0.02", ((Deliverable)result.get(1)).getKey());
102 }
103
104 /** Test the retrieval using supplier id */
105 public void testFindBySupplierId(){
106
107 Release release = new Release("3.0", 3, 0, new Date());
108 DeliverableType type = new DeliverableType("typeFindByUser", "Type FindByUser Label", "typeFindByUser-{0}.{1}", true, true);
109 Deliverable deliverable = new Deliverable("01", "comments", "testSupplierId", release, type);
110 int size = getDeliverableListSize();
111 typeDao.save(type);
112 releDao.save(release);
113 dao.save(deliverable);
114
115 assertEquals("Deliverable is successfully created", size + 1, dao.findAll().size());
116
117 List result = dao.getDeliverablesSuppliedByUser("testSupplierId");
118 assertNotNull("Deliverables list is not null", result);
119 assertEquals("Deliverables list has 1 element", 1, result.size());
120 assertEquals("Deliverable is correct", "typeFindByUser-3.0.01", ((Deliverable)result.get(0)).getKey());
121 assertEquals("Deliverable supplier is correct", "testSupplierId", ((Deliverable)result.get(0)).getSupplierId());
122 }
123
124
125
126
127 /** Test the findAll on deliverable */
128 protected int getDeliverableListSize(){
129 return dao.findAll().size();
130 }
131
132
133
134
135 /** @return An array of locations from Spring configuration files. */
136 public String[] getConfigLocations(){
137 return configLocations;
138 }
139 }