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.nounmarshall.component.cyclic2;
18:
19: import java.util.HashSet;
20:
21: import org.compass.core.CompassSession;
22: import org.compass.core.CompassTransaction;
23: import org.compass.core.Property;
24: import org.compass.core.Resource;
25: import org.compass.core.mapping.ResourceMapping;
26: import org.compass.core.mapping.ResourcePropertyMapping;
27: import org.compass.core.spi.InternalCompass;
28: import org.compass.core.test.AbstractTestCase;
29:
30: /**
31: * @author kimchy
32: */
33: public class Cyclic2Tests extends AbstractTestCase {
34:
35: protected String[] getMappings() {
36: return new String[] { "nounmarshall/component/cyclic2/mapping.cpm.xml" };
37: }
38:
39: public void testMappings() {
40: ResourceMapping aMapping = ((InternalCompass) getCompass())
41: .getMapping().getRootMappingByAlias("a");
42: ResourcePropertyMapping[] aPropertyMappings = aMapping
43: .getResourcePropertyMappings();
44: assertEquals(5, aPropertyMappings.length);
45: }
46:
47: public void testSimpleCyclicNoUnmarshall() {
48: CompassSession session = openSession();
49: CompassTransaction tr = session.beginTransaction();
50:
51: A a = new A();
52: a.id = 1;
53: a.value = "avalue";
54:
55: B b = new B();
56: b.value = "bvalue";
57:
58: C c = new C();
59: c.value = "cvalue";
60:
61: D d = new D();
62: d.value = "dvalue";
63:
64: a.b = b;
65: b.c = c;
66: b.d = d;
67: c.a = a;
68: d.b = b;
69:
70: session.save(a);
71:
72: Resource resource = session.loadResource(A.class, 1);
73: // 5 mappings + uid + alias
74: assertEquals(7, resource.getProperties().length);
75: HashSet<String> values = new HashSet<String>();
76: for (Property prop : resource.getProperties("value")) {
77: values.add(prop.getStringValue());
78: }
79: assertEquals(4, values.size());
80: assertTrue(values.contains("avalue"));
81: assertTrue(values.contains("bvalue"));
82: assertTrue(values.contains("cvalue"));
83: assertTrue(values.contains("dvalue"));
84:
85: assertNotNull(resource.getValue("$/a/id"));
86: assertNotNull(resource.getValue("$/uid"));
87:
88: tr.commit();
89: session.close();
90: }
91: }
|