Index: src/java/org/apache/jdo/tck/pc/company/CompanyFactoryAbstractImpl.java =================================================================== --- src/java/org/apache/jdo/tck/pc/company/CompanyFactoryAbstractImpl.java (Revision 398560) +++ src/java/org/apache/jdo/tck/pc/company/CompanyFactoryAbstractImpl.java (Arbeitskopie) @@ -16,6 +16,10 @@ package org.apache.jdo.tck.pc.company; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + import javax.jdo.PersistenceManager; import org.apache.commons.logging.Log; @@ -43,6 +47,16 @@ this.pm = pm; } + /** All instances created using one of the factory methods + */ + protected List allInstances = new ArrayList(); + + /** Get all instances created with this factory + */ + public List getAllInstances() { + return new ArrayList(allInstances); + } + abstract IAddress newAddress(); abstract ICompany newCompany(); abstract IDentalInsurance newDentalInsurance(); @@ -66,6 +80,7 @@ public ICompany newCompany(long companyid, String name, java.util.Date founded) { ICompany result = newCompany(); + allInstances.add(result); if (debug) logger.debug("newCompany returned" + result); result.setCompanyid(companyid); result.setName(name); @@ -75,6 +90,7 @@ public ICompany newCompany(long companyid, String name, java.util.Date founded, IAddress addr) { ICompany result = newCompany(); + allInstances.add(result); if (debug) logger.debug("newCompany returned" + result); result.setCompanyid(companyid); result.setName(name); @@ -85,6 +101,7 @@ public IDentalInsurance newDentalInsurance(long insid, String carrier, java.math.BigDecimal lifetimeOrthoBenefit) { IDentalInsurance result = newDentalInsurance(); + allInstances.add(result); if (debug) logger.debug("newDentalInsurance returned" + result); result.setInsid(insid); result.setCarrier(carrier); @@ -94,6 +111,7 @@ public IDentalInsurance newDentalInsurance(long insid, String carrier, IEmployee employee, java.math.BigDecimal lifetimeOrthoBenefit) { IDentalInsurance result = newDentalInsurance(); + allInstances.add(result); if (debug) logger.debug("newDentalInsurance returned" + result); result.setInsid(insid); result.setCarrier(carrier); @@ -104,6 +122,7 @@ public IDepartment newDepartment(long deptid, String name) { IDepartment result = newDepartment(); + allInstances.add(result); if (debug) logger.debug("newDepartment returned" + result); result.setDeptid(deptid); result.setName(name); @@ -112,6 +131,7 @@ public IDepartment newDepartment(long deptid, String name, ICompany company) { IDepartment result = newDepartment(); + allInstances.add(result); if (debug) logger.debug("newDepartment returned" + result); result.setDeptid(deptid); result.setName(name); @@ -121,6 +141,7 @@ public IDepartment newDepartment(long deptid, String name, ICompany company, IEmployee employeeOfTheMonth) { IDepartment result = newDepartment(); + allInstances.add(result); if (debug) logger.debug("newDepartment returned" + result); result.setDeptid(deptid); result.setName(name); @@ -131,6 +152,7 @@ public IFullTimeEmployee newFullTimeEmployee(long personid, String first, String last, String middle, java.util.Date born, java.util.Date hired, double sal) { IFullTimeEmployee result = newFullTimeEmployee(); + allInstances.add(result); if (debug) logger.debug("newFullTimeEmployee returned" + result); result.setPersonid(personid); result.setFirstname(first); @@ -144,6 +166,7 @@ public IFullTimeEmployee newFullTimeEmployee(long personid, String first, String last, String middle, java.util.Date born, IAddress addr, java.util.Date hired, double sal) { IFullTimeEmployee result = newFullTimeEmployee(); + allInstances.add(result); if (debug) logger.debug("newFullTimeEmployee returned" + result); result.setPersonid(personid); result.setFirstname(first); @@ -158,6 +181,7 @@ public IMedicalInsurance newMedicalInsurance(long insid, String carrier, String planType) { IMedicalInsurance result = newMedicalInsurance(); + allInstances.add(result); if (debug) logger.debug("newMedicalInsurance returned" + result); result.setInsid(insid); result.setCarrier(carrier); @@ -167,6 +191,7 @@ public IMedicalInsurance newMedicalInsurance(long insid, String carrier, IEmployee employee, String planType) { IMedicalInsurance result = newMedicalInsurance(); + allInstances.add(result); if (debug) logger.debug("newMedicalInsurance returned" + result); result.setInsid(insid); result.setCarrier(carrier); @@ -177,6 +202,7 @@ public IPartTimeEmployee newPartTimeEmployee(long personid, String first, String last, String middle, java.util.Date born, java.util.Date hired, double wage) { IPartTimeEmployee result = newPartTimeEmployee(); + allInstances.add(result); if (debug) logger.debug("newPartTimeEmployee returned" + result); result.setPersonid(personid); result.setFirstname(first); @@ -190,6 +216,7 @@ public IPartTimeEmployee newPartTimeEmployee(long personid, String first, String last, String middle, java.util.Date born, IAddress addr, java.util.Date hired, double wage) { IPartTimeEmployee result = newPartTimeEmployee(); + allInstances.add(result); if (debug) logger.debug("newPartTimeEmployee returned" + result); result.setPersonid(personid); result.setFirstname(first); @@ -204,6 +231,7 @@ public IProject newProject(long projid, String name, java.math.BigDecimal budget) { IProject result = newProject(); + allInstances.add(result); if (debug) logger.debug("newProject returned" + result); result.setProjid(projid); result.setName(name); Index: src/java/org/apache/jdo/tck/pc/company/CompanyFactoryConcreteClass.java =================================================================== --- src/java/org/apache/jdo/tck/pc/company/CompanyFactoryConcreteClass.java (Revision 398560) +++ src/java/org/apache/jdo/tck/pc/company/CompanyFactoryConcreteClass.java (Arbeitskopie) @@ -18,7 +18,9 @@ import java.math.BigDecimal; +import java.util.ArrayList; import java.util.Date; +import java.util.List; import javax.jdo.PersistenceManager; @@ -28,6 +30,10 @@ */ public class CompanyFactoryConcreteClass implements CompanyFactory { + /** All instances created using one of the factory methods + */ + protected List allInstances = new ArrayList(); + /** */ public static final Class[] tearDownClasses = new Class[] { DentalInsurance.class, MedicalInsurance.class, @@ -35,6 +41,7 @@ Project.class, Department.class, Company.class }; + public CompanyFactoryConcreteClass(PersistenceManager pm) { } @@ -43,103 +50,143 @@ public ICompany newCompany(long companyid, String name, Date founded) { - return new Company(companyid, name, founded); + ICompany result = new Company(companyid, name, founded); + allInstances.add(result); + return result; } public ICompany newCompany(long companyid, String name, Date founded, IAddress addr) { - return new Company(companyid, name, founded, addr); + ICompany result = new Company(companyid, name, founded, addr); + allInstances.add(result); + return result; } public IAddress newAddress(long addrid, String street, String city, String state, String zipcode, String country) { - return new Address(addrid, street, city, state, zipcode, country); + IAddress result = new Address(addrid, street, city, state, zipcode, country); + return result; } public IDentalInsurance newDentalInsurance(long insid, String carrier, BigDecimal lifetimeOrthoBenefit) { - return new DentalInsurance(insid, carrier, lifetimeOrthoBenefit); + IDentalInsurance result = new DentalInsurance(insid, carrier, lifetimeOrthoBenefit); + allInstances.add(result); + return result; } public IDentalInsurance newDentalInsurance(long insid, String carrier, IEmployee employee, BigDecimal lifetimeOrthoBenefit) { - return new DentalInsurance(insid, carrier, lifetimeOrthoBenefit); + IDentalInsurance result = new DentalInsurance(insid, carrier, lifetimeOrthoBenefit); + allInstances.add(result); + return result; } public IDepartment newDepartment(long deptid, String name) { - return new Department(deptid, name); + IDepartment result = new Department(deptid, name); + allInstances.add(result); + return result; } + public IDepartment newDepartment(long deptid, String name, ICompany company) { - return new Department(deptid, name, company); + IDepartment result = new Department(deptid, name, company); + allInstances.add(result); + return result; } public IDepartment newDepartment(long deptid, String name, ICompany company, IEmployee employeeOfTheMonth) { - return new Department(deptid, name, company, employeeOfTheMonth); + IDepartment result = new Department(deptid, name, company, employeeOfTheMonth); + allInstances.add(result); + return result; } public IFullTimeEmployee newFullTimeEmployee(long personid, String first, String last, String middle, Date born, Date hired, double sal) { - return new FullTimeEmployee(personid, first, last, middle, + IFullTimeEmployee result = new FullTimeEmployee(personid, first, last, middle, born, hired, sal); + allInstances.add(result); + return result; } public IFullTimeEmployee newFullTimeEmployee(long personid, String first, String last, String middle, Date born, IAddress addr, Date hired, double sal) { - return new FullTimeEmployee(personid, first, last, middle, - born, addr, hired, sal); + IFullTimeEmployee result = new FullTimeEmployee(personid, first, last, middle, + born, addr, hired, sal); + allInstances.add(result); + return result; } public IMedicalInsurance newMedicalInsurance(long insid, String carrier, String planType) { - return new MedicalInsurance(insid, carrier, planType); + IMedicalInsurance result = new MedicalInsurance(insid, carrier, planType); + allInstances.add(result); + return result; } public IMedicalInsurance newMedicalInsurance(long insid, String carrier, IEmployee employee, String planType) { - return new MedicalInsurance(insid, carrier, planType); + IMedicalInsurance result = new MedicalInsurance(insid, carrier, planType); + allInstances.add(result); + return result; } public IPartTimeEmployee newPartTimeEmployee(long personid, String first, String last, String middle, Date born, Date hired, double wage ) { - return new PartTimeEmployee(personid, first, last, middle, - born, hired, wage); + IPartTimeEmployee result = new PartTimeEmployee(personid, first, last, middle, + born, hired, wage); + allInstances.add(result); + return result; } public IPartTimeEmployee newPartTimeEmployee(long personid, String first, String last, String middle, Date born, IAddress addr, Date hired, double wage) { - return new PartTimeEmployee(personid, first, last, middle, - born, addr, hired, wage); + IPartTimeEmployee result = new PartTimeEmployee(personid, first, last, middle, + born, addr, hired, wage); + allInstances.add(result); + return result; } public IPerson newPerson(long personid, String firstname, String lastname, String middlename, Date birthdate) { - return new Person(personid, firstname, lastname, middlename, - birthdate); + IPerson result = new Person(personid, firstname, lastname, middlename, + birthdate); + allInstances.add(result); + return result; } public IPerson newPerson(long personid, String firstname, String lastname, String middlename, Date birthdate, IAddress address) { - return new Person(personid, firstname, lastname, middlename, - birthdate, address); + IPerson result = new Person(personid, firstname, lastname, middlename, + birthdate, address); + allInstances.add(result); + return result; } public IProject newProject(long projid, String name, BigDecimal budget) { - return new Project(projid, name, budget); + IProject result = new Project(projid, name, budget); + allInstances.add(result); + return result; } public Class[] getTearDownClasses() { return tearDownClasses; } + + /** Get all instances created with this factory + */ + public List getAllInstances() { + return new ArrayList(allInstances); + } } Index: src/java/org/apache/jdo/tck/pc/company/CompanyFactory.java =================================================================== --- src/java/org/apache/jdo/tck/pc/company/CompanyFactory.java (Revision 398560) +++ src/java/org/apache/jdo/tck/pc/company/CompanyFactory.java (Arbeitskopie) @@ -24,6 +24,7 @@ import java.math.BigDecimal; import java.util.Date; +import java.util.List; /** * This interface is implemented by a factory class that can create @@ -64,4 +65,5 @@ Date born, IAddress addr, Date hired, double wage); IProject newProject(long projid, String name, BigDecimal budget); Class[] getTearDownClasses(); + List getAllInstances(); } Index: src/java/org/apache/jdo/tck/mapping/LifecycleCompleteness.java =================================================================== --- src/java/org/apache/jdo/tck/mapping/LifecycleCompleteness.java (Revision 0) +++ src/java/org/apache/jdo/tck/mapping/LifecycleCompleteness.java (Revision 0) @@ -0,0 +1,332 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed 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.Arrays; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +import javax.jdo.Extent; +import javax.jdo.Query; + +import javax.jdo.identity.SingleFieldIdentity; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.pc.company.CompanyFactoryRegistry; +import org.apache.jdo.tck.pc.company.CompanyModelReader; +import org.apache.jdo.tck.util.BatchTestRunner; +import org.apache.jdo.tck.util.DeepEquality; +import org.apache.jdo.tck.util.EqualityHelper; + +//import org.springframework.beans.factory.xml.XmlBeanFactory; + +/** + *Title:Completeness Test + *
+ *Keywords: mapping + *
+ *Assertion ID: A18.[not identified] + *
+ *Assertion Description: + */ + +public class LifecycleCompleteness extends JDO_Test { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A18-[not identified] failed: "; + + /** */ + private final boolean isTestToBePerformed = isTestToBePerformed(); + + /** Reader for transient instances + */ + private CompanyModelReader reader; + + /** Reader for persistent instances + */ + private CompanyModelReader reader2; + + /** */ + protected List allOids; + + /** */ + protected List allTransientInstances; + + /** */ + protected List persistentClasses; + + /** */ + protected final String inputFilename = + System.getProperty("jdo.tck.testdata"); + + /** + * 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(LifecycleCompleteness.class); + } + + /** + * @see JDO_Test#localSetUp() + */ + protected void localSetUp() { + if (isTestToBePerformed) { + // register the default factory + CompanyFactoryRegistry.registerFactory(); + // get new obj graph to compare persistent graph with + reader = new CompanyModelReader(inputFilename); + reader.getRootList(); + allTransientInstances = + CompanyFactoryRegistry.getInstance().getAllInstances(); + + getPM(); + CompanyFactoryRegistry.registerFactory(pm); + reader2 = new CompanyModelReader(inputFilename); + // persist test data + pm.currentTransaction().begin(); + List rootObjects2 = reader2.getRootList(); + Class[] tearDownClasses = reader2.getTearDownClassesFromFactory(); + addTearDownClass(tearDownClasses); + persistentClasses = Arrays.asList(tearDownClasses); + pm.makePersistentAll(rootObjects2); + List allPersistentInstances = + CompanyFactoryRegistry.getInstance().getAllInstances(); + allOids = new ArrayList(); + for (Iterator i = allTransientInstances.iterator(); i.hasNext();) { + // get the object in the transient list + Object transientInstance = i.next(); + // find the corresponding persistent instance + Object persistentInstance; + boolean found = false; + Iterator persistentIterator = allPersistentInstances.iterator(); + while (persistentIterator.hasNext()) { + persistentInstance = persistentIterator.next(); + if (transientInstance.equals(persistentInstance)) { + found = true; + allOids.add(pm.getObjectId(persistentInstance)); + break; + } + } + if (!found) { + appendMessage("localSetUp could not find persistent instance for" + + transientInstance); + } + } + pm.currentTransaction().commit(); + cleanupPM(); + } + } + + /** */ + public void test() { + if (isTestToBePerformed) { + verifyOids(); + runGetObjectById(); + runGetObjectsById(); + runExtentIteration(); + runQueryIterationFromClass(); + runQueryIterationFromExtent(); + failOnError(); + } + } + + /** */ + protected void verifyOids() { + // for each oid, verify that the class is one of the persistent classes + Iterator oidIterator = allOids.iterator(); + while (oidIterator.hasNext()) { + Object oid = oidIterator.next(); + if (oid instanceof SingleFieldIdentity) { + SingleFieldIdentity id = (SingleFieldIdentity)(oid); + Class clazz = id.getTargetClass(); + if (!persistentClasses.contains(clazz)) { + appendMessage("verifyOids found wrong class " + clazz + + " in oid " + id); + } + } + } + } + + /** */ + public void runGetObjectById() { + List rootList = reader.getRootList(); + getPM(); + pm.currentTransaction().begin(); + int size = allOids.size(); + List actual = new ArrayList(size); + for (int i = 0; i < size; i++) { + Object oid = allOids.get(i); + Object persisted = pm.getObjectById(oid); + actual.add(persisted); + } + compareLists("runGetObjectById", allTransientInstances, actual); + pm.currentTransaction().commit(); + cleanupPM(); + } + + /** */ + public void runGetObjectsById() { + List rootList = reader.getRootList(); + getPM(); + pm.currentTransaction().begin(); + int size = allOids.size(); + Collection actual = pm.getObjectsById(allOids); + compareLists("runGetObjectsById", allTransientInstances, actual); + pm.currentTransaction().commit(); + cleanupPM(); + } + + /** */ + protected void runExtentIteration() { + List expectedList = new ArrayList(allTransientInstances); + List actualList = new ArrayList(); + getPM(); + pm.currentTransaction().begin(); + Class[] classes = reader2.getTearDownClassesFromFactory(); + // get the objects for each class from the iterator over the Extent + for (int i = 0; i < classes.length; ++i) { + Class clazz = classes[i]; + Extent extent = pm.getExtent(clazz, false); + int count = 0; + for (Iterator it = extent.iterator(); it.hasNext();) { + ++count; + Object persistent = it.next(); + actualList.add(persistent); + } + } + // check list of persistent instances against expected + compareCollections("runExtentIteration", + expectedList, actualList); + pm.currentTransaction().commit(); + cleanupPM(); + } + + /** */ + protected void runQueryIterationFromClass() { + List expectedList = new ArrayList(allTransientInstances); + Collection actualCollection = new ArrayList(); + getPM(); + pm.currentTransaction().begin(); + Class[] classes = reader2.getTearDownClassesFromFactory(); + // query for instances of each class in the list + for (int i = 0; i < classes.length; ++i) { + Query query = pm.newQuery(classes[i]); + Collection resultCollection = (Collection)query.execute(); + Iterator resultIterator = resultCollection.iterator(); + while (resultIterator.hasNext()) { + actualCollection.add(resultIterator.next()); + } + } + compareCollections("runQueryIterationFromClass", + expectedList, actualCollection); + pm.currentTransaction().commit(); + cleanupPM(); + } + + /** */ + protected void runQueryIterationFromExtent() { + List expectedList = new ArrayList(allTransientInstances); + List actualList = new ArrayList(); + getPM(); + pm.currentTransaction().begin(); + Class[] classes = reader2.getTearDownClassesFromFactory(); + // query for instances of each class in the list + for (int i = 0; i < classes.length; ++i) { + Query query = pm.newQuery(); + query.setCandidates(pm.getExtent(classes[i])); + Collection resultCollection = (Collection)query.execute(); + Iterator resultIterator = resultCollection.iterator(); + while (resultIterator.hasNext()) { + actualList.add(resultIterator.next()); + } + } + compareCollections("runQueryIterationFromExtent", + expectedList, actualList); + pm.currentTransaction().commit(); + cleanupPM(); + } + + /** */ + protected void compareLists(String where, + Collection expectedCollection, + Collection actualCollection) { + int expectedSize = expectedCollection.size(); + int actualSize = actualCollection.size(); + if (expectedSize != actualSize) { + appendMessage(where + " expected size " + expectedSize + + " does not match actual size " + actualSize); + } + Iterator expectedIterator = expectedCollection.iterator(); + Iterator actualIterator = actualCollection.iterator(); + for (int i = 0; i < expectedSize; ++i) { + Object expected = expectedIterator.next(); + if (actualIterator.hasNext()) { + Object actual = actualIterator.next(); + if (!expected.equals(actual)) { + appendMessage(where + " comparison failed; " + + "position " + i + NL + + "expected: " + expected + + " actual: " + actual + NL); + } + } else { + appendMessage(where + " actual collection exhausted after " + + i + " elements"); + return; + } + } + } + + /** */ + protected void compareCollections(String where, + Collection expectedCollection, + Collection actualCollection) { + // first compare size + int expectedSize = expectedCollection.size(); + int actualSize = actualCollection.size(); + if (expectedSize != actualSize) { + appendMessage(where + " expected size " + expectedSize + + " does not match actual size " + actualSize); + } + // iterate over the expected collection and remove corresponding elements + Iterator expectedIterator = expectedCollection.iterator(); + while (expectedIterator.hasNext()) { + Object expectedInstance = expectedIterator.next(); + if (!actualCollection.remove(expectedInstance)) { + appendMessage(where + + " unmatched instance in expected collection " + + expectedInstance); + } + } + // make sure each element in the actualCollection was retrieved + int leftovers = actualCollection.size(); + if (leftovers != 0) { + appendMessage(where + " had " + + leftovers + " leftovers"); + Iterator leftoverIterator = actualCollection.iterator(); + while (leftoverIterator.hasNext()) { + appendMessage(where + " resulted in leftover instance " + + leftoverIterator.next()); + } + } + } + +} Index: src/conf/lifecyclecompletenessPMInterface.conf =================================================================== --- src/conf/lifecyclecompletenessPMInterface.conf (Revision 0) +++ src/conf/lifecyclecompletenessPMInterface.conf (Revision 0) @@ -0,0 +1,7 @@ +jdo.tck.description = Completeness test with standard mapping, basic testdata with all relationships \ +and embedded objects. +jdo.tck.mapping.companyfactory = org.apache.jdo.tck.pc.company.CompanyFactoryPMInterface +jdo.tck.classes = org.apache.jdo.tck.mapping.LifecycleCompleteness +jdo.tck.testdata = org/apache/jdo/tck/pc/company/companyAllRelationships.xml +jdo.tck.mapping = 0 +jdo.tck.requiredOptions = Index: src/conf/lifecyclecompletenessConcreteClass.conf =================================================================== --- src/conf/lifecyclecompletenessConcreteClass.conf (Revision 0) +++ src/conf/lifecyclecompletenessConcreteClass.conf (Revision 0) @@ -0,0 +1,7 @@ +jdo.tck.description = Completeness test with standard mapping, basic testdata with all relationships \ +and embedded objects. +jdo.tck.mapping.companyfactory = org.apache.jdo.tck.pc.company.CompanyFactoryConcreteClass +jdo.tck.classes = org.apache.jdo.tck.mapping.LifecycleCompleteness +jdo.tck.testdata = org/apache/jdo/tck/pc/company/companyAllRelationships.xml +jdo.tck.mapping = 0 +jdo.tck.requiredOptions = Index: src/conf/lifecyclecompletenessPMClass.conf =================================================================== --- src/conf/lifecyclecompletenessPMClass.conf (Revision 0) +++ src/conf/lifecyclecompletenessPMClass.conf (Revision 0) @@ -0,0 +1,7 @@ +jdo.tck.description = Completeness test with standard mapping, basic testdata with all relationships \ +and embedded objects. +jdo.tck.mapping.companyfactory = org.apache.jdo.tck.pc.company.CompanyFactoryPMClass +jdo.tck.classes = org.apache.jdo.tck.mapping.LifecycleCompleteness +jdo.tck.testdata = org/apache/jdo/tck/pc/company/companyAllRelationships.xml +jdo.tck.mapping = 0 +jdo.tck.requiredOptions = Index: src/conf/configurations.list =================================================================== --- src/conf/configurations.list (Revision 398560) +++ src/conf/configurations.list (Arbeitskopie) @@ -21,6 +21,9 @@ companyAllRelationships.conf \ companyPMClass.conf \ companyPMInterface.conf \ + lifecyclecompletenessConcreteClass.conf \ + lifecyclecompletenessPMClass.conf \ + lifecyclecompletenessPMInterface.conf \ inheritance1.conf \ inheritance2.conf \ inheritance3.conf \