cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r407100 - in /incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests: java/org/objectstyle/cayenne/ java/org/objectstyle/cayenne/unit/ resources/dml/
Date Tue, 16 May 2006 23:00:45 GMT
Author: aadamchik
Date: Tue May 16 16:00:38 2006
New Revision: 407100

URL: http://svn.apache.org/viewcvs?rev=407100&view=rev
Log:
Refactoring tests as a part of CAY-548 investigation

Added:
    incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/resources/dml/CayenneDataObjectFlattenedRelTst.xml
Modified:
    incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/objectstyle/cayenne/CayenneDOTestBase.java
    incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/objectstyle/cayenne/CayenneDataObjectFlattenedRelTst.java
    incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/objectstyle/cayenne/unit/TestCaseDataFactory.java

Modified: incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/objectstyle/cayenne/CayenneDOTestBase.java
URL: http://svn.apache.org/viewcvs/incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/objectstyle/cayenne/CayenneDOTestBase.java?rev=407100&r1=407099&r2=407100&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/objectstyle/cayenne/CayenneDOTestBase.java
(original)
+++ incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/objectstyle/cayenne/CayenneDOTestBase.java
Tue May 16 16:00:38 2006
@@ -74,8 +74,7 @@
     public static final String galleryName = "my gallery";
     public static final String textReview = "this painting sucks...";
     public static final String paintingName = "painting about nothing";
-    public static final String groupName = "a group";
-
+   
     static final byte[] paintingImage = new byte[] { 2, 3, 4, 5 };
 
     protected DataContext ctxt;

Modified: incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/objectstyle/cayenne/CayenneDataObjectFlattenedRelTst.java
URL: http://svn.apache.org/viewcvs/incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/objectstyle/cayenne/CayenneDataObjectFlattenedRelTst.java?rev=407100&r1=407099&r2=407100&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/objectstyle/cayenne/CayenneDataObjectFlattenedRelTst.java
(original)
+++ incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/objectstyle/cayenne/CayenneDataObjectFlattenedRelTst.java
Tue May 16 16:00:38 2006
@@ -62,8 +62,6 @@
 import org.objectstyle.cayenne.access.DataContext;
 import org.objectstyle.cayenne.exp.ExpressionFactory;
 import org.objectstyle.cayenne.query.SelectQuery;
-import org.objectstyle.cayenne.unit.TestCaseDataFactory;
-import org.objectstyle.cayenne.util.Util;
 
 /**
  * Test case for objects with flattened relationships.
@@ -71,48 +69,40 @@
  * @author Andrei Adamchik
  */
 // TODO: redefine all test cases in terms of entities in "relationships" map
