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.idcomponent;
18:
19: import org.compass.core.CompassSession;
20: import org.compass.core.CompassTransaction;
21: import org.compass.core.test.AbstractTestCase;
22:
23: /**
24: * @author kimchy
25: */
26: public class IdComponentTests extends AbstractTestCase {
27:
28: protected String[] getMappings() {
29: return new String[] { "idcomponent/mapping.cpm.xml" };
30: }
31:
32: public void testSimpleIdComponent() {
33: CompassSession session = openSession();
34: CompassTransaction tr = session.beginTransaction();
35:
36: A a = new A();
37: a.b = new B(1, 2);
38: a.value = "value1";
39: session.save(a);
40:
41: a = new A();
42: a.b = new B(1, 2);
43: a = session.load(A.class, a);
44: assertNotNull(a);
45:
46: a = session.load(A.class, a.b);
47: assertNotNull(a);
48:
49: tr.commit();
50: session.close();
51: }
52:
53: public void testIdComponentReferenceMapping() {
54: CompassSession session = openSession();
55: CompassTransaction tr = session.beginTransaction();
56:
57: A a = new A();
58: a.b = new B(1, 2);
59: a.value = "value1";
60: session.save(a);
61: C c = new C();
62: c.id = 1;
63: c.a = a;
64: session.save(c);
65:
66: c = session.load(C.class, "1");
67: assertNotNull(c);
68: assertNotNull(c.a);
69:
70: tr.commit();
71: session.close();
72: }
73:
74: public void testIdComponentReferenceMappingWithNullValue() {
75: CompassSession session = openSession();
76: CompassTransaction tr = session.beginTransaction();
77:
78: C c = new C();
79: c.id = 1;
80: c.a = null;
81: session.save(c);
82:
83: c = session.load(C.class, "1");
84: assertNotNull(c);
85: assertNull(c.a);
86:
87: tr.commit();
88: session.close();
89: }
90: }
|