|
From: Wes B. <wb...@us...> - 2006-02-08 19:14:17
|
Update of /cvsroot/xorm/xorm/unit-tests/src/java/org/xorm/test/basic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31049 Modified Files: StateTestCase.java Log Message: Add some tests related to recent issues with nontransactional persistent objects and deletion. Index: StateTestCase.java =================================================================== RCS file: /cvsroot/xorm/xorm/unit-tests/src/java/org/xorm/test/basic/StateTestCase.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** StateTestCase.java 27 Oct 2005 23:18:38 -0000 1.1 --- StateTestCase.java 8 Feb 2006 19:14:09 -0000 1.2 *************** *** 10,13 **** --- 10,14 ---- import javax.jdo.JDOHelper; + import javax.jdo.JDOObjectNotFoundException; import javax.jdo.spi.JDOImplHelper; import javax.jdo.spi.PersistenceCapable; *************** *** 109,112 **** --- 110,176 ---- } + public void testPersistentNontransactional() { + mManager.currentTransaction().begin(); + Baz pc = (Baz) XORM.newInstance(mManager, Baz.class); + pc.setName("Luka"); + mManager.makePersistent(pc); + mManager.currentTransaction().commit(); + + assertTrue("IsPersistent should be true", + JDOHelper.isPersistent(pc)); + assertFalse("IsTransactional should be false", + JDOHelper.isTransactional(pc)); + + assertTrue("Can read value back after commit", + "Luka".equals(pc.getName())); + assertFalse("IsTransactional is still false", + JDOHelper.isTransactional(pc)); + + mManager.currentTransaction().begin(); + + pc.getName(); + assertTrue("IsTransactional is now true", + JDOHelper.isTransactional(pc)); + + mManager.currentTransaction().commit(); + } + + /** + * Tests that a persistent nontransactional object + * is properly enlisted in a transaction and deleted + * from the database. + */ + public void testDeletePersistentNontransactional() { + mManager.currentTransaction().begin(); + Baz pc = (Baz) XORM.newInstance(mManager, Baz.class); + pc.setName("Luka"); + mManager.makePersistent(pc); + mManager.currentTransaction().commit(); + + Object oid = JDOHelper.getObjectId(pc); + + // Make sure it's there in the DB + Baz pc2 = (Baz) mManager.getObjectById(oid, true); + assertNotNull("Object should exist in the database", + pc2); + + // Start a new transaction to delete + mManager.currentTransaction().begin(); + mManager.deletePersistent(pc); + mManager.currentTransaction().commit(); + + // See if we can read it now + JDOObjectNotFoundException expected = null; + try { + Baz pc3 = (Baz) mManager.getObjectById(oid, true); + } catch (JDOObjectNotFoundException e) { + expected = e; + } + + assertNotNull("Retrieving deleted object should throw JDOObjectNotFoundException", + expected); + + } + /** * Asserts that an object fulfills all requirements |