Added: incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/Test_PMFProperties.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/Test_PMFProperties.java?view=auto&rev=158176 ============================================================================== --- incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/Test_PMFProperties.java (added) +++ incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/Test_PMFProperties.java Fri Mar 18 17:02:29 2005 @@ -0,0 +1,170 @@ +/* + * 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.test; + +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.security.AccessController; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; +import java.util.Properties; + +import javax.jdo.JDOException; +import javax.jdo.JDOFatalUserException; +import javax.jdo.JDOHelper; +import javax.jdo.PersistenceManagerFactory; + +import org.apache.jdo.impl.fostore.FOStorePMF; +import org.apache.jdo.test.util.AbstractTest; +import org.apache.jdo.test.util.JDORITestRunner; + +/** +* Test the PersistenceManagerFactory.getPersistenceManagerFactory (Properties). +* +* @author Craig Russell +*/ +public class Test_PMFProperties extends AbstractTest { + + /** */ + public static void main(String args[]) { + JDORITestRunner.run(Test_PMFProperties.class); + } + + /** */ + protected void setUp() { + // create PMF here to allow configuration + pmf = new FOStorePMF(); + } + + /** + * + */ + public void test() throws Exception { + configPMF(); + } + + /** + * Configures a PMF with some basic properties, and creates the + * corresponding database. + */ + protected void configPMF() throws Exception { + PersistenceManagerFactory pmf2, pmf3, pmf4, pmf5, pmf6, pmf7; + + if( pmf instanceof FOStorePMF ) + ((FOStorePMF)pmf).setConnectionCreate(true); + + pmf.setConnectionUserName(System.getProperty ("user", "fred")); + pmf.setConnectionPassword(System.getProperty ("password", "wombat")); + + String url = createURL(); + pmf.setConnectionURL(url); + Properties propout; + if( pmf instanceof FOStorePMF ) + propout = ((FOStorePMF)pmf).getAsProperties(); + else { + initProperties(); + propout = this.properties; + } + + writeProperties(propout, "testPropsBefore.tmp", "Original Properties"); + // use the properties to construct a new pmf from the same properties + pmf = JDOHelper.getPersistenceManagerFactory (propout); + // the same instance should be returned with the same properties. + pmf2 = JDOHelper.getPersistenceManagerFactory (propout); + if (pmf != pmf2) { + dump (pmf, "original"); + dump (pmf2, "from properties"); + fail ("PersistenceManagerFactory instances don't match."); + } + // the same instance should be returned if a default property is set explicitly + propout.setProperty("javax.jdo.option.Optimistic", "true"); + pmf3 = JDOHelper.getPersistenceManagerFactory (propout); + if (pmf != pmf3) { + dump (pmf, "original"); + dump (pmf3, "from properties"); + fail ("PersistenceManagerFactory instances don't match."); + } + // the same instance should be returned if an unknown property is set explicitly + propout.setProperty("junque", "ignored"); + pmf4 = JDOHelper.getPersistenceManagerFactory (propout); + if (pmf != pmf4) { + dump (pmf, "original"); + dump (pmf4, "from properties"); + fail ("PersistenceManagerFactory instances don't match."); + } + // a different instance should be returned if a non-default property is set explicitly + propout.setProperty("javax.jdo.option.Optimistic", "false"); + pmf5 = JDOHelper.getPersistenceManagerFactory (propout); + if (pmf == pmf5) { + dump (pmf, "original"); + dump (pmf5, "from properties"); + fail ("PersistenceManagerFactory instances match."); + } + // an exception should be thrown if the user doesn't configure ConnectionURL + propout.remove("javax.jdo.option.ConnectionURL"); + writeProperties(propout, "testPropsAfter.tmp", "After removing javax.jdo.option.ConnectionURL"); + try { + pmf6 = JDOHelper.getPersistenceManagerFactory (propout); + fail ("Expected exception not caught (no ConnectionURL in properties)."); + } catch (JDOException e) { + // ok to throw JDOFatalUserException + if (!(e instanceof JDOFatalUserException)) { + fail ("Unexpected exception caught (no ConnectionURL in properties): " + e); + } + } + // configure using FOStoreConnectionFactory + propout.setProperty ("org.apache.jdo.FOStoreConnectionFactory.option.URL", url); + writeProperties(propout, "testPropsAfterConnectionFactory.tmp", "After adding FOStoreConnectionFactory"); + pmf7 = JDOHelper.getPersistenceManagerFactory (propout); + if (pmf == pmf7) { + dump (pmf, "original"); + dump (pmf7, "from properties"); + fail ("PersistenceManagerFactory instances match."); + } + } + + /** */ + protected void dump (PersistenceManagerFactory pmf, String header) throws IOException { + Properties props; + if( pmf instanceof FOStorePMF ) + props = ((FOStorePMF)pmf).getAsProperties(); + else + props = this.properties; + props.store (System.out, header); + } + + /** */ + protected void writeProperties(final Properties props, + final String filename, + final String header) throws IOException { + FileOutputStream fos = null; + try { + fos = (FileOutputStream)AccessController.doPrivileged( + new PrivilegedExceptionAction () { + public Object run () throws FileNotFoundException { + return new FileOutputStream(filename); + }}); + } + catch (PrivilegedActionException ex) { + // unwrap FileNotFoundException + throw (FileNotFoundException)ex.getException(); + } + props.store(fos, header); + } + +}
Added: incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/Test_ParallelPMs.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/Test_ParallelPMs.java?view=auto&rev=158176 ============================================================================== --- incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/Test_ParallelPMs.java (added) +++ incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/Test_ParallelPMs.java Fri Mar 18 17:02:29 2005 @@ -0,0 +1,276 @@ +/* + * 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.test; + +import java.util.Iterator; + +import javax.jdo.Extent; +import javax.jdo.JDOException; +import javax.jdo.PersistenceManager; +import javax.jdo.PersistenceManagerFactory; +import javax.jdo.Transaction; + +import org.apache.jdo.pc.PointFactory; +import org.apache.jdo.test.util.AbstractTest; +import org.apache.jdo.test.util.Factory; +import org.apache.jdo.test.util.JDORITestRunner; + +/** +* Tests that multiple PersistenceManager's, each running in their own thread, +* can successfully insert objects into the store. +* +* @author Dave Bristor +*/ +public class Test_ParallelPMs extends AbstractTest { + + /** One thread per PM. */ + private int threads = 0; + + /** Factory for creating PersistenceCapable instances that are stored. */ + private LocalFactory localFactory; + + /** If true, then each PM tries to insert the same "shared" PC instance. + * Otherwise, each PM tries to insert its own, independent PC instance. + */ + private boolean share; + + /** */ + private int attempts; + + /** */ + private Throwable throwable = null; + + /** The number of objects that is expected to have been inserted. */ + protected int insertedCountExpected = 0; + + /** */ + public static void main(String args[]) { + JDORITestRunner.run(Test_ParallelPMs.class); + } + + /** */ + public void testShared() throws Throwable { + share = true; + localFactory = new LocalFactory(share); + insertedCountExpected++; + insertObjects(); + if (throwable != null) + throw throwable; + } + + /** */ + public void testNotShared() throws Throwable { + share = false; + localFactory = new LocalFactory(share); + insertedCountExpected += numInsert; + insertObjects(); + if (throwable != null) + throw throwable; + } + + // Creates PC instances, which can be either shared among + // PersistenceManagers or not, depending on how the factory is created. + // + // This is so that, by changing the system property "share", we + // can test two conditions: + // + // (a) each PM-in-a-thread stores it's own PC: each should succeed. + // (b) each PM-in-a-thread stores the *same* PC: only one should succeed. + // + class LocalFactory { + private final Object pc; + + LocalFactory(boolean share) { + if (debug) + logger.debug(Thread.currentThread() + + " LocalFactory: " + share); + if (share) { + pc = factory.create(-999); + } else { + pc = null; + } + } + + // If the factory was created with arg=true, then always return the + // same instance. + Object create(int i) { + return null == pc ? factory.create(i) : pc; + } + } + + /** + * ThreadGroup to pass an exception thrown by a test thread to the + * Test_ParallelPMs instance, such that the test method can throw the + * exception and the test framework can handle it. + */ + class MyThreadGroup extends ThreadGroup + { + MyThreadGroup () { + super("Test_ParallelPMs"); + } + + public void uncaughtException(Thread t, Throwable e) { + throwable = e; + } + } + + protected void insertObjects() { + Inserter inserters[] = new Inserter[numInsert]; + + MyThreadGroup threadGroup = new MyThreadGroup(); + for (int i = 0; i < numInsert; i++) { + Object pc = localFactory.create(i); + threads++; + Thread t = new Thread(threadGroup, new Inserter(pmf, pc)); + t.setName("Inserter-" + i); + t.start(); + } + + Thread.currentThread().yield(); + + while (! attemptsComplete()) { + try { + Thread.currentThread().sleep(100); + } catch (InterruptedException ex) { + System.err.println("interrupted while waiting for threads to insert"); + } + } + + while (threads > 0) { + try { + Thread.currentThread().sleep(100); + } catch (InterruptedException ex) { + System.err.println("interrupted while waiting for threads to finish"); + } + } + } + + synchronized void signal() { + threads--; + } + + protected synchronized void incrAttempts() { + attempts++; + } + + protected synchronized boolean attemptsComplete() { + return attempts == numInsert; + } + + protected int getDefaultInsert() + { + return 5; + } + + + class Inserter implements Runnable { + private final PersistenceManager pm; + private final Object pc; + private final Class instanceClass; + + Inserter(PersistenceManagerFactory pmf, Object pc) { + this.pm = pmf.getPersistenceManager(); + this.pc = pc; + this.instanceClass = pc.getClass(); + } + + public void run() { + Transaction tx = null; + try { + if (debug) + logger.debug(Thread.currentThread() + " running"); + tx = pm.currentTransaction(); + tx.begin(); + try { + pm.makePersistent(pc); + announce("inserted ", pc); + tx.commit(); + } + catch (JDOException ex) { + if (!share) + throw ex; + } + finally { + if (tx != null && tx.isActive()) + tx.rollback(); + } + incrAttempts(); + + while (!attemptsComplete()) { + try { + Thread.currentThread().sleep(100); + } catch (InterruptedException ex) { + if (debug) + logger.debug(Thread.currentThread() + + " interrupted"); + } + } + + // Verify that the number of inserted objects matches + // the expected number + if (insertedCount!=insertedCountExpected) { + assertEquals("Wrong number of objects in extent", + insertedCount, insertedCountExpected); + } + + boolean messagePrinted = false; + int objCount = 0; + if (debug) + logger.debug(Thread.currentThread() + " getting Extent of " + + instanceClass.getName()); + Extent e = pm.getExtent(instanceClass, false); + for (Iterator i = e.iterator(); i.hasNext();) { + Object instance = (Object)i.next(); + if (debug) { + if (objCount < maxMessages) { + logger.debug(Thread.currentThread() + + " " + instance); + } else if (! messagePrinted) { + logger.debug(Thread.currentThread() + + " skipping remaining extent messages"); + messagePrinted = true; + } + } + objCount++; + } + assertEquals("Wrong number of objects in extent", + insertedCount, objCount); + } finally { + if (tx != null && tx.isActive()) + tx.rollback(); + if (pm != null && !pm.isClosed()) + pm.close(); + Test_ParallelPMs.this.signal(); + } + } + + public String toString() { + String rc = "Inserter "; + if (debug) { + rc += Thread.currentThread(); + } + return rc; + } + } + + /** */ + protected Factory getFactory(int verify) { + PointFactory rc = new PointFactory(); + rc.setVerify(verify); + return rc; + } +} Added: incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/Test_Primitives.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/Test_Primitives.java?view=auto&rev=158176 ============================================================================== --- incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/Test_Primitives.java (added) +++ incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/Test_Primitives.java Fri Mar 18 17:02:29 2005 @@ -0,0 +1,84 @@ +/* + * 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.test; + +import javax.jdo.JDOHelper; +import javax.jdo.PersistenceManager; +import javax.jdo.Transaction; + +import org.apache.jdo.pc.PCPrimitive; +import org.apache.jdo.test.util.JDORITestRunner; + +/** +* This test tries to insert a persistent capable object into a database; the +* object has a field of each of the kind of primitive and immutable Java +* types. +* +* @author Dave Bristor +*/ +public class Test_Primitives extends Test_Fetch { + + /** */ + public static void main(String args[]) { + JDORITestRunner.run(Test_Primitives.class); + } + + /** */ + public void test() throws Exception { + insertObjects(); + readObjects(); + checkExtent(PCPrimitive.class, 1); + } + + /** Redefine to insert our own objects. */ + protected void insertObjects() { + PersistenceManager pm = pmf.getPersistenceManager(); + Transaction tx = pm.currentTransaction(); + try { + tx.begin(); + PCPrimitive pcPrimitive = new PCPrimitive(); + pcPrimitive.init(); + if(debug) logger.debug("Before insert: " + pcPrimitive); + pm.makePersistent(pcPrimitive); + tx.commit(); + + Object oid1 = JDOHelper.getObjectId(pcPrimitive); + if(debug) + logger.debug("Test_Primitive: inserted pcPrimitive: " + oid1); + oids.add(oid1); + } + finally { + if (tx != null && tx.isActive()) + tx.rollback(); + if (pm != null && !pm.isClosed()) + pm.close(); + } + } + + /** + * redefine verify called by readObjects to check whether the read + * instance is correct. + */ + protected void verify(int i, Object pc) { + if (i > 0) + fail("Wrong number of inserted objects, expected only one"); + PCPrimitive expected = new PCPrimitive(); + expected.init(); + assertEquals("Wrong instance returned from datastore", expected, pc); + } + +} Added: incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/Test_Query.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/Test_Query.java?view=auto&rev=158176 ============================================================================== --- incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/Test_Query.java (added) +++ incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/Test_Query.java Fri Mar 18 17:02:29 2005 @@ -0,0 +1,948 @@ +/* + * 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.test; + +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.PrintStream; +import java.math.BigDecimal; +import java.math.BigInteger; +import java.security.AccessController; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; + +import javax.jdo.PersistenceManager; +import javax.jdo.Transaction; + +import org.apache.jdo.pc.xempdept.Company; +import org.apache.jdo.pc.xempdept.Department; +import org.apache.jdo.pc.xempdept.Employee; +import org.apache.jdo.pc.xempdept.FullTimeEmployee; +import org.apache.jdo.pc.xempdept.Insurance; +import org.apache.jdo.pc.xempdept.PartTimeEmployee; +import org.apache.jdo.pc.xempdept.PrimitiveTypes; +import org.apache.jdo.pc.xempdept.Project; +import org.apache.jdo.test.query.AdvancedTest; +import org.apache.jdo.test.query.ArithmeticTest; +import org.apache.jdo.test.query.BasicTest; +import org.apache.jdo.test.query.CollectionTest; +import org.apache.jdo.test.query.InheritanceTest; +import org.apache.jdo.test.query.NavigationTest; +import org.apache.jdo.test.query.OrderingTest; +import org.apache.jdo.test.query.ParameterTest; +import org.apache.jdo.test.query.QueryApiTest; +import org.apache.jdo.test.query.QueryErrorTest; +import org.apache.jdo.test.query.QueryTest; +import org.apache.jdo.test.query.ScopingTest; +import org.apache.jdo.test.query.SemanticErrorTest; +import org.apache.jdo.test.query.SyntaxErrorTest; +import org.apache.jdo.test.query.TreeTest; +import org.apache.jdo.test.query.UnsupportedTest; +import org.apache.jdo.test.util.AbstractTest; +import org.apache.jdo.test.util.JDORITestRunner; + +/** + * Tests JDOQL queries. The following test scenarios are supported: + * <ul> + * <li> Extent queries with new fostore. The test first initializes a new + * fostore with the expected test instances from the xempdept schema. The + * test queries use the extent of a xempdept pc class as the query candidates. + * <li> Extent queries with existing fostore. The test ommits creating a new + * fostore, if the property <code>existing</code> is set to <code>true</code>. + * The test queries use the extent of a xempdept pc class as the query + * candidates. + * <li> Memory queries using transient instances of the xempdept classes. + * The test uses a memory collection of transient xempdept instances, + * if the property <code>memory</code> is set to <code>true</code>. + * <li> Memory query using persistent instances (not yet implemented). + * </ul> + * + * @author Michael Bouschen + */ +public class Test_Query extends AbstractTest +{ + PrintStream log; + + Collection companies; + Collection departments; + Collection employees; + Collection fullTimeEmployees; + Collection partTimeEmployees; + Collection insurances; + Collection projects; + Collection primitiveTypes; + String logFileSuffix = ""; + + /** */ + public static void main(String args[]) { + JDORITestRunner.run(Test_Query.class); + } + + /** */ + public Test_Query() + { + super(); + String suffix = System.getProperty("logFileSuffix"); + if ((suffix != null) && (suffix.length() > 0)) + logFileSuffix = suffix; + } + + /** + * TestCase: run negative query tests. + */ + public void testNegativeTests() + { + String logFileName = "NegativeQueryTests" + logFileSuffix + ".log"; + initLogFile(logFileName); + boolean ok = runQueryTestSuite(createNegativeTestClasses()); + finitLogFile(ok); + assertTrue("see " + logFileName + " for details", ok); + } + + /** + * TestCase: run positive query tests as memory queries using transient + * instances. + */ + public void testMemoryQueries() + { + String logFileName = "MemoryQueryTests" + logFileSuffix + ".log"; + createObjects(); + initLogFile(logFileName); + boolean ok = runQueryTestSuite(createPositiveTestClasses()); + finitLogFile(ok); + assertTrue("see " + logFileName + " for details", ok); + } + + /** + * TestCase: run positive query tests as extent queries using + * persistent instances. + */ + public void testExtentQueries() + { + String logFileName = "ExtentQueryTests" + logFileSuffix + ".log"; + if (!existing) { + createFOStore(); + } + initLogFile(logFileName); + boolean ok = runQueryTestSuite(createPositiveTestClasses()); + finitLogFile(ok); + assertTrue("see " + logFileName + " for details", ok); + } + + // ------------------------------------------------------------------------ + // Helper methods + // ------------------------------------------------------------------------ + + /** + * Create persistent instances and store them in FOStore. + */ + private void createFOStore() + { + PersistenceManager pm = pmf.getPersistenceManager(); + Transaction tx = pm.currentTransaction(); + tx.begin(); + createObjects(); + pm.makePersistentAll(companies); + pm.makePersistentAll(departments); + pm.makePersistentAll(employees); + // Note, there is no need to call makePersistentAll on + // fullTimeEmployees and partTimeEmployees, because they are part + // of employees + //pm.makePersistentAll(fullTimeEmployees); + //pm.makePersistentAll(partTimeEmployees); + pm.makePersistentAll(insurances); + pm.makePersistentAll(projects); + pm.makePersistentAll(primitiveTypes); + tx.commit(); + pm.close(); + + // cleanup candidates + companies = null; + departments = null; + employees = null; + fullTimeEmployees = null; + partTimeEmployees = null; + insurances = null; + projects = null; + primitiveTypes = null; + } + + /** + * Iterate query test classes and run the tests. + */ + private boolean runQueryTestSuite(List testClasses) + { + boolean ok = true; + // run all tests, if no specific test cases specified + for (Iterator i = testClasses.iterator(); i.hasNext();) + if (!((QueryTest)i.next()).runAll()) + ok = false; + return ok; + } + + /** + * Create test classes representing negative query tests. + */ + private List createNegativeTestClasses() + { + List testClasses = new ArrayList(4); + // negative tests + testClasses.add(new QueryErrorTest (pmf, log)); + testClasses.add(new SyntaxErrorTest (pmf, log)); + testClasses.add(new SemanticErrorTest (pmf, log)); + testClasses.add(new UnsupportedTest (pmf, log)); + return testClasses; + } + + /** + * Create test classes representing positive query tests. + */ + private List createPositiveTestClasses() + { + List testClasses = new ArrayList(11); + + // positive tests + QueryApiTest queryApiTest = new QueryApiTest(pmf, log); + queryApiTest.initCandidates(companies, departments, employees, + fullTimeEmployees, partTimeEmployees, + insurances, projects, primitiveTypes); + testClasses.add(queryApiTest); + BasicTest basicTest = new BasicTest (pmf, log); + basicTest.initCandidates(companies, departments, employees, + fullTimeEmployees, partTimeEmployees, + insurances, projects, primitiveTypes); + testClasses.add(basicTest); + ArithmeticTest arithmeticTest = new ArithmeticTest (pmf, log); + arithmeticTest.initCandidates(companies, departments, employees, + fullTimeEmployees, partTimeEmployees, + insurances, projects, primitiveTypes); + testClasses.add(arithmeticTest); + ParameterTest parameterTest = new ParameterTest (pmf, log); + parameterTest.initCandidates(companies, departments, employees, + fullTimeEmployees, partTimeEmployees, + insurances, projects, primitiveTypes); + testClasses.add(parameterTest); + AdvancedTest advancedTest = new AdvancedTest (pmf, log); + advancedTest.initCandidates(companies, departments, employees, + fullTimeEmployees, partTimeEmployees, + insurances, projects, primitiveTypes); + testClasses.add(advancedTest); + NavigationTest navigationTest = new NavigationTest (pmf, log); + navigationTest.initCandidates(companies, departments, employees, + fullTimeEmployees, partTimeEmployees, + insurances, projects, primitiveTypes); + testClasses.add(navigationTest); + CollectionTest collectionTest = new CollectionTest (pmf, log); + collectionTest.initCandidates(companies, departments, employees, + fullTimeEmployees, partTimeEmployees, + insurances, projects, primitiveTypes); + testClasses.add(collectionTest); + OrderingTest orderingTest = new OrderingTest (pmf, log); + orderingTest.initCandidates(companies, departments, employees, + fullTimeEmployees, partTimeEmployees, + insurances, projects, primitiveTypes); + testClasses.add(orderingTest); + ScopingTest scopingTest = new ScopingTest (pmf, log); + scopingTest.initCandidates(companies, departments, employees, + fullTimeEmployees, partTimeEmployees, + insurances, projects, primitiveTypes); + testClasses.add(scopingTest); + TreeTest treeTest = new TreeTest (pmf, log); + treeTest.initCandidates(companies, departments, employees, + fullTimeEmployees, partTimeEmployees, + insurances, projects, primitiveTypes); + testClasses.add(treeTest); + InheritanceTest inheritanceTest = new InheritanceTest (pmf, log); + inheritanceTest.initCandidates(companies, departments, employees, + fullTimeEmployees, partTimeEmployees, + insurances, projects, primitiveTypes); + testClasses.add(inheritanceTest); + + return testClasses; + } + + /** + * + */ + private void initLogFile(final String logFileName) + { + try { + log = (PrintStream)AccessController.doPrivileged( + new PrivilegedExceptionAction () { + public Object run () throws FileNotFoundException { + return new PrintStream(new FileOutputStream(logFileName)); + } + }); + } + catch (PrivilegedActionException ex) { + System.err.println("Cannot create log file " + logFileName + " reason " + ex.getException()); + log = System.out; + } + log.println("START " + new Date()); + } + + /** + * + */ + private void finitLogFile(boolean ok) + { + log.println("END " + new Date() + (ok ? " TEST OK" : " TEST NOT OK")); + if ((log != System.out) && (log != System.err)) + log.close(); + } + + + /** + * Creates test instances for positive query tests. + */ + void createObjects() + { + companies = new HashSet(); + departments = new HashSet(); + employees = new HashSet(); + fullTimeEmployees = new HashSet(); + partTimeEmployees = new HashSet(); + insurances = new HashSet(); + projects = new HashSet(); + primitiveTypes = new HashSet(); + + HashSet tmp; // temporay variable to update collection relatinships + + // create Company instances + + Company abcCompany = new Company( + "abc", new GregorianCalendar(1995, 0, 1).getTime(), + "Lombard Street 2", null); + companies.add(abcCompany); + Company xyzCompany = new Company( + "xyz", new GregorianCalendar(1998, 11, 1).getTime(), + "Kurfuerstendamm 5", null); + companies.add(xyzCompany); + + // create Department instances + + Department dept01 = new Department( + 1L, "Engineering", abcCompany, null); + departments.add(dept01); + Department dept02 = new Department( + 2L, "Sales", abcCompany, null); + departments.add(dept02); + Department dept03 = new Department( + 3L, "Marketing", abcCompany, null); + departments.add(dept03); + Department dept04 = new Department( + 4L, "Human Resource", abcCompany, null); + departments.add(dept04); + + Department dept11 = new Department( + 11L, "Engineering", xyzCompany, null); + departments.add(dept11); + Department dept12 = new Department( + 12L, "Human Resource", xyzCompany, null); + departments.add(dept12); + + Department dept100 = new Department( + 100L, "Unrelated", null, null); + departments.add(dept100); + + // set relatoinship Company.departments<->Department.company + // This code assumes the field Department.company is already + // initialzed on Department creation + tmp = new HashSet(); + tmp.add(dept01); + tmp.add(dept02); + tmp.add(dept03); + tmp.add(dept04); + abcCompany.setDepartments(tmp); + tmp = new HashSet(); + tmp.add(dept11); + tmp.add(dept12); + xyzCompany.setDepartments(tmp); + + // create Employee instances + + Employee emp01 = new FullTimeEmployee( + 1L, "lastEngOne", "firstEngOne", + new GregorianCalendar(2000, 0, 1).getTime(), + new GregorianCalendar(1911, 0, 1).getTime(), + 40.0D, 'F', null, null, // Projects + null, dept01, // Insurance, Department + null, null, // Manager, Team + null, null, // Mentor, Protege + null, null, // HRAdvisor, HRAdvisees + 50000.0D); + employees.add(emp01); + fullTimeEmployees.add(emp01); + Employee emp02 = new FullTimeEmployee( + 2L, "lastEngTwo", "firstEngTwo", + new GregorianCalendar(2000, 1, 2).getTime(), + new GregorianCalendar(1922, 1, 2).getTime(), + 40.0D, 'F', null, null, // Projects + null, dept01, // Insurance, Department + emp01, null, // Manager, Team + null, null, // Mentor, Protege + null, null, // HRAdvisor, HRAdvisees + 45000.0D); + employees.add(emp02); + fullTimeEmployees.add(emp02); + Employee emp03 = new PartTimeEmployee( + 3L, "lastEngThree", "firstEngThree", + new GregorianCalendar(2000, 2, 3).getTime(), + new GregorianCalendar(1933, 2, 3).getTime(), + 30.0D, 'P', null, null, // Projects + null, dept01, // Insurance, Department + emp01, null, // Manager, Team + null, null, // Mentor, Protege + null, null, // HRAdvisor, HRAdvisees + 25000.0D); + employees.add(emp03); + partTimeEmployees.add(emp03); + Employee emp04 = new FullTimeEmployee( + 4L, "lastSalesFour", "firstSalesFour", + new GregorianCalendar(2000, 3, 4).getTime(), + new GregorianCalendar(1944, 3, 4).getTime(), + 40.0D, 'F', null, null, // Projects + null, dept02, // Insurance, Department + null, null, // Manager, Team + null, null, // Mentor, Protege + null, null, // HRAdvisor, HRAdvisees + 45000.0D); + employees.add(emp04); + fullTimeEmployees.add(emp04); + Employee emp05 = new PartTimeEmployee( + 5L, "lastSalesFive", "firstSalesFive", + new GregorianCalendar(2000, 4, 5).getTime(), + new GregorianCalendar(1955, 4, 5).getTime(), + 20.0D, 'P', null, null, // Projects + null, dept02, // Insurance, Department + emp04, null, // Manager, Team + null, null, // Mentor, Protege + null, null, // HRAdvisor, HRAdvisees + 22000.0D); + employees.add(emp05); + partTimeEmployees.add(emp05); + Employee emp06 = new FullTimeEmployee( + 6L, "lastMarketingSix", "firstMarketingSix", + new GregorianCalendar(2000, 5, 6).getTime(), + new GregorianCalendar(1966, 5, 6).getTime(), + 40.0D, 'F', null, null, // Projects + null, dept03, // Insurance, Department + null, null, // Manager, Team + null, null, // Mentor, Protege + null, null, // HRAdvisor, HRAdvisees + 50000.0D); + employees.add(emp06); + fullTimeEmployees.add(emp06); + Employee emp07 = new PartTimeEmployee( + 7L, "lastMarketingSeven", "firstMarketingSeven", + new GregorianCalendar(2000, 6, 7).getTime(), + new GregorianCalendar(1977, 6, 7).getTime(), + 30.0D, 'P', null, null, // Projects + null, dept03, // Insurance, Department + emp06, null, // Manager, Team + null, null, // Mentor, Protege + null, null, // HRAdvisor, HRAdvisees + 30000.0D); + employees.add(emp07); + partTimeEmployees.add(emp07); + Employee emp08 = new FullTimeEmployee( + 8L, "lastHREight", "firstHREight", + new GregorianCalendar(2000, 7, 8).getTime(), + new GregorianCalendar(1988, 7, 8).getTime(), + 40.0D, 'F', null, null, // Projects + null, dept04, // Insurance, Department + null, null, // Manager, Team + null, null, // Mentor, Protege + null, null, // HRAdvisor, HRAdvisees + 55000.0D); + employees.add(emp08); + fullTimeEmployees.add(emp08); + Employee emp09 = new PartTimeEmployee( + 9L, "lastHRNine", "firstHRNine", + new GregorianCalendar(2000, 8, 9).getTime(), + new GregorianCalendar(1999, 8, 9).getTime(), + 30.0D, 'P', null, null, // Projects + null, dept04, // Insurance, Department + emp08, null, // Manager, Team + null, null, // Mentor, Protege + null, null, // HRAdvisor, HRAdvisees + 30000.0D); + employees.add(emp09); + partTimeEmployees.add(emp09); + + Employee emp11 = new FullTimeEmployee( + 11L, "lastEngOne", "firstEngOne", + new GregorianCalendar(1999, 0, 1).getTime(), + new GregorianCalendar(1911, 0, 1).getTime(), + 40.0D, 'F', null, null, // Projects + null, dept11, // Insurance, Department + null, null, // Manager, Team + null, null, // Mentor, Protege + null, null, // HRAdvisor, HRAdvisees + 55000.0D); + employees.add(emp11); + fullTimeEmployees.add(emp11); + Employee emp12 = new PartTimeEmployee( + 12L, "lastEngTwo", "firstEngTwo", + new GregorianCalendar(1999, 1, 2).getTime(), + new GregorianCalendar(1922, 1, 2).getTime(), + 30.0D, 'P', null, null, // Projects + null, dept11, // Insurance, Department + emp11, null, // Manager, Team + null, null, // Mentor, Protege + null, null, // HRAdvisor, HRAdvisees + 20000.0D); + employees.add(emp12); + partTimeEmployees.add(emp12); + Employee emp13 = new FullTimeEmployee( + 13L, "lastHRThree", "firstHRThree", + new GregorianCalendar(1999, 2, 3).getTime(), + new GregorianCalendar(1933, 1, 2).getTime(), + 40.0D, 'F', null, null, // Projects + null, dept12, // Insurance, Department + null, null, // Manager, Team + null, null, // Mentor, Protege + null, null, // HRAdvisor, HRAdvisees + 50000.0D); + employees.add(emp13); + fullTimeEmployees.add(emp13); + + Employee emp100 = new Employee( + 100L, "unrelated", null, + null, + null, + 0.0D, ' ', null, null, // Projects + null, null, // Insurance, Department + null, null, // Manager, Team + null, null, // Mentor, Protege + null, null); // HRAdvisor, HRAdvisees + employees.add(emp100); + + // set relationship Department.employees<->Emplyoee.department + // This code assumes the field Emplyoee.department is already + // initialzed on Emplyoee creation + tmp = new HashSet(); + tmp.add(emp01); + tmp.add(emp02); + tmp.add(emp03); + dept01.setEmployees(tmp); + tmp = new HashSet(); + tmp.add(emp04); + tmp.add(emp05); + dept02.setEmployees(tmp); + tmp = new HashSet(); + tmp.add(emp06); + tmp.add(emp07); + dept03.setEmployees(tmp); + tmp = new HashSet(); + tmp.add(emp08); + tmp.add(emp09); + dept04.setEmployees(tmp); + tmp = new HashSet(); + tmp.add(emp11); + tmp.add(emp12); + dept11.setEmployees(tmp); + tmp = new HashSet(); + tmp.add(emp13); + dept12.setEmployees(tmp); + + // set relationship Employee.manager<->Employee.team + // This code assumes the field Emplyoee.manager is already + // initialzed on Emplyoee creation. + // NOTE: there is a difference in the team relationship: + // emp02, emp03, emp05, emp07, emp09 have an empty set + // emp12, emp13 have no relationship, meaning the field is null + tmp = new HashSet(); + tmp.add(emp02); + tmp.add(emp03); + emp01.setTeam(tmp); + emp02.setTeam(new HashSet()); + emp03.setTeam(new HashSet()); + tmp = new HashSet(); + tmp.add(emp05); + emp04.setTeam(tmp); + emp05.setTeam(new HashSet()); + tmp = new HashSet(); + tmp.add(emp07); + emp06.setTeam(tmp); + emp07.setTeam(new HashSet()); + tmp = new HashSet(); + tmp.add(emp09); + emp08.setTeam(tmp); + emp09.setTeam(new HashSet()); + tmp = new HashSet(); + tmp.add(emp12); + emp11.setTeam(tmp); + emp12.setTeam(null); + emp13.setTeam(null); + + // set relationship Employee.manager<->Employee.team + emp01.setMentor(emp09); + emp09.setProtege(emp01); + emp02.setMentor(emp01); + emp01.setProtege(emp02); + emp03.setMentor(emp02); + emp02.setProtege(emp03); + emp04.setMentor(emp03); + emp03.setProtege(emp04); + emp05.setMentor(emp04); + emp04.setProtege(emp05); + emp06.setMentor(emp05); + emp05.setProtege(emp06); + emp07.setMentor(emp06); + emp06.setProtege(emp07); + emp08.setMentor(emp07); + emp07.setProtege(emp08); + emp09.setMentor(emp08); + emp08.setProtege(emp09); + emp11.setMentor(emp13); + emp13.setProtege(emp11); + emp12.setMentor(emp11); + emp11.setProtege(emp12); + emp13.setMentor(emp12); + emp12.setProtege(emp13); + + // set relationship Employee.hradvisor <-> Employee.hradvisees relationship + tmp = new HashSet(); + emp01.setHradvisor(emp08); + tmp.add(emp01); + emp02.setHradvisor(emp08); + tmp.add(emp02); + emp03.setHradvisor(emp08); + tmp.add(emp03); + emp04.setHradvisor(emp08); + tmp.add(emp04); + emp05.setHradvisor(emp08); + tmp.add(emp05); + emp06.setHradvisor(emp08); + tmp.add(emp06); + emp07.setHradvisor(emp08); + tmp.add(emp07); + emp09.setHradvisor(emp08); + tmp.add(emp09); + emp08.setHradvisees(tmp); + tmp = new HashSet(); + emp11.setHradvisor(emp13); + tmp.add(emp11); + emp12.setHradvisor(emp13); + tmp.add(emp12); + emp13.setHradvisees(tmp); + + // create Insurance instances + + Insurance ins01 = new Insurance(1L, "Carrier One", emp01); + insurances.add(ins01); + Insurance ins02 = new Insurance(2L, "Carrier Two", emp02); + insurances.add(ins02); + Insurance ins03 = new Insurance(3L, "Carrier Three", emp03); + insurances.add(ins03); + Insurance ins04 = new Insurance(4L, "Carrier Four", emp04); + insurances.add(ins04); + Insurance ins05 = new Insurance(5L, "Carrier Five", emp05); + insurances.add(ins05); + Insurance ins06 = new Insurance(6L, "Carrier Six", emp06); + insurances.add(ins06); + Insurance ins07 = new Insurance(7L, "Carrier Seven", emp07); + insurances.add(ins07); + Insurance ins08 = new Insurance(8L, "Carrier Eight", emp08); + insurances.add(ins08); + Insurance ins09 = new Insurance(9L, "Carrier Nine", emp09); + insurances.add(ins09); + + Insurance ins11 = new Insurance(11L, "Carrier Eleven", emp11); + insurances.add(ins11); + Insurance ins12 = new Insurance(12L, "Carrier Twelve", emp12); + insurances.add(ins12); + Insurance ins13 = new Insurance(13L, "Carrier Thirteen", emp13); + insurances.add(ins13); + + // set relationship Insurance.employee<->Emplyoee.insurance + // This code assumes the field Insurance.employee is already + // initialzed on Insurance creation + emp01.setInsurance(ins01); + emp02.setInsurance(ins02); + emp03.setInsurance(ins03); + emp04.setInsurance(ins04); + emp05.setInsurance(ins05); + emp06.setInsurance(ins06); + emp07.setInsurance(ins07); + emp08.setInsurance(ins08); + emp09.setInsurance(ins09); + emp11.setInsurance(ins11); + emp12.setInsurance(ins12); + emp13.setInsurance(ins13); + + // create Project instances + + Project proj01 = new Project( + 1L, "Engineering Project", new BigDecimal("10000000.0"), null, null); + projects.add(proj01); + Project proj02 = new Project( + 2L, "Sales Project", new BigDecimal("5000000.0"), null, null); + projects.add(proj02); + Project proj03 = new Project( + 3L, "Marketing Project", new BigDecimal("8000000.0"), null, null); + projects.add(proj03); + Project proj04 = new Project( + 4L, "HR Project", new BigDecimal("10000000.0"), null, null); + projects.add(proj04); + Project proj11 = new Project( + 11L, "Engineering Project", new BigDecimal("2000000.0"), null, null); + projects.add(proj11); + Project proj12 = new Project( + 12L, "HR Project", new BigDecimal("1500000.0"), null, null); + projects.add(proj12); + + // set relationship Employee.projects<->Project.employees + HashSet proj01Emps = new HashSet(); + HashSet proj02Emps = new HashSet(); + HashSet proj03Emps = new HashSet(); + HashSet proj11Emps = new HashSet(); + HashSet proj12Emps = new HashSet(); + HashSet emp01Projs = new HashSet(); + HashSet emp02Projs = new HashSet(); + HashSet emp03Projs = new HashSet(); + HashSet emp04Projs = new HashSet(); + HashSet emp05Projs = new HashSet(); + HashSet emp06Projs = new HashSet(); + HashSet emp07Projs = new HashSet(); + HashSet emp11Projs = new HashSet(); + HashSet emp12Projs = new HashSet(); + HashSet emp13Projs = new HashSet(); + + proj01Emps.add(emp01); + emp01Projs.add(proj01); + proj01Emps.add(emp02); + emp02Projs.add(proj01); + proj01Emps.add(emp03); + emp03Projs.add(proj01); + proj01Emps.add(emp04); + emp04Projs.add(proj01); + proj01Emps.add(emp06); + emp06Projs.add(proj01); + proj02Emps.add(emp01); + emp01Projs.add(proj02); + proj02Emps.add(emp06); + emp06Projs.add(proj02); + proj02Emps.add(emp04); + emp04Projs.add(proj02); + proj02Emps.add(emp05); + emp05Projs.add(proj02); + proj03Emps.add(emp01); + emp01Projs.add(proj03); + proj03Emps.add(emp04); + emp04Projs.add(proj03); + proj03Emps.add(emp06); + emp06Projs.add(proj03); + proj03Emps.add(emp07); + emp07Projs.add(proj03); + proj11Emps.add(emp11); + emp11Projs.add(proj11); + proj11Emps.add(emp12); + emp12Projs.add(proj11); + proj12Emps.add(emp13); + emp13Projs.add(proj12); + + proj01.setEmployees(proj01Emps); + proj02.setEmployees(proj02Emps); + proj03.setEmployees(proj03Emps); + proj11.setEmployees(proj11Emps); + proj12.setEmployees(proj12Emps); + emp01.setProjects(emp01Projs); + emp02.setProjects(emp02Projs); + emp03.setProjects(emp03Projs); + emp04.setProjects(emp04Projs); + emp05.setProjects(emp05Projs); + emp06.setProjects(emp06Projs); + emp07.setProjects(emp07Projs); + emp11.setProjects(emp11Projs); + emp12.setProjects(emp12Projs); + emp13.setProjects(emp13Projs); + + // set relationship Employee.reviewedProjects<->Projects.reviewers + HashSet proj01Reviewers = new HashSet(); + HashSet proj02Reviewers = new HashSet(); + HashSet proj03Reviewers = new HashSet(); + HashSet proj04Reviewers = new HashSet(); + HashSet proj11Reviewers = new HashSet(); + HashSet proj12Reviewers = new HashSet(); + HashSet emp01RevProjs = new HashSet(); + HashSet emp04RevProjs = new HashSet(); + HashSet emp06RevProjs = new HashSet(); + HashSet emp08RevProjs = new HashSet(); + HashSet emp11RevProjs = new HashSet(); + HashSet emp12RevProjs = new HashSet(); + + proj01Reviewers.add(emp01); + emp01RevProjs.add(proj01); + proj01Reviewers.add(emp04); + emp04RevProjs.add(proj01); + proj01Reviewers.add(emp06); + emp06RevProjs.add(proj01); + proj02Reviewers.add(emp04); + emp04RevProjs.add(proj03); + proj02Reviewers.add(emp06); + emp06RevProjs.add(proj02); + proj03Reviewers.add(emp04); + emp04RevProjs.add(proj03); + proj03Reviewers.add(emp06); + emp06RevProjs.add(proj03); + proj03Reviewers.add(emp08); + emp08RevProjs.add(proj03); + proj04Reviewers.add(emp08); + emp08RevProjs.add(proj04); + proj11Reviewers.add(emp12); + emp12RevProjs.add(proj11); + proj12Reviewers.add(emp11); + emp11RevProjs.add(proj12); + + proj01.setReviewers(proj01Reviewers); + proj02.setReviewers(proj02Reviewers); + proj03.setReviewers(proj03Reviewers); + proj04.setReviewers(proj04Reviewers); + proj11.setReviewers(proj11Reviewers); + proj12.setReviewers(proj12Reviewers); + emp01.setReviewedProjects(emp01RevProjs); + emp04.setReviewedProjects(emp04RevProjs); + emp06.setReviewedProjects(emp06RevProjs); + emp08.setReviewedProjects(emp08RevProjs); + emp11.setReviewedProjects(emp11RevProjs); + emp12.setReviewedProjects(emp12RevProjs); + + // create Primitive_Types instances + PrimitiveTypes prim100 = new PrimitiveTypes( + 100L, false, null, (byte)0, null, (short)0, null, 0, null, + 0L, null, 0.0F, null, 0.0, null, '0', null, + null, null, null, null, null); + primitiveTypes.add(prim100); + PrimitiveTypes prim00 = new PrimitiveTypes( + 0L, false, Boolean.FALSE, + (byte)0, new Byte((byte)0), (short)0, new Short((short)0), + 0, new Integer(0), 0L, new Long(0L), + 0.0F, new Float(0.0F), 0.0, new Double(0.0), + '0', new Character('0'), + new GregorianCalendar(2001, 0, 1).getTime(), " ", + new BigDecimal("0.0"), new BigInteger("0"), new Long(0L)); + primitiveTypes.add(prim00); + PrimitiveTypes prim01 = new PrimitiveTypes( + 1L, true, Boolean.TRUE, + (byte)1, new Byte((byte)1), (short)1, new Short((short)1), + 1, new Integer(1), 1L, new Long(1L), + 1.0F, new Float(1.0F), 1.0, new Double(1.0), + '1', new Character('1'), + new GregorianCalendar(2001, 0, 1).getTime(), "text", + new BigDecimal("1.0"), new BigInteger("1"), new Long(1L)); + primitiveTypes.add(prim01); + PrimitiveTypes prim02 = new PrimitiveTypes( + 2L, false, Boolean.FALSE, + (byte)2, new Byte((byte)2), (short)2, new Short((short)2), + 2, new Integer(2), 2L, new Long(2L), + 2.0F, new Float(2.0F), 2.0, new Double(2.0), + '2', new Character('2'), + new GregorianCalendar(2001, 1, 2).getTime(), "text", + new BigDecimal("2.0"), new BigInteger("2"), new Long(2L)); + primitiveTypes.add(prim02); + PrimitiveTypes prim03 = new PrimitiveTypes( + 3L, true, Boolean.TRUE, + (byte)3, new Byte((byte)3), (short)3, new Short((short)3), + 3, new Integer(3), 3L, new Long(3L), + 3.0F, new Float(3.0F), 3.0, new Double(3.0), + '3', new Character('3'), + new GregorianCalendar(2001, 2, 3).getTime(), "text", + new BigDecimal("3.0"), new BigInteger("3"), new Long(3L)); + primitiveTypes.add(prim03); + PrimitiveTypes prim04 = new PrimitiveTypes( + 4L, false, Boolean.FALSE, + (byte)4, new Byte((byte)4), (short)4, new Short((short)4), + 4, new Integer(4), 4L, new Long(4L), + 4.0F, new Float(4.0F), 4.0, new Double(4.0), + '4', new Character('4'), + new GregorianCalendar(2001, 3, 4).getTime(), "text", + new BigDecimal("4.0"), new BigInteger("4"), new Long(4L)); + primitiveTypes.add(prim04); + PrimitiveTypes prim05 = new PrimitiveTypes( + 5L, true, Boolean.TRUE, + (byte)5, new Byte((byte)5), (short)5, new Short((short)5), + 5, new Integer(5), 5L, new Long(5L), + 5.0F, new Float(5.0F), 5.0, new Double(5.0), + '5', new Character('5'), + new GregorianCalendar(2001, 4, 5).getTime(), "text", + new BigDecimal("5.0"), new BigInteger("5"), new Long(5L)); + primitiveTypes.add(prim05); + PrimitiveTypes prim10 = new PrimitiveTypes( + 10L, false, Boolean.FALSE, + (byte)127, new Byte((byte)127), (short)32767, new Short((short)32767), + 2147483647, new Integer(2147483647), 9223372036854775807L, new Long(9223372036854775807L), + 1.2345F, new Float(1.2345F), 1.2345, new Double(1.2345), + 'a', new Character('a'), + new GregorianCalendar(2001, 5, 6).getTime(), "this is a string", + new BigDecimal("10000.123"), new BigInteger("10000"), new Long(10L)); + primitiveTypes.add(prim10); + PrimitiveTypes prim11 = new PrimitiveTypes( + 11L, true, Boolean.TRUE, + (byte)-128, new Byte((byte)-128), (short)-32767, new Short((short)-32767), + -2147483648, new Integer(-2147483648), -9223372036854775808L, new Long(-9223372036854775808L), + -1.2345F, new Float(-1.2345F), -1.2345, new Double(-1.2345), + 'A', new Character('A'), + new GregorianCalendar(2001, 6, 7).getTime(), "this is a string", + new BigDecimal("-10000.123"), new BigInteger("-10000"), new Long(11L)); + primitiveTypes.add(prim11); + PrimitiveTypes prim12 = new PrimitiveTypes( + 12L, false, Boolean.FALSE, + (byte)0, new Byte((byte)0), (short)0, new Short((short)0), + 0, new Integer(0), 0L, new Long(0L), + 0.00005F, new Float(0.00005F), 0.000000005, new Double(0.000000005), + '0', new Character('0'), + new GregorianCalendar(2001, 7, 8).getTime(), "yet another string", + new BigDecimal("0.0"), new BigInteger("0"), new Long(0L)); + primitiveTypes.add(prim12); + PrimitiveTypes prim13 = new PrimitiveTypes( + 13L, false, Boolean.FALSE, + (byte)0, new Byte((byte)0), (short)0, new Short((short)0), + 0, new Integer(0), 0L, new Long(0L), + -0.00005F, new Float(-0.00005F), -0.000000005, new Double(-0.000000005), + '0', new Character('0'), + new GregorianCalendar(2001, 8, 9).getTime(), "yet another string", + new BigDecimal("0.0"), new BigInteger("0"), new Long(0L)); + primitiveTypes.add(prim13); + PrimitiveTypes prim14 = new PrimitiveTypes( + 14L, false, Boolean.FALSE, + (byte)0, new Byte((byte)0), (short)0, new Short((short)0), + 0, new Integer(0), 0L, new Long(0L), + 1234567.8F, new Float(1234567.8F), 1234567890000.5, new Double(1234567890000.5), + '0', new Character('0'), + new GregorianCalendar(2001, 9, 10).getTime(), "yet another string", + new BigDecimal("0.0"), new BigInteger("0"), new Long(0L)); + primitiveTypes.add(prim14); + PrimitiveTypes prim15 = new PrimitiveTypes( + 15L, false, Boolean.FALSE, + (byte)0, new Byte((byte)0), (short)0, new Short((short)0), + 0, new Integer(0), 0L, new Long(0L), + -1234567.8F, new Float(-1234567.8F), -1234567890000.5, new Double(-1234567890000.5), + '0', new Character('0'), + new GregorianCalendar(2001, 11, 12).getTime(), "yet another string", + new BigDecimal("0.0"), new BigInteger("0"), new Long(0L)); + primitiveTypes.add(prim15); + } + +} Added: incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/Test_Reachability.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/Test_Reachability.java?view=auto&rev=158176 ============================================================================== --- incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/Test_Reachability.java (added) +++ incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/Test_Reachability.java Fri Mar 18 17:02:29 2005 @@ -0,0 +1,304 @@ +/* + * 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.test; + +import java.util.GregorianCalendar; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.Map; +import java.util.TimeZone; + +import javax.jdo.JDOHelper; +import javax.jdo.PersistenceManager; +import javax.jdo.Transaction; + +import org.apache.jdo.pc.PCDepartment1; +import org.apache.jdo.pc.PCEmployee1; +import org.apache.jdo.pc.PCInsurance1; +import org.apache.jdo.pc.PCPoint; +import org.apache.jdo.pc.PCProject1; +import org.apache.jdo.test.util.AbstractTest; +import org.apache.jdo.test.util.JDORITestRunner; + +/** +* Test a reachability algorithm for PC that has some fields which +* are Collections or PC's. +* +* @author Marina Vatkina +* @version 1.0.1 +*/ +public class Test_Reachability extends AbstractTest { + + PCEmployee1 scott; + PCEmployee1 ed; + PCEmployee1 admin; + + PCDepartment1 board; + PCDepartment1 emg; + + PCInsurance1 scottIns; + PCInsurance1 edIns; + PCInsurance1 adminIns; + + PCProject1 solaris; + PCProject1 sparc; + + Object adminKey; + + Object scottOid; + Object edOid; + + /** */ + public static void main(String args[]) { + JDORITestRunner.run(Test_Reachability.class); + } + + /** */ + public void test() { + createObjects(); + insertObjects(); + checkExtent(PCEmployee1.class, 2); + checkExtent(PCDepartment1.class, 2); + checkExtent(PCInsurance1.class, 1); + checkExtent(PCProject1.class, 2); + checkExtent(PCPoint.class, 3); + readObjects(); + } + + // We override this from Test_ActivateClass and insert our own objects. + // Use Test_Extent to read them back. + protected void createObjects() { + HashSet h; + Map m; + LinkedList l; + Object[] a; + + // Create and set up employees. Scott is Ed's manager. Ed is + // Scott's sole employee. Admin reports to Ed. + // + GregorianCalendar born = + new GregorianCalendar(TimeZone.getTimeZone("America/New_York")); + GregorianCalendar hired = + new GregorianCalendar(TimeZone.getTimeZone("America/New_York")); + + born.set(1969, 7, 20); + hired.set(1982, 5, 5); + scott = new PCEmployee1(1L, "McNealy", "Scott", 200000.0, + born.getTime(), hired.getTime()); + born.set(1960, 4, 8); + hired.set(1985, 2, 3); + ed = new PCEmployee1(100L, "Zander", "Ed", 400000.0, + born.getTime(), hired.getTime()); + born.set(1980, 10, 18); + hired.set(1998, 5, 3); + admin = new PCEmployee1(99100L, "Clark", "Jane", 50000.0, + born.getTime(), hired.getTime()); + + // Set up their departments. + board = new PCDepartment1(100L, "board"); + h = new HashSet(); + h.add(scott); + board.setEmployees(h); + scott.setDepartment(board); + + emg = new PCDepartment1(200L, "emg"); + h = new HashSet(); + h.add(ed); + h.add(admin); + emg.setEmployees(h); + ed.setDepartment(emg); + admin.setDepartment(emg); + + // Insure these guys + scottIns = new PCInsurance1(1000, "Aetna", scott); + edIns = new PCInsurance1(1001, "BlueCross", ed); + adminIns = new PCInsurance1(2001, "BlueCross", admin); + scott.setInsurance(scottIns); + ed.setInsurance(edIns); + admin.setInsurance(adminIns); + + // Give them some projects to work on. Scott works on both; Ed and admin + // only on one. + solaris = new PCProject1(1L, "Solaris"); + sparc = new PCProject1(2L, "Sparc"); + + m = new HashMap(); + m.put(new PCPoint(2, 111), scott); + m.put(new PCPoint(10, 110), ed); + adminKey=new PCPoint(99, 999); + m.put(adminKey, admin); + solaris.setEmployees(m); // Solaris is worked on by Scott, Ed, and Admin + + m = new HashMap(); + m.put(new PCPoint(1, 112), scott); + sparc.setEmployees(m); // Sparc is worked on by Scott + + l = new LinkedList(); + l.add(solaris); + l.add(sparc); + scott.setProjects(l); // Scott works on Solaris and Sparc + + l = new LinkedList(); + l.add(solaris); + ed.setProjects(l); // Ed works on Solaris + admin.setProjects(l); // Admin works on Solaris + + // Set managers: + ed.setManager(scott); + admin.setManager(ed); + + a = new PCEmployee1[1]; + a[0] = ed; + scott.setEmployees(a); + + a = new PCEmployee1[1]; + a[0] = admin; + ed.setEmployees(a); + + // Show what we've got + if (debug) { + logger.debug("Before insert: "); + printObjects(); + } + } + + protected void insertObjects() { + PersistenceManager pm = null; + Transaction tx = null; + try { + pm = pmf.getPersistenceManager(); + tx = pm.currentTransaction(); + tx.begin(); + + // Make it all persistent. If reachability were implemented, we'd + // only have to make scott and ed persistent, as everything else is + // reachable from them. + pm.makePersistent(board); + pm.makePersistent(emg); + + sparc.setName("SPARC"); + + // Show what we have + if (debug) { + logger.debug("\nAfter insert and update: "); + printObjects(); + } + + // Scott's insurance is not reachable any more: + scott.setInsurance(null); + + // Admin and her insurance are not reachable any more: + emg.getEmployees().remove(admin); + solaris.getEmployees().remove(adminKey); + pm.deletePersistent(admin); + + // Show what we have now + if (debug) { + logger.debug("\nBefore commit: "); + printObjects(); + } + + tx.commit(); + + scottOid = JDOHelper.getObjectId(scott); + edOid = JDOHelper.getObjectId(ed); + + // Show with what we ended + if (debug) { + logger.debug("\nAfter commit: "); + printObjects(); + } + } + finally { + if (tx != null && tx.isActive()) + tx.rollback(); + if (pm != null && !pm.isClosed()) + pm.close(); + } + } + + protected void readObjects() { + PersistenceManager pm = null; + Transaction tx = null; + try { + pm = pmf.getPersistenceManager(); + tx = pm.currentTransaction(); + tx.begin(); + + scott = (PCEmployee1)pm.getObjectById(scottOid, true); + ed = (PCEmployee1)pm.getObjectById(edOid, true); + if (debug) { + logger.debug("\nload scott and ed: "); + logger.debug(scott.toString()); + logger.debug(ed.toString()); + } + + // check scott + assertEquals("Wrong string representation of scott", + "Emp: McNealy, Scott, id=1, born 20/Aug/1969, hired 5/Jun/1982 $200000.0 manager: none dept: board emps: 1 insurance: null", + scott.toString()); + assertEquals("Wrong string representation of ed", + "Emp: Zander, Ed, id=100, born 8/May/1960, hired 3/Mar/1985 $400000.0 manager: McNealy dept: emg emps: 1 insurance: BlueCross", + ed.toString()); + + // check departments + assertEquals("Wrong string representation of board department", + "Dept: board, id=100, emps: 1", + scott.getDepartment().toString()); + assertEquals("Wrong string representation of emg department", + "Dept: emg, id=200, emps: 1", + ed.getDepartment().toString()); + + // check insurances + assertEquals("Wrong string representation of blue cross insurance", + "Ins: BlueCross, id=1001, emp Zander", + ed.getInsurance().toString()); + + // check projects + assertEquals("Wrong string representation of scotts projects", + "[Project: Solaris, id=1, emps: 2, Project: SPARC, id=2, emps: 1]", + scott.getProjects().toString()); + assertEquals("Wrong string representation of scotts projects", + "[Project: Solaris, id=1, emps: 2]", + ed.getProjects().toString()); + } + finally { + if (tx != null && tx.isActive()) + tx.rollback(); + if (pm != null && !pm.isClosed()) + pm.close(); + } + } + + private void printObjects() { + logger.debug(scott.toString()); + logger.debug(ed.toString()); + try { + logger.debug(admin.toString()); + } catch (Exception e) { + // Ignore - it was about deleted instance. + } + logger.debug(board.toString()); + logger.debug(emg.toString()); + logger.debug(scottIns.toString()); + logger.debug(edIns.toString()); + logger.debug(adminIns.toString()); + logger.debug(solaris.toString()); + logger.debug(sparc.toString()); + } +} Added: incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/Test_Rect.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/Test_Rect.java?view=auto&rev=158176 ============================================================================== --- incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/Test_Rect.java (added) +++ incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/Test_Rect.java Fri Mar 18 17:02:29 2005 @@ -0,0 +1,116 @@ +/* + * 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.test; + +import javax.jdo.JDOHelper; +import javax.jdo.PersistenceManager; +import javax.jdo.Transaction; + +import org.apache.jdo.pc.PCPoint; +import org.apache.jdo.pc.PCRect; +import org.apache.jdo.test.util.JDORITestRunner; + +/** +* Test a PC that has some fields which are PC's. +* +* @author Dave Bristor +*/ +public class Test_Rect extends Test_Fetch { + + /** */ + public static void main(String args[]) { + JDORITestRunner.run(Test_Rect.class); + } + + /** */ + public void test() throws Exception { + insertObjects(); + readObjects(); + checkExtent(PCPoint.class, 2); + checkExtent(PCRect.class, 1); + writeOIDs(); + } + + /** We override this to insert our own objects. */ + protected void insertObjects() { + PersistenceManager pm = pmf.getPersistenceManager(); + Transaction tx = pm.currentTransaction(); + try { + tx.begin(); + + PCPoint p1 = new PCPoint(1, 3); + PCPoint p2 = new PCPoint(13, 42); + PCRect pcRect = new PCRect(p1, p2); + + if (debug) logger.debug("Before insert: " + pcRect); + // Next 2 statements allow this test to work whether or not + // reachability or navigation work. + pm.makePersistent(p1); + pm.makePersistent(p2); + pm.makePersistent(pcRect); + + tx.commit(); + + // Next 4 statements allow this test to work whether or not + // reachability or navigation work. + Object oid_p1 = JDOHelper.getObjectId(p1); + Object oid_p2 = JDOHelper.getObjectId(p2); + oids.add(oid_p1); + oids.add(oid_p2); + + Object oid1 = JDOHelper.getObjectId(pcRect); + if (debug) logger.debug("inserted pcRect: " + oid1); + oids.add(oid1); + } + finally { + if (tx != null && tx.isActive()) + tx.rollback(); + if (pm != null && !pm.isClosed()) + pm.close(); + } + } + + /** + * redefine verify called by readObjects to check whether the read + * instance is correct. + */ + protected void verify(int i, Object pc) { + if (debug) logger.debug("verify (i = " + i + ") " + pc); + PCPoint p1 = null; + PCPoint p2 = null; + // PCPoint and PCRect do not redefine equals, so use the string representation. + switch(i) { + case 0 : + p1 = new PCPoint(1, 3); + assertEquals("Wrong instance returned from datastore", p1.toString(), pc.toString()); + break; + case 1: + p2 = new PCPoint(13, 42); + assertEquals("Wrong instance returned from datastore", p2.toString(), pc.toString()); + break; + case 2: + p1 = new PCPoint(1, 3); + p2 = new PCPoint(13, 42); + PCRect pcRect = new PCRect(p1, p2); + assertEquals("Wrong instance returned from datastore", pcRect.toString(), pc.toString()); + break; + default: + fail("Wrong number of inserted objects, expected three"); + break; + } + } +} Added: incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/Test_RectAppId.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/Test_RectAppId.java?view=auto&rev=158176 ============================================================================== --- incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/Test_RectAppId.java (added) +++ incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/Test_RectAppId.java Fri Mar 18 17:02:29 2005 @@ -0,0 +1,137 @@ +/* + * 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.test; + +import java.util.Iterator; +import java.util.TreeMap; + +import javax.jdo.Extent; +import javax.jdo.PersistenceManager; +import javax.jdo.Transaction; + +import org.apache.jdo.pc.appid.PCPoint; +import org.apache.jdo.pc.appid.PCRect; +import org.apache.jdo.test.util.AbstractTest; +import org.apache.jdo.test.util.JDORITestRunner; + +/** +* Test a PC with application identity that has some fields which are PC's. +* +* @author Marina Vatkina +*/ +public class Test_RectAppId extends AbstractTest { + + /** */ + public static void main(String args[]) { + JDORITestRunner.run(Test_RectAppId.class); + } + + /** The idea is that we're going to write a bunch of stuff to a data + * store, then read it back in; we should get the same data back. + */ + public void test() throws Exception { + insertObjects(); + } + + /** We override this to insert our own objects */ + protected void insertObjects() { + PersistenceManager pm = pmf.getPersistenceManager(); + Transaction tx = pm.currentTransaction(); + try { + if (debug) logger.debug("INSERT"); + tx.begin(); + + PCPoint p1 = new PCPoint(1, 3); + PCPoint p2 = new PCPoint(13, 42); + PCRect pcRect = new PCRect(1, p1, p2); + + if (debug) logger.debug("Before insert: " + pcRect); + + pm.makePersistent(pcRect); + if (debug) { + logger.debug("After makePersistent pcRect OID: " + + pm.getObjectId(pcRect)); + logger.debug("After makePersistent p1 OID: " + + pm.getObjectId(p1)); + logger.debug("After makePersistent p2 OID: " + + pm.getObjectId(p2)); + } + + tx.commit(); tx = null; + + loadAndVerifyObject(p1, pm); + loadAndVerifyObject(p2, pm); + loadAndVerifyObject(pcRect, pm); + + pm.close(); pm = null; + + if (debug) logger.debug("EXTENT PCRect"); + pm = pmf.getPersistenceManager(); + tx = pm.currentTransaction(); + Extent ext = + pm.getExtent(org.apache.jdo.pc.appid.PCRect.class, false); + for (Iterator i = ext.iterator(); i.hasNext();) { + Object p = i.next(); + if (debug) logger.debug("Fetched: " + p); + loadAndVerifyObject(p, pm); + } + + if (debug) logger.debug("EXTENT PCPoint"); + ext = pm.getExtent(org.apache.jdo.pc.appid.PCPoint.class, false); + TreeMap elements = new TreeMap(); // Sort the results. + for (Iterator i = ext.iterator(); i.hasNext();) { + PCPoint p = (PCPoint)i.next(); + elements.put(p.toString(), p); + } + + for (Iterator i = elements.values().iterator(); i.hasNext();) { + Object p = i.next(); + if (debug) logger.debug("Fetched: " + p); + loadAndVerifyObject(p, pm); + } + } + finally { + if (tx != null && tx.isActive()) + tx.rollback(); + if (pm != null && !pm.isClosed()) + pm.close(); + } + } + + /** */ + void loadAndVerifyObject(Object obj, PersistenceManager pm) { + Object oid = pm.getObjectId(obj); + if (debug) logger.debug("Instance OID: " + oid); + + PersistenceManager pm1 = null; + try { + pm1 = pmf.getPersistenceManager(); + Object obj1 = pm1.getObjectById(oid, true); + if (debug) logger.debug("Instance from OID: " + obj1); + assertEquals("Wrong string represenatation of loaded instance", + obj.toString(), obj1.toString()); + Object oid1 = pm1.getObjectId(obj1); + if (debug) logger.debug("OID from instance: " + oid1); + assertEquals("OID from instance not equal", oid, oid1); + } + finally { + if (pm1 != null && !pm1.isClosed()) + pm1.close(); + } + } + +} Added: incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/Test_RefArrays.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/Test_RefArrays.java?view=auto&rev=158176 ============================================================================== --- incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/Test_RefArrays.java (added) +++ incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/Test_RefArrays.java Fri Mar 18 17:02:29 2005 @@ -0,0 +1,122 @@ +/* + * 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.test; + +import javax.jdo.JDOHelper; +import javax.jdo.PersistenceManager; +import javax.jdo.Transaction; + +import org.apache.jdo.pc.PCPoint; +import org.apache.jdo.pc.PCRefArrays; +import org.apache.jdo.test.util.JDORITestRunner; + +/** +* Test that we can store and fetch an array of object references. +* +* @author Dave Bristor +*/ +public class Test_RefArrays extends Test_Fetch { + + /** */ + public static void main(String args[]) { + JDORITestRunner.run(Test_RefArrays.class); + } + + /** */ + public void test() throws Exception { + insertObjects(); + readObjects(); + checkExtent(PCPoint.class, 2); + checkExtent(PCRefArrays.class, 1); + } + + /** We override this from Test_ActivateClass and insert our own objects */ + protected void insertObjects() { + PersistenceManager pm = pmf.getPersistenceManager(); + Transaction tx = pm.currentTransaction(); + try { + tx.begin(); + + PCPoint p1 = new PCPoint(1, 3); + PCPoint p2 = new PCPoint(13, 42); + PCRefArrays refArrays = new PCRefArrays(); + refArrays.init(p1, p2); + + if (debug) logger.debug("Before insert: " + refArrays); + + // Next 2 statements allow this test to work whether or not + // reachability or navigation work. + pm.makePersistent(p1); + pm.makePersistent(p2); + + pm.makePersistent(refArrays); + tx.commit(); + + // Next 4 statements allow this test to work whether or not + // reachability or navigation work. + Object oid_p1 = JDOHelper.getObjectId(p1); + Object oid_p2 = JDOHelper.getObjectId(p2); + oids.add(oid_p1); + oids.add(oid_p2); + + Object oid1 = JDOHelper.getObjectId(refArrays); + if (debug) logger.debug("inserted refArrays: " + oid1); + oids.add(oid1); + } + finally { + if (tx != null && tx.isActive()) + tx.rollback(); + if (pm != null && !pm.isClosed()) + pm.close(); + } + } + + /** + * redefine verify called by readObjects to check whether the read + * instance is correct. + */ + protected void verify(int i, Object pc) { + if (debug) logger.debug("verify (i = " + i + ") " + pc); + PCPoint p1 = null; + PCPoint p2 = null; + // PCPoint and PCRefArrays do not redefine equals, + // so use the string representation. + switch(i) { + case 0 : + p1 = new PCPoint(1, 3); + assertEquals("Wrong instance returned from datastore", + p1.toString(), pc.toString()); + break; + case 1: + p2 = new PCPoint(13, 42); + assertEquals("Wrong instance returned from datastore", + p2.toString(), pc.toString()); + break; + case 2: + p1 = new PCPoint(1, 3); + p2 = new PCPoint(13, 42); + PCRefArrays refArrays = new PCRefArrays(); + refArrays.init(p1, p2); + assertEquals("Wrong instance returned from datastore", + refArrays.toString(), pc.toString()); + break; + default: + fail("Wrong number of inserted objects, expected three"); + break; + } + } +}