cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r954454 [1/2] - in /cayenne/main/trunk: build-tools/cayenne-test-utilities/ build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/jdbc/ framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/ framework/c...
Date Mon, 14 Jun 2010 13:35:33 GMT
Author: aadamchik
Date: Mon Jun 14 13:35:32 2010
New Revision: 954454

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

* a simple framework for DI-based unit testing
* allowing annotations of non-public classes
* a better startup logging
* adding logging to DBHelper
* deleting "inheritance-map" stack that was attempting to deal with horizontal inheritance
* switching test stacks to the new injectable testing:
	inheritance-vertical,
	inheritance-single-table1
	quoted-identifiers

Added:
    cayenne/main/trunk/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/jdbc/UtilityLogger.java
      - copied, changed from r954444, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/InheritanceCase.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/QuotedIdentifiersTest.java
      - copied, changed from r954444, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContexQuoteTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/SingleTableInheritance1Test.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/DICase.java
      - copied, changed from r954444, cayenne/main/trunk/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/jdbc/ResultSetTemplate.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/DICaseSelfTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/DefaultUnitTestLifecycleManager.java
      - copied, changed from r954444, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/InheritanceCase.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/UnitTestLifecycleManager.java
      - copied, changed from r954444, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/InheritanceCase.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/UnitTestScope.java
      - copied, changed from r954444, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/InheritanceCase.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/UnitTestScopedProvider.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/CachingServerRuntimeFactory.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/CayenneResourcesDataSourceProvider.java
      - copied, changed from r954444, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/InheritanceCase.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/CayenneResourcesDbAdapterProvider.java
      - copied, changed from r954444, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/InheritanceCase.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/FlavoredDBHelper.java
      - copied, changed from r954444, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/InheritanceCase.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/FlavoredDBHelperProvider.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCase.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataContextProvider.java
      - copied, changed from r954444, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/InheritanceCase.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataDomainProvider.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseLifecycleManager.java
      - copied, changed from r954444, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/InheritanceCase.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseProperties.java
      - copied, changed from r954444, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/InheritanceCase.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseSelfTest.java
      - copied, changed from r954444, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/InheritanceCase.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerRuntimeFactory.java
      - copied, changed from r954444, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/InheritanceCase.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/UseServerRuntime.java
      - copied, changed from r954444, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/InheritanceCase.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/cayenne-inheritance-single-table1.xml
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/cayenne-inheritance-vertical.xml
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/cayenne-quoted-identifiers.xml
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/inheritance-single-table1.map.xml
      - copied, changed from r954444, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/inheritance-flat.map.xml
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/quoted-identifiers.map.xml
      - copied, changed from r954444, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/quotemap.map.xml
Removed:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContexQuoteTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/HorizontalInheritanceTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/reflect/ClassDescriptorInheritanceInContextTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/InheritanceCase.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/jira/CAY_1378Test.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/jira/CAY_1379Test.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/inheritance-flat.map.xml
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/inheritance.map.xml
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/quotemap.map.xml
Modified:
    cayenne/main/trunk/build-tools/cayenne-test-utilities/pom.xml
    cayenne/main/trunk/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/jdbc/DBHelper.java
    cayenne/main/trunk/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/jdbc/ResultSetTemplate.java
    cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/EventfulScope.java
    cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/ScopeEventBinding.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/XMLDataChannelDescriptorLoader.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/VerticalInheritanceTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/CayenneCase.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/CayenneResources.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/SimpleAccessStack.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/cayenne-default.xml
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/spring-test-resources.xml

Modified: cayenne/main/trunk/build-tools/cayenne-test-utilities/pom.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/build-tools/cayenne-test-utilities/pom.xml?rev=954454&r1=954453&r2=954454&view=diff
==============================================================================
--- cayenne/main/trunk/build-tools/cayenne-test-utilities/pom.xml (original)
+++ cayenne/main/trunk/build-tools/cayenne-test-utilities/pom.xml Mon Jun 14 13:35:32 2010
@@ -41,6 +41,10 @@
 			<artifactId>junit</artifactId>
 			<scope>compile</scope>
 		</dependency>
+		<dependency>
+			<groupId>commons-logging</groupId>
+			<artifactId>commons-logging</artifactId>
+		</dependency>
 	</dependencies>
 
 	<build>

