1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.kuali.student.common_test_tester; |
17 |
|
|
18 |
|
import static org.junit.Assert.assertEquals; |
19 |
|
import static org.junit.Assert.assertNotNull; |
20 |
|
import static org.junit.Assert.assertTrue; |
21 |
|
|
22 |
|
import java.lang.reflect.Method; |
23 |
|
|
24 |
|
import org.aopalliance.aop.Advice; |
25 |
|
import org.apache.log4j.Logger; |
26 |
|
import org.aspectj.lang.ProceedingJoinPoint; |
27 |
|
import org.junit.Test; |
28 |
|
import org.kuali.student.common.test.spring.AbstractServiceTest; |
29 |
|
import org.kuali.student.common.test.spring.Client; |
30 |
|
import org.kuali.student.common.test.spring.Dao; |
31 |
|
import org.kuali.student.common.test.spring.Daos; |
32 |
|
import org.kuali.student.common.test.spring.IdToObjectEhcacheAdvice; |
33 |
|
import org.kuali.student.common.test.spring.PersistenceFileLocation; |
34 |
|
import org.kuali.student.common_test_tester.support.MyService; |
35 |
|
import org.springframework.aop.aspectj.AspectInstanceFactory; |
36 |
|
import org.springframework.aop.aspectj.AspectJAroundAdvice; |
37 |
|
import org.springframework.aop.aspectj.AspectJExpressionPointcut; |
38 |
|
import org.springframework.aop.aspectj.AspectJPointcutAdvisor; |
39 |
|
import org.springframework.aop.aspectj.SingletonAspectInstanceFactory; |
40 |
|
import org.springframework.aop.framework.ProxyFactory; |
41 |
|
|
42 |
|
@Daos( { |
43 |
|
@Dao(value = "org.kuali.student.common_test_tester.support.MyDaoImpl", testDataFile = "classpath:META-INF/load-my-beans.xml",testSqlFile="classpath:test.sql"), |
44 |
|
@Dao("org.kuali.student.common_test_tester.support.OtherDaoImpl") }) |
45 |
|
@PersistenceFileLocation("classpath:META-INF/test-persistence.xml") |
|
|
| 93.9% |
Uncovered Elements: 2 (33) |
Complexity: 5 |
Complexity Density: 0.17 |
|
46 |
|
public class ServiceCommonTest extends AbstractServiceTest { |
47 |
|
final Logger LOG = Logger.getLogger(ServiceCommonTest.class); |
48 |
|
@Client(value="org.kuali.student.common_test_tester.support.MyServiceImpl",additionalContextFile="classpath:test-my-additional-context.xml") |
49 |
|
private MyService client; |
50 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1
PASS
|
|
51 |
1
|
@Test... |
52 |
|
public void test1() { |
53 |
1
|
LOG.info(System.getProperty("ks.test.daoImplClasses")); |
54 |
1
|
assertNotNull(client.saveString("la la la")); |
55 |
|
} |
56 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1
PASS
|
|
57 |
1
|
@Test... |
58 |
|
public void testDaoLoader(){ |
59 |
1
|
String value = "loaded-value"; |
60 |
1
|
assertEquals(value, client.findValueFromValue(value)); |
61 |
|
} |
62 |
|
|
|
|
| 92.3% |
Uncovered Elements: 2 (26) |
Complexity: 3 |
Complexity Density: 0.12 |
1
PASS
|
|
63 |
1
|
@Test... |
64 |
|
public void testClientCaching() { |
65 |
|
|
66 |
1
|
MyService cachedClient = client; |
67 |
1
|
try { |
68 |
|
|
69 |
1
|
ProxyFactory factory = new ProxyFactory(client); |
70 |
1
|
factory.addInterface(MyService.class); |
71 |
|
|
72 |
|
|
73 |
1
|
Advice cacheAdvice = new IdToObjectEhcacheAdvice("cachename"); |
74 |
1
|
AspectInstanceFactory aif = new SingletonAspectInstanceFactory( |
75 |
|
cacheAdvice); |
76 |
|
|
77 |
|
|
78 |
1
|
Method method = IdToObjectEhcacheAdvice.class.getMethod( |
79 |
|
"getFromCache", ProceedingJoinPoint.class); |
80 |
|
|
81 |
1
|
AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut(); |
82 |
1
|
pointcut |
83 |
|
.setExpression("execution(* org.kuali.student.common_test_tester.support.MyService.find*(..))"); |
84 |
|
|
85 |
1
|
AspectJAroundAdvice advice = new AspectJAroundAdvice(method, |
86 |
|
pointcut, aif); |
87 |
|
|
88 |
1
|
AspectJPointcutAdvisor advisor = new AspectJPointcutAdvisor(advice); |
89 |
|
|
90 |
1
|
factory.addAdvisor(advisor); |
91 |
|
|
92 |
|
|
93 |
1
|
method = IdToObjectEhcacheAdvice.class.getMethod("invalidateCache", |
94 |
|
ProceedingJoinPoint.class); |
95 |
1
|
pointcut = new AspectJExpressionPointcut(); |
96 |
1
|
pointcut |
97 |
|
.setExpression("execution(* org.kuali.student.common_test_tester.support.MyService.update*(..))"); |
98 |
1
|
advice = new AspectJAroundAdvice(method, pointcut, aif); |
99 |
1
|
advisor = new AspectJPointcutAdvisor(advice); |
100 |
1
|
factory.addAdvisor(advisor); |
101 |
|
|
102 |
1
|
cachedClient = (MyService) factory.getProxy(); |
103 |
|
} catch (SecurityException e) { |
104 |
0
|
LOG.error(e); |
105 |
|
} catch (NoSuchMethodException e) { |
106 |
0
|
LOG.error(e); |
107 |
|
} |
108 |
|
|
109 |
1
|
String id = cachedClient.saveString("Cache me!"); |
110 |
1
|
cachedClient.findStringId(id); |
111 |
|
|
112 |
1
|
assertNotNull(cachedClient.findStringId(id)); |
113 |
1
|
assertTrue(cachedClient.updateValue(id, "Updated!!!")); |
114 |
|
|
115 |
1
|
assertNotNull(cachedClient.findStringId(id)); |
116 |
|
} |
117 |
|
} |