continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ri...@apache.org
Subject svn commit: r491397 - in /maven/continuum/branches/key-based-refactor/continuum-store: ./ src/test/java/org/apache/maven/continuum/store/ibatis/ src/test/java/org/apache/maven/continuum/store/jdo/ src/test/resources/ src/test/resources/db/
Date Sun, 31 Dec 2006 06:32:53 GMT
Author: rinku
Date: Sat Dec 30 22:32:52 2006
New Revision: 491397

URL: http://svn.apache.org/viewvc?view=rev&rev=491397
Log:
o  started prepping up for DBUnit.

Added:
    maven/continuum/branches/key-based-refactor/continuum-store/src/test/java/org/apache/maven/continuum/store/ibatis/AbstractIbatisStoreTestCase.java
  (with props)
    maven/continuum/branches/key-based-refactor/continuum-store/src/test/resources/db/
    maven/continuum/branches/key-based-refactor/continuum-store/src/test/resources/db/schema.sql
      - copied unchanged from r490866, maven/continuum/branches/key-based-refactor/continuum-store/src/test/resources/schema.sql
    maven/continuum/branches/key-based-refactor/continuum-store/src/test/resources/db/teardown.sql
    maven/continuum/branches/key-based-refactor/continuum-store/src/test/resources/db/testData.sql
      - copied unchanged from r491355, maven/continuum/branches/key-based-refactor/continuum-store/src/test/resources/testData.sql
Removed:
    maven/continuum/branches/key-based-refactor/continuum-store/src/test/resources/schema.sql
    maven/continuum/branches/key-based-refactor/continuum-store/src/test/resources/testData.sql
Modified:
    maven/continuum/branches/key-based-refactor/continuum-store/pom.xml
    maven/continuum/branches/key-based-refactor/continuum-store/src/test/java/org/apache/maven/continuum/store/jdo/AbstractJdoStoreTestCase.java

Modified: maven/continuum/branches/key-based-refactor/continuum-store/pom.xml
URL: http://svn.apache.org/viewvc/maven/continuum/branches/key-based-refactor/continuum-store/pom.xml?view=diff&rev=491397&r1=491396&r2=491397
==============================================================================
--- maven/continuum/branches/key-based-refactor/continuum-store/pom.xml (original)
+++ maven/continuum/branches/key-based-refactor/continuum-store/pom.xml Sat Dec 30 22:32:52
2006
@@ -33,6 +33,13 @@
       <artifactId>hsqldb</artifactId>
       <scope>test</scope>
     </dependency>
+    <!-- TODO: Should this be moved to dep mgmt in parent? -->
+    <dependency>
+      <groupId>dbunit</groupId>
+      <artifactId>dbunit</artifactId>
+      <version>2.1</version>
+      <scope>test</scope>
+    </dependency>
     <dependency>
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-utils</artifactId>

