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.task;
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.task.StepDao;
031: import wilos.model.spem2.task.Step;
032: import wilos.model.spem2.task.TaskDefinition;
033: import wilos.test.TestConfiguration;
034:
035: /**
036: * Test for DAO That manage Step objets
037: *
038: * @author garwind
039: *
040: */
041: public class StepDaoTest {
042:
043: private StepDao stepDao = (StepDao) TestConfiguration.getInstance()
044: .getApplicationContext().getBean("StepDao");;
045:
046: private Step step = null;
047:
048: /**
049: * attributes from Element
050: */
051: public static final String ID = "thisId";
052:
053: public static final String NAME = "thisStep";
054:
055: public static final String DESCRIPTION = "step";
056:
057: @Before
058: public void setUp() {
059:
060: // Create empty TaskDefinition
061: this .step = new Step();
062: this .step.setName(NAME);
063: this .step.setDescription(DESCRIPTION);
064: }
065:
066: @After
067: public void tearDown() {
068: this .step = null;
069: }
070:
071: @Test
072: public void testSaveOrUpdateStep() {
073: // Rk: the setUp method is called here.
074:
075: // Save the task with the method to test.
076: String id = this .stepDao.saveOrUpdateStep(this .step);
077:
078: // Check the saving.
079: TaskDefinition taskTmp = (TaskDefinition) this .stepDao
080: .getHibernateTemplate().load(TaskDefinition.class, id);
081: assertNotNull(taskTmp);
082:
083: this .stepDao.deleteStep(this .step);
084:
085: // Rk: the tearDown method is called here.
086: }
087:
088: @Test
089: public void testGetAllSteps() {
090: // Rk: the setUp method is called here.
091:
092: // Save the task into the database.
093: this .stepDao.getHibernateTemplate().saveOrUpdate(this .step);
094:
095: // Look if this task is also into the database and look if the size of
096: // the set is >= 1.
097: List<Step> steps = this .stepDao.getAllSteps();
098: assertNotNull(steps);
099: assertTrue(steps.size() >= 1);
100:
101: this .stepDao.deleteStep(this .step);
102:
103: // Rk: the tearDown method is called here.
104: }
105:
106: @Test
107: public void testGetStep() {
108: // Rk: the setUp method is called here.
109:
110: // Save the task into the database.
111: String id = this .stepDao.saveOrUpdateStep(this .step);
112:
113: // Test the method getTask with an existing task.
114: Step sectionTmp = this .stepDao.getStep(id);
115: assertNotNull(sectionTmp);
116: assertEquals("Name", sectionTmp.getName(), NAME);
117: assertEquals("Description", sectionTmp.getDescription(),
118: DESCRIPTION);
119:
120: // Test the method getTask with an unexisting task.
121: this .stepDao.getHibernateTemplate().delete(step);
122:
123: // Rk: the tearDown method is called here.
124: }
125:
126: @Test
127: public void testDeleteTask() {
128: // Rk: the setUp method is called here.
129:
130: // Save the task into the database.
131: String id = this .stepDao.saveOrUpdateStep(this .step);
132:
133: // Test the method deleteTask with an acitivity existing into the db.
134: this .stepDao.deleteStep(this .step);
135:
136: // See if the step is now absent in the db.
137: Step stepTmp = (Step) this .stepDao.getStep(id);
138: assertNull(stepTmp);
139:
140: // Rk: the tearDown method is called here.
141: }
142: }
|