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.aop;
18:
19: import junit.framework.TestCase;
20: import org.compass.core.Compass;
21: import org.compass.core.CompassTemplate;
22: import org.springframework.context.support.ClassPathXmlApplicationContext;
23:
24: public class CompassAopTests extends TestCase {
25:
26: private ClassPathXmlApplicationContext applicationContext;
27:
28: private MockDaoOrService mockDaoOrService;
29:
30: private Compass compass;
31:
32: private CompassTemplate compassTemplate;
33:
34: protected void setUp() throws Exception {
35: applicationContext = new ClassPathXmlApplicationContext(
36: "org/compass/spring/test/aop/applicationContext.xml");
37: mockDaoOrService = (MockDaoOrService) applicationContext
38: .getBean("mockDaoOrService");
39: compass = (Compass) applicationContext.getBean("compass");
40: compass.getSearchEngineIndexManager().cleanIndex();
41: compassTemplate = new CompassTemplate(compass);
42: }
43:
44: protected void tearDown() throws Exception {
45: compass.getSearchEngineIndexManager().deleteIndex();
46: applicationContext.close();
47: }
48:
49: public void testAop() throws Exception {
50: Long id = new Long(1);
51: A a = (A) compassTemplate.get(A.class, id);
52: assertNull(a);
53: a = new A();
54: a.setId(id);
55: a.setValue1("test");
56: mockDaoOrService.create(a);
57:
58: a = (A) compassTemplate.get(A.class, id);
59: assertNotNull(a);
60: assertEquals("test", a.getValue1());
61:
62: a.setValue1("NewTest");
63: mockDaoOrService.save(a);
64: a = (A) compassTemplate.get(A.class, id);
65: assertNotNull(a);
66: assertEquals("NewTest", a.getValue1());
67:
68: mockDaoOrService.delete(a);
69: a = (A) compassTemplate.get(A.class, id);
70: assertNull(a);
71: }
72: }
|