cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1126279 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit: CayenneResources.java di/server/CayenneResourcesProvider.java di/server/SchemaHelper.java
Date Mon, 23 May 2011 00:04:46 GMT
Author: aadamchik
Date: Mon May 23 00:04:46 2011
New Revision: 1126279

URL: http://svn.apache.org/viewvc?rev=1126279&view=rev
Log:
unit test refactoring

cleaning up access stack Spring stuff

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/CayenneResources.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/CayenneResourcesProvider.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/SchemaHelper.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/CayenneResources.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/CayenneResources.java?rev=1126279&r1=1126278&r2=1126279&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/CayenneResources.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/CayenneResources.java
Mon May 23 00:04:46 2011
@@ -19,32 +19,17 @@
 
 package org.apache.cayenne.unit;
 
-import java.sql.SQLException;
 import java.util.Map;
 
-import javax.sql.DataSource;
-
-import org.apache.cayenne.access.DataNode;
 import org.apache.cayenne.access.jdbc.BatchQueryBuilderFactory;
 import org.apache.cayenne.access.jdbc.DefaultBatchQueryBuilderFactory;
-import org.apache.cayenne.conn.DataSourceInfo;
-import org.apache.cayenne.conn.PoolDataSource;
-import org.apache.cayenne.conn.PoolManager;
 import org.apache.cayenne.dba.JdbcAdapter;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 
 /**
  * Initializes connections for Cayenne unit tests.
  */
 public class CayenneResources {
 
-    private static Log logger = LogFactory.getLog(CayenneResources.class);
-
-    public static final String SQL_TEMPLATE_CUSTOMIZER = "SQLTemplateCustomizer";
-
-    protected DataSourceInfo connectionInfo;
-    protected DataSource dataSource;
     protected Map<String, AccessStackAdapter> adapterMap;
 
     public CayenneResources(Map<String, AccessStackAdapter> adapterMap) {
@@ -58,11 +43,6 @@ public class CayenneResources {
 
     }
 
-    public void setConnectionInfo(DataSourceInfo connectionInfo) {
-        this.connectionInfo = connectionInfo;
-        this.dataSource = createDataSource();
-    }
-
     /**
      * Returns DB-specific testing adapter.
      */
@@ -76,52 +56,4 @@ public class CayenneResources {
 
         return stackAdapter;
     }
-
-    /**
-     * Returns shared DataSource.
-     */
-    public DataSource getDataSource() {
-        return dataSource;
-    }
-
-    /**
-     * Creates new DataNode.
-     */
-    public DataNode newDataNode(String name) throws Exception {
-        AccessStackAdapter adapter = getAccessStackAdapter(connectionInfo
-                .getAdapterClassName());
-
-        DataNode node = new DataNode(name);
-        node.setDataSource(dataSource);
-        node.setAdapter(adapter.getAdapter());
-        return node;
-    }
-
-    public DataSource createDataSource() {
-
-        try {
-            PoolDataSource poolDS = new PoolDataSource(
-                    connectionInfo.getJdbcDriver(),
-                    connectionInfo.getDataSourceUrl());
-            return new PoolManager(
-                    poolDS,
-                    1,
-                    1,
-                    connectionInfo.getUserName(),
-                    connectionInfo.getPassword()) {
-
-                @Override
-                public void shutdown() throws SQLException {
-                    // noop - make sure we are not shutdown by the test scope, but at the
-                    // same time PoolManager methods are exposed (so we can't wrap
-                    // PoolManager)
-                }
-            };
-        }
-        catch (Exception ex) {
-            logger.error("Can not create shared data source.", ex);
-            throw new RuntimeException("Can not create shared data source.", ex);
-        }
-    }
-
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/CayenneResourcesProvider.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/CayenneResourcesProvider.java?rev=1126279&r1=1126278&r2=1126279&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/CayenneResourcesProvider.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/CayenneResourcesProvider.java
Mon May 23 00:04:46 2011
@@ -80,8 +80,6 @@ public class CayenneResourcesProvider im
                 "TestResources",
                 CayenneResources.class);
 
-        resources.setConnectionInfo(dataSourceInfo);
-
         // rebuild schema after the resources instance is loaded so that after
         // possible initial failure we don't attempt rebuilding schema in subsequent
         // tests
@@ -120,7 +118,8 @@ public class CayenneResourcesProvider im
             maps[i] = new MapLoader().loadDataMap(in);
         }
 
-        SchemaHelper schemaHelper = new SchemaHelper(dataSource, resources, maps);
+        SchemaHelper schemaHelper = new SchemaHelper(dataSource, dataSourceInfo
+                .getAdapterClassName(), resources, maps);
 
         schemaHelper.dropSchema();
         schemaHelper.dropPKSupport();

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/SchemaHelper.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/SchemaHelper.java?rev=1126279&r1=1126278&r2=1126279&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/SchemaHelper.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/SchemaHelper.java
Mon May 23 00:04:46 2011
@@ -67,10 +67,12 @@ class SchemaHelper {
     protected CayenneResources resources;
     protected UnitTestDomain domain;
     private DataSource dataSource;
+    private String adapterClassName;
 
-    public SchemaHelper(DataSource dataSource, CayenneResources resources, DataMap[] maps)
-            throws Exception {
+    public SchemaHelper(DataSource dataSource, String adapterClassName,
+            CayenneResources resources, DataMap[] maps) throws Exception {
 
+        this.adapterClassName = adapterClassName;
         this.dataSource = dataSource;
         this.resources = resources;
         this.domain = new UnitTestDomain("domain");
@@ -88,7 +90,12 @@ class SchemaHelper {
     }
 
     private void initNode(DataMap map) throws Exception {
-        DataNode node = resources.newDataNode(map.getName());
+
+        AccessStackAdapter adapter = resources.getAccessStackAdapter(adapterClassName);
+
+        DataNode node = new DataNode(map.getName());
+        node.setAdapter(adapter.getAdapter());
+        node.setDataSource(dataSource);
 
         // setup test extended types
         node.getAdapter().getExtendedTypes().registerType(new StringET1ExtendedType());



Mime
View raw message