cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1126271 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test: java/org/apache/cayenne/unit/ java/org/apache/cayenne/unit/di/server/ resources/
Date Sun, 22 May 2011 22:52:57 GMT
Author: aadamchik
Date: Sun May 22 22:52:57 2011
New Revision: 1126271

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

unmapping AccessStack

Added:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/SchemaHelper.java
      - copied, changed from r1126270, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/SimpleAccessStack.java
Removed:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/AccessStack.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/SimpleAccessStack.java
Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/CayenneResourcesProvider.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/spring-test-resources.xml

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/CayenneResourcesProvider.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/CayenneResourcesProvider.java?rev=1126271&r1=1126270&r2=1126271&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/CayenneResourcesProvider.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/CayenneResourcesProvider.java
Sun May 22 22:52:57 2011
@@ -24,13 +24,15 @@ import org.apache.cayenne.ConfigurationE
 import org.apache.cayenne.conn.DataSourceInfo;
 import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.di.Provider;
-import org.apache.cayenne.unit.AccessStack;
+import org.apache.cayenne.map.DataMap;
+import org.apache.cayenne.map.MapLoader;
 import org.apache.cayenne.unit.CayenneResources;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.springframework.beans.factory.BeanFactory;
 import org.springframework.beans.factory.xml.XmlBeanFactory;
 import org.springframework.core.io.InputStreamResource;
