01: /*
02: * Copyright 2004-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.compass.annotations.test.component.cascade.simple;
18:
19: import org.compass.annotations.test.AbstractAnnotationsTestCase;
20: import org.compass.core.CompassSession;
21: import org.compass.core.CompassTransaction;
22: import org.compass.core.config.CompassConfiguration;
23:
24: /**
25: * Simple tests for cascading operation between two root objects (A and B)
26: * with component mapping.
27: *
28: * @author kimchy
29: */
30: public class SimpleCascadeTests extends AbstractAnnotationsTestCase {
31:
32: protected void addExtraConf(CompassConfiguration conf) {
33: conf.addClass(A.class).addClass(B.class);
34: }
35:
36: public void testCascadeAll() {
37: CompassSession session = openSession();
38: CompassTransaction tr = session.beginTransaction();
39:
40: B b = new B(1, "bvalue");
41: A a = new A(1, "avalue", b);
42: // this should cause cascading for b as well
43: session.create("A", a);
44:
45: a = (A) session.load("A", "1");
46: session.load("B", "1");
47:
48: a.b.value = "bupdated";
49: session.save("A", a);
50: b = (B) session.load("B", "1");
51: assertEquals("bupdated", b.value);
52:
53: session.delete("A", a);
54: assertNull(session.get("A", "1"));
55: assertNull(session.get("B", "1"));
56:
57: tr.commit();
58: session.close();
59: }
60: }
|