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.spi.JDOImplHelper;
09: import javax.jdo.spi.PersistenceCapable;
10:
11: public class TestXORM extends XORMTestCase {
12: public void testNewInterfaceInstance() {
13: PersistenceManager mgr = factory.getPersistenceManager();
14: XORM.newInstance(mgr, EmptyInterface.class);
15: }
16:
17: public void testNewAbstractClassInstance() {
18: PersistenceManager mgr = factory.getPersistenceManager();
19: XORM.newInstance(mgr, EmptyAbstractClass.class);
20: }
21:
22: /**
23: * Creates and then deletes (in two separate transactions) a simple
24: * String wrapper. The String is not initialized and should be null.
25: */
26: public void testNewPersistentString() {
27: PersistenceManager mgr = factory.getPersistenceManager();
28: mgr.currentTransaction().begin();
29: StringInterface si = (StringInterface) XORM.newInstance(mgr,
30: StringInterface.class);
31: mgr.makePersistent(si);
32: mgr.currentTransaction().commit();
33:
34: // Now delete it
35: mgr.currentTransaction().begin();
36: mgr.deletePersistent(si);
37: mgr.currentTransaction().commit();
38: }
39:
40: public void testNewOneToMany() {
41: PersistenceManager mgr = factory.getPersistenceManager();
42: mgr.currentTransaction().begin();
43: ManySide m1 = (ManySide) XORM.newInstance(mgr, ManySide.class);
44: OneSide one = (OneSide) XORM.newInstance(mgr, OneSide.class);
45: m1.setOne(one);
46: one.getMany().add(m1); // shouldn't have to do both of these, but..
47: mgr.makePersistent(m1);
48: mgr.makePersistent(one);
49: mgr.currentTransaction().commit();
50: }
51:
52: public void testJDOImplHelper() {
53: Object obj = JDOImplHelper.getInstance().newInstance(
54: EmptyInterface.class, null);
55: assertTrue(obj instanceof EmptyInterface);
56: assertTrue(obj instanceof PersistenceCapable);
57: }
58:
59: public static void main(String args[]) {
60: String[] testCaseName = { TestXORM.class.getName() };
61: junit.textui.TestRunner.main(testCaseName);
62: }
63:
64: public static Test suite() {
65: TestSuite suite = new TestSuite();
66: suite.addTestSuite(TestXORM.class);
67: suite.addTestSuite(TestStateManagement.class);
68: suite.addTestSuite(TestJDOEnhanced.class);
69: suite.addTestSuite(TestObjectId.class);
70: suite.addTestSuite(TestStringOps.class);
71: return suite;
72: }
73:
74: }
|