01: package org.compass.core.test.component.inheritance1;
02:
03: import org.compass.core.CompassSession;
04: import org.compass.core.CompassTransaction;
05: import org.compass.core.Resource;
06: import org.compass.core.test.AbstractTestCase;
07:
08: /**
09: * This holds a pretty complex relationship that has been reported as
10: * broken in Compass. The main goal here is to test that the relationship
11: * is supported.
12: *
13: * @author kimchy
14: */
15: public class ComponentInheritance1Tests extends AbstractTestCase {
16:
17: protected String[] getMappings() {
18: return new String[] { "component/inheritance1/Father.cpm.xml",
19: "component/inheritance1/Child.cpm.xml" };
20: }
21:
22: public void testCorrectFatherSave() throws Exception {
23: CompassSession session = openSession();
24: CompassTransaction tr = session.beginTransaction();
25:
26: FatherImpl.resetId();
27: ChildImpl.resetId();
28:
29: FatherImpl father = new FatherImpl("Sir Ivan");
30: FavouriteSonImpl favouriteSon = new FavouriteSonImpl("Ivan Jr",
31: father);
32: father.setFavouriteSon(favouriteSon);
33:
34: DaughterImpl daughter = new DaughterImpl("Betty Jr", father);
35: father.getChildren().add(daughter);
36:
37: session.save(father);
38:
39: father = (FatherImpl) session.load("father", father.getId());
40: assertEquals("Sir Ivan", father.getName());
41: assertNotNull(father.getFavouriteSon());
42: assertEquals("Ivan Jr", father.getFavouriteSon().getName());
43: assertSame(father, father.getFavouriteSon().getFather());
44: assertEquals(1, father.getChildren().size());
45: assertEquals("Betty Jr", ((DaughterImpl) father.getChildren()
46: .iterator().next()).getName());
47: assertSame(father, ((DaughterImpl) father.getChildren()
48: .iterator().next()).getFather());
49:
50: Resource resource = session.loadResource("father", father
51: .getId());
52: assertEquals(18, resource.getProperties().length);
53: assertEquals("father", resource.getValue("alias"));
54: assertEquals("0", resource.getValue("$/father/id"));
55: assertEquals("Sir Ivan", resource.getProperties("name")[0]
56: .getStringValue());
57: assertEquals("Sir Ivan", resource.getValue("$/father/name"));
58: assertEquals(FavouriteSonImpl.class.getName(), resource
59: .getValue("$/father/favouriteSon/class"));
60: assertEquals("0", resource.getValue("$/father/favouriteSon/id"));
61: assertEquals("Ivan Jr", resource.getProperties("name")[1]
62: .getStringValue());
63: assertEquals("Ivan Jr", resource
64: .getValue("$/father/favouriteSon/name"));
65: assertEquals("0", resource
66: .getValue("$/father/favouriteSon/father/id"));
67: assertEquals("child", resource.getProperties("childalias")[0]
68: .getStringValue());
69: assertEquals(DaughterImpl.class.getName(), resource
70: .getValue("$/father/children/class"));
71: assertEquals("1", resource.getValue("$/father/children/id"));
72: assertEquals("Betty Jr", resource.getProperties("name")[2]
73: .getStringValue());
74: assertEquals("Betty Jr", resource
75: .getValue("$/father/children/name"));
76: assertEquals("0", resource
77: .getValue("$/father/children/father/id"));
78: assertEquals("child", resource.getProperties("childalias")[1]
79: .getStringValue());
80: assertEquals("1", resource
81: .getValue("$/father/children/colSize"));
82:
83: tr.commit();
84: session.close();
85: }
86: }
|