continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jvan...@apache.org
Subject svn commit: r219953 - in /maven/continuum/trunk/continuum-core/src: main/java/org/apache/maven/continuum/store/ test/java/org/apache/maven/continuum/store/
Date Wed, 20 Jul 2005 17:20:00 GMT
Author: jvanzyl
Date: Wed Jul 20 10:20:00 2005
New Revision: 219953

URL: http://svn.apache.org/viewcvs?rev=219953&view=rev
Log:
o updates for buildGroups in the store

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
    maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/store/NewModelTest.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=219953&r1=219952&r2=219953&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
Wed Jul 20 10:20:00 2005
@@ -28,6 +28,7 @@
 import javax.jdo.PersistenceManagerFactory;
 import javax.jdo.Query;
 import javax.jdo.Transaction;
+import javax.jdo.JDOHelper;
 
 import org.apache.maven.continuum.project.ContinuumBuild;
 import org.apache.maven.continuum.project.ContinuumProject;
@@ -130,50 +131,7 @@
                     System.out.println( "removed: " + r );
                 }
             }
-/*
-            System.out.println( "------------------------------------------" );
-            System.out.println( "Remove project" );
-            System.out.println( "------------------------------------------" );
-
-            System.out.println( "project.getId() = " + project.getId() );
-            System.out.println( "project.getBuildGroups() = " + project.getBuildGroups()
);
-            System.out.println( "project.getBuildGroups().size() = " + project.getBuildGroups().size()
);
-
-            if ( project.getBuildGroups() != null && project.getBuildGroups().size()
> 0 )
-            {
-                Set buildGroups = project.getBuildGroups();
-
-                for ( Iterator i = buildGroups.iterator(); i.hasNext(); )
-                {
-                    ContinuumBuildGroup buildGroup = (ContinuumBuildGroup) i.next();
 
-                    System.out.println( "buildGroup.getProjects() = " + buildGroup.getProjects()
);
-                    System.out.println( "buildGroup.getProjects().size() = " + buildGroup.getProjects().size()
);
-
-//                    boolean removed = buildGroup.getProjects().remove( project );
-//
-//                    System.out.println( "removed: " + removed );
-
-                    for ( Iterator j = buildGroup.getProjects().iterator(); j.hasNext();
)
-                    {
-                        ContinuumProject continuumProject = (ContinuumProject) j.next();
-
-                        System.out.println( "testing : " + continuumProject.getId() );
-                        if ( continuumProject.getId().equals( project.getId() ) )
-                        {
-                            System.out.println( "removing " + project.getId() + ", " + project
);
-
-                            j.remove();
-                        }
-                    }
-                }
-            }
-            System.out.println( "project.getBuildGroups() = " + project.getBuildGroups()
);
-            System.out.println( "project.getBuildGroups().size() = " + project.getBuildGroups().size()
);
-
-            System.out.println( "project = " + project );
-            System.out.println( "project.getProjectGroup() = " + project.getProjectGroup()
);
-*/
             if ( project.getProjectGroup() != null )
             {
                 ContinuumProjectGroup pg = project.getProjectGroup();
@@ -222,12 +180,6 @@
 
             if ( project.getBuildGroups() != null && project.getBuildGroups().size()
> 0 )
             {
-                for ( Iterator it = project.getBuildGroups().iterator(); it.hasNext(); )
-                {
-                    ContinuumBuildGroup buildGroup = (ContinuumBuildGroup) it.next();
-
-                    System.err.println( "buildGroup.id: " + buildGroup.getId() );
-                }
                 pm.attachCopyAll( project.getBuildGroups(), true );
             }
 
@@ -787,12 +739,95 @@
         return ((ContinuumBuildGroup) addObject( buildGroup )).getId();
     }
 
