continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tryg...@apache.org
Subject svn commit: r170801 - /maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/store /maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/store /maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/store /maven/continuum/trunk/continuum-core/src/test/resources/org/apache/maven/continuum/store
Date Wed, 18 May 2005 19:39:51 GMT
Author: trygvis
Date: Wed May 18 12:39:48 2005
New Revision: 170801

URL: http://svn.apache.org/viewcvs?rev=170801&view=rev
Log:
o Adding the required methods to resolve CONTINUUM-113.
 - Adding getProjectByName() and getProjectByScmUrl().
o Removing findProjectsByName() as it wasn't used.

Modified:
    maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/store/ContinuumStore.java
    maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/store/ModelloJPoxContinuumStore.java
    maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/store/ModelloJPoxContinuumStoreTest.java
    maven/continuum/trunk/continuum-core/src/test/resources/org/apache/maven/continuum/store/ModelloJPoxContinuumStoreTest.xml

Modified: maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/store/ContinuumStore.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/store/ContinuumStore.java?rev=170801&r1=170800&r2=170801&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/store/ContinuumStore.java
(original)
+++ maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/store/ContinuumStore.java
Wed May 18 12:39:48 2005
@@ -76,7 +76,10 @@
     Collection getAllProjects()
         throws ContinuumStoreException;
 
-    Collection findProjectsByName( String nameSearchPattern )
+    ContinuumProject getProjectByName( String nameSearchPattern )
+        throws ContinuumStoreException;
+
+    ContinuumProject getProjectByScmUrl( String scmUrl )
         throws ContinuumStoreException;
 
     ContinuumProject getProject( String projectId )

