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.core.test.component.cascade.array;
18:
19: import org.compass.core.CompassSession;
20: import org.compass.core.CompassTransaction;
21: import org.compass.core.test.AbstractTestCase;
22:
23: /**
24: * Simple tests for cascading operation between two root objects (A and B)
25: * with component mapping on an array property.
26: *
27: * @author kimchy
28: */
29: public class ArrayCascadeTests extends AbstractTestCase {
30:
31: protected String[] getMappings() {
32: return new String[] { "component/cascade/array/mapping.cpm.xml" };
33: }
34:
35: public void testCascadeAll() {
36: CompassSession session = openSession();
37: CompassTransaction tr = session.beginTransaction();
38:
39: B b1 = new B(1, "bvalue1");
40: B b2 = new B(2, "bvalue2");
41: A a = new A(1, "avalue", new B[] { b1, b2 });
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: session.load("b", "2");
48:
49: a.b[0].value = "bupdated1";
50: a.b[1].value = "bupdated2";
51: session.save("a", a);
52: b1 = (B) session.load("b", "1");
53: assertEquals("bupdated1", b1.value);
54: b2 = (B) session.load("b", "2");
55: assertEquals("bupdated2", b2.value);
56:
57: session.delete("a", a);
58: assertNull(session.get("a", "1"));
59: assertNull(session.get("b", "1"));
60: assertNull(session.get("b", "2"));
61:
62: tr.commit();
63: session.close();
64: }
65: }
|