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.iteration;
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.spem2.iteration.IterationDao;
031: import wilos.model.spem2.iteration.Iteration;
032: import wilos.test.TestConfiguration;
033:
034: /**
035: *
036: * @author Soosuske
037: *
038: */
039: public class IterationDaoTest {
040: private IterationDao iterationDao = (IterationDao) TestConfiguration
041: .getInstance().getApplicationContext().getBean(
042: "IterationDao");;
043:
044: private Iteration iteration = null;
045:
046: public static final String NAME = "thisIteration";
047:
048: public static final String DESCRIPTION = "iteration description";
049:
050: public static final String PREFIX = "prefix";
051:
052: public static final Boolean IS_OPTIONAL = true;
053:
054: public static final Boolean HAS_MULTIPLE_OCCURENCES = true;
055:
056: public static final Boolean IS_EVEN_DRIVEN = true;
057:
058: public static final Boolean IS_ON_GOING = true;
059:
060: public static final Boolean IS_PLANNED = true;
061:
062: public static final Boolean IS_REPEATABLE = true;
063:
064: @Before
065: public void setUp() {
066:
067: this .iteration = new Iteration();
068: // Add properties to the iteration.
069: this .iteration.setName(NAME);
070: this .iteration.setDescription(DESCRIPTION);
071: this .iteration.setPrefix(PREFIX);
072: this .iteration
073: .setHasMultipleOccurrences(HAS_MULTIPLE_OCCURENCES);
074: this .iteration.setIsEvenDriven(IS_EVEN_DRIVEN);
075: this .iteration.setIsOngoing(IS_ON_GOING);
076: this .iteration.setIsOptional(IS_OPTIONAL);
077: this .iteration.setIsPlanned(IS_PLANNED);
078: this .iteration.setIsRepeatable(IS_REPEATABLE);
079: }
080:
081: @After
082: public void tearDown() {
083: this .iteration = null;
084: }
085:
086: @Test
087: public final void testSaveOrUpdateIteration() {
088: // Rk: the setUp method is called here.
089:
090: // Save the iteration with the method to test.
091: this .iterationDao.saveOrUpdateIteration(this .iteration);
092:
093: // Check the saving.
094: String id = this .iteration.getId();
095: Iteration iterationTmp = (Iteration) this .iterationDao
096: .getIteration(id);
097: assertNotNull(iterationTmp);
098:
099: this .iterationDao.deleteIteration(this .iteration);
100:
101: // Rk: the tearDown method is called here.
102: }
103:
104: @Test
105: public final void testGetAllIterations() {
106: // Rk: the setUp method is called here.
107:
108: // Save the iteration with the method to test.
109: this .iterationDao.saveOrUpdateIteration(this .iteration);
110:
111: // Look if this iteration is also into the database and look if the size
112: // of the set is >= 1.
113: List<Iteration> iterations = this .iterationDao
114: .getAllIterations();
115: assertNotNull(iterations);
116: assertTrue(iterations.size() >= 1);
117:
118: this .iterationDao.deleteIteration(this .iteration);
119:
120: // Rk: the tearDown method is called here.
121: }
122:
123: @Test
124: public final void testGetIteration() {
125: // Rk: the setUp method is called here.
126:
127: // Save the iteration into the database.
128: this .iterationDao.saveOrUpdateIteration(this .iteration);
129: String id = this .iteration.getId();
130:
131: // Test the method getIteration with an existing iteration.
132: Iteration iterationTmp = this .iterationDao.getIteration(id);
133: assertNotNull(iterationTmp);
134: assertEquals("Name", iterationTmp.getName(), NAME);
135: assertEquals("Description", iterationTmp.getDescription(),
136: DESCRIPTION);
137: assertEquals("Prefix", iterationTmp.getPrefix(), PREFIX);
138: assertEquals("HasMultipleOccurences", iterationTmp
139: .getHasMultipleOccurrences(), HAS_MULTIPLE_OCCURENCES);
140: assertEquals("IsEvenDriven", iterationTmp.getIsEvenDriven(),
141: IS_EVEN_DRIVEN);
142: assertEquals("IsOnGoing", iterationTmp.getIsOngoing(),
143: IS_ON_GOING);
144: assertEquals("IsOptional", iterationTmp.getIsOptional(),
145: IS_OPTIONAL);
146: assertEquals("IsPlanned", iterationTmp.getIsPlanned(),
147: IS_PLANNED);
148: assertEquals("IsRepeatale", iterationTmp.getIsRepeatable(),
149: IS_REPEATABLE);
150:
151: // Test the method getIteration with an unexisting iteration.
152: this .iterationDao.deleteIteration(this .iteration);
153:
154: // Rk: the tearDown method is called here.
155: }
156:
157: @Test
158: public final void testDeleteIteration() {
159: // Rk: the setUp method is called here.
160:
161: // Save the iteration into the database.
162: this .iterationDao.saveOrUpdateIteration(this .iteration);
163: String id = this .iteration.getId();
164:
165: // Test the method deleteIteration with an iteration existing into the
166: // db.
167: this .iterationDao.deleteIteration(this .iteration);
168:
169: // See if this.iteration is now absent in the db.
170: Iteration iterationTmp = (Iteration) this .iterationDao
171: .getIteration(id);
172: assertNull(iterationTmp);
173:
174: // Rk: the tearDown method is called here.
175: }
176: }
|