continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ri...@apache.org
Subject svn commit: r490675 - in /maven/continuum/branches/key-based-refactor/continuum-store/src/test/java/org/apache/maven/continuum/store/jdo: AbstractJdoStoreTestCase.java JdoProjectGroupTestCase.java JdoProjectStoreTestCase.java JdoSystemStoreTestCase.java
Date Thu, 28 Dec 2006 08:19:19 GMT
Author: rinku
Date: Thu Dec 28 00:19:16 2006
New Revision: 490675

URL: http://svn.apache.org/viewvc?view=rev&rev=490675
Log:
o  clean ups.
o  Each of the Store test cases now createw its own test database instance and populates it.
o  Provision for Store test case extensions to override and allow populating the database
with their own set of test data. 

Modified:
    maven/continuum/branches/key-based-refactor/continuum-store/src/test/java/org/apache/maven/continuum/store/jdo/AbstractJdoStoreTestCase.java
    maven/continuum/branches/key-based-refactor/continuum-store/src/test/java/org/apache/maven/continuum/store/jdo/JdoProjectGroupTestCase.java
    maven/continuum/branches/key-based-refactor/continuum-store/src/test/java/org/apache/maven/continuum/store/jdo/JdoProjectStoreTestCase.java
    maven/continuum/branches/key-based-refactor/continuum-store/src/test/java/org/apache/maven/continuum/store/jdo/JdoSystemStoreTestCase.java

Modified: maven/continuum/branches/key-based-refactor/continuum-store/src/test/java/org/apache/maven/continuum/store/jdo/AbstractJdoStoreTestCase.java
URL: http://svn.apache.org/viewvc/maven/continuum/branches/key-based-refactor/continuum-store/src/test/java/org/apache/maven/continuum/store/jdo/AbstractJdoStoreTestCase.java?view=diff&rev=490675&r1=490674&r2=490675
==============================================================================
--- maven/continuum/branches/key-based-refactor/continuum-store/src/test/java/org/apache/maven/continuum/store/jdo/AbstractJdoStoreTestCase.java
(original)
+++ maven/continuum/branches/key-based-refactor/continuum-store/src/test/java/org/apache/maven/continuum/store/jdo/AbstractJdoStoreTestCase.java
Thu Dec 28 00:19:16 2006
@@ -1,8 +1,21 @@
-/**
- * 
- */
 package org.apache.maven.continuum.store.jdo;
 
