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