cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1126295 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit: ./ di/client/ di/server/
Date Mon, 23 May 2011 02:18:47 GMT
Author: aadamchik
Date: Mon May 23 02:18:46 2011
New Revision: 1126295

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

unwinding CayenneResources and friends

Added:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/AccessStackAdapterProvider.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDbAdapterProvider.java
      - copied, changed from r1126279, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/CayenneResourcesDbAdapterProvider.java
Removed:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/CayenneResourcesAccessStackAdapterProvider.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/CayenneResourcesDbAdapterProvider.java
Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/HSQLDBStackAdapter.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientCase.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCase.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseModule.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/HSQLDBStackAdapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/HSQLDBStackAdapter.java?rev=1126295&r1=1126294&r2=1126295&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/HSQLDBStackAdapter.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/HSQLDBStackAdapter.java
Mon May 23 02:18:46 2011
@@ -24,8 +24,6 @@ import java.sql.Connection;
 import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.map.DataMap;
 
-/**
- */
 public class HSQLDBStackAdapter extends AccessStackAdapter {
 
     public HSQLDBStackAdapter(DbAdapter adapter) {
@@ -36,7 +34,7 @@ public class HSQLDBStackAdapter extends 
     public boolean supportsLobs() {
         return true;
     }
-    
+
     /**
      * Note that out of all SP tests HSQLDB (as of 8.0.2) supports only updates that do
      * not return a ResultSet (see HSQL CallableStatement JavaDocs). Once HSQL implements

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientCase.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientCase.java?rev=1126295&r1=1126294&r2=1126295&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientCase.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientCase.java
Mon May 23 02:18:46 2011
@@ -21,6 +21,7 @@ package org.apache.cayenne.unit.di.clien
 import org.apache.cayenne.di.DIBootstrap;
 import org.apache.cayenne.di.Injector;
 import org.apache.cayenne.di.spi.DefaultScope;
+import org.apache.cayenne.unit.CayenneResources;
 import org.apache.cayenne.unit.di.DICase;
 import org.apache.cayenne.unit.di.server.ServerCaseModule;
 
@@ -37,6 +38,8 @@ public class ClientCase extends DICase {
         injector = DIBootstrap.createInjector(
                 new ServerCaseModule(testScope),
                 new ClientCaseModule(testScope));
+        // this triggers schema setup
+        injector.getInstance(CayenneResources.class);
     }
 
     @Override

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/AccessStackAdapterProvider.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/AccessStackAdapterProvider.java?rev=1126295&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/AccessStackAdapterProvider.java
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/AccessStackAdapterProvider.java
Mon May 23 02:18:46 2011
@@ -0,0 +1,83 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.
+ ****************************************************************/
+package org.apache.cayenne.unit.di.server;
+
+import java.lang.reflect.Constructor;
+import java.util.Map;
+
+import org.apache.cayenne.CayenneRuntimeException;
+import org.apache.cayenne.ConfigurationException;
+import org.apache.cayenne.conn.DataSourceInfo;
+import org.apache.cayenne.dba.DbAdapter;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.di.Provider;
+import org.apache.cayenne.unit.AccessStackAdapter;
+import org.apache.cayenne.util.Util;
+
+public class AccessStackAdapterProvider implements Provider<AccessStackAdapter> {
+
+    static final String TEST_ADAPTERS_MAP = "org.apache.cayenne.unit.di.server.CayenneResourcesAccessStackAdapterProvider.adapters";
+
+    private DbAdapter adapter;
+    private DataSourceInfo dataSourceInfo;
+    private Map<String, String> adapterTypesMap;
+
+    public AccessStackAdapterProvider(
+            @Inject(TEST_ADAPTERS_MAP) Map<String, String> adapterTypesMap,
+            @Inject DataSourceInfo dataSourceInfo, @Inject DbAdapter adapter) {
+        this.dataSourceInfo = dataSourceInfo;
+        this.adapterTypesMap = adapterTypesMap;
+        this.adapter = adapter;
+    }
+
+    public AccessStackAdapter get() throws ConfigurationException {
+
+        String testAdapterType = adapterTypesMap
+                .get(dataSourceInfo.getAdapterClassName());
+        if (testAdapterType == null) {
+            throw new IllegalStateException("Unmapped adapter type: "
+                    + dataSourceInfo.getAdapterClassName());
+        }
+
+        Class<AccessStackAdapter> type;
+        try {
+            type = (Class<AccessStackAdapter>) Util.getJavaClass(testAdapterType);
+        }
+        catch (ClassNotFoundException e) {
+            throw new CayenneRuntimeException(
+                    "Invalid class %s of type AccessStackAdapter",
+                    e,
+                    testAdapterType);
+        }
+
+        if (!AccessStackAdapter.class.isAssignableFrom(type)) {
+            throw new CayenneRuntimeException(
+                    "Class %s is not assignable to AccessStackAdapter",
+                    testAdapterType);
+        }
+
+        try {
+            Constructor<AccessStackAdapter> c = type.getConstructor(DbAdapter.class);
+            return c.newInstance(adapter);
+        }
+        catch (Exception e) {
+            throw new ConfigurationException("Error instantiating " + testAdapterType, e);
+        }
+    }
+}

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCase.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCase.java?rev=1126295&r1=1126294&r2=1126295&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCase.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCase.java
Mon May 23 02:18:46 2011
@@ -21,6 +21,7 @@ package org.apache.cayenne.unit.di.serve
 import org.apache.cayenne.di.DIBootstrap;
 import org.apache.cayenne.di.Injector;
 import org.apache.cayenne.di.spi.DefaultScope;
+import org.apache.cayenne.unit.CayenneResources;
 import org.apache.cayenne.unit.di.DICase;
 
 public class ServerCase extends DICase {
@@ -43,6 +44,9 @@ public class ServerCase extends DICase {
     static {
         DefaultScope testScope = new DefaultScope();
         injector = DIBootstrap.createInjector(new ServerCaseModule(testScope));
+        
+        // this triggers schema setup
+        injector.getInstance(CayenneResources.class);
     }
 
     @Override

Copied: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDbAdapterProvider.java
(from r1126279, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/CayenneResourcesDbAdapterProvider.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDbAdapterProvider.java?p2=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDbAdapterProvider.java&p1=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/CayenneResourcesDbAdapterProvider.java&r1=1126279&r2=1126295&rev=1126295&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/CayenneResourcesDbAdapterProvider.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDbAdapterProvider.java
Mon May 23 02:18:46 2011
@@ -19,29 +19,26 @@
 package org.apache.cayenne.unit.di.server;
 
 import org.apache.cayenne.ConfigurationException;
+import org.apache.cayenne.configuration.AdhocObjectFactory;
 import org.apache.cayenne.conn.DataSourceInfo;
 import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.di.Provider;
-import org.apache.cayenne.unit.AccessStackAdapter;
-import org.apache.cayenne.unit.CayenneResources;
 
-public class CayenneResourcesDbAdapterProvider implements Provider<DbAdapter> {
+public class ServerCaseDbAdapterProvider implements Provider<DbAdapter> {
 
-    private CayenneResources resources;
     private DataSourceInfo dataSourceInfo;
+    private AdhocObjectFactory objectFactory;
 
-    public CayenneResourcesDbAdapterProvider(@Inject CayenneResources resources,
-            @Inject DataSourceInfo dataSourceInfo) {
+    public ServerCaseDbAdapterProvider(@Inject DataSourceInfo dataSourceInfo,
+            @Inject AdhocObjectFactory objectFactory) {
         this.dataSourceInfo = dataSourceInfo;
-        this.resources = resources;
+        this.objectFactory = objectFactory;
     }
 
     public DbAdapter get() throws ConfigurationException {
 
-        AccessStackAdapter adapter = resources.getAccessStackAdapter(dataSourceInfo
+        return objectFactory.newInstance(DbAdapter.class, dataSourceInfo
                 .getAdapterClassName());
-
-        return adapter.getAdapter();
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseModule.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseModule.java?rev=1126295&r1=1126294&r2=1126295&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseModule.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseModule.java
Mon May 23 02:18:46 2011
@@ -24,9 +24,24 @@ import org.apache.cayenne.ObjectContext;
 import org.apache.cayenne.access.DataContext;
 import org.apache.cayenne.access.DataNode;
 import org.apache.cayenne.access.jdbc.BatchQueryBuilderFactory;
+import org.apache.cayenne.configuration.AdhocObjectFactory;
+import org.apache.cayenne.configuration.DefaultAdhocObjectFactory;
 import org.apache.cayenne.configuration.server.ServerRuntime;
 import org.apache.cayenne.conn.DataSourceInfo;
 import org.apache.cayenne.dba.DbAdapter;
+import org.apache.cayenne.dba.db2.DB2Adapter;
+import org.apache.cayenne.dba.frontbase.FrontBaseAdapter;
+import org.apache.cayenne.dba.h2.H2Adapter;
+import org.apache.cayenne.dba.hsqldb.HSQLDBAdapter;
+import org.apache.cayenne.dba.ingres.IngresAdapter;
+import org.apache.cayenne.dba.mysql.MySQLAdapter;
+import org.apache.cayenne.dba.openbase.OpenBaseAdapter;
+import org.apache.cayenne.dba.oracle.Oracle8Adapter;
+import org.apache.cayenne.dba.oracle.OracleAdapter;
+import org.apache.cayenne.dba.postgres.PostgresAdapter;
+import org.apache.cayenne.dba.sqlite.SQLiteAdapter;
+import org.apache.cayenne.dba.sqlserver.SQLServerAdapter;
+import org.apache.cayenne.dba.sybase.SybaseAdapter;
 import org.apache.cayenne.di.Binder;
 import org.apache.cayenne.di.Module;
 import org.apache.cayenne.di.spi.DefaultScope;
@@ -36,6 +51,18 @@ import org.apache.cayenne.map.EntityReso
 import org.apache.cayenne.test.jdbc.DBHelper;
 import org.apache.cayenne.unit.AccessStackAdapter;
 import org.apache.cayenne.unit.CayenneResources;
+import org.apache.cayenne.unit.DB2StackAdapter;
+import org.apache.cayenne.unit.FrontBaseStackAdapter;
+import org.apache.cayenne.unit.H2StackAdapter;
+import org.apache.cayenne.unit.HSQLDBStackAdapter;
+import org.apache.cayenne.unit.IngresStackAdapter;
+import org.apache.cayenne.unit.MySQLStackAdapter;
+import org.apache.cayenne.unit.OpenBaseStackAdapter;
+import org.apache.cayenne.unit.OracleStackAdapter;
+import org.apache.cayenne.unit.PostgresStackAdapter;
+import org.apache.cayenne.unit.SQLServerStackAdapter;
+import org.apache.cayenne.unit.SQLiteStackAdapter;
+import org.apache.cayenne.unit.SybaseStackAdapter;
 import org.apache.cayenne.unit.di.DataChannelInterceptor;
 import org.apache.cayenne.unit.di.UnitTestLifecycleManager;
 import org.apache.cayenne.unit.util.SQLTemplateCustomizer;
@@ -56,6 +83,34 @@ public class ServerCaseModule implements
         // unit test injector. ServerRuntime injector contents are customized
         // inside ServerRuntimeProvider.
 
+        binder.bindMap(AccessStackAdapterProvider.TEST_ADAPTERS_MAP).put(
+                OracleAdapter.class.getName(),
+                OracleStackAdapter.class.getName()).put(
+                Oracle8Adapter.class.getName(),
+                OracleStackAdapter.class.getName()).put(
+                SybaseAdapter.class.getName(),
+                SybaseStackAdapter.class.getName()).put(
+                MySQLAdapter.class.getName(),
+                MySQLStackAdapter.class.getName()).put(
+                PostgresAdapter.class.getName(),
+                PostgresStackAdapter.class.getName()).put(
+                OpenBaseAdapter.class.getName(),
+                OpenBaseStackAdapter.class.getName()).put(
+                SQLServerAdapter.class.getName(),
+                SQLServerStackAdapter.class.getName()).put(
+                DB2Adapter.class.getName(),
+                DB2StackAdapter.class.getName()).put(
+                HSQLDBAdapter.class.getName(),
+                HSQLDBStackAdapter.class.getName()).put(
+                H2Adapter.class.getName(),
+                H2StackAdapter.class.getName()).put(
+                FrontBaseAdapter.class.getName(),
+                FrontBaseStackAdapter.class.getName()).put(
+                IngresAdapter.class.getName(),
+                IngresStackAdapter.class.getName()).put(
+                SQLiteAdapter.class.getName(),
+                SQLiteStackAdapter.class.getName());
+
         binder.bind(CayenneResources.class).toProvider(CayenneResourcesProvider.class);
         binder.bind(JdbcEventLogger.class).to(CommonsJdbcEventLogger.class);
 
@@ -68,9 +123,10 @@ public class ServerCaseModule implements
         binder
                 .bind(DataSource.class)
                 .toProvider(ServerCaseSharedDataSourceProvider.class);
-        binder.bind(DbAdapter.class).toProvider(CayenneResourcesDbAdapterProvider.class);
-        binder.bind(AccessStackAdapter.class).toProvider(
-                CayenneResourcesAccessStackAdapterProvider.class);
+        binder.bind(DbAdapter.class).toProvider(ServerCaseDbAdapterProvider.class);
+        binder
+                .bind(AccessStackAdapter.class)
+                .toProvider(AccessStackAdapterProvider.class);
         binder.bind(BatchQueryBuilderFactory.class).toProvider(
                 ServerCaseBatchQueryBuilderFactoryProvider.class);
         binder.bind(DataChannelInterceptor.class).to(
@@ -79,6 +135,7 @@ public class ServerCaseModule implements
                 SQLTemplateCustomizerProvider.class);
         binder.bind(ServerCaseDataSourceFactory.class).to(
                 ServerCaseDataSourceFactory.class);
+        binder.bind(AdhocObjectFactory.class).to(DefaultAdhocObjectFactory.class);
 
         // test-scoped objects
         binder.bind(EntityResolver.class).toProvider(



Mime
View raw message