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.simple;
18:
19: import org.compass.annotations.test.AbstractAnnotationsTestCase;
20: import org.compass.core.CompassHits;
21: import org.compass.core.CompassSession;
22: import org.compass.core.CompassTransaction;
23: import org.compass.core.config.CompassConfiguration;
24:
25: /**
26: * @author kimchy
27: */
28: public class SimpleTests extends AbstractAnnotationsTestCase {
29:
30: protected void addExtraConf(CompassConfiguration conf) {
31: conf.addClass(A.class);
32: conf.addClass(B.class);
33: conf.addClass(CImpl.class);
34: }
35:
36: public void testSimpleAnnotations() throws Exception {
37: CompassSession session = openSession();
38: CompassTransaction tr = session.beginTransaction();
39:
40: A a = new A();
41: a.setId(1);
42: a.setValue("value");
43: session.save(a);
44:
45: a = (A) session.load(A.class, 1);
46: assertEquals("value", a.getValue());
47:
48: CompassHits hits = session.find("value");
49: assertEquals(1, hits.length());
50:
51: tr.commit();
52: session.close();
53: }
54:
55: public void testJavaExtends() throws Exception {
56: CompassSession session = openSession();
57: CompassTransaction tr = session.beginTransaction();
58:
59: B b = new B();
60: b.setId(1);
61: b.setValue("value");
62: b.setValue1("value1");
63: session.save(b);
64:
65: b = (B) session.load(B.class, 1);
66: assertEquals("value", b.getValue());
67: assertEquals("value1", b.getValue1());
68:
69: CompassHits hits = session.find("value");
70: assertEquals(1, hits.length());
71: hits = session.find("value1");
72: assertEquals(1, hits.length());
73:
74: tr.commit();
75: session.close();
76: }
77:
78: public void testJavaInterface() throws Exception {
79: CompassSession session = openSession();
80: CompassTransaction tr = session.beginTransaction();
81:
82: CImpl cImpl = new CImpl();
83: cImpl.setId(1);
84: cImpl.setValue("value");
85: session.save(cImpl);
86:
87: CInterface cInteface = (CInterface) session
88: .load(CImpl.class, 1);
89: assertEquals("value", cInteface.getValue());
90:
91: CompassHits hits = session.find("value");
92: assertEquals(1, hits.length());
93:
94: tr.commit();
95: session.close();
96: }
97: }
|