cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1073909 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/dba/AutoAdapter.java test/java/org/apache/cayenne/dba/AutoAdapterTest.java test/java/org/apache/cayenne/dba/MockDbAdapterFactory.java
Date Wed, 23 Feb 2011 19:47:40 GMT
Author: aadamchik
Date: Wed Feb 23 19:47:40 2011
New Revision: 1073909

URL: http://svn.apache.org/viewvc?rev=1073909&view=rev
Log:
tests cleanup

    switching to DI
switching to mockito

Removed:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/dba/MockDbAdapterFactory.java
Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/AutoAdapter.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/dba/AutoAdapterTest.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/AutoAdapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/AutoAdapter.java?rev=1073909&r1=1073908&r2=1073909&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/AutoAdapter.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/AutoAdapter.java
Wed Feb 23 19:47:40 2011
@@ -128,9 +128,7 @@ public class AutoAdapter implements DbAd
     /**
      * Creates an AutoAdapter that can detect adapters known to Cayenne.
      * 
-     * @deprecated since 3.1 as
-     *             {@link org.apache.cayenne.configuration.server.DbAdapterFactory}
-     *             parameter is required.
+     * @deprecated since 3.1 use {@link #AutoAdapter(Provider)}
      */
     public AutoAdapter(DataSource dataSource) {
         this((DbAdapterFactory) null, dataSource);
@@ -140,9 +138,7 @@ public class AutoAdapter implements DbAd
      * Creates an AutoAdapter with specified adapter factory and DataSource. If
      * adapterFactory is null, default factory is used.
      * 
-     * @deprecated since 3.1 in favor of
-     *             {@link org.apache.cayenne.configuration.server.DbAdapterFactory}
-     *             configured via dependency injection.
+     * @deprecated since 3.1 use {@link #AutoAdapter(Provider)}
      */
     public AutoAdapter(DbAdapterFactory adapterFactory, final DataSource dataSource) {
         // sanity check
@@ -244,8 +240,6 @@ public class AutoAdapter implements DbAd
         return adapterProvider.get();
     }
 
-    // ---- DbAdapter methods ----
-
     public String getBatchTerminator() {
         return getAdapter().getBatchTerminator();
     }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/dba/AutoAdapterTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/dba/AutoAdapterTest.java?rev=1073909&r1=1073908&r2=1073909&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/dba/AutoAdapterTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/dba/AutoAdapterTest.java
Wed Feb 23 19:47:40 2011
@@ -19,64 +19,47 @@
 
 package org.apache.cayenne.dba;
 
-import java.sql.DatabaseMetaData;
-import java.sql.SQLException;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 
+import org.apache.cayenne.access.DataNode;
 import org.apache.cayenne.access.jdbc.SQLTemplateAction;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.di.Provider;
 import org.apache.cayenne.query.SQLTemplate;
 import org.apache.cayenne.testdo.testmap.Artist;
-import org.apache.cayenne.unit.CayenneCase;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
 
-import com.mockrunner.mock.jdbc.MockConnection;
-import com.mockrunner.mock.jdbc.MockDataSource;
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class AutoAdapterTest extends ServerCase {
 
-public class AutoAdapterTest extends CayenneCase {
+    @Inject
+    private DataNode dataNode;
 
-    public void testAddFactory() {
+    public void testGetAdapter_Proxy() throws Exception {
+        Provider<DbAdapter> adapterProvider = mock(Provider.class);
+        when(adapterProvider.get()).thenReturn(dataNode.getAdapter());
 
-        DbAdapterFactory mockFactory = new DbAdapterFactory() {
-
-            public DbAdapter createAdapter(DatabaseMetaData md) throws SQLException {
-                return null;
-            }
-        };
-        AutoAdapter.addFactory(mockFactory);
-        assertTrue(AutoAdapter.defaultFactories.contains(mockFactory));
-        AutoAdapter.defaultFactories.remove(mockFactory);
-    }
-
-    public void testGetAdapter() {
-        MockDbAdapter realAdapter = new MockDbAdapter();
-        MockDbAdapterFactory factory = new MockDbAdapterFactory(realAdapter);
-
-        MockDataSource dataSource = new MockDataSource();
-        dataSource.setupConnection(new MockConnection());
-        AutoAdapter adapter = new AutoAdapter(factory, dataSource);
-
-        assertSame(realAdapter, adapter.getAdapter());
-    }
-
-    public void testGetDefaultAdapter() throws Exception {
-
-        AutoAdapter adapter = new AutoAdapter(getNode().getDataSource());
+        AutoAdapter adapter = new AutoAdapter(adapterProvider);
         DbAdapter detected = adapter.getAdapter();
-
-        assertNotNull(detected);
-        assertEquals(getNode().getAdapter().getClass(), detected.getClass());
+        assertSame(dataNode.getAdapter(), detected);
     }
 
     public void testCreateSQLTemplateAction() {
 
-        AutoAdapter adapter = new AutoAdapter(getNode().getDataSource());
+        Provider<DbAdapter> adapterProvider = mock(Provider.class);
+        when(adapterProvider.get()).thenReturn(dataNode.getAdapter());
+
+        AutoAdapter adapter = new AutoAdapter(adapterProvider);
         SQLTemplateAction action = (SQLTemplateAction) adapter.getAction(new SQLTemplate(
                 Artist.class,
-                "select * from artist"), getNode());
+                "select * from artist"), dataNode);
 
         // it is important for SQLTemplateAction to be used with unwrapped adapter, as the
         // adapter class name is used as a key to the correct SQL template.
-        assertNotNull(action);
         assertNotNull(action.getAdapter());
         assertFalse(action.getAdapter() instanceof AutoAdapter);
-        assertSame(adapter.getAdapter(), action.getAdapter());
+        assertSame(dataNode.getAdapter(), action.getAdapter());
     }
 }



Mime
View raw message