cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r956400 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/configuration/rop/client/ test/java/org/apache/cayenne/ test/java/org/apache/cayenne/access/ test/java/org/apache/cayenne/unit/di/ test/...
Date Sun, 20 Jun 2010 20:11:31 GMT
Author: aadamchik
Date: Sun Jun 20 20:11:30 2010
New Revision: 956400

URL: http://svn.apache.org/viewvc?rev=956400&view=rev
Log:
DI-enabled unit tests

* switching more test cases
* clientserverchannel interceptor for tests

Added:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/LocalClientServerChannelProvider.java
      - copied, changed from r956370, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/LocalConnectionProvider.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextCayenneTest.java
      - copied, changed from r956370, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextDataObjectUtilsTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/DataChannelInterceptor.java
      - copied, changed from r956370, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/DataChannelQueryInterceptor.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/DataChannelSyncStats.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientCaseCayenneContextProvider.java
      - copied, changed from r956370, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientServerChannelProvider.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientServerDataChannelDecorator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientServerDataChannelInterceptor.java
      - copied, changed from r956370, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataChannelQueryInterceptor.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/InterceptingClientServerChannelProvider.java
      - copied, changed from r956370, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientServerChannelProvider.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataChannelInterceptor.java
      - copied, changed from r956370, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataChannelQueryInterceptor.java
Removed:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextDataObjectUtilsTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/DataChannelQueryInterceptor.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataChannelQueryInterceptor.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/dml/CayenneContextEJBQLTest.xml
Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/ClientLocalRuntime.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/LocalConnectionProvider.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextDeleteRulesTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextEJBQLTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextGraphDiffCompressorTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextInheritanceTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextMergeHandlerTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/ClientServerChannelTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLFetchJoinTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPerformQueryAPITest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPrefetchTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextRefreshingTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/SimpleIdIncrementalFaultListPrefetchTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientCaseModule.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientRuntimeProvider.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientServerChannelProvider.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseModule.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerRuntimeProvider.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/ClientLocalRuntime.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/ClientLocalRuntime.java?rev=956400&r1=956399&r2=956400&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/ClientLocalRuntime.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/ClientLocalRuntime.java Sun Jun 20 20:11:30 2010
@@ -21,36 +21,44 @@ package org.apache.cayenne.configuration
 import java.util.Collection;
 import java.util.Map;
 
+import org.apache.cayenne.DataChannel;
 import org.apache.cayenne.di.Binder;
 import org.apache.cayenne.di.Injector;
+import org.apache.cayenne.di.Key;
 import org.apache.cayenne.di.Module;
 import org.apache.cayenne.remote.ClientConnection;
 
 /**
- * A {@link ClientRuntime} that provides an ROP stack based on a local connection
- * on top of a server stack.
+ * A {@link ClientRuntime} that provides an ROP stack based on a local connection on top
+ * of a server stack.
  * 
  * @since 3.1
  */
 public class ClientLocalRuntime extends ClientRuntime {
 
+    public static final String CLIENT_SERVER_CHANNEL_KEY = "client-server-channel";
+
     private static Module mainModuleOverride(final Injector serverInjector) {
         return new Module() {
 
             public void configure(Binder binder) {
+                binder
+                        .bind(Key.get(DataChannel.class, CLIENT_SERVER_CHANNEL_KEY))
+                        .toProviderInstance(
+                                new LocalClientServerChannelProvider(serverInjector));
                 binder.bind(ClientConnection.class).toProviderInstance(
-                        new LocalConnectionProvider(serverInjector));
+                        new LocalConnectionProvider());
             }
         };
     }
 
