001: /*
002: * Wilos Is a cLever process Orchestration Software - http://www.wilos-project.org
003: * Copyright (C) 2006-2007 Paul Sabatier University, IUP ISI (Toulouse, France) <massie@irit.fr>
004: * Copyright (C) 2007 Sebastien BALARD <sbalard@wilos-project.org>
005: *
006: * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
007: * General Public License as published by the Free Software Foundation; either version 2 of the License,
008: * or (at your option) any later version.
009: *
010: * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
011: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License along with this program; if not,
015: * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
016: */
017: package wilos.test.hibernate.spem2.task;
018:
019: import static org.junit.Assert.assertEquals;
020: import static org.junit.Assert.assertNotNull;
021: import static org.junit.Assert.assertNull;
022: import static org.junit.Assert.assertTrue;
023:
024: import java.util.List;
025:
026: import org.junit.After;
027: import org.junit.Before;
028: import org.junit.Test;
029:
030: import wilos.hibernate.misc.concretetask.ConcreteTaskDescriptorDao;
031: import wilos.hibernate.spem2.task.TaskDescriptorDao;
032: import wilos.model.misc.concretetask.ConcreteTaskDescriptor;
033: import wilos.model.spem2.task.TaskDescriptor;
034: import wilos.test.TestConfiguration;
035:
036: /**
037: * Unit test for TaskDescriptorDao
038: *
039: * @author eperico
040: *
041: */
042: public class TaskDescriptorDaoTest {
043:
044: private TaskDescriptorDao taskDescriptorDao = (TaskDescriptorDao) TestConfiguration
045: .getInstance().getApplicationContext().getBean(
046: "TaskDescriptorDao");
047:
048: private ConcreteTaskDescriptorDao concreteTaskDescriptorDao = (ConcreteTaskDescriptorDao) TestConfiguration
049: .getInstance().getApplicationContext().getBean(
050: "ConcreteTaskDescriptorDao");
051:
052: private TaskDescriptor taskDescriptor = null;
053:
054: /**
055: * attributes from Element
056: */
057: public static final String ID = "thisId";
058:
059: public static final String NAME = "thisTaskDescriptor";
060:
061: public static final String DESCRIPTION = "taskDescriptor description";
062:
063: /**
064: * attributes from BreakdownElement
065: */
066: public static final String PREFIX = "prefix";
067:
068: public static final Boolean IS_PLANNED = true;
069:
070: public static final Boolean HAS_MULTIPLE_OCCURENCES = true;
071:
072: public static final Boolean IS_OPTIONAL = true;
073:
074: /**
075: * attributes from WorkBreakdownElement
076: */
077: public static final Boolean IS_REPEATABLE = true;
078:
079: public static final Boolean IS_ON_GOING = true;
080:
081: public static final Boolean IS_EVEN_DRIVEN = true;
082:
083: @Before
084: public void setUp() {
085:
086: // Create empty TaskDescriptor
087: this .taskDescriptor = new TaskDescriptor();
088: this .taskDescriptor.setName(NAME);
089: this .taskDescriptor.setDescription(DESCRIPTION);
090:
091: this .taskDescriptor.setPrefix(PREFIX);
092: this .taskDescriptor.setIsPlanned(IS_PLANNED);
093: this .taskDescriptor
094: .setHasMultipleOccurrences(HAS_MULTIPLE_OCCURENCES);
095: this .taskDescriptor.setIsOptional(IS_OPTIONAL);
096:
097: this .taskDescriptor.setIsRepeatable(IS_REPEATABLE);
098: this .taskDescriptor.setIsOngoing(IS_ON_GOING);
099: this .taskDescriptor.setIsEvenDriven(IS_EVEN_DRIVEN);
100: }
101:
102: @After
103: public void tearDown() {
104: this .taskDescriptor = null;
105: }
106:
107: @Test
108: public void testSaveOrUpdateTaskDescriptor() {
109: // Rk: the setUp method is called here.
110:
111: // Save the taskDescriptor with the method to test.
112: String id = this .taskDescriptorDao
113: .saveOrUpdateTaskDescriptor(this .taskDescriptor);
114:
115: // Check the saving.
116: TaskDescriptor taskDescriptorTmp = (TaskDescriptor) this .taskDescriptorDao
117: .getHibernateTemplate().load(TaskDescriptor.class, id);
118: assertNotNull(taskDescriptorTmp);
119:
120: this .taskDescriptorDao
121: .deleteTaskDescriptor(this .taskDescriptor);
122:
123: // Rk: the tearDown method is called here.
124: }
125:
126: @Test
127: public void testGetAllTaskDescriptors() {
128: // Rk: the setUp method is called here.
129:
130: // Save the taskDescriptor into the database.
131: this .taskDescriptorDao
132: .saveOrUpdateTaskDescriptor(this .taskDescriptor);
133:
134: // Look if this taskDescriptor is also into the database and look if the
135: // size of the set is >= 1.
136: List<TaskDescriptor> taskDescriptors = this .taskDescriptorDao
137: .getAllTaskDescriptors();
138: assertNotNull(taskDescriptors);
139: assertTrue(taskDescriptors.size() >= 1);
140:
141: this .taskDescriptorDao
142: .deleteTaskDescriptor(this .taskDescriptor);
143:
144: // Rk: the tearDown method is called here.
145: }
146:
147: @Test
148: public void testGetTaskDescriptor() {
149: // Rk: the setUp method is called here.
150:
151: // Save the taskDescriptor into the database.
152: String id = this .taskDescriptorDao
153: .saveOrUpdateTaskDescriptor(this .taskDescriptor);
154:
155: ConcreteTaskDescriptor concreteTaskDescriptor = new ConcreteTaskDescriptor();
156: concreteTaskDescriptor.setConcreteName("My name");
157:
158: this .concreteTaskDescriptorDao
159: .saveOrUpdateConcreteTaskDescriptor(concreteTaskDescriptor);
160:
161: this .taskDescriptor
162: .addConcreteTaskDescriptor(concreteTaskDescriptor);
163: this .concreteTaskDescriptorDao
164: .saveOrUpdateConcreteTaskDescriptor(concreteTaskDescriptor);
165:
166: this .taskDescriptorDao
167: .saveOrUpdateTaskDescriptor(this .taskDescriptor);
168:
169: // Test the method getTaskDescriptor with an existing taskDescriptor.
170: TaskDescriptor taskDescriptorTmp = this .taskDescriptorDao
171: .getTaskDescriptor(id);
172: assertNotNull(taskDescriptorTmp);
173: assertEquals("Name", taskDescriptorTmp.getName(), NAME);
174: assertEquals("Description", taskDescriptorTmp.getDescription(),
175: DESCRIPTION);
176: assertEquals("Prefix", taskDescriptorTmp.getPrefix(), PREFIX);
177: assertEquals("IsPlanned", taskDescriptorTmp.getIsPlanned(),
178: IS_PLANNED);
179: assertEquals("HasMultipleOccurences", taskDescriptorTmp
180: .getHasMultipleOccurrences(), HAS_MULTIPLE_OCCURENCES);
181: assertEquals("IsOptional", taskDescriptorTmp.getIsOptional(),
182: IS_OPTIONAL);
183: assertEquals("IsRepeatable", taskDescriptorTmp
184: .getIsRepeatable(), IS_REPEATABLE);
185: assertEquals("IsOnGoing", taskDescriptorTmp.getIsOngoing(),
186: IS_ON_GOING);
187: assertEquals("IsEvenDriven", taskDescriptorTmp
188: .getIsEvenDriven(), IS_EVEN_DRIVEN);
189:
190: // clean temporary data
191: this .concreteTaskDescriptorDao
192: .deleteConcreteTaskDescriptor(concreteTaskDescriptor);
193: this .taskDescriptorDao
194: .deleteTaskDescriptor(this .taskDescriptor);
195:
196: // Rk: the tearDown method is called here.
197: }
198:
199: @Test
200: public void testDeleteTaskDescriptor() {
201: // Rk: the setUp method is called here.
202:
203: // Save the taskDescriptor into the database.
204: String id = this .taskDescriptorDao
205: .saveOrUpdateTaskDescriptor(this .taskDescriptor);
206:
207: // Test the method deleteTaskDescriptor with an activity existing into
208: // the db.
209: this .taskDescriptorDao
210: .deleteTaskDescriptor(this .taskDescriptor);
211:
212: // See if this.taskDescriptor is now absent in the db.
213: TaskDescriptor taskDescriptorTmp = (TaskDescriptor) this .taskDescriptorDao
214: .getHibernateTemplate().get(TaskDescriptor.class, id);
215: assertNull(taskDescriptorTmp);
216:
217: // Rk: the tearDown method is called here.
218: }
219: }
|