+/*
+ * Copyright 2004-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 import org.apache.maven.continuum.store.ProjectStore;
 import org.codehaus.plexus.PlexusTestCase;
 import org.codehaus.plexus.jdo.DefaultConfigurableJdoFactory;
@@ -22,65 +35,94 @@
 import java.util.List;
 
 /**
- * @author <a href='mailto:rahul.thakur.xdev@gmail.com'>Rahul Thakur</a>
+ * Provides some service methods for Store test case extensions.
  * 
+ * @author <a href='mailto:rahul.thakur.xdev@gmail.com'>Rahul Thakur</a>
+ * @version $Id$
+ * @since 1.1
  */
 public abstract class AbstractJdoStoreTestCase extends PlexusTestCase
 {
-    protected ProjectStore store;
 
     /**
-     * DDL for Database creation.
+     * Default location for SQL test data.
      */
-    protected File sqlSchema = getTestFile( getBasedir(), "src/test/resources/schema.sql"
);
+    private static final String SQL_TEST_DATA = "src/test/resources/testData.sql";
 
     /**
-     * Test Data.
+     * Password to connect to the target test database instance.
      */
-    protected File sqlTestData = getTestFile( getBasedir(), "src/test/resources/testData.sql"
);
+    private static final String PASSWORD_TEST_DATABASE = "";
 
     /**
-     * Setup JDO Factory
-     * 
-     * @todo push down to a Jdo specific test
+     * Username to connect to the target test database instance.
      */
-    protected ProjectStore createStore() throws Exception
-    {
-        DefaultConfigurableJdoFactory jdoFactory = (DefaultConfigurableJdoFactory) lookup(
JdoFactory.ROLE );
-
-        jdoFactory.setUrl( "jdbc:hsqldb:mem:continuum" );
-
-        jdoFactory.setDriverName( "org.hsqldb.jdbcDriver" );
+    private static final String USERNAME_TEST_DATABASE = "sa";
 
-        jdoFactory.setUserName( "sa" );
+    /**
+     * Driver class to connect to the target database instance.
+     */
+    private static final String DRIVER_TEST_DATABASE = "org.hsqldb.jdbcDriver";
 
-        jdoFactory.setPassword( "" );
+    /**
+     * JDBC URL to connect to the target test database instance.
+     */
+    private final String URL_TEST_DATABASE = "jdbc:hsqldb:mem:" + getName();
 
-        return (ProjectStore) lookup( ProjectStore.ROLE );
-    }
+    /**
+     * DDL for Database creation.
+     */
+    private static final File SQL_DATABSE_SCHEMA = getTestFile( getBasedir(), "src/test/resources/schema.sql"
);
 
+    /**
+     * Creates an instance of Continuum Database for test purposes and loads up
+     * the test data from the specified schema and test data SQL scripts.
+     * 
+     * @throws Exception if there was an error with test database set up.
+     */
     protected void createBuildDatabase() throws Exception
     {
         DefaultConfigurableJdoFactory jdoFactory = (DefaultConfigurableJdoFactory) lookup(
JdoFactory.ROLE );
 
-        jdoFactory.setUrl( "jdbc:hsqldb:mem:continuum" );
+        jdoFactory.setUrl( URL_TEST_DATABASE );
 
-        jdoFactory.setDriverName( "org.hsqldb.jdbcDriver" );
+        jdoFactory.setDriverName( DRIVER_TEST_DATABASE );
 
-        jdoFactory.setUserName( "sa" );
+        jdoFactory.setUserName( USERNAME_TEST_DATABASE );
 
-        jdoFactory.setPassword( "" );
+        jdoFactory.setPassword( PASSWORD_TEST_DATABASE );
 
         PersistenceManager pm = jdoFactory.getPersistenceManagerFactory().getPersistenceManager();
 
         Connection connection = (Connection) pm.getDataStoreConnection().getNativeConnection();
 
-        createStoreFromSQL( sqlSchema, connection );
+        loadSQL( SQL_DATABSE_SCHEMA, connection );
+
+        // load test data.
+        List scripts = getSQLScripts();
+
+        for ( Iterator it = scripts.iterator(); it.hasNext(); )
+        {
+            File script = (File) it.next();
+
+            System.out.println( "Loading SQL data from script: " + script.getAbsolutePath()
);
+
+            loadSQL( script, connection );
+        }
 
-        createStoreFromSQL( sqlTestData, connection );
     }
 
-    public void createStoreFromSQL( File sqlData, Connection connection ) throws Exception
+    /**
+     * Reads SQL statements from the specified file and uses the passed in
+     * {@link Connection} to populate the target database instance.
+     * 
+     * @param sqlData SQL data to load.
+     * @param connection {@link Connection} instance that wraps an underlying
+     *            connection to target database.
+     * @throws Exception if there was an error reading SQL scripts or executing
+     *             SQL statements for the target Database.
+     */
+    private void loadSQL( File sqlData, Connection connection ) throws Exception
     {
         FileInputStream fis = new FileInputStream( sqlData );
         BufferedReader br = new BufferedReader( new InputStreamReader( fis ) );
@@ -92,7 +134,7 @@
         while ( null != line )
         {
             // only add to sql list if its not empty or not commented
-            if ( !line.trim().equals( "" ) && !line.startsWith( "#" ) &&
!line.startsWith( "--" ) )
+            if ( !line.trim().equals( PASSWORD_TEST_DATABASE ) && !line.startsWith(
"#" ) && !line.startsWith( "--" ) )
             {
                 sb.append( line );
                 // check if the SQL statement was terminated
@@ -130,5 +172,20 @@
             }
         }
         // System.out.println( "Done!" );
+    }
+
+    /**
+     * Extensions are allowed to implement and return a list of SQL script
+     * {@link File} instances that are to be read and loaded into the target
+     * test database.
+     * 
+     * @return List of locations of SQL scripts
+     */
+    protected List getSQLScripts()
+    {
+        List list = new ArrayList();
+        // add default test data source.
+        list.add( getTestFile( getBasedir(), SQL_TEST_DATA ) );
+        return list;
     }
 }

Modified: maven/continuum/branches/key-based-refactor/continuum-store/src/test/java/org/apache/maven/continuum/store/jdo/JdoProjectGroupTestCase.java
URL: http://svn.apache.org/viewvc/maven/continuum/branches/key-based-refactor/continuum-store/src/test/java/org/apache/maven/continuum/store/jdo/JdoProjectGroupTestCase.java?view=diff&rev=490675&r1=490674&r2=490675
==============================================================================
--- maven/continuum/branches/key-based-refactor/continuum-store/src/test/java/org/apache/maven/continuum/store/jdo/JdoProjectGroupTestCase.java
(original)
+++ maven/continuum/branches/key-based-refactor/continuum-store/src/test/java/org/apache/maven/continuum/store/jdo/JdoProjectGroupTestCase.java
Thu Dec 28 00:19:16 2006
@@ -2,6 +2,9 @@
 
 import org.apache.maven.continuum.store.ProjectGroupStore;
 