-    public ClientLocalRuntime(Injector serverInjector,
-            Map<String, String> properties, Collection<Module> extraModules) {
+    public ClientLocalRuntime(Injector serverInjector, Map<String, String> properties,
+            Collection<Module> extraModules) {
         super(properties, mergeModules(mainModuleOverride(serverInjector), extraModules));
     }
 
-    public ClientLocalRuntime(Injector serverInjector,
-            Map<String, String> properties, Module... extraModules) {
+    public ClientLocalRuntime(Injector serverInjector, Map<String, String> properties,
+            Module... extraModules) {
         super(properties, mergeModules(mainModuleOverride(serverInjector), extraModules));
     }
 

Copied: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/LocalClientServerChannelProvider.java (from r956370, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/LocalConnectionProvider.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/LocalClientServerChannelProvider.java?p2=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/LocalClientServerChannelProvider.java&p1=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/LocalConnectionProvider.java&r1=956370&r2=956400&rev=956400&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/LocalConnectionProvider.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/LocalClientServerChannelProvider.java Sun Jun 20 20:11:30 2010
@@ -25,30 +25,27 @@ import org.apache.cayenne.access.DataCon
 import org.apache.cayenne.configuration.ObjectContextFactory;
 import org.apache.cayenne.di.Injector;
 import org.apache.cayenne.di.Provider;
-import org.apache.cayenne.remote.ClientConnection;
 import org.apache.cayenne.remote.service.LocalConnection;
 
 /**
+ * Creates a {@link ClientServerChannel} for the {@link LocalConnection}.
+ * 
  * @since 3.1
  */
-public class LocalConnectionProvider implements Provider<ClientConnection> {
+public class LocalClientServerChannelProvider implements Provider<DataChannel> {
 
     protected Injector serverInjector;
 
-    public LocalConnectionProvider(Injector serverInjector) {
+    public LocalClientServerChannelProvider(Injector serverInjector) {
         this.serverInjector = serverInjector;
     }
 
-    public ClientConnection get() throws ConfigurationException {
-
+    public DataChannel get() throws ConfigurationException {
         ObjectContextFactory factory = serverInjector
                 .getInstance(ObjectContextFactory.class);
 
         // TODO: ugly cast
         DataContext serverContext = (DataContext) factory.createContext();
-        DataChannel clientServerChannel = new ClientServerChannel(serverContext);
-        return new LocalConnection(
-                clientServerChannel,
-                LocalConnection.HESSIAN_SERIALIZATION);
+        return new ClientServerChannel(serverContext);
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/LocalConnectionProvider.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/LocalConnectionProvider.java?rev=956400&r1=956399&r2=956400&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/LocalConnectionProvider.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/LocalConnectionProvider.java Sun Jun 20 20:11:30 2010
@@ -20,10 +20,7 @@ package org.apache.cayenne.configuration
 
 import org.apache.cayenne.ConfigurationException;
 import org.apache.cayenne.DataChannel;
-import org.apache.cayenne.access.ClientServerChannel;
-import org.apache.cayenne.access.DataContext;
-import org.apache.cayenne.configuration.ObjectContextFactory;
-import org.apache.cayenne.di.Injector;
+import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.di.Provider;
 import org.apache.cayenne.remote.ClientConnection;
 import org.apache.cayenne.remote.service.LocalConnection;
@@ -33,20 +30,12 @@ import org.apache.cayenne.remote.service
  */
 public class LocalConnectionProvider implements Provider<ClientConnection> {
 
-    protected Injector serverInjector;
-
-    public LocalConnectionProvider(Injector serverInjector) {
-        this.serverInjector = serverInjector;
-    }
+    @Inject(ClientLocalRuntime.CLIENT_SERVER_CHANNEL_KEY)
+    protected Provider<DataChannel> clientServerChannelProvider;
 
     public ClientConnection get() throws ConfigurationException {
 
-        ObjectContextFactory factory = serverInjector
-                .getInstance(ObjectContextFactory.class);
-
-        // TODO: ugly cast
-        DataContext serverContext = (DataContext) factory.createContext();
-        DataChannel clientServerChannel = new ClientServerChannel(serverContext);
+        DataChannel clientServerChannel = clientServerChannelProvider.get();
         return new LocalConnection(
                 clientServerChannel,
                 LocalConnection.HESSIAN_SERIALIZATION);

Copied: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextCayenneTest.java (from r956370, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextDataObjectUtilsTest.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextCayenneTest.java?p2=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextCayenneTest.java&p1=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextDataObjectUtilsTest.java&r1=956370&r2=956400&rev=956400&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextDataObjectUtilsTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextCayenneTest.java Sun Jun 20 20:11:30 2010
@@ -18,37 +18,30 @@
  ****************************************************************/
 package org.apache.cayenne;
 
-import org.apache.cayenne.access.ClientServerChannel;
+import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.query.SQLTemplate;
-import org.apache.cayenne.remote.ClientChannel;
-import org.apache.cayenne.remote.service.LocalConnection;
+import org.apache.cayenne.test.jdbc.DBHelper;
 import org.apache.cayenne.testdo.mt.ClientMtTable1;
-import org.apache.cayenne.unit.AccessStack;
-import org.apache.cayenne.unit.CayenneCase;
-import org.apache.cayenne.unit.CayenneResources;
+import org.apache.cayenne.unit.di.client.ClientCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
 
-public class CayenneContextDataObjectUtilsTest extends CayenneCase {
+@UseServerRuntime(ClientCase.MULTI_TIER_PROJECT)
+public class CayenneContextCayenneTest extends ClientCase {
 
-    @Override
-    protected AccessStack buildAccessStack() {
-        return CayenneResources.getResources().getAccessStack(MULTI_TIER_ACCESS_STACK);
-    }
+    @Inject
+    private DBHelper dbHelper;
+
+    @Inject
+    private CayenneContext context;
 
-    private CayenneContext createClientContext() {
-        ClientServerChannel serverChannel = new ClientServerChannel(getDomain());
-        LocalConnection connection = new LocalConnection(
-                serverChannel,
-                LocalConnection.HESSIAN_SERIALIZATION);
-        ClientChannel clientChannel = new ClientChannel(connection);
-        return new CayenneContext(clientChannel);
+    @Override
+    protected void setUpAfterInjection() throws Exception {
+        dbHelper.deleteAll("MT_TABLE2");
+        dbHelper.deleteAll("MT_TABLE1");
     }
 
     public void testObjectForPK() throws Exception {
 
-        deleteTestData();
-
-        CayenneContext context = createClientContext();
-
         context.performGenericQuery(new SQLTemplate(
                 ClientMtTable1.class,
                 "insert into MT_TABLE1 "

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextDeleteRulesTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextDeleteRulesTest.java?rev=956400&r1=956399&r2=956400&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextDeleteRulesTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextDeleteRulesTest.java Sun Jun 20 20:11:30 2010
@@ -19,42 +19,26 @@
 
 package org.apache.cayenne;
 
-import org.apache.cayenne.access.ClientServerChannel;
-import org.apache.cayenne.remote.ClientChannel;
-import org.apache.cayenne.remote.service.LocalConnection;
+import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.testdo.mt.ClientMtDeleteCascade;
 import org.apache.cayenne.testdo.mt.ClientMtDeleteDeny;
 import org.apache.cayenne.testdo.mt.ClientMtDeleteNullify;
 import org.apache.cayenne.testdo.mt.ClientMtDeleteRule;
-import org.apache.cayenne.unit.AccessStack;
-import org.apache.cayenne.unit.CayenneCase;
-import org.apache.cayenne.unit.CayenneResources;
-
-public class CayenneContextDeleteRulesTest extends CayenneCase {
-
-    @Override
-    protected AccessStack buildAccessStack() {
-        return CayenneResources
-                .getResources()
-                .getAccessStack(MULTI_TIER_ACCESS_STACK);
-    }
+import org.apache.cayenne.unit.di.client.ClientCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
 
-    private CayenneContext createClientContext() {
-        ClientServerChannel serverChannel = new ClientServerChannel(getDomain());
-        LocalConnection connection = new LocalConnection(serverChannel);
-        ClientChannel clientChannel = new ClientChannel(connection);
-        return new CayenneContext(clientChannel);
-    }
+@UseServerRuntime(ClientCase.MULTI_TIER_PROJECT)
+public class CayenneContextDeleteRulesTest extends ClientCase {
+
+    @Inject
+    private CayenneContext context;
 
     public void testNullifyToOne() {
-        CayenneContext context = createClientContext();
 
-        ClientMtDeleteNullify object = context
-                .newObject(ClientMtDeleteNullify.class);
+        ClientMtDeleteNullify object = context.newObject(ClientMtDeleteNullify.class);
         object.setName("object");
 
-        ClientMtDeleteRule related = context
-                .newObject(ClientMtDeleteRule.class);
+        ClientMtDeleteRule related = context.newObject(ClientMtDeleteRule.class);
         object.setName("related");
 
         object.setNullify(related);
@@ -70,12 +54,8 @@ public class CayenneContextDeleteRulesTe
 
     public void testDenyToOne() {
 
-        CayenneContext context = createClientContext();
-
-        ClientMtDeleteDeny object = context
-                .newObject(ClientMtDeleteDeny.class);
-        ClientMtDeleteRule related = context
-                .newObject(ClientMtDeleteRule.class);
+        ClientMtDeleteDeny object = context.newObject(ClientMtDeleteDeny.class);
+        ClientMtDeleteRule related = context.newObject(ClientMtDeleteRule.class);
         object.setDeny(related);
         context.commitChanges();
 
@@ -93,14 +73,11 @@ public class CayenneContextDeleteRulesTe
     }
 
     public void testCascadeToOne() {
-        CayenneContext context = createClientContext();
 
-        ClientMtDeleteCascade object = context
-                .newObject(ClientMtDeleteCascade.class);
+        ClientMtDeleteCascade object = context.newObject(ClientMtDeleteCascade.class);
         object.setName("object");
 
-        ClientMtDeleteRule related = context
-                .newObject(ClientMtDeleteRule.class);
+        ClientMtDeleteRule related = context.newObject(ClientMtDeleteRule.class);
         object.setName("related");
 
         object.setCascade(related);
@@ -115,14 +92,11 @@ public class CayenneContextDeleteRulesTe
     }
 
     public void testCascadeToOneNewObject() {
-        CayenneContext context = createClientContext();
 
-        ClientMtDeleteRule related = context
-                .newObject(ClientMtDeleteRule.class);
+        ClientMtDeleteRule related = context.newObject(ClientMtDeleteRule.class);
         context.commitChanges();
 
-        ClientMtDeleteCascade object = context
-                .newObject(ClientMtDeleteCascade.class);
+        ClientMtDeleteCascade object = context.newObject(ClientMtDeleteCascade.class);
         object.setName("object");
         object.setCascade(related);
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextEJBQLTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextEJBQLTest.java?rev=956400&r1=956399&r2=956400&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextEJBQLTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextEJBQLTest.java Sun Jun 20 20:11:30 2010
@@ -20,44 +20,40 @@ package org.apache.cayenne;
 
 import java.util.List;
 
-import org.apache.cayenne.access.ClientServerChannel;
-import org.apache.cayenne.access.DataContext;
+import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.query.EJBQLQuery;
-import org.apache.cayenne.remote.ClientChannel;
-import org.apache.cayenne.remote.service.LocalConnection;
+import org.apache.cayenne.test.jdbc.DBHelper;
+import org.apache.cayenne.test.jdbc.TableHelper;
 import org.apache.cayenne.testdo.mt.ClientMtTable1;
-import org.apache.cayenne.unit.AccessStack;
-import org.apache.cayenne.unit.CayenneCase;
-import org.apache.cayenne.unit.CayenneResources;
-import org.apache.cayenne.unit.UnitLocalConnection;
+import org.apache.cayenne.unit.di.client.ClientCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
 
-public class CayenneContextEJBQLTest extends CayenneCase {
+@UseServerRuntime(ClientCase.MULTI_TIER_PROJECT)
+public class CayenneContextEJBQLTest extends ClientCase {
 
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-        deleteTestData();
-    }
+    @Inject
+    private DBHelper dbHelper;
+
+    @Inject
+    private CayenneContext context;
+
+    private TableHelper tMtTable1;
 
     @Override
-    protected AccessStack buildAccessStack() {
-        return CayenneResources.getResources().getAccessStack(MULTI_TIER_ACCESS_STACK);
+    protected void setUpAfterInjection() throws Exception {
+        dbHelper.deleteAll("MT_TABLE2");
+        dbHelper.deleteAll("MT_TABLE1");
+
+        tMtTable1 = new TableHelper(dbHelper, "MT_TABLE1");
+        tMtTable1.setColumns("TABLE1_ID", "GLOBAL_ATTRIBUTE1", "SERVER_ATTRIBUTE1");
     }
 
     public void testEJBQLSelect() throws Exception {
-        createTestData("testEJBQLSelect");
-        
-        DataContext context = createDataContext();
-        ClientServerChannel clientServerChannel = new ClientServerChannel(context);
-        UnitLocalConnection connection = new UnitLocalConnection(
-                clientServerChannel,
-                LocalConnection.HESSIAN_SERIALIZATION);
-        ClientChannel channel = new ClientChannel(connection);
-        CayenneContext clientContext = new CayenneContext(channel);
+        tMtTable1.insert(1, "g1", "s1");
+        tMtTable1.insert(2, "g2", "s2");
 
         EJBQLQuery query = new EJBQLQuery("SELECT a FROM MtTable1 a");
-
-        List<ClientMtTable1> results = clientContext.performQuery(query);
+        List<ClientMtTable1> results = context.performQuery(query);
         assertEquals(2, results.size());
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextGraphDiffCompressorTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextGraphDiffCompressorTest.java?rev=956400&r1=956399&r2=956400&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextGraphDiffCompressorTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextGraphDiffCompressorTest.java Sun Jun 20 20:11:30 2010
@@ -18,130 +18,79 @@
  ****************************************************************/
 package org.apache.cayenne;
 
-import org.apache.cayenne.access.ClientServerChannel;
-import org.apache.cayenne.access.DataDomain;
-import org.apache.cayenne.graph.GraphChangeHandler;
-import org.apache.cayenne.graph.GraphDiff;
-import org.apache.cayenne.remote.ClientChannel;
-import org.apache.cayenne.remote.service.LocalConnection;
+import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.testdo.mt.ClientMtTable1;
 import org.apache.cayenne.testdo.mt.ClientMtTable2;
-import org.apache.cayenne.unit.AccessStack;
-import org.apache.cayenne.unit.CayenneCase;
-import org.apache.cayenne.unit.CayenneResources;
-
-public class CayenneContextGraphDiffCompressorTest extends CayenneCase {
-
-    @Override
-    protected AccessStack buildAccessStack() {
-        return CayenneResources.getResources().getAccessStack(MULTI_TIER_ACCESS_STACK);
-    }
+import org.apache.cayenne.unit.di.DataChannelInterceptor;
+import org.apache.cayenne.unit.di.DataChannelSyncStats;
+import org.apache.cayenne.unit.di.UnitTestClosure;
+import org.apache.cayenne.unit.di.client.ClientCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+@UseServerRuntime(ClientCase.MULTI_TIER_PROJECT)
+public class CayenneContextGraphDiffCompressorTest extends ClientCase {
+
+    @Inject(ClientCase.ROP_CLIENT_KEY)
+    protected DataChannelInterceptor clientServerInterceptor;
+
+    @Inject
+    protected CayenneContext context;
 
     public void testMultipleSimpleProperties() {
-        DiffCounter serverChannel = new DiffCounter(getDomain());
-        LocalConnection connection = new LocalConnection(
-                serverChannel,
-                LocalConnection.HESSIAN_SERIALIZATION);
-        ClientChannel channel = new ClientChannel(connection);
-        CayenneContext context = new CayenneContext(channel);
 
         ClientMtTable1 o1 = context.newObject(ClientMtTable1.class);
         o1.setGlobalAttribute1("v1");
         o1.setGlobalAttribute1("v2");
 
-        context.commitChanges();
-        assertEquals(1, serverChannel.nodePropertiesChanged);
-        assertEquals(1, serverChannel.nodesCreated);
+        DataChannelSyncStats stats = clientServerInterceptor
+                .runWithSyncStatsCollection(new UnitTestClosure() {
+
+                    public void execute() {
+                        context.commitChanges();
+                    }
+                });
+
+        assertEquals(1, stats.nodePropertiesChanged);
+        assertEquals(1, stats.nodesCreated);
     }
 
     public void testComplimentaryArcs() {
-        DiffCounter serverChannel = new DiffCounter(getDomain());
-        LocalConnection connection = new LocalConnection(
-                serverChannel,
-                LocalConnection.HESSIAN_SERIALIZATION);
-        ClientChannel channel = new ClientChannel(connection);
-        CayenneContext context = new CayenneContext(channel);
 
         ClientMtTable1 o1 = context.newObject(ClientMtTable1.class);
         ClientMtTable2 o2 = context.newObject(ClientMtTable2.class);
         o2.setTable1(o1);
         o2.setTable1(null);
 
-        context.commitChanges();
-        assertEquals(0, serverChannel.nodePropertiesChanged);
-        assertEquals(2, serverChannel.nodesCreated);
-        assertEquals(0, serverChannel.arcsCreated);
-        assertEquals(0, serverChannel.arcsDeleted);
+        DataChannelSyncStats stats = clientServerInterceptor
+                .runWithSyncStatsCollection(new UnitTestClosure() {
+
+                    public void execute() {
+                        context.commitChanges();
+                    }
+                });
+
+        assertEquals(0, stats.nodePropertiesChanged);
+        assertEquals(2, stats.nodesCreated);
+        assertEquals(0, stats.arcsCreated);
+        assertEquals(0, stats.arcsDeleted);
     }
 
     public void testDelete() {
-        DiffCounter serverChannel = new DiffCounter(getDomain());
-        LocalConnection connection = new LocalConnection(
-                serverChannel,
-                LocalConnection.HESSIAN_SERIALIZATION);
-        ClientChannel channel = new ClientChannel(connection);
-        CayenneContext context = new CayenneContext(channel);
 
         ClientMtTable1 o1 = context.newObject(ClientMtTable1.class);
         o1.setGlobalAttribute1("v1");
         context.deleteObject(o1);
 
-        context.commitChanges();
-        assertEquals(0, serverChannel.nodePropertiesChanged);
-        assertEquals(0, serverChannel.nodesCreated);
-        assertEquals(0, serverChannel.nodesRemoved);
-    }
+        DataChannelSyncStats stats = clientServerInterceptor
+                .runWithSyncStatsCollection(new UnitTestClosure() {
 
-    final class DiffCounter extends ClientServerChannel implements GraphChangeHandler {
-
-        int arcsCreated;
-        int arcsDeleted;
-        int nodesCreated;
-        int nodeIdsChanged;
-        int nodePropertiesChanged;
-        int nodesRemoved;
-
-        public DiffCounter(DataDomain domain) {
-            super(domain);
-        }
-
-        @Override
-        public GraphDiff onSync(
-                ObjectContext originatingContext,
-                GraphDiff changes,
-                int syncType) {
-
-            changes.apply(this);
-
-            return super.onSync(originatingContext, changes, syncType);
-        }
-
-        public void arcCreated(Object nodeId, Object targetNodeId, Object arcId) {
-            arcsCreated++;
-        }
-
-        public void arcDeleted(Object nodeId, Object targetNodeId, Object arcId) {
-            arcsDeleted++;
-        }
-
-        public void nodeCreated(Object nodeId) {
-            nodesCreated++;
-        }
-
-        public void nodeIdChanged(Object nodeId, Object newId) {
-            nodeIdsChanged++;
-        }
-
-        public void nodePropertyChanged(
-                Object nodeId,
-                String property,
-                Object oldValue,
-                Object newValue) {
-            nodePropertiesChanged++;
-        }
-
-        public void nodeRemoved(Object nodeId) {
-            nodesRemoved++;
-        }
+                    public void execute() {
+                        context.commitChanges();
+                    }
+                });
+        assertEquals(0, stats.nodePropertiesChanged);
+        assertEquals(0, stats.nodesCreated);
+        assertEquals(0, stats.nodesRemoved);
     }
+
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextInheritanceTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextInheritanceTest.java?rev=956400&r1=956399&r2=956400&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextInheritanceTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextInheritanceTest.java Sun Jun 20 20:11:30 2010
@@ -20,44 +20,41 @@ package org.apache.cayenne;
 
 import java.util.List;
 
-import org.apache.cayenne.access.ClientServerChannel;
+import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.exp.ExpressionFactory;
-import org.apache.cayenne.query.CapsStrategy;
-import org.apache.cayenne.query.SQLTemplate;
 import org.apache.cayenne.query.SelectQuery;
-import org.apache.cayenne.remote.ClientChannel;
-import org.apache.cayenne.remote.service.LocalConnection;
+import org.apache.cayenne.test.jdbc.DBHelper;
+import org.apache.cayenne.test.jdbc.TableHelper;
 import org.apache.cayenne.testdo.mt.ClientMtTable1;
 import org.apache.cayenne.testdo.mt.ClientMtTable1Subclass;
-import org.apache.cayenne.testdo.mt.MtTable1;
-import org.apache.cayenne.unit.AccessStack;
-import org.apache.cayenne.unit.CayenneCase;
-import org.apache.cayenne.unit.CayenneResources;
+import org.apache.cayenne.unit.di.client.ClientCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
 
-public class CayenneContextInheritanceTest extends CayenneCase {
+@UseServerRuntime(ClientCase.MULTI_TIER_PROJECT)
+public class CayenneContextInheritanceTest extends ClientCase {
 
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-        deleteTestData();
-    }
+    @Inject
+    private DBHelper dbHelper;
 
-    @Override
-    protected AccessStack buildAccessStack() {
-        return CayenneResources.getResources().getAccessStack(MULTI_TIER_ACCESS_STACK);
-    }
+    @Inject
+    private CayenneContext context;
+
+    private TableHelper tMtTable1;
 
-    private CayenneContext createClientContext() {
-        ClientServerChannel serverChannel = new ClientServerChannel(getDomain());
-        LocalConnection connection = new LocalConnection(
-                serverChannel,
-                LocalConnection.HESSIAN_SERIALIZATION);
-        ClientChannel clientChannel = new ClientChannel(connection);
-        return new CayenneContext(clientChannel);
+    @Override
+    protected void setUpAfterInjection() throws Exception {
+        dbHelper.deleteAll("MT_TABLE2");
+        dbHelper.deleteAll("MT_TABLE1");
+
+        tMtTable1 = new TableHelper(dbHelper, "MT_TABLE1");
+        tMtTable1.setColumns(
+                "TABLE1_ID",
+                "GLOBAL_ATTRIBUTE1",
+                "SERVER_ATTRIBUTE1",
+                "SUBCLASS_ATTRIBUTE1");
     }
 
-    public void testInsertSubclass() {
-        CayenneContext context = createClientContext();
+    public void testInsertSubclass() throws Exception {
 
         ClientMtTable1Subclass object = context.newObject(ClientMtTable1Subclass.class);
         object.setGlobalAttribute1("sub1");
@@ -66,35 +63,17 @@ public class CayenneContextInheritanceTe
 
         context.commitChanges();
 
-        ObjectContext checkContext = createDataContext();
-        SQLTemplate query = new SQLTemplate(MtTable1.class, "SELECT * FROM MT_TABLE1");
-        query.setColumnNamesCapitalization(CapsStrategy.UPPER);
-        query.setFetchingDataRows(true);
-
-        List<DataRow> rows = checkContext.performQuery(query);
-        assertEquals(1, rows.size());
-        assertEquals("sub1", rows.get(0).get("GLOBAL_ATTRIBUTE1"));
-        assertEquals("sa1", rows.get(0).get("SERVER_ATTRIBUTE1"));
-        assertEquals("suba1", rows.get(0).get("SUBCLASS_ATTRIBUTE1"));
+        assertEquals(1, tMtTable1.getRowCount());
+        assertEquals("sub1", tMtTable1.getString("GLOBAL_ATTRIBUTE1"));
+        assertEquals("sa1", tMtTable1.getString("SERVER_ATTRIBUTE1"));
+        assertEquals("suba1", tMtTable1.getString("SUBCLASS_ATTRIBUTE1"));
     }
 
-    public void testPerformQueryInheritanceLeaf() {
-
-        ObjectContext setupContext = createDataContext();
-        setupContext
-                .performQuery(new SQLTemplate(
-                        MtTable1.class,
-                        "INSERT INTO MT_TABLE1 (TABLE1_ID, GLOBAL_ATTRIBUTE1, SERVER_ATTRIBUTE1) VALUES (1, 'xxx', 'yyy')"));
-        setupContext
-                .performQuery(new SQLTemplate(
-                        MtTable1.class,
-                        "INSERT INTO MT_TABLE1 (TABLE1_ID, GLOBAL_ATTRIBUTE1, SERVER_ATTRIBUTE1, SUBCLASS_ATTRIBUTE1) VALUES (2, 'sub1', 'zzz', 'sa1')"));
-        setupContext
-                .performQuery(new SQLTemplate(
-                        MtTable1.class,
-                        "INSERT INTO MT_TABLE1 (TABLE1_ID, GLOBAL_ATTRIBUTE1, SERVER_ATTRIBUTE1) VALUES (3, '1111', 'aaa')"));
+    public void testPerformQueryInheritanceLeaf() throws Exception {
 
-        CayenneContext context = createClientContext();
+        tMtTable1.insert(1, "xxx", "yyy", null);
+        tMtTable1.insert(2, "sub1", "zzz", "sa1");
+        tMtTable1.insert(3, "1111", "aaa", null);
 
         SelectQuery query = new SelectQuery(ClientMtTable1Subclass.class);
         List<ClientMtTable1Subclass> objects = context.performQuery(query);
@@ -103,23 +82,11 @@ public class CayenneContextInheritanceTe
         assertEquals("sa1", objects.get(0).getSubclassAttribute1());
     }
 
-    public void testPerformQueryInheritanceSuper() {
-
-        ObjectContext setupContext = createDataContext();
-        setupContext
-                .performQuery(new SQLTemplate(
-                        MtTable1.class,
-                        "INSERT INTO MT_TABLE1 (TABLE1_ID, GLOBAL_ATTRIBUTE1, SERVER_ATTRIBUTE1) VALUES (1, 'a', 'yyy')"));
-        setupContext
-                .performQuery(new SQLTemplate(
-                        MtTable1.class,
-                        "INSERT INTO MT_TABLE1 (TABLE1_ID, GLOBAL_ATTRIBUTE1, SERVER_ATTRIBUTE1, SUBCLASS_ATTRIBUTE1) VALUES (2, 'sub1', 'zzz', 'sa1')"));
-        setupContext
-                .performQuery(new SQLTemplate(
-                        MtTable1.class,
-                        "INSERT INTO MT_TABLE1 (TABLE1_ID, GLOBAL_ATTRIBUTE1, SERVER_ATTRIBUTE1) VALUES (3, 'z', 'aaa')"));
+    public void testPerformQueryInheritanceSuper() throws Exception {
 
-        CayenneContext context = createClientContext();
+        tMtTable1.insert(1, "a", "yyy", null);
+        tMtTable1.insert(2, "sub1", "zzz", "sa1");
+        tMtTable1.insert(3, "z", "aaa", null);
 
         SelectQuery query = new SelectQuery(ClientMtTable1.class);
         List<ClientMtTable1> objects = context.performQuery(query);
@@ -144,23 +111,11 @@ public class CayenneContextInheritanceTe
         assertEquals(2, checkedFields);
     }
 
-    public void testPerformQueryWithQualifierInheritanceSuper() {
+    public void testPerformQueryWithQualifierInheritanceSuper() throws Exception {
 
-        ObjectContext setupContext = createDataContext();
-        setupContext
-                .performQuery(new SQLTemplate(
-                        MtTable1.class,
-                        "INSERT INTO MT_TABLE1 (TABLE1_ID, GLOBAL_ATTRIBUTE1, SERVER_ATTRIBUTE1) VALUES (1, 'a', 'XX')"));
-        setupContext
-                .performQuery(new SQLTemplate(
-                        MtTable1.class,
-                        "INSERT INTO MT_TABLE1 (TABLE1_ID, GLOBAL_ATTRIBUTE1, SERVER_ATTRIBUTE1, SUBCLASS_ATTRIBUTE1) VALUES (2, 'sub1', 'XXA', 'sa1')"));
-        setupContext
-                .performQuery(new SQLTemplate(
-                        MtTable1.class,
-                        "INSERT INTO MT_TABLE1 (TABLE1_ID, GLOBAL_ATTRIBUTE1, SERVER_ATTRIBUTE1) VALUES (3, 'z', 'MM')"));
-
-        CayenneContext context = createClientContext();
+        tMtTable1.insert(1, "a", "XX", null);
+        tMtTable1.insert(2, "sub1", "XXA", "sa1");
+        tMtTable1.insert(3, "z", "MM", null);
 
         SelectQuery query = new SelectQuery(ClientMtTable1.class);
         query.andQualifier(ExpressionFactory.likeExp(
@@ -169,7 +124,7 @@ public class CayenneContextInheritanceTe
         List<ClientMtTable1> objects = context.performQuery(query);
 
         assertEquals(2, objects.size());
-        
+
         int checkedFields = 0;
         for (int i = 0; i < objects.size(); i++) {
             Integer id = (Integer) objects.get(i).getObjectId().getIdSnapshot().get(

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextMergeHandlerTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextMergeHandlerTest.java?rev=956400&r1=956399&r2=956400&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextMergeHandlerTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextMergeHandlerTest.java Sun Jun 20 20:11:30 2010
@@ -19,40 +19,38 @@
 
 package org.apache.cayenne;
 
+import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.graph.GraphEvent;
 import org.apache.cayenne.testdo.mt.ClientMtTable1;
-import org.apache.cayenne.unit.AccessStack;
-import org.apache.cayenne.unit.CayenneCase;
-import org.apache.cayenne.unit.CayenneResources;
-
-public class CayenneContextMergeHandlerTest extends CayenneCase {
-
-    @Override
-    protected AccessStack buildAccessStack() {
-        return CayenneResources
-                .getResources()
-                .getAccessStack(MULTI_TIER_ACCESS_STACK);
-    }
+import org.apache.cayenne.unit.di.client.ClientCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+@UseServerRuntime(ClientCase.MULTI_TIER_PROJECT)
+public class CayenneContextMergeHandlerTest extends ClientCase {
+
+    @Inject
+    protected CayenneContext context;
 
     public void testShouldProcessEvent() {
-        DataChannel channel = new MockDataChannel();
-        CayenneContext context = new CayenneContext(channel);
 
         CayenneContextMergeHandler handler = new CayenneContextMergeHandler(context);
 
         // 1. Our context initiated the sync:
         // src == channel && postedBy == context
-        GraphEvent e1 = new GraphEvent(channel, context, null);
+        GraphEvent e1 = new GraphEvent(context.getChannel(), context, null);
         assertFalse(handler.shouldProcessEvent(e1));
 
         // 2. Another context initiated the sync:
         // postedBy != context && source == channel
-        GraphEvent e2 = new GraphEvent(channel, new MockObjectContext(), null);
+        GraphEvent e2 = new GraphEvent(
+                context.getChannel(),
+                new MockObjectContext(),
+                null);
         assertTrue(handler.shouldProcessEvent(e2));
 
         // 2.1 Another object initiated the sync:
         // postedBy != context && source == channel
-        GraphEvent e21 = new GraphEvent(channel, new Object(), null);
+        GraphEvent e21 = new GraphEvent(context.getChannel(), new Object(), null);
         assertTrue(handler.shouldProcessEvent(e21));
 
         // 3. Another channel initiated the sync:
@@ -61,17 +59,16 @@ public class CayenneContextMergeHandlerT
         assertFalse(handler.shouldProcessEvent(e3));
 
         // 4. inactive
-        GraphEvent e4 = new GraphEvent(channel, new MockObjectContext(), null);
+        GraphEvent e4 = new GraphEvent(
+                context.getChannel(),
+                new MockObjectContext(),
+                null);
         handler.active = false;
         assertFalse(handler.shouldProcessEvent(e4));
     }
 
     public void testNodePropertyChanged() {
-        DataChannel channel = new MockDataChannel(getDomain()
-                .getEntityResolver()
-                .getClientEntityResolver());
 
-        CayenneContext context = new CayenneContext(channel);
         ClientMtTable1 o1 = context.newObject(ClientMtTable1.class);
 
         CayenneContextMergeHandler handler = new CayenneContextMergeHandler(context);

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/ClientServerChannelTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/ClientServerChannelTest.java?rev=956400&r1=956399&r2=956400&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/ClientServerChannelTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/ClientServerChannelTest.java Sun Jun 20 20:11:30 2010
@@ -43,9 +43,9 @@ import org.apache.cayenne.testdo.mt.Clie
 import org.apache.cayenne.testdo.mt.ClientMtTable2;
 import org.apache.cayenne.testdo.mt.ClientMtTable3;
 import org.apache.cayenne.testdo.mt.MtTable1;
+import org.apache.cayenne.unit.di.DataChannelInterceptor;
 import org.apache.cayenne.unit.di.UnitTestClosure;
 import org.apache.cayenne.unit.di.client.ClientCase;
-import org.apache.cayenne.unit.di.server.DataChannelQueryInterceptor;
 import org.apache.cayenne.unit.di.server.UseServerRuntime;
 import org.apache.cayenne.util.EqualsBuilder;
 
@@ -62,7 +62,7 @@ public class ClientServerChannelTest ext
     protected DBHelper dbHelper;
 
     @Inject
-    protected DataChannelQueryInterceptor queryInterceptor;
+    protected DataChannelInterceptor queryInterceptor;
 
     private TableHelper tMtTable1;
     private TableHelper tMtTable2;

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLFetchJoinTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLFetchJoinTest.java?rev=956400&r1=956399&r2=956400&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLFetchJoinTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLFetchJoinTest.java Sun Jun 20 20:11:30 2010
@@ -34,8 +34,8 @@ import org.apache.cayenne.testdo.testmap
 import org.apache.cayenne.testdo.testmap.ArtistExhibit;
 import org.apache.cayenne.testdo.testmap.Gallery;
 import org.apache.cayenne.testdo.testmap.Painting;
+import org.apache.cayenne.unit.di.DataChannelInterceptor;
 import org.apache.cayenne.unit.di.UnitTestClosure;
-import org.apache.cayenne.unit.di.server.DataChannelQueryInterceptor;
 import org.apache.cayenne.unit.di.server.ServerCase;
 import org.apache.cayenne.unit.di.server.UseServerRuntime;
 
@@ -49,7 +49,7 @@ public class DataContextEJBQLFetchJoinTe
     protected DBHelper dbHelper;
 
     @Inject
-    protected DataChannelQueryInterceptor queryBlocker;
+    protected DataChannelInterceptor queryBlocker;
 
     protected TableHelper tArtist;
     protected TableHelper tPainting;

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPerformQueryAPITest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPerformQueryAPITest.java?rev=956400&r1=956399&r2=956400&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPerformQueryAPITest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPerformQueryAPITest.java Sun Jun 20 20:11:30 2010
@@ -34,8 +34,8 @@ import org.apache.cayenne.test.jdbc.Tabl
 import org.apache.cayenne.testdo.testmap.Artist;
 import org.apache.cayenne.testdo.testmap.Painting;
 import org.apache.cayenne.unit.AccessStackAdapter;
+import org.apache.cayenne.unit.di.DataChannelInterceptor;
 import org.apache.cayenne.unit.di.UnitTestClosure;
-import org.apache.cayenne.unit.di.server.DataChannelQueryInterceptor;
 import org.apache.cayenne.unit.di.server.ServerCase;
 import org.apache.cayenne.unit.di.server.UseServerRuntime;
 
@@ -55,7 +55,7 @@ public class DataContextPerformQueryAPIT
     protected AccessStackAdapter accessStackAdapter;
 
     @Inject
-    protected DataChannelQueryInterceptor queryInterceptor;
+    protected DataChannelInterceptor queryInterceptor;
 
     protected TableHelper tArtist;
     protected TableHelper tPainting;

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPrefetchTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPrefetchTest.java?rev=956400&r1=956399&r2=956400&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPrefetchTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPrefetchTest.java Sun Jun 20 20:11:30 2010
@@ -44,8 +44,8 @@ import org.apache.cayenne.testdo.testmap
 import org.apache.cayenne.testdo.testmap.ArtistExhibit;
 import org.apache.cayenne.testdo.testmap.Painting;
 import org.apache.cayenne.testdo.testmap.PaintingInfo;
+import org.apache.cayenne.unit.di.DataChannelInterceptor;
 import org.apache.cayenne.unit.di.UnitTestClosure;
-import org.apache.cayenne.unit.di.server.DataChannelQueryInterceptor;
 import org.apache.cayenne.unit.di.server.ServerCase;
 import org.apache.cayenne.unit.di.server.UseServerRuntime;
 
@@ -59,7 +59,7 @@ public class DataContextPrefetchTest ext
     protected DBHelper dbHelper;
 
     @Inject
-    protected DataChannelQueryInterceptor queryInterceptor;
+    protected DataChannelInterceptor queryInterceptor;
 
     protected TableHelper tArtist;
     protected TableHelper tPainting;

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextRefreshingTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextRefreshingTest.java?rev=956400&r1=956399&r2=956400&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextRefreshingTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextRefreshingTest.java Sun Jun 20 20:11:30 2010
@@ -31,8 +31,8 @@ import org.apache.cayenne.test.jdbc.DBHe
 import org.apache.cayenne.test.jdbc.TableHelper;
 import org.apache.cayenne.testdo.testmap.Artist;
 import org.apache.cayenne.testdo.testmap.Painting;
+import org.apache.cayenne.unit.di.DataChannelInterceptor;
 import org.apache.cayenne.unit.di.UnitTestClosure;
-import org.apache.cayenne.unit.di.server.DataChannelQueryInterceptor;
 import org.apache.cayenne.unit.di.server.ServerCase;
 import org.apache.cayenne.unit.di.server.UseServerRuntime;
 import org.hsqldb.Types;
@@ -52,7 +52,7 @@ public class DataContextRefreshingTest e
     protected DBHelper dbHelper;
 
     @Inject
-    protected DataChannelQueryInterceptor queryInterceptor;
+    protected DataChannelInterceptor queryInterceptor;
 
     protected TableHelper tArtist;
     protected TableHelper tPainting;

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextTest.java?rev=956400&r1=956399&r2=956400&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextTest.java Sun Jun 20 20:11:30 2010
@@ -52,8 +52,8 @@ import org.apache.cayenne.testdo.testmap
 import org.apache.cayenne.testdo.testmap.Painting;
 import org.apache.cayenne.testdo.testmap.ROArtist;
 import org.apache.cayenne.unit.AccessStackAdapter;
+import org.apache.cayenne.unit.di.DataChannelInterceptor;
 import org.apache.cayenne.unit.di.UnitTestClosure;
-import org.apache.cayenne.unit.di.server.DataChannelQueryInterceptor;
 import org.apache.cayenne.unit.di.server.ServerCase;
 import org.apache.cayenne.unit.di.server.UseServerRuntime;
 
@@ -70,7 +70,7 @@ public class DataContextTest extends Ser
     protected AccessStackAdapter accessStackAdapter;
 
     @Inject
-    protected DataChannelQueryInterceptor queryInterceptor;
+    protected DataChannelInterceptor queryInterceptor;
 
     @Inject
     protected DataSource dataSource;

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/SimpleIdIncrementalFaultListPrefetchTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/SimpleIdIncrementalFaultListPrefetchTest.java?rev=956400&r1=956399&r2=956400&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/SimpleIdIncrementalFaultListPrefetchTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/SimpleIdIncrementalFaultListPrefetchTest.java Sun Jun 20 20:11:30 2010
@@ -33,8 +33,8 @@ import org.apache.cayenne.test.jdbc.DBHe
 import org.apache.cayenne.test.jdbc.TableHelper;
 import org.apache.cayenne.testdo.testmap.Artist;
 import org.apache.cayenne.testdo.testmap.Painting;
+import org.apache.cayenne.unit.di.DataChannelInterceptor;
 import org.apache.cayenne.unit.di.UnitTestClosure;
-import org.apache.cayenne.unit.di.server.DataChannelQueryInterceptor;
 import org.apache.cayenne.unit.di.server.ServerCase;
 import org.apache.cayenne.unit.di.server.UseServerRuntime;
 
@@ -48,7 +48,7 @@ public class SimpleIdIncrementalFaultLis
     protected DBHelper dbHelper;
 
     @Inject
-    protected DataChannelQueryInterceptor queryInterceptor;
+    protected DataChannelInterceptor queryInterceptor;
 
     protected TableHelper tArtist;
     protected TableHelper tPaining;

Copied: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/DataChannelInterceptor.java (from r956370, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/DataChannelQueryInterceptor.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/DataChannelInterceptor.java?p2=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/DataChannelInterceptor.java&p1=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/DataChannelQueryInterceptor.java&r1=956370&r2=956400&rev=956400&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/DataChannelQueryInterceptor.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/DataChannelInterceptor.java Sun Jun 20 20:11:30 2010
@@ -16,13 +16,17 @@
  *  specific language governing permissions and limitations
  *  under the License.
  ****************************************************************/
-package org.apache.cayenne.unit.di.server;
+package org.apache.cayenne.unit.di;
 
-import org.apache.cayenne.unit.di.UnitTestClosure;
-
-public interface DataChannelQueryInterceptor {
+/**
+ * An interface that allows to block a DataChannel or to collect DataChannel statistics
+ * for the duration of execution of some code.
+ */
+public interface DataChannelInterceptor {
 
     void runWithQueriesBlocked(UnitTestClosure closure);
-    
+
     int runWithQueryCounter(UnitTestClosure closure);
+
+    DataChannelSyncStats runWithSyncStatsCollection(UnitTestClosure closure);
 }

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/DataChannelSyncStats.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/DataChannelSyncStats.java?rev=956400&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/DataChannelSyncStats.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/DataChannelSyncStats.java Sun Jun 20 20:11:30 2010
@@ -0,0 +1,59 @@
+/*****************************************************************
+ *   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;
+
+import org.apache.cayenne.graph.GraphChangeHandler;
+
+public class DataChannelSyncStats implements GraphChangeHandler {
+
+    public int arcsCreated;
+    public int arcsDeleted;
+    public int nodesCreated;
+    public int nodeIdsChanged;
+    public int nodePropertiesChanged;
+    public int nodesRemoved;
+
+    public void arcCreated(Object nodeId, Object targetNodeId, Object arcId) {
+        arcsCreated++;
+    }
+
+    public void arcDeleted(Object nodeId, Object targetNodeId, Object arcId) {
+        arcsDeleted++;
+    }
+
+    public void nodeCreated(Object nodeId) {
+        nodesCreated++;
+    }
+
+    public void nodeIdChanged(Object nodeId, Object newId) {
+        nodeIdsChanged++;
+    }
+
+    public void nodePropertyChanged(
+            Object nodeId,
+            String property,
+            Object oldValue,
+            Object newValue) {
+        nodePropertiesChanged++;
+    }
+
+    public void nodeRemoved(Object nodeId) {
+        nodesRemoved++;
+    }
+}
\ No newline at end of file

Copied: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientCaseCayenneContextProvider.java (from r956370, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientServerChannelProvider.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientCaseCayenneContextProvider.java?p2=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientCaseCayenneContextProvider.java&p1=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientServerChannelProvider.java&r1=956370&r2=956400&rev=956400&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientServerChannelProvider.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientCaseCayenneContextProvider.java Sun Jun 20 20:11:30 2010
@@ -18,23 +18,19 @@
  ****************************************************************/
 package org.apache.cayenne.unit.di.client;
 
+import org.apache.cayenne.CayenneContext;
 import org.apache.cayenne.ConfigurationException;
-import org.apache.cayenne.access.ClientServerChannel;
-import org.apache.cayenne.configuration.rop.client.ClientRuntime;
+import org.apache.cayenne.ObjectContext;
 import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.di.Provider;
-import org.apache.cayenne.remote.service.LocalConnection;
 
-public class ClientServerChannelProvider implements Provider<ClientServerChannel> {
 
-    @Inject
-    protected Provider<ClientRuntime> clientRuntimeProvider;
+public class ClientCaseCayenneContextProvider implements Provider<CayenneContext> {
 
-    public ClientServerChannel get() throws ConfigurationException {
-
-        LocalConnection connection = (LocalConnection) clientRuntimeProvider
-                .get()
-                .getConnection();
-        return (ClientServerChannel) connection.getChannel();
+    @Inject(ClientCase.ROP_CLIENT_KEY)
+    protected Provider<ObjectContext> objectContextProvider;
+    
+    public CayenneContext get() throws ConfigurationException {
+        return (CayenneContext) objectContextProvider.get();
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientCaseModule.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientCaseModule.java?rev=956400&r1=956399&r2=956400&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientCaseModule.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientCaseModule.java Sun Jun 20 20:11:30 2010
@@ -18,6 +18,7 @@
  ****************************************************************/
 package org.apache.cayenne.unit.di.client;
 
+import org.apache.cayenne.CayenneContext;
 import org.apache.cayenne.ObjectContext;
 import org.apache.cayenne.access.ClientServerChannel;
 import org.apache.cayenne.configuration.rop.client.ClientRuntime;
@@ -25,6 +26,7 @@ import org.apache.cayenne.di.Binder;
 import org.apache.cayenne.di.Key;
 import org.apache.cayenne.di.Module;
 import org.apache.cayenne.di.spi.DefaultScope;
+import org.apache.cayenne.unit.di.DataChannelInterceptor;
 import org.apache.cayenne.unit.di.UnitTestLifecycleManager;
 
 public class ClientCaseModule implements Module {
@@ -41,6 +43,8 @@ public class ClientCaseModule implements
 
         binder.bind(UnitTestLifecycleManager.class).toInstance(
                 new ClientCaseLifecycleManager(testScope));
+        binder.bind(Key.get(DataChannelInterceptor.class, ClientCase.ROP_CLIENT_KEY)).to(
+                ClientServerDataChannelInterceptor.class);
 
         // test-scoped objects
 
@@ -52,6 +56,8 @@ public class ClientCaseModule implements
 
         binder.bind(Key.get(ObjectContext.class, ClientCase.ROP_CLIENT_KEY)).toProvider(
                 ClientCaseObjectContextProvider.class).in(testScope);
+        binder.bind(CayenneContext.class).toProvider(
+                ClientCaseCayenneContextProvider.class).in(testScope);
 
         binder.bind(ClientServerChannel.class).toProvider(
                 ClientServerChannelProvider.class).in(testScope);

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientRuntimeProvider.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientRuntimeProvider.java?rev=956400&r1=956399&r2=956400&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientRuntimeProvider.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientRuntimeProvider.java Sun Jun 20 20:11:30 2010
@@ -19,11 +19,15 @@
 package org.apache.cayenne.unit.di.client;
 
 import org.apache.cayenne.ConfigurationException;
+import org.apache.cayenne.DataChannel;
 import org.apache.cayenne.configuration.rop.client.ClientLocalRuntime;
 import org.apache.cayenne.configuration.rop.client.ClientRuntime;
 import org.apache.cayenne.configuration.server.ServerRuntime;
+import org.apache.cayenne.di.Binder;
 import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.di.Injector;
+import org.apache.cayenne.di.Key;
+import org.apache.cayenne.di.Module;
 import org.apache.cayenne.di.Provider;
 
 public class ClientRuntimeProvider implements Provider<ClientRuntime> {
@@ -38,6 +42,31 @@ public class ClientRuntimeProvider imple
     public ClientRuntime get() throws ConfigurationException {
         Injector serverInjector = serverRuntimeProvider.get().getInjector();
         return new ClientLocalRuntime(serverInjector, clientCaseProperties
-                .getRuntimeProperties());
+                .getRuntimeProperties(), new ClientExtraModule(serverInjector));
+    }
+
+    class ClientExtraModule implements Module {
+
+        private Injector serverInjector;
+
+        ClientExtraModule(Injector serverInjector) {
+            this.serverInjector = serverInjector;
+        }
+
+        public void configure(Binder binder) {
+
+            // these are the objects overriding standard ClientLocalModule definitions or
+            // dependencies needed by such overrides
+
+            // add an interceptor between client and server parts to capture and inspect
+            // the traffic
+            binder
+                    .bind(
+                            Key.get(
+                                    DataChannel.class,
+                                    ClientLocalRuntime.CLIENT_SERVER_CHANNEL_KEY))
+                    .toProviderInstance(
+                            new InterceptingClientServerChannelProvider(serverInjector));
+        }
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientServerChannelProvider.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientServerChannelProvider.java?rev=956400&r1=956399&r2=956400&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientServerChannelProvider.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientServerChannelProvider.java Sun Jun 20 20:11:30 2010
@@ -35,6 +35,8 @@ public class ClientServerChannelProvider
         LocalConnection connection = (LocalConnection) clientRuntimeProvider
                 .get()
                 .getConnection();
-        return (ClientServerChannel) connection.getChannel();
+        
+        ClientServerDataChannelDecorator channelDecorator = (ClientServerDataChannelDecorator) connection.getChannel();
+        return (ClientServerChannel) channelDecorator.getDelegate();
     }
 }

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientServerDataChannelDecorator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientServerDataChannelDecorator.java?rev=956400&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientServerDataChannelDecorator.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientServerDataChannelDecorator.java Sun Jun 20 20:11:30 2010
@@ -0,0 +1,90 @@
+/*****************************************************************
+ *   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.client;
+
+import junit.framework.Assert;
+import junit.framework.AssertionFailedError;
+
+import org.apache.cayenne.DataChannel;
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.QueryResponse;
+import org.apache.cayenne.event.EventManager;
+import org.apache.cayenne.graph.GraphDiff;
+import org.apache.cayenne.map.EntityResolver;
+import org.apache.cayenne.query.Query;
+import org.apache.cayenne.unit.di.DataChannelSyncStats;
+
+public class ClientServerDataChannelDecorator implements DataChannel {
+
+    private DataChannel delegate;
+    private boolean blockingMessages;
+    private DataChannelSyncStats statsCounter;
+
+    public ClientServerDataChannelDecorator(DataChannel delegate) {
+        this.delegate = delegate;
+    }
+    
+    public DataChannel getDelegate() {
+        return delegate;
+    }
+
+    public EntityResolver getEntityResolver() {
+        checkMessageAllowed("getEntityResolver");
+        return delegate.getEntityResolver();
+    }
+
+    public EventManager getEventManager() {
+        checkMessageAllowed("getEventManager");
+        return delegate.getEventManager();
+    }
+
+    public QueryResponse onQuery(ObjectContext originatingContext, Query query) {
+        checkMessageAllowed("onQuery");
+        return delegate.onQuery(originatingContext, query);
+    }
+
+    public GraphDiff onSync(
+            ObjectContext originatingContext,
+            GraphDiff changes,
+            int syncType) {
+        checkMessageAllowed("onSync");
+        countDiffs(changes);
+        return delegate.onSync(originatingContext, changes, syncType);
+    }
+
+    public void setBlockingMessages(boolean blockingMessages) {
+        this.blockingMessages = blockingMessages;
+    }
+
+    public void setSyncStatsCounter(DataChannelSyncStats statsCounter) {
+        this.statsCounter = statsCounter;
+    }
+
+    private void checkMessageAllowed(String label) throws AssertionFailedError {
+        if (blockingMessages) {
+            Assert.fail("Message is unexpected: " + label);
+        }
+    }
+
+    private void countDiffs(GraphDiff changes) {
+        if (statsCounter != null) {
+            changes.apply(statsCounter);
+        }
+    }
+}

Copied: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientServerDataChannelInterceptor.java (from r956370, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataChannelQueryInterceptor.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientServerDataChannelInterceptor.java?p2=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientServerDataChannelInterceptor.java&p1=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataChannelQueryInterceptor.java&r1=956370&r2=956400&rev=956400&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataChannelQueryInterceptor.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientServerDataChannelInterceptor.java Sun Jun 20 20:11:30 2010
@@ -16,50 +16,60 @@
  *  specific language governing permissions and limitations
  *  under the License.
  ****************************************************************/
-package org.apache.cayenne.unit.di.server;
+package org.apache.cayenne.unit.di.client;
 
-import org.apache.cayenne.access.UnitTestDomain;
-import org.apache.cayenne.configuration.server.ServerRuntime;
+import org.apache.cayenne.configuration.rop.client.ClientRuntime;
 import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.di.Provider;
+import org.apache.cayenne.remote.service.LocalConnection;
+import org.apache.cayenne.unit.di.DataChannelInterceptor;
+import org.apache.cayenne.unit.di.DataChannelSyncStats;
 import org.apache.cayenne.unit.di.UnitTestClosure;
 
-public class ServerCaseDataChannelQueryInterceptor implements DataChannelQueryInterceptor {
+public class ClientServerDataChannelInterceptor implements DataChannelInterceptor {
 
     @Inject
-    // injecting provider to make this provider independent from scoping of ServerRuntime
-    protected Provider<ServerRuntime> serverRuntimeProvider;
+    protected Provider<ClientRuntime> clientRuntimeProvider;
 
-    public void runWithQueriesBlocked(UnitTestClosure closure) {
+    private ClientServerDataChannelDecorator getChannelDecorator() {
 
-        UnitTestDomain channel = (UnitTestDomain) serverRuntimeProvider
+        LocalConnection connection = (LocalConnection) clientRuntimeProvider
                 .get()
-                .getChannel();
+                .getConnection();
+
+        return (ClientServerDataChannelDecorator) connection.getChannel();
+    }
+
+    public void runWithQueriesBlocked(UnitTestClosure closure) {
+        ClientServerDataChannelDecorator channel = getChannelDecorator();
 
-        channel.setBlockingQueries(true);
+        channel.setBlockingMessages(true);
         try {
             closure.execute();
         }
         finally {
-            channel.setBlockingQueries(false);
+            channel.setBlockingMessages(false);
         }
     }
 
     public int runWithQueryCounter(UnitTestClosure closure) {
+        throw new UnsupportedOperationException("TODO... unused for now");
+    }
 
-        UnitTestDomain channel = (UnitTestDomain) serverRuntimeProvider
-                .get()
-                .getChannel();
+    public DataChannelSyncStats runWithSyncStatsCollection(UnitTestClosure closure) {
+        ClientServerDataChannelDecorator channel = getChannelDecorator();
 
-        int start = channel.getQueryCount();
-        int end;
+        DataChannelSyncStats stats = new DataChannelSyncStats();
+
+        channel.setSyncStatsCounter(stats);
         try {
             closure.execute();
         }
         finally {
-            end = channel.getQueryCount();
+            channel.setSyncStatsCounter(null);
         }
 
-        return end - start;
+        return stats;
     }
+
 }

Copied: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/InterceptingClientServerChannelProvider.java (from r956370, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientServerChannelProvider.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/InterceptingClientServerChannelProvider.java?p2=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/InterceptingClientServerChannelProvider.java&p1=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientServerChannelProvider.java&r1=956370&r2=956400&rev=956400&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientServerChannelProvider.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/InterceptingClientServerChannelProvider.java Sun Jun 20 20:11:30 2010
@@ -19,22 +19,20 @@
 package org.apache.cayenne.unit.di.client;
 
 import org.apache.cayenne.ConfigurationException;
-import org.apache.cayenne.access.ClientServerChannel;
-import org.apache.cayenne.configuration.rop.client.ClientRuntime;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.di.Provider;
-import org.apache.cayenne.remote.service.LocalConnection;
+import org.apache.cayenne.DataChannel;
+import org.apache.cayenne.configuration.rop.client.LocalClientServerChannelProvider;
+import org.apache.cayenne.di.Injector;
 
-public class ClientServerChannelProvider implements Provider<ClientServerChannel> {
+public class InterceptingClientServerChannelProvider extends
+        LocalClientServerChannelProvider {
 
-    @Inject
-    protected Provider<ClientRuntime> clientRuntimeProvider;
-
-    public ClientServerChannel get() throws ConfigurationException {
+    public InterceptingClientServerChannelProvider(Injector serverInjector) {
+        super(serverInjector);
+    }
 
-        LocalConnection connection = (LocalConnection) clientRuntimeProvider
-                .get()
-                .getConnection();
-        return (ClientServerChannel) connection.getChannel();
+    @Override
+    public DataChannel get() throws ConfigurationException {
+        DataChannel clientServerChannel = super.get();
+        return new ClientServerDataChannelDecorator(clientServerChannel);
     }
 }

Copied: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataChannelInterceptor.java (from r956370, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataChannelQueryInterceptor.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataChannelInterceptor.java?p2=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataChannelInterceptor.java&p1=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataChannelQueryInterceptor.java&r1=956370&r2=956400&rev=956400&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataChannelQueryInterceptor.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataChannelInterceptor.java Sun Jun 20 20:11:30 2010
@@ -22,9 +22,11 @@ import org.apache.cayenne.access.UnitTes
 import org.apache.cayenne.configuration.server.ServerRuntime;
 import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.di.Provider;
+import org.apache.cayenne.unit.di.DataChannelInterceptor;
+import org.apache.cayenne.unit.di.DataChannelSyncStats;
 import org.apache.cayenne.unit.di.UnitTestClosure;
 
-public class ServerCaseDataChannelQueryInterceptor implements DataChannelQueryInterceptor {
+public class ServerCaseDataChannelInterceptor implements DataChannelInterceptor {
 
     @Inject
     // injecting provider to make this provider independent from scoping of ServerRuntime
@@ -62,4 +64,8 @@ public class ServerCaseDataChannelQueryI
 
         return end - start;
     }
+
+    public DataChannelSyncStats runWithSyncStatsCollection(UnitTestClosure closure) {
+        throw new UnsupportedOperationException("TODO... so far unused");
+    }
 }

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=956400&r1=956399&r2=956400&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 Sun Jun 20 20:11:30 2010
@@ -31,6 +31,7 @@ import org.apache.cayenne.di.spi.Default
 import org.apache.cayenne.test.jdbc.DBHelper;
 import org.apache.cayenne.unit.AccessStackAdapter;
 import org.apache.cayenne.unit.CayenneResources;
+import org.apache.cayenne.unit.di.DataChannelInterceptor;
 import org.apache.cayenne.unit.di.UnitTestLifecycleManager;
 import org.apache.cayenne.unit.util.SQLTemplateCustomizer;
 
@@ -63,8 +64,8 @@ public class ServerCaseModule implements
         binder.bind(AccessStackAdapter.class).toProviderInstance(
                 new CayenneResourcesAccessStackAdapterProvider(resources));
         binder.bind(DataNode.class).toProvider(ServerCaseDataNodeProvider.class);
-        binder.bind(DataChannelQueryInterceptor.class).to(
-                ServerCaseDataChannelQueryInterceptor.class);
+        binder.bind(DataChannelInterceptor.class).to(
+                ServerCaseDataChannelInterceptor.class);
         binder.bind(SQLTemplateCustomizer.class).toProviderInstance(
                 new CayenneResourcesSQLTemplateCustomizerProvider(resources));
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerRuntimeProvider.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerRuntimeProvider.java?rev=956400&r1=956399&r2=956400&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerRuntimeProvider.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerRuntimeProvider.java Sun Jun 20 20:11:30 2010
@@ -45,8 +45,8 @@ public class ServerRuntimeProvider imple
 
         String configurationLocation = properties.getConfigurationLocation();
         if (configurationLocation == null) {
-            throw new NullPointerException(
-                    "Null 'configurationLocation', method is called out of scope");
+            throw new NullPointerException("Null 'configurationLocation', "
+                    + "annotate your test case with @UseServerRuntime");
         }
 
         return new ServerRuntime(configurationLocation, new ServerExtraModule());



Mime
View raw message