01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19: package org.apache.openjpa.persistence.kernel;
20:
21: import javax.persistence.EntityManager;
22:
23: import org.apache.openjpa.persistence.kernel.common.apps.InverseA;
24: import org.apache.openjpa.persistence.kernel.common.apps.InverseB;
25: import org.apache.openjpa.persistence.common.utils.AbstractTestCase;
26:
27: public class TestEJBManagedInverses extends AbstractTestCase {
28:
29: public TestEJBManagedInverses(String name) {
30: super (name, "kernelcactusapp");
31: }
32:
33: public void setUp() {
34: deleteAll(InverseA.class);
35: deleteAll(InverseB.class);
36: }
37:
38: public void testOneOne() {
39: oneOneTest(true);
40: }
41:
42: public void testOneOneWithPreStore() {
43: oneOneTest(false);
44: }
45:
46: private void oneOneTest(boolean flush) {
47: EntityManager pm = currentEntityManager();
48: startTx(pm);
49: InverseA a = new InverseA();
50: InverseA a2 = new InverseA();
51: InverseA a3 = new InverseA();
52: a.setOneOne(a2);
53: a.setOneOneOwner(a2);
54: pm.persist(a);
55: pm.persist(a3);
56:
57: // assertEquals (a, a2.getOneOne ());
58: // assertEquals (a, a2.getOneOneOwner ());
59: assertEquals("a.getOneOne is not a2", a2, a.getOneOne());
60: assertEquals("a.getOneOneOwner is not a2", a2, a
61: .getOneOneOwner());
62: endTx(pm);
63:
64: startTx(pm);
65: a2.setOneOne(a3);
66: a2.setOneOneOwner(a3);
67:
68: // assertEquals (a2, a3.getOneOne ());
69: // assertEquals (a2, a3.getOneOneOwner ());
70: assertEquals(a3, a2.getOneOne());
71: assertEquals(a3, a2.getOneOneOwner());
72: endTx(pm);
73:
74: // make sure commit doesn't retrigger changes
75: // assertEquals (a2, a3.getOneOne ());
76: // assertEquals (a2, a3.getOneOneOwner ());
77: assertEquals(a3, a2.getOneOne());
78: assertEquals(a3, a2.getOneOneOwner());
79:
80: // test persistent -> dirty
81: startTx(pm);
82: a2.setOneOne(null);
83: a2.setOneOneOwner(null);
84: // if (flush)
85: // pm.flush ();
86: // else
87: // pm.setFlushMode(FlushModeType.AUTO);
88: // assertNull (a3.getOneOne ());
89: // assertNull (a3.getOneOneOwner ());
90: endTx(pm);
91: endEm(pm);
92: }
93: }
|