db-jdo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c..@apache.org
Subject svn commit: r1039618 - in /db/jdo/trunk/tck/src/java/org/apache/jdo/tck/mapping: AbstractRelationshipTest.java Relationship1ToManyAllRelationships.java RelationshipManyToManyAllRelationships.java
Date Sat, 27 Nov 2010 04:24:31 GMT
Author: clr
Date: Sat Nov 27 04:24:30 2010
New Revision: 1039618

URL: http://svn.apache.org/viewvc?rev=1039618&view=rev
Log:
JDO-669 Avoid using hashCode and equals in contains test for deleted objects

Modified:
    db/jdo/trunk/tck/src/java/org/apache/jdo/tck/mapping/AbstractRelationshipTest.java
    db/jdo/trunk/tck/src/java/org/apache/jdo/tck/mapping/Relationship1ToManyAllRelationships.java
    db/jdo/trunk/tck/src/java/org/apache/jdo/tck/mapping/RelationshipManyToManyAllRelationships.java

Modified: db/jdo/trunk/tck/src/java/org/apache/jdo/tck/mapping/AbstractRelationshipTest.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck/src/java/org/apache/jdo/tck/mapping/AbstractRelationshipTest.java?rev=1039618&r1=1039617&r2=1039618&view=diff
==============================================================================
--- db/jdo/trunk/tck/src/java/org/apache/jdo/tck/mapping/AbstractRelationshipTest.java (original)
+++ db/jdo/trunk/tck/src/java/org/apache/jdo/tck/mapping/AbstractRelationshipTest.java Sat
Nov 27 04:24:30 2010
@@ -18,12 +18,15 @@
 package org.apache.jdo.tck.mapping;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
 
 import org.apache.jdo.tck.AbstractReaderTest;
 import org.apache.jdo.tck.pc.company.CompanyFactoryRegistry;
 import org.apache.jdo.tck.pc.company.CompanyModelReader;