+import java.util.ArrayList;
+import java.util.List;
+
 /**
  * @author <a href='mailto:rahul.thakur.xdev@gmail.com'>Rahul Thakur</a>
  * @version $Id$
@@ -9,6 +12,19 @@
  */
 public class JdoProjectGroupTestCase extends AbstractJdoStoreTestCase
 {
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+        createBuildDatabase();
+    }
+
+    /**
+     * @see junit.framework.TestCase#getName()
+     */
+    public String getName()
+    {
+        return getClass().getName();
+    }
 
     public void testComponentLookup() throws Exception
     {
@@ -16,4 +32,5 @@
         assertNotNull( store );
     }
 
+  
 }

Modified: maven/continuum/branches/key-based-refactor/continuum-store/src/test/java/org/apache/maven/continuum/store/jdo/JdoProjectStoreTestCase.java
URL: http://svn.apache.org/viewvc/maven/continuum/branches/key-based-refactor/continuum-store/src/test/java/org/apache/maven/continuum/store/jdo/JdoProjectStoreTestCase.java?view=diff&rev=490675&r1=490674&r2=490675
==============================================================================
--- maven/continuum/branches/key-based-refactor/continuum-store/src/test/java/org/apache/maven/continuum/store/jdo/JdoProjectStoreTestCase.java
(original)
+++ maven/continuum/branches/key-based-refactor/continuum-store/src/test/java/org/apache/maven/continuum/store/jdo/JdoProjectStoreTestCase.java
Thu Dec 28 00:19:16 2006
@@ -1,10 +1,25 @@
-/**
- * 
- */
 package org.apache.maven.continuum.store.jdo;
 
+/*
+ * Copyright 2004-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 import org.apache.maven.continuum.store.ProjectStore;
 
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * @author <a href='mailto:rahul.thakur.xdev@gmail.com'>Rahul Thakur</a>
@@ -20,10 +35,19 @@
         createBuildDatabase();
     }
 
+    /**
+     * @see junit.framework.TestCase#getName()
+     */
+    public String getName()
+    {
+        return getClass().getName();
+    }
+
     public void testComponentLookup() throws Exception
     {
         ProjectStore store = (ProjectStore) lookup( ProjectStore.ROLE, "jdo" );
         assertNotNull( store );
     }
 
+  
 }

Modified: maven/continuum/branches/key-based-refactor/continuum-store/src/test/java/org/apache/maven/continuum/store/jdo/JdoSystemStoreTestCase.java
URL: http://svn.apache.org/viewvc/maven/continuum/branches/key-based-refactor/continuum-store/src/test/java/org/apache/maven/continuum/store/jdo/JdoSystemStoreTestCase.java?view=diff&rev=490675&r1=490674&r2=490675
==============================================================================
--- maven/continuum/branches/key-based-refactor/continuum-store/src/test/java/org/apache/maven/continuum/store/jdo/JdoSystemStoreTestCase.java
(original)
+++ maven/continuum/branches/key-based-refactor/continuum-store/src/test/java/org/apache/maven/continuum/store/jdo/JdoSystemStoreTestCase.java
Thu Dec 28 00:19:16 2006
@@ -1,10 +1,26 @@
-/**
- * 
- */
 package org.apache.maven.continuum.store.jdo;
 
+/*
+ * Copyright 2004-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 import org.apache.maven.continuum.store.SystemStore;
 
+import java.util.ArrayList;
+import java.util.List;
+
 /**
  * @author <a href='mailto:rahul.thakur.xdev@gmail.com'>Rahul Thakur</a>
  * @version $Id$
@@ -12,9 +28,25 @@
  */
 public class JdoSystemStoreTestCase extends AbstractJdoStoreTestCase
 {
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+        createBuildDatabase();
+    }
+
+    /**
+     * @see junit.framework.TestCase#getName()
+     */
+    public String getName()
+    {
+        return getClass().getName();
+    }
+
     public void testComponentLookup() throws Exception
     {
         SystemStore store = (SystemStore) lookup( SystemStore.ROLE, "jdo" );
         assertNotNull( store );
     }
+
+   
 }



Mime
View raw message