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.annotations.test.component.deeplevel1;
18:
19: import java.util.Arrays;
20:
21: import org.compass.annotations.test.AbstractAnnotationsTestCase;
22: import org.compass.core.CompassSession;
23: import org.compass.core.CompassTransaction;
24: import org.compass.core.config.CompassConfiguration;
25:
26: /**
27: * @author kimchy
28: */
29: public class DataMovesAroundTest extends AbstractAnnotationsTestCase {
30:
31: protected void addExtraConf(CompassConfiguration conf) {
32: conf.addClass(A.class).addClass(B.class).addClass(C.class)
33: .addClass(D.class);
34: }
35:
36: public void testWeirdness() throws Exception {
37: A original = new A();
38: original.setId(1);
39:
40: B b1 = createB(2, 5);
41: B b2 = createB(3, null);
42: original.setBs(Arrays.asList(b2, b1));
43:
44: // save
45: CompassSession session = openSession();
46: CompassTransaction transaction = session.beginTransaction();
47: session.save(original);
48: transaction.commit();
49: session.close();
50:
51: // fetch
52: session = openSession();
53: transaction = session.beginTransaction();
54: A retrieved = (A) session.load(A.class, original.getId());
55: transaction.commit();
56: session.close();
57:
58: // validate
59: assertEquals(2, retrieved.getBs().size());
60: b2 = retrieved.getBs().get(0);
61: assertEquals(3, b2.getD().getId().intValue());
62: assertEquals("3", b2.getD().getValue());
63: assertNull(b2.getC());
64:
65: b1 = retrieved.getBs().get(1);
66: assertEquals(2, b1.getD().getId().intValue());
67: assertEquals("2", b1.getD().getValue());
68: assertEquals(5, b1.getC().getId().intValue());
69: assertEquals("5", b1.getC().getValue());
70: }
71:
72: private B createB(Integer dId, Integer cId) {
73: D d = new D();
74: d.setId(dId);
75: d.setValue(dId.toString());
76:
77: C c = null;
78: if (cId != null) {
79: c = new C();
80: c.setId(cId);
81: c.setValue(cId.toString());
82: }
83:
84: return new B(c, d);
85: }
86: }
|