Modified: cayenne/main/trunk/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/jdbc/DBHelper.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/jdbc/DBHelper.java?rev=954454&r1=954453&r2=954454&view=diff
==============================================================================
--- cayenne/main/trunk/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/jdbc/DBHelper.java (original)
+++ cayenne/main/trunk/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/jdbc/DBHelper.java Mon Jun 14 13:35:32 2010
@@ -42,6 +42,15 @@ public class DBHelper {
     }
 
     /**
+     * Quotes a SQL identifier as appropriate for the given DB. This implementation
+     * returns the identifier unchanged, while subclasses can implement a custom quoting
+     * strategy.
+     */
+    protected String quote(String sqlIdentifier) {
+        return sqlIdentifier;
+    }
+
+    /**
      * Selects a single row.
      */
     public Object[] select(String table, final String[] columns) throws SQLException {
@@ -51,11 +60,11 @@ public class DBHelper {
         }
 
         StringBuilder sql = new StringBuilder("select ");
-        sql.append(columns[0]);
+        sql.append(quote(columns[0]));
         for (int i = 1; i < columns.length; i++) {
-            sql.append(", ").append(columns[i]);
+            sql.append(", ").append(quote(columns[i]));
         }
-        sql.append(" from ").append(table);
+        sql.append(" from ").append(quote(table));
 
         return new RowTemplate<Object[]>(this) {
 
@@ -91,9 +100,9 @@ public class DBHelper {
         }
 
         StringBuilder sql = new StringBuilder("INSERT INTO ");
-        sql.append(table).append(" (").append(columns[0]);
+        sql.append(quote(table)).append(" (").append(quote(columns[0]));
         for (int i = 1; i < columns.length; i++) {
-            sql.append(", ").append(columns[i]);
+            sql.append(", ").append(quote(columns[i]));
         }
 
         sql.append(") VALUES (?");
@@ -105,7 +114,9 @@ public class DBHelper {
         Connection c = getConnection();
         try {
 
-            PreparedStatement st = c.prepareStatement(sql.toString());
+            String sqlString = sql.toString();
+            UtilityLogger.log(sqlString);
+            PreparedStatement st = c.prepareStatement(sqlString);
             ParameterMetaData parameters = null;
             try {
                 for (int i = 0; i < values.length; i++) {
@@ -137,8 +148,9 @@ public class DBHelper {
     }
 
     public int deleteAll(String table) throws SQLException {
-        String sql = "delete from " + table;
-
+        String sql = "delete from " + quote(table);
+        UtilityLogger.log(sql);
+        
         Connection c = getConnection();
         try {
 
@@ -155,7 +167,7 @@ public class DBHelper {
     }
 
     public int getRowCount(String table) throws SQLException {
-        String sql = "select count(*) from " + table;
+        String sql = "select count(*) from " + quote(table);
 
         return new RowTemplate<Integer>(this) {
 
@@ -168,7 +180,7 @@ public class DBHelper {
     }
 
     public Object getObject(String table, String column) throws SQLException {
-        final String sql = "select " + column + " from " + table;
+        final String sql = "select " + quote(column) + " from " + quote(table);
 
         return new RowTemplate<Object>(this) {
 
@@ -181,7 +193,7 @@ public class DBHelper {
     }
 
     public byte getByte(String table, String column) throws SQLException {
-        final String sql = "select " + column + " from " + table;
+        final String sql = "select " + quote(column) + " from " + quote(table);
 
         return new RowTemplate<Byte>(this) {
 
@@ -194,7 +206,7 @@ public class DBHelper {
     }
 
     public byte[] getBytes(String table, String column) throws SQLException {
-        final String sql = "select " + column + " from " + table;
+        final String sql = "select " + quote(column) + " from " + quote(table);
 
         return new RowTemplate<byte[]>(this) {
 
@@ -207,7 +219,7 @@ public class DBHelper {
     }
 
     public int getInt(String table, String column) throws SQLException {
-        final String sql = "select " + column + " from " + table;
+        final String sql = "select " + quote(column) + " from " + quote(table);
 
         return new RowTemplate<Integer>(this) {
 
@@ -220,7 +232,7 @@ public class DBHelper {
     }
 
     public long getLong(String table, String column) throws SQLException {
-        final String sql = "select " + column + " from " + table;
+        final String sql = "select " + quote(column) + " from " + quote(table);
 
         return new RowTemplate<Long>(this) {
 
@@ -233,7 +245,7 @@ public class DBHelper {
     }
 
     public double getDouble(String table, String column) throws SQLException {
-        final String sql = "select " + column + " from " + table;
+        final String sql = "select " + quote(column) + " from " + quote(table);
 
         return new RowTemplate<Double>(this) {
 
@@ -246,7 +258,7 @@ public class DBHelper {
     }
 
     public boolean getBoolean(String table, String column) throws SQLException {
-        final String sql = "select " + column + " from " + table;
+        final String sql = "select " + quote(column) + " from " + quote(table);
 
         return new RowTemplate<Boolean>(this) {
 
@@ -264,7 +276,7 @@ public class DBHelper {
     }
 
     public java.sql.Date getSqlDate(String table, String column) throws SQLException {
-        final String sql = "select " + column + " from " + table;
+        final String sql = "select " + quote(column) + " from " + quote(table);
 
         return new RowTemplate<java.sql.Date>(this) {
 
@@ -277,7 +289,7 @@ public class DBHelper {
     }
 
     public Time getTime(String table, String column) throws SQLException {
-        final String sql = "select " + column + " from " + table;
+        final String sql = "select " + quote(column) + " from " + quote(table);
 
         return new RowTemplate<Time>(this) {
 
@@ -290,7 +302,7 @@ public class DBHelper {
     }
 
     public Timestamp getTimestamp(String table, String column) throws SQLException {
-        final String sql = "select " + column + " from " + table;
+        final String sql = "select " + quote(column) + " from " + quote(table);
 
         return new RowTemplate<Timestamp>(this) {
 

Modified: cayenne/main/trunk/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/jdbc/ResultSetTemplate.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/jdbc/ResultSetTemplate.java?rev=954454&r1=954453&r2=954454&view=diff
==============================================================================
--- cayenne/main/trunk/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/jdbc/ResultSetTemplate.java (original)
+++ cayenne/main/trunk/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/jdbc/ResultSetTemplate.java Mon Jun 14 13:35:32 2010
@@ -34,6 +34,7 @@ abstract class ResultSetTemplate<T> {
     abstract T readResultSet(ResultSet rs, String sql) throws SQLException;
 
     T execute(String sql) throws SQLException {
+        UtilityLogger.log(sql);
         Connection c = parent.getConnection();
         try {
 

Copied: cayenne/main/trunk/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/jdbc/UtilityLogger.java (from r954444, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/InheritanceCase.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/jdbc/UtilityLogger.java?p2=cayenne/main/trunk/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/jdbc/UtilityLogger.java&p1=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/InheritanceCase.java&r1=954444&r2=954454&rev=954454&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/InheritanceCase.java (original)
+++ cayenne/main/trunk/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/jdbc/UtilityLogger.java Mon Jun 14 13:35:32 2010
@@ -16,17 +16,16 @@
  *  specific language governing permissions and limitations
  *  under the License.
  ****************************************************************/
-package org.apache.cayenne.unit;
+package org.apache.cayenne.test.jdbc;
 
-/**
- * A superclass of test cases using "inheritance" DataMap for its access stack.
- * 
- */
-public abstract class InheritanceCase extends CayenneCase {
-    public static final String INHERITANCE_ACCESS_STACK = "InheritanceStack";
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
-    @Override
-    protected AccessStack buildAccessStack() {
-        return CayenneResources.getResources().getAccessStack(INHERITANCE_ACCESS_STACK);
+class UtilityLogger {
+
+    private static Log logger = LogFactory.getLog(UtilityLogger.class);
+    
+    static void log(String sql) {
+        logger.info(sql);
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/EventfulScope.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/EventfulScope.java?rev=954454&r1=954453&r2=954454&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/EventfulScope.java (original)
+++ cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/EventfulScope.java Mon Jun 14 13:35:32 2010
@@ -91,7 +91,7 @@ public abstract class EventfulScope impl
      * event dispatching. An exception thrown by any of the listeners stops further event
      * processing and is rethrown.
      */
-    protected void postScopeEvent(
+    public void postScopeEvent(
             Class<? extends Annotation> type,
             Object... eventParameters) {
 

Modified: cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/ScopeEventBinding.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/ScopeEventBinding.java?rev=954454&r1=954453&r2=954454&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/ScopeEventBinding.java (original)
+++ cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/ScopeEventBinding.java Mon Jun 14 13:35:32 2010
@@ -37,6 +37,9 @@ class ScopeEventBinding {
         this.object = object;
         this.eventHandlerMethod = eventHandlerMethod;
         this.argWidth = eventHandlerMethod.getParameterTypes().length;
+
+        // allow public methods of non-public classes to be annotated
+        eventHandlerMethod.setAccessible(true);
     }
 
     void onScopeEvent(Object... eventArgs) {

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/XMLDataChannelDescriptorLoader.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/XMLDataChannelDescriptorLoader.java?rev=954454&r1=954453&r2=954454&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/XMLDataChannelDescriptorLoader.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/XMLDataChannelDescriptorLoader.java Mon Jun 14 13:35:32 2010
@@ -117,12 +117,16 @@ public class XMLDataChannelDescriptorLoa
 
     public ConfigurationTree<DataChannelDescriptor> load(Resource configurationResource)
             throws ConfigurationException {
+        
+      
 
         if (configurationResource == null) {
             throw new NullPointerException("Null configurationResource");
         }
 
         URL configurationURL = configurationResource.getURL();
+        
+        logger.info("Loading XML configuration resource from " + configurationURL);
 
         DataChannelDescriptor descriptor = new DataChannelDescriptor();
         descriptor.setConfigurationSource(configurationResource);

Copied: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/QuotedIdentifiersTest.java (from r954444, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContexQuoteTest.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/QuotedIdentifiersTest.java?p2=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/QuotedIdentifiersTest.java&p1=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContexQuoteTest.java&r1=954444&r2=954454&rev=954454&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContexQuoteTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/QuotedIdentifiersTest.java Mon Jun 14 13:35:32 2010
@@ -22,87 +22,81 @@ import java.util.Collections;
 import java.util.Date;
 import java.util.List;
 
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.query.SelectQuery;
 import org.apache.cayenne.query.UpdateBatchQuery;
+import org.apache.cayenne.test.jdbc.DBHelper;
 import org.apache.cayenne.testdo.quotemap.QuoteAdress;
 import org.apache.cayenne.testdo.quotemap.Quote_Person;
-import org.apache.cayenne.unit.AccessStack;
-import org.apache.cayenne.unit.CayenneCase;
-import org.apache.cayenne.unit.CayenneResources;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
 
+@UseServerRuntime(ServerCase.QUOTED_IDENTIFIERS_STACK)
+public class QuotedIdentifiersTest extends ServerCase {
 
+    @Inject
+    private ObjectContext context;
 
-public class DataContexQuoteTest extends CayenneCase{
-    private DataContext context;
+    @Inject
+    private DBHelper dbHelper;
 
     @Override
-    protected AccessStack buildAccessStack() {
-        return CayenneResources.getResources().getAccessStack(QUOTEMAP_ACCESS_STACK);
+    protected void setUpAfterInjection() throws Exception {
+        dbHelper.deleteAll("QUOTED_ADDRESS");
+        dbHelper.deleteAll("quote Person");
     }
-    
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-        deleteTestData();
-        context = createDataContext();
-    }
-    
+
     public void testPrefetchQuote() throws Exception {
-        
-        // work with tables QuoteAdress and Quote_Person. 
-        // In this table parameter quoteSqlIdentifiers = true. 
-        
-        QuoteAdress quoteAdress = (QuoteAdress) context.newObject("QuoteAdress");
+
+        QuoteAdress quoteAdress = context.newObject(QuoteAdress.class);
         quoteAdress.setCity("city");
-        
-        Quote_Person quote_Person = (Quote_Person) context.newObject("Quote_Person");
+
+        Quote_Person quote_Person = context.newObject(Quote_Person.class);
         quote_Person.setSalary(10000);
         quote_Person.setName("Arcadi");
-        
+
         context.commitChanges();
-        
+
         SelectQuery q = new SelectQuery(QuoteAdress.class);
         List objects = context.performQuery(q);
         assertEquals(1, objects.size());
-        
-        
+
         SelectQuery qQuote_Person = new SelectQuery(Quote_Person.class);
         List objects2 = context.performQuery(qQuote_Person);
         assertEquals(1, objects2.size());
-        
-        QuoteAdress quoteAdress2 = (QuoteAdress) context.newObject("QuoteAdress");
+
+        QuoteAdress quoteAdress2 = context.newObject(QuoteAdress.class);
         quoteAdress2.setCity("city2");
-        
-        Quote_Person quote_Person2 = (Quote_Person) context.newObject("Quote_Person");
+
+        Quote_Person quote_Person2 = context.newObject(Quote_Person.class);
         quote_Person2.setSalary(100);
         quote_Person2.setName("Name");
         quote_Person2.setDAte(new Date());
-        
+
         context.commitChanges();
-        
-        DbEntity entity = getDomain().getEntityResolver().lookupObjEntity(
-                QuoteAdress.class).getDbEntity();
-        List idAttributes = Collections.singletonList(entity
-                    .getAttribute("City"));
-        List updatedAttributes = Collections.singletonList(entity
-                    .getAttribute("City"));
+
+        DbEntity entity = context
+                .getEntityResolver()
+                .lookupObjEntity(QuoteAdress.class)
+                .getDbEntity();
+        List idAttributes = Collections.singletonList(entity.getAttribute("City"));
+        List updatedAttributes = Collections.singletonList(entity.getAttribute("City"));
 
         UpdateBatchQuery updateQuery = new UpdateBatchQuery(
-                    entity,
-                    idAttributes,
-                    updatedAttributes,
-                    null,
-                    1);
-        
+                entity,
+                idAttributes,
+                updatedAttributes,
+                null,
+                1);
+
         List objects3 = context.performQuery(updateQuery);
         assertEquals(0, objects3.size());
-  
+
         SelectQuery qQuote_Person2 = new SelectQuery(Quote_Person.class);
-        List objects4 = context.performQuery(qQuote_Person);
+        List objects4 = context.performQuery(qQuote_Person2);
         assertEquals(2, objects4.size());
- 
-        
     }
 
 }

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/SingleTableInheritance1Test.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/SingleTableInheritance1Test.java?rev=954454&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/SingleTableInheritance1Test.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/SingleTableInheritance1Test.java Mon Jun 14 13:35:32 2010
@@ -0,0 +1,103 @@
+/*****************************************************************
+ *   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.access;
+
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.exp.Expression;
+import org.apache.cayenne.exp.ExpressionFactory;
+import org.apache.cayenne.query.SelectQuery;
+import org.apache.cayenne.test.jdbc.DBHelper;
+import org.apache.cayenne.testdo.inheritance_flat.Group;
+import org.apache.cayenne.testdo.inheritance_flat.Role;
+import org.apache.cayenne.testdo.inheritance_flat.User;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+/**
+ * Special test cases per CAY-1378, CAY-1379.
+ */
+@UseServerRuntime(ServerCase.INHERTITANCE_SINGLE_TABLE1_STACK)
+public class SingleTableInheritance1Test extends ServerCase {
+
+    @Inject
+    protected ObjectContext context;
+
+    @Inject
+    protected DBHelper dbHelper;
+
+    @Override
+    protected void setUpAfterInjection() throws Exception {
+        super.setUpAfterInjection();
+
+        dbHelper.deleteAll("GROUP_MEMBERS");
+        dbHelper.deleteAll("USER_PROPERTIES");
+        dbHelper.deleteAll("GROUP_PROPERTIES");
+        dbHelper.deleteAll("ROLES");
+    }
+
+    public void testGroupActions() throws Exception {
+
+        User user = context.newObject(User.class);
+        user.setName("test_user");
+
+        Group group1 = context.newObject(Group.class);
+        group1.setName("test_group1");
+
+        Group group2 = context.newObject(Group.class);
+        group2.setName("test_group2");
+
+        group1.addToGroupMembers(user);
+        group2.addToGroupMembers(group1);
+
+        group2.getObjectContext().commitChanges();
+
+        // Per CAY-1379 removing user and then refetching resulted in a FFE downstream
+        group1.removeFromGroupMembers(user);
+        Expression exp = ExpressionFactory.matchExp(Role.ROLE_GROUPS_PROPERTY, group2);
+        SelectQuery query = new SelectQuery(Group.class, exp);
+        context.performQuery(query);
+        context.commitChanges();
+
+        context.deleteObject(group1);
+        context.deleteObject(group2);
+        context.deleteObject(user);
+        context.commitChanges();
+    }
+
+    public void testFlattenedNullifyNullifyDeleteRules() throws Exception {
+
+        User user = context.newObject(User.class);
+        user.setName("test_user");
+        Group group = context.newObject(Group.class);
+        group.setName("test_group");
+        group.addToGroupMembers(user);
+        context.commitChanges();
+
+        context.deleteObject(user);
+        assertTrue(group.getGroupMembers().isEmpty());
+
+        context.commitChanges();
+
+        // here Cayenne would throw per CAY-1378 on an attempt to delete a previously
+        // related transient object
+        context.deleteObject(group);
+        context.commitChanges();
+    }
+}

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/VerticalInheritanceTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/VerticalInheritanceTest.java?rev=954454&r1=954453&r2=954454&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/VerticalInheritanceTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/VerticalInheritanceTest.java Mon Jun 14 13:35:32 2010
@@ -23,6 +23,7 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.query.SelectQuery;
 import org.apache.cayenne.test.jdbc.DBHelper;
 import org.apache.cayenne.test.jdbc.TableHelper;
@@ -32,40 +33,38 @@ import org.apache.cayenne.testdo.inherit
 import org.apache.cayenne.testdo.inheritance.vertical.IvSub1;
 import org.apache.cayenne.testdo.inheritance.vertical.IvSub1Sub1;
 import org.apache.cayenne.testdo.inheritance.vertical.IvSub2;
-import org.apache.cayenne.unit.AccessStack;
-import org.apache.cayenne.unit.CayenneCase;
-import org.apache.cayenne.unit.CayenneResources;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
 
-public class VerticalInheritanceTest extends CayenneCase {
+@UseServerRuntime(ServerCase.INHERTITANCE_VERTICAL_STACK)
+public class VerticalInheritanceTest extends ServerCase {
+
+    @Inject
+    protected ObjectContext context;
+
+    @Inject
+    protected DBHelper dbHelper;
 
     @Override
-    protected void setUp() throws Exception {
-        super.setUp();
+    protected void setUpAfterInjection() throws Exception {
 
-        DBHelper dbHelper = getDbHelper();
         dbHelper.deleteAll("IV_SUB1_SUB1");
         dbHelper.deleteAll("IV_SUB1");
         dbHelper.deleteAll("IV_SUB2");
         dbHelper.deleteAll("IV_ROOT");
-        
+
         dbHelper.deleteAll("IV1_SUB1");
         dbHelper.deleteAll("IV1_ROOT");
     }
 
-    @Override
-    protected AccessStack buildAccessStack() {
-        return CayenneResources.getResources().getAccessStack("InheritanceVerticalStack");
-    }
-
     public void testInsert_Root() throws Exception {
-        DBHelper dbHelper = getDbHelper();
 
         TableHelper ivRootTable = new TableHelper(dbHelper, "IV_ROOT");
         ivRootTable.setColumns("ID", "NAME", "DISCRIMINATOR");
 
         assertEquals(0, ivRootTable.getRowCount());
 
-        IvRoot root = createDataContext().newObject(IvRoot.class);
+        IvRoot root = context.newObject(IvRoot.class);
         root.setName("XyZ");
         root.getObjectContext().commitChanges();
 
@@ -80,7 +79,6 @@ public class VerticalInheritanceTest ext
     }
 
     public void testInsert_Sub1() throws Exception {
-        DBHelper dbHelper = getDbHelper();
 
         TableHelper ivRootTable = new TableHelper(dbHelper, "IV_ROOT");
         ivRootTable.setColumns("ID", "NAME", "DISCRIMINATOR");
@@ -88,7 +86,7 @@ public class VerticalInheritanceTest ext
         TableHelper ivSub1Table = new TableHelper(dbHelper, "IV_SUB1");
         ivSub1Table.setColumns("ID", "SUB1_NAME");
 
-        IvSub1 sub1 = createDataContext().newObject(IvSub1.class);
+        IvSub1 sub1 = context.newObject(IvSub1.class);
         sub1.setName("XyZX");
         sub1.getObjectContext().commitChanges();
 
@@ -110,7 +108,7 @@ public class VerticalInheritanceTest ext
         ivSub1Table.deleteAll();
         ivRootTable.deleteAll();
 
-        IvSub1 sub11 = createDataContext().newObject(IvSub1.class);
+        IvSub1 sub11 = context.newObject(IvSub1.class);
         sub11.setName("XyZXY");
         sub11.setSub1Name("BdE2");
         sub11.getObjectContext().commitChanges();
@@ -129,7 +127,6 @@ public class VerticalInheritanceTest ext
     }
 
     public void testInsert_Sub1Sub1() throws Exception {
-        DBHelper dbHelper = getDbHelper();
 
         TableHelper ivRootTable = new TableHelper(dbHelper, "IV_ROOT");
         ivRootTable.setColumns("ID", "NAME", "DISCRIMINATOR");
@@ -140,7 +137,7 @@ public class VerticalInheritanceTest ext
         TableHelper ivSub1Sub1Table = new TableHelper(dbHelper, "IV_SUB1_SUB1");
         ivSub1Sub1Table.setColumns("ID", "SUB1_SUB1_NAME");
 
-        IvSub1Sub1 sub1Sub1 = createDataContext().newObject(IvSub1Sub1.class);
+        IvSub1Sub1 sub1Sub1 = context.newObject(IvSub1Sub1.class);
         sub1Sub1.setName("XyZN");
         sub1Sub1.setSub1Name("mDA");
         sub1Sub1.setSub1Sub1Name("3DQa");
@@ -169,7 +166,6 @@ public class VerticalInheritanceTest ext
     }
 
     public void testSelectQuery_SuperSub() throws Exception {
-        DBHelper dbHelper = getDbHelper();
 
         TableHelper ivRootTable = new TableHelper(dbHelper, "IV_ROOT");
         ivRootTable.setColumns("ID", "NAME", "DISCRIMINATOR");
@@ -183,7 +179,7 @@ public class VerticalInheritanceTest ext
         ivSub1Table.insert(2, "xSUB1");
 
         SelectQuery query = new SelectQuery(IvRoot.class);
-        List<IvRoot> results = createDataContext().performQuery(query);
+        List<IvRoot> results = context.performQuery(query);
 
         assertEquals(2, results.size());
 
@@ -209,7 +205,6 @@ public class VerticalInheritanceTest ext
     }
 
     public void testSelectQuery_DeepAndWide() throws Exception {
-        DBHelper dbHelper = getDbHelper();
 
         TableHelper ivRootTable = new TableHelper(dbHelper, "IV_ROOT");
         ivRootTable.setColumns("ID", "NAME", "DISCRIMINATOR");
@@ -237,7 +232,7 @@ public class VerticalInheritanceTest ext
         ivSub2Table.insert(4, "xSUB2");
 
         SelectQuery query = new SelectQuery(IvRoot.class);
-        List<IvRoot> results = createDataContext().performQuery(query);
+        List<IvRoot> results = context.performQuery(query);
 
         assertEquals(4, results.size());
 
@@ -276,7 +271,6 @@ public class VerticalInheritanceTest ext
     }
 
     public void testSelectQuery_MiddleLeaf() throws Exception {
-        DBHelper dbHelper = getDbHelper();
 
         TableHelper ivRootTable = new TableHelper(dbHelper, "IV_ROOT");
         ivRootTable.setColumns("ID", "NAME", "DISCRIMINATOR");
@@ -304,7 +298,7 @@ public class VerticalInheritanceTest ext
         ivSub2Table.insert(4, "xSUB2");
 
         SelectQuery query = new SelectQuery(IvSub1.class);
-        List<IvRoot> results = createDataContext().performQuery(query);
+        List<IvRoot> results = context.performQuery(query);
 
         assertEquals(2, results.size());
 
@@ -332,7 +326,6 @@ public class VerticalInheritanceTest ext
     }
 
     public void testDelete_Mix() throws Exception {
-        DBHelper dbHelper = getDbHelper();
 
         TableHelper ivRootTable = new TableHelper(dbHelper, "IV_ROOT");
         ivRootTable.setColumns("ID", "NAME", "DISCRIMINATOR");
@@ -361,7 +354,6 @@ public class VerticalInheritanceTest ext
 
         SelectQuery query = new SelectQuery(IvRoot.class);
 
-        ObjectContext context = createDataContext();
         List<IvRoot> results = context.performQuery(query);
 
         assertEquals(4, results.size());
@@ -391,7 +383,6 @@ public class VerticalInheritanceTest ext
     }
 
     public void testSelectQuery_AttributeOverrides() throws Exception {
-        DBHelper dbHelper = getDbHelper();
 
         TableHelper iv1RootTable = new TableHelper(dbHelper, "IV1_ROOT");
         iv1RootTable.setColumns("ID", "NAME", "DISCRIMINATOR");
@@ -405,7 +396,7 @@ public class VerticalInheritanceTest ext
         iv1Sub1Table.insert(2, "xSUB1");
 
         SelectQuery query = new SelectQuery(Iv1Root.class);
-        List<Iv1Root> results = createDataContext().performQuery(query);
+        List<Iv1Root> results = context.performQuery(query);
 
         assertEquals(2, results.size());
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/CayenneCase.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/CayenneCase.java?rev=954454&r1=954453&r2=954454&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/CayenneCase.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/CayenneCase.java Mon Jun 14 13:35:32 2010
@@ -44,7 +44,6 @@ public abstract class CayenneCase extend
     public static final String TEST_ACCESS_STACK = "TestStack";
     public static final String MULTI_TIER_ACCESS_STACK = "MultiTierStack";
     public static final String QUALIFIED_ACCESS_STACK = "QualifiedStack";
-    public static final String QUOTEMAP_ACCESS_STACK = "QuoteMapStack";
 
     protected AccessStack accessStack;
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/CayenneResources.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/CayenneResources.java?rev=954454&r1=954453&r2=954454&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/CayenneResources.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/CayenneResources.java Mon Jun 14 13:35:32 2010
@@ -241,13 +241,13 @@ public class CayenneResources implements
     /**
      * Returns DB-specific testing adapter.
      */
-    public AccessStackAdapter getAccessStackAdapter(Class adapterClass) {
+    public AccessStackAdapter getAccessStackAdapter(String adapterClassName) {
         AccessStackAdapter stackAdapter = (AccessStackAdapter) adapterMap
-                .get(adapterClass.getName());
+                .get(adapterClassName);
 
         if (stackAdapter == null) {
             throw new RuntimeException("No AccessStackAdapter for DbAdapter class: "
-                    + adapterClass);
+                    + adapterClassName);
         }
 
         // post init
@@ -274,8 +274,8 @@ public class CayenneResources implements
      * Creates new DataNode.
      */
     public DataNode newDataNode(String name) throws Exception {
-        AccessStackAdapter adapter = getAccessStackAdapter(Class.forName(connectionInfo
-                .getAdapterClassName()));
+        AccessStackAdapter adapter = getAccessStackAdapter(connectionInfo
+                .getAdapterClassName());
 
         DataNode node = new DataNode(name);
         node.setDataSource(dataSource);

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/SimpleAccessStack.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/SimpleAccessStack.java?rev=954454&r1=954453&r2=954454&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/SimpleAccessStack.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/SimpleAccessStack.java Mon Jun 14 13:35:32 2010
@@ -83,7 +83,7 @@ public class SimpleAccessStack implement
     }
 
     public AccessStackAdapter getAdapter(DataNode node) {
-        return resources.getAccessStackAdapter(node.getAdapter().getClass());
+        return resources.getAccessStackAdapter(node.getAdapter().getClass().getName());
     }
 
     protected DataDomain getDomain() {

Copied: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/DICase.java (from r954444, cayenne/main/trunk/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/jdbc/ResultSetTemplate.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/DICase.java?p2=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/DICase.java&p1=cayenne/main/trunk/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/jdbc/ResultSetTemplate.java&r1=954444&r2=954454&rev=954454&view=diff
==============================================================================
--- cayenne/main/trunk/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/jdbc/ResultSetTemplate.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/DICase.java Mon Jun 14 13:35:32 2010
@@ -16,45 +16,43 @@
  *  specific language governing permissions and limitations
  *  under the License.
  ****************************************************************/
-package org.apache.cayenne.test.jdbc;
+package org.apache.cayenne.unit.di;
 
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
+import junit.framework.TestCase;
 
-abstract class ResultSetTemplate<T> {
+import org.apache.cayenne.di.Injector;
 
-    DBHelper parent;
+/**
+ * A unit test superclass that supports injection of members based on the standard unit
+ * test container.
+ */
+public abstract class DICase extends TestCase {
 
-    public ResultSetTemplate(DBHelper parent) {
-        this.parent = parent;
+    protected abstract Injector getUnitTestInjector();
+
+    @Override
+    protected final void setUp() throws Exception {
+        getUnitTestInjector().getInstance(UnitTestLifecycleManager.class).setUp(this);
+        setUpAfterInjection();
     }
 
-    abstract T readResultSet(ResultSet rs, String sql) throws SQLException;
+    @Override
+    protected final void tearDown() throws Exception {
 
-    T execute(String sql) throws SQLException {
-        Connection c = parent.getConnection();
         try {
-
-            PreparedStatement st = c.prepareStatement(sql);
-
-            try {
-                ResultSet rs = st.executeQuery();
-                try {
-
-                    return readResultSet(rs, sql);
-                }
-                finally {
-                    rs.close();
-                }
-            }
-            finally {
-                st.close();
-            }
+            tearDownBeforeInjection();
         }
         finally {
-            c.close();
+            getUnitTestInjector().getInstance(UnitTestLifecycleManager.class).tearDown(
+                    this);
         }
     }
+
+    protected void setUpAfterInjection() throws Exception {
+        // noop
+    }
+
+    protected void tearDownBeforeInjection() throws Exception {
+        // noop
+    }
 }

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/DICaseSelfTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/DICaseSelfTest.java?rev=954454&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/DICaseSelfTest.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/DICaseSelfTest.java Mon Jun 14 13:35:32 2010
@@ -0,0 +1,80 @@
+/*****************************************************************
+ *   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.di.Binder;
+import org.apache.cayenne.di.DIBootstrap;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.di.Injector;
+import org.apache.cayenne.di.Key;
+import org.apache.cayenne.di.Module;
+
+public class DICaseSelfTest extends DICase {
+
+    private static final Injector injector;
+
+    static {
+        Module selfTestModule = new Module() {
+
+            public void configure(Binder binder) {
+                UnitTestScope testScope = new UnitTestScope();
+
+                binder.bind(UnitTestLifecycleManager.class).toInstance(
+                        new DefaultUnitTestLifecycleManager(testScope));
+
+                binder.bind(Key.get(Object.class, "test-scope")).to(Object.class).in(
+                        testScope);
+                binder
+                        .bind(Key.get(Object.class, "singleton-scope"))
+                        .to(Object.class)
+                        .inSingletonScope();
+            }
+        };
+
+        injector = DIBootstrap.createInjector(selfTestModule);
+    }
+
+    @Inject("test-scope")
+    protected Object testScoped;
+
+    @Inject("singleton-scope")
+    protected Object singletonScoped;
+
+    @Override
+    protected Injector getUnitTestInjector() {
+        return injector;
+    }
+
+    public void testInjection() throws Exception {
+
+        Object testScoped = this.testScoped;
+        assertNotNull(testScoped);
+
+        Object singletonScoped = this.singletonScoped;
+        assertNotNull(singletonScoped);
+
+        tearDown();
+        setUp();
+
+        assertNotSame(testScoped, this.testScoped);
+        assertNotNull(this.testScoped);
+        assertSame(singletonScoped, this.singletonScoped);
+    }
+
+}

Copied: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/DefaultUnitTestLifecycleManager.java (from r954444, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/InheritanceCase.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/DefaultUnitTestLifecycleManager.java?p2=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/DefaultUnitTestLifecycleManager.java&p1=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/InheritanceCase.java&r1=954444&r2=954454&rev=954454&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/InheritanceCase.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/DefaultUnitTestLifecycleManager.java Mon Jun 14 13:35:32 2010
@@ -16,17 +16,31 @@
  *  specific language governing permissions and limitations
  *  under the License.
  ****************************************************************/
-package org.apache.cayenne.unit;
+package org.apache.cayenne.unit.di;
 
-/**
- * A superclass of test cases using "inheritance" DataMap for its access stack.
- * 
- */
-public abstract class InheritanceCase extends CayenneCase {
-    public static final String INHERITANCE_ACCESS_STACK = "InheritanceStack";
-
-    @Override
-    protected AccessStack buildAccessStack() {
-        return CayenneResources.getResources().getAccessStack(INHERITANCE_ACCESS_STACK);
+import junit.framework.TestCase;
+
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.di.Injector;
+import org.apache.cayenne.di.OnScopeEnd;
+
+public class DefaultUnitTestLifecycleManager implements UnitTestLifecycleManager {
+
+    @Inject
+    protected Injector injector;
+
+    protected UnitTestScope scope;
+
+    public DefaultUnitTestLifecycleManager(UnitTestScope scope) {
+        this.scope = scope;
+    }
+
+    public <T extends TestCase> void setUp(T testCase) {
+        injector.injectMembers(testCase);
+    }
+
+    @OnScopeEnd
+    public <T extends TestCase> void tearDown(T testCase) {
+        scope.postScopeEvent(OnScopeEnd.class);
     }
 }

Copied: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/UnitTestLifecycleManager.java (from r954444, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/InheritanceCase.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/UnitTestLifecycleManager.java?p2=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/UnitTestLifecycleManager.java&p1=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/InheritanceCase.java&r1=954444&r2=954454&rev=954454&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/InheritanceCase.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/UnitTestLifecycleManager.java Mon Jun 14 13:35:32 2010
@@ -16,17 +16,13 @@
  *  specific language governing permissions and limitations
  *  under the License.
  ****************************************************************/
-package org.apache.cayenne.unit;
+package org.apache.cayenne.unit.di;
 
-/**
- * A superclass of test cases using "inheritance" DataMap for its access stack.
- * 
- */
-public abstract class InheritanceCase extends CayenneCase {
-    public static final String INHERITANCE_ACCESS_STACK = "InheritanceStack";
+import junit.framework.TestCase;
 
-    @Override
-    protected AccessStack buildAccessStack() {
-        return CayenneResources.getResources().getAccessStack(INHERITANCE_ACCESS_STACK);
-    }
+public interface UnitTestLifecycleManager {
+
+    <T extends TestCase> void setUp(T testCase);
+
+    <T extends TestCase> void tearDown(T testCase);
 }

Copied: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/UnitTestScope.java (from r954444, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/InheritanceCase.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/UnitTestScope.java?p2=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/UnitTestScope.java&p1=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/InheritanceCase.java&r1=954444&r2=954454&rev=954454&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/InheritanceCase.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/UnitTestScope.java Mon Jun 14 13:35:32 2010
@@ -16,17 +16,21 @@
  *  specific language governing permissions and limitations
  *  under the License.
  ****************************************************************/
-package org.apache.cayenne.unit;
+package org.apache.cayenne.unit.di;
 
-/**
- * A superclass of test cases using "inheritance" DataMap for its access stack.
- * 
- */
-public abstract class InheritanceCase extends CayenneCase {
-    public static final String INHERITANCE_ACCESS_STACK = "InheritanceStack";
+import org.apache.cayenne.di.OnScopeEnd;
+import org.apache.cayenne.di.Provider;
+import org.apache.cayenne.di.spi.EventfulScope;
+
+public class UnitTestScope extends EventfulScope {
+
+    public UnitTestScope() {
+        addEventAnnotation(OnScopeEnd.class);
+    }
 
     @Override
-    protected AccessStack buildAccessStack() {
-        return CayenneResources.getResources().getAccessStack(INHERITANCE_ACCESS_STACK);
+    public <T> Provider<T> scope(Provider<T> unscoped) {
+        return new UnitTestScopedProvider<T>(this, unscoped);
     }
+
 }

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/UnitTestScopedProvider.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/UnitTestScopedProvider.java?rev=954454&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/UnitTestScopedProvider.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/UnitTestScopedProvider.java Mon Jun 14 13:35:32 2010
@@ -0,0 +1,77 @@
+/*****************************************************************
+ *   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 java.lang.reflect.Method;
+
+import org.apache.cayenne.ConfigurationException;
+import org.apache.cayenne.di.OnScopeEnd;
+import org.apache.cayenne.di.Provider;
+
+class UnitTestScopedProvider<T> implements Provider<T> {
+
+    private Provider<T> delegate;
+    private UnitTestScope scope;
+
+    // presumably "volatile" works in Java 5 and newer to prevent double-checked locking
+    private volatile T instance;
+
+    public UnitTestScopedProvider(UnitTestScope scope, Provider<T> delegate) {
+        this.scope = scope;
+        this.delegate = delegate;
+        scope.addScopeEventListener(this);
+    }
+
+    public T get() throws ConfigurationException {
+
+        if (instance == null) {
+            synchronized (this) {
+                if (instance == null) {
+                    instance = delegate.get();
+
+                    if (instance == null) {
+                        throw new ConfigurationException(
+                                "Underlying provider (%s) returned NULL instance",
+                                delegate.getClass().getName());
+                    }
+
+                    scope.addScopeEventListener(instance);
+                }
+            }
+        }
+
+        return instance;
+    }
+
+    @OnScopeEnd
+    public void onTearDown() throws Exception {
+
+        if (instance != null) {
+
+            for (Method method : instance.getClass().getMethods()) {
+
+                if (method.isAnnotationPresent(OnScopeEnd.class)) {
+                    method.invoke(instance, new Object[0]);
+                }
+            }
+
+            instance = null;
+        }
+    }
+}

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/CachingServerRuntimeFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/CachingServerRuntimeFactory.java?rev=954454&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/CachingServerRuntimeFactory.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/CachingServerRuntimeFactory.java Mon Jun 14 13:35:32 2010
@@ -0,0 +1,80 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.unit.di.server;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.sql.DataSource;
+
+import org.apache.cayenne.access.DataDomain;
+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.unit.CayenneResources;
+import org.apache.cayenne.unit.di.UnitTestScope;
+
+public class CachingServerRuntimeFactory implements ServerRuntimeFactory {
+
+    protected CayenneResources resources;
+    protected UnitTestScope testScope;
+    protected Map<String, ServerRuntime> cache;
+
+    public CachingServerRuntimeFactory(CayenneResources resources, UnitTestScope testScope) {
+        this.resources = resources;
+        this.testScope = testScope;
+        this.cache = new HashMap<String, ServerRuntime>();
+    }
+
+    public ServerRuntime get(String configurationLocation) {
+        
+        if (configurationLocation == null) {
+            throw new NullPointerException("Null 'configurationLocation'");
+        }
+        
+        ServerRuntime runtime = cache.get(configurationLocation);
+
+        if (runtime == null) {
+            runtime = create(configurationLocation);
+            cache.put(configurationLocation, runtime);
+        }
+
+        return runtime;
+    }
+
+    protected ServerRuntime create(String configurationLocation) {
+        return new ServerRuntime(configurationLocation, new ServerExtraModule());
+    }
+
+    class ServerExtraModule implements Module {
+
+        public void configure(Binder binder) {
+
+            // these are the objects overriding standard ServerModule definitions or
+            // dependencies needed by such overrides
+
+            binder.bind(DbAdapter.class).toProviderInstance(
+                    new CayenneResourcesDbAdapterProvider(resources));
+            binder.bind(DataDomain.class).toProvider(ServerCaseDataDomainProvider.class);
+            binder.bind(DataSource.class).toProviderInstance(
+                    new CayenneResourcesDataSourceProvider(resources));
+        }
+    }
+}

Copied: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/CayenneResourcesDataSourceProvider.java (from r954444, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/InheritanceCase.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/CayenneResourcesDataSourceProvider.java?p2=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/CayenneResourcesDataSourceProvider.java&p1=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/InheritanceCase.java&r1=954444&r2=954454&rev=954454&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/InheritanceCase.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/CayenneResourcesDataSourceProvider.java Mon Jun 14 13:35:32 2010
@@ -16,17 +16,24 @@
  *  specific language governing permissions and limitations
  *  under the License.
  ****************************************************************/
-package org.apache.cayenne.unit;
+package org.apache.cayenne.unit.di.server;
 
-/**
- * A superclass of test cases using "inheritance" DataMap for its access stack.
- * 
- */
-public abstract class InheritanceCase extends CayenneCase {
-    public static final String INHERITANCE_ACCESS_STACK = "InheritanceStack";
-
-    @Override
-    protected AccessStack buildAccessStack() {
-        return CayenneResources.getResources().getAccessStack(INHERITANCE_ACCESS_STACK);
+import javax.sql.DataSource;
+
+import org.apache.cayenne.ConfigurationException;
+import org.apache.cayenne.di.Provider;
+import org.apache.cayenne.unit.CayenneResources;
+
+public class CayenneResourcesDataSourceProvider implements Provider<DataSource> {
+
+    protected CayenneResources resources;
+
+    public CayenneResourcesDataSourceProvider(CayenneResources resources) {
+        this.resources = resources;
     }
+
+    public DataSource get() throws ConfigurationException {
+        return resources.getDataSource();
+    }
+
 }

Copied: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/CayenneResourcesDbAdapterProvider.java (from r954444, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/InheritanceCase.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/CayenneResourcesDbAdapterProvider.java?p2=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/CayenneResourcesDbAdapterProvider.java&p1=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/InheritanceCase.java&r1=954444&r2=954454&rev=954454&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/InheritanceCase.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/CayenneResourcesDbAdapterProvider.java Mon Jun 14 13:35:32 2010
@@ -16,17 +16,29 @@
  *  specific language governing permissions and limitations
  *  under the License.
  ****************************************************************/
-package org.apache.cayenne.unit;
+package org.apache.cayenne.unit.di.server;
 
-/**
- * A superclass of test cases using "inheritance" DataMap for its access stack.
- * 
- */
-public abstract class InheritanceCase extends CayenneCase {
-    public static final String INHERITANCE_ACCESS_STACK = "InheritanceStack";
-
-    @Override
-    protected AccessStack buildAccessStack() {
-        return CayenneResources.getResources().getAccessStack(INHERITANCE_ACCESS_STACK);
+import org.apache.cayenne.ConfigurationException;
+import org.apache.cayenne.conn.DataSourceInfo;
+import org.apache.cayenne.dba.DbAdapter;
+import org.apache.cayenne.di.Provider;
+import org.apache.cayenne.unit.AccessStackAdapter;
+import org.apache.cayenne.unit.CayenneResources;
+
+public class CayenneResourcesDbAdapterProvider implements Provider<DbAdapter> {
+
+    protected CayenneResources resources;
+
+    public CayenneResourcesDbAdapterProvider(CayenneResources resources) {
+        this.resources = resources;
+    }
+
+    public DbAdapter get() throws ConfigurationException {
+
+        DataSourceInfo connectionInfo = resources.getConnectionInfo();
+        AccessStackAdapter adapter = resources.getAccessStackAdapter(connectionInfo
+                .getAdapterClassName());
+
+        return adapter.getAdapter();
     }
 }

Copied: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/FlavoredDBHelper.java (from r954444, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/InheritanceCase.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/FlavoredDBHelper.java?p2=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/FlavoredDBHelper.java&p1=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/InheritanceCase.java&r1=954444&r2=954454&rev=954454&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/InheritanceCase.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/FlavoredDBHelper.java Mon Jun 14 13:35:32 2010
@@ -16,17 +16,28 @@
  *  specific language governing permissions and limitations
  *  under the License.
  ****************************************************************/
-package org.apache.cayenne.unit;
+package org.apache.cayenne.unit.di.server;
+
+import javax.sql.DataSource;
+
+import org.apache.cayenne.dba.QuotingStrategy;
+import org.apache.cayenne.test.jdbc.DBHelper;
 
 /**
- * A superclass of test cases using "inheritance" DataMap for its access stack.
- * 
+ * A DbHelper that understands various supported DB flavors.
  */
-public abstract class InheritanceCase extends CayenneCase {
-    public static final String INHERITANCE_ACCESS_STACK = "InheritanceStack";
+public class FlavoredDBHelper extends DBHelper {
+
+    protected QuotingStrategy quotingStrategy;
+
+    public FlavoredDBHelper(DataSource dataSource, QuotingStrategy quotingStrategy) {
+        super(dataSource);
+        this.quotingStrategy = quotingStrategy;
+    }
 
     @Override
-    protected AccessStack buildAccessStack() {
-        return CayenneResources.getResources().getAccessStack(INHERITANCE_ACCESS_STACK);
+    protected String quote(String sqlIdentifier) {
+        return quotingStrategy.quoteString(sqlIdentifier);
     }
+
 }

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/FlavoredDBHelperProvider.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/FlavoredDBHelperProvider.java?rev=954454&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/FlavoredDBHelperProvider.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/FlavoredDBHelperProvider.java Mon Jun 14 13:35:32 2010
@@ -0,0 +1,54 @@
+/*****************************************************************
+ *   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.ConfigurationException;
+import org.apache.cayenne.DataChannel;
+import org.apache.cayenne.dba.DbAdapter;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.di.Provider;
+import org.apache.cayenne.map.DataMap;
+import org.apache.cayenne.test.jdbc.DBHelper;
+
+public class FlavoredDBHelperProvider implements Provider<DBHelper> {
+
+    @Inject
+    protected DataSource dataSource;
+
+    @Inject
+    protected ServerRuntimeFactory runtimeFactory;
+
+    @Inject
+    protected DbAdapter adapter;
+
+    @Inject
+    protected ServerCaseProperties properties;
+
+    public DBHelper get() throws ConfigurationException {
+        
+        DataChannel channel = runtimeFactory
+                .get(properties.getConfigurationLocation())
+                .getChannel();
+        DataMap firstMap = channel.getEntityResolver().getDataMaps().iterator().next();
+        return new FlavoredDBHelper(dataSource, adapter.getQuotingStrategy(firstMap
+                .isQuotingSQLIdentifiers()));
+    }
+}

Added: 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=954454&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCase.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCase.java Mon Jun 14 13:35:32 2010
@@ -0,0 +1,94 @@
+/*****************************************************************
+ *   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.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.test.jdbc.DBHelper;
+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.di.UnitTestScope;
+
+public class ServerCase extends DICase {
+
+    // known runtimes... unit tests may reuse these with @UseServerRuntime annotation or
+    // can define their own on the fly (TODO: how would that work with the global schema
+    // setup?)
+    public static final String INHERTITANCE_SINGLE_TABLE1_STACK = "cayenne-inheritance-single-table1.xml";
+    public static final String INHERTITANCE_VERTICAL_STACK = "cayenne-inheritance-vertical.xml";
+    public static final String QUOTED_IDENTIFIERS_STACK = "cayenne-quoted-identifiers.xml";
+
+    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) {
+                UnitTestScope testScope = new UnitTestScope();
+
+                // these are the objects injectable in unit tests that subclass from
+                // ServerCase. Server runtime extensions are configured in
+                // CachingServerRuntimeFactory. There is some overlap between the two
+                // registries (some services declared in both), as cayenne-di does not
+                // support registry inheritance.
+
+                // singleton objects
+                binder.bind(UnitTestLifecycleManager.class).toInstance(
+                        new ServerCaseLifecycleManager(testScope));
+                binder.bind(ServerRuntimeFactory.class).toInstance(
+                        new CachingServerRuntimeFactory(resources, testScope));
+                binder.bind(DataSource.class).toProviderInstance(
+                        new CayenneResourcesDataSourceProvider(resources));
+                binder.bind(DbAdapter.class).toProviderInstance(
+                        new CayenneResourcesDbAdapterProvider(resources));
+
+                // test-scoped objects
+                binder
+                        .bind(ServerCaseProperties.class)
+                        .to(ServerCaseProperties.class)
+                        .in(testScope);
+                binder.bind(ObjectContext.class).toProvider(
+                        ServerCaseDataContextProvider.class).in(testScope);
+
+                binder
+                        .bind(DBHelper.class)
+                        .toProvider(FlavoredDBHelperProvider.class)
+                        .in(testScope);
+            }
+        };
+
+        injector = DIBootstrap.createInjector(module);
+    }
+
+    @Override
+    protected Injector getUnitTestInjector() {
+        return injector;
+    }
+}

Copied: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataContextProvider.java (from r954444, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/InheritanceCase.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataContextProvider.java?p2=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataContextProvider.java&p1=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/InheritanceCase.java&r1=954444&r2=954454&rev=954454&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/InheritanceCase.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataContextProvider.java Mon Jun 14 13:35:32 2010
@@ -16,17 +16,22 @@
  *  specific language governing permissions and limitations
  *  under the License.
  ****************************************************************/
-package org.apache.cayenne.unit;
+package org.apache.cayenne.unit.di.server;
 
-/**
- * A superclass of test cases using "inheritance" DataMap for its access stack.
- * 
- */
-public abstract class InheritanceCase extends CayenneCase {
-    public static final String INHERITANCE_ACCESS_STACK = "InheritanceStack";
+import org.apache.cayenne.ConfigurationException;
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.di.Provider;
 
-    @Override
-    protected AccessStack buildAccessStack() {
-        return CayenneResources.getResources().getAccessStack(INHERITANCE_ACCESS_STACK);
+public class ServerCaseDataContextProvider implements Provider<ObjectContext> {
+
+    @Inject
+    protected ServerRuntimeFactory runtimeFactory;
+
+    @Inject
+    protected ServerCaseProperties properties;
+
+    public ObjectContext get() throws ConfigurationException {
+        return runtimeFactory.get(properties.getConfigurationLocation()).getContext();
     }
 }

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataDomainProvider.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataDomainProvider.java?rev=954454&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataDomainProvider.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseDataDomainProvider.java Mon Jun 14 13:35:32 2010
@@ -0,0 +1,81 @@
+/*****************************************************************
+ *   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.access.DataDomain;
+import org.apache.cayenne.access.DataNode;
+import org.apache.cayenne.access.dbsync.SkipSchemaUpdateStrategy;
+import org.apache.cayenne.configuration.server.DataDomainProvider;
+import org.apache.cayenne.dba.DbAdapter;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.map.DataMap;
+
+class ServerCaseDataDomainProvider extends DataDomainProvider {
+
+    @Inject
+    protected DataSource dataSource;
+
+    @Inject
+    protected DbAdapter adapter;
+
+    @Override
+    protected DataDomain createDataDomain() throws Exception {
+        DataDomain domain = super.createDataDomain();
+
+        // add nodes dynamically
+        // TODO: andrus, 06/14/2010 should probably map them in XML to avoid this mess...
+        for (DataMap dataMap : domain.getDataMaps()) {
+
+            DataNode node = new DataNode(dataMap.getName());
+            node.setDataSource(dataSource);
+            node.setAdapter(adapter);
+            node.addDataMap(dataMap);
+            node.setSchemaUpdateStrategy(new SkipSchemaUpdateStrategy());
+
+            // customizations from SimpleAccessStackAdapter that are not yet ported...
+            // those can be done better now
+
+            // node
+            // .getAdapter()
+            // .getExtendedTypes()
+            // .registerType(new StringET1ExtendedType());
+            //
+            // // tweak mapping with a delegate
+            // for (Procedure proc : map.getProcedures()) {
+            // getAdapter(node).tweakProcedure(proc);
+            // }
+
+            // use shared data source in all cases but the multi-node...
+            // if (MultiNodeCase.NODE1.equals(node.getName())
+            // || MultiNodeCase.NODE2.equals(node.getName())) {
+            // node.setDataSource(resources.createDataSource());
+            // }
+            // else {
+            // node.setDataSource(resources.getDataSource());
+            // }
+
+            domain.addNode(node);
+        }
+
+        return domain;
+    }
+
+}

Copied: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseLifecycleManager.java (from r954444, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/InheritanceCase.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseLifecycleManager.java?p2=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseLifecycleManager.java&p1=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/InheritanceCase.java&r1=954444&r2=954454&rev=954454&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/InheritanceCase.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCaseLifecycleManager.java Mon Jun 14 13:35:32 2010
@@ -16,17 +16,33 @@
  *  specific language governing permissions and limitations
  *  under the License.
  ****************************************************************/
-package org.apache.cayenne.unit;
+package org.apache.cayenne.unit.di.server;
 
-/**
- * A superclass of test cases using "inheritance" DataMap for its access stack.
- * 
- */
-public abstract class InheritanceCase extends CayenneCase {
-    public static final String INHERITANCE_ACCESS_STACK = "InheritanceStack";
+import junit.framework.TestCase;
+
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.di.Provider;
+import org.apache.cayenne.unit.di.DefaultUnitTestLifecycleManager;
+import org.apache.cayenne.unit.di.UnitTestScope;
+
+public class ServerCaseLifecycleManager extends DefaultUnitTestLifecycleManager {
+
+    @Inject
+    protected Provider<ServerCaseProperties> propertiesProvider;
+
+    public ServerCaseLifecycleManager(UnitTestScope scope) {
+        super(scope);
+    }
 
     @Override
-    protected AccessStack buildAccessStack() {
-        return CayenneResources.getResources().getAccessStack(INHERITANCE_ACCESS_STACK);
+    public <T extends TestCase> void setUp(T testCase) {
+
+        UseServerRuntime runtimeName = testCase.getClass().getAnnotation(
+                UseServerRuntime.class);
+
+        String location = runtimeName != null ? runtimeName.value() : null;
+        propertiesProvider.get().setConfigurationLocation(location);
+
+        super.setUp(testCase);
     }
 }



Mime
View raw message