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.iteration;
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.misc.concreteiteration.ConcreteIteration;
028: import wilos.model.spem2.iteration.Iteration;
029:
030: public class IterationTest {
031:
032: private Iteration iteration;
033:
034: public static final String PREFIX = "prefix";
035:
036: public static final Boolean IS_OPTIONAL = true;
037:
038: public static final String CONCRETENAME = "ConcreteName1";
039:
040: public static final String CONCRETENAME2 = "ConcreteName2";
041:
042: @Before
043: public void setUp() throws Exception {
044: this .iteration = new Iteration();
045: this .iteration.setPrefix(PREFIX);
046: this .iteration.setIsOptional(IS_OPTIONAL);
047: }
048:
049: @After
050: public void tearDown() throws Exception {
051: //None.
052: }
053:
054: @Test
055: public final void testHashCode() {
056: // Rk: the setUp method is called here.
057:
058: Iteration iter = new Iteration();
059: iter.setPrefix(PREFIX);
060: iter.setIsOptional(IS_OPTIONAL);
061:
062: assertNotNull(this .iteration.hashCode());
063: assertNotNull(iter.hashCode());
064: assertEquals(this .iteration.hashCode(), iter.hashCode());
065:
066: // Rk: the tearDown method is called here.
067: }
068:
069: @Test
070: public final void testEquals() {
071: // Rk: the setUp method is called here.
072:
073: // Assert if it's equal by references.
074: assertTrue("By references", this .iteration
075: .equals(this .iteration));
076:
077: // Assert if it's equal field by field.
078: Iteration iterationTmp1 = null;
079: try {
080: iterationTmp1 = this .iteration.clone();
081: } catch (CloneNotSupportedException e) {
082: fail("Error CloneNotSupportedException in the testEquals method");
083: }
084: assertTrue("Field by field", this .iteration
085: .equals(iterationTmp1));
086:
087: // Assert if it's not equal.
088: Iteration iterTmp2 = new Iteration();
089: iterTmp2.setPrefix("prefixFalse");
090: iterTmp2.setIsOptional(true);
091: assertFalse("Not equals", this .iteration.equals(iterTmp2));
092:
093: // Rk: the tearDown method is called here.
094: }
095:
096: @Test
097: public final void testClone() {
098: // Rk: the setUp method is called here.
099:
100: try {
101: assertEquals(this .iteration.clone(), this .iteration);
102: } catch (CloneNotSupportedException e) {
103: fail("Error CloneNotSupportedException in the testClone method");
104: }
105:
106: // Rk: the tearDown method is called here.
107: }
108:
109: @Test
110: public void testAddConcreteIteration() {
111: ConcreteIteration concreteIteration = new ConcreteIteration();
112: concreteIteration.setConcreteName(CONCRETENAME);
113:
114: this .iteration.addConcreteIteration(concreteIteration);
115:
116: assertTrue(this .iteration.getConcreteIterations().size() == 1);
117: assertNotNull(concreteIteration.getIteration());
118: }
119:
120: @Test
121: public void testAddToAllConcreteIteration() {
122: ConcreteIteration concreteIteration1 = new ConcreteIteration();
123: concreteIteration1.setConcreteName(CONCRETENAME);
124:
125: ConcreteIteration concreteIteration2 = new ConcreteIteration();
126: concreteIteration2.setConcreteName(CONCRETENAME2);
127:
128: Set<ConcreteIteration> set = new HashSet<ConcreteIteration>();
129: set.add(concreteIteration1);
130: set.add(concreteIteration2);
131:
132: this .iteration.addAllConcreteIterations(set);
133:
134: assertFalse(this .iteration.getConcreteIterations().isEmpty());
135: assertTrue(this .iteration.getConcreteIterations().size() == 2);
136: assertNotNull(concreteIteration1.getIteration());
137: assertNotNull(concreteIteration2.getIteration());
138: }
139:
140: @Test
141: public void testRemoveConcreteIteration() {
142: ConcreteIteration concreteIteration = new ConcreteIteration();
143: concreteIteration.setConcreteName(CONCRETENAME);
144:
145: this .iteration.removeConcreteIteration(concreteIteration);
146:
147: assertTrue(this .iteration.getConcreteIterations().isEmpty());
148: assertNull(concreteIteration.getIteration());
149: }
150:
151: @Test
152: public void testRemoveAllConcreteIterations() {
153: ConcreteIteration concreteIteration1 = new ConcreteIteration();
154: concreteIteration1.setConcreteName(CONCRETENAME);
155:
156: ConcreteIteration concreteIteration2 = new ConcreteIteration();
157: concreteIteration2.setConcreteName(CONCRETENAME2);
158:
159: Set<ConcreteIteration> set = new HashSet<ConcreteIteration>();
160: set.add(concreteIteration1);
161: set.add(concreteIteration2);
162:
163: this .iteration.addAllConcreteIterations(set);
164:
165: assertTrue(this .iteration.getConcreteIterations().size() == 2);
166: assertNotNull(concreteIteration1.getIteration());
167: assertNotNull(concreteIteration2.getIteration());
168:
169: this.iteration.removeAllConcreteIterations();
170: assertTrue(this.iteration.getConcreteIterations().isEmpty());
171: assertNull(concreteIteration1.getIteration());
172: assertNull(concreteIteration2.getIteration());
173: }
174: }
|