You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2010/06/20 17:18:37 UTC
svn commit: r956370 - in
/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test:
java/org/apache/cayenne/ java/org/apache/cayenne/access/
java/org/apache/cayenne/unit/di/client/
java/org/apache/cayenne/unit/di/server/ resources/ resources/dml/
Author: aadamchik
Date: Sun Jun 20 15:18:34 2010
New Revision: 956370
URL: http://svn.apache.org/viewvc?rev=956370&view=rev
Log:
DI-enabled unit tests
* ROP client test stack
Added:
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientCase.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientCaseLifecycleManager.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/ClientCaseObjectContextProvider.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientCaseProperties.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientCaseSelfTest.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientRuntimeProperty.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/resources/cayenne-multi-tier.xml
Removed:
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/dml/CayenneContextClientChannelEventsTest.xml
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/dml/access.ClientServerChannelQueryTest.xml
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/dml/access.ClientServerChannelTest.xml
Modified:
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/BaseContextTest.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextClientChannelEventsTest.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/ClientServerChannelQueryTest.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/DataContextEJBQLArrayResultTest.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCase.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/cayenne-default.xml
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/BaseContextTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/BaseContextTest.java?rev=956370&r1=956369&r2=956370&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/BaseContextTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/BaseContextTest.java Sun Jun 20 15:18:34 2010
@@ -20,9 +20,9 @@ package org.apache.cayenne;
import java.util.Map;
-import org.apache.cayenne.unit.CayenneCase;
+import junit.framework.TestCase;
-public class BaseContextTest extends CayenneCase {
+public class BaseContextTest extends TestCase {
public void testUserPropertiesLazyInit() {
BaseContext context = new MockBaseContext();
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextClientChannelEventsTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextClientChannelEventsTest.java?rev=956370&r1=956369&r2=956370&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextClientChannelEventsTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextClientChannelEventsTest.java Sun Jun 20 15:18:34 2010
@@ -19,43 +19,70 @@
package org.apache.cayenne;
-import org.apache.cayenne.access.ClientServerChannel;
+import org.apache.cayenne.configuration.rop.client.ClientModule;
+import org.apache.cayenne.configuration.rop.client.ClientRuntime;
+import org.apache.cayenne.di.Inject;
import org.apache.cayenne.query.ObjectIdQuery;
-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.ClientMtTable2;
import org.apache.cayenne.testdo.mt.ClientMtTable4;
import org.apache.cayenne.testdo.mt.ClientMtTable5;
-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.client.ClientRuntimeProperty;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
/**
* Tests peer context synchronization via ClientChannel events.
- *
*/
-public class CayenneContextClientChannelEventsTest extends CayenneCase {
+@UseServerRuntime(ClientCase.MULTI_TIER_PROJECT)
+@ClientRuntimeProperty( {
+ ClientModule.CHANNEL_EVENTS, "true"
+})
+public class CayenneContextClientChannelEventsTest extends ClientCase {
+
+ @Inject
+ private DBHelper dbHelper;
+
+ @Inject
+ private ClientRuntime runtime;
+
+ private TableHelper tMtTable1;
+ private TableHelper tMtTable2;
+ private TableHelper tMtTable4;
+ private TableHelper tMtTable5;
+ private TableHelper tMtJoin45;
@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");
+ dbHelper.deleteAll("MT_JOIN45");
+ dbHelper.deleteAll("MT_TABLE4");
+ dbHelper.deleteAll("MT_TABLE5");
+
+ tMtTable1 = new TableHelper(dbHelper, "MT_TABLE1");
+ tMtTable1.setColumns("TABLE1_ID", "GLOBAL_ATTRIBUTE1", "SERVER_ATTRIBUTE1");
+
+ tMtTable2 = new TableHelper(dbHelper, "MT_TABLE2");
+ tMtTable2.setColumns("TABLE2_ID", "TABLE1_ID", "GLOBAL_ATTRIBUTE");
+
+ tMtTable4 = new TableHelper(dbHelper, "MT_TABLE4");
+ tMtTable4.setColumns("ID");
+
+ tMtTable5 = new TableHelper(dbHelper, "MT_TABLE5");
+ tMtTable5.setColumns("ID");
+
+ tMtJoin45 = new TableHelper(dbHelper, "MT_JOIN45");
+ tMtJoin45.setColumns("TABLE4_ID", "TABLE5_ID");
}
public void testSyncNewObject() throws Exception {
- // this resets snapshot cache...
- createDataContext();
- deleteTestData();
-
- DataChannel serverChannel = new ClientServerChannel(getDomain());
- ClientChannel clientChannel = new ClientChannel(
- new LocalConnection(serverChannel),
- true);
- CayenneContext c1 = new CayenneContext(clientChannel);
- CayenneContext c2 = new CayenneContext(clientChannel);
+ CayenneContext c1 = (CayenneContext) runtime.getContext();
+ CayenneContext c2 = (CayenneContext) runtime.getContext();
+ assertNotSame(c1, c2);
ClientMtTable1 o1 = c1.newObject(ClientMtTable1.class);
o1.setGlobalAttribute1("X");
@@ -77,17 +104,10 @@ public class CayenneContextClientChannel
}
public void testSyncNewDeletedObject() throws Exception {
- // this resets snapshot cache...
- createDataContext();
- deleteTestData();
-
- DataChannel serverChannel = new ClientServerChannel(getDomain());
- ClientChannel clientChannel = new ClientChannel(
- new LocalConnection(serverChannel),
- true);
- CayenneContext c1 = new CayenneContext(clientChannel);
- CayenneContext c2 = new CayenneContext(clientChannel);
+ CayenneContext c1 = (CayenneContext) runtime.getContext();
+ CayenneContext c2 = (CayenneContext) runtime.getContext();
+ assertNotSame(c1, c2);
// insert, then delete - this shouldn't propagate via an event.
ClientMtTable1 o1 = c1.newObject(ClientMtTable1.class);
@@ -109,17 +129,10 @@ public class CayenneContextClientChannel
}
public void testSyncNewObjectIntoDirtyContext() throws Exception {
- // this resets snapshot cache...
- createDataContext();
- deleteTestData();
-
- DataChannel serverChannel = new ClientServerChannel(getDomain());
- ClientChannel clientChannel = new ClientChannel(
- new LocalConnection(serverChannel),
- true);
- CayenneContext c1 = new CayenneContext(clientChannel);
- CayenneContext c2 = new CayenneContext(clientChannel);
+ CayenneContext c1 = (CayenneContext) runtime.getContext();
+ CayenneContext c2 = (CayenneContext) runtime.getContext();
+ assertNotSame(c1, c2);
// make sure c2 has uncommitted changes
c2.newObject(ClientMtTable1.class);
@@ -143,19 +156,12 @@ public class CayenneContextClientChannel
}
public void testSyncSimpleProperty() throws Exception {
- // this resets snapshot cache...
- createDataContext();
-
- deleteTestData();
- createTestData("testSyncSimpleProperty");
- DataChannel serverChannel = new ClientServerChannel(getDomain());
- ClientChannel clientChannel = new ClientChannel(
- new LocalConnection(serverChannel),
- true);
+ tMtTable1.insert(1, "g1", "s1");
- CayenneContext c1 = new CayenneContext(clientChannel);
- CayenneContext c2 = new CayenneContext(clientChannel);
+ CayenneContext c1 = (CayenneContext) runtime.getContext();
+ CayenneContext c2 = (CayenneContext) runtime.getContext();
+ assertNotSame(c1, c2);
ClientMtTable1 o1 = (ClientMtTable1) Cayenne.objectForQuery(
c1,
@@ -177,19 +183,13 @@ public class CayenneContextClientChannel
}
public void testSyncToOneRelationship() throws Exception {
- // this resets snapshot cache...
- createDataContext();
- deleteTestData();
- createTestData("testSyncToOneRelationship");
+ tMtTable1.insert(1, "g1", "s1");
+ tMtTable1.insert(2, "g2", "s2");
+ tMtTable2.insert(1, 1, "g1");
- DataChannel serverChannel = new ClientServerChannel(getDomain());
- ClientChannel clientChannel = new ClientChannel(
- new LocalConnection(serverChannel),
- true);
-
- CayenneContext c1 = new CayenneContext(clientChannel);
- CayenneContext c2 = new CayenneContext(clientChannel);
+ CayenneContext c1 = (CayenneContext) runtime.getContext();
+ CayenneContext c2 = (CayenneContext) runtime.getContext();
ClientMtTable2 o1 = (ClientMtTable2) Cayenne.objectForQuery(
c1,
@@ -215,19 +215,11 @@ public class CayenneContextClientChannel
}
public void testSyncToManyRelationship() throws Exception {
- // this resets snapshot cache...
- createDataContext();
-
- deleteTestData();
- createTestData("testSyncToManyRelationship");
-
- DataChannel serverChannel = new ClientServerChannel(getDomain());
- ClientChannel clientChannel = new ClientChannel(
- new LocalConnection(serverChannel),
- true);
+ tMtTable1.insert(1, "g1", "s1");
+ tMtTable2.insert(1, 1, "g1");
- CayenneContext c1 = new CayenneContext(clientChannel);
- CayenneContext c2 = new CayenneContext(clientChannel);
+ CayenneContext c1 = (CayenneContext) runtime.getContext();
+ CayenneContext c2 = (CayenneContext) runtime.getContext();
ClientMtTable1 o1 = (ClientMtTable1) Cayenne.objectForQuery(
c1,
@@ -253,19 +245,11 @@ public class CayenneContextClientChannel
}
public void testSyncToManyRelationship1() throws Exception {
- // this resets snapshot cache...
- createDataContext();
+ tMtTable1.insert(1, "g1", "s1");
+ tMtTable2.insert(1, 1, "g1");
- deleteTestData();
- createTestData("testSyncToManyRelationship");
-
- DataChannel serverChannel = new ClientServerChannel(getDomain());
- ClientChannel clientChannel = new ClientChannel(
- new LocalConnection(serverChannel),
- true);
-
- CayenneContext c1 = new CayenneContext(clientChannel);
- CayenneContext c2 = new CayenneContext(clientChannel);
+ CayenneContext c1 = (CayenneContext) runtime.getContext();
+ CayenneContext c2 = (CayenneContext) runtime.getContext();
ClientMtTable1 o1 = (ClientMtTable1) Cayenne.objectForQuery(
c1,
@@ -294,19 +278,14 @@ public class CayenneContextClientChannel
}
public void testSyncManyToManyRelationship() throws Exception {
- // this resets snapshot cache...
- createDataContext();
-
- deleteTestData();
- createTestData("testSyncManyToManyRelationship");
+ tMtTable4.insert(1);
+ tMtTable5.insert(1);
+ tMtTable5.insert(2);
+ tMtJoin45.insert(1, 1);
+ tMtJoin45.insert(1, 2);
- DataChannel serverChannel = new ClientServerChannel(getDomain());
- ClientChannel clientChannel = new ClientChannel(
- new LocalConnection(serverChannel),
- true);
-
- CayenneContext c1 = new CayenneContext(clientChannel);
- CayenneContext c2 = new CayenneContext(clientChannel);
+ CayenneContext c1 = (CayenneContext) runtime.getContext();
+ CayenneContext c2 = (CayenneContext) runtime.getContext();
ClientMtTable4 o1 = (ClientMtTable4) Cayenne.objectForQuery(
c1,
@@ -333,18 +312,9 @@ public class CayenneContextClientChannel
}
public void testSyncManyToManyRelationship1() throws Exception {
- // this resets snapshot cache...
- createDataContext();
-
- deleteTestData();
-
- DataChannel serverChannel = new ClientServerChannel(getDomain());
- ClientChannel clientChannel = new ClientChannel(
- new LocalConnection(serverChannel),
- true);
- CayenneContext c1 = new CayenneContext(clientChannel);
- CayenneContext c2 = new CayenneContext(clientChannel);
+ CayenneContext c1 = (CayenneContext) runtime.getContext();
+ CayenneContext c2 = (CayenneContext) runtime.getContext();
ClientMtTable4 o1 = c1.newObject(ClientMtTable4.class);
ClientMtTable5 o1r = c1.newObject(ClientMtTable5.class);
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/ClientServerChannelQueryTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/ClientServerChannelQueryTest.java?rev=956370&r1=956369&r2=956370&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/ClientServerChannelQueryTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/ClientServerChannelQueryTest.java Sun Jun 20 15:18:34 2010
@@ -21,48 +21,68 @@ package org.apache.cayenne.access;
import java.util.List;
-import org.apache.cayenne.CayenneContext;
import org.apache.cayenne.ObjectContext;
import org.apache.cayenne.ValueHolder;
import org.apache.cayenne.cache.QueryCache;
+import org.apache.cayenne.di.Inject;
import org.apache.cayenne.exp.Expression;
import org.apache.cayenne.query.NamedQuery;
import org.apache.cayenne.query.SelectQuery;
import org.apache.cayenne.query.SortOrder;
-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.ClientMtTable2;
-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;
import org.apache.cayenne.util.PersistentObjectHolder;
import org.apache.cayenne.util.PersistentObjectList;
-public class ClientServerChannelQueryTest extends CayenneCase {
+@UseServerRuntime(ClientCase.MULTI_TIER_PROJECT)
+public class ClientServerChannelQueryTest extends ClientCase {
- private ObjectContext context;
+ @Inject(ClientCase.ROP_CLIENT_KEY)
+ protected ObjectContext context;
+
+ @Inject
private ClientServerChannel serverChannel;
+ @Inject
+ private DBHelper dbHelper;
+
+ private TableHelper tMtTable1;
+ private TableHelper tMtTable2;
+
@Override
- protected void setUp() throws Exception {
- super.setUp();
+ protected void setUpAfterInjection() throws Exception {
+ dbHelper.deleteAll("MT_TABLE2");
+ dbHelper.deleteAll("MT_TABLE1");
- serverChannel = new ClientServerChannel(getDomain());
- LocalConnection connector = new LocalConnection(
- serverChannel,
- LocalConnection.HESSIAN_SERIALIZATION);
+ tMtTable1 = new TableHelper(dbHelper, "MT_TABLE1");
+ tMtTable1.setColumns("TABLE1_ID", "GLOBAL_ATTRIBUTE1", "SERVER_ATTRIBUTE1");
- context = new CayenneContext(new ClientChannel(connector));
+ tMtTable2 = new TableHelper(dbHelper, "MT_TABLE2");
+ tMtTable2.setColumns("TABLE2_ID", "TABLE1_ID", "GLOBAL_ATTRIBUTE");
}
- @Override
- protected AccessStack buildAccessStack() {
- return CayenneResources.getResources().getAccessStack(MULTI_TIER_ACCESS_STACK);
+ protected void createSevenMtTable1sDataSet() throws Exception {
+
+ for (int i = 1; i <= 7; i++) {
+ tMtTable1.insert(i, "g" + i, "s" + i);
+ }
+ }
+
+ protected void createTwoMtTable1sAnd2sDataSet() throws Exception {
+
+ tMtTable1.insert(1, "g1", "s1");
+ tMtTable1.insert(2, "g2", "s2");
+
+ tMtTable2.insert(1, 1, "g1");
+ tMtTable2.insert(2, 1, "g2");
}
public void testPaginatedQueryServerCacheOverflow() throws Exception {
- createTestData("testPaginatedQueryServerCacheOverflow");
+ createSevenMtTable1sDataSet();
SelectQuery query = new SelectQuery(ClientMtTable1.class);
query.addOrdering(ClientMtTable1.GLOBAL_ATTRIBUTE1_PROPERTY, SortOrder.ASCENDING);
@@ -84,7 +104,7 @@ public class ClientServerChannelQueryTes
}
public void testNamedQuery() throws Exception {
- createTestData("prepare");
+ createTwoMtTable1sAnd2sDataSet();
NamedQuery q = new NamedQuery("AllMtTable1");
List<?> results = context.performQuery(q);
@@ -94,7 +114,7 @@ public class ClientServerChannelQueryTes
}
public void testSelectQueryEntityNameRoot() throws Exception {
- createTestData("prepare");
+ createTwoMtTable1sAnd2sDataSet();
SelectQuery q = new SelectQuery("MtTable1");
List<?> results = context.performQuery(q);
@@ -105,7 +125,7 @@ public class ClientServerChannelQueryTes
}
public void testSelectQueryClientClassRoot() throws Exception {
- createTestData("prepare");
+ createTwoMtTable1sAnd2sDataSet();
SelectQuery q = new SelectQuery(ClientMtTable1.class);
List<?> results = context.performQuery(q);
@@ -115,7 +135,7 @@ public class ClientServerChannelQueryTes
}
public void testSelectQuerySimpleQualifier() throws Exception {
- createTestData("prepare");
+ createTwoMtTable1sAnd2sDataSet();
SelectQuery q = new SelectQuery(ClientMtTable1.class, Expression
.fromString("globalAttribute1 = 'g1'"));
@@ -127,7 +147,7 @@ public class ClientServerChannelQueryTes
}
public void testSelectQueryToManyRelationshipQualifier() throws Exception {
- createTestData("prepare");
+ createTwoMtTable1sAnd2sDataSet();
SelectQuery q = new SelectQuery(ClientMtTable1.class, Expression
.fromString("table2Array.globalAttribute = 'g1'"));
@@ -138,7 +158,7 @@ public class ClientServerChannelQueryTes
}
public void testSelectQueryOrdering() throws Exception {
- createTestData("prepare");
+ createTwoMtTable1sAnd2sDataSet();
SelectQuery q = new SelectQuery("MtTable1");
q.addOrdering(ClientMtTable1.GLOBAL_ATTRIBUTE1_PROPERTY, SortOrder.ASCENDING);
@@ -165,7 +185,7 @@ public class ClientServerChannelQueryTes
}
public void testSelectQueryPrefetchToOne() throws Exception {
- createTestData("prepare");
+ createTwoMtTable1sAnd2sDataSet();
SelectQuery q = new SelectQuery(ClientMtTable2.class, Expression
.fromString("globalAttribute = 'g1'"));
@@ -187,7 +207,7 @@ public class ClientServerChannelQueryTes
}
public void testSelectQueryPrefetchToMany() throws Exception {
- createTestData("prepare");
+ createTwoMtTable1sAnd2sDataSet();
SelectQuery q = new SelectQuery(ClientMtTable1.class, Expression
.fromString("globalAttribute1 = 'g1'"));
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=956370&r1=956369&r2=956370&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 15:18:34 2010
@@ -19,10 +19,7 @@
package org.apache.cayenne.access;
-import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
-import java.util.Map;
import org.apache.cayenne.DataChannel;
import org.apache.cayenne.MockDataChannel;
@@ -30,6 +27,7 @@ import org.apache.cayenne.ObjectContext;
import org.apache.cayenne.ObjectId;
import org.apache.cayenne.QueryResponse;
import org.apache.cayenne.ValueHolder;
+import org.apache.cayenne.di.Inject;
import org.apache.cayenne.graph.MockGraphDiff;
import org.apache.cayenne.graph.NodeCreateOperation;
import org.apache.cayenne.map.EntityResolver;
@@ -38,29 +36,65 @@ import org.apache.cayenne.query.Query;
import org.apache.cayenne.query.SelectQuery;
import org.apache.cayenne.query.SortOrder;
import org.apache.cayenne.remote.QueryMessage;
-import org.apache.cayenne.remote.hessian.service.HessianUtil;
+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.ClientMtTable2;
import org.apache.cayenne.testdo.mt.ClientMtTable3;
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.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;
-/**
- */
-public class ClientServerChannelTest extends CayenneCase {
+@UseServerRuntime(ClientCase.MULTI_TIER_PROJECT)
+public class ClientServerChannelTest extends ClientCase {
+
+ @Inject
+ protected DataContext serverContext;
+
+ @Inject
+ protected ClientServerChannel clientServerChannel;
+
+ @Inject
+ protected DBHelper dbHelper;
+
+ @Inject
+ protected DataChannelQueryInterceptor queryInterceptor;
+
+ private TableHelper tMtTable1;
+ private TableHelper tMtTable2;
+ private TableHelper tMtTable3;
@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");
+ dbHelper.deleteAll("MT_TABLE3");
+
+ tMtTable1 = new TableHelper(dbHelper, "MT_TABLE1");
+ tMtTable1.setColumns("TABLE1_ID", "GLOBAL_ATTRIBUTE1", "SERVER_ATTRIBUTE1");
+
+ tMtTable2 = new TableHelper(dbHelper, "MT_TABLE2");
+ tMtTable2.setColumns("TABLE2_ID", "TABLE1_ID", "GLOBAL_ATTRIBUTE");
+
+ tMtTable3 = new TableHelper(dbHelper, "MT_TABLE3");
+ tMtTable3.setColumns("TABLE3_ID", "BINARY_COLUMN", "CHAR_COLUMN", "INT_COLUMN");
+ }
+
+ protected void createTwoMtTable1sAnd2sDataSet() throws Exception {
+
+ tMtTable1.insert(1, "g1", "s1");
+ tMtTable1.insert(2, "g2", "s2");
+
+ tMtTable2.insert(1, 1, "g1");
+ tMtTable2.insert(2, 1, "g2");
}
public void testGetEntityResolver() throws Exception {
- EntityResolver resolver = new ClientServerChannel(getDomain())
- .getEntityResolver();
+ EntityResolver resolver = clientServerChannel.getEntityResolver();
assertNotNull(resolver);
assertNull(resolver.lookupObjEntity(ClientMtTable1.class));
assertNotNull(resolver.getClientEntityResolver().lookupObjEntity(
@@ -69,39 +103,32 @@ public class ClientServerChannelTest ext
public void testSynchronizeCommit() throws Exception {
- deleteTestData();
SelectQuery query = new SelectQuery(MtTable1.class);
- DataContext context = createDataContext();
-
- assertEquals(0, context.performQuery(query).size());
-
// no changes...
- ClientServerChannel channel = new ClientServerChannel(context);
- channel.onSync(context, new MockGraphDiff(), DataChannel.FLUSH_CASCADE_SYNC);
+ clientServerChannel.onSync(
+ serverContext,
+ new MockGraphDiff(),
+ DataChannel.FLUSH_CASCADE_SYNC);
- assertEquals(0, context.performQuery(query).size());
+ assertEquals(0, serverContext.performQuery(query).size());
// introduce changes
- channel.onSync(
- context,
- new NodeCreateOperation(new ObjectId("MtTable1")),
- DataChannel.FLUSH_CASCADE_SYNC);
+ clientServerChannel.onSync(serverContext, new NodeCreateOperation(new ObjectId(
+ "MtTable1")), DataChannel.FLUSH_CASCADE_SYNC);
- assertEquals(1, context.performQuery(query).size());
+ assertEquals(1, serverContext.performQuery(query).size());
}
public void testPerformQueryObjectIDInjection() throws Exception {
- createTestData("testOnSelectQueryObjectIDInjection");
-
- DataContext context = createDataContext();
+ tMtTable1.insert(55, "g1", "s1");
Query query = new SelectQuery("MtTable1");
- QueryResponse response = new ClientServerChannel(context).onQuery(null, query);
+ QueryResponse response = clientServerChannel.onQuery(null, query);
assertNotNull(response);
- List results = response.firstList();
+ List<?> results = response.firstList();
assertNotNull(results);
assertEquals(1, results.size());
@@ -122,22 +149,14 @@ public class ClientServerChannelTest ext
1, 2, 3
};
- String chars = "abc";
-
- Map parameters = new HashMap();
- parameters.put("bytes", bytes);
- parameters.put("chars", chars);
-
- createTestData("testOnSelectQueryValuePropagation", parameters);
-
- DataContext context = createDataContext();
+ tMtTable3.insert(1, bytes, "abc", 4);
Query query = new SelectQuery("MtTable3");
- QueryResponse response = new ClientServerChannel(context).onQuery(null, query);
+ QueryResponse response = clientServerChannel.onQuery(null, query);
assertNotNull(response);
- List results = response.firstList();
+ List<?> results = response.firstList();
assertNotNull(results);
assertEquals(1, results.size());
@@ -146,7 +165,7 @@ public class ClientServerChannelTest ext
assertTrue("Result is of wrong type: " + result, result instanceof ClientMtTable3);
ClientMtTable3 clientObject = (ClientMtTable3) result;
- assertEquals(chars, clientObject.getCharColumn());
+ assertEquals("abc", clientObject.getCharColumn());
assertEquals(new Integer(4), clientObject.getIntColumn());
assertTrue(new EqualsBuilder()
.append(clientObject.getBinaryColumn(), bytes)
@@ -155,30 +174,14 @@ public class ClientServerChannelTest ext
public void testPerformQueryPropagationInheritance() throws Exception {
- Map parameters = new HashMap();
- parameters.put("GLOBAL_ATTRIBUTE1", "sub1");
- parameters.put("SERVER_ATTRIBUTE1", "xyz");
- createTestData("testOnSelectQueryValuePropagationInheritance", parameters);
-
- DataContext context = createDataContext();
+ tMtTable1.insert(65, "sub1", "xyz");
- // must use real SelectQuery instead of mockup as root overriding depends on the
- // fact that Query inherits from AbstractQuery.
SelectQuery query = new SelectQuery(ClientMtTable1.class);
-
- // must pass through the serialization pipe before running query as
- // HessianSerializer has needed preprocessing hooks...
- Query preprocessedQuery = (Query) HessianUtil.cloneViaClientServerSerialization(
- query,
- context.getEntityResolver());
-
- QueryResponse response = new ClientServerChannel(context).onQuery(
- null,
- preprocessedQuery);
+ QueryResponse response = clientServerChannel.onQuery(null, query);
assertNotNull(response);
- List results = response.firstList();
+ List<?> results = response.firstList();
assertNotNull(results);
assertEquals(1, results.size());
@@ -212,74 +215,51 @@ public class ClientServerChannelTest ext
}
public void testOnQueryPrefetchingToMany() throws Exception {
- createTestData("testPrefetching");
+ createTwoMtTable1sAnd2sDataSet();
- DataContext context = createDataContext();
- ClientServerChannel channel = new ClientServerChannel(context);
+ SelectQuery query = new SelectQuery(ClientMtTable1.class);
+ query.addOrdering(ClientMtTable1.GLOBAL_ATTRIBUTE1_PROPERTY, SortOrder.ASCENDING);
+ query.addPrefetch(ClientMtTable1.TABLE2ARRAY_PROPERTY);
- SelectQuery q = new SelectQuery(ClientMtTable1.class);
- q.addOrdering(ClientMtTable1.GLOBAL_ATTRIBUTE1_PROPERTY, SortOrder.ASCENDING);
- q.addPrefetch(ClientMtTable1.TABLE2ARRAY_PROPERTY);
+ final List<?> results = clientServerChannel.onQuery(null, query).firstList();
+
+ queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
- // must pass through the serialization pipe before running query as
- // HessianSerializer has needed preprocessing hooks...
- Query preprocessedQuery = (Query) HessianUtil.cloneViaClientServerSerialization(
- q,
- context.getEntityResolver());
-
- List results = channel.onQuery(null, preprocessedQuery).firstList();
-
- blockQueries();
- try {
-
- ClientMtTable1 o1 = (ClientMtTable1) results.get(0);
- assertNull(o1.getObjectContext());
-
- List children1 = o1.getTable2Array();
-
- assertEquals(2, children1.size());
- Iterator it = children1.iterator();
- while (it.hasNext()) {
- ClientMtTable2 o = (ClientMtTable2) it.next();
- assertNull(o.getObjectContext());
+ public void execute() {
+ ClientMtTable1 o1 = (ClientMtTable1) results.get(0);
+ assertNull(o1.getObjectContext());
+
+ List<ClientMtTable2> children1 = o1.getTable2Array();
+
+ assertEquals(2, children1.size());
+ for (ClientMtTable2 o : children1) {
+ assertNull(o.getObjectContext());
+ }
}
- }
- finally {
- unblockQueries();
- }
+ });
}
public void testOnQueryPrefetchingToManyEmpty() throws Exception {
- createTestData("testPrefetching");
-
- DataContext context = createDataContext();
- ClientServerChannel channel = new ClientServerChannel(context);
+ createTwoMtTable1sAnd2sDataSet();
SelectQuery q = new SelectQuery(ClientMtTable1.class);
q.addOrdering(ClientMtTable1.GLOBAL_ATTRIBUTE1_PROPERTY, SortOrder.ASCENDING);
q.addPrefetch(ClientMtTable1.TABLE2ARRAY_PROPERTY);
- // must pass through the serialization pipe before running query as
- // HessianSerializer has needed preprocessing hooks...
- Query preprocessedQuery = (Query) HessianUtil.cloneViaClientServerSerialization(
- q,
- context.getEntityResolver());
-
- List results = channel.onQuery(null, preprocessedQuery).firstList();
-
- blockQueries();
- try {
-
- ClientMtTable1 o2 = (ClientMtTable1) results.get(1);
- assertNull(o2.getObjectContext());
-
- List children2 = o2.getTable2Array();
- assertNotNull(children2);
- assertFalse(((ValueHolder) children2).isFault());
- assertEquals(0, children2.size());
- }
- finally {
- unblockQueries();
- }
+ final List<?> results = clientServerChannel.onQuery(null, q).firstList();
+
+ queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
+
+ public void execute() {
+
+ ClientMtTable1 o2 = (ClientMtTable1) results.get(1);
+ assertNull(o2.getObjectContext());
+
+ List<?> children2 = o2.getTable2Array();
+ assertNotNull(children2);
+ assertFalse(((ValueHolder) children2).isFault());
+ assertEquals(0, children2.size());
+ }
+ });
}
}
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLArrayResultTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLArrayResultTest.java?rev=956370&r1=956369&r2=956370&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLArrayResultTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLArrayResultTest.java Sun Jun 20 15:18:34 2010
@@ -70,7 +70,7 @@ public class DataContextEJBQLArrayResult
EJBQLQuery query = new EJBQLQuery(ejbql);
- List objects = context.performQuery(query);
+ List<?> objects = context.performQuery(query);
assertEquals(1, objects.size());
Object o1 = objects.get(0);
@@ -83,7 +83,7 @@ public class DataContextEJBQLArrayResult
EJBQLQuery query = new EJBQLQuery(ejbql);
- List objects = context.performQuery(query);
+ List<?> objects = context.performQuery(query);
assertEquals(1, objects.size());
Object o1 = objects.get(0);
@@ -103,7 +103,7 @@ public class DataContextEJBQLArrayResult
EJBQLQuery query = new EJBQLQuery(ejbql);
- List objects = context.performQuery(query);
+ List<?> objects = context.performQuery(query);
assertEquals(4, objects.size());
Object o1 = objects.get(0);
Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientCase.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientCase.java?rev=956370&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientCase.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientCase.java Sun Jun 20 15:18:34 2010
@@ -0,0 +1,49 @@
+/*****************************************************************
+ * 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 org.apache.cayenne.di.DIBootstrap;
+import org.apache.cayenne.di.Injector;
+import org.apache.cayenne.di.spi.DefaultScope;
+import org.apache.cayenne.unit.CayenneResources;
+import org.apache.cayenne.unit.di.DICase;
+import org.apache.cayenne.unit.di.server.ServerCaseModule;
+
+public class ClientCase extends DICase {
+
+ public static final String ROP_CLIENT_KEY = "client";
+
+ public static final String MULTI_TIER_PROJECT = "cayenne-multi-tier.xml";
+
+ private static final Injector injector;
+
+ static {
+ final CayenneResources resources = CayenneResources.getResources();
+ DefaultScope testScope = new DefaultScope();
+ injector = DIBootstrap.createInjector(
+ new ServerCaseModule(resources, testScope),
+ new ClientCaseModule(testScope));
+ }
+
+ @Override
+ protected Injector getUnitTestInjector() {
+ return injector;
+ }
+
+}
Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientCaseLifecycleManager.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientCaseLifecycleManager.java?rev=956370&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientCaseLifecycleManager.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientCaseLifecycleManager.java Sun Jun 20 15:18:34 2010
@@ -0,0 +1,69 @@
+/*****************************************************************
+ * 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 java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.di.Provider;
+import org.apache.cayenne.di.spi.DefaultScope;
+import org.apache.cayenne.unit.di.server.ServerCaseLifecycleManager;
+
+public class ClientCaseLifecycleManager extends ServerCaseLifecycleManager {
+
+ @Inject
+ protected Provider<ClientCaseProperties> propertiesProvider;
+
+ public ClientCaseLifecycleManager(DefaultScope scope) {
+ super(scope);
+ }
+
+ @Override
+ public <T extends TestCase> void setUp(T testCase) {
+
+ Map<String, String> map = new HashMap<String, String>();
+
+ ClientRuntimeProperty properties = testCase.getClass().getAnnotation(
+ ClientRuntimeProperty.class);
+
+ if (properties != null) {
+ String[] pairs = properties.value();
+ if (pairs != null && pairs.length > 1) {
+
+ String key = null;
+
+ for (int i = 0; i < pairs.length; i++) {
+ if (i % 2 == 0) {
+ key = pairs[i];
+ }
+ else {
+ map.put(key, pairs[i]);
+ }
+ }
+ }
+ }
+
+ propertiesProvider.get().setRuntimeProperties(map);
+
+ super.setUp(testCase);
+ }
+}
Added: 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=956370&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientCaseModule.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientCaseModule.java Sun Jun 20 15:18:34 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.client;
+
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.access.ClientServerChannel;
+import org.apache.cayenne.configuration.rop.client.ClientRuntime;
+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.UnitTestLifecycleManager;
+
+public class ClientCaseModule implements Module {
+
+ protected DefaultScope testScope;
+
+ public ClientCaseModule(DefaultScope testScope) {
+ this.testScope = testScope;
+ }
+
+ public void configure(Binder binder) {
+
+ // singletons
+
+ binder.bind(UnitTestLifecycleManager.class).toInstance(
+ new ClientCaseLifecycleManager(testScope));
+
+ // test-scoped objects
+
+ binder.bind(ClientCaseProperties.class).to(ClientCaseProperties.class).in(
+ testScope);
+
+ binder.bind(ClientRuntime.class).toProvider(ClientRuntimeProvider.class).in(
+ testScope);
+
+ binder.bind(Key.get(ObjectContext.class, ClientCase.ROP_CLIENT_KEY)).toProvider(
+ ClientCaseObjectContextProvider.class).in(testScope);
+
+ binder.bind(ClientServerChannel.class).toProvider(
+ ClientServerChannelProvider.class).in(testScope);
+ }
+}
Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientCaseObjectContextProvider.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientCaseObjectContextProvider.java?rev=956370&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientCaseObjectContextProvider.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientCaseObjectContextProvider.java Sun Jun 20 15:18:34 2010
@@ -0,0 +1,35 @@
+/*****************************************************************
+ * 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 org.apache.cayenne.ConfigurationException;
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.configuration.rop.client.ClientRuntime;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.di.Provider;
+
+public class ClientCaseObjectContextProvider implements Provider<ObjectContext> {
+
+ @Inject
+ protected Provider<ClientRuntime> clientRuntimeProvider;
+
+ public ObjectContext get() throws ConfigurationException {
+ return clientRuntimeProvider.get().getContext();
+ }
+}
Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientCaseProperties.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientCaseProperties.java?rev=956370&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientCaseProperties.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientCaseProperties.java Sun Jun 20 15:18:34 2010
@@ -0,0 +1,36 @@
+/*****************************************************************
+ * 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 java.util.Collections;
+import java.util.Map;
+
+public class ClientCaseProperties {
+
+ protected Map<String, String> runtimeProperties;
+
+ Map<String, String> getRuntimeProperties() {
+ return runtimeProperties != null ? runtimeProperties : Collections.EMPTY_MAP;
+ }
+
+ void setRuntimeProperties(Map<String, String> runtimeProperties) {
+ this.runtimeProperties = runtimeProperties;
+ }
+
+}
Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientCaseSelfTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientCaseSelfTest.java?rev=956370&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientCaseSelfTest.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientCaseSelfTest.java Sun Jun 20 15:18:34 2010
@@ -0,0 +1,46 @@
+/*****************************************************************
+ * 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 org.apache.cayenne.configuration.server.ServerRuntime;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.di.Provider;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+@UseServerRuntime(ClientCase.MULTI_TIER_PROJECT)
+public class ClientCaseSelfTest extends ClientCase {
+
+ @Inject
+ protected ServerRuntime runtime;
+
+ @Inject
+ protected Provider<ServerRuntime> runtimeProvider;
+
+ public void testServerSetup_TearDown_Runtime() throws Exception {
+
+ ServerRuntime local = this.runtime;
+ assertNotNull(local);
+ assertSame(local, runtimeProvider.get());
+
+ tearDown();
+
+ setUp();
+ assertNotSame(local, this.runtime);
+ }
+}
Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientRuntimeProperty.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientRuntimeProperty.java?rev=956370&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientRuntimeProperty.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientRuntimeProperty.java Sun Jun 20 15:18:34 2010
@@ -0,0 +1,36 @@
+/*****************************************************************
+ * 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 java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Used to annotate unit test classes to specify runtime properties for a given test case.
+ */
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+public @interface ClientRuntimeProperty {
+
+ String[] value();
+}
Added: 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=956370&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientRuntimeProvider.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientRuntimeProvider.java Sun Jun 20 15:18:34 2010
@@ -0,0 +1,43 @@
+/*****************************************************************
+ * 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 org.apache.cayenne.ConfigurationException;
+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.Inject;
+import org.apache.cayenne.di.Injector;
+import org.apache.cayenne.di.Provider;
+
+public class ClientRuntimeProvider implements Provider<ClientRuntime> {
+
+ @Inject
+ // injecting provider to make this provider independent from scoping of ServerRuntime
+ protected Provider<ServerRuntime> serverRuntimeProvider;
+
+ @Inject
+ protected ClientCaseProperties clientCaseProperties;
+
+ public ClientRuntime get() throws ConfigurationException {
+ Injector serverInjector = serverRuntimeProvider.get().getInjector();
+ return new ClientLocalRuntime(serverInjector, clientCaseProperties
+ .getRuntimeProperties());
+ }
+}
Added: 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=956370&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientServerChannelProvider.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/client/ClientServerChannelProvider.java Sun Jun 20 15:18:34 2010
@@ -0,0 +1,40 @@
+/*****************************************************************
+ * 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 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;
+
+public class ClientServerChannelProvider implements Provider<ClientServerChannel> {
+
+ @Inject
+ protected Provider<ClientRuntime> clientRuntimeProvider;
+
+ public ClientServerChannel get() throws ConfigurationException {
+
+ LocalConnection connection = (LocalConnection) clientRuntimeProvider
+ .get()
+ .getConnection();
+ return (ClientServerChannel) connection.getChannel();
+ }
+}
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCase.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCase.java?rev=956370&r1=956369&r2=956370&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCase.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCase.java Sun Jun 20 15:18:34 2010
@@ -18,24 +18,11 @@
****************************************************************/
package org.apache.cayenne.unit.di.server;
-import javax.sql.DataSource;
-
-import org.apache.cayenne.ObjectContext;
-import org.apache.cayenne.access.DataContext;
-import org.apache.cayenne.access.DataNode;
-import org.apache.cayenne.configuration.server.ServerRuntime;
-import org.apache.cayenne.dba.DbAdapter;
-import org.apache.cayenne.di.Binder;
import org.apache.cayenne.di.DIBootstrap;
import org.apache.cayenne.di.Injector;
-import org.apache.cayenne.di.Module;
import org.apache.cayenne.di.spi.DefaultScope;
-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.DICase;
-import org.apache.cayenne.unit.di.UnitTestLifecycleManager;
-import org.apache.cayenne.unit.util.SQLTemplateCustomizer;
public class ServerCase extends DICase {
@@ -50,57 +37,9 @@ public class ServerCase extends DICase {
private static final Injector injector;
static {
-
- // TODO: andrus 6/14/2010 - this should probably also be DI driven
- final CayenneResources resources = CayenneResources.getResources();
-
- Module module = new Module() {
-
- public void configure(Binder binder) {
- DefaultScope testScope = new DefaultScope();
-
- // these are the objects injectable in unit tests that subclass from
- // ServerCase. Note that ServerRuntimeProvider creates ServerRuntime
- // instances complete with their own DI injectors, independent from the
- // unit test injector. ServerRuntime injector contents are customized
- // inside ServerRuntimeProvider.
-
- // singleton objects
- binder.bind(UnitTestLifecycleManager.class).toInstance(
- new ServerCaseLifecycleManager(testScope));
-
- binder.bind(DataSource.class).toProviderInstance(
- new CayenneResourcesDataSourceProvider(resources));
- binder.bind(DbAdapter.class).toProviderInstance(
- new CayenneResourcesDbAdapterProvider(resources));
- binder.bind(AccessStackAdapter.class).toProviderInstance(
- new CayenneResourcesAccessStackAdapterProvider(resources));
- binder.bind(DataNode.class).toProvider(ServerCaseDataNodeProvider.class);
- binder.bind(DataChannelQueryInterceptor.class).to(
- ServerCaseDataChannelQueryInterceptor.class);
- binder.bind(SQLTemplateCustomizer.class).toProviderInstance(
- new CayenneResourcesSQLTemplateCustomizerProvider(resources));
-
- // test-scoped objects
- binder
- .bind(ServerCaseProperties.class)
- .to(ServerCaseProperties.class)
- .in(testScope);
- binder.bind(ServerRuntime.class).toProviderInstance(
- new ServerRuntimeProvider(resources)).in(testScope);
- binder.bind(ObjectContext.class).toProvider(
- ServerCaseObjectContextProvider.class).in(testScope);
- binder.bind(DataContext.class).toProvider(
- ServerCaseDataContextProvider.class).in(testScope);
- binder
- .bind(DBHelper.class)
- .toProvider(FlavoredDBHelperProvider.class)
- .in(testScope);
-
- }
- };
-
- injector = DIBootstrap.createInjector(module);
+ CayenneResources resources = CayenneResources.getResources();
+ DefaultScope testScope = new DefaultScope();
+ injector = DIBootstrap.createInjector(new ServerCaseModule(resources, testScope));
}
@Override
Added: 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=956370&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseModule.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseModule.java Sun Jun 20 15:18:34 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.server;
+
+import javax.sql.DataSource;
+
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.access.DataContext;
+import org.apache.cayenne.access.DataNode;
+import org.apache.cayenne.configuration.server.ServerRuntime;
+import org.apache.cayenne.dba.DbAdapter;
+import org.apache.cayenne.di.Binder;
+import org.apache.cayenne.di.Module;
+import org.apache.cayenne.di.spi.DefaultScope;
+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.UnitTestLifecycleManager;
+import org.apache.cayenne.unit.util.SQLTemplateCustomizer;
+
+public class ServerCaseModule implements Module {
+
+ protected CayenneResources resources;
+ protected DefaultScope testScope;
+
+ public ServerCaseModule(CayenneResources resources, DefaultScope testScope) {
+ this.resources = resources;
+ this.testScope = testScope;
+ }
+
+ public void configure(Binder binder) {
+
+ // these are the objects injectable in unit tests that subclass from
+ // ServerCase. Note that ServerRuntimeProvider creates ServerRuntime
+ // instances complete with their own DI injectors, independent from the
+ // unit test injector. ServerRuntime injector contents are customized
+ // inside ServerRuntimeProvider.
+
+ // singleton objects
+ binder.bind(UnitTestLifecycleManager.class).toInstance(
+ new ServerCaseLifecycleManager(testScope));
+
+ binder.bind(DataSource.class).toProviderInstance(
+ new CayenneResourcesDataSourceProvider(resources));
+ binder.bind(DbAdapter.class).toProviderInstance(
+ new CayenneResourcesDbAdapterProvider(resources));
+ binder.bind(AccessStackAdapter.class).toProviderInstance(
+ new CayenneResourcesAccessStackAdapterProvider(resources));
+ binder.bind(DataNode.class).toProvider(ServerCaseDataNodeProvider.class);
+ binder.bind(DataChannelQueryInterceptor.class).to(
+ ServerCaseDataChannelQueryInterceptor.class);
+ binder.bind(SQLTemplateCustomizer.class).toProviderInstance(
+ new CayenneResourcesSQLTemplateCustomizerProvider(resources));
+
+ // test-scoped objects
+ binder.bind(ServerCaseProperties.class).to(ServerCaseProperties.class).in(
+ testScope);
+ binder.bind(ServerRuntime.class).toProviderInstance(
+ new ServerRuntimeProvider(resources)).in(testScope);
+
+ binder
+ .bind(ObjectContext.class)
+ .toProvider(ServerCaseObjectContextProvider.class)
+ .in(testScope);
+ binder
+ .bind(DataContext.class)
+ .toProvider(ServerCaseDataContextProvider.class)
+ .in(testScope);
+
+ binder.bind(DBHelper.class).toProvider(FlavoredDBHelperProvider.class).in(
+ testScope);
+ }
+
+}
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/cayenne-default.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/cayenne-default.xml?rev=956370&r1=956369&r2=956370&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/cayenne-default.xml (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/cayenne-default.xml Sun Jun 20 15:18:34 2010
@@ -5,9 +5,9 @@
<map name="locking"/>
<map name="map-db1"/>
<map name="map-db2"/>
- <map name="multi-tier"/>
<map name="people"/>
<map name="qualified"/>
<map name="relationships"/>
<map name="sus-map"/>
</domain>
+
Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/cayenne-multi-tier.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/cayenne-multi-tier.xml?rev=956370&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/cayenne-multi-tier.xml (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/cayenne-multi-tier.xml Sun Jun 20 15:18:34 2010
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<domain project-version="6">
+ <map name="multi-tier"/>
+</domain>
\ No newline at end of file