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