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.component.cyclic2;
018:
019: import java.util.ArrayList;
020: import java.util.List;
021:
022: import org.compass.core.CompassSession;
023: import org.compass.core.CompassTransaction;
024: import org.compass.core.test.AbstractTestCase;
025:
026: /**
027: * @author kimchy
028: */
029: public class ParentChildCycleComponentTests extends AbstractTestCase {
030:
031: protected String[] getMappings() {
032: return new String[] { "component/cyclic2/ParentChildCycle.cpm.xml" };
033: }
034:
035: public void testParentChildCyclic() throws Exception {
036: CompassSession session = openSession();
037: CompassTransaction tr = session.beginTransaction();
038:
039: ParentCycle parentCycle = new ParentCycle();
040: parentCycle.setId(new Long(1));
041: parentCycle.setValue("parentValue");
042:
043: ChildCycle childCycle11 = new ChildCycle();
044: childCycle11.setValue("child11");
045: ChildCycle childCycle12 = new ChildCycle();
046: childCycle12.setValue("child12");
047:
048: List children = new ArrayList();
049: children.add(childCycle11);
050: children.add(childCycle12);
051:
052: parentCycle.setChildren(children);
053:
054: ChildCycle childCycle21 = new ChildCycle();
055: childCycle21.setValue("child21");
056: ChildCycle childCycle22 = new ChildCycle();
057: childCycle22.setValue("child22");
058:
059: children = new ArrayList();
060: children.add(childCycle21);
061: children.add(childCycle22);
062: childCycle11.setChildren(children);
063:
064: ChildCycle childCycle31 = new ChildCycle();
065: childCycle31.setValue("child31");
066:
067: children = new ArrayList();
068: children.add(childCycle31);
069: childCycle21.setChildren(children);
070:
071: session.save(parentCycle);
072:
073: parentCycle = (ParentCycle) session.load(ParentCycle.class,
074: new Long(1));
075: assertEquals("parentValue", parentCycle.getValue());
076:
077: children = parentCycle.getChildren();
078: assertEquals(2, children.size());
079: childCycle11 = (ChildCycle) children.get(0);
080: assertEquals("child11", childCycle11.getValue());
081: childCycle12 = (ChildCycle) children.get(1);
082: assertEquals("child12", childCycle12.getValue());
083:
084: children = childCycle11.getChildren();
085: assertEquals(2, children.size());
086: childCycle21 = (ChildCycle) children.get(0);
087: assertEquals("child21", childCycle21.getValue());
088: childCycle22 = (ChildCycle) children.get(1);
089: assertEquals("child22", childCycle22.getValue());
090:
091: assertNull(childCycle12.getChildren());
092:
093: children = childCycle21.getChildren();
094: assertEquals(1, children.size());
095: childCycle31 = (ChildCycle) children.get(0);
096: assertEquals("child31", childCycle31.getValue());
097:
098: assertNull(childCycle22.getChildren());
099:
100: tr.commit();
101: session.close();
102: }
103: }
|