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.businessfacades.commons;
16
17 import org.figure8.join.util.SpringTestCase;
18 import org.figure8.join.businessobjects.commons.Step;
19 import org.figure8.join.businessobjects.commons.Status;
20 import org.figure8.join.businessobjects.commons.Target;
21 import org.figure8.join.businessobjects.commons.Release;
22 import org.figure8.join.core.DuplicateEntityException;
23
24 import java.util.Date;
25 import java.util.List;
26 /**
27 * JUnit test case for testing the IntegrationProcessManager implementation
28 * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
29 * @version $Revision: 1.1 $
30 */
31 public class IntegrationProcessManagerTest extends SpringTestCase{
32
33
34
35 /** Spring configuration files */
36 private String[] configLocations = new String[]{
37 "classpath:/org/figure8/join/businessfacades/commons/spring.xml",
38 "classpath:/org/figure8/join/businessobjects/commons/persistence/spring.xml"};
39
40
41
42
43 /** The IntegrationProcessManager implementation to test */
44 protected IntegrationProcessManager processManager = null;
45
46
47
48
49 /** Retrieve process manager after having initialized context */
50 public void setUp(){
51 super.setUp();
52
53 processManager = (IntegrationProcessManager)context.getBean("processManager");
54 }
55
56
57
58
59 /** Test status related methods. */
60 public void testStatus(){
61
62 Status status1 = new Status("key1", "label1", Status.DEPLOYMENT_PREPARATION_TYPE);
63 Status status2 = new Status("key2", "label2", Status.DEPLOYMENT_PREPARATION_TYPE);
64 Status status3 = new Status("key3", "label3", Status.DEPLOYMENT_REALIZATION_TYPE);
65 try{
66 processManager.saveStatus(status1);
67 processManager.saveStatus(status2);
68 processManager.saveStatus(status3);
69 }
70 catch (Exception e){
71 fail("No exception should be thrown");
72 }
73
74 assertEquals("Three Status have been created successfully", 3, processManager.getStatus().size());
75
76
77 Status foundStatus = processManager.getStatus("key1");
78
79 assertNotNull("Found a Status", foundStatus);
80 assertEquals("Found the correct Status", "label1", foundStatus.getLabel());
81 assertFalse("Found the correct Status", foundStatus.isCancelled());
82
83
84 List statusList = processManager.getStatusForType(Status.DEPLOYMENT_PREPARATION_TYPE);
85 assertNotNull("Found a Status list", statusList);
86 assertEquals("Found the correct number of Status", 2, statusList.size());
87
88 statusList = processManager.getStatusForType(Status.DEPLOYMENT_REALIZATION_TYPE);
89 assertNotNull("Found a Status list", statusList);
90 assertEquals("Found the correct number of Status", 1, statusList.size());
91
92
93 foundStatus.setCancelled(true);
94 try {processManager.saveStatus(foundStatus);}
95 catch (Exception e) {fail("No exception should be thrown");}
96
97 assertEquals("Three Status are enlisted", 3, processManager.getStatus().size());
98
99
100 boolean exception = false;
101 Status status4 = new Status("key1", "label4", Status.DEPLOYMENT_REALIZATION_TYPE);
102 try{
103
104 processManager.saveStatus(status4);
105 }
106 catch (DuplicateEntityException dee){
107
108 assertEquals("Original entity causes duplicate", "key1", ((Status)dee.getOriginalEntity()).getKey());
109 exception = true;
110 }
111 assertTrue("DuplicateEntityException was thrown", exception);
112 }
113
114 /** Test step related methods. */
115 public void testSteps(){
116
117 Step step1 = new Step("Acceptance", 1);
118 processManager.saveStep(step1);
119 Step step2 = new Step("Integration", 2);
120 processManager.saveStep(step2);
121 Step step3 = new Step("Non regression", 3);
122 processManager.saveStep(step3);
123
124 assertEquals("Three Steps have been created successfully", 3, processManager.getSteps().size());
125
126
127 Step foundStep = processManager.getStep("Acceptance");
128
129 assertNotNull("Found a Step", foundStep);
130 assertEquals("Found the correct Step", 1, foundStep.getPosition());
131 assertEquals("Chaining has been done", "Integration", foundStep.getNextStep().getLabel());
132 assertEquals("Chaining has been done", "Non regression", foundStep.getNextStep().getNextStep().getLabel());
133
134
135 foundStep.setLabel("Acceptance tests");
136 processManager.saveStep(foundStep);
137
138 assertEquals("Three Steps are enlisted", 3, processManager.getSteps().size());
139
140
141 Step step2a = new Step("New features tests", 3);
142 processManager.saveStep(step2a);
143
144 assertEquals("Four Steps are enlisted", 4, processManager.getSteps().size());
145 assertEquals("Step 2a has correct next step", "Non regression", step2a.getNextStep().getLabel());
146 assertEquals("Step 2a has correct previous step", "Integration", step2a.getPreviousStep().getLabel());
147 }
148
149 /** Test target related methods. */
150 public void testTargets(){
151
152 Target target1 = new Target("target1", "description1");
153 Target target2 = new Target("target2", "description2");
154 try{
155 processManager.saveTarget(target1);
156 processManager.saveTarget(target2);
157 }
158 catch (Exception e){
159 fail("No exception should be thrown");
160 }
161
162 assertEquals("Two Targets have been created successfully", 2, processManager.getTargets().size());
163
164
165 Target foundTarget = processManager.getTarget("target2");
166
167 assertNotNull("Found a Target", foundTarget);
168 assertEquals("Found the correct Target", "target2", foundTarget.getName());
169 assertEquals("Found the correct Target", "description2", foundTarget.getDescription());
170
171
172 foundTarget.setDescription("updated descrption2");
173 try {processManager.saveTarget(foundTarget);}
174 catch (Exception e) {fail("No exception should be thrown");}
175
176 assertEquals("Two Targets are enlisted", 2, processManager.getTargets().size());
177
178
179 boolean exception = false;
180 Target target3 = new Target("target1", "description3");
181 try{
182
183 processManager.saveTarget(target3);
184 }
185 catch (DuplicateEntityException dee){
186
187 assertEquals("Original entity causes duplicate", "target1", ((Target)dee.getOriginalEntity()).getName());
188 exception = true;
189 }
190 assertTrue("DuplicateEntityException was thrown", exception);
191 }
192
193 /** Test release related methods. */
194 public void testReleases(){
195
196 Release release1 = new Release("11.0", 11, 0, new Date());
197 Release release2 = new Release("21.0", 21, 0, new Date());
198 int size = processManager.getReleases().size();
199 try{
200 processManager.saveRelease(release1);
201 processManager.saveRelease(release2);
202 }
203 catch (Exception e){
204 fail("No exception should be thrown");
205 }
206
207 assertEquals("Two Releases have been created sucessfully", size + 2, processManager.getReleases().size());
208
209
210 Release foundRelease = processManager.getRelease("21.0");
211
212 assertNotNull("Found a Release", foundRelease);
213 assertEquals("Found the correct Release", 21, foundRelease.getMajor());
214 assertEquals("Found the correct Release", 0, foundRelease.getMinor());
215
216
217 foundRelease.setName("21.1");
218 foundRelease.setMinor(1);
219 try {processManager.saveRelease(foundRelease);}
220 catch (Exception e) {fail("No exception should be thrown");}
221
222 assertEquals("Two Releases are enlisted", size + 2, processManager.getReleases().size());
223
224
225 boolean exception = false;
226 Release release3 = new Release("release3", 11, 0, new Date());
227 try{
228
229 processManager.saveRelease(release3);
230 }
231 catch (DuplicateEntityException dee){
232
233 assertEquals("Original entity causes duplicate", "11.0", ((Release)dee.getOriginalEntity()).getName());
234 exception = true;
235 }
236 assertTrue("DuplicateEntityException was thrown", exception);
237 }
238
239
240
241
242 /** @return configLocations inner field */
243 public String[] getConfigLocations(){
244 return configLocations;
245 }
246 }