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.cascade.parent;
18:
19: import java.util.HashSet;
20:
21: import org.compass.annotations.test.AbstractAnnotationsTestCase;
22: import org.compass.core.CompassHits;
23: import org.compass.core.CompassSession;
24: import org.compass.core.CompassTransaction;
25: import org.compass.core.config.CompassConfiguration;
26:
27: /**
28: * @author kimchy
29: */
30: public class ComponentParentCascadeTests extends
31: AbstractAnnotationsTestCase {
32:
33: protected void addExtraConf(CompassConfiguration conf) {
34: conf.addClass(A.class).addClass(B.class);
35: }
36:
37: public void testPlainCascades() {
38: CompassSession session = openSession();
39: CompassTransaction tr = session.beginTransaction();
40:
41: A a = new A();
42: a.id = 1;
43:
44: B b1 = new B();
45: b1.value = "b1";
46: b1.as = new HashSet<A>();
47: b1.as.add(a);
48:
49: B b2 = new B();
50: b2.value = "b2";
51: b2.as = new HashSet<A>();
52: b2.as.add(a);
53:
54: a.bs = new HashSet<B>();
55: a.bs.add(b1);
56: a.bs.add(b2);
57:
58: // saving b will cause it to cascade and save a
59: session.save(b1);
60: session.save(b2);
61:
62: CompassHits hits = session.find("b1");
63: assertEquals(1, hits.length());
64:
65: tr.commit();
66: session.close();
67: }
68:
69: public void testNullParentValueCascade() {
70: CompassSession session = openSession();
71: CompassTransaction tr = session.beginTransaction();
72:
73: B b1 = new B();
74: b1.value = "b1";
75: session.save(b1);
76:
77: tr.commit();
78: session.close();
79: }
80: }
|