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.activity;
018:
019: import static org.junit.Assert.*;
020:
021: import java.util.List;
022:
023: import org.junit.After;
024: import org.junit.Before;
025: import org.junit.Test;
026:
027: import wilos.hibernate.spem2.activity.ActivityDao;
028: import wilos.model.spem2.activity.Activity;
029: import wilos.test.TestConfiguration;
030:
031: public class ActivityDaoTest {
032:
033: private ActivityDao activityDao = (ActivityDao) TestConfiguration
034: .getInstance().getApplicationContext().getBean(
035: "ActivityDao");
036:
037: private Activity activity = null;
038:
039: public static final String NAME = "thisActivity";
040:
041: public static final String DESCRIPTION = "activity description";
042:
043: public static final String PREFIX = "prefix";
044:
045: public static final Boolean IS_OPTIONAL = true;
046:
047: public static final Boolean HAS_MULTIPLE_OCCURENCES = true;
048:
049: public static final Boolean IS_EVEN_DRIVEN = true;
050:
051: public static final Boolean IS_ON_GOING = true;
052:
053: public static final Boolean IS_PLANNED = true;
054:
055: public static final Boolean IS_REPEATABLE = true;
056:
057: @Before
058: public void setUp() {
059:
060: this .activity = new Activity();
061: this .activity.setName(NAME);
062: this .activity.setDescription(DESCRIPTION);
063: this .activity.setPrefix(PREFIX);
064: this .activity
065: .setHasMultipleOccurrences(HAS_MULTIPLE_OCCURENCES);
066: this .activity.setIsEvenDriven(IS_EVEN_DRIVEN);
067: this .activity.setIsOngoing(IS_ON_GOING);
068: this .activity.setIsOptional(IS_OPTIONAL);
069: this .activity.setIsPlanned(IS_PLANNED);
070: this .activity.setIsRepeatable(IS_REPEATABLE);
071: }
072:
073: @After
074: public void tearDown() {
075: this .activity = null;
076: }
077:
078: @Test
079: public void testSaveOrUpdateActivity() {
080: // Rk: the setUp method is called here.
081:
082: // Save the activity with the method to test.
083: String id = this .activityDao
084: .saveOrUpdateActivity(this .activity);
085:
086: Activity activityTmp = (Activity) this .activityDao
087: .getActivity(id);
088: assertNotNull(activityTmp);
089:
090: this .activityDao.deleteActivity(this .activity);
091: // Rk: the tearDown method is called here.
092: }
093:
094: @Test
095: public void testGetAllActivities() {
096: // Rk: the setUp method is called here.
097:
098: // Save the activity with the method to test.
099: this .activityDao.saveOrUpdateActivity(this .activity);
100:
101: // Look if this activity is also into the database and look if the size
102: // of the set is >= 1.
103: List<Activity> activities = this .activityDao.getAllActivities();
104: assertNotNull(activities);
105: assertTrue(activities.size() >= 1);
106:
107: this .activityDao.deleteActivity(this .activity);
108:
109: // Rk: the tearDown method is called here.
110: }
111:
112: @Test
113: public void testGetActivity() {
114:
115: // Save the activity into the database.
116: String id = this .activityDao
117: .saveOrUpdateActivity(this .activity);
118:
119: // Test the method getActivity with an existing activity.
120: Activity activityTmp = this .activityDao.getActivity(id);
121: assertNotNull(activityTmp);
122: assertEquals("Name", activityTmp.getName(), NAME);
123: assertEquals("Description", activityTmp.getDescription(),
124: DESCRIPTION);
125: assertEquals("Prefix", activityTmp.getPrefix(), PREFIX);
126: assertEquals("HasMultipleOccurences", activityTmp
127: .getHasMultipleOccurrences(), HAS_MULTIPLE_OCCURENCES);
128: assertEquals("IsEvenDriven", activityTmp.getIsEvenDriven(),
129: IS_EVEN_DRIVEN);
130: assertEquals("IsOnGoing", activityTmp.getIsOngoing(),
131: IS_ON_GOING);
132: assertEquals("IsOptional", activityTmp.getIsOptional(),
133: IS_OPTIONAL);
134: assertEquals("IsPlanned", activityTmp.getIsPlanned(),
135: IS_PLANNED);
136: assertEquals("IsRepeatale", activityTmp.getIsRepeatable(),
137: IS_REPEATABLE);
138:
139: // Test the method getActivity with an unexisting activity.
140: this .activityDao.deleteActivity(this .activity);
141:
142: // Rk: the tearDown method is called here.
143: }
144:
145: @Test
146: public void testDeleteActivity() {
147: // Rk: the setUp method is called here.
148:
149: // Save the activity into the database.
150: String id = this .activityDao
151: .saveOrUpdateActivity(this .activity);
152:
153: // Test the method deleteActivity with an activity existing into the db.
154: this .activityDao.deleteActivity(this .activity);
155:
156: // See if this.activity is now absent in the db.
157: Activity activityTmp = (Activity) this .activityDao
158: .getActivity(id);
159: assertNull(activityTmp);
160:
161: // Rk: the tearDown method is called here.
162: }
163: }
|