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.cyclic1;
18:
19: import java.util.ArrayList;
20:
21: import org.compass.core.CompassSession;
22: import org.compass.core.CompassTransaction;
23: import org.compass.core.Resource;
24: import org.compass.core.test.AbstractTestCase;
25:
26: /**
27: * @author kimchy
28: */
29: public class Cyclic1Tests extends AbstractTestCase {
30:
31: protected String[] getMappings() {
32: return new String[] { "nounmarshall/component/cyclic1/Cyclic.cpm.xml" };
33: }
34:
35: public void testSingleLevelCyclic() throws Exception {
36: CompassSession session = openSession();
37: CompassTransaction tr = session.beginTransaction();
38:
39: Cyclic rootCyclic = new Cyclic();
40: rootCyclic.id = new Long(1);
41: rootCyclic.value = "rootCyclic";
42:
43: Cyclic cyclic1 = new Cyclic();
44: cyclic1.id = new Long(2);
45: cyclic1.value = "cyclic1";
46:
47: rootCyclic.cyclic = cyclic1;
48:
49: session.save(rootCyclic);
50:
51: Resource resource = session.loadResource(Cyclic.class,
52: new Long(1));
53: assertEquals(5, resource.getProperties().length);
54: assertEquals(2, resource.getProperties("value").length);
55: // this is our actual id
56: assertEquals("1", resource.getValue("$/cyclic/id"));
57: // note, only the root class mappings ids are saved
58: assertEquals(1, resource.getProperties("$/cyclic/id").length);
59:
60: tr.commit();
61: session.close();
62: }
63:
64: public void testSingleLevelCollectionCyclic() throws Exception {
65: CompassSession session = openSession();
66: CompassTransaction tr = session.beginTransaction();
67:
68: Cyclic rootCyclic = new Cyclic();
69: rootCyclic.id = new Long(1);
70: rootCyclic.value = "rootCyclic";
71:
72: Cyclic cyclic1 = new Cyclic();
73: cyclic1.id = new Long(2);
74: cyclic1.value = "cyclic1";
75:
76: Cyclic cyclic2 = new Cyclic();
77: cyclic2.id = new Long(3);
78: cyclic2.value = "cyclic2";
79:
80: rootCyclic.cyclics = new ArrayList();
81: rootCyclic.cyclics.add(cyclic1);
82: rootCyclic.cyclics.add(cyclic2);
83:
84: session.save(rootCyclic);
85:
86: Resource resource = session.loadResource(Cyclic.class,
87: new Long(1));
88: assertEquals(6, resource.getProperties().length);
89: assertEquals(3, resource.getProperties("value").length);
90: // this is our actual id
91: assertEquals("1", resource.getValue("$/cyclic/id"));
92: // note, only the root class mappings ids are saved
93: assertEquals(1, resource.getProperties("$/cyclic/id").length);
94:
95: tr.commit();
96: session.close();
97: }
98: }
|