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: *
005: * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
006: * General Public License as published by the Free Software Foundation; either version 2 of the License,
007: * or (at your option) any later version.
008: *
009: * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
010: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
011: * GNU General Public License for more details.
012: *
013: * You should have received a copy of the GNU General Public License along with this program; if not,
014: * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
015: */
016: package wilos.test.model.spem2.breakdownelement;
017:
018: import static org.junit.Assert.*;
019:
020: import java.util.HashSet;
021: import java.util.Set;
022:
023: import org.junit.After;
024: import org.junit.Before;
025: import org.junit.Test;
026:
027: import wilos.model.spem2.activity.Activity;
028: import wilos.model.spem2.breakdownelement.BreakdownElement;
029:
030: public class BreakdownElementTest {
031:
032: private BreakdownElement breakdownElement;
033:
034: @Before
035: public void setUp() throws Exception {
036: this .breakdownElement = new BreakdownElement();
037: this .breakdownElement.setGuid("idEPF1");
038: this .breakdownElement.setName("name1");
039: this .breakdownElement.setDescription("description1");
040: this .breakdownElement.setPrefix("prefix1");
041: this .breakdownElement.setIsOptional(true);
042: this .breakdownElement.setIsPlanned(false);
043: this .breakdownElement.setHasMultipleOccurrences(false);
044: }
045:
046: @After
047: public void tearDown() throws Exception {
048: //None.
049: }
050:
051: @Test
052: public void testClone() {
053: try {
054: assertEquals(this .breakdownElement, this .breakdownElement
055: .clone());
056: } catch (CloneNotSupportedException e) {
057: fail("Error CloneNotSupportedException in the testClone method");
058: }
059: }
060:
061: @Test
062: public void testHashCode() {
063: // Rk: the setUp method is called here.
064:
065: BreakdownElement bdeTmp1 = new BreakdownElement();
066: bdeTmp1.setGuid("idEPF1");
067: bdeTmp1.setName("name1");
068: bdeTmp1.setDescription("description1");
069: bdeTmp1.setPrefix("prefix1");
070: bdeTmp1.setIsOptional(true);
071: bdeTmp1.setIsPlanned(false);
072: bdeTmp1.setHasMultipleOccurrences(false);
073:
074: assertNotNull(this .breakdownElement.hashCode());
075: assertNotNull(bdeTmp1.hashCode());
076: assertEquals(this .breakdownElement.hashCode(), bdeTmp1
077: .hashCode());
078:
079: // Rk: the tearDown method is called here.
080: }
081:
082: @Test
083: public void testEquals() {
084: // Rk: the setUp method is called here.
085:
086: // Assert if it's equal by references.
087: assertTrue("By references", this .breakdownElement
088: .equals(this .breakdownElement));
089:
090: // Assert if it's equal field by field.
091: BreakdownElement bdeTmp1 = new BreakdownElement();
092: bdeTmp1.setGuid("idEPF1");
093: bdeTmp1.setName("name1");
094: bdeTmp1.setDescription("description1");
095: bdeTmp1.setPrefix("prefix1");
096: bdeTmp1.setIsOptional(true);
097: bdeTmp1.setIsPlanned(false);
098: bdeTmp1.setHasMultipleOccurrences(false);
099: assertTrue("Field by field", this .breakdownElement
100: .equals(bdeTmp1));
101:
102: // Assert if it's not equal.
103: BreakdownElement bdeTmp2 = new BreakdownElement();
104: bdeTmp2.setGuid("idEPF2");
105: bdeTmp2.setName("name2");
106: bdeTmp2.setDescription("description2");
107: bdeTmp2.setPrefix("prefix2");
108: bdeTmp2.setIsOptional(true);
109: bdeTmp2.setIsPlanned(false);
110: bdeTmp2.setHasMultipleOccurrences(false);
111: assertFalse("Not equals", this .breakdownElement.equals(bdeTmp2));
112:
113: // Rk: the tearDown method is called here.
114: }
115:
116: @Test
117: public void testAddToActivity() {
118: // Rk: the setUp method is called here.
119:
120: assertTrue("Empty (begin)", this .breakdownElement
121: .getSuperActivities().isEmpty());
122:
123: Activity activity1 = new Activity();
124: activity1.setGuid("idEPF");
125: activity1.setName("name1");
126: activity1.setDescription("description1");
127: activity1.setPrefix("prefix1");
128: activity1.setIsOptional(true);
129: activity1.setIsPlanned(false);
130: activity1.setHasMultipleOccurrences(false);
131: activity1.setIsEvenDriven(true);
132: activity1.setIsOngoing(false);
133: activity1.setIsRepeatable(true);
134: this .breakdownElement.addSuperActivity(activity1);
135: assertTrue("acts.size == 1", this .breakdownElement
136: .getSuperActivities().size() == 1);
137: assertTrue("bdes.size1 == 1", activity1.getBreakdownElements()
138: .size() == 1);
139:
140: Activity activity2 = new Activity();
141: activity2.setGuid("idEPF");
142: activity2.setName("name2");
143: activity2.setDescription("description2");
144: activity2.setPrefix("prefix2");
145: activity2.setIsOptional(true);
146: activity2.setIsPlanned(false);
147: activity2.setHasMultipleOccurrences(false);
148: activity2.setIsEvenDriven(true);
149: activity2.setIsOngoing(false);
150: activity2.setIsRepeatable(true);
151: this .breakdownElement.addSuperActivity(activity2);
152: assertTrue("acts.size == 2", this .breakdownElement
153: .getSuperActivities().size() == 2);
154: assertTrue("bdes.size2 == 1", activity2.getBreakdownElements()
155: .size() == 1);
156:
157: // Rk: the tearDown method is called here.
158: }
159:
160: @Test
161: public void testAddToAllActivities() {
162: // Rk: the setUp method is called here.
163:
164: Activity activity1 = new Activity();
165: activity1.setGuid("idEPF");
166: activity1.setName("name1");
167: activity1.setDescription("description1");
168: activity1.setPrefix("prefix1");
169: activity1.setIsOptional(true);
170: activity1.setIsPlanned(false);
171: activity1.setHasMultipleOccurrences(false);
172: activity1.setIsEvenDriven(true);
173: activity1.setIsOngoing(false);
174: activity1.setIsRepeatable(true);
175:
176: Activity activity2 = new Activity();
177: activity2.setGuid("idEPF");
178: activity2.setName("name2");
179: activity2.setDescription("description2");
180: activity2.setPrefix("prefix2");
181: activity2.setIsOptional(true);
182: activity2.setIsPlanned(false);
183: activity2.setHasMultipleOccurrences(false);
184: activity2.setIsEvenDriven(true);
185: activity2.setIsOngoing(false);
186: activity2.setIsRepeatable(true);
187:
188: Set<Activity> activities = new HashSet<Activity>();
189: activities.add(activity1);
190: activities.add(activity2);
191:
192: this .breakdownElement.addAllSuperActivities(activities);
193:
194: assertTrue("acts.size == 2", this .breakdownElement
195: .getSuperActivities().size() == 2);
196: assertTrue("bdes1.size == 1", activity1.getBreakdownElements()
197: .size() == 1);
198: assertTrue("bdes2.size == 1", activity2.getBreakdownElements()
199: .size() == 1);
200:
201: // Rk: the tearDown method is called here.
202: }
203:
204: @Test
205: public void testRemoveFromActivity() {
206: // Rk: the setUp method is called here.
207:
208: Activity activity = new Activity();
209: activity.setGuid("idEPF");
210: activity.setName("name1");
211: activity.setDescription("description1");
212: activity.setPrefix("prefix1");
213: activity.setIsOptional(true);
214: activity.setIsPlanned(false);
215: activity.setHasMultipleOccurrences(false);
216: activity.setIsEvenDriven(true);
217: activity.setIsOngoing(false);
218: activity.setIsRepeatable(true);
219: this .breakdownElement.addSuperActivity(activity);
220: this .breakdownElement.removeSuperActivity(activity);
221:
222: assertTrue(this .breakdownElement.getSuperActivities().isEmpty());
223: assertTrue(activity.getBreakdownElements().isEmpty());
224:
225: // Rk: the tearDown method is called here.
226: }
227:
228: @Test
229: public void testRemoveFromAllActivities() {
230: // Rk: the setUp method is called here.
231:
232: Activity activity = new Activity();
233: activity.setGuid("idEPF");
234: activity.setName("name1");
235: activity.setDescription("description1");
236: activity.setPrefix("prefix1");
237: activity.setIsOptional(true);
238: activity.setIsPlanned(false);
239: activity.setHasMultipleOccurrences(false);
240: activity.setIsEvenDriven(true);
241: activity.setIsOngoing(false);
242: activity.setIsRepeatable(true);
243:
244: Activity activity2 = new Activity();
245: activity2.setGuid("idEPF");
246: activity2.setName("name2");
247: activity2.setDescription("description2");
248: activity2.setPrefix("prefix2");
249: activity2.setIsOptional(true);
250: activity2.setIsPlanned(false);
251: activity2.setHasMultipleOccurrences(false);
252: activity2.setIsEvenDriven(true);
253: activity2.setIsOngoing(false);
254: activity2.setIsRepeatable(true);
255:
256: Set<Activity> set = new HashSet<Activity>();
257: set.add(activity);
258: set.add(activity2);
259:
260: this .breakdownElement.addAllSuperActivities(set);
261: this .breakdownElement.removeAllSuperActivities();
262:
263: assertTrue(this .breakdownElement.getSuperActivities().isEmpty());
264: assertTrue(activity.getBreakdownElements().isEmpty());
265: assertTrue(activity2.getBreakdownElements().isEmpty());
266:
267: // Rk: the tearDown method is called here.
268: }
269: }
|