01: package org.xorm.tests;
02:
03: import junit.framework.*;
04:
05: import org.xorm.XORM;
06: import org.xorm.tests.model.*;
07: import javax.jdo.PersistenceManager;
08: import javax.jdo.JDOHelper;
09:
10: public class TestObjectId extends XORMTestCase {
11: public TestObjectId(String name) {
12: super (name);
13: }
14:
15: private void testObjectIdImpl(PersistenceManager mgr, Object pc) {
16: Object mgrObjectId = mgr.getObjectId(pc);
17: Object helperObjectId = JDOHelper.getObjectId(pc);
18: assertTrue(
19: "PersistenceManager.getObjectId(pc) should equal JDOHelper.getObjectId(pc)",
20: mgrObjectId.equals(helperObjectId));
21: Object objectById = mgr.getObjectById(mgrObjectId, true);
22: assertTrue(
23: "getObjectById() should return the same JVM instance",
24: objectById == pc);
25: }
26:
27: public void testObjectId() {
28: PersistenceManager mgr = factory.getPersistenceManager();
29: mgr.currentTransaction().begin();
30: StringInterface pc = (StringInterface) XORM.newInstance(mgr,
31: StringInterface.class);
32: mgr.makePersistent(pc);
33: testObjectIdImpl(mgr, pc);
34: mgr.currentTransaction().commit();
35:
36: // Test again now that it's got a "real" primary key
37: mgr.currentTransaction().begin();
38: testObjectIdImpl(mgr, pc);
39: mgr.currentTransaction().commit();
40:
41: mgr.close();
42: }
43:
44: public static void main(String args[]) {
45: String[] testCaseName = { TestObjectId.class.getName() };
46: junit.textui.TestRunner.main(testCaseName);
47: }
48:
49: public static Test suite() {
50: return new TestSuite(TestObjectId.class);
51: }
52:
53: }
|