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.misc.concreteactivity;
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.Date;
025: import java.util.List;
026:
027: import org.junit.After;
028: import org.junit.Before;
029: import org.junit.Test;
030:
031: import wilos.hibernate.misc.concreteactivity.ConcreteActivityDao;
032: import wilos.model.misc.concreteactivity.ConcreteActivity;
033: import wilos.test.TestConfiguration;
034:
035: /*
036: * Unit test for ConcreteActivityDao
037: *
038: * @author deder
039: * @author garwind
040: */
041: public class ConcreteActivityDaoTest {
042:
043: private ConcreteActivityDao concreteactivityDao = (ConcreteActivityDao) TestConfiguration
044: .getInstance().getApplicationContext().getBean(
045: "ConcreteActivityDao");
046:
047: private ConcreteActivity concreteactivity = null;
048:
049: public static final String NAME = "thisConcreteActivity";
050:
051: public static final String DESCRIPTION = "concrete activity description";
052:
053: public static final String PREFIX = "prefix";
054:
055: public static final Boolean IS_OPTIONAL = true;
056:
057: public static final Boolean HAS_MULTIPLE_OCCURENCES = true;
058:
059: public static final Boolean IS_EVEN_DRIVEN = true;
060:
061: public static final Boolean IS_ON_GOING = true;
062:
063: public static final Boolean IS_PLANNED = true;
064:
065: public static final Boolean IS_REPEATABLE = true;
066:
067: @Before
068: public void setUp() {
069:
070: // Create empty ConcreteActivity.
071: this .concreteactivity = new ConcreteActivity();
072: this .concreteactivity.setConcreteName("My concrete name");
073: this .concreteactivity.setPlannedFinishingDate(new Date());
074: }
075:
076: @After
077: public void tearDown() {
078: this .concreteactivity = null;
079: }
080:
081: @Test
082: public void testSaveOrUpdateConcreteActivity() {
083: // Rk: the setUp method is called here.
084:
085: // Save the concrete activity with the method to test.
086: this .concreteactivityDao
087: .saveOrUpdateConcreteActivity(this .concreteactivity);
088:
089: // Check the saving.
090: String id = this .concreteactivity.getId();
091: ConcreteActivity concreteactivityTmp = (ConcreteActivity) this .concreteactivityDao
092: .getConcreteActivity(id);
093: assertNotNull(concreteactivityTmp);
094:
095: // Delete the data stored in the database
096: this .concreteactivityDao
097: .deleteConcreteActivity(this .concreteactivity);
098: // Rk: the tearDown method is called here.
099: }
100:
101: @Test
102: public void testGetAllConcreteActivities() {
103: // Rk: the setUp method is called here.
104:
105: // Save the concrete activity with the method to test.
106: this .concreteactivityDao
107: .saveOrUpdateConcreteActivity(this .concreteactivity);
108:
109: // Look if this concrete activity is also into the database and look if
110: // the size of the set is >= 1.
111: List<ConcreteActivity> concreteactivities = this .concreteactivityDao
112: .getAllConcreteActivities();
113: assertNotNull(concreteactivities);
114: assertTrue(concreteactivities.size() >= 1);
115:
116: // Delete the data stored in the database
117: this .concreteactivityDao
118: .deleteConcreteActivity(this .concreteactivity);
119: // Rk: the tearDown method is called here.
120: }
121:
122: @Test
123: public void testGetConcreteActivity() {
124: // Rk: the setUp method is called here.
125:
126: // Save the concrete activity into the database.
127: this .concreteactivityDao
128: .saveOrUpdateConcreteActivity(this .concreteactivity);
129: String id = this .concreteactivity.getId();
130:
131: // Test the method getConcreteActivity with an existing activity.
132: ConcreteActivity concreteactivityTmp = this .concreteactivityDao
133: .getConcreteActivity(id);
134: assertNotNull(concreteactivityTmp);
135: assertEquals("Name", concreteactivityTmp.getConcreteName(),
136: this .concreteactivity.getConcreteName());
137:
138: // Test the method getConcreteActivity with an unexisting activity.
139: this .concreteactivityDao
140: .deleteConcreteActivity(this .concreteactivity);
141:
142: // Rk: the tearDown method is called here.
143: }
144:
145: @Test
146: public void testDeleteConcreteActivity() {
147: // Rk: the setUp method is called here.
148:
149: // Save the concreteactivity into the database.
150: this .concreteactivityDao
151: .saveOrUpdateConcreteActivity(this .concreteactivity);
152: String id = this .concreteactivity.getId();
153:
154: // Test the method deleteConcreteActivity with an activity existing into
155: // the db.
156: this .concreteactivityDao
157: .deleteConcreteActivity(this .concreteactivity);
158:
159: // See if this.concreteactivity is now absent in the db.
160: ConcreteActivity concreteactivityTmp = (ConcreteActivity) this .concreteactivityDao
161: .getConcreteActivity(id);
162: assertNull(concreteactivityTmp);
163:
164: // Rk: the tearDown method is called here.
165: }
166: }
|