You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jdo-commits@db.apache.org by mc...@apache.org on 2007/09/07 19:52:23 UTC
svn commit: r573641 [2/2] - in /db/jdo/trunk/tck2/src: conf/
java/org/apache/jdo/tck/ java/org/apache/jdo/tck/mapping/
Added: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/mapping/RelationshipManyToManyNoRelationships.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/mapping/RelationshipManyToManyNoRelationships.java?rev=573641&view=auto
==============================================================================
--- db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/mapping/RelationshipManyToManyNoRelationships.java (added)
+++ db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/mapping/RelationshipManyToManyNoRelationships.java Fri Sep 7 10:52:21 2007
@@ -0,0 +1,250 @@
+/*
+ * 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.jdo.tck.mapping;
+
+import java.math.BigDecimal;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Set;
+import org.apache.jdo.tck.pc.company.Employee;
+import org.apache.jdo.tck.pc.company.FullTimeEmployee;
+import org.apache.jdo.tck.pc.company.Project;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+
+/**
+ *<B>Title:</B>RelationshipManyToManyNoRelationships
+ *<BR>
+ *<B>Keywords:</B> mapping, managed relationships
+ *<BR>
+ *<B>Assertion ID:</B> A15.3-1
+ *<BR>
+ *<B>Assertion Description: Regardless of which side changes the relationship,
+ * flush (whether done as part of commit or explicitly by the user) will modify
+ * the datastore to reflect the change and will update the memory model
+ * for consistency.</B>
+ */
+
+public class RelationshipManyToManyNoRelationships extends AbstractRelationshipTest {
+
+ String testMethod = null;
+ protected String ASSERTION_FAILED =
+ "Assertion A15-3.1 (RelationshipManyToManyNoRelationships) failed: ";
+
+ Object emp1Oid = null;
+ Object proj1Oid = null;
+ Employee emp1 = null;
+ Project proj1 = null;
+
+ /**
+ * The <code>main</code> is called when the class
+ * is directly executed from the command line.
+ * @param args The arguments passed to the program.
+ */
+ public static void main(String[] args) {
+ BatchTestRunner.run(RelationshipManyToManyNoRelationships.class);
+ }
+
+
+ /**
+ * @see JDO_Test#localSetUp()
+ */
+ protected void localSetUp() {
+ super.localSetUp();
+ if (isTestToBePerformed) {
+ getPM();
+ pm.currentTransaction().begin();
+
+ emp1Oid = getOidByName("emp1");
+ proj1Oid = getOidByName("proj1");
+ emp1 = (Employee)pm.getObjectById(emp1Oid);
+ proj1 = (Project)pm.getObjectById(proj1Oid);
+
+ // Preconditions
+ assertTrue(testMethod +
+ ": Test aborted, precondition is false; " +
+ "expected emp.getProjects()to be empty",
+ emp1.getProjects().isEmpty());
+ assertTrue(testMethod +
+ ": Test aborted, precondition is false; " +
+ "expected ins.getMembers() to be empty",
+ proj1.getMembers().isEmpty());
+ }
+ }
+
+ /** */
+ public void testAddFromMappedSide() {
+ testMethod = "testAddFromMappedSide";
+ if (isTestToBePerformed) {
+ Object emp4Oid = getOidByName("emp4");
+ Employee emp4 = (Employee)pm.getObjectById(emp4Oid);
+ Object proj2Oid = getOidByName("proj2");
+ Project proj2 = (Project)pm.getObjectById(proj2Oid);
+
+ // Set relationship
+ Set emps = new HashSet();
+ emps.add(emp4);
+ proj1.setMembers(emps);
+ pm.flush();
+
+ // Postcondition
+ deferredAssertTrue(emp4.getProjects().contains(proj1),
+ ASSERTION_FAILED + testMethod,
+ "Postcondition is false; "
+ + "other side of relationship not set on flush");
+ pm.currentTransaction().commit();
+ cleanupPM();
+ getPM();
+
+ pm.currentTransaction().begin();
+ emp4 = (Employee)pm.getObjectById(emp4Oid);
+ proj1 = (Project)pm.getObjectById(proj1Oid);
+ proj2 = (Project)pm.getObjectById(proj2Oid);
+ deferredAssertTrue(
+ emp4.getProjects().contains(proj1),
+ ASSERTION_FAILED + testMethod,
+ "In new transaction, postcondition is false; " +
+ "other side of relationship is not set.");
+ pm.currentTransaction().commit();
+
+ failOnError();
+ }
+ }
+
+ /** */
+ public void testAddFromMappedbySide() {
+ testMethod = "testAddFromMappedbySide";
+ if (isTestToBePerformed) {
+ Object emp4Oid = getOidByName("emp4");
+ Employee emp4 = (Employee)pm.getObjectById(emp4Oid);
+ Object proj2Oid = getOidByName("proj2");
+ Project proj2 = (Project)pm.getObjectById(proj2Oid);
+
+ // Set relationship
+ Set projs = new HashSet();
+ projs.add(proj1);
+ emp4.setProjects(projs);
+ pm.flush();
+
+ // Postcondition
+ deferredAssertTrue(proj1.getMembers().contains(emp4),
+ ASSERTION_FAILED + testMethod,
+ "Postcondition is false; "
+ + "other side of relationship not set on flush");
+ pm.currentTransaction().commit();
+ cleanupPM();
+ getPM();
+
+ pm.currentTransaction().begin();
+ emp1 = (Employee)pm.getObjectById(emp1Oid);
+ proj1 = (Project)pm.getObjectById(proj1Oid);
+ deferredAssertTrue(
+ proj1.getMembers().contains(emp4),
+ ASSERTION_FAILED + testMethod,
+ "In new transaction, postcondition is false; " +
+ "other side of relationship is not set.");
+ pm.currentTransaction().commit();
+
+ failOnError();
+ }
+ }
+
+ /** */
+ public void testReplaceFromMappedSide() {
+ testMethod = "testReplaceFromMappedSide";
+ if (isTestToBePerformed) {
+
+ // Set relationship
+ Set members = new HashSet();
+ Employee empNew = new FullTimeEmployee(100, "Jerry", "Valentine",
+ "Brown", new Date(500L), new Date(10000L), 125000);
+ pm.makePersistent(empNew);
+ members.add(empNew);
+ proj1.setMembers(members);
+ Object empNewOid = pm.getObjectId(empNew);
+ pm.flush();
+
+ assertFalse(testMethod + ": Test aborted, precondition is false; " +
+ "expected empNewOid to be non-null", empNewOid == null);
+
+ // Postcondition
+
+ deferredAssertTrue(empNew.getProjects().contains(proj1),
+ ASSERTION_FAILED + testMethod,
+ "Postcondition is false; "
+ + "other side of relationship not set on flush");
+ pm.currentTransaction().commit();
+ cleanupPM();
+ getPM();
+
+ pm.currentTransaction().begin();
+ empNew = (Employee)pm.getObjectById(empNewOid);
+ emp1 = (Employee)pm.getObjectById(emp1Oid);
+ proj1 = (Project)pm.getObjectById(proj1Oid);
+ deferredAssertTrue(empNew.getProjects().contains(proj1),
+ ASSERTION_FAILED + testMethod,
+ "Postcondition is false; "
+ + "other side of relationship not set in new pm");
+ pm.currentTransaction().commit();
+
+ failOnError();
+ }
+ }
+
+ /** */
+ public void testReplaceFromMappedbySide() {
+ testMethod = "testReplaceFromMappedbySide";
+ if (isTestToBePerformed) {
+
+ // Set relationship
+ Set projects = new HashSet();
+ Project projNew = new Project(99L, "Skunkworks",
+ new BigDecimal(10000.35));
+ pm.makePersistent(projNew);
+ projects.add(projNew);
+ emp1.setProjects(projects);
+ Object projNewOid = pm.getObjectId((Object)projNew);
+ pm.flush();
+
+ assertFalse(testMethod + ": Test aborted, precondition is false; " +
+ "expected projNewOid to be non-null", projNewOid == null);
+
+ // Postcondition
+ deferredAssertTrue(projNew.getMembers().contains(emp1),
+ ASSERTION_FAILED + testMethod,
+ "Postcondition is false; "
+ + "other side of relationship not set on flush");
+ pm.currentTransaction().commit();
+ cleanupPM();
+ getPM();
+
+ pm.currentTransaction().begin();
+ emp1 = (Employee)pm.getObjectById(emp1Oid);
+ projNew = (Project)pm.getObjectById(projNewOid);
+ proj1 = (Project)pm.getObjectById(proj1Oid);
+ deferredAssertTrue(projNew.getMembers().contains(emp1),
+ ASSERTION_FAILED + testMethod,
+ "Postcondition is false; "
+ + "other side of relationship not set in new pm");
+ pm.currentTransaction().commit();
+
+ failOnError();
+ }
+ }
+
+}
Propchange: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/mapping/RelationshipManyToManyNoRelationships.java
------------------------------------------------------------------------------
svn:eol-style = LF
Added: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/mapping/RelationshipNegative1To1Test.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/mapping/RelationshipNegative1To1Test.java?rev=573641&view=auto
==============================================================================
--- db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/mapping/RelationshipNegative1To1Test.java (added)
+++ db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/mapping/RelationshipNegative1To1Test.java Fri Sep 7 10:52:21 2007
@@ -0,0 +1,154 @@
+/*
+ * 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.jdo.tck.mapping;
+
+import java.util.Date;
+import javax.jdo.JDOUserException;
+import org.apache.jdo.tck.pc.company.FullTimeEmployee;
+import org.apache.jdo.tck.pc.company.IEmployee;
+import org.apache.jdo.tck.pc.company.IMedicalInsurance;
+import org.apache.jdo.tck.pc.company.MedicalInsurance;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+
+/**
+ *<B>Title:</B>RelationshipNegative1To1Test
+ *<BR>
+ *<B>Keywords:</B> mapping, managed relationships
+ *<BR>
+ *<B>Assertion ID:</B> A15.3-1
+ *<BR>
+ *<B>Assertion Description: Regardless of which side changes the relationship,
+ * flush (whether done as part of commit or explicitly by the user) will modify
+ * the datastore to reflect the change and will update the memory model
+ * for consistency.</B>
+ */
+
+public class RelationshipNegative1To1Test extends AbstractRelationshipTest {
+
+ String testMethod = null;
+ protected String ASSERTION_FAILED =
+ "Assertion A15-3.1 (RelationshipNegative1To1Test) failed: ";
+
+ Object emp1Oid = null;
+ Object emp2Oid = null;
+ Object medIns1Oid = null;
+ Object medIns2Oid = null;
+ IEmployee emp1 = null;
+ IEmployee emp2 = null;
+ IMedicalInsurance medIns1 = null;
+ IMedicalInsurance medIns2 = null;
+
+ /**
+ * The <code>main</code> is called when the class
+ * is directly executed from the command line.
+ * @param args The arguments passed to the program.
+ */
+ public static void main(String[] args) {
+ BatchTestRunner.run(RelationshipNegative1To1Test.class);
+ }
+
+ /**
+ * @see JDO_Test#localSetUp()
+ */
+ protected void localSetUp() {
+ super.localSetUp();
+ if (isTestToBePerformed) {
+ getPM();
+ pm.currentTransaction().begin();
+
+ emp1Oid = getOidByName("emp1");
+ emp2Oid = getOidByName("emp2");
+ medIns1Oid = getOidByName("medicalIns1");
+ medIns2Oid = getOidByName("medicalIns2");
+ emp1 = (IEmployee)pm.getObjectById(emp1Oid);
+ emp2 = (IEmployee)pm.getObjectById(emp2Oid);
+ medIns1 = (IMedicalInsurance)pm.getObjectById(medIns1Oid);
+ medIns2 = (IMedicalInsurance)pm.getObjectById(medIns2Oid);
+ }
+ }
+
+ /**
+ * Test that JdoUserException is thrown if two sides of a relationship
+ * do not refer to each other.
+ */
+ public void testA2BbutNotB2AMapped() {
+ testMethod = "testA2BbutNotB2AMapped";
+ if (isTestToBePerformed) {
+ IEmployee empNew = new FullTimeEmployee(99, "Matthew", "", "Adams",
+ new Date(0L), new Date(10000L), 125000);
+ pm.makePersistent(empNew);
+ emp1.setMedicalInsurance(medIns2);
+ medIns2.setEmployee(empNew);
+ doFlush(testMethod);
+ }
+ }
+
+ /**
+ * Test that JdoUserException is thrown if two sides of a relationship
+ * do not refer to each other.
+ */
+ public void testA2BbutNotB2AMappedBy() {
+ testMethod = "testA2BbutNotB2AMappedBy";
+ if (isTestToBePerformed) {
+ IMedicalInsurance medInsNew = new MedicalInsurance(99,
+ "The American Company", "B");
+ pm.makePersistent(medInsNew);
+ medIns2.setEmployee(emp1);
+ emp1.setMedicalInsurance(medInsNew);
+ doFlush(testMethod);
+ }
+ }
+
+ /**
+ * Test that JdoUserException is thrown setting mapped side
+ * of a one-to-one relationship and setting the other side to null
+ */
+ public void testSetOtherSideToNullMapped() {
+ testMethod = "testSetOtherSideToNullMapped";
+ if (isTestToBePerformed) {
+ emp1.setMedicalInsurance(medIns2);
+ medIns2.setEmployee(null);
+ doFlush(testMethod);
+ }
+ }
+
+ /**
+ * Test that JdoUserException is thrown setting mapped by side
+ * of a one-to-one relationship and setting the other side to null
+ */
+ public void testSetOtherSideToNullMappedBy() {
+ testMethod = "testSetOtherSideToNullMappedBy";
+ if (isTestToBePerformed) {
+ medIns2.setEmployee(emp1);
+ emp1.setMedicalInsurance(null);
+ doFlush(testMethod);
+ }
+ }
+
+ protected void doFlush(String method) {
+ try {
+ pm.flush();
+ fail(ASSERTION_FAILED + testMethod
+ + ": expected JDOUserException on flush!");
+ } catch (JDOUserException jdoe) {
+ // expected exception
+ }
+ pm.currentTransaction().rollback();
+ }
+}
Propchange: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/mapping/RelationshipNegative1To1Test.java
------------------------------------------------------------------------------
svn:eol-style = LF
Added: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/mapping/RelationshipNegative1ToManyTest.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/mapping/RelationshipNegative1ToManyTest.java?rev=573641&view=auto
==============================================================================
--- db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/mapping/RelationshipNegative1ToManyTest.java (added)
+++ db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/mapping/RelationshipNegative1ToManyTest.java Fri Sep 7 10:52:21 2007
@@ -0,0 +1,136 @@
+/*
+ * 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.jdo.tck.mapping;
+
+import java.util.Date;
+import javax.jdo.JDOUserException;
+import org.apache.jdo.tck.pc.company.Department;
+import org.apache.jdo.tck.pc.company.Employee;
+import org.apache.jdo.tck.pc.company.FullTimeEmployee;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+
+/**
+ *<B>Title:</B>RelationshipNegative1ToManyTest
+ *<BR>
+ *<B>Keywords:</B> mapping, managed relationships
+ *<BR>
+ *<B>Assertion ID:</B> A15.3-1
+ *<BR>
+ *<B>Assertion Description: Regardless of which side changes the relationship,
+ * flush (whether done as part of commit or explicitly by the user) will modify
+ * the datastore to reflect the change and will update the memory model
+ * for consistency.</B>
+ */
+
+public class RelationshipNegative1ToManyTest extends AbstractRelationshipTest {
+
+ String testMethod = null;
+ protected String ASSERTION_FAILED =
+ "Assertion A15-3.1 (RelationshipNegative1ToManyTest) failed: ";
+
+ Object emp1Oid = null;
+ Object dept1Oid = null;
+ Object dept2Oid = null;
+ Employee emp1 = null;
+ Department dept1 = null;
+ Department dept2 = null;
+
+ /**
+ * The <code>main</code> is called when the class
+ * is directly executed from the command line.
+ * @param args The arguments passed to the program.
+ */
+ public static void main(String[] args) {
+ BatchTestRunner.run(RelationshipNegative1ToManyTest.class);
+ }
+
+ /**
+ * @see JDO_Test#localSetUp()
+ */
+ protected void localSetUp() {
+ super.localSetUp();
+ if (isTestToBePerformed) {
+ getPM();
+ pm.currentTransaction().begin();
+
+ emp1Oid = getOidByName("emp1");
+ dept1Oid = getOidByName("dept1");
+ dept2Oid = getOidByName("dept2");
+ emp1 = (Employee)pm.getObjectById(emp1Oid);
+ dept1 = (Department)pm.getObjectById(dept1Oid);
+ dept2 = (Department)pm.getObjectById(dept2Oid);
+ }
+ }
+
+ /**
+ * Test that JdoUserException is thrown setting one side
+ * of a one-to-many relationship and deleting the other side
+ */
+ public void testDeleteOtherSide() {
+ testMethod = "testDeleteOtherSide";
+ if (isTestToBePerformed) {
+ dept2.addEmployee(emp1);
+ pm.deletePersistent(emp1);
+ doFlush(testMethod);
+ }
+ }
+
+ /**
+ * adding a related instance (with a single-valued mapped-by relationship
+ * field) to more than one one-to-many collection relationship
+ */
+ public void testAddToMoreThanOne() {
+ testMethod = "testAddToMoreThanOne";
+ if (isTestToBePerformed) {
+ Employee empNew = new FullTimeEmployee(99, "Matthew", "", "Adams",
+ new Date(0L), new Date(10000L), 125000);
+ pm.makePersistent(empNew);
+ dept1.addEmployee(empNew);
+ dept2.addEmployee(empNew);
+ doFlush(testMethod);
+ }
+ }
+
+ /**
+ * adding a related instance to a collection and setting the other side
+ * to a different instance
+ */
+ public void testAInBbutNotB2A() {
+ testMethod = "testAInBbutNotB2A";
+ if (isTestToBePerformed) {
+ Employee empNew = new FullTimeEmployee(99, "Matthew", "", "Adams",
+ new Date(0L), new Date(10000L), 125000);
+ pm.makePersistent(empNew);
+ dept1.addEmployee(empNew);
+ empNew.setDepartment(dept2);
+ doFlush(testMethod);
+ }
+ }
+
+ protected void doFlush(String method) {
+ try {
+ pm.flush();
+ fail(ASSERTION_FAILED + testMethod
+ + ": expected JDOUserException on flush!");
+ } catch (JDOUserException jdoe) {
+ // expected exception
+ }
+ pm.currentTransaction().rollback();
+ }
+}
Propchange: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/mapping/RelationshipNegative1ToManyTest.java
------------------------------------------------------------------------------
svn:eol-style = LF