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.deephierarchy2;
18:
19: import java.util.ArrayList;
20: import java.util.Iterator;
21: import java.util.List;
22:
23: import org.compass.core.CompassSession;
24: import org.compass.core.CompassTransaction;
25: import org.compass.core.test.AbstractTestCase;
26:
27: /**
28: * @author kimchy
29: */
30: public class DeepHierarchy2Tests extends AbstractTestCase {
31:
32: protected String[] getMappings() {
33: return new String[] { "component/deephierarchy2/mapping.cpm.xml" };
34: }
35:
36: public void testNullValue() {
37: CompassSession session = openSession();
38: CompassTransaction tr = session.beginTransaction();
39:
40: A a = new A();
41: a.setName("A");
42: a.setId("1");
43:
44: B b = new B("1", "AA");
45:
46: List bs = new ArrayList();
47: bs.add(b);
48: a.setBs(bs);
49:
50: session.save(a);
51:
52: b = new B("2", "AB");
53: C c = new C("3", "AC3");
54:
55: List childrenOf1 = new ArrayList();
56: childrenOf1.add(c);
57: b.setCs(childrenOf1);
58:
59: List newBs = new ArrayList(a.getBs());
60: newBs.add(b);
61: a.setBs(newBs);
62:
63: session.save(a);
64:
65: a = (A) session.load(A.class, "1");
66: for (Iterator it = a.getBs().iterator(); it.hasNext();) {
67: b = (B) it.next();
68: int childrenSize = b.getCs() == null ? 0 : b.getCs().size();
69: if (b.getName().equals("AA")) {
70: assertEquals(0, childrenSize);
71: } else if (b.getName().equals("AB")) {
72: assertEquals(1, childrenSize);
73: }
74: }
75:
76: tr.commit();
77: session.close();
78: }
79: }
|