-// and merge this test case with FlattenedRelationshipsTst that inherits 
+// and merge this test case with FlattenedRelationshipsTst that inherits
 // from RelationshipTestCase.
 public class CayenneDataObjectFlattenedRelTst extends CayenneDOTestBase {
 
     public void testReadFlattenedRelationship() throws Exception {
-        //Test no groups
-        TestCaseDataFactory.createArtistBelongingToGroups(artistName, new String[] {
-        });
-
-        Artist a1 = fetchArtist();
+        createTestData("testReadFlattenedRelationship");
+        Artist a1 = (Artist) DataObjectUtils.objectForPK(ctxt, Artist.class, 33001);
         List groupList = a1.getGroupArray();
         assertNotNull(groupList);
         assertEquals(0, groupList.size());
     }
 
     public void testReadFlattenedRelationship2() throws Exception {
-        //Test no groups
-        TestCaseDataFactory.createArtistBelongingToGroups(
-            artistName,
-            new String[] { groupName });
+        createTestData("testReadFlattenedRelationship2");
 
-        Artist a1 = fetchArtist();
+        Artist a1 = (Artist) DataObjectUtils.objectForPK(ctxt, Artist.class, 33001);
         List groupList = a1.getGroupArray();
         assertNotNull(groupList);
         assertEquals(1, groupList.size());
-        assertEquals(
-            PersistenceState.COMMITTED,
-            ((ArtGroup) groupList.get(0)).getPersistenceState());
-        assertEquals(groupName, ((ArtGroup) groupList.get(0)).getName());
+        assertEquals(PersistenceState.COMMITTED, ((ArtGroup) groupList.get(0))
+                .getPersistenceState());
+        assertEquals("g1", ((ArtGroup) groupList.get(0)).getName());
     }
 
     public void testAddToFlattenedRelationship() throws Exception {
-        TestCaseDataFactory.createArtist(artistName);
-        TestCaseDataFactory.createUnconnectedGroup(groupName);
 
-        Artist a1 = fetchArtist();
+        createTestData("testAddToFlattenedRelationship");
+
+        Artist a1 = (Artist) DataObjectUtils.objectForPK(ctxt, Artist.class, 33001);
         assertEquals(0, a1.getGroupArray().size());
 
-        SelectQuery q =
-            new SelectQuery(
-                ArtGroup.class,
-                ExpressionFactory.matchExp("name", groupName));
+        SelectQuery q = new SelectQuery(ArtGroup.class, ExpressionFactory.matchExp(
+                "name",
+                "g1"));
         List results = ctxt.performQuery(q);
         assertEquals(1, results.size());
 
@@ -123,33 +113,30 @@
 
         List groupList = a1.getGroupArray();
         assertEquals(1, groupList.size());
-        assertEquals(groupName, ((ArtGroup) groupList.get(0)).getName());
+        assertEquals("g1", ((ArtGroup) groupList.get(0)).getName());
 
-        //Ensure that the commit doesn't fail
+        // Ensure that the commit doesn't fail
         a1.getDataContext().commitChanges();
 
-        //and check again
+        // and check again
         assertFalse(ctxt.hasChanges());
 
         // refetch artist with a different context
         ctxt = createDataContext();
-        a1 = fetchArtist();
+        a1 = (Artist) DataObjectUtils.objectForPK(ctxt, Artist.class, 33001);
         groupList = a1.getGroupArray();
         assertEquals(1, groupList.size());
-        assertEquals(groupName, ((ArtGroup) groupList.get(0)).getName());
+        assertEquals("g1", ((ArtGroup) groupList.get(0)).getName());
     }
 
-    //Test case to show up a bug in committing more than once
+    // Test case to show up a bug in committing more than once
     public void testDoubleCommitAddToFlattenedRelationship() throws Exception {
-        TestCaseDataFactory.createArtistBelongingToGroups(artistName, new String[] {
-        });
-        TestCaseDataFactory.createUnconnectedGroup(groupName);
-        Artist a1 = fetchArtist();
-
-        SelectQuery q =
-            new SelectQuery(
-                ArtGroup.class,
-                ExpressionFactory.matchExp("name", groupName));
+        createTestData("testDoubleCommitAddToFlattenedRelationship");
+        Artist a1 = (Artist) DataObjectUtils.objectForPK(ctxt, Artist.class, 33001);
+
+        SelectQuery q = new SelectQuery(ArtGroup.class, ExpressionFactory.matchExp(
+                "name",
+                "g1"));
         List results = ctxt.performQuery(q);
         assertEquals(1, results.size());
 
@@ -158,13 +145,13 @@
 
         List groupList = a1.getGroupArray();
         assertEquals(1, groupList.size());
-        assertEquals(groupName, ((ArtGroup) groupList.get(0)).getName());
+        assertEquals("g1", ((ArtGroup) groupList.get(0)).getName());
 
-        //Ensure that the commit doesn't fail
+        // Ensure that the commit doesn't fail
         a1.getDataContext().commitChanges();
 
         try {
-            //The bug caused the second commit to fail (the link record
+            // The bug caused the second commit to fail (the link record
             // was inserted again)
             a1.getDataContext().commitChanges();
         }
@@ -176,10 +163,8 @@
     }
 
     public void testRemoveFromFlattenedRelationship() throws Exception {
-        TestCaseDataFactory.createArtistBelongingToGroups(
-            artistName,
-            new String[] { groupName });
-        Artist a1 = fetchArtist();
+        createTestData("testRemoveFromFlattenedRelationship");
+        Artist a1 = (Artist) DataObjectUtils.objectForPK(ctxt, Artist.class, 33001);
 
         ArtGroup group = (ArtGroup) a1.getGroupArray().get(0);
         a1.removeFromGroupArray(group);
@@ -187,27 +172,26 @@
         List groupList = a1.getGroupArray();
         assertEquals(0, groupList.size());
 
-        //Ensure that the commit doesn't fail
+        // Ensure that the commit doesn't fail
         a1.getDataContext().commitChanges();
 
-        //and check again
+        // and check again
         groupList = a1.getGroupArray();
         assertEquals(0, groupList.size());
     }
 
-    //Shows up a possible bug in ordering of deletes, when a flattened relationships link
record is deleted
+    // Shows up a possible bug in ordering of deletes, when a flattened relationships link
+    // record is deleted
     // at the same time (same transaction) as one of the record to which it links.
     public void testRemoveFlattenedRelationshipAndRootRecord() throws Exception {
-        TestCaseDataFactory.createArtistBelongingToGroups(
-            artistName,
-            new String[] { groupName });
-        Artist a1 = fetchArtist();
+        createTestData("testRemoveFlattenedRelationshipAndRootRecord");
+        Artist a1 = (Artist) DataObjectUtils.objectForPK(ctxt, Artist.class, 33001);
         DataContext dc = a1.getDataContext();
 
         ArtGroup group = (ArtGroup) a1.getGroupArray().get(0);
-        a1.removeFromGroupArray(group); //Cause the delete of the link record
+        a1.removeFromGroupArray(group); // Cause the delete of the link record
 
-        dc.deleteObject(a1); //Cause the deletion of the artist
+        dc.deleteObject(a1); // Cause the deletion of the artist
 
         try {
             dc.commitChanges();
@@ -218,42 +202,44 @@
         }
     }
 
-    /* Catches a bug in the flattened relationship registration which just inserted/deleted
willy-nilly, 
-     * even if unneccessary */
-    public void testAddRemoveAddFlattenedRelationship() throws Exception {
-        String specialGroupName = "Special Group2";
-        TestCaseDataFactory.createArtistBelongingToGroups(artistName, new String[] {
-        });
-        TestCaseDataFactory.createUnconnectedGroup(specialGroupName);
-        Artist a1 = fetchArtist();
-
-        SelectQuery q =
-            new SelectQuery(
-                ArtGroup.class,
-                ExpressionFactory.matchExp("name", specialGroupName));
+    public void testAddRemoveFlattenedRelationship1() throws Exception {
+        createTestData("testAddRemoveFlattenedRelationship1");
+        Artist a1 = (Artist) DataObjectUtils.objectForPK(ctxt, Artist.class, 33001);
+
+        SelectQuery q = new SelectQuery(ArtGroup.class, ExpressionFactory.matchExp(
+                "name",
+                "g1"));
         List results = ctxt.performQuery(q);
         assertEquals(1, results.size());
 
         ArtGroup group = (ArtGroup) results.get(0);
         a1.addToGroupArray(group);
         group.removeFromArtistArray(a1);
-        //a1.addToGroupArray(group);
 
+        blockQueries();
         try {
             ctxt.commitChanges();
         }
-        catch (Exception e) {
-            Util.unwindException(e).printStackTrace();
-            fail("Should not have thrown the exception " + e.getMessage());
+        finally {
+            unblockQueries();
         }
+    }
 
-        ctxt = createDataContext();
-        results = ctxt.performQuery(q);
-        assertEquals(1, results.size());
+    public void testAddRemoveFlattenedRelationship2() throws Exception {
+
+        createTestData("testAddRemoveFlattenedRelationship2");
+        Artist a1 = (Artist) DataObjectUtils.objectForPK(ctxt, Artist.class, 33001);
+
+        SelectQuery q = new SelectQuery(ArtGroup.class);
+        List results = ctxt.performQuery(q);
+        assertEquals(2, results.size());
+
+        ArtGroup g1 = (ArtGroup) results.get(0);
+        ArtGroup g2 = (ArtGroup) results.get(1);
+        a1.addToGroupArray(g1);
+        a1.addToGroupArray(g2);
+        a1.removeFromGroupArray(g1);
 
-        group = (ArtGroup) results.get(0);
-        assertEquals(0, group.getArtistArray().size());
-        //a1 = fetchArtist();
-        //assertTrue(group.getArtistArray().contains(a1));
+        ctxt.commitChanges();
     }
 }

Modified: incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/objectstyle/cayenne/unit/TestCaseDataFactory.java
URL: http://svn.apache.org/viewcvs/incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/objectstyle/cayenne/unit/TestCaseDataFactory.java?rev=407100&r1=407099&r2=407100&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/objectstyle/cayenne/unit/TestCaseDataFactory.java
(original)
+++ incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/objectstyle/cayenne/unit/TestCaseDataFactory.java
Tue May 16 16:00:38 2006
@@ -74,22 +74,6 @@
         conn.commit();
     }
 
-    public static void createArtist(String artistName) throws Exception {
-
-        Connection conn = CayenneTestResources
-                .getResources()
-                .getDataSource()
-                .getConnection();
-
-        try {
-            conn.setAutoCommit(false);
-            createArtist(conn, artistName);
-        }
-        finally {
-            conn.close();
-        }
-    }
-
     public static void createArtistWithPainting(
             String artistName,
             String[] paintingNames,
@@ -138,63 +122,4 @@
             conn.close();
         }
     }
