1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package ch.elca.el4j.tests.aspects;
18
19 import javax.annotation.Resource;
20
21 import static junit.framework.Assert.assertEquals;
22
23 import org.aopalliance.aop.Advice;
24 import org.junit.runner.RunWith;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27 import org.springframework.aop.Advisor;
28 import org.springframework.aop.aspectj.AspectJAroundAdvice;
29 import org.springframework.aop.framework.Advised;
30 import org.springframework.test.context.ContextConfiguration;
31
32 import ch.elca.el4j.tests.aspects.interceptor.ServiceLoggerInterceptor;
33 import ch.elca.el4j.tests.aspects.services.Service;
34 import ch.elca.el4j.tests.aspects.util.InvocationMonitor;
35 import ch.elca.el4j.tests.core.ModuleTestContextLoader;
36 import ch.elca.el4j.tests.core.context.junit4.EL4JJunit4ClassRunner;
37
38
39
40
41
42
43
44
45
46 @RunWith(EL4JJunit4ClassRunner.class)
47 @ContextConfiguration(
48 locations = {
49 "classpath*:mandatory/*.xml",
50 "classpath*:scenarios/db/raw/*.xml",
51 "classpath*:scenarios/dataaccess/hibernate/*.xml" },
52 loader = ModuleTestContextLoader.class)
53 public abstract class AbstractInvokationTests {
54
55
56
57 private static final Logger s_logger = LoggerFactory.getLogger(InvokationWithoutTrJ5ATest.class);
58
59
60
61
62 @Resource
63 protected Service myService;
64
65
66
67
68 protected void reportAspectInformation(Object o) {
69 if (o instanceof Advised) {
70 Advised myAdvisedService = (Advised) o;
71 for (Advisor adv : myAdvisedService.getAdvisors()) {
72 Advice advice = adv.getAdvice();
73 if (advice instanceof AspectJAroundAdvice) {
74 AspectJAroundAdvice around = (AspectJAroundAdvice) advice;
75 s_logger.info("- around advice " + around.getAspectName() + ": " + adv.getAdvice());
76 } else {
77 s_logger.info("- " + adv.getAdvice());
78 }
79 }
80 }
81 }
82
83
84
85
86 protected void commonDoubleInvokationTest() {
87 InvocationMonitor.initCounter(ServiceLoggerInterceptor.class);
88 reportAspectInformation(myService);
89 myService.oneMethod();
90 assertEquals("Service logger interceptor called not exactly once!",
91 1, InvocationMonitor.getCounter(ServiceLoggerInterceptor.class));
92 }
93 }