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