continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jvan...@apache.org
Subject svn commit: r219561 - in /maven/continuum/trunk/continuum-core/src: main/java/org/apache/maven/continuum/store/JdoContinuumStore.java test/java/org/apache/maven/continuum/store/AbstractContinuumStoreTest.java
Date Mon, 18 Jul 2005 19:58:08 GMT
Author: jvanzyl
Date: Mon Jul 18 12:54:26 2005
New Revision: 219561

URL: http://svn.apache.org/viewcvs?rev=219561&view=rev
Log:
o adding full tests for the M:N relationship between schedules and projects

Modified:
    maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/store/JdoContinuumStore.java
    maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/store/AbstractContinuumStoreTest.java

Modified: maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/store/JdoContinuumStore.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/store/JdoContinuumStore.java?rev=219561&r1=219560&r2=219561&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/store/JdoContinuumStore.java
(original)
+++ maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/store/JdoContinuumStore.java
Mon Jul 18 12:54:26 2005
@@ -113,8 +113,6 @@
 
                     schedule.getProjects().remove( project );
                 }
-
-                makePersistentAll( pm, project.getSchedules() );
             }
 
             pm.deletePersistent( project );
@@ -139,7 +137,8 @@
             tx.begin();
 
             // ----------------------------------------------------------------------
-            // Work around for bug with M:N relationships
+            // Work around for bug with M:N relationships. We must persist the list
+            // of schedules or they don't get saved.
             // ----------------------------------------------------------------------
 
             if ( project.getSchedules() != null && project.getSchedules().size()
> 0 )
@@ -340,6 +339,29 @@
     // Schedules
     // ----------------------------------------------------------------------
 
+    public String addSchedule( ContinuumSchedule schedule )
+        throws ContinuumStoreException
+    {
+        PersistenceManager pm = pmf.getPersistenceManager();
+
+        Transaction tx = pm.currentTransaction();
+
+        try
+        {
+            tx.begin();
+
+            schedule = (ContinuumSchedule) makePersistent( pm, schedule );
+
+            commit( tx );
+
+            return schedule.getId();
+        }
+        finally
+        {
+            rollback( tx );
+        }
+    }
+
     public ContinuumSchedule getSchedule( String projectId )
         throws ContinuumStoreException
     {
@@ -420,10 +442,49 @@
         updateObject( schedule );
     }
 
-    public void removeSchedule( ContinuumSchedule schedule )
+    public void removeSchedule( String scheduleId )
         throws ContinuumStoreException
     {
-        attachAndDelete( schedule );
+        PersistenceManager pm = pmf.getPersistenceManager();
+
+        Transaction tx = pm.currentTransaction();
+
+        try
+        {
+            tx.begin();
+
+            Object id = pm.newObjectIdInstance( ContinuumSchedule.class, scheduleId );
+
+            ContinuumSchedule schedule = (ContinuumSchedule) pm.getObjectById( id );
+
+            // ----------------------------------------------------------------------
+            // We need to remove this schedule reference from any project in the
+            // system. So grab the list of projects this schedule belongs to
+            // then iterate through the collection of projects removing the
+            // reference to this schedule. This seems like a bit much but the
+            // only thing that works.
+            // ----------------------------------------------------------------------
+
+            if ( schedule.getProjects() != null && schedule.getProjects().size()
> 0 )
+            {
+                Set projects = schedule.getProjects();
+
+                for ( Iterator i = projects.iterator(); i.hasNext(); )
+                {
+                    ContinuumProject project = (ContinuumProject) i.next();
+
+                    project.getSchedules().remove( schedule );
+                }
+            }
+
+            pm.deletePersistent( schedule );
+
+            commit( tx );
+        }
+        finally
+        {
+            rollback( tx );
+        }
     }
 
     // ----------------------------------------------------------------------

Modified: maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/store/AbstractContinuumStoreTest.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/store/AbstractContinuumStoreTest.java?rev=219561&r1=219560&r2=219561&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/store/AbstractContinuumStoreTest.java
(original)
+++ maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/store/AbstractContinuumStoreTest.java
Mon Jul 18 12:54:26 2005
@@ -715,25 +715,34 @@
     // Schedules
     // ----------------------------------------------------------------------
 
-    public void testSchedulesBeingAddedToProject()
+    public void testScheduleAdditionAndRemovalFromProject()
         throws Exception
     {
+        // create project
         String projectId = addMavenTwoProject( "Project Scheduling", "scm:scheduling" );
 
         ContinuumProject project = store.getProject( projectId );
 
+        // add schedule
         project.addSchedule( createStubSchedule( "schedule1" ) );
 
+        // update project
         store.updateProject( project );
 
+        // retrieve project
         project = store.getProject( projectId );
 
         assertNotNull( project );
 
+        // get schedules out of the project
         Set schedules = project.getSchedules();
 
+        assertEquals( 1, schedules.size() );
+
+        // get individual schedule
         ContinuumSchedule schedule = (ContinuumSchedule) schedules.iterator().next();
 
+        // test values within schedule
         assertEquals( "schedule1", schedule.getName() );
 
         assertEquals( "schedule1", schedule.getDescription() );
@@ -773,6 +782,69 @@
         schedule = store.getSchedule( scheduleId );
 
         assertNotNull( schedule );
+    }
+
+    public void testProjectAdditionAndRemovalFromSchedule()
+        throws Exception
+    {
+        // create schedule
+        ContinuumSchedule schedule = createStubSchedule( "schedule2" );
+
+        String scheduleId = store.addSchedule( schedule );
+
+        schedule = store.getSchedule( scheduleId );
+
+        String projectId = addMavenTwoProject( "Project", "scm:scheduling" );
+
+        ContinuumProject project = store.getProject( projectId );
+
+        // add project
+        schedule.addProject( project );
+
+        // update schedule
+        store.updateSchedule( schedule );
+
+        // retrieve schedule
+        schedule = store.getSchedule( scheduleId );
+
+        assertNotNull( schedule );
+
+        // get projects out of the schedule
+        Set projects = schedule.getProjects();
+
+        assertEquals( 1, projects.size() );
+
+        // get individual project
+        project = (ContinuumProject) schedule.getProjects().iterator().next();
+
+        // test values within project
+        assertEquals( "Project", project.getName() );
+
+        // ----------------------------------------------------------------------
+        // Now lookup the project on its own and make sure the schedule is
+        // present within the project.
+        // ----------------------------------------------------------------------
+
+        project = store.getProject( projectId );
+
+        assertNotNull( project );
+
+        schedule = (ContinuumSchedule) project.getSchedules().iterator().next();
+
+        assertEquals( "schedule2", schedule.getName() );
+
+        // ----------------------------------------------------------------------
+        // Now delete the schedule from the store and make sure that the project
+        // still remains in the store.
+        // ----------------------------------------------------------------------
+
+        schedule = store.getSchedule( scheduleId );
+
+        store.removeSchedule( schedule.getId() );
+
+        project = store.getProject( projectId );
+
+        assertNotNull( project );
     }
 
     // ----------------------------------------------------------------------



Mime
View raw message