Index: conf/configurations.list =================================================================== --- conf/configurations.list (revision 566378) +++ conf/configurations.list (working copy) @@ -57,6 +57,8 @@ inheritance2.conf \ inheritance3.conf \ inheritance4.conf \ + relationshipAllRelationships.conf \ + relationshipNoRelationships.conf \ schemaAttributeClass.conf \ schemaAttributeOrm.conf \ schemaAttributePackage.conf \ Index: conf/relationshipAllRelationships.conf =================================================================== --- conf/relationshipAllRelationships.conf (revision 0) +++ conf/relationshipAllRelationships.conf (revision 0) @@ -0,0 +1,25 @@ +# 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. + +jdo.tck.description = Managed relationship tests with standard mapping, \ + basic testdata with all relationships. +jdo.tck.mapping.companyfactory = +jdo.tck.testdata = org/apache/jdo/tck/pc/company/companyAllRelationships.xml +jdo.tck.mapping = 0 +jdo.tck.requiredOptions = +jdo.tck.classes = org.apache.jdo.tck.mapping.Relationship1To1AllRelationships \ + org.apache.jdo.tck.mapping.Relationship1ToManyAllRelationships \ + org.apache.jdo.tck.mapping.RelationshipManyToManyAllRelationships \ + Index: conf/relationshipNoRelationships.conf =================================================================== --- conf/relationshipNoRelationships.conf (revision 0) +++ conf/relationshipNoRelationships.conf (revision 0) @@ -0,0 +1,26 @@ +# 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. + +jdo.tck.description = Managed relationship tests with standard mapping, \ + basic testdata with no relationships. +jdo.tck.mapping.companyfactory = +jdo.tck.testdata = org/apache/jdo/tck/pc/company/companyNoRelationships.xml +jdo.tck.mapping = 0 +jdo.tck.requiredOptions = +jdo.tck.classes = org.apache.jdo.tck.mapping.Relationship1To1NoRelationships \ + org.apache.jdo.tck.mapping.Relationship1ToManyNoRelationships \ + org.apache.jdo.tck.mapping.RelationshipManyToManyNoRelationships \ + org.apache.jdo.tck.mapping.RelationshipNegative1To1Test \ + org.apache.jdo.tck.mapping.RelationshipNegative1ToManyTest \ Index: java/org/apache/jdo/tck/JDO_Test.java =================================================================== --- java/org/apache/jdo/tck/JDO_Test.java (revision 566378) +++ java/org/apache/jdo/tck/JDO_Test.java (working copy) @@ -187,6 +187,9 @@ */ protected static final boolean closePMFAfterEachTest = System.getProperty("jdo.tck.closePMFAfterEachTest", "false").equalsIgnoreCase("true"); + + /** */ + protected final boolean isTestToBePerformed = isTestToBePerformed(); /** The Properties object for the PersistenceManagerFactory. */ protected static Properties PMFPropertiesObject; @@ -1081,6 +1084,15 @@ messages.append(NL); } + /** Appends to error messages. + */ + protected static synchronized void deferredAssertTrue(Boolean test, + String context, String message) { + if (!test) { + appendMessage(context + ": " +message); + } + } + /** * Returns collected error messages, or null if there * are none, and clears the buffer. Index: java/org/apache/jdo/tck/mapping/AbstractRelationshipTest.java =================================================================== --- java/org/apache/jdo/tck/mapping/AbstractRelationshipTest.java (revision 0) +++ java/org/apache/jdo/tck/mapping/AbstractRelationshipTest.java (revision 0) @@ -0,0 +1,86 @@ +/* + * 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.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.pc.company.CompanyFactoryRegistry; +import org.apache.jdo.tck.pc.company.CompanyModelReader; + +/* + * Abstract class for managed relationship tests + */ +public class AbstractRelationshipTest extends JDO_Test { + + /** */ + protected List rootOids; + + /** */ + protected final String inputFilename = System.getProperty("jdo.tck.testdata"); + + protected CompanyModelReader reader = null; + + protected Map oidMap = new HashMap(); + + /** + * @see JDO_Test#localSetUp() + */ + protected void localSetUp() { + if (isTestToBePerformed) { + getPM(); + CompanyFactoryRegistry.registerFactory(pm); + reader = new CompanyModelReader(inputFilename); + addTearDownClass(reader.getTearDownClassesFromFactory()); + // persist test data + pm.currentTransaction().begin(); + List rootList = reader.getRootList(); + pm.makePersistentAll(rootList); + rootOids = new ArrayList(); + for (Iterator i = rootList.iterator(); i.hasNext(); ) { + Object pc = i.next(); + rootOids.add(pm.getObjectId(pc)); + } + // DO THIS + // in xmlBeanFactory String[] getBeanDefinitionNames() + oidMap.put("emp1", pm.getObjectId(reader.getEmployee("emp1"))); + oidMap.put("emp2", pm.getObjectId(reader.getEmployee("emp2"))); + oidMap.put("emp4", pm.getObjectId(reader.getEmployee("emp4"))); + oidMap.put("medicalIns1", + pm.getObjectId(reader.getMedicalInsurance("medicalIns1"))); + oidMap.put("medicalIns2", + pm.getObjectId(reader.getMedicalInsurance("medicalIns2"))); + oidMap.put("dept1", pm.getObjectId(reader.getDepartment("dept1"))); + oidMap.put("dept2", pm.getObjectId(reader.getDepartment("dept2"))); + oidMap.put("proj1", pm.getObjectId(reader.getProject("proj1"))); + oidMap.put("proj2", pm.getObjectId(reader.getProject("proj2"))); + + pm.currentTransaction().commit(); + cleanupPM(); + } + } + + protected Object getOidByName(String name) { + return oidMap.get((Object)name); + } + +} Property changes on: java\org\apache\jdo\tck\mapping\AbstractRelationshipTest.java ___________________________________________________________________ Name: svn:eol-style + LF Index: java/org/apache/jdo/tck/mapping/Relationship1To1AllRelationships.java =================================================================== --- java/org/apache/jdo/tck/mapping/Relationship1To1AllRelationships.java (revision 0) +++ java/org/apache/jdo/tck/mapping/Relationship1To1AllRelationships.java (revision 0) @@ -0,0 +1,419 @@ +/* + * 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 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; + + +/** + *Title:Relationship1To1AllRelationships + *
+ *Keywords: mapping, managed relationships + *
+ *Assertion ID: A15.3-1 + *
+ *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. + */ + +public class Relationship1To1AllRelationships extends AbstractRelationshipTest { + + String testMethod = null; + protected String ASSERTION_FAILED = + "Assertion A15-3.1 (Relationship1To1AllRelationships) failed: "; + + /** + * The main 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(Relationship1To1AllRelationships.class); + } + + Object emp1Oid = null; + Object emp2Oid = null; + Object medIns1Oid = null; + Object medIns2Oid = null; + IEmployee emp1 = null; + IEmployee emp2 = null; + IMedicalInsurance medIns1 = null; + IMedicalInsurance medIns2 = null; + + /** + * @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); + + // Preconditions + assertTrue(ASSERTION_FAILED + testMethod + + ": Test aborted, precondition is false; " + + "expected emp.getMedicalInsurance()to be medicalIns1", + emp1.getMedicalInsurance() == medIns1); + assertTrue(ASSERTION_FAILED + testMethod + + ": Test aborted, precondition is false; " + + "expected ins.getEmployee() to be emp1", + medIns1.getEmployee() == emp1); + assertTrue(ASSERTION_FAILED + testMethod + + ": Test aborted, precondition is false; " + + "expected emp.getMedicalInsurance()to be medicalIns1", + emp2.getMedicalInsurance() == medIns2); + assertTrue(ASSERTION_FAILED + testMethod + + ": Test aborted, precondition is false; " + + "expected ins.getEmployee() to be emp1", + medIns2.getEmployee() == emp2); + } + } + + /** */ + public void testSetToExistingFromMappedSide() { + testMethod = "testSetToExistingFromMappedSide"; + if (isTestToBePerformed) { + + // Set relationship + medIns1.setEmployee(emp2); + pm.flush(); + + // Postcondition + deferredAssertTrue(emp2.getMedicalInsurance() == medIns1, + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "other side of relationship not set on flush"); + deferredAssertTrue(emp1.getMedicalInsurance() == null, + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "previous relationship (emp1) not nulled on flush"); + deferredAssertTrue(medIns2.getEmployee() == null, + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "previous relationship (medIns2) not nulled on flush"); + pm.currentTransaction().commit(); + cleanupPM(); + getPM(); + + pm.currentTransaction().begin(); + emp1 = (IEmployee)pm.getObjectById(emp1Oid); + emp2 = (IEmployee)pm.getObjectById(emp2Oid); + medIns1 = (IMedicalInsurance)pm.getObjectById(medIns1Oid); + medIns2 = (IMedicalInsurance)pm.getObjectById(medIns2Oid); + deferredAssertTrue(emp2.getMedicalInsurance() == medIns1, + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "other side of relationship not set in new pm"); + deferredAssertTrue(emp1.getMedicalInsurance() == null, + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "previous relationship (emp1) not nulled in new pm"); + deferredAssertTrue(medIns2.getEmployee() == null, + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "previous relationship (medIns2) not nulled in new pm"); + pm.currentTransaction().commit(); + + failOnError(); + } + } + + /** */ + public void testSetToExistingFromMappedBySide() { + testMethod = "testSetToExistingFromMappedBySide"; + if (isTestToBePerformed) { + + // Set relationship + emp1.setMedicalInsurance(medIns2); + pm.flush(); + + // Postcondition + deferredAssertTrue(medIns2.getEmployee() == emp1, + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "other side of relationship not set on flush."); + deferredAssertTrue(medIns1.getEmployee() == null, + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "previous relationship (medIns1) not nulled on flush."); + deferredAssertTrue(emp2.getMedicalInsurance() == null, + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "previous relationship (emp2) not nulled on flush"); + pm.currentTransaction().commit(); + cleanupPM(); + getPM(); + + pm.currentTransaction().begin(); + emp1 = (IEmployee)pm.getObjectById(emp1Oid); + emp2 = (IEmployee)pm.getObjectById(emp2Oid); + medIns1 = (IMedicalInsurance)pm.getObjectById(medIns1Oid); + medIns2 = (IMedicalInsurance)pm.getObjectById(medIns2Oid); + deferredAssertTrue(medIns2.getEmployee() == emp1, + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "other side of relationship not set in new pm."); + deferredAssertTrue(medIns1.getEmployee() == null, + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "previous relationship (medIns1) not nulled in new pm."); + deferredAssertTrue(emp2.getMedicalInsurance() == null, + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "previous relationship (emp2) not nulled in new pm."); + pm.currentTransaction().commit(); + + failOnError(); + } + } + + /** */ + public void testSetToNullFromMappedSide() { + testMethod = "testSetToNullFromMappedSide"; + if (isTestToBePerformed) { + + // Set relationship + medIns1.setEmployee(null); + pm.flush(); + + // Postcondition + deferredAssertTrue(emp1.getMedicalInsurance() == null, + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "other side of relationship not set on flush"); + pm.currentTransaction().commit(); + cleanupPM(); + getPM(); + + pm.currentTransaction().begin(); + emp1 = (IEmployee)pm.getObjectById(emp1Oid); + deferredAssertTrue( + emp1.getMedicalInsurance() == null, + ASSERTION_FAILED + testMethod, + "In new transaction, postcondition is false; " + + "other side of relationship is not set."); + pm.currentTransaction().commit(); + + failOnError(); + } + } + + /** */ + public void testSetToNullFromMappedBySide() { + testMethod = "testSetToNullFromMappedBySide"; + if (isTestToBePerformed) { + + // Set relationship + emp1.setMedicalInsurance(null); + pm.flush(); + + // Postcondition + deferredAssertTrue(medIns1.getEmployee() == null, + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "other side of relationship not set on flush"); + pm.currentTransaction().commit(); + cleanupPM(); + getPM(); + + pm.currentTransaction().begin(); + //emp1 = (IEmployee)pm.getObjectById(emp1Oid); + medIns1 = (IMedicalInsurance)pm.getObjectById(medIns1Oid); + deferredAssertTrue( + medIns1.getEmployee() == null, + ASSERTION_FAILED + testMethod, + "In new transaction, postcondition is false; " + + "other side of relationship is not set."); + pm.currentTransaction().commit(); + + failOnError(); + } + } + + /** */ + public void testSetToNewFromMappedSide() { + testMethod = "testSetToNewFromMappedSide"; + if (isTestToBePerformed) { + + // Set relationship + IEmployee empNew = new FullTimeEmployee(99, "Matthew", "", "Adams", + new Date(0L), new Date(10000L), 125000); + pm.makePersistent(empNew); + medIns1.setEmployee(empNew); + Object empNewOid = pm.getObjectId((Object)empNew); + pm.flush(); + + assertFalse(testMethod + ": Test aborted, precondition is false; " + + "expected empNewOid to be non-null", empNewOid == null); + + // Postcondition + deferredAssertTrue(empNew.getMedicalInsurance() == medIns1, + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "other side of relationship not set on flush"); + deferredAssertTrue(emp1.getMedicalInsurance() == null, + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "previous relationship (emp1) not nulled on flush"); + + pm.currentTransaction().commit(); + cleanupPM(); + getPM(); + + pm.currentTransaction().begin(); + emp1 = (IEmployee)pm.getObjectById(emp1Oid); + empNew = (IEmployee)pm.getObjectById(empNewOid); + medIns1 = (IMedicalInsurance)pm.getObjectById(medIns1Oid); + deferredAssertTrue(empNew.getMedicalInsurance() == medIns1, + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "other side of relationship not set in new pm"); + deferredAssertTrue(emp1.getMedicalInsurance() == null, + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "previous relationship (emp1) not nulled in new pm"); + pm.currentTransaction().commit(); + + failOnError(); + } + } + + /** */ + public void testSetToNewFromMappedBySide() { + testMethod = "testSetToNewFromMappedBySide"; + if (isTestToBePerformed) { + + // Set relationship + IMedicalInsurance medInsNew = new MedicalInsurance(99L, + "Ameriblast", "B"); + pm.makePersistent(medInsNew); + emp1.setMedicalInsurance(medInsNew); + Object medInsNewOid = pm.getObjectId((Object)medInsNew); + pm.flush(); + + assertFalse(testMethod + ": Test aborted, precondition is false; " + + "expected medInsNewOid to be non-null", medInsNewOid == null); + + // Postcondition + deferredAssertTrue(medInsNew.getEmployee() == emp1, + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "other side of relationship not set on flush."); + deferredAssertTrue(medIns1.getEmployee() == null, + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "previous relationship (medIns1) not nulled on flush."); + + pm.currentTransaction().commit(); + cleanupPM(); + getPM(); + + pm.currentTransaction().begin(); + emp1 = (IEmployee)pm.getObjectById(emp1Oid); + medInsNew = (IMedicalInsurance)pm.getObjectById(medInsNewOid); + medIns1 = (IMedicalInsurance)pm.getObjectById(medIns1Oid); + deferredAssertTrue(medInsNew.getEmployee() == emp1, + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "other side of relationship not set in new pm"); + deferredAssertTrue(medIns1.getEmployee() == null, + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "previous relationship (medIns1) not nulled in new pm"); + pm.currentTransaction().commit(); + + failOnError(); + } + } + /** */ + public void testDeleteFromMappedSide() { + testMethod = "testDeleteFromMappedSide"; + if (isTestToBePerformed) { + // Set relationship + pm.deletePersistent(medIns1); + pm.flush(); + + // Postcondition + deferredAssertTrue(emp1.getMedicalInsurance() == null, + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "other side of relationship not set on flush"); + pm.currentTransaction().commit(); + cleanupPM(); + getPM(); + + pm.currentTransaction().begin(); + emp1 = (IEmployee)pm.getObjectById(emp1Oid); + deferredAssertTrue( + emp1.getMedicalInsurance() == null, + ASSERTION_FAILED + testMethod, + "In new transaction, postcondition is false; " + + "other side of relationship is not set."); + pm.currentTransaction().commit(); + + failOnError(); + } + } + + /** */ + public void testDeleteFromMappedBySide() { + testMethod = "testDeleteFromMappedBySide"; + if (isTestToBePerformed) { + // Set relationship + pm.deletePersistent(emp1); + pm.flush(); + + // Postcondition + deferredAssertTrue(medIns1.getEmployee() == null, + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "other side of relationship not set on flush"); + pm.currentTransaction().commit(); + cleanupPM(); + getPM(); + + pm.currentTransaction().begin(); + medIns1 = (IMedicalInsurance)pm.getObjectById(medIns1Oid); + deferredAssertTrue( + medIns1.getEmployee() == null, + ASSERTION_FAILED + testMethod, + "In new transaction, postcondition is false; " + + "other side of relationship is not set."); + pm.currentTransaction().commit(); + + failOnError(); + } + } + +} Property changes on: java\org\apache\jdo\tck\mapping\Relationship1To1AllRelationships.java ___________________________________________________________________ Name: svn:eol-style + LF Index: java/org/apache/jdo/tck/mapping/Relationship1To1NoRelationships.java =================================================================== --- java/org/apache/jdo/tck/mapping/Relationship1To1NoRelationships.java (revision 0) +++ java/org/apache/jdo/tck/mapping/Relationship1To1NoRelationships.java (revision 0) @@ -0,0 +1,227 @@ +/* + * 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 org.apache.jdo.tck.pc.company.Employee; +import org.apache.jdo.tck.pc.company.FullTimeEmployee; +import org.apache.jdo.tck.pc.company.MedicalInsurance; +import org.apache.jdo.tck.util.BatchTestRunner; + + +/** + *Title:Relationship1To1NoRelationships + *
+ *Keywords: mapping, managed relationships + *
+ *Assertion ID: A15.3-1 + *
+ *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. + */ + +public class Relationship1To1NoRelationships extends AbstractRelationshipTest { + + String testMethod = null; + protected String ASSERTION_FAILED = + "Assertion A15-3.1 (Relationship1To1NoRelationships) failed: "; + + Object emp1Oid = null; + Object emp2Oid = null; + Object medIns1Oid = null; + Object medIns2Oid = null; + Employee emp1 = null; + Employee emp2 = null; + MedicalInsurance medIns1 = null; + MedicalInsurance medIns2 = null; + + /** + * The main 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(Relationship1To1NoRelationships.class); + } + + /** + * @see JDO_Test#localSetUp() + */ + protected void localSetUp() { + super.localSetUp(); + if (isTestToBePerformed) { + getPM(); + pm.currentTransaction().begin(); + + emp1Oid = getOidByName("emp1"); + medIns1Oid = getOidByName("medicalIns1"); + emp1 = (Employee)pm.getObjectById(emp1Oid); + medIns1 = (MedicalInsurance)pm.getObjectById(medIns1Oid); + + // Preconditions + assertTrue(ASSERTION_FAILED + + ": Test aborted, precondition is false; " + + "expected emp.getMedicalInsurance()to be null", + emp1.getMedicalInsurance() == null); + assertTrue(ASSERTION_FAILED + + ": Test aborted, precondition is false; " + + "expected ins.getEmployee() to be null", + medIns1.getEmployee() == null); + } + } + + /** */ + public void testSetToExistingFromMappedSide() { + testMethod = "testSetToExistingFromMappedSide"; + if (isTestToBePerformed) { + + // Set relationship + medIns1.setEmployee(emp1); + pm.flush(); + + // Postcondition + deferredAssertTrue(emp1.getMedicalInsurance() == medIns1, + 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); + medIns1 = (MedicalInsurance)pm.getObjectById(medIns1Oid); + deferredAssertTrue( + emp1.getMedicalInsurance() == medIns1, + ASSERTION_FAILED + testMethod, + "In new transaction, postcondition is false; " + + "other side of relationship is not set."); + pm.currentTransaction().commit(); + + failOnError(); + } + } + + /** */ + public void testSetToExistingFromMappedBySide() { + testMethod = "testSetToExistingFromMappedBySide"; + if (isTestToBePerformed) { + + // Set relationship + emp1.setMedicalInsurance(medIns1); + pm.flush(); + + // Postcondition + deferredAssertTrue(medIns1.getEmployee() == 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); + medIns1 = (MedicalInsurance)pm.getObjectById(medIns1Oid); + deferredAssertTrue( + medIns1.getEmployee() == emp1, + ASSERTION_FAILED + testMethod, + "In new transaction, postcondition is false; " + + "other side of relationship is not set."); + pm.currentTransaction().commit(); + + failOnError(); + } + } + + /** */ + public void testSetToNewFromMappedSide() { + testMethod = "testSetToNewFromMappedSide"; + if (isTestToBePerformed) { + + // Set relationship + Employee empNew = new FullTimeEmployee(99, "Matthew", "", "Adams", + new Date(0L), new Date(10000L), 125000); + pm.makePersistent(empNew); + medIns1.setEmployee(empNew); + Object empNewOid = pm.getObjectId((Object)empNew); + pm.flush(); + + // Postcondition + deferredAssertTrue(empNew.getMedicalInsurance() == medIns1, + 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); + empNew = (Employee)pm.getObjectById(empNewOid); + medIns1 = (MedicalInsurance)pm.getObjectById(medIns1Oid); + deferredAssertTrue(empNew.getMedicalInsurance() == medIns1, + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "other side of relationship not set in new pm"); + pm.currentTransaction().commit(); + + failOnError(); + } + } + + /** */ + public void testSetToNewFromMappedBySide() { + testMethod = "testSetToNewFromMappedBySide"; + if (isTestToBePerformed) { + + // Set relationship + MedicalInsurance medInsNew = new MedicalInsurance(99L, + "Ameriblast", "B"); + pm.makePersistent(medInsNew); + emp1.setMedicalInsurance(medInsNew); + Object medInsNewOid = pm.getObjectId((Object)medInsNew); + pm.flush(); + + // Postcondition + deferredAssertTrue(medInsNew.getEmployee() == 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); + medInsNew = (MedicalInsurance)pm.getObjectById(medInsNewOid); + medIns1 = (MedicalInsurance)pm.getObjectById(medIns1Oid); + deferredAssertTrue(medInsNew.getEmployee() == emp1, + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "other side of relationship not set in new pm"); + pm.currentTransaction().commit(); + + failOnError(); + } + } +} Property changes on: java\org\apache\jdo\tck\mapping\Relationship1To1NoRelationships.java ___________________________________________________________________ Name: svn:eol-style + LF Index: java/org/apache/jdo/tck/mapping/Relationship1ToManyAllRelationships.java =================================================================== --- java/org/apache/jdo/tck/mapping/Relationship1ToManyAllRelationships.java (revision 0) +++ java/org/apache/jdo/tck/mapping/Relationship1ToManyAllRelationships.java (revision 0) @@ -0,0 +1,464 @@ +/* + * 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 java.util.HashSet; +import java.util.Set; +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.pc.company.IDepartment; +import org.apache.jdo.tck.pc.company.IEmployee; +import org.apache.jdo.tck.util.BatchTestRunner; + + +/** + *Title:Relationship1ToManyAllRelationships + *
+ *Keywords: mapping, managed relationships + *
+ *Assertion ID: A15.3-1 + *
+ *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. + */ + +public class Relationship1ToManyAllRelationships extends AbstractRelationshipTest { + + String testMethod = null; + protected String ASSERTION_FAILED = + "Assertion A15-3.1 (Relationship1ToManyAllRelationships) failed: "; + + Object emp1Oid = null; + Object dept1Oid = null; + Object dept2Oid = null; + Employee emp1 = null; + Department dept1 = null; + Department dept2 = null; + + /** + * The main 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(Relationship1ToManyAllRelationships.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); + + // Preconditions + assertTrue(ASSERTION_FAILED + + ": Test aborted, precondition is false; " + + "expected emp.getDepartment()to be dept1", + emp1.getDepartment() == dept1); + assertTrue(ASSERTION_FAILED + + ": Test aborted, precondition is false; " + + "expected dept.getEmployees() to contain emp1", + dept1.getEmployees().contains(emp1)); + } + } + + /** */ + public void testSetToExistingFromMappedSide() { + testMethod = "testSetToExistingFromMappedSide"; + if (isTestToBePerformed) { + + // Set relationship + emp1.setDepartment(dept2); + pm.flush(); + + // Postcondition + deferredAssertTrue(dept2.getEmployees().contains(emp1), + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "other side of relationship not set on flush"); + deferredAssertTrue(!dept1.getEmployees().contains(emp1), + ASSERTION_FAILED + testMethod, + "Postcondition is false; reference emp1 not removed " + + "from previous relationship (dept1.employees)"); + + pm.currentTransaction().commit(); + cleanupPM(); + getPM(); + + pm.currentTransaction().begin(); + emp1 = (Employee)pm.getObjectById(emp1Oid); + dept1 = (Department)pm.getObjectById(dept1Oid); + dept2 = (Department)pm.getObjectById(dept2Oid); + deferredAssertTrue(dept2.getEmployees().contains(emp1), + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "other side of relationship not set in new pm"); + deferredAssertTrue(!dept1.getEmployees().contains(emp1), + ASSERTION_FAILED + testMethod, + "Postcondition is false; reference emp1 not removed " + + "from previous relationship (dept1.employees)"); + pm.currentTransaction().commit(); + + failOnError(); + } + } + + + /** */ + public void testAddExistingFromMappedbySide() { + testMethod = "testAddExistingFromMappedbySide"; + if (isTestToBePerformed) { + + // Set relationship + Object emp4Oid = getOidByName("emp4"); + Employee emp4 = (Employee)pm.getObjectById(emp4Oid); + Object dept2Oid = getOidByName("dept2"); + Department dept2 = (Department)pm.getObjectById(dept2Oid); + + dept1.addEmployee(emp4); + pm.flush(); + + // Postcondition + deferredAssertTrue(emp4.getDepartment() == dept1, + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "other side of relationship not set on flush"); + deferredAssertTrue(!dept2.getEmployees().contains(emp4), + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "previous relationship not unset on flush"); + pm.currentTransaction().commit(); + cleanupPM(); + getPM(); + + pm.currentTransaction().begin(); + emp4 = (Employee)pm.getObjectById(emp4Oid); + dept1 = (Department)pm.getObjectById(dept1Oid); + dept2 = (Department)pm.getObjectById(dept2Oid); + deferredAssertTrue(emp4.getDepartment() == dept1, + ASSERTION_FAILED + testMethod, + "In new transaction, postcondition is false; " + + "other side of relationship is not set."); + deferredAssertTrue(!dept2.getEmployees().contains(emp4), + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "previous relationship not unset on flush"); + pm.currentTransaction().commit(); + + failOnError(); + } + } + + /** */ + public void testReplaceFromMappedbySide() { + testMethod = "testReplaceFromMappedbySide"; + if (isTestToBePerformed) { + + // Set relationship + Object emp4Oid = getOidByName("emp4"); + Employee emp4 = (Employee)pm.getObjectById(emp4Oid); + Object dept2Oid = getOidByName("dept2"); + Department dept2 = (Department)pm.getObjectById(dept2Oid); + + Set emps = new HashSet(); + emps.add(emp4); + dept1.setEmployees(emps); + pm.flush(); + + // Postcondition + deferredAssertTrue(emp4.getDepartment() == dept1, + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "other side of relationship not set on flush"); + deferredAssertTrue(!dept2.getEmployees().contains(emp4), + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "previous relationship not unset on flush"); + pm.currentTransaction().commit(); + cleanupPM(); + getPM(); + + pm.currentTransaction().begin(); + emp4 = (Employee)pm.getObjectById(emp4Oid); + dept1 = (Department)pm.getObjectById(dept1Oid); + dept2 = (Department)pm.getObjectById(dept2Oid); + deferredAssertTrue(emp4.getDepartment() == dept1, + ASSERTION_FAILED + testMethod, + "In new transaction, postcondition is false; " + + "other side of relationship is not set."); + deferredAssertTrue(!dept2.getEmployees().contains(emp4), + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "previous relationship not unset on flush"); + pm.currentTransaction().commit(); + + failOnError(); + } + } + + /** */ + public void testAddNewFromMappedbySide() { + testMethod = "testAddNewFromMappedbySide"; + if (isTestToBePerformed) { + + // Set relationship + Employee empNew = new FullTimeEmployee(101, "Jenny", "Merriwether", + "White", new Date(500L), new Date(10000L), 135000); + pm.makePersistent(empNew); + Object empNewOid = pm.getObjectId((Object)empNew); + + dept1.addEmployee(empNew); + pm.flush(); + + // Postcondition + deferredAssertTrue(empNew.getDepartment() == dept1, + 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); + dept1 = (Department)pm.getObjectById(dept1Oid); + deferredAssertTrue(empNew.getDepartment() == dept1, + ASSERTION_FAILED + testMethod, + "In new transaction, postcondition is false; " + + "other side of relationship is not set."); + pm.currentTransaction().commit(); + + failOnError(); + } + } + + /** */ + public void testSetToNullFromMappedSide() { + testMethod = "testSetToNullFromMappedSide"; + if (isTestToBePerformed) { + // Set relationship + emp1.setDepartment(null); + pm.flush(); + + // Postcondition + deferredAssertTrue(!dept1.getEmployees().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); + dept1 = (Department)pm.getObjectById(dept1Oid); + deferredAssertTrue( + !dept1.getEmployees().contains(emp1), + ASSERTION_FAILED + testMethod, + "In new transaction, postcondition is false; " + + "other side of relationship is not set."); + pm.currentTransaction().commit(); + + failOnError(); + } + } + + /** */ + public void testSetToNullFromMappedbySide() { + testMethod = "testSetToNullFromMappedbySide"; + if (isTestToBePerformed) { + + // Set relationship + dept1.setEmployees(null); + pm.flush(); + + // Postcondition + deferredAssertTrue(emp1.getDepartment() == null, + 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); + deferredAssertTrue( + emp1.getDepartment() == null, + ASSERTION_FAILED + testMethod, + "In new transaction, postcondition is false; " + + "other side of relationship is not set."); + pm.currentTransaction().commit(); + + failOnError(); + } + } + + /** */ + public void testSetToNewFromMappedSide() { + testMethod = "testSetToNewFromMappedSide"; + if (isTestToBePerformed) { + + // Set relationship + IDepartment deptNew = new Department(99L, "The New Department"); + pm.makePersistent(deptNew); + emp1.setDepartment(deptNew); + Object deptNewOid = pm.getObjectId((Object)deptNew); + pm.flush(); + + assertFalse(testMethod + ": Test aborted, precondition is false; " + + "expected deptNewOid to be non-null", deptNewOid == null); + + // Postcondition + deferredAssertTrue(deptNew.getEmployees().contains(emp1), + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "other side of relationship not set on flush"); + deferredAssertTrue(!dept1.getEmployees().contains(emp1), + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "previous relationship (dept1) not nulled on flush"); + + pm.currentTransaction().commit(); + cleanupPM(); + getPM(); + + pm.currentTransaction().begin(); + emp1 = (Employee)pm.getObjectById(emp1Oid); + deptNew = (Department)pm.getObjectById(deptNewOid); + dept1 = (Department)pm.getObjectById(dept1Oid); + deferredAssertTrue(deptNew.getEmployees().contains(emp1), + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "other side of relationship not set in new pm"); + deferredAssertTrue(!dept1.getEmployees().contains(emp1), + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "previous relationship (dept1) not nulled in new pm"); + pm.currentTransaction().commit(); + + failOnError(); + } + } + + /** */ + public void testRemoveFromMappedbySide() { + testMethod = "testRemoveFromMappedbySide"; + if (isTestToBePerformed) { + + // Set relationship + dept1.removeEmployee(emp1); + pm.flush(); + + // Postcondition + deferredAssertTrue(emp1.getDepartment() == null, + 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); + deferredAssertTrue( + emp1.getDepartment() == null, + ASSERTION_FAILED + testMethod, + "In new transaction, postcondition is false; " + + "other side of relationship is not set."); + pm.currentTransaction().commit(); + + failOnError(); + } + } + + /** */ + public void testDeleteFromMappedSide() { + testMethod = "testDeleteFromMappedSide"; + if (isTestToBePerformed) { + // Set relationship + pm.deletePersistent(emp1); + pm.flush(); + + // Postcondition + deferredAssertTrue(!dept1.getEmployees().contains(emp1), + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "other side of relationship not set on flush"); + pm.currentTransaction().commit(); + cleanupPM(); + getPM(); + + pm.currentTransaction().begin(); + dept1 = (Department)pm.getObjectById(dept1Oid); + deferredAssertTrue( + !dept1.getEmployees().contains(emp1), + ASSERTION_FAILED + testMethod, + "In new transaction, postcondition is false; " + + "other side of relationship is not set."); + pm.currentTransaction().commit(); + + failOnError(); + } + } + + /** */ + public void testDeleteFromMappedbySide() { + testMethod = "testDeleteFromMappedbySide"; + if (isTestToBePerformed) { + + // Set relationship + pm.deletePersistent(dept1); + pm.flush(); + + // Postcondition + deferredAssertTrue(emp1.getDepartment() == null, + 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); + deferredAssertTrue( + emp1.getDepartment() == null, + ASSERTION_FAILED + testMethod, + "In new transaction, postcondition is false; " + + "other side of relationship is not set."); + pm.currentTransaction().commit(); + + failOnError(); + } + } +} Property changes on: java\org\apache\jdo\tck\mapping\Relationship1ToManyAllRelationships.java ___________________________________________________________________ Name: svn:eol-style + LF Index: java/org/apache/jdo/tck/mapping/Relationship1ToManyNoRelationships.java =================================================================== --- java/org/apache/jdo/tck/mapping/Relationship1ToManyNoRelationships.java (revision 0) +++ java/org/apache/jdo/tck/mapping/Relationship1ToManyNoRelationships.java (revision 0) @@ -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.util.Date; +import java.util.HashSet; +import java.util.Set; +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; + + +/** + *Title:Relationship1ToManyNoRelationships + *
+ *Keywords: mapping, managed relationships + *
+ *Assertion ID: A15.3-1 + *
+ *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. + */ + +public class Relationship1ToManyNoRelationships extends AbstractRelationshipTest { + + String testMethod = null; + protected String ASSERTION_FAILED = + "Assertion A15-3.1 (Relationship1ToManyNoRelationships) failed: "; + + Object emp1Oid = null; + Object dept1Oid = null; + Object dept2Oid = null; + Employee emp1 = null; + Department dept1 = null; + Department dept2 = null; + + /** + * The main 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(Relationship1ToManyNoRelationships.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); + + // Preconditions + assertTrue(ASSERTION_FAILED + + ": Test aborted, precondition is false; " + + "expected emp.getDepartment()to be dept1", + emp1.getDepartment() == dept1); + assertTrue(ASSERTION_FAILED + testMethod + + ": Test aborted, precondition is false; " + + "expected dept.getEmployees() to contain emp1", + dept1.getEmployees().contains(emp1)); + } + } + + /** */ + public void testSetToExistingFromMappedSide() { + testMethod = "testSetToExistingFromMappedSide"; + if (isTestToBePerformed) { + + // Set relationship + emp1.setDepartment(dept1); + pm.flush(); + + // Postcondition + deferredAssertTrue(dept1.getEmployees().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); + dept1 = (Department)pm.getObjectById(dept1Oid); + deferredAssertTrue( + dept1.getEmployees().contains(emp1), + ASSERTION_FAILED + testMethod, + "In new transaction, postcondition is false; " + + "other side of relationship is not set."); + pm.currentTransaction().commit(); + + failOnError(); + } + } + + /** */ + public void testAddExistingFromMappedbySide() { + testMethod = "testSetToExistingFromMappedbySide"; + if (isTestToBePerformed) { + + // Set relationship + Set emps = new HashSet(); + emps.add(emp1); + dept1.setEmployees(emps); + pm.flush(); + + // Postcondition + deferredAssertTrue(emp1.getDepartment() == dept1, + 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); + dept1 = (Department)pm.getObjectById(dept1Oid); + deferredAssertTrue( + emp1.getDepartment() == dept1, + ASSERTION_FAILED + testMethod, + "In new transaction, postcondition is false; " + + "other side of relationship is not set."); + pm.currentTransaction().commit(); + + failOnError(); + } + } + + /** */ + public void testSetToNewFromMappedSide() { + testMethod = "testSetToNewFromMappedSide"; + if (isTestToBePerformed) { + + // Set relationship + Department deptNew = new Department(99L, "The New Department"); + emp1.setDepartment(deptNew); + pm.makePersistent(deptNew); + Object deptNewOid = pm.getObjectId((Object)deptNew); + pm.flush(); + + assertFalse(testMethod + ": Test aborted, precondition is false; " + + "expected deptNewOid to be non-null", deptNewOid == null); + + // Postcondition + deferredAssertTrue(deptNew.getEmployees().contains(emp1), + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "other side of relationship not set on flush"); + deferredAssertTrue(!dept1.getEmployees().contains(emp1), + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "previous relationship (dept1) not nulled on flush"); + + pm.currentTransaction().commit(); + cleanupPM(); + getPM(); + + pm.currentTransaction().begin(); + emp1 = (Employee)pm.getObjectById(emp1Oid); + deptNew = (Department)pm.getObjectById(deptNewOid); + dept1 = (Department)pm.getObjectById(dept1Oid); + deferredAssertTrue(deptNew.getEmployees().contains(emp1), + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "other side of relationship not set in new pm"); + deferredAssertTrue(!dept1.getEmployees().contains(emp1), + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "previous relationship (dept1) not nulled in new pm"); + pm.currentTransaction().commit(); + + failOnError(); + } + } + + /** */ + public void testSetToNewFromMappedbySide() { + testMethod = "testSetToNewFromMappedbySide"; + if (isTestToBePerformed) { + + // Set relationship + Set emps = new HashSet(); + Employee empNew = new FullTimeEmployee(101, "Jenny", "Merriwether", + "White", new Date(500L), new Date(10000L), 135000); + pm.makePersistent(empNew); + emps.add(empNew); + dept1.setEmployees(emps); + Object empNewOid = pm.getObjectId((Object)empNew); + pm.flush(); + + // Postcondition + deferredAssertTrue(empNew.getDepartment() == dept1, + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "other side of relationship not set on flush"); + deferredAssertTrue(emp1.getDepartment() == null, + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "previous relationship not nulled on flush"); + pm.currentTransaction().commit(); + cleanupPM(); + getPM(); + + pm.currentTransaction().begin(); + empNew = (Employee)pm.getObjectById(empNewOid); + emp1 = (Employee)pm.getObjectById(emp1Oid); + dept1 = (Department)pm.getObjectById(dept1Oid); + deferredAssertTrue(empNew.getDepartment() == dept1, + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "other side of relationship not set in new pm"); + deferredAssertTrue(emp1.getDepartment() == null, + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "previous relationship not nulled in new pm"); + pm.currentTransaction().commit(); + + failOnError(); + } + } +} Property changes on: java\org\apache\jdo\tck\mapping\Relationship1ToManyNoRelationships.java ___________________________________________________________________ Name: svn:eol-style + LF Index: java/org/apache/jdo/tck/mapping/RelationshipManyToManyAllRelationships.java =================================================================== --- java/org/apache/jdo/tck/mapping/RelationshipManyToManyAllRelationships.java (revision 0) +++ java/org/apache/jdo/tck/mapping/RelationshipManyToManyAllRelationships.java (revision 0) @@ -0,0 +1,497 @@ +/* + * 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.IEmployee; +import org.apache.jdo.tck.pc.company.IProject; +import org.apache.jdo.tck.pc.company.Project; +import org.apache.jdo.tck.util.BatchTestRunner; + + +/** + *Title:RelationshipManyToManyAllRelationships + *
+ *Keywords: mapping, managed relationships + *
+ *Assertion ID: A15.3-1 + *
+ *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. + */ + +public class RelationshipManyToManyAllRelationships + extends AbstractRelationshipTest { + + String testMethod = null; + protected String ASSERTION_FAILED = + "Assertion A15-3.1 (RelationshipManyToManyAllRelationships) failed: "; + + Object emp1Oid = null; + Object proj1Oid = null; + Employee emp1 = null; + Project proj1 = null; + + /** + * The main 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(RelationshipManyToManyAllRelationships.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 contain proj1", + emp1.getProjects().contains(proj1)); + assertTrue(testMethod + + ": Test aborted, precondition is false; " + + "expected proj.getMembers() to contain emp1", + proj1.getMembers().contains(emp1)); + } + } + + /** */ + public void testSetToNullFromMappedSide() { + testMethod = "testSetToNullFromMappedSide"; + if (isTestToBePerformed) { + + // Set relationship + proj1.setMembers(null); + pm.flush(); + + // Postcondition + deferredAssertTrue(!emp1.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(); + emp1 = (Employee)pm.getObjectById(emp1Oid); + proj1 = (Project)pm.getObjectById(proj1Oid); + deferredAssertTrue( + !emp1.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 testSetToNullFromMappedbySide() { + testMethod = "testSetToNullFromMappedbySide"; + if (isTestToBePerformed) { + // Set relationship + emp1.setProjects(null); + pm.flush(); + + // Postcondition + deferredAssertTrue(!proj1.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); + proj1 = (Project)pm.getObjectById(proj1Oid); + deferredAssertTrue( + !proj1.getMembers().contains(emp1), + 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 + IEmployee empNew = new FullTimeEmployee(100, "Jerry", "Valentine", + "Brown", new Date(500L), new Date(10000L), 125000); + pm.makePersistent(empNew); + Set members = new HashSet(); + members.add(empNew); + proj1.setMembers(members); + Object empNewOid = pm.getObjectId((Object)empNew); + pm.flush(); + + // 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 = (IEmployee)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 + IProject projNew = new Project(99L, "Skunkworks", + new BigDecimal(10000.35)); + pm.makePersistent(projNew); + Set projects = new HashSet(); + projects.add(projNew); + emp1.setProjects(projects); + Object projNewOid = pm.getObjectId((Object)projNew); + pm.flush(); + + // 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(); + } + } + + /** */ + public void testAddNewFromMappedSide() { + testMethod = "testAddNewFromMappedSide"; + if (isTestToBePerformed) { + + // Set relationship + Employee empNew = new FullTimeEmployee(100, "Jerry", "Valentine", + "Brown", new Date(500L), new Date(10000L), 125000); + pm.makePersistent(empNew); + proj1.addMember(empNew); + Object empNewOid = pm.getObjectId((Object)empNew); + pm.flush(); + + // 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 testAddNewFromMappedbySide() { + testMethod = "testAddNewFromMappedbySide"; + if (isTestToBePerformed) { + + // Set relationship + Project projNew = new Project(99L, "Skunkworks", + new BigDecimal(10000.35)); + pm.makePersistent(projNew); + emp1.addProject(projNew); + Object projNewOid = pm.getObjectId((Object)projNew); + pm.flush(); + + // 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(); + } + } + /** */ + public void testAddExistingFromMappedSide() { + testMethod = "testAddExistingFromMappedSide"; + if (isTestToBePerformed) { + + // Set relationship + Object emp4Oid = getOidByName("emp4"); + Employee emp4 = (Employee)pm.getObjectById(emp4Oid); + proj1.addMember(emp4); + 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); + emp1 = (Employee)pm.getObjectById(emp1Oid); + proj1 = (Project)pm.getObjectById(proj1Oid); + deferredAssertTrue(emp4.getProjects().contains(proj1), + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "other side of relationship not set in new pm"); + pm.currentTransaction().commit(); + + failOnError(); + } + } + + /** */ + public void testAddExistingFromMappedbySide() { + testMethod = "testAddExistingFromMappedbySide"; + if (isTestToBePerformed) { + + // Set relationship + Object proj2Oid = getOidByName("proj2"); + Project proj2 = (Project)pm.getObjectById(proj2Oid); + emp1.addProject(proj2); + pm.flush(); + + // Postcondition + deferredAssertTrue(proj2.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); + proj2 = (Project)pm.getObjectById(proj2Oid); + proj1 = (Project)pm.getObjectById(proj1Oid); + deferredAssertTrue(proj2.getMembers().contains(emp1), + ASSERTION_FAILED + testMethod, + "Postcondition is false; " + + "other side of relationship not set in new pm"); + pm.currentTransaction().commit(); + + failOnError(); + } + } + + /** */ + public void testRemoveFromMappedSide() { + testMethod = "testRemoveFromMappedSide"; + if (isTestToBePerformed) { + + // Set relationship + proj1.removeMember(emp1); + pm.flush(); + + // Postcondition + deferredAssertTrue(!emp1.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(); + emp1 = (Employee)pm.getObjectById(emp1Oid); + proj1 = (Project)pm.getObjectById(proj1Oid); + deferredAssertTrue( + !emp1.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 testRemoveFromMappedbySide() { + testMethod = "testRemoveFromMappedbySide"; + if (isTestToBePerformed) { + + // Set relationship + emp1.removeProject(proj1); + pm.flush(); + + // Postcondition + deferredAssertTrue(!proj1.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); + proj1 = (Project)pm.getObjectById(proj1Oid); + deferredAssertTrue( + !proj1.getMembers().contains(emp1), + ASSERTION_FAILED + testMethod, + "In new transaction, postcondition is false; " + + "other side of relationship is not set."); + pm.currentTransaction().commit(); + + failOnError(); + } + } + /** */ + public void testDeleteFromMappedSide() { + testMethod = "testDeleteFromMappedSide"; + if (isTestToBePerformed) { + // Set relationship + pm.deletePersistent(proj1); + pm.flush(); + + // Postcondition + deferredAssertTrue(!emp1.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(); + emp1 = (Employee)pm.getObjectById(emp1Oid); + deferredAssertTrue( + !emp1.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 testDeleteFromMappedbySide() { + testMethod = "testDeleteFromMappedbySide"; + if (isTestToBePerformed) { + + // Set relationship + pm.deletePersistent(emp1); + pm.flush(); + + // Postcondition + deferredAssertTrue(!proj1.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(); + proj1 = (Project)pm.getObjectById(proj1Oid); + deferredAssertTrue( + !proj1.getMembers().contains(emp1), + ASSERTION_FAILED + testMethod, + "In new transaction, postcondition is false; " + + "other side of relationship is not set."); + pm.currentTransaction().commit(); + + failOnError(); + } + } +} Property changes on: java\org\apache\jdo\tck\mapping\RelationshipManyToManyAllRelationships.java ___________________________________________________________________ Name: svn:eol-style + LF Index: java/org/apache/jdo/tck/mapping/RelationshipManyToManyNoRelationships.java =================================================================== --- java/org/apache/jdo/tck/mapping/RelationshipManyToManyNoRelationships.java (revision 0) +++ java/org/apache/jdo/tck/mapping/RelationshipManyToManyNoRelationships.java (revision 0) @@ -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; + + +/** + *Title:RelationshipManyToManyNoRelationships + *
+ *Keywords: mapping, managed relationships + *
+ *Assertion ID: A15.3-1 + *
+ *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. + */ + +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 main 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(); + } + } + +} Property changes on: java\org\apache\jdo\tck\mapping\RelationshipManyToManyNoRelationships.java ___________________________________________________________________ Name: svn:eol-style + LF Index: java/org/apache/jdo/tck/mapping/RelationshipNegative1To1Test.java =================================================================== --- java/org/apache/jdo/tck/mapping/RelationshipNegative1To1Test.java (revision 0) +++ java/org/apache/jdo/tck/mapping/RelationshipNegative1To1Test.java (revision 0) @@ -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; + + +/** + *Title:RelationshipNegative1To1Test + *
+ *Keywords: mapping, managed relationships + *
+ *Assertion ID: A15.3-1 + *
+ *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. + */ + +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 main 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(); + } +} Property changes on: java\org\apache\jdo\tck\mapping\RelationshipNegative1To1Test.java ___________________________________________________________________ Name: svn:eol-style + LF Index: java/org/apache/jdo/tck/mapping/RelationshipNegative1ToManyTest.java =================================================================== --- java/org/apache/jdo/tck/mapping/RelationshipNegative1ToManyTest.java (revision 0) +++ java/org/apache/jdo/tck/mapping/RelationshipNegative1ToManyTest.java (revision 0) @@ -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; + + +/** + *Title:RelationshipNegative1ToManyTest + *
+ *Keywords: mapping, managed relationships + *
+ *Assertion ID: A15.3-1 + *
+ *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. + */ + +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 main 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(); + } +} Property changes on: java\org\apache\jdo\tck\mapping\RelationshipNegative1ToManyTest.java ___________________________________________________________________ Name: svn:eol-style + LF