1 /**
2 * Copyright 2005-2006 the original author or authors.
3 *
4 * Licensed under the Gnu General Pubic License, Version 2.0 (the
5 * "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/gpl-license.php
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the Gnu General Public License for more details.
14 */
15 package org.figure8.join.businessobjects.environment.persistence;
16
17 import org.figure8.join.util.SpringTestCase;
18 import org.figure8.join.businessobjects.commons.Step;
19 import org.figure8.join.businessobjects.commons.Release;
20 import org.figure8.join.businessobjects.commons.persistence.StepDao;
21 import org.figure8.join.businessobjects.commons.persistence.ReleaseDao;
22 import org.figure8.join.businessobjects.environment.LogicalEnvironment;
23
24 import java.util.Date;
25 /**
26 * JUnit test case for testing LogicalEnvironmentDao implementation
27 * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
28 * @version $Revision: 1.2 $
29 */
30 public class LogicalEnvironmentDaoTest extends SpringTestCase{
31
32
33
34 /** Spring configuration files */
35 private String[] configLocations = new String[]{
36 "classpath:/org/figure8/join/businessobjects/environment/persistence/spring.xml"};
37
38
39
40
41 /** The needed StepDao impl */
42 protected StepDao stepDao = null;
43 /** The needed ReleaseDao impl */
44 protected ReleaseDao releaseDao = null;
45 /** The logical environment dao implementation to test */
46 protected LogicalEnvironmentDao dao = null;
47
48
49
50
51 /** Retrieve needed daos after having initialized context */
52 public void setUp(){
53 super.setUp();
54
55 dao = (LogicalEnvironmentDao)context.getBean("logicalEnvironmentDao");
56 stepDao = (StepDao)context.getBean("stepDao");
57 releaseDao = (ReleaseDao)context.getBean("releaseDao");
58 }
59
60
61
62
63 /** Test the creation of a Logical enironment. */
64 public void testLogicalEnvironmentCreation(){
65
66 Step step = new Step("logEnvCreation", 1);
67 Release release = new Release("1.0", 1, 0, new Date());
68 LogicalEnvironment env = new LogicalEnvironment("creationKey", "creationLabel", "creationDescription",
69 "managerId", step, release);
70 int size = getLogicalEnvironmentListSize();
71 stepDao.save(step);
72 releaseDao.save(release);
73 dao.save(env);
74
75 assertEquals("LogicalEnvironment is successfully created", size + 1, dao.findAll().size());
76 }
77
78 /** Test the getByKey() for environment. */
79 public void testFindByKey(){
80
81 Step step = new Step("logEnvFindByKey", 2);
82 Release release = new Release("2.0", 2, 0, new Date());
83 LogicalEnvironment env = new LogicalEnvironment("findByKey", "findByLabel", "findByDescription",
84 "managerId", step, release);
85 int size = getLogicalEnvironmentListSize();
86 stepDao.save(step);
87 releaseDao.save(release);
88 dao.save(env);
89
90 assertEquals("LogicalEnvironment is successfully creation", size + 1, dao.findAll().size());
91
92 LogicalEnvironment foundEnv = dao.getLogicalEnvironment("findByKey");
93 assertNotNull("Found a LogicalEnvironment", foundEnv);
94 assertEquals("Found the correct LogicalEnvironment", "findByLabel", foundEnv.getLabel());
95 assertEquals("Found the correct LogicalEnvironment", "findByDescription", foundEnv.getDescription());
96 assertEquals("Found the correct LogicalEnvironment", "managerId", foundEnv.getManagerId());
97 assertEquals("Found the correct LogicalEnvironment", "logEnvFindByKey", foundEnv.getStep().getLabel());
98 }
99
100
101
102
103 /** Test the findAll on LogicalEnvironment */
104 protected int getLogicalEnvironmentListSize(){
105 return dao.findAll().size();
106 }
107
108
109
110
111 /** @return configLocations inner field */
112 public String[] getConfigLocations(){
113 return configLocations;
114 }
115 }