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.spring.test.context;
18:
19: import junit.framework.TestCase;
20: import org.compass.core.CompassSession;
21: import org.compass.core.CompassTransaction;
22: import org.compass.core.spi.InternalCompass;
23: import org.springframework.beans.factory.DisposableBean;
24: import org.springframework.context.ApplicationContext;
25: import org.springframework.context.support.ClassPathXmlApplicationContext;
26:
27: /**
28: * @author kimchy
29: */
30: public class SpringCompassContextTests extends TestCase {
31:
32: public void testSimpleDaoWithCompassContext() throws Exception {
33: ApplicationContext ctx = new ClassPathXmlApplicationContext(
34: "org/compass/spring/test/context/simple-context.xml");
35:
36: CompassContextDao dao = (CompassContextDao) ctx.getBean("dao");
37: assertEquals("compass", ((InternalCompass) dao.compass)
38: .getName());
39:
40: // using local transaciton, check that outer/inner works
41: CompassSession session = dao.session;
42: CompassTransaction tr = session.beginTransaction();
43:
44: A a = new A();
45: a.id = 1;
46: dao.session.save(a);
47:
48: dao.session.load(A.class, 1);
49:
50: tr.commit();
51: session.close();
52:
53: ((DisposableBean) ctx).destroy();
54: }
55:
56: public void testSimpleDaoWithLocalCompassSession() throws Exception {
57: ApplicationContext ctx = new ClassPathXmlApplicationContext(
58: "org/compass/spring/test/context/simple-context.xml");
59:
60: CompassContextDao2 dao = (CompassContextDao2) ctx
61: .getBean("dao2");
62: assertEquals("compass", ((InternalCompass) dao.compass)
63: .getName());
64:
65: // using local transaciton, check that outer/inner works
66: CompassSession session = dao.session;
67: CompassTransaction tr = session.beginTransaction();
68:
69: A a = new A();
70: a.id = 1;
71: dao.session.save(a);
72:
73: dao.session.load(A.class, 1);
74:
75: tr.commit();
76: session.close();
77:
78: ((DisposableBean) ctx).destroy();
79: }
80: }
|