-
-    public static void createArtistBelongingToGroups(
-            String artistName,
-            String[] groupNames) throws Exception {
-        Connection conn = CayenneTestResources
-                .getResources()
-                .getDataSource()
-                .getConnection();
-
-        try {
-            conn.setAutoCommit(false);
-            createArtist(conn, artistName);
-            String insertGroup = "INSERT INTO ARTGROUP (GROUP_ID, NAME) VALUES (?,?)";
-            String insertLink = "INSERT INTO ARTIST_GROUP (GROUP_ID, ARTIST_ID) VALUES (?,?)";
-            PreparedStatement groupStmt = conn.prepareStatement(insertGroup);
-            PreparedStatement linkStmt = conn.prepareStatement(insertLink);
-
-            int len = groupNames.length;
-            if (len > 0) {
-                for (int i = 0; i < len; i++) {
-                    groupStmt.setInt(1, i + 1);
-                    groupStmt.setString(2, groupNames[i]);
-                    groupStmt.executeUpdate();
-
-                    linkStmt.setInt(1, i + 1); // group id
-                    linkStmt.setInt(2, 1); // artist id
-                    linkStmt.executeUpdate();
-                }
-                groupStmt.close();
-                linkStmt.close();
-                conn.commit();
-            }
-        }
-        finally {
-            conn.close();
-        }
-    }
-
-    public static void createUnconnectedGroup(String groupName) throws Exception {
-        Connection conn = CayenneTestResources
-                .getResources()
-                .getDataSource()
-                .getConnection();
-
-        try {
-            conn.setAutoCommit(false);
-            String insertGroup = "INSERT INTO ARTGROUP (GROUP_ID, NAME) VALUES (?,?)";
-            PreparedStatement groupStmt = conn.prepareStatement(insertGroup);
-            groupStmt.setInt(1, 1);
-            groupStmt.setString(2, groupName);
-            groupStmt.executeUpdate();
-            groupStmt.close();
-            conn.commit();
-        }
-        finally {
-            conn.close();
-        }
-    }
-
 }