Modified: maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/store/ModelloJPoxContinuumStore.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/store/ModelloJPoxContinuumStore.java?rev=170801&r1=170800&r2=170801&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/store/ModelloJPoxContinuumStore.java
(original)
+++ maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/store/ModelloJPoxContinuumStore.java
Wed May 18 12:39:48 2005
@@ -96,6 +96,16 @@
                               Properties configuration )
         throws ContinuumStoreException
     {
+        if ( getProjectByName( name ) != null )
+        {
+            throw new ContinuumStoreException( "A project with the specified name already
exist." );
+        }
+
+        if ( getProjectByScmUrl( scmUrl ) != null )
+        {
+            throw new ContinuumStoreException( "A project with the specified scm url already
exist." );
+        }
+
         ContinuumProject project = new ContinuumProject();
 
         project.setName( name );
@@ -289,24 +299,52 @@
         }
     }
 
-    public Collection findProjectsByName( String nameSearchPattern )
+    public ContinuumProject getProjectByName( String name )
         throws ContinuumStoreException
     {
-        Iterator it = getAllProjects().iterator();
+        try
+        {
+            String filter = "this.name == \"" + name + "\"";
 
-        List hits = new ArrayList();
+            String ordering = "";
 
-        while ( it.hasNext() )
-        {
-            ContinuumProject continuumProject = (ContinuumProject) it.next();
+            Collection projects = store.getContinuumProjectCollection( true, filter, ordering
);
 
-            if ( continuumProject.getName().toLowerCase().indexOf( nameSearchPattern.toLowerCase()
) != -1 )
+            if ( projects.size() == 0 )
             {
-                hits.add( continuumProject );
+                return null;
             }
+
+            return (ContinuumProject) projects.iterator().next();
+        }
+        catch ( Exception e )
+        {
+            throw new ContinuumStoreException( "Error while loading project set", e );
         }
+    }
 
-        return hits;
+    public ContinuumProject getProjectByScmUrl( String scmUrl )
+        throws ContinuumStoreException
+    {
+        try
+        {
+            String filter = "this.scmUrl == \"" + scmUrl + "\"";
+
+            String ordering = "";
+
+            Collection projects = store.getContinuumProjectCollection( true, filter, ordering
);
+
+            if ( projects.size() == 0 )
+            {
+                return null;
+            }
+
+            return (ContinuumProject) projects.iterator().next();
+        }
+        catch ( Exception e )
+        {
+            throw new ContinuumStoreException( "Error while finding projects.", e );
+        }
     }
 
     public ContinuumProject getProject( String projectId )
@@ -514,7 +552,11 @@
     {
         try
         {
-            return store.getContinuumBuildCollection( true, "this.project.id == \"" + projectId
+ "\"", "startTime descending" );
+            String filter = "this.project.id == \"" + projectId + "\"";
+
+            String ordering = "startTime descending";
+
+            return store.getContinuumBuildCollection( true, filter, ordering );
         }
         catch ( Exception e )
         {

Modified: maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/store/ModelloJPoxContinuumStoreTest.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/store/ModelloJPoxContinuumStoreTest.java?rev=170801&r1=170800&r2=170801&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/store/ModelloJPoxContinuumStoreTest.java
(original)
+++ maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/store/ModelloJPoxContinuumStoreTest.java
Wed May 18 12:39:48 2005
@@ -368,8 +368,6 @@
 
         String projectId = addProject( "Test Project" );
 
-//        store.setBuildSignalled( projectId );
-
         store.setIsUpdating( projectId );
 
         store.setUpdateDone( projectId );
@@ -391,6 +389,52 @@
         store.removeProject( projectId );
     }
 
+    public void testAddDuplicateProject()
+        throws Exception
+    {
+        ContinuumStore store = (ContinuumStore) lookup( ContinuumStore.ROLE );
+
+        // ----------------------------------------------------------------------
+        // Test projects with duplicate names
+        // ----------------------------------------------------------------------
+
+        String projectId = addProject( "trygve" );
+
+        assertEquals( projectId, store.getProjectByName( "trygve" ).getId() );
+
+        try
+        {
+            addProject( "trygve" );
+
+            fail( "Expected a exception" );
+        }
+        catch( ContinuumStoreException e )
+        {
+            // expected
+        }
+
+        ContinuumProject project = makeStubProject( "brett" );
+
+        project.setScmUrl( "foo" );
+
+        addProject( project );
+
+        assertNotNull( store.getProjectByScmUrl( "foo" ) );
+
+        try
+        {
+            project.setName( "jason" );
+
+            addProject( project );
+
+            fail( "Expected a exception" );
+        }
+        catch ( ContinuumStoreException e )
+        {
+            // expected
+        }
+    }
+
     // ----------------------------------------------------------------------
     // Build
     // ----------------------------------------------------------------------
@@ -406,8 +450,6 @@
 
         String projectId = addProject( "Test Project" );
 
-//        store.setBuildSignalled( projectId );
-
         store.setIsUpdating( projectId );
 
         store.setUpdateDone( projectId );
@@ -442,24 +484,18 @@
 
         String projectId = addProject( "Test Project" );
 
-//        store.setBuildSignalled( projectId );
-
         store.setIsUpdating( projectId );
 
         store.setUpdateDone( projectId );
 
         String projectIdFoo = addProject( "Foo Project" );
 
-//        store.setBuildSignalled( projectIdFoo );
-
         store.setIsUpdating( projectIdFoo );
 
         store.setUpdateDone( projectIdFoo );
 
         String projectIdBar = addProject( "Bar Project" );
 
-//        store.setBuildSignalled( projectIdBar );
-
         store.setIsUpdating( projectIdBar );
 
         store.setUpdateDone( projectIdBar );
@@ -517,10 +553,6 @@
 
         String projectId = addProject( "Test Project" );
 
-//        store.setBuildSignalled( projectId );
-
-//        assertInState( projectId, ContinuumProjectState.BUILD_SIGNALED );
-
         store.setIsUpdating( projectId );
 
         assertInState( projectId, ContinuumProjectState.UPDATING );
@@ -607,41 +639,93 @@
     }
 
     // ----------------------------------------------------------------------
-    //
+    // Utility methods
     // ----------------------------------------------------------------------
 
-    private void assertInState( String projectId, int state )
-        throws ContinuumStoreException
+    public static ContinuumProject makeStubProject( String name )
     {
-        ContinuumProject project = store.getProject( projectId );
+        ContinuumProject project = new ContinuumProject();
 
-        assertEquals( state, project.getState() );
+        project.setName( name );
+        project.setScmUrl( "scm:local:src/test/repo" );
+        project.setNagEmailAddress( "foo@bar.com" );
+        project.setVersion( "1.0" );
+        project.setExecutorId( "maven2" );
+        project.setWorkingDirectory( "/tmp" );
+        project.setConfiguration( new Properties() );
+
+        return project;
     }
 
-    private void assertIsCommitted( ContinuumStore store )
+    public static ContinuumProject makeProject( String name,
+                                                String scmUrl,
+                                                String nagEmailAddress,
+                                                String version,
+                                                String executorId,
+                                                String workingDirectory,
+                                                Properties configuration )
     {
-        ContinuumJPoxStore.ThreadState state = ( (ModelloJPoxContinuumStore) store ).getStore().getThreadState();
+        ContinuumProject project = new ContinuumProject();
 
-        assertNull( state );
+        project.setName( name );
+        project.setScmUrl( scmUrl );
+        project.setNagEmailAddress( nagEmailAddress );
+        project.setVersion( version );
+        project.setExecutorId( executorId );
+        project.setWorkingDirectory( workingDirectory );
+        project.setConfiguration( configuration );
+
+        return project;
     }
 
     private String addProject( String name )
         throws Exception
     {
-        return addProject( (ContinuumStore) lookup( ContinuumStore.ROLE ), name );
+        return addProject( (ContinuumStore) lookup( ContinuumStore.ROLE ), makeStubProject(
name ) );
+    }
+
+    private String addProject( ContinuumProject project )
+        throws Exception
+    {
+        return addProject( (ContinuumStore) lookup( ContinuumStore.ROLE ), project );
+    }
+
+    public static String addProject( ContinuumStore store, ContinuumProject project )
+        throws Exception
+    {
+        return addProject( store,
+                           project.getName(),
+                           project.getScmUrl(),
+                           project.getNagEmailAddress(),
+                           project.getVersion(),
+                           project.getExecutorId(),
+                           project.getWorkingDirectory(),
+                           project.getConfiguration() );
     }
 
     public static String addProject( ContinuumStore store, String name )
         throws Exception
     {
-        String scmUrl = "scm:local:src/test/repo";
-        String nagEmailAddress = "foo@bar.com";
-        String version = "1.0";
-        String builderId = "maven2";
-        String workingDirectory = "/tmp";
-        Properties configuration = new Properties();
+        return addProject( store, makeStubProject( name ) );
+    }
 
-        String projectId = store.addProject( name, scmUrl, nagEmailAddress, version, builderId,
workingDirectory, configuration );
+    public static String addProject( ContinuumStore store,
+                                     String name,
+                                     String scmUrl,
+                                     String nagEmailAddress,
+                                     String version,
+                                     String executorId,
+                                     String workingDirectory,
+                                     Properties configuration )
+        throws Exception
+    {
+        String projectId = store.addProject( name,
+                                             scmUrl,
+                                             nagEmailAddress,
+                                             version,
+                                             executorId,
+                                             workingDirectory,
+                                             configuration );
 
         CheckOutScmResult checkOutScmResult = new CheckOutScmResult();
 
@@ -656,6 +740,25 @@
         assertEquals( ContinuumProjectState.NEW, project.getState() );
 
         return projectId;
+    }
+
+    // ----------------------------------------------------------------------
+    // Assertions
+    // ----------------------------------------------------------------------
+
+    private void assertInState( String projectId, int state )
+        throws ContinuumStoreException
+    {
+        ContinuumProject project = store.getProject( projectId );
+
+        assertEquals( state, project.getState() );
+    }
+
+    private void assertIsCommitted( ContinuumStore store )
+    {
+        ContinuumJPoxStore.ThreadState state = ( (ModelloJPoxContinuumStore) store ).getStore().getThreadState();
+
+        assertNull( state );
     }
 
     private void assertProjectEquals( String projectId, String name, String scmUrl, String
nagEmailAddress, String version, String builderId, String workingDirectory, Properties configuration,
ContinuumProject project )

Modified: maven/continuum/trunk/continuum-core/src/test/resources/org/apache/maven/continuum/store/ModelloJPoxContinuumStoreTest.xml
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-core/src/test/resources/org/apache/maven/continuum/store/ModelloJPoxContinuumStoreTest.xml?rev=170801&r1=170800&r2=170801&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-core/src/test/resources/org/apache/maven/continuum/store/ModelloJPoxContinuumStoreTest.xml
(original)
+++ maven/continuum/trunk/continuum-core/src/test/resources/org/apache/maven/continuum/store/ModelloJPoxContinuumStoreTest.xml
Wed May 18 12:39:48 2005
@@ -25,24 +25,6 @@
             <name>javax.jdo.option.ConnectionPassword</name>
             <value></value>
           </property>
-<!--
-          <property>
-            <name>javax.jdo.option.ConnectionDriverName</name>
-            <value>org.postgresql.Driver</value>
-          </property>
-          <property>
-            <name>javax.jdo.option.ConnectionURL</name>
-            <value>jdbc:postgresql://localhost/continuum</value>
-          </property>
-          <property>
-            <name>javax.jdo.option.ConnectionUserName</name>
-            <value>trygvis</value>
-          </property>
-          <property>
-            <name>javax.jdo.option.ConnectionPassword</name>
-            <value></value>
-          </property>
- -->
           <property>
             <name>org.jpox.autoCreateSchema</name>
             <value>true</value>



Mime
View raw message