+    public void updateBuildGroup( ContinuumBuildGroup schedule )
+        throws ContinuumStoreException
+    {
+        updateObject( schedule );
+    }
+
+    public void removeBuildGroup( String buildGroupId )
+        throws ContinuumStoreException
+    {
+        PersistenceManager pm = pmf.getPersistenceManager();
+
+        Transaction tx = pm.currentTransaction();
+
+        try
+        {
+            tx.begin();
+
+            Object id = pm.newObjectIdInstance( ContinuumBuildGroup.class, buildGroupId );
+
+            ContinuumBuildGroup buildGroup = (ContinuumBuildGroup) pm.getObjectById( id );
+
+            // ----------------------------------------------------------------------
+            // We need to remove this buildGroup reference from any project in the
+            // system. So grab the list of projects this buildGroup belongs to
+            // then iterate through the collection of projects removing the
+            // reference to this buildGroup. This seems like a bit much but the
+            // only thing that works.
+            // ----------------------------------------------------------------------
+
+            if ( buildGroup.getProjects() != null && buildGroup.getProjects().size()
> 0 )
+            {
+                Set projects = buildGroup.getProjects();
+
+                for ( Iterator i = projects.iterator(); i.hasNext(); )
+                {
+                    ContinuumProject project = (ContinuumProject) i.next();
+
+                    project.getBuildGroups().remove( buildGroup );
+                }
+            }
+
+            pm.deletePersistent( buildGroup );
+
+            commit( tx );
+        }
+        finally
+        {
+            rollback( tx );
+        }
+    }
+
+
     public ContinuumBuildGroup getBuildGroup( String buildGroupId )
         throws ContinuumStoreException
     {
         return (ContinuumBuildGroup) getDetailedObject( ContinuumBuildGroup.class,
                                                         buildGroupId,
                                                         "build-group-detail" );
+    }
+
+    public Collection getBuildGroups()
+        throws ContinuumStoreException
+    {
+        PersistenceManager pm = pmf.getPersistenceManager();
+
+        Transaction tx = pm.currentTransaction();
+
+        try
+        {
+            tx.begin();
+
+            Extent extent = pm.getExtent( ContinuumBuildGroup.class, true );
+
+            Query query = pm.newQuery( extent );
+
+            query.setOrdering( "name ascending" );
+
+            Collection result = (Collection) query.execute();
+
+            result = pm.detachCopyAll( result );
+
+            commit( tx );
+
+            return result;
+        }
+        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=219953&r1=219952&r2=219953&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
Wed Jul 20 10:20:00 2005
@@ -32,11 +32,11 @@
 public class AbstractContinuumStoreTest
     extends AbstractContinuumTest
 {
-    private ContinuumStore store;
+    protected ContinuumStore store;
 
-    private String roleHint;
+    protected String roleHint;
 
-    private Class implementationClass;
+    protected Class implementationClass;
 
     public AbstractContinuumStoreTest( String roleHint, Class implementationClass )
     {
@@ -652,7 +652,7 @@
     // Private utility methods
     // ----------------------------------------------------------------------
 
-    private String addMavenTwoProject( String name, String scmUrl )
+    protected String addMavenTwoProject( String name, String scmUrl )
         throws Exception
     {
         return addMavenTwoProject( store,
@@ -714,10 +714,20 @@
         ContinuumProject project = store.getProject( projectId );
 
         // add schedule
-        project.addSchedule( createStubSchedule( "schedule1" ) );
+        //project.addSchedule( createStubSchedule( "schedule1" ) );
+
+        ContinuumSchedule s = createStubSchedule( "schedule1" );
+
+        String sid = store.addSchedule( s );
+
+        s = store.getSchedule( sid );
+
+        project.addSchedule( s );
 
         // update project
         store.updateProject( project );
+
+        assertEquals( 1, store.getSchedules().size() );
 
         // retrieve project
         project = store.getProject( projectId );

Modified: maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/store/NewModelTest.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/store/NewModelTest.java?rev=219953&r1=219952&r2=219953&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/store/NewModelTest.java
(original)
+++ maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/store/NewModelTest.java
Wed Jul 20 10:20:00 2005
@@ -20,8 +20,10 @@
 import org.apache.maven.continuum.project.ContinuumBuildGroup;
 import org.apache.maven.continuum.project.ContinuumProject;
 import org.apache.maven.continuum.project.ContinuumProjectGroup;
+import org.apache.maven.continuum.project.ContinuumSchedule;
 
 import java.util.Collection;
+import java.util.Set;
 
 /**
  * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
@@ -30,12 +32,89 @@
 public class NewModelTest
     extends AbstractContinuumTest
 {
-    public void testFoo()
+    public void testAddingBuildGroupToProjectAndUpdatingProject()
+        throws Exception
     {
-        // Just to make sure that there is at least a single test in this test case.
+        String projectId = addMavenTwoProject( getStore(), "Project Scheduling", "scm:scheduling"
);
+
+        ContinuumProject project = getStore().getProject( projectId );
+
+        project.addBuildGroup( createStubBuildGroup( "Plexus", "Description" ) );
+
+        getStore().updateProject( project );
+
+        assertEquals( 1, getStore().getBuildGroups().size() );
+
+        project = getStore().getProject( projectId );
+
+        assertEquals( 1, project.getBuildGroups().size() );
+    }
+
+    public void testProjectAdditionAndRemovalFromBuildGroup()
+        throws Exception
+    {
+        // create buildGroup
+        ContinuumBuildGroup buildGroup = createStubBuildGroup( "buildGroup1", "buildGroup1"
);
+
+        String buildGroupId = getStore().addBuildGroup( buildGroup );
+
+        buildGroup = getStore().getBuildGroup( buildGroupId );
+
+        String projectId = addMavenTwoProject( getStore(), "project1", "scm:scheduling" );
+
+        ContinuumProject project = getStore().getProject( projectId );
+
+        // add project
+        buildGroup.addProject( project );
+
+        // update buildGroup
+        getStore().updateBuildGroup( buildGroup );
+
+        // retrieve buildGroup
+        buildGroup = getStore().getBuildGroup( buildGroupId );
+
+        assertNotNull( buildGroup );
+
+        // get projects out of the buildGroup
+        Set projects = buildGroup.getProjects();
+
+        assertEquals( 1, projects.size() );
+
+        // get individual project
+        project = (ContinuumProject) buildGroup.getProjects().iterator().next();
+
+        // test values within project
+        assertEquals( "project1", project.getName() );
+
+        // ----------------------------------------------------------------------
+        // Now lookup the project on its own and make sure the buildGroup is
+        // present within the project.
+        // ----------------------------------------------------------------------
+
+        project = getStore().getProject( projectId );
+
+        assertNotNull( project );
+
+        buildGroup = (ContinuumBuildGroup) project.getBuildGroups().iterator().next();
+
+        assertEquals( "buildGroup1", buildGroup.getName() );
+
+        // ----------------------------------------------------------------------
+        // Now delete the buildGroup from the getStore() and make sure that the project
+        // still remains in the getStore().
+        // ----------------------------------------------------------------------
+
+        buildGroup = getStore().getBuildGroup( buildGroupId );
+
+        getStore().removeBuildGroup( buildGroup.getId() );
+
+        project = getStore().getProject( projectId );
+
+        assertNotNull( project );
     }
 
-    public void XXXtestBasic()
+
+    public void xtestBasic()
         throws Exception
     {
         // ----------------------------------------------------------------------
@@ -98,11 +177,13 @@
 
         ContinuumBuildGroup buildGroup = new ContinuumBuildGroup();
 
-        buildGroup.setName( "Plexus Hey Yo");
+        buildGroup.setName( "Plexus Hey Yo" );
 
-        String buildGroupId = getStore().addBuildGroup( buildGroup );
+        buildGroup.setDescription( "Description" );
 
-        buildGroup = getStore().getBuildGroup( buildGroupId );
+        //String buildGroupId = getStore().addBuildGroup( buildGroup );
+
+        //buildGroup = getStore().getBuildGroup( buildGroupId );
 
         System.err.println( "buildGroup.id: " + buildGroup.getId() );
 
@@ -116,6 +197,17 @@
 
         getStore().updateProject( componentA );
 
+        System.out.println( "componentA.getBuildGroups().size() = " + componentA.getBuildGroups().size()
);
+
+        buildGroup = (ContinuumBuildGroup) componentA.getBuildGroups().iterator().next();
+
+        String buildGroupId = buildGroup.getId();
+
+        assertNotNull( buildGroup );
+
+        //String buildGroupId = getStore().getBuildGroup;
+
+
         // ----------------------------------------------------------------------
         // Assert that the project has a build group
         // ----------------------------------------------------------------------
@@ -140,7 +232,7 @@
 
         assertEquals( "buildGroup.projects.size", 1, buildGroup.getProjects().size() );
 
-        assertEquals( projectIdA, ((ContinuumProject) buildGroup.getProjects().iterator().next()
).getId() );
+        assertEquals( projectIdA, ( (ContinuumProject) buildGroup.getProjects().iterator().next()
).getId() );
 
         // ----------------------------------------------------------------------
         //
@@ -165,5 +257,16 @@
         assertNotNull( plexusGroup );
 
 //        assertEquals( 0, plexusGroup.getProjects().size() );
+    }
+
+    public ContinuumBuildGroup createStubBuildGroup( String name, String description )
+    {
+        ContinuumBuildGroup buildGroup = new ContinuumBuildGroup();
+
+        buildGroup.setName( name );
+
+        buildGroup.setDescription( description );
+
+        return buildGroup;
     }
 }



Mime
View raw message