1
1
/*
2
- * Copyright 2002-2014 the original author or authors.
2
+ * Copyright 2002-2015 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
20
20
import java .lang .reflect .Proxy ;
21
21
import java .util .Map ;
22
22
23
- import junit .framework .TestCase ;
24
23
import org .aopalliance .intercept .MethodInterceptor ;
25
24
import org .aopalliance .intercept .MethodInvocation ;
25
+ import org .junit .Before ;
26
+ import org .junit .Test ;
26
27
27
28
import org .springframework .aop .support .AopUtils ;
28
29
import org .springframework .aop .support .StaticMethodMatcherPointcut ;
40
41
import org .springframework .transaction .TransactionException ;
41
42
import org .springframework .transaction .TransactionStatus ;
42
43
44
+ import static org .junit .Assert .*;
43
45
import static org .mockito .BDDMockito .*;
44
46
47
+
45
48
/**
46
49
* Test cases for AOP transaction management.
47
50
*
48
51
* @author Rod Johnson
52
+ * @author Juergen Hoeller
49
53
* @since 23.04.2003
50
54
*/
51
- public class BeanFactoryTransactionTests extends TestCase {
55
+ public class BeanFactoryTransactionTests {
52
56
53
57
private DefaultListableBeanFactory factory ;
54
58
55
- @ Override
59
+
60
+ @ Before
56
61
public void setUp () {
57
62
this .factory = new DefaultListableBeanFactory ();
58
63
new XmlBeanDefinitionReader (this .factory ).loadBeanDefinitions (
59
64
new ClassPathResource ("transactionalBeanFactory.xml" , getClass ()));
60
65
}
61
66
67
+
68
+ @ Test
62
69
public void testGetsAreNotTransactionalWithProxyFactory1 () throws NoSuchMethodException {
63
70
ITestBean testBean = (ITestBean ) factory .getBean ("proxyFactory1" );
64
71
assertTrue ("testBean is a dynamic proxy" , Proxy .isProxyClass (testBean .getClass ()));
65
72
doTestGetsAreNotTransactional (testBean );
66
73
}
67
74
75
+ @ Test
68
76
public void testGetsAreNotTransactionalWithProxyFactory2DynamicProxy () throws NoSuchMethodException {
69
77
this .factory .preInstantiateSingletons ();
70
78
ITestBean testBean = (ITestBean ) factory .getBean ("proxyFactory2DynamicProxy" );
71
79
assertTrue ("testBean is a dynamic proxy" , Proxy .isProxyClass (testBean .getClass ()));
72
80
doTestGetsAreNotTransactional (testBean );
73
81
}
74
82
83
+ @ Test
75
84
public void testGetsAreNotTransactionalWithProxyFactory2Cglib () throws NoSuchMethodException {
76
85
ITestBean testBean = (ITestBean ) factory .getBean ("proxyFactory2Cglib" );
77
86
assertTrue ("testBean is CGLIB advised" , AopUtils .isCglibProxy (testBean ));
78
87
doTestGetsAreNotTransactional (testBean );
79
88
}
80
89
90
+ @ Test
81
91
public void testProxyFactory2Lazy () throws NoSuchMethodException {
82
92
ITestBean testBean = (ITestBean ) factory .getBean ("proxyFactory2Lazy" );
83
93
assertFalse (factory .containsSingleton ("target" ));
84
94
assertEquals (666 , testBean .getAge ());
85
95
assertTrue (factory .containsSingleton ("target" ));
86
96
}
87
97
98
+ @ Test
88
99
public void testCglibTransactionProxyImplementsNoInterfaces () throws NoSuchMethodException {
89
100
ImplementsNoInterfaces ini = (ImplementsNoInterfaces ) factory .getBean ("cglibNoInterfaces" );
90
101
assertTrue ("testBean is CGLIB advised" , AopUtils .isCglibProxy (ini ));
@@ -99,6 +110,7 @@ public void testCglibTransactionProxyImplementsNoInterfaces() throws NoSuchMetho
99
110
assertEquals (2 , ptm .commits );
100
111
}
101
112
113
+ @ Test
102
114
public void testGetsAreNotTransactionalWithProxyFactory3 () throws NoSuchMethodException {
103
115
ITestBean testBean = (ITestBean ) factory .getBean ("proxyFactory3" );
104
116
assertTrue ("testBean is a full proxy" , testBean instanceof DerivedTestBean );
@@ -158,6 +170,7 @@ public void rollback(TransactionStatus status) throws TransactionException {
158
170
assertTrue (testBean .getAge () == age );
159
171
}
160
172
173
+ @ Test
161
174
public void testGetBeansOfTypeWithAbstract () {
162
175
Map <String , ITestBean > beansOfType = factory .getBeansOfType (ITestBean .class , true , true );
163
176
assertNotNull (beansOfType );
@@ -166,6 +179,7 @@ public void testGetBeansOfTypeWithAbstract() {
166
179
/**
167
180
* Check that we fail gracefully if the user doesn't set any transaction attributes.
168
181
*/
182
+ @ Test
169
183
public void testNoTransactionAttributeSource () {
170
184
try {
171
185
DefaultListableBeanFactory bf = new DefaultListableBeanFactory ();
@@ -181,6 +195,7 @@ public void testNoTransactionAttributeSource() {
181
195
/**
182
196
* Test that we can set the target to a dynamic TargetSource.
183
197
*/
198
+ @ Test
184
199
public void testDynamicTargetSource () throws NoSuchMethodException {
185
200
// Install facade
186
201
CallCountingTransactionManager txMan = new CallCountingTransactionManager ();
0 commit comments