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