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.component.many2many;
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 Many2ManyTests extends AbstractTestCase {
27:
28: protected String[] getMappings() {
29: return new String[] { "component/many2many/ManyToMany.cpm.xml" };
30: }
31:
32: public void testManyToMany() throws Exception {
33: CompassSession session = openSession();
34: CompassTransaction tr = session.beginTransaction();
35:
36: ManyToMany1 many11 = new ManyToMany1();
37: many11.id = new Long(1);
38: many11.value = "many11";
39:
40: ManyToMany1 many12 = new ManyToMany1();
41: many12.id = new Long(2);
42: many12.value = "many12";
43:
44: ManyToMany2 many21 = new ManyToMany2();
45: many21.id = new Long(1);
46: many21.value = "many21";
47:
48: many11.many2.add(many21);
49: many12.many2.add(many21);
50:
51: many21.many1.add(many11);
52: many21.many1.add(many12);
53:
54: session.save(many11);
55: session.save(many12);
56: session.save(many21);
57:
58: many21 = (ManyToMany2) session.load("many2", new Long(1));
59: assertEquals("many21", many21.value);
60: assertEquals(2, many21.many1.size());
61: assertEquals("many11",
62: ((ManyToMany1) many21.many1.get(0)).value);
63: assertEquals("many12",
64: ((ManyToMany1) many21.many1.get(1)).value);
65:
66: many11 = (ManyToMany1) session.load("many1", new Long(1));
67: assertEquals("many11", many11.value);
68: assertEquals(1, many11.many2.size());
69: assertEquals("many21",
70: ((ManyToMany2) many11.many2.get(0)).value);
71:
72: tr.commit();
73: session.close();
74: }
75:
76: }
|