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