View Javadoc

1   package org.apache.maven.continuum.store;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.continuum.dao.BuildDefinitionTemplateDao;
23  import org.apache.continuum.dao.BuildQueueDao;
24  import org.apache.continuum.dao.ContinuumReleaseResultDao;
25  import org.apache.continuum.dao.DaoUtils;
26  import org.apache.continuum.dao.DirectoryPurgeConfigurationDao;
27  import org.apache.continuum.dao.InstallationDao;
28  import org.apache.continuum.dao.LocalRepositoryDao;
29  import org.apache.continuum.dao.ProfileDao;
30  import org.apache.continuum.dao.ProjectDao;
31  import org.apache.continuum.dao.ProjectGroupDao;
32  import org.apache.continuum.dao.ProjectScmRootDao;
33  import org.apache.continuum.dao.RepositoryPurgeConfigurationDao;
34  import org.apache.continuum.dao.ScheduleDao;
35  import org.apache.continuum.dao.SystemConfigurationDao;
36  import org.apache.continuum.model.project.ProjectScmRoot;
37  import org.apache.continuum.model.release.ContinuumReleaseResult;
38  import org.apache.continuum.model.repository.DirectoryPurgeConfiguration;
39  import org.apache.continuum.model.repository.LocalRepository;
40  import org.apache.continuum.model.repository.RepositoryPurgeConfiguration;
41  import org.apache.maven.continuum.installation.InstallationService;
42  import org.apache.maven.continuum.model.project.BuildDefinition;
43  import org.apache.maven.continuum.model.project.BuildDefinitionTemplate;
44  import org.apache.maven.continuum.model.project.BuildQueue;
45  import org.apache.maven.continuum.model.project.BuildResult;
46  import org.apache.maven.continuum.model.project.Project;
47  import org.apache.maven.continuum.model.project.ProjectDependency;
48  import org.apache.maven.continuum.model.project.ProjectDeveloper;
49  import org.apache.maven.continuum.model.project.ProjectGroup;
50  import org.apache.maven.continuum.model.project.ProjectNotifier;
51  import org.apache.maven.continuum.model.project.Schedule;
52  import org.apache.maven.continuum.model.scm.ChangeFile;
53  import org.apache.maven.continuum.model.scm.ChangeSet;
54  import org.apache.maven.continuum.model.scm.ScmResult;
55  import org.apache.maven.continuum.model.system.Installation;
56  import org.apache.maven.continuum.model.system.Profile;
57  import org.apache.maven.continuum.model.system.SystemConfiguration;
58  import org.codehaus.plexus.jdo.DefaultConfigurableJdoFactory;
59  import org.codehaus.plexus.jdo.JdoFactory;
60  import org.codehaus.plexus.spring.PlexusInSpringTestCase;
61  
62  import java.util.ArrayList;
63  import java.util.HashMap;
64  import java.util.Iterator;
65  import java.util.List;
66  import java.util.Map;
67  
68  /**
69   * Base class for tests using the continuum store.
70   */
71  public abstract class AbstractContinuumStoreTestCase
72      extends PlexusInSpringTestCase
73  {
74      protected DaoUtils daoUtilsImpl;
75  
76      protected DirectoryPurgeConfigurationDao directoryPurgeConfigurationDao;
77  
78      protected LocalRepositoryDao localRepositoryDao;
79  
80      protected RepositoryPurgeConfigurationDao repositoryPurgeConfigurationDao;
81  
82      protected InstallationDao installationDao;
83  
84      protected ProfileDao profileDao;
85  
86      protected ProjectGroupDao projectGroupDao;
87  
88      protected ProjectDao projectDao;
89  
90      protected ScheduleDao scheduleDao;
91  
92      protected SystemConfigurationDao systemConfigurationDao;
93  
94      protected ProjectScmRootDao projectScmRootDao;
95  
96      protected ContinuumReleaseResultDao releaseResultDao;
97  
98      protected BuildQueueDao buildQueueDao;
99  
100     protected BuildDefinitionTemplateDao buildDefinitionTemplateDao;
101 
102     protected ProjectGroup defaultProjectGroup;
103 
104     protected ProjectGroup testProjectGroup2;
105 
106     protected Project testProject1;
107 
108     protected Project testProject2;
109 
110     protected Schedule testSchedule1;
111 
112     protected Schedule testSchedule2;
113 
114     protected Schedule testSchedule3;
115 
116     protected Profile testProfile1;
117 
118     protected Profile testProfile2;
119 
120     protected Profile testProfile3;
121 
122     protected Profile testProfile4;
123 
124     protected Installation testInstallationJava13;
125 
126     protected Installation testInstallationJava14;
127 
128     protected Installation testInstallationMaven20a3;
129 
130     protected Installation testInstallationEnvVar;
131 
132     protected BuildResult testBuildResult1;
133 
134     protected BuildResult testBuildResult2;
135 
136     protected BuildResult testBuildResult3;
137 
138     protected ScmResult testCheckoutResult1;
139 
140     protected LocalRepository testLocalRepository1;
141 
142     protected LocalRepository testLocalRepository2;
143 
144     protected LocalRepository testLocalRepository3;
145 
146     protected RepositoryPurgeConfiguration testRepoPurgeConfiguration1;
147 
148     protected RepositoryPurgeConfiguration testRepoPurgeConfiguration2;
149 
150     protected RepositoryPurgeConfiguration testRepoPurgeConfiguration3;
151 
152     protected DirectoryPurgeConfiguration testDirectoryPurgeConfig;
153 
154     protected ProjectScmRoot testProjectScmRoot;
155 
156     protected ContinuumReleaseResult testContinuumReleaseResult;
157 
158     protected BuildQueue testBuildQueue1;
159 
160     protected BuildQueue testBuildQueue2;
161 
162     protected BuildQueue testBuildQueue3;
163 
164     private SystemConfiguration systemConfiguration;
165 
166     @Override
167     protected void setUp()
168         throws Exception
169     {
170         super.setUp();
171 
172         createStore();
173 
174         directoryPurgeConfigurationDao =
175             (DirectoryPurgeConfigurationDao) lookup( DirectoryPurgeConfigurationDao.class.getName() );
176 
177         localRepositoryDao = (LocalRepositoryDao) lookup( LocalRepositoryDao.class.getName() );
178 
179         repositoryPurgeConfigurationDao =
180             (RepositoryPurgeConfigurationDao) lookup( RepositoryPurgeConfigurationDao.class.getName() );
181 
182         installationDao = (InstallationDao) lookup( InstallationDao.class.getName() );
183 
184         profileDao = (ProfileDao) lookup( ProfileDao.class.getName() );
185 
186         projectGroupDao = (ProjectGroupDao) lookup( ProjectGroupDao.class.getName() );
187 
188         projectDao = (ProjectDao) lookup( ProjectDao.class.getName() );
189 
190         scheduleDao = (ScheduleDao) lookup( ScheduleDao.class.getName() );
191 
192         systemConfigurationDao = (SystemConfigurationDao) lookup( SystemConfigurationDao.class.getName() );
193 
194         projectScmRootDao = (ProjectScmRootDao) lookup( ProjectScmRootDao.class.getName() );
195 
196         releaseResultDao = (ContinuumReleaseResultDao) lookup( ContinuumReleaseResultDao.class.getName() );
197 
198         buildQueueDao = (BuildQueueDao) lookup( BuildQueueDao.class.getName() );
199 
200         buildDefinitionTemplateDao = (BuildDefinitionTemplateDao) lookup( BuildDefinitionTemplateDao.class.getName() );
201     }
202 
203     protected void createBuildDatabase( boolean isTestFromDataManagementTool )
204         throws Exception
205     {
206         createBuildDatabase( true, isTestFromDataManagementTool );
207     }
208 
209     protected void createBuildDatabase( boolean addToStore, boolean isTestFromDataManagementTool )
210         throws Exception
211     {
212         // Setting up test data
213         testLocalRepository1 = createTestLocalRepository( "name1", "location1", "layout1" );
214 
215         LocalRepository localRepository1 = createTestLocalRepository( testLocalRepository1 );
216         if ( addToStore )
217         {
218             localRepository1 = localRepositoryDao.addLocalRepository( localRepository1 );
219             testLocalRepository1.setId( localRepository1.getId() );
220         }
221         else
222         {
223             localRepository1.setId( 1 );
224             testLocalRepository1.setId( 1 );
225         }
226 
227         testLocalRepository2 = createTestLocalRepository( "name2", "location2", "layout2" );
228 
229         LocalRepository localRepository2 = createTestLocalRepository( testLocalRepository2 );
230         if ( addToStore )
231         {
232             localRepository2 = localRepositoryDao.addLocalRepository( localRepository2 );
233             testLocalRepository2.setId( localRepository2.getId() );
234         }
235         else
236         {
237             localRepository2.setId( 2 );
238             testLocalRepository2.setId( 2 );
239         }
240 
241         testLocalRepository3 = createTestLocalRepository( "name3", "location3", "layout3" );
242 
243         LocalRepository localRepository3 = createTestLocalRepository( testLocalRepository3 );
244         if ( addToStore )
245         {
246             localRepository3 = localRepositoryDao.addLocalRepository( localRepository3 );
247             testLocalRepository3.setId( localRepository3.getId() );
248         }
249         else
250         {
251             localRepository3.setId( 3 );
252             testLocalRepository3.setId( 3 );
253         }
254 
255         testBuildQueue1 = createTestBuildQueue( "build queue 1" );
256 
257         BuildQueue buildQueue1 = createTestBuildQueue( testBuildQueue1 );
258         if ( addToStore )
259         {
260             buildQueue1 = buildQueueDao.addBuildQueue( buildQueue1 );
261             testBuildQueue1.setId( buildQueue1.getId() );
262         }
263         else
264         {
265             buildQueue1.setId( 1 );
266             testBuildQueue1.setId( 1 );
267         }
268 
269         testBuildQueue2 = createTestBuildQueue( "build queue 2" );
270 
271         BuildQueue buildQueue2 = createTestBuildQueue( testBuildQueue2 );
272         if ( addToStore )
273         {
274             buildQueue2 = buildQueueDao.addBuildQueue( buildQueue2 );
275             testBuildQueue2.setId( buildQueue2.getId() );
276         }
277         else
278         {
279             buildQueue2.setId( 2 );
280             testBuildQueue2.setId( 2 );
281         }
282 
283         testBuildQueue3 = createTestBuildQueue( "build queue 3" );
284 
285         BuildQueue buildQueue3 = createTestBuildQueue( testBuildQueue3 );
286         if ( addToStore )
287         {
288             buildQueue3 = buildQueueDao.addBuildQueue( buildQueue3 );
289             testBuildQueue3.setId( buildQueue3.getId() );
290         }
291         else
292         {
293             buildQueue3.setId( 3 );
294             testBuildQueue3.setId( 3 );
295         }
296 
297         defaultProjectGroup = createTestProjectGroup( "Default Group", "The Default Group",
298                                                       "org.apache.maven.test.default", localRepository1 );
299 
300         testProjectGroup2 =
301             createTestProjectGroup( "test group 2", "test group 2 desc", "test group 2 groupId", localRepository2 );
302 
303         testProject1 = createTestProject( "artifactId1", 1, "description1", defaultProjectGroup.getGroupId(), "name1",
304                                           "scmUrl1", 1, "url1", "version1", "workingDirectory1" );
305 
306         // state must be 1 unless we setup a build in the correct state
307         testProject2 = createTestProject( "artifactId2", 2, "description2", defaultProjectGroup.getGroupId(), "name2",
308                                           "scmUrl2", 1, "url2", "version2", "workingDirectory2" );
309 
310         testSchedule1 = createTestSchedule( "name1", "description1", 1, "cronExpression1", true );
311         testSchedule1.addBuildQueue( buildQueue1 );
312         testSchedule1.addBuildQueue( buildQueue2 );
313         
314         testSchedule2 = createTestSchedule( "name2", "description2", 2, "cronExpression2", true );
315         testSchedule2.addBuildQueue( buildQueue2 );
316         testSchedule2.addBuildQueue( buildQueue3 );
317 
318         testSchedule3 = createTestSchedule( "name3", "description3", 3, "cronExpression3", true );
319 
320         testInstallationJava13 =
321             createTestInstallation( "JDK 1.3", InstallationService.JDK_TYPE, "JAVA_HOME", "/usr/local/java-1.3" );
322         testInstallationJava14 =
323             createTestInstallation( "JDK 1.4", InstallationService.JDK_TYPE, "JAVA_HOME", "/usr/local/java-1.4" );
324         testInstallationMaven20a3 = createTestInstallation( "Maven 2.0 alpha 3", InstallationService.MAVEN2_TYPE,
325                                                             "M2_HOME", "/usr/local/maven-2.0-alpha-3" );
326         testInstallationEnvVar =
327             createTestInstallation( "Maven Heap Size", InstallationService.ENVVAR_TYPE, "MAVEN_OPTS", "-Xms256m -Xmx256m" );
328 
329         ProjectNotifier testGroupNotifier1 = createTestNotifier( 1, true, false, true, "type1" );
330         ProjectNotifier testGroupNotifier2 = createTestNotifier( 2, false, true, false, "type2" );
331         ProjectNotifier testGroupNotifier3 = createTestNotifier( 3, true, false, false, "type3" );
332 
333         ProjectNotifier testNotifier1 = createTestNotifier( 11, true, true, false, "type11" );
334         ProjectNotifier testNotifier2 = createTestNotifier( 12, false, false, true, "type12" );
335         ProjectNotifier testNotifier3 = createTestNotifier( 13, false, true, false, "type13" );
336 
337         ProjectDeveloper testDeveloper1 = createTestDeveloper( 1, "email1", "name1", "scmId1" );
338         ProjectDeveloper testDeveloper2 = createTestDeveloper( 2, "email2", "name2", "scmId2" );
339         ProjectDeveloper testDeveloper3 = createTestDeveloper( 3, "email3", "name3", "scmId3" );
340 
341         ProjectDependency testDependency1 = createTestDependency( "groupId1", "artifactId1", "version1" );
342         ProjectDependency testDependency2 = createTestDependency( "groupId2", "artifactId2", "version2" );
343         ProjectDependency testDependency3 = createTestDependency( "groupId3", "artifactId3", "version3" );
344 
345         // TODO: simplify by deep copying the relationships in createTest... ?
346         long baseTime = System.currentTimeMillis();
347         testBuildResult1 = createTestBuildResult( 1, true, 1, 1, "error1", 1, baseTime, baseTime + 1000 );
348         BuildResult buildResult1 = createTestBuildResult( testBuildResult1 );
349         ScmResult scmResult = createTestScmResult( "commandOutput1", "providerMessage1", true, "1" );
350         buildResult1.setScmResult( scmResult );
351         ScmResult testBuildResult1ScmResult = createTestScmResult( scmResult, "1" );
352         testBuildResult1.setScmResult( testBuildResult1ScmResult );
353         testCheckoutResult1 = createTestScmResult( "commandOutputCO1", "providerMessageCO1", false, "CO1" );
354         ScmResult checkoutResult1 = createTestScmResult( testCheckoutResult1, "CO1" );
355         testProject1.setCheckoutResult( checkoutResult1 );
356         testProject1.addBuildResult( buildResult1 );
357 
358         testBuildResult2 = createTestBuildResult( 2, false, 2, 2, "error2", 2, baseTime + 2000, baseTime + 3000 );
359         BuildResult buildResult2 = createTestBuildResult( testBuildResult2 );
360         testProject1.addBuildResult( buildResult2 );
361 
362         testBuildResult3 = createTestBuildResult( 3, true, 3, 3, "error3", 3, baseTime + 4000, baseTime + 5000 );
363         BuildResult buildResult3 = createTestBuildResult( testBuildResult3 );
364         scmResult = createTestScmResult( "commandOutput3", "providerMessage3", true, "3" );
365         buildResult3.setScmResult( scmResult );
366         testBuildResult3.setScmResult( createTestScmResult( scmResult, "3" ) );
367         testProject2.addBuildResult( buildResult3 );
368 
369         // TODO: better way? this assumes that some untested methods already work!
370         Schedule schedule2 = createTestSchedule( testSchedule2 );
371         if ( addToStore )
372         {
373             schedule2 = scheduleDao.addSchedule( schedule2 );
374             testSchedule2.setId( schedule2.getId() );
375         }
376         else
377         {
378             // from expected.xml, continuum-data-management
379             testSchedule2.setId( 1 );
380         }
381 
382         Schedule schedule1 = createTestSchedule( testSchedule1 );
383         if ( addToStore )
384         {
385             schedule1 = scheduleDao.addSchedule( schedule1 );
386             testSchedule1.setId( schedule1.getId() );
387         }
388         else
389         {
390             // from expected.xml, continuum-data-management
391             testSchedule1.setId( 2 );
392         }
393 
394         Schedule schedule3 = createTestSchedule( testSchedule3 );
395         if ( addToStore )
396         {
397             schedule3 = scheduleDao.addSchedule( schedule3 );
398             testSchedule3.setId( schedule3.getId() );
399         }
400         else
401         {
402             // from expected.xml, continuum-data-management
403             testSchedule3.setId( 3 );
404         }
405 
406         Installation installationJava14 = createTestInstallation( testInstallationJava14 );
407         if ( addToStore )
408         {
409             installationJava14 = installationDao.addInstallation( installationJava14 );
410         }
411         else
412         {
413             installationJava14.setInstallationId( 1 );
414         }
415 
416         Installation installationMaven20a3 = createTestInstallation( testInstallationMaven20a3 );
417         if ( addToStore )
418         {
419             installationMaven20a3 = installationDao.addInstallation( installationMaven20a3 );
420         }
421         else
422         {
423             installationMaven20a3.setInstallationId( 2 );
424         }
425 
426         Installation installationJava13 = createTestInstallation( testInstallationJava13 );
427         if ( addToStore )
428         {
429             installationJava13 = installationDao.addInstallation( installationJava13 );
430         }
431         else
432         {
433             installationJava13.setInstallationId( 3 );
434         }
435 
436         Installation installationEnvVar = createTestInstallation( testInstallationEnvVar );
437         if ( addToStore )
438         {
439             installationEnvVar = installationDao.addInstallation( installationEnvVar );
440         }
441         else
442         {
443             installationEnvVar.setInstallationId( 4 );
444         }
445 
446         testProfile1 =
447             createTestProfile( "name1", "description1", 1, true, true, installationJava13, installationMaven20a3 );
448         testProfile2 =
449             createTestProfile( "name2", "description2", 2, false, true, installationJava14, installationMaven20a3 );
450         testProfile3 =
451             createTestProfile( "name3", "description3", 3, true, false, installationJava14, installationMaven20a3 );
452         testProfile4 =
453             createTestProfile( "name4", "description4", 4, false, false, installationJava14, installationMaven20a3 );
454         testProfile4.addEnvironmentVariable( installationEnvVar );
455 
456         Profile profile1 = createTestProfile( testProfile1 );
457         if ( addToStore )
458         {
459             profile1 = profileDao.addProfile( profile1 );
460             testProfile1.setId( profile1.getId() );
461         }
462         else
463         {
464             testProfile1.setId( 1 );
465         }
466 
467         Profile profile2 = createTestProfile( testProfile2 );
468         if ( addToStore )
469         {
470             profile2 = profileDao.addProfile( profile2 );
471             testProfile2.setId( profile2.getId() );
472         }
473         else
474         {
475             testProfile2.setId( 2 );
476         }
477 
478         Profile profile3 = createTestProfile( testProfile3 );
479         if ( addToStore )
480         {
481             profile3 = profileDao.addProfile( profile3 );
482             testProfile3.setId( profile3.getId() );
483         }
484         else
485         {
486             profile3.setId( 3 );
487         }
488 
489         Profile profile4 = createTestProfile( testProfile4 );
490         if ( addToStore )
491         {
492             profile4 = profileDao.addProfile( profile4 );
493             testProfile4.setId( profile4.getId() );
494         }
495         else
496         {
497             profile4.setId( 4 );
498         }
499 
500         testRepoPurgeConfiguration1 =
501             createTestRepositoryPurgeConfiguration( true, 5, 50, false, schedule2, true, localRepository1 );
502         if ( addToStore )
503         {
504             testRepoPurgeConfiguration1 =
505                 repositoryPurgeConfigurationDao.addRepositoryPurgeConfiguration( testRepoPurgeConfiguration1 );
506         }
507         else
508         {
509             testRepoPurgeConfiguration1.setId( 1 );
510         }
511 
512         testRepoPurgeConfiguration2 =
513             createTestRepositoryPurgeConfiguration( false, 10, 200, true, schedule1, true, localRepository2 );
514         if ( addToStore )
515         {
516             testRepoPurgeConfiguration2 =
517                 repositoryPurgeConfigurationDao.addRepositoryPurgeConfiguration( testRepoPurgeConfiguration2 );
518         }
519         else
520         {
521             testRepoPurgeConfiguration2.setId( 2 );
522         }
523 
524         testRepoPurgeConfiguration3 =
525             createTestRepositoryPurgeConfiguration( false, 10, 200, true, schedule2, true, localRepository1 );
526         if ( addToStore )
527         {
528             testRepoPurgeConfiguration3 =
529                 repositoryPurgeConfigurationDao.addRepositoryPurgeConfiguration( testRepoPurgeConfiguration3 );
530         }
531         else
532         {
533             testRepoPurgeConfiguration3.setId( 3 );
534         }
535 
536         testDirectoryPurgeConfig =
537             createTestDirectoryPurgeConfiguration( "location1", "directoryType1", true, 10, 50, schedule2, true );
538         if ( addToStore )
539         {
540             testDirectoryPurgeConfig =
541                 directoryPurgeConfigurationDao.addDirectoryPurgeConfiguration( testDirectoryPurgeConfig );
542         }
543         else
544         {
545             testDirectoryPurgeConfig.setId( 1 );
546         }
547 
548         BuildDefinition testGroupBuildDefinition1 =
549             createTestBuildDefinition( "arguments1", "buildFile1", "goals1", profile1, schedule2, false, false );
550         BuildDefinition testGroupBuildDefinition2 =
551             createTestBuildDefinition( "arguments2", "buildFile2", "goals2", profile1, schedule1, false, false );
552         BuildDefinition testGroupBuildDefinition3 =
553             createTestBuildDefinition( "arguments3", "buildFile3", "goals3", profile2, schedule1, false, false );
554         BuildDefinition testGroupBuildDefinition4 =
555             createTestBuildDefinition( null, null, "deploy", null, null, false, false );
556 
557         BuildDefinition testBuildDefinition1 =
558             createTestBuildDefinition( "arguments11", "buildFile11", "goals11", profile2, schedule1, false, false );
559         BuildDefinition testBuildDefinition2 =
560             createTestBuildDefinition( "arguments12", "buildFile12", "goals12", profile2, schedule2, false, false );
561         BuildDefinition testBuildDefinition3 =
562             createTestBuildDefinition( "arguments13", "buildFile13", "goals13", profile1, schedule2, false, false );
563         BuildDefinition testBuildDefinition4 =
564             createTestBuildDefinition( null, null, "deploy", null, null, false, false );
565         BuildDefinition testBuildDefinition5 =
566             createTestBuildDefinition( "arguments14", "buildFile14", "goals14", profile1, schedule1, false, false );
567         testBuildDefinition5.setTemplate( true );
568             
569         BuildDefinitionTemplate testBuildDefinitionTemplate1 = createTestBuildDefinitionTemplate( "template2", "type2", false );
570         testBuildDefinitionTemplate1.addBuildDefinition( testBuildDefinition5 );
571 
572         if ( addToStore )
573         {
574             buildDefinitionTemplateDao.addBuildDefinitionTemplate( testBuildDefinitionTemplate1 );
575         }
576 
577         ProjectGroup group = createTestProjectGroup( defaultProjectGroup );
578 
579         Project project1 = createTestProject( testProject1 );
580         project1.addBuildResult( buildResult1 );
581         project1.addBuildResult( buildResult2 );
582         project1.setCheckoutResult( checkoutResult1 );
583         ProjectNotifier notifier1 = createTestNotifier( testNotifier1 );
584         project1.addNotifier( notifier1 );
585         testProject1.addNotifier( testNotifier1 );
586 
587         BuildDefinition buildDefinition1 = createTestBuildDefinition( testBuildDefinition1 );
588         project1.addBuildDefinition( buildDefinition1 );
589         testProject1.addBuildDefinition( testBuildDefinition1 );
590         BuildDefinition buildDefinition2 = createTestBuildDefinition( testBuildDefinition2 );
591         project1.addBuildDefinition( buildDefinition2 );
592         testProject1.addBuildDefinition( testBuildDefinition2 );
593 
594         ProjectDeveloper projectDeveloper1 = createTestDeveloper( testDeveloper1 );
595         project1.addDeveloper( projectDeveloper1 );
596         testProject1.addDeveloper( testDeveloper1 );
597 
598         ProjectDependency projectDependency1 = createTestDependency( testDependency1 );
599         project1.addDependency( projectDependency1 );
600         testProject1.addDependency( testDependency1 );
601 
602         ProjectDependency projectDependency2 = createTestDependency( testDependency2 );
603         project1.addDependency( projectDependency2 );
604         testProject1.addDependency( testDependency2 );
605 
606         group.addProject( project1 );
607         defaultProjectGroup.addProject( project1 );
608         Project project2 = createTestProject( testProject2 );
609         project2.addBuildResult( buildResult3 );
610         ProjectNotifier notifier2 = createTestNotifier( testNotifier2 );
611         project2.addNotifier( notifier2 );
612         testProject2.addNotifier( testNotifier2 );
613         ProjectNotifier notifier3 = createTestNotifier( testNotifier3 );
614         project2.addNotifier( notifier3 );
615         testProject2.addNotifier( testNotifier3 );
616 
617         BuildDefinition buildDefinition3 = createTestBuildDefinition( testBuildDefinition3 );
618         project2.addBuildDefinition( buildDefinition3 );
619         testProject2.addBuildDefinition( testBuildDefinition3 );
620 
621         BuildDefinition buildDefinition4 = createTestBuildDefinition( testBuildDefinition4 );
622         project2.addBuildDefinition( buildDefinition4 );
623         testProject2.addBuildDefinition( testBuildDefinition4 );
624 
625         ProjectDeveloper projectDeveloper2 = createTestDeveloper( testDeveloper2 );
626         project2.addDeveloper( projectDeveloper2 );
627         testProject2.addDeveloper( testDeveloper2 );
628 
629         ProjectDeveloper projectDeveloper3 = createTestDeveloper( testDeveloper3 );
630         project2.addDeveloper( projectDeveloper3 );
631         testProject2.addDeveloper( testDeveloper3 );
632 
633         ProjectDependency projectDependency3 = createTestDependency( testDependency3 );
634         project2.addDependency( projectDependency3 );
635         testProject2.addDependency( testDependency3 );
636 
637         group.addProject( project2 );
638         defaultProjectGroup.addProject( project2 );
639 
640         ProjectNotifier groupNotifier1 = createTestNotifier( testGroupNotifier1 );
641         group.addNotifier( groupNotifier1 );
642         defaultProjectGroup.addNotifier( testGroupNotifier1 );
643         ProjectNotifier groupNotifier2 = createTestNotifier( testGroupNotifier2 );
644         group.addNotifier( groupNotifier2 );
645         defaultProjectGroup.addNotifier( testGroupNotifier2 );
646 
647         BuildDefinition groupBuildDefinition1 = createTestBuildDefinition( testGroupBuildDefinition1 );
648         group.addBuildDefinition( groupBuildDefinition1 );
649         defaultProjectGroup.addBuildDefinition( testGroupBuildDefinition1 );
650 
651         if ( addToStore )
652         {
653             group = projectGroupDao.addProjectGroup( group );
654             defaultProjectGroup.setId( group.getId() );
655             testProject1.setId( project1.getId() );
656             testProject2.setId( project2.getId() );
657             testBuildResult1.setId( buildResult1.getId() );
658             testBuildResult2.setId( buildResult2.getId() );
659             testBuildResult3.setId( buildResult3.getId() );
660         }
661         else
662         {
663             // from expected.xml, continuum-data-management
664             defaultProjectGroup.setId( 1 );
665             testProject1.setId( 1 );
666             testProject2.setId( 2 );
667         }
668 
669         group = createTestProjectGroup( testProjectGroup2 );
670 
671         ProjectNotifier groupNotifier3 = createTestNotifier( testGroupNotifier3 );
672         group.addNotifier( groupNotifier3 );
673         testProjectGroup2.addNotifier( testGroupNotifier3 );
674 
675         BuildDefinition groupBuildDefinition2 = createTestBuildDefinition( testGroupBuildDefinition2 );
676         group.addBuildDefinition( groupBuildDefinition2 );
677         testProjectGroup2.addBuildDefinition( testGroupBuildDefinition2 );
678 
679         BuildDefinition groupBuildDefinition3 = createTestBuildDefinition( testGroupBuildDefinition3 );
680         group.addBuildDefinition( groupBuildDefinition3 );
681         testProjectGroup2.addBuildDefinition( testGroupBuildDefinition3 );
682 
683         BuildDefinition groupBuildDefinition4 = createTestBuildDefinition( testGroupBuildDefinition4 );
684         group.addBuildDefinition( groupBuildDefinition4 );
685         testProjectGroup2.addBuildDefinition( testGroupBuildDefinition4 );
686 
687         if ( addToStore )
688         {
689             group = projectGroupDao.addProjectGroup( group );
690             testProjectGroup2.setId( group.getId() );
691         }
692         else
693         {
694             group.setId( 2 );
695             testProjectGroup2.setId( 2 ); // from expected.xml, continuum-data-management
696         }
697 
698         systemConfiguration = new SystemConfiguration();
699         systemConfiguration.setBaseUrl( "baseUrl" );
700         systemConfiguration.setBuildOutputDirectory( "buildOutputDirectory" );
701         systemConfiguration.setDefaultScheduleCronExpression( "* * * * *" );
702         systemConfiguration.setDefaultScheduleDescription( "Description" );
703         systemConfiguration.setDeploymentRepositoryDirectory( "deployment" );
704         systemConfiguration.setGuestAccountEnabled( false );
705         systemConfiguration.setInitialized( true );
706         systemConfiguration.setWorkingDirectory( "workingDirectory" );
707 
708         if ( addToStore && !isTestFromDataManagementTool )
709         {   
710             systemConfiguration = systemConfigurationDao.addSystemConfiguration( systemConfiguration );
711         }
712         else
713         {
714             // hack for DataManagementTool test
715             // data-management-jdo has a dependency to continuum-commons where DefaultConfigurationService
716             //      is located. DefaultConfiguration loads the data and already adds a system configuration, causing
717             //      this to throw an exception
718             boolean isExisting = false;
719             try
720             {
721                 systemConfigurationDao.getSystemConfiguration();
722             }
723             catch ( ContinuumStoreException e )
724             {
725                 isExisting = true;
726             }
727             
728             if( !isExisting )
729             {
730                 systemConfiguration = systemConfigurationDao.getSystemConfiguration();
731                 systemConfiguration.setBaseUrl( "baseUrl" );
732                 systemConfiguration.setBuildOutputDirectory( "buildOutputDirectory" );
733                 systemConfiguration.setDefaultScheduleCronExpression( "* * * * *" );
734                 systemConfiguration.setDefaultScheduleDescription( "Description" );
735                 systemConfiguration.setDeploymentRepositoryDirectory( "deployment" );
736                 systemConfiguration.setGuestAccountEnabled( false );
737                 systemConfiguration.setInitialized( true );
738                 systemConfiguration.setWorkingDirectory( "workingDirectory" );
739                 
740                 systemConfigurationDao.updateSystemConfiguration( systemConfiguration );
741             }
742         }
743         
744         testProjectScmRoot = createTestProjectScmRoot( "scmRootAddress1", 1, 0, "error1", group );
745         ProjectScmRoot scmRoot = createTestProjectScmRoot( testProjectScmRoot );
746 
747         if ( addToStore )
748         {
749             scmRoot = projectScmRootDao.addProjectScmRoot( scmRoot );
750             testProjectScmRoot.setId( scmRoot.getId() );
751         }
752         else
753         {
754             testProjectScmRoot.setId( 1 );
755         }
756 
757         testContinuumReleaseResult = createTestContinuumReleaseResult( group, null, "releaseGoal", 0, 0, 0 );
758         ContinuumReleaseResult releaseResult = createTestContinuumReleaseResult( testContinuumReleaseResult );
759 
760         if ( addToStore )
761         {
762             releaseResult = releaseResultDao.addContinuumReleaseResult( releaseResult );
763             testContinuumReleaseResult.setId( releaseResult.getId() );
764         }
765         else
766         {
767             testContinuumReleaseResult.setId( 1 );
768         }
769     }
770 
771     @Override
772     protected void tearDown()
773         throws Exception
774     {
775         super.tearDown();
776 
777         daoUtilsImpl.eraseDatabase();
778 
779         daoUtilsImpl.closeStore();
780     }
781 
782     protected void assertBuildDatabase()
783         throws ContinuumStoreException
784     {
785         assertProjectGroupEquals( defaultProjectGroup, projectGroupDao.getProjectGroup( defaultProjectGroup.getId() ) );
786         assertProjectGroupEquals( testProjectGroup2, projectGroupDao.getProjectGroup( testProjectGroup2.getId() ) );
787 
788         assertProjectEquals( testProject1, projectDao.getProject( testProject1.getId() ) );
789         assertProjectEquals( testProject2, projectDao.getProject( testProject2.getId() ) );
790 
791         assertScheduleEquals( testSchedule1, scheduleDao.getSchedule( testSchedule1.getId() ) );
792         assertScheduleEquals( testSchedule2, scheduleDao.getSchedule( testSchedule2.getId() ) );
793         assertScheduleEquals( testSchedule3, scheduleDao.getSchedule( testSchedule3.getId() ) );
794 
795         Iterator<Installation> iterator = installationDao.getAllInstallations().iterator();
796         assertInstallationEquals( testInstallationJava13, iterator.next() );
797         assertInstallationEquals( testInstallationJava14, iterator.next() );
798         assertInstallationEquals( testInstallationMaven20a3, iterator.next() );
799 
800 /*
801         // TODO!!! -- definitely need to test the changeset stuff since it uses modello.refid
802         ProjectNotifier testGroupNotifier1 = createTestNotifier( 1, true, false, true, "type1" );
803         ProjectNotifier testGroupNotifier2 = createTestNotifier( 2, false, true, false, "type2" );
804         ProjectNotifier testGroupNotifier3 = createTestNotifier( 3, true, false, false, "type3" );
805 
806         ProjectNotifier testNotifier1 = createTestNotifier( 11, true, true, false, "type11" );
807         ProjectNotifier testNotifier2 = createTestNotifier( 12, false, false, true, "type12" );
808         ProjectNotifier testNotifier3 = createTestNotifier( 13, false, true, false, "type13" );
809 
810         ProjectDeveloper testDeveloper1 = createTestDeveloper( 1, "email1", "name1", "scmId1" );
811         ProjectDeveloper testDeveloper2 = createTestDeveloper( 2, "email2", "name2", "scmId2" );
812         ProjectDeveloper testDeveloper3 = createTestDeveloper( 3, "email3", "name3", "scmId3" );
813 
814         ProjectDependency testDependency1 = createTestDependency( "groupId1", "artifactId1", "version1" );
815         ProjectDependency testDependency2 = createTestDependency( "groupId2", "artifactId2", "version2" );
816         ProjectDependency testDependency3 = createTestDependency( "groupId3", "artifactId3", "version3" );
817 
818         // TODO: simplify by deep copying the relationships in createTest... ?
819         long baseTime = System.currentTimeMillis();
820         testBuildResult1 = createTestBuildResult( 1, true, 1, 1, "error1", 1, baseTime, baseTime + 1000 );
821         BuildResult buildResult1 = createTestBuildResult( testBuildResult1 );
822         ScmResult scmResult = createTestScmResult( "commandOutput1", "providerMessage1", true, "1" );
823         buildResult1.setScmResult( scmResult );
824         ScmResult testBuildResult1ScmResult = createTestScmResult( scmResult, "1" );
825         testBuildResult1.setScmResult( testBuildResult1ScmResult );
826         testCheckoutResult1 = createTestScmResult( "commandOutputCO1", "providerMessageCO1", false, "CO1" );
827         ScmResult checkoutResult1 = createTestScmResult( testCheckoutResult1, "CO1" );
828         testProject1.setCheckoutResult( checkoutResult1 );
829         testProject1.addBuildResult( buildResult1 );
830 
831         testBuildResult2 = createTestBuildResult( 2, false, 2, 2, "error2", 2, baseTime + 2000, baseTime + 3000 );
832         BuildResult buildResult2 = createTestBuildResult( testBuildResult2 );
833         testProject1.addBuildResult( buildResult2 );
834 
835         testBuildResult3 = createTestBuildResult( 3, true, 3, 3, "error3", 3, baseTime + 4000, baseTime + 5000 );
836         BuildResult buildResult3 = createTestBuildResult( testBuildResult3 );
837         scmResult = createTestScmResult( "commandOutput3", "providerMessage3", true, "3" );
838         buildResult3.setScmResult( scmResult );
839         testBuildResult3.setScmResult( createTestScmResult( scmResult, "3" ) );
840         testProject2.addBuildResult( buildResult3 );
841 
842         BuildDefinition testGroupBuildDefinition1 =
843             createTestBuildDefinition( "arguments1", "buildFile1", "goals1", profile1, schedule2 );
844         BuildDefinition testGroupBuildDefinition2 =
845             createTestBuildDefinition( "arguments2", "buildFile2", "goals2", profile1, schedule1 );
846         BuildDefinition testGroupBuildDefinition3 =
847             createTestBuildDefinition( "arguments3", "buildFile3", "goals3", profile2, schedule1 );
848 
849         BuildDefinition testBuildDefinition1 =
850             createTestBuildDefinition( "arguments11", "buildFile11", "goals11", profile2, schedule1 );
851         BuildDefinition testBuildDefinition2 =
852             createTestBuildDefinition( "arguments12", "buildFile12", "goals12", profile2, schedule2 );
853         BuildDefinition testBuildDefinition3 =
854             createTestBuildDefinition( "arguments13", "buildFile13", "goals13", profile1, schedule2 );
855 
856         ProjectGroup group = createTestProjectGroup( defaultProjectGroup );
857 
858         Project project1 = createTestProject( testProject1 );
859         project1.addBuildResult( buildResult1 );
860         project1.addBuildResult( buildResult2 );
861         project1.setCheckoutResult( checkoutResult1 );
862         ProjectNotifier notifier1 = createTestNotifier( testNotifier1 );
863         project1.addNotifier( notifier1 );
864         testProject1.addNotifier( testNotifier1 );
865 
866         BuildDefinition buildDefinition1 = createTestBuildDefinition( testBuildDefinition1 );
867         project1.addBuildDefinition( buildDefinition1 );
868         testProject1.addBuildDefinition( testBuildDefinition1 );
869         BuildDefinition buildDefinition2 = createTestBuildDefinition( testBuildDefinition2 );
870         project1.addBuildDefinition( buildDefinition2 );
871         testProject1.addBuildDefinition( testBuildDefinition2 );
872 
873         ProjectDeveloper projectDeveloper1 = createTestDeveloper( testDeveloper1 );
874         project1.addDeveloper( projectDeveloper1 );
875         testProject1.addDeveloper( testDeveloper1 );
876 
877         ProjectDependency projectDependency1 = createTestDependency( testDependency1 );
878         project1.addDependency( projectDependency1 );
879         testProject1.addDependency( testDependency1 );
880 
881         ProjectDependency projectDependency2 = createTestDependency( testDependency2 );
882         project1.addDependency( projectDependency2 );
883         testProject1.addDependency( testDependency2 );
884 
885         group.addProject( project1 );
886         defaultProjectGroup.addProject( project1 );
887         Project project2 = createTestProject( testProject2 );
888         project2.addBuildResult( buildResult3 );
889         ProjectNotifier notifier2 = createTestNotifier( testNotifier2 );
890         project2.addNotifier( notifier2 );
891         testProject2.addNotifier( testNotifier2 );
892         ProjectNotifier notifier3 = createTestNotifier( testNotifier3 );
893         project2.addNotifier( notifier3 );
894         testProject2.addNotifier( testNotifier3 );
895 
896         BuildDefinition buildDefinition3 = createTestBuildDefinition( testBuildDefinition3 );
897         project2.addBuildDefinition( buildDefinition3 );
898         testProject2.addBuildDefinition( testBuildDefinition3 );
899 
900         ProjectDeveloper projectDeveloper2 = createTestDeveloper( testDeveloper2 );
901         project2.addDeveloper( projectDeveloper2 );
902         testProject2.addDeveloper( testDeveloper2 );
903 
904         ProjectDeveloper projectDeveloper3 = createTestDeveloper( testDeveloper3 );
905         project2.addDeveloper( projectDeveloper3 );
906         testProject2.addDeveloper( testDeveloper3 );
907 
908         ProjectDependency projectDependency3 = createTestDependency( testDependency3 );
909         project2.addDependency( projectDependency3 );
910         testProject2.addDependency( testDependency3 );
911 
912         group.addProject( project2 );
913         defaultProjectGroup.addProject( project2 );
914 
915         ProjectNotifier groupNotifier1 = createTestNotifier( testGroupNotifier1 );
916         group.addNotifier( groupNotifier1 );
917         defaultProjectGroup.addNotifier( testGroupNotifier1 );
918         ProjectNotifier groupNotifier2 = createTestNotifier( testGroupNotifier2 );
919         group.addNotifier( groupNotifier2 );
920         defaultProjectGroup.addNotifier( testGroupNotifier2 );
921 
922         BuildDefinition groupBuildDefinition1 = createTestBuildDefinition( testGroupBuildDefinition1 );
923         group.addBuildDefinition( groupBuildDefinition1 );
924         defaultProjectGroup.addBuildDefinition( testGroupBuildDefinition1 );
925 
926         store.addProjectGroup( group );
927         defaultProjectGroup.setId( group.getId() );
928         testProject1.setId( project1.getId() );
929         testBuildResult1.setId( buildResult1.getId() );
930         testBuildResult2.setId( buildResult2.getId() );
931         testProject2.setId( project2.getId() );
932         testBuildResult3.setId( buildResult3.getId() );
933 
934         group = createTestProjectGroup( testProjectGroup2 );
935 
936         ProjectNotifier groupNotifier3 = createTestNotifier( testGroupNotifier3 );
937         group.addNotifier( groupNotifier3 );
938         testProjectGroup2.addNotifier( testGroupNotifier3 );
939 
940         BuildDefinition groupBuildDefinition2 = createTestBuildDefinition( testGroupBuildDefinition2 );
941         group.addBuildDefinition( groupBuildDefinition2 );
942         testProjectGroup2.addBuildDefinition( testGroupBuildDefinition2 );
943 
944         BuildDefinition groupBuildDefinition3 = createTestBuildDefinition( testGroupBuildDefinition3 );
945         group.addBuildDefinition( groupBuildDefinition3 );
946         testProjectGroup2.addBuildDefinition( testGroupBuildDefinition3 );
947 
948         store.addProjectGroup( group );
949         testProjectGroup2.setId( group.getId() );
950 */
951         assertSystemConfiguration( systemConfiguration, systemConfigurationDao.getSystemConfiguration() );
952 
953         assertLocalRepositoryEquals( testLocalRepository1, localRepositoryDao.getLocalRepository( testLocalRepository1.getId() ) );
954         assertLocalRepositoryEquals( testLocalRepository2, localRepositoryDao.getLocalRepository( testLocalRepository2.getId() ) );
955         assertLocalRepositoryEquals( testLocalRepository3, localRepositoryDao.getLocalRepository( testLocalRepository3.getId() ) );
956 
957 /*
958         assertRepositoryPurgeConfigurationEquals( testRepoPurgeConfiguration1,
959                                                   repositoryPurgeConfigurationDao.getRepositoryPurgeConfiguration( testRepoPurgeConfiguration1.getId() ) );
960         assertRepositoryPurgeConfigurationEquals( testRepoPurgeConfiguration2,
961                                                   repositoryPurgeConfigurationDao.getRepositoryPurgeConfiguration( testRepoPurgeConfiguration2.getId() ) );
962         assertRepositoryPurgeConfigurationEquals( testRepoPurgeConfiguration3,
963                                                   repositoryPurgeConfigurationDao.getRepositoryPurgeConfiguration( testRepoPurgeConfiguration3.getId() ) );
964 
965         assertDirectoryPurgeConfigurationEquals( testDirectoryPurgeConfig, 
966                                                  directoryPurgeConfigurationDao.getDirectoryPurgeConfiguration( testDirectoryPurgeConfig.getId() ) );
967 */
968         assertProjectScmRootEquals( testProjectScmRoot, projectScmRootDao.getProjectScmRoot( testProjectScmRoot.getId() ) );
969 
970         assertReleaseResultEquals( testContinuumReleaseResult, releaseResultDao.getContinuumReleaseResult( testContinuumReleaseResult.getId() ) );
971     }
972 
973     private void assertSystemConfiguration( SystemConfiguration expected, SystemConfiguration actual )
974     {
975         assertNotSame( expected, actual );
976         assertEquals( expected.getBaseUrl(), actual.getBaseUrl() );
977         assertEquals( expected.getBuildOutputDirectory(), actual.getBuildOutputDirectory() );
978         assertEquals( expected.getDefaultScheduleCronExpression(), actual.getDefaultScheduleCronExpression() );
979         assertEquals( expected.getDefaultScheduleDescription(), actual.getDefaultScheduleDescription() );
980         assertEquals( expected.getDeploymentRepositoryDirectory(), actual.getDeploymentRepositoryDirectory() );
981         assertEquals( expected.isGuestAccountEnabled(), actual.isGuestAccountEnabled() );
982         assertEquals( expected.isInitialized(), actual.isInitialized() );
983         assertEquals( expected.getWorkingDirectory(), actual.getWorkingDirectory() );
984     }
985 
986     protected void assertEmpty( boolean isTestFromDataManagementTool )
987         throws ContinuumStoreException
988     {
989         assertEquals( 0, installationDao.getAllInstallations().size() );
990         assertEquals( 0, profileDao.getAllProfilesByName().size() );
991         assertEquals( 0, projectGroupDao.getAllProjectGroups().size() );
992         assertEquals( 0, projectDao.getAllProjectsByName().size() );
993         if( !isTestFromDataManagementTool )
994         {
995             assertNull( systemConfigurationDao.getSystemConfiguration() );
996         }
997     }
998 
999     protected static BuildDefinition createTestBuildDefinition( BuildDefinition buildDefinition )
1000     {
1001         return createTestBuildDefinition( buildDefinition.getArguments(), buildDefinition.getBuildFile(),
1002                                           buildDefinition.getGoals(), buildDefinition.getProfile(), buildDefinition
1003             .getSchedule(), buildDefinition.isDefaultForProject(), buildDefinition
1004             .isBuildFresh() );
1005     }
1006 
1007     protected static BuildDefinition createTestBuildDefinition( String arguments, String buildFile, String goals,
1008                                                                 Profile profile, Schedule schedule,
1009                                                                 boolean defaultForProject, boolean buildFresh )
1010     {
1011         BuildDefinition definition = new BuildDefinition();
1012         definition.setArguments( arguments );
1013         definition.setBuildFile( buildFile );
1014         definition.setGoals( goals );
1015         definition.setProfile( profile );
1016         definition.setSchedule( schedule );
1017         definition.setDefaultForProject( defaultForProject );
1018         definition.setBuildFresh( buildFresh );
1019         return definition;
1020     }
1021 
1022     protected static ProjectNotifier createTestNotifier( ProjectNotifier notifier )
1023     {
1024         return createTestNotifier( notifier.getRecipientType(), notifier.isSendOnError(), notifier.isSendOnFailure(),
1025                                    notifier.isSendOnSuccess(), notifier.getType() );
1026     }
1027 
1028     protected static ProjectNotifier createTestNotifier( int recipientType, boolean sendOnError, boolean sendOnFailure,
1029                                                          boolean sendOnSuccess, String type )
1030     {
1031         Map<String, String> configuration = new HashMap<String, String>();
1032         configuration.put( "key1", "value1" );
1033         configuration.put( "key2", "value2" );
1034 
1035         ProjectNotifier notifier = new ProjectNotifier();
1036         notifier.setConfiguration( configuration );
1037         notifier.setRecipientType( recipientType );
1038         notifier.setSendOnError( sendOnError );
1039         notifier.setSendOnFailure( sendOnFailure );
1040         notifier.setSendOnSuccess( sendOnSuccess );
1041         notifier.setType( type );
1042 
1043         return notifier;
1044     }
1045 
1046     private static ScmResult createTestScmResult( ScmResult scmResult, String base )
1047     {
1048         return createTestScmResult( scmResult.getCommandOutput(), scmResult.getProviderMessage(), scmResult.isSuccess(),
1049                                     base );
1050     }
1051 
1052     private static ScmResult createTestScmResult( String commandOutput, String providerMessage, boolean success,
1053                                                   String base )
1054     {
1055         ScmResult scmResult = new ScmResult();
1056         scmResult.setCommandOutput( commandOutput );
1057         scmResult.setProviderMessage( providerMessage );
1058         scmResult.setSuccess( success );
1059 
1060         List<ChangeSet> changes = new ArrayList<ChangeSet>();
1061         changes.add( createTestChangeSet( "author" + base + ".1", "comment" + base + ".1", base + ".1" ) );
1062         changes.add( createTestChangeSet( "author" + base + ".2", "comment" + base + ".2", base + ".2" ) );
1063         scmResult.setChanges( changes );
1064         return scmResult;
1065     }
1066 
1067     private static ChangeSet createTestChangeSet( String author, String comment, String base )
1068     {
1069         ChangeSet changeSet = new ChangeSet();
1070         changeSet.setAuthor( author );
1071         changeSet.setComment( comment );
1072         changeSet.setDate( System.currentTimeMillis() );
1073         List<ChangeFile> files = new ArrayList<ChangeFile>();
1074         files.add( createTestChangeFile( "name" + base + ".1", "rev" + base + ".1" ) );
1075         files.add( createTestChangeFile( "name" + base + ".2", "rev" + base + ".2" ) );
1076         files.add( createTestChangeFile( "name" + base + ".3", "rev" + base + ".3" ) );
1077         changeSet.setFiles( files );
1078         return changeSet;
1079     }
1080 
1081     private static ChangeFile createTestChangeFile( String name, String revision )
1082     {
1083         ChangeFile changeFile = new ChangeFile();
1084         changeFile.setName( name );
1085         changeFile.setRevision( revision );
1086         return changeFile;
1087     }
1088 
1089     private static BuildResult createTestBuildResult( BuildResult buildResult )
1090     {
1091         return createTestBuildResult( buildResult.getTrigger(), buildResult.isSuccess(), buildResult.getState(),
1092                                       buildResult.getExitCode(), buildResult.getError(), buildResult.getBuildNumber(),
1093                                       buildResult.getStartTime(), buildResult.getEndTime() );
1094     }
1095 
1096     private static BuildResult createTestBuildResult( int trigger, boolean success, int state, int exitCode,
1097                                                       String error, int buildNumber, long startTime, long endTime )
1098     {
1099         BuildResult result = new BuildResult();
1100         result.setBuildNumber( buildNumber );
1101         result.setStartTime( startTime );
1102         result.setEndTime( endTime );
1103         result.setError( error );
1104         result.setExitCode( exitCode );
1105         result.setState( state );
1106         result.setSuccess( success );
1107         result.setTrigger( trigger );
1108         return result;
1109     }
1110 
1111     protected static Installation createTestInstallation( String name, String type, String varName, String varValue )
1112     {
1113         Installation installation = new Installation();
1114         installation.setName( name );
1115         installation.setType( type );
1116         installation.setVarName( varName );
1117         installation.setVarValue( varValue );
1118         return installation;
1119     }
1120 
1121     protected static Installation createTestInstallation( Installation installation )
1122     {
1123         return createTestInstallation( installation.getName(), installation.getType(), installation.getVarName(),
1124                                        installation.getVarValue() );
1125     }
1126 
1127     protected static Schedule createTestSchedule( Schedule schedule )
1128     {
1129         return createTestSchedule( schedule.getName(), schedule.getDescription(), schedule.getDelay(), schedule
1130             .getCronExpression(), schedule.isActive(), schedule.getBuildQueues() );
1131     }
1132 
1133     protected static Schedule createTestSchedule( String name, String description, int delay, String cronExpression,
1134                                                   boolean active )
1135     {
1136         return createTestSchedule( name, description, delay, cronExpression, active, null );
1137     }
1138                                                   
1139     protected static Schedule createTestSchedule( String name, String description, int delay, String cronExpression,
1140                                                   boolean active, List<BuildQueue> buildQueues )
1141     {
1142         Schedule schedule = new Schedule();
1143         schedule.setActive( active );
1144         schedule.setCronExpression( cronExpression );
1145         schedule.setDelay( delay );
1146         schedule.setDescription( description );
1147         schedule.setName( name );
1148         schedule.setBuildQueues( buildQueues );
1149 
1150         return schedule;
1151     }
1152 
1153     protected static Profile createTestProfile( Profile profile )
1154     {
1155         return createTestProfile( profile.getName(), profile.getDescription(), profile.getScmMode(), profile
1156             .isBuildWithoutChanges(), profile.isActive(), profile.getJdk(), profile.getBuilder(),
1157                                       profile.getEnvironmentVariables() );
1158     }
1159 
1160     protected static Profile createTestProfile( String name, String description, int scmMode,
1161                                                 boolean buildWithoutChanges, boolean active, Installation jdk,
1162                                                 Installation builder )
1163     {
1164         return createTestProfile( name, description, scmMode, buildWithoutChanges, active, jdk, builder, null );
1165     }
1166 
1167     protected static Profile createTestProfile( String name, String description, int scmMode,
1168                                                 boolean buildWithoutChanges, boolean active, Installation jdk,
1169                                                 Installation builder, List<Installation> envVars )
1170     {
1171         Profile profile = new Profile();
1172         profile.setActive( active );
1173         profile.setBuildWithoutChanges( buildWithoutChanges );
1174         profile.setScmMode( scmMode );
1175         profile.setDescription( description );
1176         profile.setName( name );
1177         profile.setBuilder( builder );
1178         profile.setJdk( jdk );
1179         profile.setEnvironmentVariables( envVars );
1180         return profile;
1181     }
1182 
1183     protected static ProjectGroup createTestProjectGroup( ProjectGroup group )
1184     {
1185         return createTestProjectGroup( group.getName(), group.getDescription(), group.getGroupId(),
1186                                        group.getLocalRepository() );
1187     }
1188 
1189     protected static ProjectGroup createTestProjectGroup( String name, String description, String groupId,
1190                                                           LocalRepository repository )
1191     {
1192         ProjectGroup group = new ProjectGroup();
1193         group.setName( name );
1194         group.setDescription( description );
1195         group.setGroupId( groupId );
1196         group.setLocalRepository( repository );
1197         return group;
1198     }
1199 
1200     protected static Project createTestProject( Project project )
1201     {
1202         return createTestProject( project.getArtifactId(), project.getBuildNumber(), project.getDescription(), project
1203             .getGroupId(), project.getName(), project.getScmUrl(), project.getState(), project.getUrl(), project
1204             .getVersion(), project.getWorkingDirectory() );
1205     }
1206 
1207     protected static Project createTestProject( String artifactId, int buildNumber, String description, String groupId,
1208                                                 String name, String scmUrl, int state, String url, String version,
1209                                                 String workingDirectory )
1210     {
1211         Project project = new Project();
1212         project.setArtifactId( artifactId );
1213         project.setBuildNumber( buildNumber );
1214         project.setDescription( description );
1215         project.setGroupId( groupId );
1216         project.setName( name );
1217         project.setScmUrl( scmUrl );
1218         project.setState( state );
1219         project.setUrl( url );
1220         project.setVersion( version );
1221         project.setWorkingDirectory( workingDirectory );
1222         return project;
1223     }
1224 
1225     protected static void assertProjectEquals( Project expectedProject, Project project )
1226     {
1227         assertEquals( "compare projects", expectedProject, project );
1228         assertNotSame( expectedProject, project );
1229         // aggressive compare, as equals is using the identity
1230         assertEquals( "compare expectedProject - name", expectedProject.getName(), project.getName() );
1231         assertEquals( "compare expectedProject - desc", expectedProject.getDescription(), project.getDescription() );
1232         assertEquals( "compare expectedProject - groupId", expectedProject.getGroupId(), project.getGroupId() );
1233         assertEquals( "compare expectedProject - artifactId", expectedProject.getArtifactId(),
1234                       project.getArtifactId() );
1235         assertEquals( "compare expectedProject - buildNumber", expectedProject.getBuildNumber(), project
1236             .getBuildNumber() );
1237         assertEquals( "compare expectedProject - scmUrl", expectedProject.getScmUrl(), project.getScmUrl() );
1238         assertEquals( "compare expectedProject - state", expectedProject.getState(), project.getState() );
1239         assertEquals( "compare expectedProject - url", expectedProject.getUrl(), project.getUrl() );
1240         assertEquals( "compare expectedProject - version", expectedProject.getVersion(), project.getVersion() );
1241         assertEquals( "compare expectedProject - workingDirectory", expectedProject.getWorkingDirectory(), project
1242             .getWorkingDirectory() );
1243     }
1244 
1245     protected static void assertProjectGroupEquals( ProjectGroup expectedGroup, ProjectGroup actualGroup )
1246     {
1247         assertEquals( "compare project groups", expectedGroup, actualGroup );
1248         assertNotSame( expectedGroup, actualGroup );
1249         // aggressive compare, as equals is using the identity
1250         assertEquals( "compare project groups - name", expectedGroup.getName(), actualGroup.getName() );
1251         assertEquals( "compare project groups - desc", expectedGroup.getDescription(), actualGroup.getDescription() );
1252         assertEquals( "compare project groups - groupId", expectedGroup.getGroupId(), actualGroup.getGroupId() );
1253     }
1254 
1255     protected static void assertScheduleEquals( Schedule expectedSchedule, Schedule actualSchedule )
1256     {
1257         assertEquals( expectedSchedule, actualSchedule );
1258         if ( expectedSchedule != null )
1259         {
1260             assertNotSame( expectedSchedule, actualSchedule );
1261             assertEquals( "compare schedule - id", expectedSchedule.getId(), actualSchedule.getId() );
1262             assertEquals( "compare schedule - name", expectedSchedule.getName(), actualSchedule.getName() );
1263             assertEquals( "compare schedule - desc", expectedSchedule.getDescription(),
1264                           actualSchedule.getDescription() );
1265             assertEquals( "compare schedule - delay", expectedSchedule.getDelay(), actualSchedule.getDelay() );
1266             assertEquals( "compare schedule - cron", expectedSchedule.getCronExpression(), actualSchedule
1267                 .getCronExpression() );
1268             assertEquals( "compare schedule - active", expectedSchedule.isActive(), actualSchedule.isActive() );
1269         }
1270     }
1271 
1272     protected static void assertProfileEquals( Profile expectedProfile, Profile actualProfile )
1273     {
1274         assertEquals( expectedProfile, actualProfile );
1275         if ( expectedProfile != null )
1276         {
1277             assertNotSame( expectedProfile, actualProfile );
1278             assertEquals( "compare profile - name", expectedProfile.getName(), actualProfile.getName() );
1279             assertEquals( "compare profile - desc", expectedProfile.getDescription(), actualProfile.getDescription() );
1280             assertEquals( "compare profile - scmMode", expectedProfile.getScmMode(), actualProfile.getScmMode() );
1281             assertEquals( "compare profile - build w/o changes", expectedProfile.isBuildWithoutChanges(), actualProfile
1282                 .isBuildWithoutChanges() );
1283             assertEquals( "compare profile - active", expectedProfile.isActive(), actualProfile.isActive() );
1284         }
1285     }
1286 
1287     protected static void assertInstallationEquals( Installation expected, Installation actual )
1288     {
1289         assertNotNull( actual );
1290         assertEquals( "compare installation - name", expected.getName(), actual.getName() );
1291         assertEquals( "compare installation - varName", expected.getVarName(), actual.getVarName() );
1292         assertEquals( "compare installation - varValue", expected.getVarValue(), actual.getVarValue() );
1293     }
1294 
1295     protected static void assertBuildResultEquals( BuildResult expected, BuildResult actual )
1296     {
1297         assertEquals( "compare build result - build #", expected.getBuildNumber(), actual.getBuildNumber() );
1298         assertEquals( "compare build result - end time", expected.getEndTime(), actual.getEndTime() );
1299         assertEquals( "compare build result - error", expected.getError(), actual.getError() );
1300         assertEquals( "compare build result - exit code", expected.getExitCode(), actual.getExitCode() );
1301         assertEquals( "compare build result - start time", expected.getStartTime(), actual.getStartTime() );
1302         assertEquals( "compare build result - state", expected.getState(), actual.getState() );
1303         assertEquals( "compare build result - trigger", expected.getTrigger(), actual.getTrigger() );
1304     }
1305 
1306     protected static void assertScmResultEquals( ScmResult expected, ScmResult actual )
1307     {
1308         assertEquals( "compare SCM result - output", expected.getCommandOutput(), actual.getCommandOutput() );
1309         assertEquals( "compare SCM result - message", expected.getProviderMessage(), actual.getProviderMessage() );
1310         assertEquals( "compare SCM result - success", expected.isSuccess(), actual.isSuccess() );
1311         assertEquals( "compare SCM result - changes size", actual.getChanges().size(), expected.getChanges().size() );
1312         for ( int i = 0; i < actual.getChanges().size(); i++ )
1313         {
1314             assertChangeSetEquals( (ChangeSet) expected.getChanges().get( i ),
1315                                    (ChangeSet) actual.getChanges().get( i ) );
1316         }
1317     }
1318 
1319     private static void assertChangeSetEquals( ChangeSet expected, ChangeSet actual )
1320     {
1321         assertEquals( "compare change set result - author", expected.getAuthor(), actual.getAuthor() );
1322         assertEquals( "compare change set result - comment", expected.getComment(), actual.getComment() );
1323         //Remove this test, in some case we have a 1ms difference between two dates
1324         //assertEquals( "compare change set result - date", changeSet.getDate(), retrievedChangeSet.getDate() );
1325         assertEquals( "compare change set result - files size", expected.getFiles().size(), actual.getFiles().size() );
1326         for ( int i = 0; i < actual.getFiles().size(); i++ )
1327         {
1328             assertChangeFileEquals( (ChangeFile) expected.getFiles().get( i ),
1329                                     (ChangeFile) actual.getFiles().get( i ) );
1330         }
1331     }
1332 
1333     private static void assertChangeFileEquals( ChangeFile expected, ChangeFile actual )
1334     {
1335         assertEquals( "compare change file result - name", expected.getName(), actual.getName() );
1336         assertEquals( "compare change file result - revision", expected.getRevision(), actual.getRevision() );
1337     }
1338 
1339     protected static void assertNotifiersEqual( List<ProjectNotifier> expected, List<ProjectNotifier> actual )
1340     {
1341         for ( int i = 0; i < actual.size(); i++ )
1342         {
1343             assertNotifierEquals( expected.get( i ), actual.get( i ) );
1344         }
1345     }
1346 
1347     protected static void assertNotifierEquals( ProjectNotifier expected, ProjectNotifier actual )
1348     {
1349         assertEquals( "compare notifier - recipient type", expected.getRecipientType(), actual.getRecipientType() );
1350         assertEquals( "compare notifier - type", expected.getType(), actual.getType() );
1351         assertEquals( "compare notifier - configuration", expected.getConfiguration(), actual.getConfiguration() );
1352         assertEquals( "compare notifier - send on success", expected.isSendOnSuccess(), actual.isSendOnSuccess() );
1353         assertEquals( "compare notifier - send on failure", expected.isSendOnFailure(), actual.isSendOnFailure() );
1354         assertEquals( "compare notifier - send on error", expected.isSendOnError(), actual.isSendOnError() );
1355     }
1356 
1357     protected static void assertBuildDefinitionsEqual( List<BuildDefinition> expectedBuildDefinitions,
1358                                                        List<BuildDefinition> actualBuildDefinitions )
1359     {
1360         for ( int i = 0; i < expectedBuildDefinitions.size(); i++ )
1361         {
1362             BuildDefinition expectedBuildDefinition = expectedBuildDefinitions.get( i );
1363             BuildDefinition actualBuildDefinition = actualBuildDefinitions.get( i );
1364             assertBuildDefinitionEquals( expectedBuildDefinition, actualBuildDefinition );
1365             assertScheduleEquals( expectedBuildDefinition.getSchedule(), actualBuildDefinition.getSchedule() );
1366             assertProfileEquals( expectedBuildDefinition.getProfile(), actualBuildDefinition.getProfile() );
1367         }
1368     }
1369 
1370     protected static void assertBuildDefinitionEquals( BuildDefinition expectedBuildDefinition,
1371                                                        BuildDefinition actualBuildDefinition )
1372     {
1373         assertEquals( "compare build definition - arguments", expectedBuildDefinition.getArguments(),
1374                       actualBuildDefinition.getArguments() );
1375         assertEquals( "compare build definition - build file", expectedBuildDefinition.getBuildFile(),
1376                       actualBuildDefinition.getBuildFile() );
1377         assertEquals( "compare build definition - goals", expectedBuildDefinition.getGoals(), actualBuildDefinition
1378             .getGoals() );
1379         assertEquals( "compare build definition - build fresh", expectedBuildDefinition.isBuildFresh(),
1380                       actualBuildDefinition.isBuildFresh() );
1381         assertEquals( "compare build definition - defaultForProject", expectedBuildDefinition.isDefaultForProject(),
1382                       actualBuildDefinition.isDefaultForProject() );
1383     }
1384 
1385     protected static void assertDevelopersEqual( List<ProjectDeveloper> expectedDevelopers,
1386                                                  List<ProjectDeveloper> actualDevelopers )
1387     {
1388         for ( int i = 0; i < actualDevelopers.size(); i++ )
1389         {
1390             assertDeveloperEquals( expectedDevelopers.get( i ), actualDevelopers
1391                 .get( i ) );
1392         }
1393     }
1394 
1395     protected static void assertDeveloperEquals( ProjectDeveloper expectedDeveloper, ProjectDeveloper actualDeveloper )
1396     {
1397         assertEquals( "compare developer - name", expectedDeveloper.getName(), actualDeveloper.getName() );
1398         assertEquals( "compare developer - email", expectedDeveloper.getEmail(), actualDeveloper.getEmail() );
1399         assertEquals( "compare developer - scmId", expectedDeveloper.getScmId(), actualDeveloper.getScmId() );
1400         assertEquals( "compare developer - continuumId", expectedDeveloper.getContinuumId(), actualDeveloper
1401             .getContinuumId() );
1402     }
1403 
1404     protected static void assertDependenciesEqual( List<ProjectDependency> expectedDependencies,
1405                                                    List<ProjectDependency> actualDependencies )
1406     {
1407         for ( int i = 0; i < actualDependencies.size(); i++ )
1408         {
1409             assertDependencyEquals( expectedDependencies.get( i ), actualDependencies.get( i ) );
1410         }
1411     }
1412 
1413     protected static void assertDependencyEquals( ProjectDependency expectedDependency,
1414                                                   ProjectDependency actualDependency )
1415     {
1416         assertEquals( "compare dependency - groupId", expectedDependency.getGroupId(), actualDependency.getGroupId() );
1417         assertEquals( "compare dependency - artifactId", expectedDependency.getArtifactId(), actualDependency
1418             .getArtifactId() );
1419         assertEquals( "compare dependency - version", expectedDependency.getVersion(), actualDependency.getVersion() );
1420     }
1421 
1422     protected static ProjectDependency createTestDependency( ProjectDependency dependency )
1423     {
1424         return createTestDependency( dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion() );
1425     }
1426 
1427     protected static ProjectDeveloper createTestDeveloper( ProjectDeveloper developer )
1428     {
1429         return createTestDeveloper( developer.getContinuumId(), developer.getEmail(), developer.getName(), developer
1430             .getScmId() );
1431     }
1432 
1433     protected static ProjectDependency createTestDependency( String groupId, String artifactId, String version )
1434     {
1435         ProjectDependency dependency = new ProjectDependency();
1436         dependency.setArtifactId( artifactId );
1437         dependency.setGroupId( groupId );
1438         dependency.setVersion( version );
1439         return dependency;
1440     }
1441 
1442     protected static ProjectDeveloper createTestDeveloper( int continuumId, String email, String name, String scmId )
1443     {
1444         ProjectDeveloper developer = new ProjectDeveloper();
1445         developer.setContinuumId( continuumId );
1446         developer.setEmail( email );
1447         developer.setName( name );
1448         developer.setScmId( scmId );
1449         return developer;
1450     }
1451 
1452     protected static LocalRepository createTestLocalRepository( LocalRepository repository )
1453     {
1454         return createTestLocalRepository( repository.getName(), repository.getLocation(), repository.getLayout() );
1455     }
1456 
1457     protected static LocalRepository createTestLocalRepository( String name, String location, String layout )
1458     {
1459         LocalRepository repository = new LocalRepository();
1460         repository.setName( name );
1461         repository.setLocation( location );
1462         repository.setLayout( layout );
1463         return repository;
1464     }
1465 
1466     protected static RepositoryPurgeConfiguration createTestRepositoryPurgeConfiguration(
1467         RepositoryPurgeConfiguration purgeConfig )
1468     {
1469         return createTestRepositoryPurgeConfiguration( purgeConfig.isDeleteAll(), purgeConfig.getRetentionCount(),
1470                                                        purgeConfig.getDaysOlder(),
1471                                                        purgeConfig.isDeleteReleasedSnapshots(),
1472                                                        purgeConfig.getSchedule(), purgeConfig.isEnabled(),
1473                                                        purgeConfig.getRepository() );
1474     }
1475 
1476     protected static RepositoryPurgeConfiguration createTestRepositoryPurgeConfiguration( boolean deleteAllArtifacts,
1477                                                                                           int retentionCount,
1478                                                                                           int daysOlder,
1479                                                                                           boolean deleteReleasedSnapshots,
1480                                                                                           Schedule schedule,
1481                                                                                           boolean enabled,
1482                                                                                           LocalRepository repository )
1483     {
1484         RepositoryPurgeConfiguration purgeConfig = new RepositoryPurgeConfiguration();
1485         purgeConfig.setDeleteAll( deleteAllArtifacts );
1486         purgeConfig.setEnabled( enabled );
1487         purgeConfig.setRetentionCount( retentionCount );
1488         purgeConfig.setDaysOlder( daysOlder );
1489         purgeConfig.setDeleteReleasedSnapshots( deleteReleasedSnapshots );
1490         purgeConfig.setSchedule( schedule );
1491         purgeConfig.setRepository( repository );
1492         return purgeConfig;
1493     }
1494 
1495     protected static DirectoryPurgeConfiguration createTestDirectoryPurgeConfiguration(
1496         DirectoryPurgeConfiguration purgeConfig )
1497     {
1498         return createTestDirectoryPurgeConfiguration( purgeConfig.getLocation(), purgeConfig.getDirectoryType(),
1499                                                       purgeConfig.isDeleteAll(), purgeConfig.getRetentionCount(),
1500                                                       purgeConfig.getDaysOlder(), purgeConfig.getSchedule(),
1501                                                       purgeConfig.isEnabled() );
1502     }
1503 
1504     protected static DirectoryPurgeConfiguration createTestDirectoryPurgeConfiguration( String location,
1505                                                                                         String directoryType,
1506                                                                                         boolean deleteAllDirectories,
1507                                                                                         int retentionCount,
1508                                                                                         int daysOlder,
1509                                                                                         Schedule schedule,
1510                                                                                         boolean enabled )
1511     {
1512         DirectoryPurgeConfiguration purgeConfig = new DirectoryPurgeConfiguration();
1513         purgeConfig.setDaysOlder( daysOlder );
1514         purgeConfig.setDeleteAll( deleteAllDirectories );
1515         purgeConfig.setDirectoryType( directoryType );
1516         purgeConfig.setEnabled( enabled );
1517         purgeConfig.setLocation( location );
1518         purgeConfig.setRetentionCount( retentionCount );
1519         purgeConfig.setSchedule( schedule );
1520         return purgeConfig;
1521     }
1522 
1523     protected static void assertLocalRepositoryEquals( LocalRepository expectedRepository,
1524                                                        LocalRepository actualRepository )
1525     {
1526         assertEquals( expectedRepository, actualRepository );
1527         if ( expectedRepository != null )
1528         {
1529             assertNotSame( expectedRepository, actualRepository );
1530             assertEquals( "compare local repository - id", expectedRepository.getId(), actualRepository.getId() );
1531             assertEquals( "compare local repository - name", expectedRepository.getName(), actualRepository.getName() );
1532             assertEquals( "compare local repository - location", expectedRepository.getLocation(),
1533                           actualRepository.getLocation() );
1534             assertEquals( "compare local repository - layout", expectedRepository.getLayout(),
1535                           actualRepository.getLayout() );
1536         }
1537     }
1538 
1539     protected static void assertRepositoryPurgeConfigurationEquals( RepositoryPurgeConfiguration expectedConfig,
1540                                                                     RepositoryPurgeConfiguration actualConfig )
1541     {
1542         assertEquals( "compare repository purge configuration - id", expectedConfig.getId(), actualConfig.getId() );
1543         assertEquals( "compare repository purge configuration - deleteAll", expectedConfig.isDeleteAll(),
1544                       actualConfig.isDeleteAll() );
1545         assertEquals( "compare repository purge configuration - retentionCount", expectedConfig.getRetentionCount(),
1546                       actualConfig.getRetentionCount() );
1547         assertEquals( "compare repository purge configuration - daysOlder", expectedConfig.getDaysOlder(),
1548                       actualConfig.getDaysOlder() );
1549         assertEquals( "compare repository purge configuration - deleteReleasedSnapshots",
1550                       expectedConfig.isDeleteReleasedSnapshots(), actualConfig.isDeleteReleasedSnapshots() );
1551         assertEquals( "compare repository purge configuration - enabled", expectedConfig.isEnabled(),
1552                       actualConfig.isEnabled() );
1553     }
1554 
1555     protected static void assertDirectoryPurgeConfigurationEquals( DirectoryPurgeConfiguration expectedConfig,
1556                                                                    DirectoryPurgeConfiguration actualConfig )
1557     {
1558         assertEquals( "compare directory purge configuration - id", expectedConfig.getId(), actualConfig.getId() );
1559         assertEquals( "compare directory purge configuration - location", expectedConfig.getLocation(),
1560                       actualConfig.getLocation() );
1561         assertEquals( "compare directory purge configuration - directoryType", expectedConfig.getDirectoryType(),
1562                       actualConfig.getDirectoryType() );
1563         assertEquals( "compare directory purge configuration - deleteAll", expectedConfig.isDeleteAll(),
1564                       actualConfig.isDeleteAll() );
1565         assertEquals( "compare directory purge configuration - retentionCount", expectedConfig.getRetentionCount(),
1566                       actualConfig.getRetentionCount() );
1567         assertEquals( "compare directory purge configuration - daysOlder", expectedConfig.getDaysOlder(),
1568                       actualConfig.getDaysOlder() );
1569         assertEquals( "compare directory purge configuration - enabled", expectedConfig.isEnabled(),
1570                       actualConfig.isEnabled() );
1571     }
1572     
1573     protected static ProjectScmRoot createTestProjectScmRoot( String scmRootAddress, int state, int oldState,
1574                                                               String error, ProjectGroup group )
1575     {
1576         ProjectScmRoot projectScmRoot = new ProjectScmRoot();
1577         
1578         projectScmRoot.setScmRootAddress( scmRootAddress );
1579         projectScmRoot.setState( state );
1580         projectScmRoot.setOldState( oldState );
1581         projectScmRoot.setError( error );
1582         projectScmRoot.setProjectGroup( group );
1583         
1584         return projectScmRoot;
1585     }
1586 
1587     protected static ProjectScmRoot createTestProjectScmRoot( ProjectScmRoot scmRoot )
1588     {
1589         return createTestProjectScmRoot( scmRoot.getScmRootAddress(), scmRoot.getState(), scmRoot.getOldState(), 
1590                                          scmRoot.getError(), scmRoot.getProjectGroup() );
1591     }
1592 
1593     protected static void assertProjectScmRootEquals( ProjectScmRoot expectedConfig, ProjectScmRoot actualConfig )
1594     {
1595         assertEquals( "compare project scm root - id", expectedConfig.getId(), actualConfig.getId() );
1596         assertEquals( "compare project scm root - scmUrl", expectedConfig.getScmRootAddress(), 
1597                                                            actualConfig.getScmRootAddress() );
1598         assertEquals( "compare project scm root - state", expectedConfig.getState(), actualConfig.getState() );
1599         assertEquals( "compare project scm root - oldState", expectedConfig.getOldState(), actualConfig.getOldState() );
1600         assertEquals( "compare project scm root - error", expectedConfig.getError(), actualConfig.getError() );
1601     }
1602 
1603     protected static ContinuumReleaseResult createTestContinuumReleaseResult( ProjectGroup group, Project project, 
1604                                                                               String releaseGoal, int resultCode,
1605                                                                               long startTime, long endTime )
1606     {
1607         ContinuumReleaseResult releaseResult = new ContinuumReleaseResult();
1608         releaseResult.setProjectGroup( group );
1609         releaseResult.setProject( project );
1610         releaseResult.setReleaseGoal( releaseGoal );
1611         releaseResult.setResultCode( resultCode );
1612         releaseResult.setStartTime( startTime );
1613         releaseResult.setEndTime( endTime );
1614         
1615         return releaseResult;
1616     }
1617 
1618     protected static ContinuumReleaseResult createTestContinuumReleaseResult( ContinuumReleaseResult releaseResult )
1619     {
1620         return createTestContinuumReleaseResult( releaseResult.getProjectGroup(), releaseResult.getProject(), 
1621                                                  releaseResult.getReleaseGoal(), releaseResult.getResultCode(),
1622                                                  releaseResult.getStartTime(), releaseResult.getEndTime() );
1623     }
1624 
1625     protected static void assertReleaseResultEquals( ContinuumReleaseResult expectedConfig, 
1626                                                      ContinuumReleaseResult actualConfig )
1627     {
1628         assertEquals( "compare continuum release result - id", expectedConfig.getId(), actualConfig.getId() );
1629         assertEquals( "compare continuum release result - releaseGoal", expectedConfig.getReleaseGoal(),
1630                       actualConfig.getReleaseGoal() );
1631         assertEquals( "compare continuum release result - resultCode", expectedConfig.getResultCode(), 
1632                       actualConfig.getResultCode() );
1633         assertEquals( "compare continuum release result - startTime", expectedConfig.getStartTime(), 
1634                       actualConfig.getStartTime() );
1635         assertEquals( "compare continuum release result - endTime", expectedConfig.getEndTime(),
1636                       actualConfig.getEndTime() );
1637     }
1638 
1639     protected static BuildQueue createTestBuildQueue( String name )
1640     {
1641         BuildQueue buildQueue = new BuildQueue();
1642         buildQueue.setName( name );
1643 
1644         return buildQueue;
1645     }
1646 
1647     protected static BuildQueue createTestBuildQueue( BuildQueue buildQueue )
1648     {
1649         return createTestBuildQueue( buildQueue.getName() );
1650     }
1651 
1652     protected static void assertBuildQueueEquals( BuildQueue expectedConfig, BuildQueue actualConfig )
1653     {
1654         assertEquals( "compare build queue - id", expectedConfig.getId(), actualConfig.getId() );
1655         assertEquals( "compare build queue - name", expectedConfig.getName(), actualConfig.getName() );
1656     }
1657 
1658     protected static BuildDefinitionTemplate createTestBuildDefinitionTemplate( String name, String type, boolean continuumDefault )
1659     {
1660         BuildDefinitionTemplate template = new BuildDefinitionTemplate();
1661         template.setName( name );
1662         template.setType( type );
1663         template.setContinuumDefault( continuumDefault );
1664 
1665         return template;
1666     }
1667 
1668     /**
1669      * Setup JDO Factory
1670      *
1671      * @todo push down to a Jdo specific test
1672      */
1673     protected void createStore()
1674         throws Exception
1675     {
1676         DefaultConfigurableJdoFactory jdoFactory =
1677             (DefaultConfigurableJdoFactory) lookup( JdoFactory.ROLE, "continuum" );
1678 
1679         jdoFactory.setUrl( "jdbc:hsqldb:mem:" + getName() );
1680 
1681         daoUtilsImpl = (DaoUtils) lookup( DaoUtils.class.getName() );
1682     }
1683 }