001: /*
002: * Copyright 2004-2006 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.compass.core.test.reference.deeprel;
018:
019: import java.util.Iterator;
020:
021: import org.compass.core.CompassSession;
022: import org.compass.core.CompassTransaction;
023: import org.compass.core.test.AbstractTestCase;
024:
025: /**
026: * @author kimchy
027: */
028: public class DeepRelationshipTests extends AbstractTestCase {
029:
030: protected String[] getMappings() {
031: return new String[] { "reference/deeprel/mapping.cpm.xml" };
032: }
033:
034: public void testCorrectUnmarshalling() {
035: CompassSession session = openSession();
036: CompassTransaction tr = session.beginTransaction();
037:
038: A a = new A();
039: a.id = 1;
040: a.value = "a";
041:
042: B b1 = new B();
043: b1.id = 1;
044: b1.value = "b1";
045: b1.a = a;
046: B b2 = new B();
047: b2.id = 2;
048: b2.value = "b2";
049: b2.a = a;
050:
051: a.bs.add(b1);
052: a.bs.add(b2);
053:
054: C c11 = new C();
055: c11.id = 1;
056: c11.value = "c11";
057: c11.bs.add(b1);
058: C c12 = new C();
059: c12.id = 2;
060: c12.value = "c12";
061: c12.bs.add(b1);
062:
063: b1.cs.add(c11);
064: b1.cs.add(c12);
065:
066: C c21 = new C();
067: c21.id = 2;
068: c21.value = "c21";
069: c21.bs.add(b2);
070:
071: b2.cs.add(c21);
072:
073: session.save(a);
074: session.save(b1);
075: session.save(b2);
076: session.save(c11);
077: session.save(c12);
078: session.save(c21);
079:
080: // check unmarshalling based on a
081: a = (A) session.load(A.class, "1");
082: assertEquals(2, a.bs.size());
083: Iterator it = a.bs.iterator();
084: // since it is a set, the order might change
085: b1 = (B) it.next();
086: assertEquals(b1.a.id, 1);
087: if (b1.id == 1) {
088: assertEquals(2, b1.cs.size());
089: assertEquals(1, ((C) b1.cs.iterator().next()).bs.size());
090: } else {
091: assertEquals(1, b1.cs.size());
092: assertEquals(1, ((C) b1.cs.iterator().next()).bs.size());
093: }
094: b2 = (B) it.next();
095: assertEquals(b2.a.id, 1);
096: if (b2.id == 1) {
097: assertEquals(2, b2.cs.size());
098: assertEquals(1, ((C) b2.cs.iterator().next()).bs.size());
099: } else {
100: assertEquals(1, b2.cs.size());
101: assertEquals(1, ((C) b2.cs.iterator().next()).bs.size());
102: }
103:
104: tr.commit();
105: session.close();
106: }
107: }
|