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.model.spem2.workbreakdownelement;
018:
019: import static org.junit.Assert.assertEquals;
020: import static org.junit.Assert.assertFalse;
021: import static org.junit.Assert.assertNotNull;
022: import static org.junit.Assert.assertTrue;
023:
024: import java.util.HashSet;
025: import java.util.Set;
026:
027: import org.junit.After;
028: import org.junit.Before;
029: import org.junit.Test;
030:
031: import wilos.model.spem2.workbreakdownelement.WorkBreakdownElement;
032: import wilos.model.spem2.workbreakdownelement.WorkOrder;
033:
034: public class WorkBreakdownElementTest {
035:
036: private WorkBreakdownElement workBreakdownElement;
037:
038: @Before
039: public void setUp() {
040: this .workBreakdownElement = new WorkBreakdownElement();
041: }
042:
043: @After
044: public void tearDown() {
045: this .workBreakdownElement = null;
046: }
047:
048: @Test
049: public void testThatWorkBreakdownElementIsEmptyByDefault() {
050: assertTrue("id", this .workBreakdownElement.getId().equals(""));
051: assertTrue("guid", this .workBreakdownElement.getGuid().equals(
052: ""));
053: assertTrue("name", this .workBreakdownElement.getName().equals(
054: ""));
055: assertEquals("isRepeatable", false, this .workBreakdownElement
056: .getIsRepeatable());
057: }
058:
059: @Test
060: public void testThatAWorkBreakdownElementEqualsAnother() {
061:
062: this .workBreakdownElement.setGuid("My guid");
063: this .workBreakdownElement.setName("My name");
064: this .workBreakdownElement.setIsRepeatable(true);
065:
066: WorkBreakdownElement workBreakdownElement1 = new WorkBreakdownElement();
067: workBreakdownElement1.setGuid("My guid");
068: workBreakdownElement1.setName("My name");
069: workBreakdownElement1.setIsRepeatable(true);
070:
071: assertTrue("equal", this .workBreakdownElement
072: .equals(workBreakdownElement1));
073:
074: WorkBreakdownElement workBreakdownElement2 = new WorkBreakdownElement();
075: workBreakdownElement2.setGuid("Your guid");
076: workBreakdownElement2.setName("Your name");
077: workBreakdownElement2.setIsRepeatable(true);
078:
079: assertFalse("not equal", this .workBreakdownElement
080: .equals(workBreakdownElement2));
081:
082: workBreakdownElement2 = null;
083: workBreakdownElement1 = null;
084: }
085:
086: @Test
087: public void testThatWorkBreakdownElementHashCodeIsValide() {
088:
089: this .workBreakdownElement.setGuid("My guid");
090: this .workBreakdownElement.setName("My name");
091: this .workBreakdownElement.setIsRepeatable(true);
092:
093: WorkBreakdownElement workBreakdownElement1 = new WorkBreakdownElement();
094: workBreakdownElement1.setGuid("My guid");
095: workBreakdownElement1.setName("My name");
096: workBreakdownElement1.setIsRepeatable(true);
097:
098: assertNotNull(this .workBreakdownElement.hashCode());
099: assertNotNull(workBreakdownElement1.hashCode());
100: assertEquals("equal", this .workBreakdownElement.hashCode(),
101: workBreakdownElement1.hashCode());
102:
103: workBreakdownElement1 = null;
104: }
105:
106: @Test
107: public void testThatAPredecessorIsCorrectlyAddedToPredecessorsCollection() {
108:
109: this .workBreakdownElement.setGuid("My guid");
110: this .workBreakdownElement.setName("My name");
111: this .workBreakdownElement.setIsRepeatable(true);
112:
113: WorkOrder workOrder = new WorkOrder();
114: workOrder.setLinkType("startToFinish");
115:
116: this .workBreakdownElement.addPredecessor(workOrder);
117:
118: assertEquals(
119: "size of predeccessors collection in the workBreakdownElement",
120: 1, this .workBreakdownElement.getPredecessors().size());
121: assertFalse("workBreakdownElement in the workOrder", workOrder
122: .getSuccessor() == null);
123:
124: assertTrue("workOrders contains the workOrder",
125: this .workBreakdownElement.getPredecessors().contains(
126: workOrder));
127: assertEquals("workBreakdownElement : code",
128: this .workBreakdownElement.getGuid(), workOrder
129: .getSuccessor().getGuid());
130: assertEquals("workBreakdownElement : name",
131: this .workBreakdownElement.getName(), workOrder
132: .getSuccessor().getName());
133: assertEquals("workBreakdownElement : isRepeatable",
134: this .workBreakdownElement.getIsRepeatable(), workOrder
135: .getSuccessor().getIsRepeatable());
136:
137: workOrder = null;
138: }
139:
140: @Test
141: public void testThatAsuccessorIsCorrectlyAddedToSuccessorsCollection() {
142:
143: this .workBreakdownElement.setGuid("My guid");
144: this .workBreakdownElement.setName("My name");
145: this .workBreakdownElement.setIsRepeatable(true);
146:
147: WorkOrder workOrder = new WorkOrder();
148: workOrder.setLinkType("startToFinish");
149:
150: this .workBreakdownElement.addSuccessor(workOrder);
151:
152: assertEquals(
153: "size of successors collection in the workBreakdownElement",
154: 1, this .workBreakdownElement.getSuccessors().size());
155: assertFalse("workBreakdownElement in the workOrder", workOrder
156: .getPredecessor() == null);
157:
158: assertTrue("workOrders contains the workOrder",
159: this .workBreakdownElement.getSuccessors().contains(
160: workOrder));
161: assertEquals("workBreakdownElement : code",
162: this .workBreakdownElement.getGuid(), workOrder
163: .getPredecessor().getGuid());
164: assertEquals("workBreakdownElement : name",
165: this .workBreakdownElement.getName(), workOrder
166: .getPredecessor().getName());
167: assertEquals("workBreakdownElement : isRepeatable",
168: this .workBreakdownElement.getIsRepeatable(), workOrder
169: .getPredecessor().getIsRepeatable());
170:
171: workOrder = null;
172: }
173:
174: @Test
175: public void testThatAPredecessorIsCorrectlyRemovedFromPredecessorsCollection() {
176:
177: WorkOrder workOrder = new WorkOrder();
178: workOrder.setLinkType("startToFinish");
179:
180: this .workBreakdownElement.addPredecessor(workOrder);
181: this .workBreakdownElement.removePredecessor(workOrder);
182:
183: assertEquals(
184: "size of predecessors collection in the workBreakdownElement",
185: 0, this .workBreakdownElement.getPredecessors().size());
186: assertTrue("workBreakdownElement of workOrder is null",
187: workOrder.getSuccessor() == null);
188:
189: workOrder = null;
190: }
191:
192: @Test
193: public void testThatASuccessorIsCorrectlyRemovedFromSuccessorsCollection() {
194:
195: WorkOrder workOrder = new WorkOrder();
196: workOrder.setLinkType("startToFinish");
197:
198: this .workBreakdownElement.addPredecessor(workOrder);
199: this .workBreakdownElement.removePredecessor(workOrder);
200:
201: assertEquals(
202: "size of successors collection in the workBreakdownElement",
203: 0, this .workBreakdownElement.getPredecessors().size());
204: assertTrue("workBreakdownElement of workOrder is null",
205: workOrder.getSuccessor() == null);
206:
207: workOrder = null;
208: }
209:
210: @Test
211: public void testThatAPredecessorsCollectionIsCorrectlyAddedToPredecessorsCollection() {
212:
213: this .workBreakdownElement.setGuid("My guid");
214: this .workBreakdownElement.setName("My name");
215: this .workBreakdownElement.setIsRepeatable(true);
216:
217: Set<WorkOrder> workOrders = new HashSet<WorkOrder>();
218:
219: WorkOrder workOrder1 = new WorkOrder();
220: workOrder1.setLinkType("startToFinish");
221:
222: WorkOrder workOrder2 = new WorkOrder();
223: workOrder2.setLinkType("startToStart");
224:
225: workOrders.add(workOrder1);
226: workOrders.add(workOrder2);
227:
228: this .workBreakdownElement.addAllPredecessors(workOrders);
229:
230: assertEquals(
231: "size of predecessors collection in the workBreakdownElement",
232: 2, this .workBreakdownElement.getPredecessors().size());
233: assertFalse("workBreakdownElement in the workOrder1",
234: workOrder1.getSuccessor() == null);
235: assertFalse("workBreakdownElement in the workOrder2",
236: workOrder2.getSuccessor() == null);
237:
238: assertTrue("workOrders contains the e1",
239: this .workBreakdownElement.getPredecessors().contains(
240: workOrder1));
241: assertTrue("workOrders contains the e2",
242: this .workBreakdownElement.getPredecessors().contains(
243: workOrder2));
244: assertEquals("workBreakdownElement in workorder1 : code",
245: this .workBreakdownElement.getGuid(), workOrder1
246: .getSuccessor().getGuid());
247: assertEquals("workBreakdownElement in workorder1 : name",
248: this .workBreakdownElement.getName(), workOrder1
249: .getSuccessor().getName());
250: assertEquals(
251: "workBreakdownElement in workorder1 : isRepeatable",
252: this .workBreakdownElement.getIsRepeatable(), workOrder1
253: .getSuccessor().getIsRepeatable());
254: assertEquals("workBreakdownElement in workorder2 : code",
255: this .workBreakdownElement.getGuid(), workOrder2
256: .getSuccessor().getGuid());
257: assertEquals("workBreakdownElement in workorder2 : name",
258: this .workBreakdownElement.getName(), workOrder2
259: .getSuccessor().getName());
260: assertEquals(
261: "workBreakdownElement in workorder2 : isRepeatable",
262: this .workBreakdownElement.getIsRepeatable(), workOrder2
263: .getSuccessor().getIsRepeatable());
264:
265: workOrder2 = null;
266: workOrder1 = null;
267: workOrders = null;
268: }
269:
270: @Test
271: public void testThatASuccessorsCollectionIsCorrectlyAddedToSuccessorsCollection() {
272:
273: this .workBreakdownElement.setGuid("My guid");
274: this .workBreakdownElement.setName("My name");
275: this .workBreakdownElement.setIsRepeatable(true);
276:
277: Set<WorkOrder> workOrders = new HashSet<WorkOrder>();
278:
279: WorkOrder workOrder1 = new WorkOrder();
280: workOrder1.setLinkType("startToFinish");
281:
282: WorkOrder workOrder2 = new WorkOrder();
283: workOrder2.setLinkType("startToStart");
284:
285: workOrders.add(workOrder1);
286: workOrders.add(workOrder2);
287:
288: this .workBreakdownElement.addAllSuccessors(workOrders);
289:
290: assertEquals(
291: "size of successors collection in the workBreakdownElement",
292: 2, this .workBreakdownElement.getSuccessors().size());
293: assertFalse("workBreakdownElement in the workOrder1",
294: workOrder1.getPredecessor() == null);
295: assertFalse("workBreakdownElement in the workOrder2",
296: workOrder2.getPredecessor() == null);
297:
298: assertTrue("workOrders contains the e1",
299: this .workBreakdownElement.getSuccessors().contains(
300: workOrder1));
301: assertTrue("workOrders contains the e2",
302: this .workBreakdownElement.getSuccessors().contains(
303: workOrder2));
304: assertEquals("workBreakdownElement in workorder1 : code",
305: this .workBreakdownElement.getGuid(), workOrder1
306: .getPredecessor().getGuid());
307: assertEquals("workBreakdownElement in workorder1 : name",
308: this .workBreakdownElement.getName(), workOrder1
309: .getPredecessor().getName());
310: assertEquals(
311: "workBreakdownElement in workorder1 : isRepeatable",
312: this .workBreakdownElement.getIsRepeatable(), workOrder1
313: .getPredecessor().getIsRepeatable());
314: assertEquals("workBreakdownElement in workorder2 : code",
315: this .workBreakdownElement.getGuid(), workOrder2
316: .getPredecessor().getGuid());
317: assertEquals("workBreakdownElement in workorder2 : name",
318: this .workBreakdownElement.getName(), workOrder2
319: .getPredecessor().getName());
320: assertEquals(
321: "workBreakdownElement in workorder2 : isRepeatable",
322: this .workBreakdownElement.getIsRepeatable(), workOrder2
323: .getPredecessor().getIsRepeatable());
324:
325: workOrder2 = null;
326: workOrder1 = null;
327: workOrders = null;
328: }
329:
330: @Test
331: public void testThatAPredecessorsCollectionIsCorrectlyRemovedFromPredecessorsCollection() {
332:
333: this .workBreakdownElement.setGuid("My guid");
334: this .workBreakdownElement.setName("My name");
335: this .workBreakdownElement.setIsRepeatable(true);
336:
337: Set<WorkOrder> workOrders = new HashSet<WorkOrder>();
338:
339: WorkOrder workOrder1 = new WorkOrder();
340: workOrder1.setLinkType("startToFinish");
341:
342: WorkOrder workOrder2 = new WorkOrder();
343: workOrder2.setLinkType("startToStart");
344:
345: workOrders.add(workOrder1);
346: workOrders.add(workOrder2);
347:
348: this .workBreakdownElement.addAllPredecessors(workOrders);
349: this .workBreakdownElement.removeAllPredecessors();
350:
351: assertEquals("predecessors contains the workOrder", 0,
352: this .workBreakdownElement.getPredecessors().size());
353: assertTrue("workBreakdownElement in the e1", workOrder1
354: .getSuccessor() == null);
355: assertTrue("workBreakdownElement in the e2", workOrder2
356: .getSuccessor() == null);
357:
358: workOrder2 = null;
359: workOrder1 = null;
360: workOrders = null;
361: }
362:
363: @Test
364: public void testThatASuccessorsCollectionIsCorrectlyRemovedFromSuccessorsCollection() {
365:
366: this .workBreakdownElement.setGuid("My guid");
367: this .workBreakdownElement.setName("My name");
368: this .workBreakdownElement.setIsRepeatable(true);
369:
370: Set<WorkOrder> workOrders = new HashSet<WorkOrder>();
371:
372: WorkOrder workOrder1 = new WorkOrder();
373: workOrder1.setLinkType("startToFinish");
374:
375: WorkOrder workOrder2 = new WorkOrder();
376: workOrder2.setLinkType("startToStart");
377:
378: workOrders.add(workOrder1);
379: workOrders.add(workOrder2);
380:
381: this .workBreakdownElement.addAllSuccessors(workOrders);
382: this .workBreakdownElement.removeAllSuccessors();
383:
384: assertEquals("predecessors contains the workOrder", 0,
385: this .workBreakdownElement.getSuccessors().size());
386: assertTrue("workBreakdownElement in the e1", workOrder1
387: .getPredecessor() == null);
388: assertTrue("workBreakdownElement in the e2", workOrder2
389: .getPredecessor() == null);
390:
391: workOrder2 = null;
392: workOrder1 = null;
393: workOrders = null;
394: }
395: }
|