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.BuildDefinitionDao;
23  import org.apache.continuum.dao.BuildDefinitionTemplateDao;
24  import org.apache.continuum.dao.BuildResultDao;
25  import org.apache.continuum.model.project.ProjectGroupSummary;
26  import org.apache.continuum.model.project.ProjectScmRoot;
27  import org.apache.continuum.model.release.ContinuumReleaseResult;
28  import org.apache.continuum.model.repository.DirectoryPurgeConfiguration;
29  import org.apache.continuum.model.repository.LocalRepository;
30  import org.apache.continuum.model.repository.RepositoryPurgeConfiguration;
31  import org.apache.maven.continuum.execution.ContinuumBuildExecutorConstants;
32  import org.apache.maven.continuum.installation.InstallationService;
33  import org.apache.maven.continuum.model.project.BuildDefinition;
34  import org.apache.maven.continuum.model.project.BuildDefinitionTemplate;
35  import org.apache.maven.continuum.model.project.BuildQueue;
36  import org.apache.maven.continuum.model.project.BuildResult;
37  import org.apache.maven.continuum.model.project.Project;
38  import org.apache.maven.continuum.model.project.ProjectDependency;
39  import org.apache.maven.continuum.model.project.ProjectDeveloper;
40  import org.apache.maven.continuum.model.project.ProjectGroup;
41  import org.apache.maven.continuum.model.project.ProjectNotifier;
42  import org.apache.maven.continuum.model.project.Schedule;
43  import org.apache.maven.continuum.model.system.Installation;
44  import org.apache.maven.continuum.model.system.Profile;
45  
46  import java.util.ArrayList;
47  import java.util.Arrays;
48  import java.util.Calendar;
49  import java.util.Collection;
50  import java.util.Date;
51  import java.util.Iterator;
52  import java.util.List;
53  import java.util.Map;
54  import javax.jdo.JDODetachedFieldAccessException;
55  
56  /**
57   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
58   * @version $Id: ContinuumStoreTest.java 1372260 2012-08-13 04:29:09Z brett $
59   * @todo I think this should have all the JDO stuff from the abstract test, and the abstract test
60   * should use a mock continuum store with the exception of the integration tests which should be
61   * running against a fully deployed plexus application instead
62   * @todo review for ambiguities and ensure it is all encapsulated in the store, otherwise the code may make the same mistake about not deleting things, etc
63   */
64  public class ContinuumStoreTest
65      extends AbstractContinuumStoreTestCase
66  {
67      private static final int INVALID_ID = 15000;
68  
69      private BuildDefinitionTemplateDao buildDefinitionTemplateDao;
70  
71      protected BuildDefinitionDao buildDefinitionDao;
72  
73      protected BuildResultDao buildResultDao;
74  
75      // ----------------------------------------------------------------------
76      //  TEST METHODS
77      // ----------------------------------------------------------------------
78  
79      public void testAddProjectGroup()
80          throws ContinuumStoreException
81      {
82          String name = "testAddProjectGroup";
83          String description = "testAddProjectGroup description";
84          String groupId = "org.apache.maven.continuum.test";
85          LocalRepository repository = localRepositoryDao.getLocalRepository( testLocalRepository3.getId() );
86          ProjectGroup group = createTestProjectGroup( name, description, groupId, repository );
87  
88          ProjectGroup copy = createTestProjectGroup( group );
89          projectGroupDao.addProjectGroup( group );
90          copy.setId( group.getId() );
91  
92          ProjectGroup retrievedGroup = projectGroupDao.getProjectGroup( group.getId() );
93          assertProjectGroupEquals( copy, retrievedGroup );
94          assertLocalRepositoryEquals( testLocalRepository3, retrievedGroup.getLocalRepository() );
95      }
96  
97      public void testGetProjectGroup()
98          throws ContinuumStoreException
99      {
100         ProjectGroup retrievedGroup = projectGroupDao.getProjectGroupWithProjects( defaultProjectGroup.getId() );
101         assertProjectGroupEquals( defaultProjectGroup, retrievedGroup );
102         assertLocalRepositoryEquals( testLocalRepository1, retrievedGroup.getLocalRepository() );
103 
104         List<Project> projects = retrievedGroup.getProjects();
105         assertEquals( "Check number of projects", 2, projects.size() );
106         assertTrue( "Check existence of project 1", projects.contains( testProject1 ) );
107         assertTrue( "Check existence of project 2", projects.contains( testProject2 ) );
108 
109         checkProjectGroupDefaultFetchGroup( retrievedGroup );
110 
111         Project project = projects.get( 0 );
112         checkProjectDefaultFetchGroup( project );
113         //assertSame( "Check project group reference matches", project.getProjectGroup(), retrievedGroup );
114         assertEquals( project.getProjectGroup().getId(), retrievedGroup.getId() );
115         assertProjectEquals( testProject1, project );
116 
117         project = projects.get( 1 );
118         checkProjectDefaultFetchGroup( project );
119         //assertSame( "Check project group reference matches", project.getProjectGroup(), retrievedGroup );
120         assertEquals( project.getProjectGroup().getId(), retrievedGroup.getId() );
121         assertProjectEquals( testProject2, project );
122     }
123 
124     public void testGetInvalidProjectGroup()
125         throws ContinuumStoreException
126     {
127         try
128         {
129             projectGroupDao.getProjectGroup( INVALID_ID );
130             fail( "Should not find group with invalid ID" );
131         }
132         catch ( ContinuumObjectNotFoundException expected )
133         {
134             assertTrue( true );
135         }
136     }
137 
138     public void testEditProjectGroup()
139         throws ContinuumStoreException
140     {
141         ProjectGroup newGroup = projectGroupDao.getProjectGroup( testProjectGroup2.getId() );
142 
143         newGroup.setName( "testEditProjectGroup2" );
144         newGroup.setDescription( "testEditProjectGroup updated description" );
145         newGroup.setGroupId( "org.apache.maven.continuum.test.new" );
146 
147         ProjectGroup copy = createTestProjectGroup( newGroup );
148         copy.setId( newGroup.getId() );
149         projectGroupDao.updateProjectGroup( newGroup );
150 
151         ProjectGroup retrievedGroup = projectGroupDao.getProjectGroup( testProjectGroup2.getId() );
152         assertProjectGroupEquals( copy, retrievedGroup );
153         assertLocalRepositoryEquals( testLocalRepository2, retrievedGroup.getLocalRepository() );
154     }
155 
156     public void testUpdateUndetachedGroup()
157     {
158         ProjectGroup newGroup = new ProjectGroup();
159         newGroup.setId( testProjectGroup2.getId() );
160         newGroup.setName( "testUpdateUndetachedGroup2" );
161         newGroup.setDescription( "testUpdateUndetachedGroup updated description" );
162         newGroup.setGroupId( "org.apache.maven.continuum.test.new" );
163 
164         try
165         {
166             projectGroupDao.updateProjectGroup( newGroup );
167             fail( "Should not have succeeded" );
168         }
169         catch ( ContinuumStoreException expected )
170         {
171             // good!
172             assertTrue( true );
173         }
174     }
175 
176     public void testGetAllProjectGroups()
177     {
178         Collection<ProjectGroup> groups = projectGroupDao.getAllProjectGroupsWithProjects();
179 
180         assertEquals( "check size", 2, groups.size() );
181         assertTrue( groups.contains( defaultProjectGroup ) );
182         assertTrue( groups.contains( testProjectGroup2 ) );
183 
184         for ( ProjectGroup group : groups )
185         {
186             List<Project> projects = group.getProjects();
187             if ( group.getId() == testProjectGroup2.getId() )
188             {
189                 assertProjectGroupEquals( testProjectGroup2, group );
190                 assertLocalRepositoryEquals( testLocalRepository2, group.getLocalRepository() );
191                 assertTrue( "check no projects", projects.isEmpty() );
192             }
193             else if ( group.getId() == defaultProjectGroup.getId() )
194             {
195                 assertProjectGroupEquals( defaultProjectGroup, group );
196                 assertLocalRepositoryEquals( testLocalRepository1, group.getLocalRepository() );
197                 assertEquals( "Check number of projects", 2, projects.size() );
198                 assertTrue( "Check existence of project 1", projects.contains( testProject1 ) );
199                 assertTrue( "Check existence of project 2", projects.contains( testProject2 ) );
200 
201                 checkProjectGroupDefaultFetchGroup( group );
202 
203                 Project p = projects.get( 0 );
204                 checkProjectDefaultFetchGroup( p );
205                 assertSame( "Check project group reference matches", p.getProjectGroup(), group );
206             }
207         }
208     }
209 
210     public void testGetProject()
211         throws ContinuumStoreException
212     {
213         Project retrievedProject = projectDao.getProject( testProject1.getId() );
214         assertProjectEquals( testProject1, retrievedProject );
215         checkProjectDefaultFetchGroup( retrievedProject );
216     }
217 
218     public void testGetProjectWithDetails()
219         throws ContinuumStoreException
220     {
221         Project retrievedProject = projectDao.getProjectWithAllDetails( testProject1.getId() );
222         assertProjectEquals( testProject1, retrievedProject );
223         checkProjectFetchGroup( retrievedProject, false, false, true, true );
224 
225         assertBuildDefinitionsEqual( retrievedProject.getBuildDefinitions(), testProject1.getBuildDefinitions() );
226         assertNotifiersEqual( testProject1.getNotifiers(), retrievedProject.getNotifiers() );
227         assertDevelopersEqual( testProject1.getDevelopers(), retrievedProject.getDevelopers() );
228         assertDependenciesEqual( testProject1.getDependencies(), retrievedProject.getDependencies() );
229     }
230 
231     public void testGetProjectWithCheckoutResult()
232         throws ContinuumStoreException
233     {
234         Project retrievedProject = projectDao.getProjectWithCheckoutResult( testProject1.getId() );
235         assertProjectEquals( testProject1, retrievedProject );
236         assertScmResultEquals( testCheckoutResult1, retrievedProject.getCheckoutResult() );
237         checkProjectFetchGroup( retrievedProject, true, false, false, false );
238     }
239 
240     public void testGetInvalidProject()
241         throws ContinuumStoreException
242     {
243         try
244         {
245             projectDao.getProject( INVALID_ID );
246             fail( "Should not find project with invalid ID" );
247         }
248         catch ( ContinuumObjectNotFoundException expected )
249         {
250             assertTrue( true );
251         }
252     }
253 
254     public void testEditProject()
255         throws ContinuumStoreException
256     {
257         Project newProject = projectDao.getProject( testProject2.getId() );
258 
259         newProject.setName( "testEditProject2" );
260         newProject.setDescription( "testEditProject updated description" );
261         newProject.setGroupId( "org.apache.maven.continuum.test.new" );
262 
263         Project copy = createTestProject( newProject );
264         copy.setId( newProject.getId() );
265         projectDao.updateProject( newProject );
266 
267         Project retrievedProject = projectDao.getProject( testProject2.getId() );
268         assertProjectEquals( copy, retrievedProject );
269 
270     }
271 
272     public void testUpdateUndetachedProject()
273     {
274         Project newProject = new Project();
275         newProject.setId( testProject2.getId() );
276         newProject.setName( "testUpdateUndetached2" );
277         newProject.setDescription( "testUpdateUndetached updated description" );
278         newProject.setGroupId( "org.apache.maven.continuum.test.new" );
279 
280         try
281         {
282             projectDao.updateProject( newProject );
283             fail( "Should not have succeeded" );
284         }
285         catch ( ContinuumStoreException expected )
286         {
287             // good!
288             assertTrue( true );
289         }
290     }
291 
292     public void testGetAllProjects()
293     {
294         List<Project> projects = projectDao.getAllProjectsByName();
295         assertEquals( "check items", Arrays.asList( testProject1, testProject2 ), projects );
296 
297         Project project = projects.get( 1 );
298         assertProjectEquals( testProject2, project );
299         checkProjectDefaultFetchGroup( project );
300         assertNotNull( "Check project group reference matches", project.getProjectGroup() );
301     }
302 
303     public void testAddSchedule()
304         throws ContinuumStoreException
305     {
306         BuildQueue buildQueue = buildQueueDao.getAllBuildQueues().get( 0 );
307 
308         Schedule newSchedule = createTestSchedule( "testAddSchedule", "testAddSchedule desc", 10, "cron test", false );
309         newSchedule.addBuildQueue( buildQueue );
310 
311         Schedule copy = createTestSchedule( newSchedule );
312         scheduleDao.addSchedule( newSchedule );
313         copy.setId( newSchedule.getId() );
314 
315         List<Schedule> schedules = scheduleDao.getAllSchedulesByName();
316         Schedule retrievedSchedule = schedules.get( schedules.size() - 1 );
317         assertScheduleEquals( copy, retrievedSchedule );
318         assertEquals( "check size of build queues", 1, retrievedSchedule.getBuildQueues().size() );
319         assertBuildQueueEquals( buildQueue, retrievedSchedule.getBuildQueues().get( 0 ) );
320     }
321 
322     public void testEditSchedule()
323         throws ContinuumStoreException
324     {
325         Schedule newSchedule = scheduleDao.getAllSchedulesByName().get( 0 );
326         newSchedule.setName( "name1.1" );
327         newSchedule.setDescription( "testEditSchedule updated description" );
328 
329         assertEquals( "check size of build queues", 2, newSchedule.getBuildQueues().size() );
330         BuildQueue buildQueue1 = newSchedule.getBuildQueues().get( 0 );
331         BuildQueue buildQueue2 = newSchedule.getBuildQueues().get( 1 );
332 
333         Schedule copy = createTestSchedule( newSchedule );
334         copy.setId( newSchedule.getId() );
335         scheduleDao.updateSchedule( newSchedule );
336 
337         Schedule retrievedSchedule = scheduleDao.getAllSchedulesByName().get( 0 );
338         assertScheduleEquals( copy, retrievedSchedule );
339         assertBuildQueueEquals( buildQueue1, retrievedSchedule.getBuildQueues().get( 0 ) );
340         assertBuildQueueEquals( buildQueue2, retrievedSchedule.getBuildQueues().get( 1 ) );
341     }
342 
343     public void testRemoveSchedule()
344     {
345         Schedule schedule = scheduleDao.getAllSchedulesByName().get( 2 );
346 
347         // TODO: test if it has any attachments
348         assertEquals( "check size of build queues", 0, schedule.getBuildQueues().size() );
349         scheduleDao.removeSchedule( schedule );
350 
351         List<Schedule> schedules = scheduleDao.getAllSchedulesByName();
352         assertEquals( "check size", 2, schedules.size() );
353         assertFalse( "check not there", schedules.contains( schedule ) );
354     }
355 
356     public void testGetAllSchedules()
357         throws ContinuumStoreException
358     {
359         List<Schedule> schedules = scheduleDao.getAllSchedulesByName();
360         List<BuildQueue> buildQueues = buildQueueDao.getAllBuildQueues();
361 
362         assertEquals( "check item count", 3, schedules.size() );
363         assertEquals( "check build queues count", 3, buildQueues.size() );
364 
365         BuildQueue buildQueue1 = buildQueues.get( 0 );
366         BuildQueue buildQueue2 = buildQueues.get( 1 );
367         BuildQueue buildQueue3 = buildQueues.get( 2 );
368 
369         // check equality and order
370         Schedule schedule = schedules.get( 0 );
371         assertScheduleEquals( testSchedule1, schedule );
372         assertEquals( "check size of buildQueues", 2, schedule.getBuildQueues().size() );
373         assertBuildQueueEquals( buildQueue1, schedule.getBuildQueues().get( 0 ) );
374         assertBuildQueueEquals( buildQueue2, schedule.getBuildQueues().get( 1 ) );
375 
376         schedule = schedules.get( 1 );
377         assertScheduleEquals( testSchedule2, schedule );
378         assertEquals( "check size of buildQueues", 2, schedule.getBuildQueues().size() );
379         assertBuildQueueEquals( buildQueue2, schedule.getBuildQueues().get( 0 ) );
380         assertBuildQueueEquals( buildQueue3, schedule.getBuildQueues().get( 1 ) );
381 
382         schedule = schedules.get( 2 );
383         assertScheduleEquals( testSchedule3, schedule );
384         assertEquals( "check size of buildQueues", 0, schedule.getBuildQueues().size() );
385     }
386 
387     public void testAddProfile()
388         throws Exception
389     {
390         List<Installation> installations = installationDao.getAllInstallations();
391         Profile newProfile = createTestProfile( "testAddProfile", "testAddProfile desc", 5, false, false,
392                                                 installations.get( 1 ), installations.get( 2 ) );
393         Profile copy = createTestProfile( newProfile );
394         profileDao.addProfile( newProfile );
395         copy.setId( newProfile.getId() );
396 
397         List<Profile> profiles = profileDao.getAllProfilesByName();
398         Profile retrievedProfile = profiles.get( profiles.size() - 1 );
399         assertProfileEquals( copy, retrievedProfile );
400         assertInstallationEquals( testInstallationMaven20a3, retrievedProfile.getBuilder() );
401         assertInstallationEquals( testInstallationJava14, retrievedProfile.getJdk() );
402     }
403 
404     public void testEditProfile()
405         throws ContinuumStoreException
406     {
407         Profile newProfile = profileDao.getAllProfilesByName().get( 0 );
408         newProfile.setName( "name1.1" );
409         newProfile.setDescription( "testEditProfile updated description" );
410 
411         Profile copy = createTestProfile( newProfile );
412         copy.setId( newProfile.getId() );
413         profileDao.updateProfile( newProfile );
414 
415         Profile retrievedProfile = profileDao.getAllProfilesByName().get( 0 );
416         assertProfileEquals( copy, retrievedProfile );
417         assertInstallationEquals( copy.getBuilder(), retrievedProfile.getBuilder() );
418         assertInstallationEquals( copy.getJdk(), retrievedProfile.getJdk() );
419 
420     }
421 
422     public void testRemoveProfile()
423     {
424         Profile profile = profileDao.getAllProfilesByName().get( 2 );
425 
426         // TODO: test if it has any attachments
427 
428         profileDao.removeProfile( profile );
429 
430         List<Profile> profiles = profileDao.getAllProfilesByName();
431         assertEquals( "check size", 3, profiles.size() );
432         assertFalse( "check not there", profiles.contains( profile ) );
433     }
434 
435     public void testGetAllProfiles()
436     {
437         List<Profile> profiles = profileDao.getAllProfilesByName();
438 
439         assertEquals( "check item count", 4, profiles.size() );
440 
441         // check equality and order
442         Profile profile = profiles.get( 0 );
443         assertProfileEquals( testProfile1, profile );
444         assertInstallationEquals( testProfile1.getBuilder(), profile.getBuilder() );
445         assertInstallationEquals( testProfile1.getJdk(), profile.getJdk() );
446         profile = profiles.get( 1 );
447         assertProfileEquals( testProfile2, profile );
448         assertInstallationEquals( testProfile2.getBuilder(), profile.getBuilder() );
449         assertInstallationEquals( testProfile2.getJdk(), profile.getJdk() );
450         profile = profiles.get( 2 );
451         assertProfileEquals( testProfile3, profile );
452         assertInstallationEquals( testProfile3.getBuilder(), profile.getBuilder() );
453         assertInstallationEquals( testProfile3.getJdk(), profile.getJdk() );
454         profile = profiles.get( 3 );
455         assertProfileEquals( testProfile4, profile );
456         assertInstallationEquals( testProfile4.getBuilder(), profile.getBuilder() );
457         assertInstallationEquals( testProfile4.getJdk(), profile.getJdk() );
458         assertEquals( "check env var count", 1, profile.getEnvironmentVariables().size() );
459         assertInstallationEquals( testProfile4.getEnvironmentVariables().get( 0 ),
460                                   profile.getEnvironmentVariables().get( 0 ) );
461     }
462 
463     /*
464         public void testGetgetProfileByName()
465             throws ContinuumStoreException
466         {
467             Profile profile = store.getProfileByName( "name1" );
468             assertNotNull( profile );
469         }
470     */
471     public void testGetAllInstallations()
472         throws Exception
473     {
474         List<Installation> installations = installationDao.getAllInstallations();
475 
476         assertEquals( "check item count", 4, installations.size() );
477 
478         // check equality and order
479         Installation installation = installations.get( 0 );
480         assertInstallationEquals( testInstallationJava13, installation );
481         installation = installations.get( 1 );
482         assertInstallationEquals( testInstallationJava14, installation );
483         installation = installations.get( 2 );
484         assertInstallationEquals( testInstallationMaven20a3, installation );
485         installation = installations.get( 3 );
486         assertInstallationEquals( testInstallationEnvVar, installation );
487     }
488 
489     public void testUpdateInstallation()
490         throws Exception
491     {
492         String name = "installationTest";
493         Installation testOne = createTestInstallation( name, InstallationService.JDK_TYPE, "varName", "varValue" );
494         testOne = installationDao.addInstallation( testOne );
495 
496         Installation fromStore = installationDao.getInstallation( testOne.getInstallationId() );
497         assertInstallationEquals( testOne, fromStore );
498 
499         fromStore.setVarName( "JAVA_HOME" );
500         fromStore.setVarValue( "/usr/local/jdk1.5.0_08" );
501         installationDao.updateInstallation( fromStore );
502 
503         Installation updatedFromStore = installationDao.getInstallation( testOne.getInstallationId() );
504 
505         assertInstallationEquals( fromStore, updatedFromStore );
506     }
507 
508     public void testRemoveInstallation()
509         throws Exception
510     {
511         String name = "installationTestRemove";
512         Installation testOne = createTestInstallation( name, InstallationService.JDK_TYPE, "varName", "varValue" );
513         testOne = installationDao.addInstallation( testOne );
514 
515         installationDao.removeInstallation( testOne );
516         Installation fromStore = installationDao.getInstallation( testOne.getInstallationId() );
517         assertNull( fromStore );
518     }
519 
520     public void testRemoveLinkedInstallations()
521         throws Exception
522     {
523         String nameFirstInst = "linkedFirstInstallationTestRemove";
524         String nameSecondInst = "linkedSecondInstallationTestRemove";
525         String nameFirstEnvVar = "firstEnvVar";
526         String nameSecondEnvVar = "secondEnvVar";
527 
528         Installation testOne = createTestInstallation( nameFirstInst, InstallationService.JDK_TYPE, "varName",
529                                                        "varValue" );
530 
531         Installation testTwo = createTestInstallation( nameSecondInst, InstallationService.MAVEN2_TYPE, "varName",
532                                                        "varValue" );
533 
534         Installation firstEnvVar = createTestInstallation( nameFirstEnvVar, InstallationService.MAVEN2_TYPE, "varName",
535                                                            "varValue" );
536 
537         Installation secondEnvVar = createTestInstallation( nameSecondEnvVar, InstallationService.MAVEN2_TYPE,
538                                                             "varName", "varValue" );
539 
540         testOne = installationDao.addInstallation( testOne );
541         testTwo = installationDao.addInstallation( testTwo );
542 
543         firstEnvVar = installationDao.addInstallation( firstEnvVar );
544         secondEnvVar = installationDao.addInstallation( secondEnvVar );
545 
546         List<Installation> envVars = new ArrayList<Installation>( 2 );
547         envVars.add( firstEnvVar );
548         envVars.add( secondEnvVar );
549 
550         Profile firstProfile = createTestProfile( "first", "", 1, true, true, testOne, testTwo, envVars );
551 
552         Profile secondProfile = createTestProfile( "first", "", 1, true, true, testOne, testTwo, envVars );
553 
554         firstProfile = profileDao.addProfile( firstProfile );
555         secondProfile = profileDao.addProfile( secondProfile );
556 
557         Profile firstGetted = profileDao.getProfile( firstProfile.getId() );
558         Profile secondGetted = profileDao.getProfile( secondProfile.getId() );
559 
560         assertNotNull( firstGetted );
561         assertNotNull( firstGetted.getJdk() );
562         assertEquals( nameFirstInst, firstGetted.getJdk().getName() );
563 
564         assertNotNull( secondGetted );
565         assertNotNull( secondGetted.getJdk() );
566         assertEquals( nameFirstInst, secondGetted.getJdk().getName() );
567 
568         assertNotNull( firstGetted.getBuilder() );
569         assertEquals( nameSecondInst, firstGetted.getBuilder().getName() );
570         assertEquals( 2, firstGetted.getEnvironmentVariables().size() );
571 
572         assertNotNull( secondGetted.getBuilder() );
573         assertEquals( nameSecondInst, secondGetted.getBuilder().getName() );
574         assertEquals( 2, secondGetted.getEnvironmentVariables().size() );
575 
576         installationDao.removeInstallation( testOne );
577 
578         Installation fromStore = installationDao.getInstallation( testOne.getInstallationId() );
579         assertNull( fromStore );
580 
581         firstGetted = profileDao.getProfile( firstProfile.getId() );
582         secondGetted = profileDao.getProfile( secondProfile.getId() );
583         assertNotNull( firstGetted );
584         assertNull( firstGetted.getJdk() );
585         assertNotNull( firstGetted.getBuilder() );
586         assertEquals( 2, firstGetted.getEnvironmentVariables().size() );
587         assertNotNull( secondGetted );
588         assertNull( secondGetted.getJdk() );
589         assertNotNull( secondGetted.getBuilder() );
590         assertEquals( 2, secondGetted.getEnvironmentVariables().size() );
591         // removing builder
592         installationDao.removeInstallation( testTwo );
593 
594         firstGetted = profileDao.getProfile( firstProfile.getId() );
595         secondGetted = profileDao.getProfile( secondProfile.getId() );
596 
597         assertNotNull( firstGetted );
598         assertNull( firstGetted.getJdk() );
599         assertNull( firstGetted.getBuilder() );
600         assertEquals( 2, firstGetted.getEnvironmentVariables().size() );
601 
602         assertNotNull( secondGetted );
603         assertNull( secondGetted.getJdk() );
604         assertNull( secondGetted.getBuilder() );
605         assertEquals( 2, secondGetted.getEnvironmentVariables().size() );
606 
607         // removing firstEnvVar
608         installationDao.removeInstallation( firstEnvVar );
609         firstGetted = profileDao.getProfile( firstProfile.getId() );
610         secondGetted = profileDao.getProfile( secondProfile.getId() );
611         assertNotNull( firstGetted );
612         assertNull( firstGetted.getJdk() );
613         assertNull( firstGetted.getBuilder() );
614         assertEquals( 1, firstGetted.getEnvironmentVariables().size() );
615         Installation env = firstGetted.getEnvironmentVariables().get( 0 );
616         assertEquals( nameSecondEnvVar, env.getName() );
617 
618         assertNotNull( secondGetted );
619         assertNull( secondGetted.getJdk() );
620         assertNull( secondGetted.getBuilder() );
621         assertEquals( 1, secondGetted.getEnvironmentVariables().size() );
622         env = secondGetted.getEnvironmentVariables().get( 0 );
623         assertEquals( nameSecondEnvVar, env.getName() );
624 
625         // removing secondEnvVar
626         installationDao.removeInstallation( secondEnvVar );
627         firstGetted = profileDao.getProfile( firstProfile.getId() );
628         secondGetted = profileDao.getProfile( secondProfile.getId() );
629         assertNotNull( firstGetted );
630         assertNull( firstGetted.getJdk() );
631         assertNull( firstGetted.getBuilder() );
632         assertEquals( 0, firstGetted.getEnvironmentVariables().size() );
633 
634         assertNotNull( secondGetted );
635         assertNull( secondGetted.getJdk() );
636         assertNull( secondGetted.getBuilder() );
637         assertEquals( 0, secondGetted.getEnvironmentVariables().size() );
638     }
639 
640     public void testDeleteProject()
641         throws ContinuumStoreException
642     {
643         Project project = projectDao.getProjectWithBuilds( testProject1.getId() );
644 
645         projectDao.removeProject( project );
646 
647         ProjectGroup projectGroup = projectGroupDao.getProjectGroupWithProjects( defaultProjectGroup.getId() );
648         assertEquals( "check size is now 1", 1, projectGroup.getProjects().size() );
649         assertProjectEquals( testProject2, projectGroup.getProjects().get( 0 ) );
650 
651         confirmProjectDeletion( testProject1 );
652     }
653 
654     public void testDeleteProjectGroup()
655         throws ContinuumStoreException
656     {
657         projectGroupDao.removeProjectGroup( projectGroupDao.getProjectGroup( defaultProjectGroup.getId() ) );
658 
659         try
660         {
661             projectGroupDao.getProjectGroup( defaultProjectGroup.getId() );
662             fail( "Project group was not deleted" );
663         }
664         catch ( ContinuumObjectNotFoundException expected )
665         {
666             assertTrue( true );
667         }
668 
669         confirmProjectDeletion( testProject1 );
670         confirmProjectDeletion( testProject2 );
671         // TODO: test the project group's notifiers are physically deleted
672         // TODO: test the project group's build definitions are physically deleted
673     }
674 
675     public void testDeleteBuildResult()
676         throws ContinuumStoreException
677     {
678         Project project = projectDao.getProjectWithBuilds( testProject1.getId() );
679 
680         for ( Iterator<BuildResult> i = project.getBuildResults().iterator(); i.hasNext(); )
681         {
682             BuildResult result = i.next();
683             if ( result.getId() == testBuildResult1.getId() )
684             {
685                 i.remove();
686             }
687         }
688         projectDao.updateProject( project );
689 
690         project = projectDao.getProjectWithBuilds( testProject1.getId() );
691         assertEquals( "check size is now 1", 1, project.getBuildResults().size() );
692         assertBuildResultEquals( testBuildResult2, project.getBuildResults().get( 0 ) );
693 
694         List<BuildResult> results = buildResultDao.getAllBuildsForAProjectByDate( testProject1.getId() );
695         assertEquals( "check item count", 1, results.size() );
696         assertBuildResultEquals( testBuildResult2, results.get( 0 ) );
697 
698         // !! These actually aren't happening !!
699         // TODO: test the build result was physically deleted
700         // TODO: test the build result's SCM result was physically deleted
701         // TODO: test the build result's SCM result's change sets and change files were physically deleted
702     }
703 
704     public void testGetInvalidBuildResult()
705         throws ContinuumStoreException
706     {
707         try
708         {
709             buildResultDao.getBuildResult( INVALID_ID );
710             fail( "Should not find build result with invalid ID" );
711         }
712         catch ( ContinuumObjectNotFoundException expected )
713         {
714             assertTrue( true );
715         }
716     }
717 
718     public void testGetAllBuildsForAProject()
719     {
720         List<BuildResult> results = buildResultDao.getAllBuildsForAProjectByDate( testProject1.getId() );
721 
722         assertEquals( "check item count", 2, results.size() );
723 
724         // check equality and order
725         BuildResult buildResult = results.get( 0 );
726         assertBuildResultEquals( testBuildResult2, buildResult );
727         assertProjectEquals( testProject1, buildResult.getProject() );
728         //checkBuildResultDefaultFetchGroup( buildResult );
729         buildResult = results.get( 1 );
730         assertBuildResultEquals( testBuildResult1, buildResult );
731         assertProjectEquals( testProject1, buildResult.getProject() );
732         //checkBuildResultDefaultFetchGroup( buildResult );
733     }
734 
735     public void testGetBuildResult()
736         throws ContinuumStoreException
737     {
738         BuildResult buildResult = buildResultDao.getBuildResult( testBuildResult3.getId() );
739         assertBuildResultEquals( testBuildResult3, buildResult );
740         //assertScmResultEquals( testBuildResult3.getScmResult(), buildResult.getScmResult() );
741         assertProjectEquals( testProject2, buildResult.getProject() );
742         // TODO: reports, artifacts, data
743     }
744 
745     public void testGetProjectGroupWithDetails()
746         throws ContinuumStoreException
747     {
748         ProjectGroup retrievedGroup = projectGroupDao.getProjectGroupWithBuildDetailsByProjectGroupId(
749             defaultProjectGroup.getId() );
750         assertProjectGroupEquals( defaultProjectGroup, retrievedGroup );
751         assertNotifiersEqual( defaultProjectGroup.getNotifiers(), retrievedGroup.getNotifiers() );
752         assertBuildDefinitionsEqual( retrievedGroup.getBuildDefinitions(), defaultProjectGroup.getBuildDefinitions() );
753 
754         List<Project> projects = retrievedGroup.getProjects();
755         assertEquals( "Check number of projects", 2, projects.size() );
756 
757         Project project = projects.get( 0 );
758         checkProjectFetchGroup( project, false, false, true, false );
759         //assertSame( "Check project group reference matches", project.getProjectGroup(), retrievedGroup );
760         assertEquals( project.getProjectGroup().getId(), retrievedGroup.getId() );
761         assertProjectEquals( testProject1, project );
762         assertNotifiersEqual( testProject1.getNotifiers(), project.getNotifiers() );
763         assertBuildDefinitionsEqual( project.getBuildDefinitions(), testProject1.getBuildDefinitions() );
764 
765         project = projects.get( 1 );
766         checkProjectFetchGroup( project, false, false, true, false );
767         //assertSame( "Check project group reference matches", project.getProjectGroup(), retrievedGroup );
768         assertEquals( project.getProjectGroup().getId(), retrievedGroup.getId() );
769         assertProjectEquals( testProject2, project );
770         assertNotifiersEqual( testProject2.getNotifiers(), project.getNotifiers() );
771         assertBuildDefinitionsEqual( project.getBuildDefinitions(), testProject2.getBuildDefinitions() );
772     }
773 
774     public void testGetAllProjectsGroupWithDetails()
775     {
776         List<ProjectGroup> projectGroups = projectGroupDao.getAllProjectGroupsWithBuildDetails();
777         ProjectGroup group1 = projectGroups.get( 0 );
778         assertProjectGroupEquals( defaultProjectGroup, group1 );
779         assertNotifiersEqual( defaultProjectGroup.getNotifiers(), group1.getNotifiers() );
780         assertBuildDefinitionsEqual( group1.getBuildDefinitions(), defaultProjectGroup.getBuildDefinitions() );
781         ProjectGroup group2 = projectGroups.get( 1 );
782         assertProjectGroupEquals( testProjectGroup2, group2 );
783         assertNotifiersEqual( testProjectGroup2.getNotifiers(), group2.getNotifiers() );
784         assertBuildDefinitionsEqual( group2.getBuildDefinitions(), testProjectGroup2.getBuildDefinitions() );
785 
786         List<Project> projects = group1.getProjects();
787         assertEquals( "Check number of projects", 2, projects.size() );
788 
789         Project project = projects.get( 0 );
790         checkProjectFetchGroup( project, false, false, true, false );
791         assertSame( "Check project group reference matches", project.getProjectGroup(), group1 );
792         assertProjectEquals( testProject1, project );
793         assertNotifiersEqual( testProject1.getNotifiers(), project.getNotifiers() );
794         assertBuildDefinitionsEqual( project.getBuildDefinitions(), testProject1.getBuildDefinitions() );
795 
796         project = projects.get( 1 );
797         checkProjectFetchGroup( project, false, false, true, false );
798         assertSame( "Check project group reference matches", project.getProjectGroup(), group1 );
799         assertProjectEquals( testProject2, project );
800         assertNotifiersEqual( testProject2.getNotifiers(), project.getNotifiers() );
801         assertBuildDefinitionsEqual( project.getBuildDefinitions(), testProject2.getBuildDefinitions() );
802 
803         projects = group2.getProjects();
804         assertEquals( "Check number of projects", 0, projects.size() );
805     }
806 
807     public void testAddDeveloperToProject()
808         throws ContinuumStoreException
809     {
810         Project project = projectDao.getProjectWithAllDetails( testProject1.getId() );
811 
812         ProjectDeveloper developer = createTestDeveloper( 11, "email TADTP", "name TADTP", "scmId TADTP" );
813         ProjectDeveloper copy = createTestDeveloper( developer );
814         project.addDeveloper( developer );
815         projectDao.updateProject( project );
816 
817         project = projectDao.getProjectWithAllDetails( testProject1.getId() );
818         assertEquals( "check # devs", 2, project.getDevelopers().size() );
819         assertDeveloperEquals( copy, project.getDevelopers().get( 1 ) );
820     }
821 
822     public void testEditDeveloper()
823         throws ContinuumStoreException
824     {
825         Project project = projectDao.getProjectWithAllDetails( testProject1.getId() );
826 
827         ProjectDeveloper newDeveloper = project.getDevelopers().get( 0 );
828         newDeveloper.setName( "name1.1" );
829         newDeveloper.setEmail( "email1.1" );
830 
831         ProjectDeveloper copy = createTestDeveloper( newDeveloper );
832         projectDao.updateProject( project );
833 
834         project = projectDao.getProjectWithAllDetails( testProject1.getId() );
835         assertEquals( "check # devs", 1, project.getDevelopers().size() );
836         assertDeveloperEquals( copy, project.getDevelopers().get( 0 ) );
837     }
838 
839     public void testDeleteDeveloper()
840         throws ContinuumStoreException
841     {
842         Project project = projectDao.getProjectWithAllDetails( testProject1.getId() );
843         project.getDevelopers().remove( 0 );
844         projectDao.updateProject( project );
845 
846         project = projectDao.getProjectWithAllDetails( testProject1.getId() );
847         assertEquals( "check size is now 0", 0, project.getDevelopers().size() );
848 
849         // !! These actually aren't happening !!
850         // TODO: test the developer was physically deleted
851     }
852 
853     public void testAddDependencyToProject()
854         throws ContinuumStoreException
855     {
856         Project project = projectDao.getProjectWithAllDetails( testProject1.getId() );
857 
858         ProjectDependency dependency = createTestDependency( "TADTP groupId", "TADTP artifactId", "TADTP version" );
859         ProjectDependency copy = createTestDependency( dependency );
860         project.addDependency( dependency );
861         projectDao.updateProject( project );
862 
863         project = projectDao.getProjectWithAllDetails( testProject1.getId() );
864         assertEquals( "check # deps", 3, project.getDependencies().size() );
865         assertDependencyEquals( copy, project.getDependencies().get( 2 ) );
866     }
867 
868     public void testEditDependency()
869         throws ContinuumStoreException
870     {
871         Project project = projectDao.getProjectWithAllDetails( testProject1.getId() );
872 
873         ProjectDependency newDependency = project.getDependencies().get( 0 );
874         newDependency.setGroupId( "groupId1.1" );
875         newDependency.setArtifactId( "artifactId1.1" );
876 
877         ProjectDependency copy = createTestDependency( newDependency );
878         projectDao.updateProject( project );
879 
880         project = projectDao.getProjectWithAllDetails( testProject1.getId() );
881         assertEquals( "check # deps", 2, project.getDependencies().size() );
882         assertDependencyEquals( copy, project.getDependencies().get( 0 ) );
883     }
884 
885     public void testDeleteDependency()
886         throws ContinuumStoreException
887     {
888         Project project = projectDao.getProjectWithAllDetails( testProject1.getId() );
889         ProjectDependency dependency = project.getDependencies().get( 1 );
890         project.getDependencies().remove( 0 );
891         projectDao.updateProject( project );
892 
893         project = projectDao.getProjectWithAllDetails( testProject1.getId() );
894         assertEquals( "check size is now 1", 1, project.getDependencies().size() );
895         assertDependencyEquals( dependency, project.getDependencies().get( 0 ) );
896 
897         // !! These actually aren't happening !!
898         // TODO: test the dependency was physically deleted
899     }
900 
901     public void testAddNotifierToProject()
902         throws ContinuumStoreException
903     {
904         Project project = projectDao.getProjectWithAllDetails( testProject1.getId() );
905 
906         ProjectNotifier notifier = createTestNotifier( 13, true, false, true, "TADNTP type" );
907         ProjectNotifier copy = createTestNotifier( notifier );
908         project.addNotifier( notifier );
909         projectDao.updateProject( project );
910 
911         project = projectDao.getProjectWithAllDetails( testProject1.getId() );
912         assertEquals( "check # notifiers", 2, project.getNotifiers().size() );
913         assertNotifierEquals( copy, project.getNotifiers().get( 1 ) );
914     }
915 
916     public void testEditNotifier()
917         throws ContinuumStoreException
918     {
919         Project project = projectDao.getProjectWithAllDetails( testProject1.getId() );
920 
921         ProjectNotifier newNotifier = project.getNotifiers().get( 0 );
922         // If we use "type1.1", jpox-rc2 store "type11", weird
923         String type = "type11";
924         newNotifier.setType( type );
925 
926         ProjectNotifier copy = createTestNotifier( newNotifier );
927         projectDao.updateProject( project );
928 
929         project = projectDao.getProjectWithAllDetails( testProject1.getId() );
930         assertEquals( "check # notifiers", 1, project.getNotifiers().size() );
931         assertNotifierEquals( copy, project.getNotifiers().get( 0 ) );
932     }
933 
934     public void testDeleteNotifier()
935         throws ContinuumStoreException
936     {
937         Project project = projectDao.getProjectWithAllDetails( testProject1.getId() );
938         project.getNotifiers().remove( 0 );
939         projectDao.updateProject( project );
940 
941         project = projectDao.getProjectWithAllDetails( testProject1.getId() );
942         assertEquals( "check size is now 0", 0, project.getNotifiers().size() );
943 
944         // !! These actually aren't happening !!
945         // TODO: test the notifier was physically deleted
946     }
947 
948     public void testAddBuildDefinitionToProject()
949         throws ContinuumStoreException
950     {
951         Project project = projectDao.getProjectWithAllDetails( testProject1.getId() );
952 
953         Profile profile = profileDao.getProfile( testProfile1.getId() );
954         Schedule schedule = scheduleDao.getSchedule( testSchedule1.getId() );
955         BuildDefinition buildDefinition = createTestBuildDefinition( "TABDTP arguments", "TABDTP buildFile",
956                                                                      "TABDTP goals", profile, schedule, false, false );
957         BuildDefinition copy = createTestBuildDefinition( buildDefinition );
958         project.addBuildDefinition( buildDefinition );
959         projectDao.updateProject( project );
960 
961         project = projectDao.getProjectWithAllDetails( testProject1.getId() );
962         assertEquals( "check # build defs", 3, project.getBuildDefinitions().size() );
963         BuildDefinition retrievedBuildDefinition = project.getBuildDefinitions().get( 2 );
964         assertBuildDefinitionEquals( copy, retrievedBuildDefinition );
965         assertScheduleEquals( testSchedule1, retrievedBuildDefinition.getSchedule() );
966         assertProfileEquals( testProfile1, retrievedBuildDefinition.getProfile() );
967     }
968 
969     public void testEditBuildDefinition()
970         throws ContinuumStoreException
971     {
972         Project project = projectDao.getProjectWithAllDetails( testProject1.getId() );
973 
974         BuildDefinition newBuildDefinition = project.getBuildDefinitions().get( 0 );
975         newBuildDefinition.setBuildFresh( true );
976         new BuildDefinition().setDefaultForProject( true );
977         String arguments = "arguments1.1";
978         newBuildDefinition.setArguments( arguments );
979         BuildDefinition copy = createTestBuildDefinition( newBuildDefinition );
980         buildDefinitionDao.storeBuildDefinition( newBuildDefinition );
981 
982         project = projectDao.getProjectWithAllDetails( testProject1.getId() );
983         assertEquals( "check # build defs", 2, project.getBuildDefinitions().size() );
984         BuildDefinition retrievedBuildDefinition = project.getBuildDefinitions().get( 0 );
985 
986         assertBuildDefinitionEquals( copy, retrievedBuildDefinition );
987         assertScheduleEquals( testSchedule1, retrievedBuildDefinition.getSchedule() );
988         assertProfileEquals( testProfile2, retrievedBuildDefinition.getProfile() );
989     }
990 
991     public void testDeleteBuildDefinition()
992         throws ContinuumStoreException
993     {
994         Project project = projectDao.getProjectWithAllDetails( testProject1.getId() );
995         BuildDefinition buildDefinition = project.getBuildDefinitions().get( 1 );
996         project.getBuildDefinitions().remove( 0 );
997         projectDao.updateProject( project );
998 
999         project = projectDao.getProjectWithAllDetails( testProject1.getId() );
1000         assertEquals( "check size is now 1", 1, project.getBuildDefinitions().size() );
1001         BuildDefinition retrievedBuildDefinition = project.getBuildDefinitions().get( 0 );
1002         assertBuildDefinitionEquals( buildDefinition, retrievedBuildDefinition );
1003         assertScheduleEquals( testSchedule2, retrievedBuildDefinition.getSchedule() );
1004         assertProfileEquals( testProfile2, retrievedBuildDefinition.getProfile() );
1005 
1006         // !! These actually aren't happening !!
1007         // TODO: test the def was physically deleted
1008         // TODO: test the schedule/profile was NOT physically deleted
1009     }
1010 
1011     public void testAddNotifierToProjectGroup()
1012         throws ContinuumStoreException
1013     {
1014         ProjectGroup projectGroup = projectGroupDao.getProjectGroupWithBuildDetailsByProjectGroupId(
1015             defaultProjectGroup.getId() );
1016 
1017         ProjectNotifier notifier = createTestNotifier( 14, true, false, true, "TADNTPG type" );
1018         ProjectNotifier copy = createTestNotifier( notifier );
1019         projectGroup.addNotifier( notifier );
1020         projectGroupDao.updateProjectGroup( projectGroup );
1021 
1022         projectGroup = projectGroupDao.getProjectGroupWithBuildDetailsByProjectGroupId( defaultProjectGroup.getId() );
1023         assertEquals( "check # notifiers", 3, projectGroup.getNotifiers().size() );
1024         assertNotifierEquals( copy, projectGroup.getNotifiers().get( 2 ) );
1025     }
1026 
1027     public void testEditGroupNotifier()
1028         throws ContinuumStoreException
1029     {
1030         ProjectGroup projectGroup = projectGroupDao.getProjectGroupWithBuildDetailsByProjectGroupId(
1031             defaultProjectGroup.getId() );
1032 
1033         ProjectNotifier newNotifier = projectGroup.getNotifiers().get( 0 );
1034         // If we use "type1.1", jpox-rc2 store "type1", weird
1035         String type = "type1";
1036         newNotifier.setType( type );
1037 
1038         ProjectNotifier copy = createTestNotifier( newNotifier );
1039         projectGroupDao.updateProjectGroup( projectGroup );
1040 
1041         projectGroup = projectGroupDao.getProjectGroupWithBuildDetailsByProjectGroupId( defaultProjectGroup.getId() );
1042         assertEquals( "check # notifiers", 2, projectGroup.getNotifiers().size() );
1043         assertNotifierEquals( copy, projectGroup.getNotifiers().get( 0 ) );
1044     }
1045 
1046     public void testDeleteGroupNotifier()
1047         throws ContinuumStoreException
1048     {
1049         ProjectGroup projectGroup = projectGroupDao.getProjectGroupWithBuildDetailsByProjectGroupId(
1050             defaultProjectGroup.getId() );
1051         ProjectNotifier notifier = projectGroup.getNotifiers().get( 1 );
1052         projectGroup.getNotifiers().remove( 0 );
1053         projectGroupDao.updateProjectGroup( projectGroup );
1054 
1055         projectGroup = projectGroupDao.getProjectGroupWithBuildDetailsByProjectGroupId( defaultProjectGroup.getId() );
1056         assertEquals( "check size is now 1", 1, projectGroup.getNotifiers().size() );
1057         assertNotifierEquals( notifier, projectGroup.getNotifiers().get( 0 ) );
1058 
1059         // !! These actually aren't happening !!
1060         // TODO: test the notifier was physically deleted
1061     }
1062 
1063     public void testAddBuildDefinitionToProjectGroup()
1064         throws ContinuumStoreException
1065     {
1066         ProjectGroup projectGroup = projectGroupDao.getProjectGroupWithBuildDetailsByProjectGroupId(
1067             defaultProjectGroup.getId() );
1068 
1069         Profile profile = profileDao.getProfile( testProfile1.getId() );
1070         Schedule schedule = scheduleDao.getSchedule( testSchedule1.getId() );
1071         BuildDefinition buildDefinition = createTestBuildDefinition( "TABDTPG arguments", "TABDTPG buildFile",
1072                                                                      "TABDTPG goals", profile, schedule, false, false );
1073         BuildDefinition copy = createTestBuildDefinition( buildDefinition );
1074         projectGroup.addBuildDefinition( buildDefinition );
1075         projectGroupDao.updateProjectGroup( projectGroup );
1076 
1077         projectGroup = projectGroupDao.getProjectGroupWithBuildDetailsByProjectGroupId( defaultProjectGroup.getId() );
1078         assertEquals( "check # build defs", 2, projectGroup.getBuildDefinitions().size() );
1079         BuildDefinition retrievedBuildDefinition = projectGroup.getBuildDefinitions().get( 1 );
1080         assertBuildDefinitionEquals( copy, retrievedBuildDefinition );
1081         assertScheduleEquals( testSchedule1, retrievedBuildDefinition.getSchedule() );
1082         assertProfileEquals( testProfile1, retrievedBuildDefinition.getProfile() );
1083     }
1084 
1085     public void testEditGroupBuildDefinition()
1086         throws ContinuumStoreException
1087     {
1088         ProjectGroup projectGroup = projectGroupDao.getProjectGroupWithBuildDetailsByProjectGroupId(
1089             defaultProjectGroup.getId() );
1090 
1091         BuildDefinition newBuildDefinition = projectGroup.getBuildDefinitions().get( 0 );
1092 
1093         // If we use "arguments1.1", jpox-rc2 store "arguments11", weird
1094         String arguments = "arguments1";
1095         newBuildDefinition.setArguments( arguments );
1096 
1097         BuildDefinition copy = createTestBuildDefinition( newBuildDefinition );
1098         projectGroupDao.updateProjectGroup( projectGroup );
1099 
1100         projectGroup = projectGroupDao.getProjectGroupWithBuildDetailsByProjectGroupId( defaultProjectGroup.getId() );
1101         assertEquals( "check # build defs", 1, projectGroup.getBuildDefinitions().size() );
1102         BuildDefinition retrievedBuildDefinition = projectGroup.getBuildDefinitions().get( 0 );
1103         assertBuildDefinitionEquals( copy, retrievedBuildDefinition );
1104         assertScheduleEquals( testSchedule2, retrievedBuildDefinition.getSchedule() );
1105         assertProfileEquals( testProfile1, retrievedBuildDefinition.getProfile() );
1106     }
1107 
1108     public void testDeleteGroupBuildDefinition()
1109         throws ContinuumStoreException
1110     {
1111         ProjectGroup projectGroup = projectGroupDao.getProjectGroupWithBuildDetailsByProjectGroupId(
1112             defaultProjectGroup.getId() );
1113         projectGroup.getBuildDefinitions().remove( 0 );
1114         projectGroupDao.updateProjectGroup( projectGroup );
1115 
1116         projectGroup = projectGroupDao.getProjectGroupWithBuildDetailsByProjectGroupId( defaultProjectGroup.getId() );
1117         assertEquals( "check size is now 0", 0, projectGroup.getBuildDefinitions().size() );
1118 
1119         // !! These actually aren't happening !!
1120         // TODO: test the def was physically deleted
1121         // TODO: test the schedule/profile was NOT physically deleted
1122     }
1123 
1124     public void testgetTemplatesBuildDefinitions()
1125         throws Exception
1126     {
1127 
1128         int all = buildDefinitionDao.getAllBuildDefinitions().size();
1129         BuildDefinition buildDefinition = new BuildDefinition();
1130         buildDefinition.setBuildFile( "pom.xml" );
1131         buildDefinition.setGoals( "clean" );
1132         buildDefinition.setTemplate( true );
1133         BuildDefinitionTemplate template = new BuildDefinitionTemplate();
1134         template.setName( "test" );
1135         template.setContinuumDefault( true );
1136         template.setType( ContinuumBuildExecutorConstants.MAVEN_TWO_BUILD_EXECUTOR );
1137         template = buildDefinitionTemplateDao.addBuildDefinitionTemplate( template );
1138         buildDefinition = buildDefinitionDao.addBuildDefinition( buildDefinition );
1139 
1140         template.addBuildDefinition( buildDefinition );
1141 
1142         template = buildDefinitionTemplateDao.updateBuildDefinitionTemplate( template );
1143 
1144         assertEquals( "test", template.getName() );
1145         assertTrue( template.isContinuumDefault() );
1146         assertEquals( 1, template.getBuildDefinitions().size() );
1147         assertEquals( all + 1, buildDefinitionDao.getAllBuildDefinitions().size() );
1148         assertEquals( 2, buildDefinitionTemplateDao.getAllBuildDefinitionTemplate().size() );
1149 
1150         template = buildDefinitionTemplateDao.getContinuumBuildDefinitionTemplateWithType(
1151             ContinuumBuildExecutorConstants.MAVEN_TWO_BUILD_EXECUTOR );
1152 
1153         assertNotNull( template );
1154         assertEquals( 1, template.getBuildDefinitions().size() );
1155 
1156         assertEquals( 2, buildDefinitionTemplateDao.getAllBuildDefinitionTemplate().size() );
1157     }
1158 
1159     public void testAddLocalRepository()
1160         throws Exception
1161     {
1162         String name = "testAddLocalRepository";
1163         String directory = "testAddLocalRepositoryDirectory";
1164         String layout = "default";
1165 
1166         LocalRepository repository = createTestLocalRepository( name, directory, layout );
1167 
1168         LocalRepository copy = createTestLocalRepository( repository );
1169         localRepositoryDao.addLocalRepository( repository );
1170         copy.setId( repository.getId() );
1171 
1172         LocalRepository retrievedRepository = localRepositoryDao.getLocalRepository( repository.getId() );
1173         assertLocalRepositoryEquals( copy, retrievedRepository );
1174     }
1175 
1176     public void testRemoveLocalRepository()
1177         throws Exception
1178     {
1179         LocalRepository repository = localRepositoryDao.getLocalRepositoryByName( testLocalRepository2.getName() );
1180 
1181         ProjectGroup projectGroup = projectGroupDao.getProjectGroupByGroupId( testProjectGroup2.getGroupId() );
1182         assertLocalRepositoryEquals( testLocalRepository2, projectGroup.getLocalRepository() );
1183         projectGroup.setLocalRepository( null );
1184 
1185         projectGroupDao.updateProjectGroup( projectGroup );
1186 
1187         projectGroup = projectGroupDao.getProjectGroup( testProjectGroup2.getId() );
1188         assertNull( "check local repository", projectGroup.getLocalRepository() );
1189 
1190         List<RepositoryPurgeConfiguration> repoPurgeList =
1191             repositoryPurgeConfigurationDao.getRepositoryPurgeConfigurationsByLocalRepository( repository.getId() );
1192 
1193         assertEquals( "check # repo purge config", 1, repoPurgeList.size() );
1194         repositoryPurgeConfigurationDao.removeRepositoryPurgeConfiguration( repoPurgeList.get( 0 ) );
1195         localRepositoryDao.removeLocalRepository( repository );
1196 
1197         List<LocalRepository> localRepositories = localRepositoryDao.getAllLocalRepositories();
1198         assertEquals( "check # local repositories", 2, localRepositories.size() );
1199         assertFalse( "check not there", localRepositories.contains( repository ) );
1200     }
1201 
1202     public void testGetAllLocalRepositories()
1203         throws Exception
1204     {
1205         List<LocalRepository> localRepositories = localRepositoryDao.getAllLocalRepositories();
1206 
1207         assertEquals( "check # local repositories", 3, localRepositories.size() );
1208         assertLocalRepositoryEquals( testLocalRepository1, localRepositories.get( 0 ) );
1209         assertLocalRepositoryEquals( testLocalRepository2, localRepositories.get( 1 ) );
1210         assertLocalRepositoryEquals( testLocalRepository3, localRepositories.get( 2 ) );
1211     }
1212 
1213     public void testAddRepositoryPurgeConfiguration()
1214         throws Exception
1215     {
1216         LocalRepository repository = localRepositoryDao.getLocalRepository( testLocalRepository3.getId() );
1217         Schedule schedule = scheduleDao.getSchedule( testSchedule1.getId() );
1218 
1219         RepositoryPurgeConfiguration repoPurge = createTestRepositoryPurgeConfiguration( true, 2, 100, false, schedule,
1220                                                                                          true, repository );
1221 
1222         RepositoryPurgeConfiguration copy = createTestRepositoryPurgeConfiguration( repoPurge );
1223         repositoryPurgeConfigurationDao.addRepositoryPurgeConfiguration( repoPurge );
1224         copy.setId( repoPurge.getId() );
1225 
1226         RepositoryPurgeConfiguration retrieved = repositoryPurgeConfigurationDao.getRepositoryPurgeConfiguration(
1227             repoPurge.getId() );
1228         assertRepositoryPurgeConfigurationEquals( copy, retrieved );
1229         assertLocalRepositoryEquals( testLocalRepository3, retrieved.getRepository() );
1230         assertScheduleEquals( testSchedule1, retrieved.getSchedule() );
1231     }
1232 
1233     public void testRemoveRepositoryPurgeConfiguration()
1234         throws Exception
1235     {
1236         RepositoryPurgeConfiguration repoPurge = repositoryPurgeConfigurationDao.getRepositoryPurgeConfiguration(
1237             testRepoPurgeConfiguration2.getId() );
1238         repositoryPurgeConfigurationDao.removeRepositoryPurgeConfiguration( repoPurge );
1239 
1240         List<RepositoryPurgeConfiguration> repoPurgeList =
1241             repositoryPurgeConfigurationDao.getAllRepositoryPurgeConfigurations();
1242         assertEquals( "check # repo purge configurations", 2, repoPurgeList.size() );
1243         assertFalse( "check not there", repoPurgeList.contains( repoPurge ) );
1244     }
1245 
1246     public void testAddDirectoryPurgeConfiguration()
1247         throws Exception
1248     {
1249         String location = "release-directory";
1250         String directoryType = "release";
1251 
1252         Schedule schedule = scheduleDao.getSchedule( testSchedule1.getId() );
1253         DirectoryPurgeConfiguration dirPurge = createTestDirectoryPurgeConfiguration( location, directoryType, false, 2,
1254                                                                                       100, schedule, true );
1255 
1256         DirectoryPurgeConfiguration copy = createTestDirectoryPurgeConfiguration( dirPurge );
1257         directoryPurgeConfigurationDao.addDirectoryPurgeConfiguration( dirPurge );
1258         copy.setId( dirPurge.getId() );
1259 
1260         DirectoryPurgeConfiguration retrieved = directoryPurgeConfigurationDao.getDirectoryPurgeConfiguration(
1261             dirPurge.getId() );
1262         assertDirectoryPurgeConfigurationEquals( copy, retrieved );
1263         assertScheduleEquals( testSchedule1, retrieved.getSchedule() );
1264     }
1265 
1266     public void testRemoveDirectoryPurgeConfiguration()
1267         throws Exception
1268     {
1269         DirectoryPurgeConfiguration dirPurge = directoryPurgeConfigurationDao.getDirectoryPurgeConfiguration(
1270             testDirectoryPurgeConfig.getId() );
1271         directoryPurgeConfigurationDao.removeDirectoryPurgeConfiguration( dirPurge );
1272 
1273         List<DirectoryPurgeConfiguration> dirPurgeList =
1274             directoryPurgeConfigurationDao.getAllDirectoryPurgeConfigurations();
1275         assertEquals( "check #  dir purge configurations", 0, dirPurgeList.size() );
1276     }
1277 
1278     public void testGetPurgeConfigurationsBySchedule()
1279         throws Exception
1280     {
1281         List<RepositoryPurgeConfiguration> repoPurgeList =
1282             repositoryPurgeConfigurationDao.getRepositoryPurgeConfigurationsBySchedule( testSchedule2.getId() );
1283         List<DirectoryPurgeConfiguration> dirPurgeList =
1284             directoryPurgeConfigurationDao.getDirectoryPurgeConfigurationsBySchedule( testSchedule2.getId() );
1285 
1286         assertEquals( "check # repo purge configurations", 2, repoPurgeList.size() );
1287         assertEquals( "check # dir purge configurations", 1, dirPurgeList.size() );
1288 
1289         assertRepositoryPurgeConfigurationEquals( testRepoPurgeConfiguration1, repoPurgeList.get( 0 ) );
1290         assertRepositoryPurgeConfigurationEquals( testRepoPurgeConfiguration3, repoPurgeList.get( 1 ) );
1291         assertDirectoryPurgeConfigurationEquals( testDirectoryPurgeConfig, dirPurgeList.get( 0 ) );
1292     }
1293 
1294     public void testAddProjectScmRoot()
1295         throws Exception
1296     {
1297         ProjectGroup projectGroup = projectGroupDao.getProjectGroup( testProjectGroup2.getId() );
1298         ProjectScmRoot projectScmRoot = createTestProjectScmRoot( "scmRootAddress", 1, 0, "", projectGroup );
1299 
1300         projectScmRoot = projectScmRootDao.addProjectScmRoot( projectScmRoot );
1301 
1302         List<ProjectScmRoot> projectScmRoots = projectScmRootDao.getProjectScmRootByProjectGroup(
1303             projectGroup.getId() );
1304 
1305         assertEquals( "check # of project scm root", 2, projectScmRoots.size() );
1306 
1307         ProjectScmRoot retrievedProjectScmRoot = projectScmRootDao.getProjectScmRootByProjectGroupAndScmRootAddress(
1308             projectGroup.getId(), "scmRootAddress" );
1309 
1310         assertProjectScmRootEquals( projectScmRoot, retrievedProjectScmRoot );
1311         assertProjectGroupEquals( projectScmRoot.getProjectGroup(), retrievedProjectScmRoot.getProjectGroup() );
1312     }
1313 
1314     public void testRemoveProjectScmRoot()
1315         throws Exception
1316     {
1317         ProjectGroup projectGroup = projectGroupDao.getProjectGroup( testProjectGroup2.getId() );
1318 
1319         List<ProjectScmRoot> projectScmRoots = projectScmRootDao.getProjectScmRootByProjectGroup(
1320             projectGroup.getId() );
1321 
1322         assertEquals( "check # of project scm root", 1, projectScmRoots.size() );
1323 
1324         ProjectScmRoot projectScmRoot = projectScmRoots.get( 0 );
1325         projectScmRootDao.removeProjectScmRoot( projectScmRoot );
1326 
1327         projectScmRoots = projectScmRootDao.getProjectScmRootByProjectGroup( projectGroup.getId() );
1328 
1329         assertEquals( "check # of project scm root", 0, projectScmRoots.size() );
1330     }
1331 
1332     public void testRemoveProjectWithReleaseResult()
1333         throws Exception
1334     {
1335         Project project = projectDao.getProject( testProject1.getId() );
1336         ProjectGroup group = project.getProjectGroup();
1337 
1338         ContinuumReleaseResult releaseResult = createTestContinuumReleaseResult( group, project, "releaseGoal", 0, 0,
1339                                                                                  0 );
1340         releaseResult = releaseResultDao.addContinuumReleaseResult( releaseResult );
1341 
1342         List<ContinuumReleaseResult> releaseResults = releaseResultDao.getAllContinuumReleaseResults();
1343         assertEquals( "check size of continuum release results", 2, releaseResults.size() );
1344 
1345         ContinuumReleaseResult retrievedResult = releaseResults.get( 1 );
1346         assertReleaseResultEquals( releaseResult, retrievedResult );
1347         assertProjectGroupEquals( group, retrievedResult.getProjectGroup() );
1348         assertProjectEquals( project, retrievedResult.getProject() );
1349 
1350         releaseResultDao.removeContinuumReleaseResult( releaseResult );
1351         projectDao.removeProject( project );
1352         assertFalse( projectDao.getProjectsInGroup( group.getId() ).contains( project ) );
1353 
1354         releaseResults = releaseResultDao.getAllContinuumReleaseResults();
1355         assertEquals( "check size of continuum release results", 1, releaseResults.size() );
1356     }
1357 
1358     public void testGetProjectSummaryByProjectGroup()
1359         throws Exception
1360     {
1361         List<Project> projects = projectDao.getProjectsInGroup( defaultProjectGroup.getId() );
1362         assertEquals( 2, projects.size() );
1363 
1364         Project project = projects.get( 0 );
1365         project.setState( 2 );
1366         projectDao.updateProject( project );
1367 
1368         project = projects.get( 1 );
1369         project.setState( 2 );
1370         projectDao.updateProject( project );
1371 
1372         ProjectGroup newGroup = projectGroupDao.getProjectGroupWithProjects( testProjectGroup2.getId() );
1373         Project project1 = createTestProject( testProject1 );
1374         project1.setState( 4 );
1375         newGroup.addProject( project1 );
1376 
1377         Project project2 = createTestProject( testProject2 );
1378         project2.setState( 1 );
1379         newGroup.addProject( project2 );
1380         projectGroupDao.updateProjectGroup( newGroup );
1381 
1382         Map<Integer, ProjectGroupSummary> summaries = projectDao.getProjectsSummary();
1383 
1384         assertNotNull( summaries );
1385         assertEquals( "check size of project summaries", 2, summaries.size() );
1386 
1387         ProjectGroupSummary summary = summaries.get( testProjectGroup2.getId() );
1388         assertEquals( "check id of project group", testProjectGroup2.getId(), summary.getProjectGroupId() );
1389         assertEquals( "check number of errors", 1, summary.getNumberOfErrors() );
1390         assertEquals( "check number of successes", 0, summary.getNumberOfSuccesses() );
1391         assertEquals( "check number of failures", 0, summary.getNumberOfFailures() );
1392         assertEquals( "check number of projects", 2, summary.getNumberOfProjects() );
1393 
1394         summary = summaries.get( defaultProjectGroup.getId() );
1395         assertEquals( "check id of project group", defaultProjectGroup.getId(), summary.getProjectGroupId() );
1396         assertEquals( "check number of errors", 0, summary.getNumberOfErrors() );
1397         assertEquals( "check number of successes", 2, summary.getNumberOfSuccesses() );
1398         assertEquals( "check number of failures", 0, summary.getNumberOfFailures() );
1399         assertEquals( "check number of projects", 2, summary.getNumberOfProjects() );
1400 
1401     }
1402 
1403     public void testGetBuildResultsInRange()
1404         throws Exception
1405     {
1406         List<BuildResult> results = buildResultDao.getBuildResultsInRange( null, null, 0, null, 0 );
1407         assertEquals( "check number of build results returned", 3, results.size() );
1408 
1409         results = buildResultDao.getBuildResultsInRange( null, null, 2, null, 0 );
1410         assertEquals( "check number of build results returned with state == OK", 2, results.size() );
1411 
1412         results = buildResultDao.getBuildResultsInRange( null, null, 0, "user", 0 );
1413         assertEquals( "check number of build results returned with triggeredBy == user", 1, results.size() );
1414 
1415         results = buildResultDao.getBuildResultsInRange( null, null, 0, "schedule", 0 );
1416         assertEquals( "check number of build results returned with triggeredBy == schedule", 2, results.size() );
1417 
1418         results = buildResultDao.getBuildResultsInRange( null, null, 2, "schedule", 0 );
1419         assertEquals( "check number of build results returned with state == Ok and triggeredBy == schedule", 1,
1420                       results.size() );
1421 
1422         results = buildResultDao.getBuildResultsInRange( null, null, 3, "user", 0 );
1423         assertEquals( "check number of build results returned with state == Failed and triggeredBy == user", 0,
1424                       results.size() );
1425 
1426         Calendar cal = Calendar.getInstance();
1427         cal.setTime( new Date( baseTime ) );
1428         cal.add( Calendar.DAY_OF_MONTH, 1 );
1429 
1430         results = buildResultDao.getBuildResultsInRange( new Date( baseTime ), cal.getTime(), 0, null, 0 );
1431         assertEquals( "check number of build results returned with startDate and endDate", 2, results.size() );
1432 
1433         results = buildResultDao.getBuildResultsInRange( new Date( baseTime ), new Date( baseTime ), 0, null, 0 );
1434         assertEquals( "check number of build results returned with the same startDate and endDate", 1, results.size() );
1435 
1436         results = buildResultDao.getBuildResultsInRange( null, null, 0, null, 1 );
1437         assertEquals( "check number of build results returned with an existing group id", 3, results.size() );
1438 
1439         results = buildResultDao.getBuildResultsInRange( null, null, 0, null, 2 );
1440         assertEquals( "check number of build results returned with non-existing group id", 0, results.size() );
1441     }
1442     // ----------------------------------------------------------------------
1443     //  HELPER METHODS
1444     // ----------------------------------------------------------------------
1445 
1446     private void confirmProjectDeletion( Project project )
1447         throws ContinuumStoreException
1448     {
1449         try
1450         {
1451             projectDao.getProject( project.getId() );
1452             fail( "Project should no longer exist" );
1453         }
1454         catch ( ContinuumObjectNotFoundException expected )
1455         {
1456             assertTrue( true );
1457         }
1458 
1459         // !! These actually aren't happening !!
1460         // TODO: test the project's checkout SCM result was physically deleted
1461         // TODO: test the project's checkout SCM result's change sets and change files were physically deleted
1462         // TODO: test the project's dependencies are physically deleted
1463         // TODO: test the project's developers are physically deleted
1464         // TODO: test the project's builds are physically deleted
1465         // TODO: test the project's notifiers are physically deleted
1466         // TODO: test the project's build definitions are physically deleted
1467     }
1468 
1469     private static void checkProjectGroupDefaultFetchGroup( ProjectGroup retrievedGroup )
1470     {
1471         try
1472         {
1473             retrievedGroup.getBuildDefinitions();
1474             fail( "buildDefinitions should not be in the default fetch group" );
1475         }
1476         catch ( JDODetachedFieldAccessException expected )
1477         {
1478             assertTrue( true );
1479         }
1480 
1481         try
1482         {
1483             retrievedGroup.getNotifiers();
1484             fail( "notifiers should not be in the default fetch group" );
1485         }
1486         catch ( JDODetachedFieldAccessException expected )
1487         {
1488             assertTrue( true );
1489         }
1490     }
1491 
1492     private static void checkProjectDefaultFetchGroup( Project project )
1493     {
1494         checkProjectFetchGroup( project, false, false, false, false );
1495     }
1496 
1497     @Override
1498     protected void setUp()
1499         throws Exception
1500     {
1501         super.setUp();
1502 
1503         buildDefinitionDao = (BuildDefinitionDao) lookup( BuildDefinitionDao.class.getName() );
1504 
1505         buildDefinitionTemplateDao = (BuildDefinitionTemplateDao) lookup( BuildDefinitionTemplateDao.class.getName() );
1506 
1507         buildResultDao = (BuildResultDao) lookup( BuildResultDao.class.getName() );
1508 
1509         createBuildDatabase( false );
1510     }
1511 
1512     private static void checkProjectFetchGroup( Project project, boolean checkoutFetchGroup,
1513                                                 boolean buildResultsFetchGroup, boolean detailsFetchGroup,
1514                                                 boolean fineDetailsFetchGroup )
1515     {
1516         if ( !fineDetailsFetchGroup )
1517         {
1518             try
1519             {
1520                 project.getDevelopers();
1521 
1522                 fail( "developers should not be in the default fetch group" );
1523             }
1524             catch ( JDODetachedFieldAccessException expected )
1525             {
1526                 assertTrue( true );
1527             }
1528 
1529             try
1530             {
1531                 project.getDependencies();
1532 
1533                 fail( "dependencies should not be in the default fetch group" );
1534             }
1535             catch ( JDODetachedFieldAccessException expected )
1536             {
1537                 assertTrue( true );
1538             }
1539         }
1540 
1541         if ( !detailsFetchGroup )
1542         {
1543             try
1544             {
1545                 project.getNotifiers();
1546 
1547                 fail( "notifiers should not be in the default fetch group" );
1548             }
1549             catch ( JDODetachedFieldAccessException expected )
1550             {
1551                 assertTrue( true );
1552             }
1553 
1554             try
1555             {
1556                 project.getBuildDefinitions();
1557 
1558                 fail( "buildDefinitions should not be in the default fetch group" );
1559             }
1560             catch ( JDODetachedFieldAccessException expected )
1561             {
1562                 assertTrue( true );
1563             }
1564         }
1565 
1566         if ( !checkoutFetchGroup )
1567         {
1568             try
1569             {
1570                 project.getCheckoutResult();
1571 
1572                 fail( "checkoutResult should not be in the fetch group" );
1573             }
1574             catch ( JDODetachedFieldAccessException expected )
1575             {
1576                 assertTrue( true );
1577             }
1578         }
1579 
1580         if ( !buildResultsFetchGroup )
1581         {
1582             try
1583             {
1584                 project.getBuildResults();
1585 
1586                 fail( "buildResults should not be in the default fetch group" );
1587             }
1588             catch ( JDODetachedFieldAccessException expected )
1589             {
1590                 assertTrue( true );
1591             }
1592         }
1593     }
1594 
1595 //    private static void checkBuildResultDefaultFetchGroup( BuildResult buildResult )
1596 //    {
1597 //        try
1598 //        {
1599 //            buildResult.getScmResult();
1600 //
1601 //            fail( "scmResult should not be in the default fetch group" );
1602 //        }
1603 //        catch ( JDODetachedFieldAccessException expected )
1604 //        {
1605 //            assertTrue( true );
1606 //        }
1607 //        // TODO: artifacts
1608 //        // TODO: report
1609 //        // TODO: long error data
1610 //    }
1611 
1612 }