From jdo-commits-return-557-apmail-db-jdo-commits-archive=www.apache.org@db.apache.org Sun May 22 19:07:59 2005 Return-Path: Delivered-To: apmail-db-jdo-commits-archive@www.apache.org Received: (qmail 63408 invoked from network); 22 May 2005 19:07:59 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 22 May 2005 19:07:59 -0000 Received: (qmail 15340 invoked by uid 500); 22 May 2005 19:07:57 -0000 Mailing-List: contact jdo-commits-help@db.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: jdo-dev@db.apache.org Delivered-To: mailing list jdo-commits@db.apache.org Received: (qmail 15296 invoked by uid 99); 22 May 2005 19:07:56 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Sun, 22 May 2005 12:07:47 -0700 Received: (qmail 56834 invoked by uid 65534); 22 May 2005 18:41:06 -0000 Message-ID: <20050522184106.56833.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: svn commit: r171355 [16/31] - in /incubator/jdo/trunk/fostore20: ./ src/ src/conf/ src/java/ src/java/org/ src/java/org/apache/ src/java/org/apache/jdo/ src/java/org/apache/jdo/impl/ src/java/org/apache/jdo/impl/fostore/ test/ test/conf/ test/fsuid2/ test/fsuid2/org/ test/fsuid2/org/apache/ test/fsuid2/org/apache/jdo/ test/fsuid2/org/apache/jdo/pc/ test/java/ test/java/org/ test/java/org/apache/ test/java/org/apache/jdo/ test/java/org/apache/jdo/impl/ test/java/org/apache/jdo/impl/fostore/ test/java/org/apache/jdo/pc/ test/java/org/apache/jdo/pc/appid/ test/java/org/apache/jdo/pc/empdept/ test/java/org/apache/jdo/pc/serializable/ test/java/org/apache/jdo/pc/xempdept/ test/java/org/apache/jdo/test/ test/java/org/apache/jdo/test/query/ test/java/org/apache/jdo/test/util/ test/jdo/ test/jdo/org/ test/jdo/org/apache/ test/jdo/org/apache/jdo/ test/jdo/org/apache/jdo/pc/ test/jdo/org/apache/jdo/pc/appid/ test/jdo/org/apache/jdo/pc/empdept/ test/jdo/org/apache/jdo/pc/serializable/ test/jdo/org/apache/jdo/pc/xempdept/ Date: Sun, 22 May 2005 18:40:21 -0000 To: jdo-commits@db.apache.org From: mbo@apache.org X-Mailer: svnmailer-1.0.0-dev X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Added: incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_451= 0817.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/fostore20/test/java/= org/apache/jdo/test/Test_4510817.java?rev=3D171355&view=3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_451081= 7=2Ejava (added) +++ incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_451081= 7=2Ejava Sun May 22 11:40:13 2005 @@ -0,0 +1,57 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + +package org.apache.jdo.test; + +import javax.jdo.PersistenceManager; + +import org.apache.jdo.test.util.AbstractTest; +import org.apache.jdo.test.util.JDORITestRunner; + +/** + * Test fix for bug 4510817: Ensure that PersistenceManager.getObjectIdCla= ss + * returns null when given class does not implement PersistenceCapable or = is + * null. + */ +public class Test_4510817 extends AbstractTest { + =20 + /** */ + public static void main(String args[]) { + JDORITestRunner.run(Test_4510817.class); + } + + /** */ + public void test() { + PersistenceManager pm =3D pmf.getPersistenceManager(); + + try { + // First case: Given class does not implement PersistenceCapab= le. + Class c1 =3D pm.getObjectIdClass(Thread.class); + assertNull("ObjectIdClass for Thread.class is not null: " + c1= , c1); + + // Second case: Given parameter is null. + Class c2 =3D pm.getObjectIdClass(null); + assertNull("ObjectIdClass for null is not null: " + c2, c2); + + if (debug) + logger.debug("Success: ObjectIdClass for Thread.class and = null returns null"); + } + finally { + if (pm !=3D null && !pm.isClosed()) + pm.close(); + } + } +} Added: incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_451= 5265.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/fostore20/test/java/= org/apache/jdo/test/Test_4515265.java?rev=3D171355&view=3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_451526= 5=2Ejava (added) +++ incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_451526= 5=2Ejava Sun May 22 11:40:13 2005 @@ -0,0 +1,96 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + +package org.apache.jdo.test; + +import javax.jdo.*; + +import org.apache.jdo.test.util.AbstractTest; +import org.apache.jdo.test.util.JDORITestRunner; + +/** + * Test fix for bug 4515265: StoreManager.getClassForOid must throw + * JDOUserException if given parameter is not an OID (spec section 12.5.6). + */ +public class Test_4515265 extends AbstractTest { + + /** */ + public static void main(String args[]) { + JDORITestRunner.run(Test_4515265.class); + } + + // Test different wrong cases of application identity: + class PCPointKey { + int x; + Integer y; + + PCPointKey(int _x, int _y) { + x =3D _x; + y =3D new Integer(_y); + } + } + =20 + class Oid { + int x; + Integer y; + + Oid(int _x, int _y) { + x =3D _x; + y =3D new Integer(_y); + } + } + =20 + public void test() { + Oid oid =3D new Oid(1, 1); + PCPointKey key =3D new PCPointKey(1, 1); + + PersistenceManager pm =3D pmf.getPersistenceManager(); + + try { + try { + pm.getObjectById(key, true); + fail("getObjectById should throw an exception or non-exist= ing PC Class."); + } catch (JDOUserException ex) { + // expected exception =3D> OK + if (debug) + logger.debug("Caught expected JDOUserException for non= -existing PC Class."); + } + + try { + pm.getObjectById(oid, true);=20 + fail("getObjectById should throw an exception for non-PC C= lass.");=20 + } catch (JDOUserException ex) { + // expected exception =3D> OK + if (debug) + logger.debug("Caught expected JDOUserException for non= -PC Class."); + } + + try { + pm.getObjectById(this, true); + fail("getObjectById should throw an exception for wrong OI= D Class name."); + } catch (JDOUserException ex) { + // expected exception =3D> OK + if (debug) + logger.debug("Caught expected JDOUserException for wro= ng OID Class name."); + } + } + finally { + if (pm !=3D null && !pm.isClosed()) + pm.close(); + } + + } +} Added: incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_621= 4617.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/fostore20/test/java/= org/apache/jdo/test/Test_6214617.java?rev=3D171355&view=3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_621461= 7=2Ejava (added) +++ incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_621461= 7=2Ejava Sun May 22 11:40:13 2005 @@ -0,0 +1,56 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + +package org.apache.jdo.test; + +import javax.jdo.PersistenceManager; +import javax.jdo.JDOUserException; + +import org.apache.jdo.test.util.AbstractTest; +import org.apache.jdo.test.util.JDORITestRunner; + +/** + * Test fix for bug 6214617: the pm is still open after pm.close fails + * because of an active transaction.=20 + */ +public class Test_6214617 extends AbstractTest { + =20 + /** */ + public static void main(String args[]) { + JDORITestRunner.run(Test_6214617.class); + } + + /** */ + public void test() { + PersistenceManager pm =3D pmf.getPersistenceManager(); + try { + pm.currentTransaction().begin(); + pm.close(); // fails because tx is still active + } + catch (JDOUserException ex) { + // expected exception: cannot close pm while tx is active + if (debug)=20 + logger.debug("Caught expected JDOUserException cannot clos= e pm while tx is active"); + } + finally { + // should succeed + pm.currentTransaction().rollback(); + pm.close(); + if (debug)=20 + logger.debug("Could rollback tx and close pm"); + } + } +} Added: incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_Act= ivateClass.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/fostore20/test/java/= org/apache/jdo/test/Test_ActivateClass.java?rev=3D171355&view=3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_Activa= teClass.java (added) +++ incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_Activa= teClass.java Sun May 22 11:40:13 2005 @@ -0,0 +1,55 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + +package org.apache.jdo.test; + +import org.apache.jdo.test.util.AbstractTest; +import org.apache.jdo.test.util.JDORITestRunner; + +import org.apache.jdo.test.util.Factory; +import org.apache.jdo.pc.PointFactory; + +/** +* Tests that we can activate a class. Actually goes farther than that, +* storing the value of an instance of a class, since that's the only way w= e can +* cause a class to be activated. +* +* @author Dave Bristor +*/ +public class Test_ActivateClass extends AbstractTest { + + /** */ + public static void main(String args[]) { + JDORITestRunner.run(Test_ActivateClass.class); + } + + /** + * Inserts some number of objects in the database + */ + public void test() throws Exception { + insertObjects(); + } + + /** + * Determines the kind of objects that are inserted. Override this if + * you want to insert some other kind of object. + */ + protected Factory getFactory(int verify) { + PointFactory rc =3D new PointFactory(); + rc.setVerify(verify); + return rc; + } +} Added: incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_App= Id.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/fostore20/test/java/= org/apache/jdo/test/Test_AppId.java?rev=3D171355&view=3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_AppId.= java (added) +++ incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_AppId.= java Sun May 22 11:40:13 2005 @@ -0,0 +1,177 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + +package org.apache.jdo.test; + +import java.util.*; + +import javax.jdo.*; + +import org.apache.jdo.pc.PCPoint1; +import org.apache.jdo.pc.PCPoint1Key; + +import org.apache.jdo.test.util.AbstractTest; +import org.apache.jdo.test.util.JDORITestRunner; + +/** +* Tests that FOStore can perform insert/update/fetch/delete for=20 +* an instance with application identity. +* +* @author Marina Vatkina +*/ +public class Test_AppId extends AbstractTest { + + /** */ + public static void main(String args[]) { + JDORITestRunner.run(Test_AppId.class); + } + + /** */ + public void test() { + + int start =3D -numInsert; + int end =3D numInsert + 1; // exclusive! + int nrOfObjects =3D end - start; + PCPoint1Key pk =3D new PCPoint1Key(); + =20 + PersistenceManager pm =3D pmf.getPersistenceManager(); + Transaction tx =3D pm.currentTransaction(); + =20 + try { + if (debug){ + logger.debug("=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D"); + logger.debug("INSERT"); + } + =20 + tx.begin(); + for (int i =3D start; i < end; i++) { + PCPoint1 p =3D new PCPoint1(i,10*i); + pm.makePersistent(p); + if (debug) logger.debug("Inserting: " + p); + } + tx.commit(); tx =3D null; + pm.close(); pm =3D null; + + if (debug){ + logger.debug("=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D"); + logger.debug("UPDATE"); + } + + pm =3D pmf.getPersistenceManager(); + tx =3D pm.currentTransaction(); + tx.begin(); + for (int i =3D start; i < end; i++) { + pk.x =3D i; + PCPoint1 p =3D (PCPoint1)pm.getObjectById(pk, true); + p.setY(new Integer(i+100)); + if (debug) logger.debug("Updating: " + p); + if (debug) printObject(p, pm); + } + tx.commit(); tx =3D null; + pm.close(); pm =3D null; + =20 + if (debug) { + logger.debug("=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D"); + logger.debug("EXTENT"); + } + =20 + pm =3D pmf.getPersistenceManager(); + List list =3D new ArrayList(); + Extent ext =3D pm.getExtent(org.apache.jdo.pc.PCPoint1.class, = false); + for (java.util.Iterator i =3D ext.iterator(); i.hasNext();) { + PCPoint1 p =3D (PCPoint1)i.next(); + if (debug) logger.debug("Fetched: " + p); + if (debug) printObject(p, pm); + list.add(p); + } + Collections.sort(list, new PCPoint1Comparator()); + assertEquals("Extent has wrong size", nrOfObjects, list.size()= ); + for (int i =3D start; i < end; i++) { + PCPoint1 p =3D (PCPoint1)list.get(i - start); + assertEquals("Wrong value of PCPoint1.x", i, p.getX()); + assertEquals("Wrong value of PCPoint1.y", (i+100), p.getY(= )=2EintValue()); + } + pm.close(); pm =3D null; + =20 + if (debug) { + logger.debug("=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D"); + logger.debug("DELETE"); + } + =20 + pm =3D pmf.getPersistenceManager(); + tx =3D pm.currentTransaction(); + tx.begin(); + for (int i =3D start; i < end; i++) { + pk.x =3D i; + PCPoint1 p =3D (PCPoint1)pm.getObjectById(pk, true); + if (debug) logger.debug("Deleting: " + p); + if (debug) printObject(p, pm); + pm.deletePersistent(p); + } + tx.commit(); tx =3D null; + pm.close(); pm =3D null; + =20 + if (debug) { + logger.debug("=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D"); + logger.debug("CHECK DELETED"); + } + + pm =3D pmf.getPersistenceManager(); + for (int i =3D start; i < end; i++) { + pk.x =3D i; + try { + PCPoint1 p =3D (PCPoint1)pm.getObjectById(pk, true); + fail("Object with primary key " + pk + " was found: " = + p); + } catch (JDODataStoreException ex) { + // expected exception =3D> OK; + if (debug) logger.debug("Deleted " + pk); + } + } + pm.close(); pm =3D null; + } + finally { + if (tx !=3D null && tx.isActive()) + tx.rollback(); + if (pm !=3D null && !pm.isClosed()) + pm.close(); + } + } + + void printObject(PCPoint1 p, PersistenceManager pm) { + Object oid =3D pm.getObjectId(p); + logger.debug("Instance OID: " + oid); + + PersistenceManager pm1 =3D pmf.getPersistenceManager(); + Object o =3D pm1.getObjectById(oid, true); + logger.debug("Instance from OID: " + o); + logger.debug("OID from instance: " + pm1.getObjectId(o)); + pm1.close(); + } + + static class PCPoint1Comparator implements Comparator + { + public int compare(Object o1, Object o2) { + if (!(o1 instanceof PCPoint1)) + throw new ClassCastException("instance " + o1 + + " + is not a PCPoint1 instance"); + if (!(o2 instanceof PCPoint1)) + throw new ClassCastException("instance " + o2 + + " + is not a PCPoint1 instance"); + return new Integer(((PCPoint1)o1).getX()).compareTo( + new Integer(((PCPoint1)o2).getX())); + } + } +} Added: incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_Arr= ays.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/fostore20/test/java/= org/apache/jdo/test/Test_Arrays.java?rev=3D171355&view=3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_Arrays= .java (added) +++ incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_Arrays= .java Sun May 22 11:40:13 2005 @@ -0,0 +1,80 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + +package org.apache.jdo.test; + +import javax.jdo.*; + +import org.apache.jdo.test.util.JDORITestRunner; + +import org.apache.jdo.pc.PCArrays; + +/** +* Tests that arrays can be stored in the datastore. +* +* @author Dave Bristor +*/ +public class Test_Arrays extends Test_Fetch { + + /** */ + public static void main(String args[]) { + JDORITestRunner.run(Test_Arrays.class); + } + + /** */ + public void test() throws Exception { + insertObjects(); + readObjects(); + checkExtent(PCArrays.class, 1); + } + + /** Redefine to insert our own objects. */ + protected void insertObjects() { + PersistenceManager pm =3D pmf.getPersistenceManager(); + Transaction tx =3D pm.currentTransaction(); + try { + tx.begin(); + PCArrays pcArrays =3D new PCArrays(); + pcArrays.init(); + if (debug) logger.debug("Before insert: " + pcArrays); + pm.makePersistent(pcArrays); + tx.commit(); + =20 + Object oid1 =3D JDOHelper.getObjectId(pcArrays); + if (debug) logger.debug("inserted pcArrays: " + oid1); + oids.add(oid1); + } + finally { + if (tx !=3D null && tx.isActive()) + tx.rollback(); + if (pm !=3D 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"); + PCArrays expected =3D new PCArrays(); + expected.init(); + // PCArrays does not redefine equals, so use the string representa= tion + assertEquals("Wrong instance returned from datastore", expected.to= String(), pc.toString()); + } +} Added: incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_Cla= ssRegistration.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/fostore20/test/java/= org/apache/jdo/test/Test_ClassRegistration.java?rev=3D171355&view=3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_ClassR= egistration.java (added) +++ incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_ClassR= egistration.java Sun May 22 11:40:13 2005 @@ -0,0 +1,229 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + +package org.apache.jdo.test; + +import java.util.*; +import java.lang.reflect.*; +import java.net.URL; +import java.net.URLClassLoader; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; + +import org.apache.jdo.test.util.AbstractTest; +import org.apache.jdo.test.util.JDORITestRunner; + +/** + * Test registration and unregistration of pc classes. + * + * @author Michael Bouschen + * @since 1.0.2 + */ +public class Test_ClassRegistration extends AbstractTest { + =20 + /** */ + public static void main(String args[]) { + JDORITestRunner.run(Test_ClassRegistration.class); + } + + /** */ + protected void setUp() { } + + /** */ + protected void tearDown() { } + + /** */ + public void test() throws Throwable { + String jdoapi =3D System.getProperty("jdoapi"); + String pcclasses =3D System.getProperty("pcclasses"); + final URL jdoapiURL =3D new URL("file:" + jdoapi); + final URL pcclassesURL =3D new URL("file:" + pcclasses); + ClassLoader cl =3D (ClassLoader)AccessController.doPrivileged( + new PrivilegedAction () { + public Object run () { + return new URLClassLoader(new URL[] {pcclassesURL, jdo= apiURL}, null); + }}); + Class implHelperClass =3D getImplHelperClass(cl); + Object implHelper =3D callGetInstance(implHelperClass); + + // ------------------------------------------- + // Test registration + // ------------------------------------------- + + // This loads the pc class + Class employeeClass =3D loadPCClass("org.apache.jdo.pc.empdept.PCE= mployee", cl); + =20 + Collection registeredClasses =3D=20 + callGetRegisteredClasses(implHelperClass, implHelper); + int nrOfRegisteredClasses =3D registeredClasses.size(); + + // test whether PCEmployee is registered + assertTrue("Missing registered class " + employeeClass,=20 + registeredClasses.contains(employeeClass)); + + // ------------------------------------------- + // Test unregistration by class + // ------------------------------------------- + + // test unregisterClass with null parameter + try { + callUnregisterClass(implHelperClass, implHelper, null); + fail("Missing exception when calling unregisterClass(null)"); + } + catch (NullPointerException ex) { + // expected exception =3D> OK + } + =20 + // test unregister by class + callUnregisterClass(implHelperClass, implHelper, employeeClass); + registeredClasses =3D callGetRegisteredClasses(implHelperClass, im= plHelper); + int newNrOfRegisteredClasses =3D registeredClasses.size(); + // test nr of registered classes is decremented + assertEquals("Wrong number of registered classes",=20 + (nrOfRegisteredClasses - 1), newNrOfRegisteredClasses= ); + + // test PCEmployee not registered anymore + assertFalse("Class " + employeeClass + " still registered",=20 + registeredClasses.contains(employeeClass)); + =20 + // ------------------------------------------- + // Test unregistration by class loader + // ------------------------------------------- + =20 + // test unregister by classLoader + callUnregisterClasses(implHelperClass, implHelper, cl); + registeredClasses =3D callGetRegisteredClasses(implHelperClass, im= plHelper); + assertTrue("Unregistration failed, set of registered classes is no= t empty: " + registeredClasses, + registeredClasses.isEmpty()); + + // Test succeeded + } +=20 + /** */ + private Class loadPCClass(String className, ClassLoader cl) + throws Exception + { + Class pcClass =3D Class.forName(className, true, cl); + assertEquals("PC class " + className + " loaded by wrong class loa= der", + cl, getClassLoaderForClass(pcClass)); + return pcClass; + } + + /** */ + private Class getImplHelperClass(ClassLoader cl) + throws Exception + { + Class implHelperClass =3D=20 + Class.forName("javax.jdo.spi.JDOImplHelper", true, cl); + assertEquals("JDOImplHelper loaded by wrong class loader",=20 + cl, getClassLoaderForClass(implHelperClass)); + return implHelperClass; + } + + /** */ + private Object callGetInstance(Class implHelperClass) + throws Throwable + { + final Method method =3D implHelperClass.getMethod("getInstance", n= ull); + try { + return AccessController.doPrivileged( + new PrivilegedExceptionAction () { + public Object run () throws Exception { + return method.invoke(null, null); + }}); + } + catch (PrivilegedActionException pae) { + Throwable e =3D pae.getException(); + if (e instanceof InvocationTargetException) + e =3D ((InvocationTargetException)e).getTargetException(); + throw e; + } + } + =20 + /** */ + private Collection callGetRegisteredClasses(Class implHelperClass, Obj= ect implHelper) + throws Throwable + { + Method method =3D implHelperClass.getMethod("getRegisteredClasses"= , null); + try { + return (Collection)method.invoke(implHelper, null); + } + catch (InvocationTargetException ex) { + throw ((InvocationTargetException)ex).getTargetException(); + } + } + + /** */ + private void callUnregisterClass(final Class implHelperClass,=20 + final Object implHelper,=20 + final Class parameter) + throws Throwable + { + final Method method =3D implHelperClass.getMethod( + "unregisterClass", new Class[] {Class.class}); + try { + AccessController.doPrivileged( + new PrivilegedExceptionAction () { + public Object run () throws Exception { + return method.invoke(implHelper, new Object[] {par= ameter}); + }}); + } + catch (PrivilegedActionException pae) { + Throwable e =3D pae.getException(); + if (e instanceof InvocationTargetException) + e =3D ((InvocationTargetException)e).getTargetException(); + throw e; + } + } + + /** */ + private void callUnregisterClasses(final Class implHelperClass,=20 + final Object implHelper,=20 + final ClassLoader parameter) + throws Throwable + { + final Method method =3D implHelperClass.getMethod( + "unregisterClasses", new Class[] {ClassLoader.class}); + try { + AccessController.doPrivileged( + new PrivilegedExceptionAction () { + public Object run () throws Exception { + return method.invoke(implHelper, new Object[] {par= ameter}); + }}); + } + catch (PrivilegedActionException pae) { + Throwable e =3D pae.getException(); + if (e instanceof InvocationTargetException) + e =3D ((InvocationTargetException)e).getTargetException(); + throw e; + } + } + + /** */ + private ClassLoader getClassLoaderForClass(final Class clazz) + { + if (clazz =3D=3D null)=20 + return null; + return(ClassLoader)AccessController.doPrivileged( + new PrivilegedAction () { + public Object run () { + return clazz.getClassLoader(); + }}); + } + =20 +} Added: incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_Clo= sePMF.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/fostore20/test/java/= org/apache/jdo/test/Test_ClosePMF.java?rev=3D171355&view=3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_CloseP= MF.java (added) +++ incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_CloseP= MF.java Sun May 22 11:40:13 2005 @@ -0,0 +1,159 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + +/* + * Test_ClosePMF.java + * + * Created on April 8, 2003, 2:59 PM + */ + +package org.apache.jdo.test; + +import java.security.AccessController; +import java.security.PrivilegedAction; + +import javax.jdo.PersistenceManager; +import javax.jdo.Transaction; +import javax.jdo.JDOUserException; +import javax.jdo.JDOException; + +import org.apache.jdo.test.util.AbstractTest; +import org.apache.jdo.test.util.JDORITestRunner; + +import org.apache.jdo.test.util.Factory; +import org.apache.jdo.pc.PointFactory; + +/** + * Test that PMF.close() behaves properly. This test creates multiple PMs + * and verifies that close() throws an exception with a nested exception + * for each PM still open; once all PMs are closed, then close() should + * complete normally. + *=20 + * @author Craig Russell + */ +public class Test_ClosePMF extends AbstractTest { + =20 + /** */ + public static void main(String args[]) { + JDORITestRunner.run(Test_ClosePMF.class); + } + + /** Creates a new instance of Test_ClosePMF */ + public Test_ClosePMF() { + super(); + } + =20 + /** + * Inserts some number of objects in the database. Here, we just get + * some PMs and use them to add objects. Next, we get a PM that is not + * closed explicitly (it should be closed automatically by PMF.close()= )=2E + * Next, get a PM, begin a tx and verify that this one causes PMF.clos= e() + * to fail. + */ + public void test() throws Exception { + PersistenceManager pm0 =3D null; + PersistenceManager pm2 =3D null; + PersistenceManager pm4 =3D null; + try { + pm0 =3D pmf.getPersistenceManager(); + pm0.currentTransaction().begin(); + pm0.currentTransaction().rollback(); + insertObjects(); // this pm is closed by insertObjects + pm2 =3D pmf.getPersistenceManager(); + pm2.currentTransaction().begin(); + pm2.currentTransaction().commit(); + insertObjects(); // this pm is closed by insertObjects + pm4 =3D pmf.getPersistenceManager(); + pm4.currentTransaction().begin(); + + assertNotClosed(pm0, "pm0"); + assertNotClosed(pm2, "pm2"); + assertNotClosed(pm4, "pm4"); + JDOUserException jdouex =3D null; + try { + AccessController.doPrivileged(new PrivilegedAction () { + public Object run () throws JDOUserException { + pmf.close(); // this should throw an exception= with pm4 + return null; + }}); + } catch (JDOUserException ex) { + jdouex =3D ex; + } catch (Exception ex) { + fail("Wrong exception, expected JDOUserException, got " + = ex); + } + =20 + assertNotNull("Failed to catch exception from close.", jdouex); + + Throwable[] nested =3D jdouex.getNestedExceptions(); + assertEquals("Got wrong number of nested exceptions", 1, neste= d=2Elength); + + JDOException jdoex =3D (JDOException)nested[0]; + Object failed =3D jdoex.getFailedObject(); + assertTrue("Got wrong failed object of type: " + failed.getCla= ss().getName() +=20 + ", expected PersistenceManager.", (failed instanceo= f PersistenceManager)); + + assertEquals("Got wrong PersistenceManager", pm4, failed); + + // since we didn't explicitly close these, they should still b= e open + assertNotClosed(pm0, "pm0"); + assertNotClosed(pm2, "pm2"); + assertNotClosed(pm4, "pm4"); + pm4.currentTransaction().commit(); + // now any exception is fatal + AccessController.doPrivileged(new PrivilegedAction () { + public Object run () throws JDOUserException { + pmf.close();=20 + return null; + }}); + // the pmf.close() should have closed all the open pms + assertClosed(pm0, "pm0"); + assertClosed(pm2, "pm2"); + assertClosed(pm4, "pm4"); + // should be able to call this now without effect + pmf.close(); + } + finally { + finalizePM(pm0); + finalizePM(pm2); + finalizePM(pm4); + } + } + + void assertNotClosed(PersistenceManager pm, String msg) { + assertFalse("PersistenceManager " + msg + "(" + pm + ") is closed.= ", pm.isClosed()); + } + + void assertClosed(PersistenceManager pm, String msg) { + assertTrue("PersistenceManager " + msg + "(" + pm + ") is not clos= ed.", pm.isClosed()); + } + + void finalizePM(PersistenceManager pm) + { + if (pm !=3D null && !pm.isClosed()) { + Transaction tx =3D pm.currentTransaction(); + if ((tx !=3D null) && tx.isActive()) { + tx.rollback(); + } + pm.close(); + } + } + =20 + /** Redefine getFactory called be insertObjects. */ + protected Factory getFactory(int verify) + { + return new PointFactory(); + } +} Added: incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_Col= lections.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/fostore20/test/java/= org/apache/jdo/test/Test_Collections.java?rev=3D171355&view=3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_Collec= tions.java (added) +++ incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_Collec= tions.java Sun May 22 11:40:13 2005 @@ -0,0 +1,66 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + +package org.apache.jdo.test; + +import org.apache.jdo.test.util.JDORITestRunner; + +import org.apache.jdo.pc.PCCollections; + +/** +* 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_Collections extends Test_SCO_Base { + + /** */ + public static void main(String args[]) { + JDORITestRunner.run(Test_Collections.class); + } + + /** */ + public void test() throws Exception { + insertObjects(); + readObjects(); + checkExtent(PCCollections.class, 1); + } + + /** */ + protected void insertObjects() { + insertAllTypes(); + } + + /** + * redefine verify called by readObjects to check whether the read + * instance is correct. + */ + protected void verify(int i, Object pc) { + switch (i) { + case 0 : + assertEquals("Wrong PCPoint instance", createPoint(), pc); + break; + case 1: + assertEqualsPCCollections(createAllTypes(createPoint()), pc); + break; + default: + fail("Wrong number of inserted objects, expected two"); + break; + } + } +} Added: incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_Con= tainer.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/fostore20/test/java/= org/apache/jdo/test/Test_Container.java?rev=3D171355&view=3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_Contai= ner.java (added) +++ incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_Contai= ner.java Sun May 22 11:40:13 2005 @@ -0,0 +1,358 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + +/* + * Test_Container.java + * + * Created on August 30, 2001 + */ + +package org.apache.jdo.test; + +import java.util.*; + +import javax.jdo.*; + +import org.apache.jdo.pc.PCPoint; +import org.apache.jdo.test.util.Container; + +import org.apache.jdo.test.util.AbstractTest; +import org.apache.jdo.test.util.JDORITestRunner; + +/** + * Test driver to test transactions in a managed environment + *=20 + * @author Marina Vatkina + */ +public class Test_Container extends AbstractTest { + + Container tc =3D null; + String url =3D null; + Object oid =3D null; + + /** */ + public static void main(String args[]) { + JDORITestRunner.run(Test_Container.class); + } + + /** */ + protected void setUp() { + tc =3D new Container(debug); + url =3D createURL(); + } + + /** */ + protected void tearDown() { + pmf =3D tc.close(); + closePMF(); + } + + /** */ + public void test() { + String repr =3D null; + + // Insert - rollback + if (debug) logger.debug("=3D=3D=3DTESTCMT_NEG: "); + runTestCMT(false); + =20 + // Insert - commit + if (debug) logger.debug("=3D=3D=3DTESTCMT_POS: "); + runTestCMT(true); + =20 + // Get Extent with 1 instance + if (debug) logger.debug("=3D=3D=3DQUERY: "); + repr =3D queryInstance(); + assertEquals("Wrong PCPoint instance", + "org.apache.jdo.pc.PCPoint x: 9, y: 999", repr); + + // Update instance and test the same PMs in both "beans" + if (debug) logger.debug("=3D=3D=3DTESTCMT_CMT: "); + runTestCMT_CMT(); + + // Update instance and test the same PMs in both "beans" + if (debug) logger.debug("=3D=3D=3DTESTBMT_JDO_CMT: "); + runTestBMT_JDO_CMT(); + + // Update instance=20 + if (debug) logger.debug("=3D=3D=3DTESTBMT_JDO_POS: "); + runTestBMT_JDO_POS(); + + // Get Extent with 1 updated instance + if (debug) logger.debug("=3D=3D=3DQUERY: "); + repr =3D queryInstance(); + assertEquals("Wrong PCPoint instance", + "org.apache.jdo.pc.PCPoint x: 72, y: 720", repr); + + // Delete the instance + if (debug) logger.debug("=3D=3D=3DTESTBMT_UT_POS: "); + runTestBMT_UT_POS(); + + // Get Extent with 0 instances + if (debug) logger.debug("=3D=3D=3DQUERY: "); + repr =3D queryInstance(); + assertEquals("Empty query result expected", "NONE", repr); + + // Fail to delete instance got by non-existent Oid + if (debug) logger.debug("=3D=3D=3DTESTBMT_UT_NEG: "); + runTestBMT_UT_NEG(); + + // Fail to update instance got by non-existent Oid + if (debug) logger.debug("=3D=3D=3DTESTBMT_JDO_NEG: "); + runTestBMT_JDO_NEG(); + } + + private void runTestCMT(boolean commit) { + PersistenceManager pm =3D null; + try { + PersistenceManagerFactory pmf =3D tc.getPMF(url); + tc.startCMT(); + pm =3D pmf.getPersistenceManager(); + + Object o =3D createInstance(); + pm.makePersistent(o); + =20 + oid =3D pm.getObjectId(o); + } + finally { + pm.close(); + =20 + // This is a hack to make transaction fail: + tc.finishCMT(commit); + } + } + =20 + private void runTestCMT_CMT() { + PersistenceManager pm =3D null; + try { + PersistenceManagerFactory pmf =3D tc.getPMF(url); + tc.startCMT(); + pm =3D pmf.getPersistenceManager(); + + PCPoint p =3D (PCPoint)pm.getObjectById(oid, false);=20 + updateInstance(p); + + validate(p, pm); + + } finally { + pm.close(); + tc.finishCMT(true); + } + } + + private void runTestBMT_JDO_CMT() { + PersistenceManager pm =3D null; + Transaction tx =3D null; + try {=20 + PersistenceManagerFactory pmf =3D tc.getPMF(url); + tc.startBMT();=20 + pm =3D pmf.getPersistenceManager();=20 + tx =3D pm.currentTransaction(); + tx.begin(); + + PCPoint p =3D (PCPoint)pm.getObjectById(oid, false);=20 + updateInstance(p); + + validate(p, pm); + =20 + tx.commit(); + } finally { + if ((tx !=3D null) && tx.isActive()) + tx.rollback(); + pm.close(); + tc.finishBMT();=20 + } + } + =20 + private void runTestBMT_JDO_POS() {=20 + PersistenceManager pm =3D null; + Transaction tx =3D null; + try { + PersistenceManagerFactory pmf =3D tc.getPMF(url); + tc.startBMT();=20 + pm =3D pmf.getPersistenceManager();=20 + tx =3D pm.currentTransaction(); + tx.begin(); + + updateInstance((PCPoint)pm.getObjectById(oid, false));=20 + + tx.commit(); + } + finally { + if ((tx !=3D null) && tx.isActive()) + tx.rollback(); + pm.close(); + tc.finishBMT();=20 + } + } + + private void runTestBMT_JDO_NEG() {=20 + PersistenceManager pm =3D null; + Transaction tx =3D null; + try { + PersistenceManagerFactory pmf =3D tc.getPMF(url); + tc.startBMT();=20 + pm =3D pmf.getPersistenceManager();=20 + tx =3D pm.currentTransaction(); + tx.begin(); + =20 + updateInstance((PCPoint)pm.getObjectById(oid, false));=20 + =20 + tx.commit(); + fail("ERROR TO FINISH: "); + } catch (Exception e) {=20 + if (debug) + logger.debug ("EXPECTED FOR testBMT_JDO_NEG: " + e.getMess= age()); + tx.rollback(); + }=20 + finally { + pm.close(); + tc.finishBMT();=20 + } + } + + + private void runTestBMT_UT_POS() { =20 + PersistenceManager pm =3D null; + try {=20 + PersistenceManagerFactory pmf =3D tc.getPMF(url); + tc.startBMT(); + tc.getUserTransaction().begin(); + =20 + pm =3D pmf.getPersistenceManager();=20 + pm.deletePersistent(pm.getObjectById(oid, false)); =20 + =20 + pm.close(); + tc.getUserTransaction().commit(); + } catch (Exception e) { =20 + if (debug) logger.debug ("testBMT_UT_POS: " + e); + try { + tc.getUserTransaction().rollback(); + } catch (Exception e1) { + if (debug) logger.debug("testBMT_UT_POS: " + e1); + fail("testBMT_UT_POS: " + e1); + } + } + finally { + if (pm !=3D null && !pm.isClosed()) + pm.close(); + tc.finishBMT();=20 + } + } + + private void runTestBMT_UT_NEG() { =20 + PersistenceManager pm =3D null; + try {=20 + PersistenceManagerFactory pmf =3D tc.getPMF(url); + tc.startBMT(); + tc.getUserTransaction().begin(); + + pm =3D pmf.getPersistenceManager();=20 + pm.deletePersistent(pm.getObjectById(oid, false)); =20 + + pm.close(); + + tc.getUserTransaction().commit(); + tc.finishBMT();=20 + fail("ERROR TO FINISH: "); + } catch (Exception e) { =20 + if (debug) + logger.debug ("EXPECTED FOR testBMT_UT_NEG: " + e.getMessa= ge()); + try { + tc.getUserTransaction().rollback(); + } catch (Exception e1) { + if (debug) logger.debug ("ERROR IN testBMT_UT_NEG: " + e1); + fail("ERROR IN testBMT_UT_NEG: " + e1); + } + } + finally { + if (pm !=3D null && !pm.isClosed()) + pm.close(); + } + =20 + } + + private PCPoint createInstance() { + PCPoint p =3D new PCPoint(9, 999); + return p; + } + + private void updateInstance(PCPoint p) { + int i =3D p.getX(); + p.setX(i*2); + p.setY(new Integer(i*20)); + } + + + private String queryInstance() { + PersistenceManagerFactory pmf =3D tc.getPMF(url); + tc.startBMT(); + PersistenceManager pm =3D pmf.getPersistenceManager(); +/* Not yet implemented + Query query =3D pm.newQuery(); + query.setClass (test.PCPoint.class); + query.setFilter("x =3D=3D " + ???); + query.setCandidates(pm.getExtent(test.PCPoint.class, false)); + + Object result =3D query.execute(); +*/ + Extent result =3D pm.getExtent(org.apache.jdo.pc.PCPoint.class, fa= lse); + + String s =3D ""; + if (result =3D=3D null) { + s =3D "NULL"; + } else { + int count =3D 0; + Object pc =3D null; + + for (Iterator i =3D result.iterator(); i.hasNext();) { + pc =3D i.next(); + count++; + } + if ( count =3D=3D 0 ) { + s =3D "NONE"; + } else if ( count > 1 ) { + s =3D "MANY"; + } else { + s =3D "" + pc; + } + } + pm.close(); + tc.finishBMT(); + + return s; + } + + private void validate(PCPoint e, PersistenceManager pm0) { + PersistenceManagerFactory pmf =3D tc.getPMF(url); + PersistenceManager pm =3D pmf.getPersistenceManager(); + + PCPoint p =3D (PCPoint)pm.getObjectById(oid, false); + + if (p !=3D e) { + fail("OBJECTS NOT EQUAL: " + e + " <> " + p); + } else { + if (debug) logger.debug ("OBJECTS ARE EQUAL!!! " ); + } + + if (!pm0.equals(pm)) { + fail("PMS NOT EQUAL!!!"); + } else { + if (debug) logger.debug ("PMS ARE EQUAL!!!"); + } + + pm.close(); + } +} Added: incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_Cyc= le.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/fostore20/test/java/= org/apache/jdo/test/Test_Cycle.java?rev=3D171355&view=3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_Cycle.= java (added) +++ incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_Cycle.= java Sun May 22 11:40:13 2005 @@ -0,0 +1,130 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + +package org.apache.jdo.test; + +import javax.jdo.*; + +import org.apache.jdo.test.util.JDORITestRunner; + +import org.apache.jdo.pc.PCCycle; +import org.apache.jdo.pc.PCCycle2; + +// +// This _test_ does not yet work. +// +// When printing the objects after reading them from the database, NPE's a= re +// generated because we don't yet have an enhancer...so the field referenc= es +// to the other class, made in each class's toString() method, fail after +// reading. When we have an enhancer, these will be enhanced to be functi= on +// calls to get the field of the other class, and toString() will be invok= ed +// in the result of that. +// + +/** +* Test 2 PC's that refer to each other in a cycle/loop. +* +* @author Dave Bristor +*/ +public class Test_Cycle extends Test_Fetch { + + /** */ + public static void main(String args[]) { + JDORITestRunner.run(Test_Cycle.class); + } + + // The idea is that we're going to write a bunch of stuff to a data + // output stream, then read it back in; we should get the same data + // back. + public void test() throws Exception { + insertObjects(); + initExpected(); + readObjects(); + checkExtent(PCCycle.class, 1); + checkExtent(PCCycle2.class, 1); + } + + // We override this from AbstractTest and insert our own objects=20 + protected void insertObjects() { + PersistenceManager pm =3D pmf.getPersistenceManager(); + Transaction tx =3D pm.currentTransaction(); + try { + tx.begin(); + + PCCycle c =3D new PCCycle(); + PCCycle2 c2 =3D new PCCycle2(); + + c.init("cyrcular", c2); + c2.init(12358, c); + =20 + if (debug) { + logger.debug("Before insert: " + c); + logger.debug("Before insert: " + c2); + } + =20 + pm.makePersistent(c); + pm.makePersistent(c2); + =20 + tx.commit(); + =20 + Object oid_c =3D JDOHelper.getObjectId(c); + Object oid_c2 =3D JDOHelper.getObjectId(c2); + =20 + if (debug) { + logger.debug("inserted c: " + oid_c); + logger.debug("inserted c2: " + oid_c2); + } + =20 + oids.add(oid_c); + oids.add(oid_c2); + } + finally { + if (tx !=3D null && tx.isActive()) + tx.rollback(); + if (pm !=3D null && !pm.isClosed()) + pm.close(); + } + } + =20 + private PCCycle expectedC =3D null; + private PCCycle2 expectedC2 =3Dnull; + + private void initExpected() { + expectedC =3D new PCCycle(); + expectedC2 =3D new PCCycle2(); + expectedC.init("cyrcular", expectedC2); + expectedC2.init(12358, expectedC); + } + + /** + * redefine verify called by readObjects to check whether the read + * instance is correct. + */ + protected void verify(int i, Object pc) { + // PCCycle and PCCycle2 do not redefine equals, so use the string = representation. + switch(i) { + case 0 :=20 + assertEquals("Wrong instance returned from datastore", expecte= dC.toString(), pc.toString()); + break;=20 + case 1: + assertEquals("Wrong instance returned from datastore", expecte= dC2.toString(), pc.toString()); + break; + default: + fail("Wrong number of inserted objects, expected two"); + break; + } + } +} Added: incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_Del= ete.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/fostore20/test/java/= org/apache/jdo/test/Test_Delete.java?rev=3D171355&view=3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_Delete= .java (added) +++ incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_Delete= .java Sun May 22 11:40:13 2005 @@ -0,0 +1,155 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + +package org.apache.jdo.test; + +import java.io.EOFException; +import java.io.ObjectInputStream; + +import javax.jdo.*; + +import org.apache.jdo.test.util.AbstractTest; +import org.apache.jdo.test.util.JDORITestRunner; +import org.apache.jdo.test.util.Factory; + +/** +* This test is similar to Test_ActivateClass, but it adds extra steps of +* getting OIDs for objects and deleting those objects. +* +* @author Dave Bristor +*/ +public class Test_Delete extends AbstractTest { + + /** */ + private static boolean silent =3D false; + =20 + /** */ + public static void main(String args[]) { + handleArgs(args); + if (silent) + runSilentDelete(); + else + JDORITestRunner.run(Test_Delete.class); + } + + /** */ + public void test() throws Exception { + if (!existing) { + insertObjects(); + writeOIDs(); + } + deleteObjects(false, false); + checkExtent(factory.getPCClass(), 0); + } + + /** */ + public void testOptimistic() throws Exception { + if (!existing) { + insertObjects(); + writeOIDs(); + } + deleteObjects(true, false); + checkExtent(factory.getPCClass(), 0); + } + + /** */ + public void testValidate() throws Exception { + if (!existing) { + insertObjects(); + writeOIDs(); + } + deleteObjects(false, true); + checkExtent(factory.getPCClass(), 0); + } + + /** */ + public void testOptimisticValidate() throws Exception { + if (!existing) { + insertObjects(); + writeOIDs(); + } + deleteObjects(true, true); + checkExtent(factory.getPCClass(), 0); + } + + /** */ + void deleteObjects(boolean optimistic, boolean validate) throws Except= ion { + PersistenceManager pm =3D pmf.getPersistenceManager(); + Transaction tx =3D pm.currentTransaction(); + + try { + ObjectInputStream in =3D getOIDFileInputStream(); + tx.setOptimistic(optimistic); + tx.begin(); + =20 + try { + while (true) { + Object pc =3D null; + Object oid =3D in.readObject(); + if (debug) logger.debug("fetching: " + oid); + pc =3D pm.getObjectById(oid, validate); + if (debug) logger.debug("Before delete: " + pc); + pm.deletePersistent(pc); + assertTrue("IsDeleted", JDOHelper.isDeleted(pc)); + } + } catch (EOFException ex) { + // OK + } + tx.commit(); + } + finally { + if (tx !=3D null && tx.isActive()) + tx.rollback(); + if (pm !=3D null && !pm.isClosed()) + pm.close(); + } + } + + /** */ + protected Factory getFactory(int verify) { + return getFactoryByClassProperty(verify, "org.apache.jdo.pc.PCPoin= t"); + } + + /** */ + protected int getDefaultInsert() + { + return 5; + } + + /** */ + private static void runSilentDelete() { + try { + Test_Delete delete =3D new Test_Delete(); + delete.setupPMF(); + delete.test(); + delete.closePMF(); + } + catch (Exception ex) { + System.out.println("Excetion during delete"); + ex.printStackTrace(); + } + } + + /** */ + private static void handleArgs(String[] args) { + for (int i =3D 0; i < args.length; i++) { + if ("-silent".equals(args[i])) + silent =3D true; + else + System.err.println("Test_Delete: ignoring unknon option" += args[i]); + } + } +} Added: incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_Dup= AppId.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/fostore20/test/java/= org/apache/jdo/test/Test_DupAppId.java?rev=3D171355&view=3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_DupApp= Id.java (added) +++ incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_DupApp= Id.java Sun May 22 11:40:13 2005 @@ -0,0 +1,103 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + +package org.apache.jdo.test; + +import javax.jdo.*; + +import org.apache.jdo.test.util.AbstractTest; +import org.apache.jdo.test.util.JDORITestRunner; + +import org.apache.jdo.pc.PCPoint1; + +/** +* Tests that FOStore can correctly determine dups for application identity. +* +* @author Marina Vatkina +*/ +public class Test_DupAppId extends AbstractTest { + + /** */ + public static void main(String args[]) { + JDORITestRunner.run(Test_DupAppId.class); + } + + /** */ + public void test() { + insertObjects(); + checkExtent(PCPoint1.class, 1); + } + + /** */ + public void insertObjects() { + PersistenceManager pm =3D pmf.getPersistenceManager(); + Transaction tx =3D pm.currentTransaction(); + + try { + PCPoint1 p =3D new PCPoint1(1,10); + PCPoint1 p1 =3D new PCPoint1(1,100); + if (debug) logger.debug("INSERT"); + tx.begin(); + if (debug) logger.debug("Inserting: " + p); + pm.makePersistent(p); + try { + if (debug) logger.debug("Inserting: " + p1); + pm.makePersistent(p1); + fail("Missing JDOException during makePersistent with the = same primary key in the PersistenceManager cache."); + } catch (JDOException ex) { + // expected exception =3D> OK + if (debug) logger.debug("caught expected " + ex); + } + tx.commit(); tx =3D null; + =20 + if (debug) { + logger.debug("Inserted: " + p); + logger.debug("P isPersistent: " + JDOHelper.isPersistent(p= )); + } + assertTrue("instance " + p + " + expected to be persistent",=20 + JDOHelper.isPersistent(p)); + if (debug)=20 + logger.debug("P1 isPersistent: " + JDOHelper.isPersistent(= p1)); + assertFalse("instance " + p1 + " + expected to be not persiste= nt", + JDOHelper.isPersistent(p1)); + =20 + pm.close(); pm =3D null; + + pm =3D pmf.getPersistenceManager(); + tx =3D pm.currentTransaction(); + if (debug) logger.debug("INSERT DUPS"); + tx.begin(); + if (debug) logger.debug("Inserting: " + p1); + pm.makePersistent(p1); + try { + tx.commit();=20 + fail("Missing JDOException during commit when inserting a = duplicate in the datastore."); + } catch (Exception ex) { + // expected exception =3D> OK + if (debug) logger.debug("caught expected " + ex); + } + if (debug)=20 + logger.debug("P1 isPersistent: " + JDOHelper.isPersistent(= p1)); + } + finally { + if (tx !=3D null && tx.isActive()) + tx.rollback(); + if (pm !=3D null && !pm.isClosed()) + pm.close(); + } + } + +} Added: incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_Emp= Dept.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/fostore20/test/java/= org/apache/jdo/test/Test_EmpDept.java?rev=3D171355&view=3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_EmpDep= t=2Ejava (added) +++ incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_EmpDep= t=2Ejava Sun May 22 11:40:13 2005 @@ -0,0 +1,300 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + +package org.apache.jdo.test; + +import java.util.*; + +import javax.jdo.*; + +import org.apache.jdo.test.util.AbstractTest; +import org.apache.jdo.test.util.JDORITestRunner; + +import org.apache.jdo.pc.PCDepartment; +import org.apache.jdo.pc.PCEmployee; +import org.apache.jdo.pc.PCInsurance; +import org.apache.jdo.pc.PCProject; + +/** +* Test a PC that has some fields which are PC's. +* +* @author Dave Bristor +*/ +public class Test_EmpDept extends AbstractTest { + PCEmployee scott; + PCEmployee ed; + + PCDepartment board; + PCDepartment emg; + + PCInsurance scottIns; + PCInsurance edIns; + + PCProject solaris; + PCProject sparc; + + Object scottOid; + Object edOid; + Object boardOid; + Object emgOid; + Object scottInsOid; + Object edInsOid; + Object solarisOid; + Object sparcOid; + + /** */ + public static void main(String args[]) { + JDORITestRunner.run(Test_EmpDept.class); + } + + /** */ + public void test() throws Exception { + createObjects(); + insertObjects(); + readObjects(); + } + + // We override this from Test_ActivateClass and insert our own objects. + // Use Test_Extent to read them back. + protected void createObjects() { + HashSet h; + =20 + // Create and set up employees. Scott is Ed's manager. Ed is + // Scott's sole employee. + // + GregorianCalendar born =3D + new GregorianCalendar(TimeZone.getTimeZone("America/New_York")= ); + GregorianCalendar hired =3D + new GregorianCalendar(TimeZone.getTimeZone("America/New_York")= ); + + born.set(1969, 7, 20); + hired.set(1982, 5, 5); + scott =3D new PCEmployee(1L, "McNealy", "Scott", 200000.0, + born.getTime(), hired.getTime()); + born.set(1960, 4, 8); + hired.set(1985, 2, 3); + ed =3D new PCEmployee(100L, "Zander", "Ed", 400000.0, + born.getTime(), hired.getTime()); + =20 + ed.setManager(scott); + + h =3D new HashSet(); + h.add(ed); + scott.setEmployees(h); + + // Set up their departments. + board =3D new PCDepartment(100L, "board"); + h =3D new HashSet(); + h.add(scott); + board.setEmployees(h); + scott.setDepartment(board); + + emg =3D new PCDepartment(200L, "emg"); + h =3D new HashSet(); + h.add(ed); + emg.setEmployees(h); + ed.setDepartment(emg); + + // Insure these guys + scottIns =3D new PCInsurance(1000, "Aetna", scott); + edIns =3D new PCInsurance(1001, "BlueCross", ed); + scott.setInsurance(scottIns); + ed.setInsurance(edIns); + + // Give them some projects to work on. Scott works on both; Ed on= ly + // on one. + solaris =3D new PCProject(1L, "Solaris"); + sparc =3D new PCProject(2L, "Sparc"); + h =3D new HashSet(); + h.add(scott); + h.add(ed); + solaris.setEmployees(h); // Solaris is worked on by Scott and Ed + + h =3D new HashSet(); + h.add(scott); + sparc.setEmployees(h); // Sparc is worked on by Scott + =20 + h =3D new HashSet(); + h.add(solaris); + h.add(sparc); + scott.setProjects(h); // Scott works on Solaris and Sparc + + h =3D new HashSet(); + h.add(solaris); + ed.setProjects(h); // Ed works on Solaris + + // Show what we've got + if (debug) { + logger.debug("Before insert: "); + logger.debug(scott.toString()); + logger.debug(ed.toString()); + logger.debug(board.toString()); + logger.debug(emg.toString()); + logger.debug(scottIns.toString()); + logger.debug(edIns.toString()); + logger.debug(solaris.toString()); + logger.debug(sparc.toString()); + } + } + + protected void insertObjects() throws Exception { + PersistenceManager pm =3D null; + Transaction tx =3D null; + try { + pm =3D pmf.getPersistenceManager(); + tx =3D pm.currentTransaction(); + tx.begin(); + + // Make it all persistent. If reachability were implemented, = we'd + // only have to make scott and ed persistent, as everything el= se is + // reachable from them. + pm.makePersistent(scott); + pm.makePersistent(ed); + pm.makePersistent(board); + pm.makePersistent(emg); + pm.makePersistent(scottIns); + pm.makePersistent(edIns); + pm.makePersistent(solaris); + pm.makePersistent(sparc); + =20 + tx.commit(); + + scottOid =3D JDOHelper.getObjectId(scott); + edOid =3D JDOHelper.getObjectId(ed); + boardOid =3D JDOHelper.getObjectId(board); + emgOid =3D JDOHelper.getObjectId(emg); + scottInsOid =3D JDOHelper.getObjectId(scottIns); + edInsOid =3D JDOHelper.getObjectId(edIns); + solarisOid =3D JDOHelper.getObjectId(solaris); + sparcOid =3D JDOHelper.getObjectId(sparc); + } + finally { + if (tx !=3D null && tx.isActive()) + tx.rollback(); + if (pm !=3D null && !pm.isClosed()) + pm.close(); + } + } + + protected void readObjects() throws Exception { + PersistenceManager pm =3D null; + Transaction tx =3D null; + try { + pm =3D pmf.getPersistenceManager(); + tx =3D pm.currentTransaction(); + tx.begin(); + if (debug) logger.debug("readObjects: "); + assertScott(pm.getObjectById(scottOid, true)); + assertEd(pm.getObjectById(edOid, true)); + assertBoard(pm.getObjectById(boardOid, true)); + assertEmg(pm.getObjectById(emgOid, true)); + assertScottIns(pm.getObjectById(scottInsOid, true)); + assertEdIns(pm.getObjectById(edInsOid, true)); + assertSolaris(pm.getObjectById(solarisOid, true)); + assertSparc(pm.getObjectById(sparcOid, true)); + tx.rollback(); + } + finally { + if (tx !=3D null && tx.isActive()) + tx.rollback(); + if (pm !=3D null && !pm.isClosed()) + pm.close(); + } + =20 + } + =20 + protected void assertScott(Object scott) { + assertNotNull("scott should not be null", scott);=20 + if (debug) logger.debug(scott.toString()); + assertTrue("scott is expected to be a PCEmployee",=20 + (scott instanceof PCEmployee)); + assertEquals("Wrong string representation of scott",=20 + "Emp: McNealy, Scott, id=3D1, born 20/Aug/1969, hired= 5/Jun/1982 $200000.0 manager: none dept: board emps: 1 insurance: Aetna",=20 + scott.toString()); + } + + protected void assertEd(Object ed) { + assertNotNull("ed should not be null", ed);=20 + if (debug) logger.debug(ed.toString()); + assertTrue("ed is expected to be a PCEmployee",=20 + (ed instanceof PCEmployee)); + assertEquals("Wrong string representation of ed", + "Emp: Zander, Ed, id=3D100, born 8/May/1960, hired 3/= Mar/1985 $400000.0 manager: McNealy dept: emg emps: 0 insurance: BlueCross", + ed.toString()); + } + + protected void assertBoard(Object board) { + assertNotNull("board should not be null", board);=20 + if (debug) logger.debug(board.toString()); + assertTrue("board is expected to be a PCDepartment",=20 + (board instanceof PCDepartment)); + assertEquals("Wrong string representation of board", + "Dept: board, id=3D100, emps: 1", + board.toString()); + } + + protected void assertEmg(Object emg) { + assertNotNull("emg should not be null", emg);=20 + if (debug) logger.debug(emg.toString()); + assertTrue("emg is expected to be a PCDepartment",=20 + (emg instanceof PCDepartment)); + assertEquals("Wrong string representation of emg", + "Dept: emg, id=3D200, emps: 1", + emg.toString()); + } + + protected void assertScottIns(Object scottIns) { + assertNotNull("scottIns should not be null", scottIns);=20 + if (debug) logger.debug(scottIns.toString()); + assertTrue("scottIns is expected to be a PCInsurance",=20 + (scottIns instanceof PCInsurance)); + assertEquals("Wrong string representation of scotts insurance", + "Ins: Aetna, id=3D1000, emp McNealy", + scottIns.toString()); + } + + protected void assertEdIns(Object edIns) { + assertNotNull("edIns should not be null", edIns);=20 + if (debug) logger.debug(edIns.toString()); + assertTrue("edIns is expected to be a PCInsurance",=20 + (edIns instanceof PCInsurance)); + assertEquals("Wrong string representation of eds insurance", + "Ins: BlueCross, id=3D1001, emp Zander", + edIns.toString()); + } + + protected void assertSolaris(Object solaris) { + assertNotNull("solaris should not be null", solaris);=20 + if (debug) logger.debug(solaris.toString()); + assertTrue("solaris is expected to be a PCProject",=20 + (solaris instanceof PCProject)); + assertEquals("Wrong string representation of project solaris", + "PCProject: Solaris, id=3D1, emps: 2", + solaris.toString()); + } + + protected void assertSparc(Object sparc) { + assertNotNull("sparc should not be null", sparc);=20 + if (debug) logger.debug(sparc.toString()); + assertTrue("sparc is expected to be a PCProject",=20 + (sparc instanceof PCProject)); + assertEquals("Wrong string representation of project sparc", + "PCProject: Sparc, id=3D2, emps: 1", + sparc.toString()); + } + =20 +} + Added: incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_Emp= DeptAppId.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/fostore20/test/java/= org/apache/jdo/test/Test_EmpDeptAppId.java?rev=3D171355&view=3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_EmpDep= tAppId.java (added) +++ incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_EmpDep= tAppId.java Sun May 22 11:40:13 2005 @@ -0,0 +1,357 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + +package org.apache.jdo.test; + + +import java.util.*; + +import javax.jdo.*; + +import org.apache.jdo.test.util.AbstractTest; +import org.apache.jdo.test.util.JDORITestRunner; + +import org.apache.jdo.pc.appid.PCDepartment; +import org.apache.jdo.pc.appid.PCEmployee; +import org.apache.jdo.pc.appid.PCFullTimeEmployee; +import org.apache.jdo.pc.appid.PCInsurance; +import org.apache.jdo.pc.appid.PCPartTimeEmployee; +import org.apache.jdo.pc.appid.PCProject; + +/** +* Test a PC that inherits from another PC with an application identity. +* +* @author Marina Vatkina +*/ +public class Test_EmpDeptAppId extends AbstractTest { + =20 + protected PersistenceManager pm; + protected Transaction tx; + protected String scottRepr =3D null; + =20 + /** */ + public static void main(String args[]) { + JDORITestRunner.run(Test_EmpDeptAppId.class); + } + + /** */ + public void test() throws Exception + { + insertObjects(); + checkObjects(); + updateObject(); + checkObjects(); + deleteObjects(); + } =20 + =20 + /** */ + protected void insertObjects() { + try + { + pm =3D pmf.getPersistenceManager(); + tx =3D pm.currentTransaction(); + tx.begin(); + createObjects(); + tx.commit(); + } + finally { + if (tx !=3D null && tx.isActive()) + tx.rollback(); + if (pm !=3D null && !pm.isClosed()) + pm.close(); + } + } + =20 + /** Check created objects by Extent and getObjectById. + */ + protected void checkObjects() { + try { + pm =3D pmf.getPersistenceManager(); + if (debug) logger.debug("EXTENT PCEmployee"); + Extent ext =3D pm.getExtent(PCEmployee.class, true); + TreeMap elements =3D new TreeMap(); // Sort the results. + for (Iterator i =3D ext.iterator(); i.hasNext();) { + PCEmployee p =3D (PCEmployee)i.next(); + elements.put(p.toString(), p); + } + =20 + int count =3D 0; + for (Iterator i =3D elements.values().iterator(); i.hasNext();= ) { + Object p =3D i.next(); + verify(count++, p); + loadAndVerifyObject(p, pm); + } + } + finally { + if (pm !=3D null && !pm.isClosed()) + pm.close(); + } + } + + /** Delete objects and check by getObjectById. + */ + protected void deleteObjects() { + try { + pm =3D pmf.getPersistenceManager(); + tx =3D pm.currentTransaction(); + tx.begin(); + + if (debug) logger.debug("EXTENT PCEmployee"); + Extent ext =3D pm.getExtent(PCEmployee.class, true); + TreeMap elements =3D new TreeMap(); // Sort the results. + for (Iterator i =3D ext.iterator(); i.hasNext();) { + PCEmployee p =3D (PCEmployee)i.next(); + elements.put(p.toString(), p); + } + =20 + for (Iterator i =3D elements.values().iterator(); i.hasNext();= ) { + Object p =3D i.next(); + Object oid =3D pm.getObjectId(p); + if (debug) logger.debug("Delete with OID: " + oid); + pm.deletePersistent(p); + =20 + Object o =3D pm.getObjectById(oid, true); + assertSame("Expected same instance from getObjectById", p,= o); + assertTrue("Instance should be deleted", JDOHelper.isDelet= ed(o)); + } + tx.commit(); + } + finally { + if (tx !=3D null && tx.isActive()) + tx.rollback(); + if (pm !=3D null && !pm.isClosed()) + pm.close(); + } + checkExtent(PCEmployee.class, 0); + } + + protected void createObjects() { + // Create and set up employees. Scott is Ed's manager. Ed is + // Scott's sole employee. + // + ArrayList arr; + =20 + GregorianCalendar born =3D + new GregorianCalendar(TimeZone.getTimeZone("America/New_York")= ); + GregorianCalendar hired =3D + new GregorianCalendar(TimeZone.getTimeZone("America/New_York")= ); + + born.set(1945, 5, 9); + hired.set(2001, 3, 5); + PCEmployee john =3D=20 + new PCEmployee(=20 + "John", "One", born.getTime(),=20 + 900L, hired.getTime(), + null, null, null, null, null); + =20 + born.set(1969, 7, 20); + hired.set(1982, 5, 5); + PCEmployee scott =3D + new PCFullTimeEmployee( + "Scott", "McNealy", born.getTime(),=20 + 1L, hired.getTime(), + 200000.0); + born.set(1960, 4, 8); + hired.set(1985, 2, 3); + PCEmployee ed =3D=20 + new PCPartTimeEmployee( + "Ed", "Zander", born.getTime(),=20 + 100L, hired.getTime(), + 400000.0);=20 + =20 + ed.setManager(scott); + + arr =3D new ArrayList(); + arr.add(ed); + scott.setEmployees(arr); + + // Set up their departments. + PCDepartment board =3D + new PCDepartment(100L, "board"); + HashSet h =3D new HashSet(); + h.add(scott); + board.setEmployees(h); + scott.setDepartment(board); + + PCDepartment emg =3D + new PCDepartment(200L, "emg"); + h =3D new HashSet(); + h.add(ed); + emg.setEmployees(h); + ed.setDepartment(emg); + john.setDepartment(emg); + + // Insure these guys + PCInsurance scottIns =3D new PCInsurance(1000, "Aetna", scott); + PCInsurance edIns =3D new PCInsurance(1001, "BlueCross", ed); + scott.setInsurance(scottIns); + ed.setInsurance(edIns); + PCInsurance johnIns =3D new PCInsurance(9001, "BlueCross", john); + john.setInsurance(johnIns); + + // Give them some projects to work on. Scott works on both; Ed on= ly + // on one. + PCProject solaris =3D new PCProject(1L, "Solaris"); + PCProject sparc =3D new PCProject(2L, "Sparc"); + h =3D new HashSet(); + h.add(scott); + h.add(ed); + solaris.setEmployees(h); // Solaris is worked on by Scott and Ed + + h =3D new HashSet(); + h.add(scott); + sparc.setEmployees(h); // Sparc is worked on by Scott + =20 + arr =3D new ArrayList(); + arr.add(solaris); + arr.add(sparc); + scott.setProjects(arr); // Scott works on Solaris and Sparc + + arr =3D new ArrayList(); + arr.add(solaris); + ed.setProjects(arr); // Ed works on Solaris + + // Show what we've got + if (debug) { + logger.debug("Before insert: "); + logger.debug(scott.toString()); + logger.debug(ed.toString()); + logger.debug(john.toString()); + logger.debug(board.toString()); + logger.debug(emg.toString()); + logger.debug(scottIns.toString()); + logger.debug(edIns.toString()); + logger.debug(johnIns.toString()); + logger.debug(solaris.toString()); + logger.debug(sparc.toString()); + } + + // 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(scott); + pm.makePersistent(ed); + pm.makePersistent(john); + + Object oid =3D pm.getObjectId(scott); + if (debug) logger.debug("Instance OID for scott: " + oid); + Object o =3D pm.getObjectById(oid, true); + assertSame("getObjectById should return the same instance", scott,= o);=20 + + oid =3D pm.getObjectId(ed); + if (debug) logger.debug("Instance OID for ed: " + oid); + o =3D pm.getObjectById(oid, true); + assertSame("getObjectById should return the same instance", ed, o)= ;=20 + + oid =3D pm.getObjectId(john); + if (debug) logger.debug("Instance OID for john: " + oid); + o =3D pm.getObjectById(oid, true); + assertSame("getObjectById should return the same instance", john, = o);=20 + + scottRepr =3D "PCFullTimeEmployee: PCEmployee: PCPerson: McNealy, = Scott, born 20/Aug/1969, id=3D1, hired 5/Jun/1982 manager: none dept: board= emps: 1 insurance: Aetna $200000.0"; + } + =20 + /** Check created objects by Extent and getObjectById. + */ + protected void updateObject() { + try { + pm =3D pmf.getPersistenceManager(); + tx =3D pm.currentTransaction(); + tx.begin(); + String s =3D "1";=20 + Object oid =3D pm.newObjectIdInstance(PCEmployee.class, s); + if (debug) + logger.debug("GOT OID: " + oid.getClass().getName() + + " value: " + oid); + PCEmployee p =3D (PCEmployee)pm.getObjectById(oid, true); + if (debug) logger.debug("GOT INSTANCE TO UPDATE: " + p); + + GregorianCalendar date =3D + new GregorianCalendar(TimeZone.getTimeZone("America/New_Yo= rk")); + date.set(1999, 7, 9); + + p.setHiredate(date.getTime()); + tx.commit(); + =20 + oid =3D pm.getObjectId(p); + Object o =3D pm.getObjectById(oid, true); + if (debug) logger.debug("GOT INSTANCE AFTER COMMIT: " + o); + assertSame("Expected to get same instance", p, o); + scottRepr =3D "PCFullTimeEmployee: PCEmployee: PCPerson: McNea= ly, Scott, born 20/Aug/1969, id=3D1, hired 9/Aug/1999 manager: none dept: b= oard emps: 1 insurance: Aetna $200000.0"; + assertEquals("Wrong string represenatation of updated instance= scott",=20 + scottRepr, o.toString()); + } + finally { + if (tx !=3D null && tx.isActive()) + tx.rollback(); + if (pm !=3D null && !pm.isClosed()) + pm.close(); + } + } + =20 + protected void loadAndVerifyObject(Object obj, PersistenceManager pm) { + Object oid =3D pm.getObjectId(obj); + if (debug) logger.debug("Instance OID: " + oid); + =20 + PersistenceManager pm1 =3D null; + try { + pm1 =3D pmf.getPersistenceManager(); + Object obj1 =3D 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 =3D pm1.getObjectId(obj1); + if (debug) logger.debug("OID from instance: " + oid1); + assertEquals("OID from instance not equal", oid, oid1); + Object obj2 =3D pm1.getObjectById(oid, true); + assertSame("Same instance from getObjectById", obj1, obj2); + } + finally { + if (pm1 !=3D null && !pm1.isClosed()) + pm1.close(); + } + } + + /** */ + protected void verify(int i, Object pc) { + if (debug) logger.debug("verify " + pc); + Object oid =3D JDOHelper.getObjectId(pc); + switch(i) { + case 0 : + // should be John + assertEquals("Unexpected string represenatation of John",=20 + "PCEmployee: PCPerson: One, John, born 9/Jun/1945= , id=3D900, hired 5/Apr/2001 manager: none dept: emg emps: 0 insurance: Blu= eCross",=20 + pc.toString()); + assertEquals("Unexpected oid", new PCEmployee.Oid("900"), oid); + break;=20 + case 1: + // should be Scott + assertEquals("Unexpected string represenatation of Scott", sco= ttRepr, pc.toString()); + assertEquals("Unexpected oid", new PCEmployee.Oid("1"), oid); + break; + case 2: + // should be Ed + assertEquals("Unexpected string represenatation of Ed",=20 + "PCPartTimeEmployee: PCEmployee: PCPerson: Zander= , Ed, born 8/May/1960, id=3D100, hired 3/Mar/1985 manager: McNealy dept: em= g emps: 0 insurance: BlueCross $400000.0",=20 + pc.toString()); + assertEquals("Unexpected oid", new PCEmployee.Oid("100"), oid); + break; + default: + fail("Wrong number of inserted objects, expected three"); + break; + } + } +} Added: incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_Emp= DeptAppIdDelete.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/fostore20/test/java/= org/apache/jdo/test/Test_EmpDeptAppIdDelete.java?rev=3D171355&view=3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_EmpDep= tAppIdDelete.java (added) +++ incubator/jdo/trunk/fostore20/test/java/org/apache/jdo/test/Test_EmpDep= tAppIdDelete.java Sun May 22 11:40:13 2005 @@ -0,0 +1,39 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + +package org.apache.jdo.test; + +import org.apache.jdo.test.util.JDORITestRunner; + +/** +* Test a PC that inherits from another PC with an application identity. +* +* @author Marina Vatkina +*/ +public class Test_EmpDeptAppIdDelete extends Test_EmpDeptAppId { + =20 + /** */ + public static void main(String args[]) { + JDORITestRunner.run(Test_EmpDeptAppIdDelete.class); + } + + /** */ + public void test() throws Exception=20 + { + deleteObjects(); + } =20 + +}