Added: incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/resources/dml/CayenneDataObjectFlattenedRelTst.xml
URL: http://svn.apache.org/viewcvs/incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/resources/dml/CayenneDataObjectFlattenedRelTst.xml?rev=407100&view=auto
==============================================================================
--- incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/resources/dml/CayenneDataObjectFlattenedRelTst.xml
(added)
+++ incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/resources/dml/CayenneDataObjectFlattenedRelTst.xml
Tue May 16 16:00:38 2006
@@ -0,0 +1,122 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
+
+<beans default-lazy-init="true">	
+	<!-- ======================================= -->
+	<!-- Named Queries -->
+	<!-- ======================================= -->
+	
+	<!-- ARTIST -->
+	<bean id="A1" class="org.objectstyle.cayenne.unit.util.UpdatingSQLTemplate">
+		<constructor-arg type="java.lang.Class"><value>org.objectstyle.art.Artist</value></constructor-arg>
+		<constructor-arg><value>
+		insert into ARTIST (ARTIST_ID, ARTIST_NAME) values (33001, 'artist1')
+		</value></constructor-arg>
+	</bean>
+	
+	<!-- ARTGROUP -->
+	<bean id="AG1" class="org.objectstyle.cayenne.unit.util.UpdatingSQLTemplate">
+		<constructor-arg type="java.lang.Class"><value>org.objectstyle.art.ArtGroup</value></constructor-arg>
+		<constructor-arg><value>
+		INSERT INTO ARTGROUP (GROUP_ID, NAME) VALUES (1,'g1')
+		</value></constructor-arg>
+	</bean>
+	
+	<bean id="AG2" class="org.objectstyle.cayenne.unit.util.UpdatingSQLTemplate">
+		<constructor-arg type="java.lang.Class"><value>org.objectstyle.art.ArtGroup</value></constructor-arg>
+		<constructor-arg><value>
+		INSERT INTO ARTGROUP (GROUP_ID, NAME) VALUES (2,'g2')
+		</value></constructor-arg>
+	</bean>
+	
+	
+	<!-- ARTIST_GROUP -->
+	<bean id="AGG1" class="org.objectstyle.cayenne.unit.util.UpdatingSQLTemplate">
+		<constructor-arg type="java.lang.Class"><value>org.objectstyle.art.ArtGroup</value></constructor-arg>
+		<constructor-arg><value>
+		INSERT INTO ARTIST_GROUP (ARTIST_ID, GROUP_ID) VALUES (33001,1)
+		</value></constructor-arg>
+	</bean>
+     
+	
+	<!-- ======================================= -->
+	<!-- Data Sets -->
+	<!-- ======================================= -->	
+	
+	<bean id="testReadFlattenedRelationship" class="java.util.ArrayList">
+		<constructor-arg>
+			<list>
+				<ref bean="A1"/>
+				<ref bean="AG1"/>
+			</list>
+		</constructor-arg>
+	</bean>
+	
+	<bean id="testReadFlattenedRelationship2" class="java.util.ArrayList">
+		<constructor-arg>
+			<list>
+				<ref bean="A1"/>
+				<ref bean="AG1"/>
+				<ref bean="AGG1"/>
+			</list>
+		</constructor-arg>
+	</bean>
+	
+	<bean id="testAddToFlattenedRelationship" class="java.util.ArrayList">
+		<constructor-arg>
+			<list>
+				<ref bean="A1"/>
+				<ref bean="AG1"/>
+			</list>
+		</constructor-arg>
+	</bean>
+	
+	
+	<bean id="testDoubleCommitAddToFlattenedRelationship" class="java.util.ArrayList">
+		<constructor-arg>
+			<list>
+				<ref bean="A1"/>
+				<ref bean="AG1"/>
+			</list>
+		</constructor-arg>
+	</bean>
+	
+	<bean id="testRemoveFromFlattenedRelationship" class="java.util.ArrayList">
+		<constructor-arg>
+			<list>
+				<ref bean="A1"/>
+				<ref bean="AG1"/>
+				<ref bean="AGG1"/>
+			</list>
+		</constructor-arg>
+	</bean>
+	
+	<bean id="testRemoveFlattenedRelationshipAndRootRecord" class="java.util.ArrayList">
+		<constructor-arg>
+			<list>
+				<ref bean="A1"/>
+				<ref bean="AG1"/>
+				<ref bean="AGG1"/>
+			</list>
+		</constructor-arg>
+	</bean>
+	
+	<bean id="testAddRemoveFlattenedRelationship1" class="java.util.ArrayList">
+		<constructor-arg>
+			<list>
+				<ref bean="A1"/>
+				<ref bean="AG1"/>
+			</list>
+		</constructor-arg>
+	</bean>
+	
+	<bean id="testAddRemoveFlattenedRelationship2" class="java.util.ArrayList">
+		<constructor-arg>
+			<list>
+				<ref bean="A1"/>
+				<ref bean="AG1"/>
+				<ref bean="AG2"/>
+			</list>
+		</constructor-arg>
+	</bean>
+</beans>
\ No newline at end of file



Mime
View raw message