+import org.apache.jdo.tck.pc.company.Employee;
+import org.apache.jdo.tck.pc.company.Project;
 
 /*
  * Abstract class for managed relationship tests
@@ -72,4 +75,22 @@ public class AbstractRelationshipTest ex
         }
     }
 
+    protected boolean containsEmployee(Collection<Employee> employees, long empid)
{
+        for (Employee emp: employees) {
+            if (emp.getPersonid() == empid) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    protected boolean containsProject(Collection<Project> projects, long projid) {
+        for (Project project: projects) {
+            if (project.getProjid() == projid) {
+                return true;
+            }
+        }
+        return false;
+    }
+
 }

Modified: db/jdo/trunk/tck/src/java/org/apache/jdo/tck/mapping/Relationship1ToManyAllRelationships.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck/src/java/org/apache/jdo/tck/mapping/Relationship1ToManyAllRelationships.java?rev=1039618&r1=1039617&r2=1039618&view=diff
==============================================================================
--- db/jdo/trunk/tck/src/java/org/apache/jdo/tck/mapping/Relationship1ToManyAllRelationships.java
(original)
+++ db/jdo/trunk/tck/src/java/org/apache/jdo/tck/mapping/Relationship1ToManyAllRelationships.java
Sat Nov 27 04:24:30 2010
@@ -409,21 +409,14 @@ public class Relationship1ToManyAllRelat
     public void testDeleteFromMappedSide() {
         testMethod = "testDeleteFromMappedSide";
         if (isTestToBePerformed) {
+            // remember id
+            long emp1Id = emp1.getPersonid();
             // Set relationship
             pm.deletePersistent(emp1);
             pm.flush();
             
             // Postcondition
-            boolean contained = false;
-            Iterator iter = dept1.getEmployees().iterator();
-            while (iter.hasNext()) {
-        	Object elem = iter.next();
-        	if (JDOHelper.getObjectId(elem).equals(emp1)) {
-        	    contained = true;
-        	    break;
-        	}
-            }
-            deferredAssertTrue(!contained,
+            deferredAssertTrue(!containsEmployee(dept1.getEmployees(), emp1Id),
                 ASSERTION_FAILED + testMethod,
                 "Postcondition is false; "
                 + "other side of relationship not set on flush");
@@ -434,7 +427,7 @@ public class Relationship1ToManyAllRelat
             pm.currentTransaction().begin();
             dept1 = (Department)pm.getObjectById(dept1Oid);
             deferredAssertTrue(
-                !dept1.getEmployees().contains(emp1),
+                !containsEmployee(dept1.getEmployees(), emp1Id),
                 ASSERTION_FAILED + testMethod,
                 "In new transaction, postcondition is false; " +
                 "other side of relationship is not set.");

Modified: db/jdo/trunk/tck/src/java/org/apache/jdo/tck/mapping/RelationshipManyToManyAllRelationships.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck/src/java/org/apache/jdo/tck/mapping/RelationshipManyToManyAllRelationships.java?rev=1039618&r1=1039617&r2=1039618&view=diff
==============================================================================
--- db/jdo/trunk/tck/src/java/org/apache/jdo/tck/mapping/RelationshipManyToManyAllRelationships.java
(original)
+++ db/jdo/trunk/tck/src/java/org/apache/jdo/tck/mapping/RelationshipManyToManyAllRelationships.java
Sat Nov 27 04:24:30 2010
@@ -162,7 +162,7 @@ public class RelationshipManyToManyAllRe
             IEmployee empNew = new FullTimeEmployee(100, "Jerry", "Valentine",
                     "Brown", new Date(500L), new Date(10000L), 125000);
             pm.makePersistent(empNew);
-            Set members = new HashSet();
+            Set<IEmployee> members = new HashSet<IEmployee>();
             members.add(empNew);
             proj1.setMembers(members);
             Object empNewOid = pm.getObjectId((Object)empNew);
@@ -201,7 +201,7 @@ public class RelationshipManyToManyAllRe
             IProject projNew = new Project(99L, "Skunkworks",
                     new BigDecimal(10000.35));
             pm.makePersistent(projNew);
-            Set projects = new HashSet();
+            Set<IProject> projects = new HashSet<IProject>();
             projects.add(projNew);
             emp1.setProjects(projects);
             Object projNewOid = pm.getObjectId((Object)projNew);
@@ -438,12 +438,14 @@ public class RelationshipManyToManyAllRe
     public void testDeleteFromMappedSide() {
     testMethod = "testDeleteFromMappedSide";
         if (isTestToBePerformed) {
+            // remember id
+            long proj1Id = proj1.getProjid();
             // Set relationship
             pm.deletePersistent(proj1);
             pm.flush();
             
             // Postcondition
-            deferredAssertTrue(!emp1.getProjects().contains(proj1),
+            deferredAssertTrue(!containsProject(emp1.getProjects(), proj1Id),
                     ASSERTION_FAILED + testMethod,
                     "Postcondition is false; "
                     + "other side of relationship not set on flush");
@@ -454,7 +456,7 @@ public class RelationshipManyToManyAllRe
             pm.currentTransaction().begin();
             emp1 = (Employee)pm.getObjectById(emp1Oid);
             deferredAssertTrue(
-                    !emp1.getProjects().contains(proj1),
+                    !containsProject(emp1.getProjects(), proj1Id),
                     ASSERTION_FAILED + testMethod,
                     "In new transaction, postcondition is false; " +
                     "other side of relationship is not set.");
@@ -468,13 +470,14 @@ public class RelationshipManyToManyAllRe
     public void testDeleteFromMappedbySide() {
         testMethod = "testDeleteFromMappedbySide";
         if (isTestToBePerformed) {
-            
+            // remember id
+            long emp1Id = emp1.getPersonid();
             // Set relationship
             pm.deletePersistent(emp1);
             pm.flush();
             
             // Postcondition
-            deferredAssertTrue(!proj1.getMembers().contains(emp1),
+            deferredAssertTrue(!containsEmployee(proj1.getMembers(), emp1Id),
                     ASSERTION_FAILED + testMethod,
                     "Postcondition is false; "
                     + "other side of relationship not set on flush");
@@ -485,7 +488,7 @@ public class RelationshipManyToManyAllRe
             pm.currentTransaction().begin();
             proj1 = (Project)pm.getObjectById(proj1Oid);
             deferredAssertTrue(
-                    !proj1.getMembers().contains(emp1),
+                    !containsEmployee(proj1.getMembers(), emp1Id),
                     ASSERTION_FAILED + testMethod,
                     "In new transaction, postcondition is false; " +
                     "other side of relationship is not set.");



Mime
View raw message