+import org.xml.sax.InputSource;
 
 public class CayenneResourcesProvider implements Provider<CayenneResources> {
 
@@ -42,7 +44,14 @@ public class CayenneResourcesProvider im
     public static final String DEFAULT_CONNECTION_KEY = "internal_embedded_datasource";
 
     public static final String SKIP_SCHEMA_KEY = "cayenne.test.schema.skip";
-    public static final String SCHEMA_SETUP_STACK = "SchemaSetupStack";
+
+    private static String[] DATA_MAPS_REQUIREING_SCHEMA_SETUP = {
+            "testmap.map.xml", "people.map.xml", "locking.map.xml",
+            "relationships.map.xml", "multi-tier.map.xml", "generic.map.xml",
+            "map-db1.map.xml", "map-db2.map.xml", "embeddable.map.xml",
+            "qualified.map.xml", "quoted-identifiers.map.xml",
+            "inheritance-single-table1.map.xml", "inheritance-vertical.map.xml"
+    };
 
     @Inject
     private DataSourceInfo dataSourceInfo;
@@ -72,7 +81,7 @@ public class CayenneResourcesProvider im
         // possible initial failure we don't attempt rebuilding schema in subsequent
         // tests
         try {
-            rebuildSchema(factory);
+            rebuildSchema(resources);
         }
         catch (Exception ex) {
             logger.error("Error generating schema...", ex);
@@ -85,26 +94,32 @@ public class CayenneResourcesProvider im
     /**
      * Completely rebuilds test schema.
      */
-    private void rebuildSchema(BeanFactory beanFactory) throws Exception {
+    private void rebuildSchema(CayenneResources resources) throws Exception {
 
         if ("true".equalsIgnoreCase(System.getProperty(SKIP_SCHEMA_KEY))) {
             logger.info("skipping schema generation... ");
             return;
         }
 
-        // generate schema using a special AccessStack that
-        // combines all DataMaps that require schema support
-        // schema generation is done like that instead of
-        // per stack on demand, to avoid conflicts when
-        // dropping and generating PK objects.
-        AccessStack stack = (AccessStack) beanFactory.getBean(
-                SCHEMA_SETUP_STACK,
-                AccessStack.class);
-
-        stack.dropSchema();
-        stack.dropPKSupport();
-        stack.createSchema();
-        stack.createPKSupport();
-    }
+        // generate schema combining all DataMaps that require schema support.
+        // Schema generation is done like that instead of per DataMap on demand to avoid
+        // conflicts when dropping and generating PK objects.
+
+        DataMap[] maps = new DataMap[DATA_MAPS_REQUIREING_SCHEMA_SETUP.length];
+
+        for (int i = 0; i < maps.length; i++) {
+            InputStream stream = getClass().getClassLoader().getResourceAsStream(
+                    DATA_MAPS_REQUIREING_SCHEMA_SETUP[i]);
+            InputSource in = new InputSource(stream);
+            in.setSystemId(DATA_MAPS_REQUIREING_SCHEMA_SETUP[i]);
+            maps[i] = new MapLoader().loadDataMap(in);
+        }
 
+        SchemaHelper schemaHelper = new SchemaHelper(resources, maps);
+
+        schemaHelper.dropSchema();
+        schemaHelper.dropPKSupport();
+        schemaHelper.createSchema();
+        schemaHelper.createPKSupport();
+    }
 }

Copied: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/SchemaHelper.java
(from r1126270, 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/di/server/SchemaHelper.java?p2=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/SchemaHelper.java&p1=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/SimpleAccessStack.java&r1=1126270&r2=1126271&rev=1126271&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/di/server/SchemaHelper.java
Sun May 22 22:52:57 2011
@@ -17,7 +17,7 @@
  *  under the License.
  ****************************************************************/
 
-package org.apache.cayenne.unit;
+package org.apache.cayenne.unit.di.server;
 
 import java.sql.Connection;
 import java.sql.DatabaseMetaData;
@@ -28,35 +28,33 @@ import java.sql.Types;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.List;
 import java.util.ListIterator;
 
-import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.access.DataNode;
 import org.apache.cayenne.access.DbGenerator;
-import org.apache.cayenne.access.QueryLogger;
 import org.apache.cayenne.access.UnitTestDomain;
 import org.apache.cayenne.access.dbsync.SkipSchemaUpdateStrategy;
 import org.apache.cayenne.ashwood.AshwoodEntitySorter;
 import org.apache.cayenne.cache.MapQueryCache;
 import org.apache.cayenne.dba.DbAdapter;
-import org.apache.cayenne.dba.QuotingStrategy;
 import org.apache.cayenne.event.DefaultEventManager;
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.Procedure;
 import org.apache.cayenne.testdo.testmap.StringET1ExtendedType;
+import org.apache.cayenne.unit.AccessStackAdapter;
+import org.apache.cayenne.unit.CayenneResources;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 /**
  * Default implementation of the AccessStack that has a single DataNode per DataMap.
  */
-public class SimpleAccessStack implements AccessStack {
+class SchemaHelper {
 
-    private static Log logger = LogFactory.getLog(SimpleAccessStack.class);
+    private static Log logger = LogFactory.getLog(SchemaHelper.class);
 
     // hardcoded dependent entities that should be excluded
     // if LOBs are not supported
@@ -67,7 +65,7 @@ public class SimpleAccessStack implement
     protected CayenneResources resources;
     protected UnitTestDomain domain;
 
-    public SimpleAccessStack(CayenneResources resources, DataMap[] maps) throws Exception
{
+    public SchemaHelper(CayenneResources resources, DataMap[] maps) throws Exception {
 
         this.resources = resources;
         this.domain = new UnitTestDomain("domain");
@@ -211,63 +209,6 @@ public class SimpleAccessStack implement
         return entities;
     }
 
-    private void deleteTestData(DataNode node, DataMap map) throws Exception {
-
-        Connection conn = node.getDataSource().getConnection();
-        List<DbEntity> list = dbEntitiesInInsertOrder(node, map);
-        try {
-            if (conn.getAutoCommit()) {
-                conn.setAutoCommit(false);
-            }
-
-            Statement stmt = conn.createStatement();
-
-            ListIterator<DbEntity> it = list.listIterator(list.size());
-            while (it.hasPrevious()) {
-                DbEntity ent = it.previous();
-
-                boolean status;
-                if (ent.getDataMap() != null
-                        && ent.getDataMap().isQuotingSQLIdentifiers()) {
-                    status = true;
-                }
-                else {
-                    status = false;
-                }
-
-                QuotingStrategy strategy = getAdapter(node).getQuotingStrategy(status);
-
-                String deleteSql = "DELETE FROM " + strategy.quoteString(ent.getName());
-
-                try {
-                    stmt.executeUpdate(deleteSql);
-                }
-                catch (SQLException e) {
-                    try {
-                        Collection<String> deleteTableSql = node
-                                .getAdapter()
-                                .dropTableStatements(ent);
-                        stmt.executeUpdate(deleteTableSql.iterator().next());
-                        String createTableSql = node.getAdapter().createTable(ent);
-                        stmt.executeUpdate(createTableSql);
-                    }
-                    catch (SQLException e1) {
-                        throw new CayenneRuntimeException(
-                                "Error deleting test data for entity '"
-                                        + ent.getName()
-                                        + "': "
-                                        + e.getLocalizedMessage());
-                    }
-                }
-            }
-            conn.commit();
-            stmt.close();
-        }
-        finally {
-            conn.close();
-        }
-    }
-
     private void dropSchema(DataNode node, DataMap map) throws Exception {
         Connection conn = node.getDataSource().getConnection();
         List<DbEntity> list = dbEntitiesInInsertOrder(node, map);
@@ -338,7 +279,7 @@ public class SimpleAccessStack implement
             Statement stmt = conn.createStatement();
 
             for (String query : tableCreateQueries(node, map)) {
-                QueryLogger.logQuery(query, Collections.EMPTY_LIST);
+                logger.info(query);
                 stmt.execute(query);
             }
             getAdapter(node).createdTables(conn, map);

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/spring-test-resources.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/spring-test-resources.xml?rev=1126271&r1=1126270&r2=1126271&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/spring-test-resources.xml
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/spring-test-resources.xml
Sun May 22 22:52:57 2011
@@ -112,31 +112,6 @@
     <bean id="InheritanceVerticalMap" class="org.apache.cayenne.unit.DataMapFactory">
         <constructor-arg><value>inheritance-vertical.map.xml</value></constructor-arg>
     </bean>
-    
-	<!-- ======================================= -->
-	<!-- Access Stacks -->
-	<!-- ======================================= -->
-	<!-- Used to create DB schema to avoid conflicts when schema for individual stacks is
generated. -->
-	<bean id="SchemaSetupStack" class="org.apache.cayenne.unit.SimpleAccessStack">
-		<constructor-arg><ref bean="TestResources"/></constructor-arg>
-		<constructor-arg>
-			<list>
-				<ref bean="TestMap"/>
-				<ref bean="PeopleMap"/>
-				<ref bean="LockingMap"/>
-				<ref bean="RelationshipMap"/>
-				<ref bean="MultiTierMap"/>
-				<ref bean="GenericMap"/>
-				<ref bean="DB1Map"/>
-				<ref bean="DB2Map"/>
-				<ref bean="EmbeddingMap"/>
-				<ref bean="QualifiedMap"/>
-                <ref bean="QuoteMap"/>
-				<ref bean="InheritanceSingleTable1Map"/>
-				<ref bean="InheritanceVerticalMap"/>
-			</list>
-		</constructor-arg>
-	</bean>
 	
 	
 	<!-- ======================================= -->



Mime
View raw message