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