Added: maven/continuum/branches/key-based-refactor/continuum-store/src/test/java/org/apache/maven/continuum/store/ibatis/AbstractIbatisStoreTestCase.java
URL: http://svn.apache.org/viewvc/maven/continuum/branches/key-based-refactor/continuum-store/src/test/java/org/apache/maven/continuum/store/ibatis/AbstractIbatisStoreTestCase.java?view=auto&rev=491397
==============================================================================
--- maven/continuum/branches/key-based-refactor/continuum-store/src/test/java/org/apache/maven/continuum/store/ibatis/AbstractIbatisStoreTestCase.java
(added)
+++ maven/continuum/branches/key-based-refactor/continuum-store/src/test/java/org/apache/maven/continuum/store/ibatis/AbstractIbatisStoreTestCase.java
Sat Dec 30 22:32:52 2006
@@ -0,0 +1,168 @@
+package org.apache.maven.continuum.store.ibatis;
+
+/*
+ * Copyright 2004-2005 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.codehaus.plexus.PlexusTestCase;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStreamReader;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * @author <a href='mailto:rahul.thakur.xdev@gmail.com'>Rahul Thakur</a>
+ * @version $Id$
+ * @since 1.1
+ */
+public abstract class AbstractIbatisStoreTestCase extends PlexusTestCase
+{
+
+    /**
+     * Default location for SQL test data.
+     */
+    private static final String SQL_TEST_DATA = "src/test/resources/db/testData.sql";
+
+    /**
+     * Password to connect to the target test database instance.
+     */
+    private static final String PASSWORD_TEST_DATABASE = "";
+
+    /**
+     * Username to connect to the target test database instance.
+     */
+    private static final String USERNAME_TEST_DATABASE = "sa";
+
+    /**
+     * Driver class to connect to the target database instance.
+     */
+    private static final String DRIVER_TEST_DATABASE = "org.hsqldb.jdbcDriver";
+
+    /**
+     * JDBC URL to connect to the target test database instance.
+     */
+    private final String URL_TEST_DATABASE = "jdbc:hsqldb:mem:" + getName();
+
+    /**
+     * DDL for Database creation.
+     */
+    private static final File SQL_DATABSE_SCHEMA = getTestFile( getBasedir(), "src/test/resources/db/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
+    {
+
+    }
+
+    /**
+     * Clean up the Continuum test database.
+     * 
+     * @throws Exception
+     */
+    protected void teardownBuildDatabase() throws Exception
+    {
+
+    }
+
+    /**
+     * 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;
+    }
+
+    /**
+     * 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 ) );
+        List sqlList = new ArrayList();
+
+        // build a list of SQL statements to execute here
+        String line = br.readLine();
+        StringBuffer sb = new StringBuffer();
+        while ( null != line )
+        {
+            // only add to sql list if its not empty or not commented
+            if ( !line.trim().equals( PASSWORD_TEST_DATABASE ) && !line.startsWith(
"#" ) && !line.startsWith( "--" ) )
+            {
+                sb.append( line );
+                // check if the SQL statement was terminated
+                if ( line.endsWith( ";" ) )
+                {
+                    sqlList.add( sb.toString() );
+                    sb = new StringBuffer();
+                }
+            }
+            line = br.readLine();
+        }
+
+        if ( sb.length() > 0 )
+            sqlList.add( sb.toString() );
+
+        // System.out.println( "Running SQL statements..." );
+
+        // Execute list of SQL statements
+        for ( Iterator it = sqlList.iterator(); it.hasNext(); )
+        {
+            String sql = (String) it.next();
+
+            // System.out.println( sql );
+
+            try
+            {
+                Statement stmt = connection.createStatement();
+                stmt.execute( sql );
+                connection.commit();
+            }
+            catch ( SQLException e )
+            {
+                connection.rollback();
+                throw e;
+            }
+        }
+        // System.out.println( "Done!" );
+    }
+
+}

Propchange: maven/continuum/branches/key-based-refactor/continuum-store/src/test/java/org/apache/maven/continuum/store/ibatis/AbstractIbatisStoreTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/continuum/branches/key-based-refactor/continuum-store/src/test/java/org/apache/maven/continuum/store/ibatis/AbstractIbatisStoreTestCase.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

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=491397&r1=491396&r2=491397
==============================================================================
--- 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
Sat Dec 30 22:32:52 2006
@@ -50,7 +50,7 @@
     /**
      * Default location for SQL test data.
      */
-    private static final String SQL_TEST_DATA = "src/test/resources/testData.sql";
+    private static final String SQL_TEST_DATA = "src/test/resources/db/testData.sql";
 
     /**
      * Password to connect to the target test database instance.
@@ -75,7 +75,7 @@
     /**
      * DDL for Database creation.
      */
-    private static final File SQL_DATABSE_SCHEMA = getTestFile( getBasedir(), "src/test/resources/schema.sql"
);
+    private static final File SQL_DATABSE_SCHEMA = getTestFile( getBasedir(), "src/test/resources/db/schema.sql"
);
 
     /**
      * Provides an interface to clients to execute queries on the underlying

Added: maven/continuum/branches/key-based-refactor/continuum-store/src/test/resources/db/teardown.sql
URL: http://svn.apache.org/viewvc/maven/continuum/branches/key-based-refactor/continuum-store/src/test/resources/db/teardown.sql?view=auto&rev=491397
==============================================================================
--- maven/continuum/branches/key-based-refactor/continuum-store/src/test/resources/db/teardown.sql
(added)
+++ maven/continuum/branches/key-based-refactor/continuum-store/src/test/resources/db/teardown.sql
Sat Dec 30 22:32:52 2006
@@ -0,0 +1,28 @@
+# Drops all tables
+
+drop table BUILDDEFINITION;
+drop table BUILDRESULT;
+drop table BUILDRESULT_MODIFIEDDEPENDENCIES;
+drop table CHANGEFILE;
+drop table CHANGESET;
+drop table CONTINUUMMODELLOMETADATA;
+drop table INSTALLATION;
+drop table NOTIFICATIONADDRESS;
+drop table NOTIFICATIONADDRESS_CONFIGURATION;
+drop table PROFILE;
+drop table PROJECT;
+drop table PROJECTDEPENDENCY;
+drop table PROJECTDEVELOPER;
+drop table PROJECTGROUP;
+drop table PROJECTGROUP_BUILDDEFINITIONS;
+drop table PROJECTGROUP_NOTIFIERS;
+drop table PROJECTNOTIFIER;
+drop table PROJECTNOTIFIER_CONFIGURATION;
+drop table PROJECT_BUILDDEFINITIONS;
+drop table PROJECT_NOTIFIERS;
+drop table SCHEDULE;
+drop table SCMRESULT;
+drop table SUITERESULT;
+drop table SYSTEMCONFIGURATION;
+drop table TESTCASEFAILURE;
+drop table TESTRESULT;
\ No newline at end of file



Mime
View raw message