Unit tests for transaction annotations on parent interfaces
Issue: SPR-15833
This commit is contained in:
parent
dd2bbcb3ec
commit
697d14a028
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -55,14 +55,14 @@ public class AnnotationTransactionAttributeSourceTests {
|
||||||
TransactionInterceptor ti = new TransactionInterceptor(ptm, tas);
|
TransactionInterceptor ti = new TransactionInterceptor(ptm, tas);
|
||||||
|
|
||||||
ProxyFactory proxyFactory = new ProxyFactory();
|
ProxyFactory proxyFactory = new ProxyFactory();
|
||||||
proxyFactory.setInterfaces(ITestBean.class);
|
proxyFactory.setInterfaces(ITestBean1.class);
|
||||||
proxyFactory.addAdvice(ti);
|
proxyFactory.addAdvice(ti);
|
||||||
proxyFactory.setTarget(tb);
|
proxyFactory.setTarget(tb);
|
||||||
ITestBean proxy = (ITestBean) proxyFactory.getProxy();
|
ITestBean1 proxy = (ITestBean1) proxyFactory.getProxy();
|
||||||
proxy.getAge();
|
proxy.getAge();
|
||||||
assertEquals(1, ptm.commits);
|
assertEquals(1, ptm.commits);
|
||||||
|
|
||||||
ITestBean serializedProxy = (ITestBean) SerializationTestUtils.serializeAndDeserialize(proxy);
|
ITestBean1 serializedProxy = (ITestBean1) SerializationTestUtils.serializeAndDeserialize(proxy);
|
||||||
serializedProxy.getAge();
|
serializedProxy.getAge();
|
||||||
Advised advised = (Advised) serializedProxy;
|
Advised advised = (Advised) serializedProxy;
|
||||||
TransactionInterceptor serializedTi = (TransactionInterceptor) advised.getAdvisors()[0].getAdvice();
|
TransactionInterceptor serializedTi = (TransactionInterceptor) advised.getAdvisors()[0].getAdvice();
|
||||||
|
|
@ -88,7 +88,7 @@ public class AnnotationTransactionAttributeSourceTests {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void transactionAttributeDeclaredOnClassMethod() throws Exception {
|
public void transactionAttributeDeclaredOnClassMethod() throws Exception {
|
||||||
Method classMethod = ITestBean.class.getMethod("getAge");
|
Method classMethod = ITestBean1.class.getMethod("getAge");
|
||||||
|
|
||||||
AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource();
|
AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource();
|
||||||
TransactionAttribute actual = atas.getTransactionAttribute(classMethod, TestBean1.class);
|
TransactionAttribute actual = atas.getTransactionAttribute(classMethod, TestBean1.class);
|
||||||
|
|
@ -104,7 +104,7 @@ public class AnnotationTransactionAttributeSourceTests {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void transactionAttributeDeclaredOnCglibClassMethod() throws Exception {
|
public void transactionAttributeDeclaredOnCglibClassMethod() throws Exception {
|
||||||
Method classMethod = ITestBean.class.getMethod("getAge");
|
Method classMethod = ITestBean1.class.getMethod("getAge");
|
||||||
TestBean1 tb = new TestBean1();
|
TestBean1 tb = new TestBean1();
|
||||||
ProxyFactory pf = new ProxyFactory(tb);
|
ProxyFactory pf = new ProxyFactory(tb);
|
||||||
pf.setProxyTargetClass(true);
|
pf.setProxyTargetClass(true);
|
||||||
|
|
@ -300,8 +300,8 @@ public class AnnotationTransactionAttributeSourceTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void transactionAttributeDeclaredOnClassMethodWithEjb3() throws Exception {
|
public void transactionAttributeDeclaredOnClassMethodWithEjb3() throws Exception {
|
||||||
Method getAgeMethod = ITestBean.class.getMethod("getAge");
|
Method getAgeMethod = ITestBean1.class.getMethod("getAge");
|
||||||
Method getNameMethod = ITestBean.class.getMethod("getName");
|
Method getNameMethod = ITestBean1.class.getMethod("getName");
|
||||||
|
|
||||||
AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource();
|
AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource();
|
||||||
TransactionAttribute getAgeAttr = atas.getTransactionAttribute(getAgeMethod, Ejb3AnnotatedBean1.class);
|
TransactionAttribute getAgeAttr = atas.getTransactionAttribute(getAgeMethod, Ejb3AnnotatedBean1.class);
|
||||||
|
|
@ -312,8 +312,8 @@ public class AnnotationTransactionAttributeSourceTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void transactionAttributeDeclaredOnClassWithEjb3() throws Exception {
|
public void transactionAttributeDeclaredOnClassWithEjb3() throws Exception {
|
||||||
Method getAgeMethod = ITestBean.class.getMethod("getAge");
|
Method getAgeMethod = ITestBean1.class.getMethod("getAge");
|
||||||
Method getNameMethod = ITestBean.class.getMethod("getName");
|
Method getNameMethod = ITestBean1.class.getMethod("getName");
|
||||||
|
|
||||||
AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource();
|
AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource();
|
||||||
TransactionAttribute getAgeAttr = atas.getTransactionAttribute(getAgeMethod, Ejb3AnnotatedBean2.class);
|
TransactionAttribute getAgeAttr = atas.getTransactionAttribute(getAgeMethod, Ejb3AnnotatedBean2.class);
|
||||||
|
|
@ -336,8 +336,8 @@ public class AnnotationTransactionAttributeSourceTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void transactionAttributeDeclaredOnClassMethodWithJta() throws Exception {
|
public void transactionAttributeDeclaredOnClassMethodWithJta() throws Exception {
|
||||||
Method getAgeMethod = ITestBean.class.getMethod("getAge");
|
Method getAgeMethod = ITestBean1.class.getMethod("getAge");
|
||||||
Method getNameMethod = ITestBean.class.getMethod("getName");
|
Method getNameMethod = ITestBean1.class.getMethod("getName");
|
||||||
|
|
||||||
AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource();
|
AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource();
|
||||||
TransactionAttribute getAgeAttr = atas.getTransactionAttribute(getAgeMethod, JtaAnnotatedBean1.class);
|
TransactionAttribute getAgeAttr = atas.getTransactionAttribute(getAgeMethod, JtaAnnotatedBean1.class);
|
||||||
|
|
@ -348,8 +348,8 @@ public class AnnotationTransactionAttributeSourceTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void transactionAttributeDeclaredOnClassWithJta() throws Exception {
|
public void transactionAttributeDeclaredOnClassWithJta() throws Exception {
|
||||||
Method getAgeMethod = ITestBean.class.getMethod("getAge");
|
Method getAgeMethod = ITestBean1.class.getMethod("getAge");
|
||||||
Method getNameMethod = ITestBean.class.getMethod("getName");
|
Method getNameMethod = ITestBean1.class.getMethod("getName");
|
||||||
|
|
||||||
AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource();
|
AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource();
|
||||||
TransactionAttribute getAgeAttr = atas.getTransactionAttribute(getAgeMethod, JtaAnnotatedBean2.class);
|
TransactionAttribute getAgeAttr = atas.getTransactionAttribute(getAgeMethod, JtaAnnotatedBean2.class);
|
||||||
|
|
@ -372,8 +372,8 @@ public class AnnotationTransactionAttributeSourceTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void transactionAttributeDeclaredOnGroovyClass() throws Exception {
|
public void transactionAttributeDeclaredOnGroovyClass() throws Exception {
|
||||||
Method getAgeMethod = ITestBean.class.getMethod("getAge");
|
Method getAgeMethod = ITestBean1.class.getMethod("getAge");
|
||||||
Method getNameMethod = ITestBean.class.getMethod("getName");
|
Method getNameMethod = ITestBean1.class.getMethod("getName");
|
||||||
Method getMetaClassMethod = GroovyObject.class.getMethod("getMetaClass");
|
Method getMetaClassMethod = GroovyObject.class.getMethod("getMetaClass");
|
||||||
|
|
||||||
AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource();
|
AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource();
|
||||||
|
|
@ -385,7 +385,7 @@ public class AnnotationTransactionAttributeSourceTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
interface ITestBean {
|
interface ITestBean1 {
|
||||||
|
|
||||||
int getAge();
|
int getAge();
|
||||||
|
|
||||||
|
|
@ -403,6 +403,10 @@ public class AnnotationTransactionAttributeSourceTests {
|
||||||
int getAge();
|
int getAge();
|
||||||
|
|
||||||
void setAge(int age);
|
void setAge(int age);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
interface ITestBean2X extends ITestBean2 {
|
||||||
|
|
||||||
String getName();
|
String getName();
|
||||||
|
|
||||||
|
|
@ -423,7 +427,7 @@ public class AnnotationTransactionAttributeSourceTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static class Empty implements ITestBean {
|
static class Empty implements ITestBean1 {
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
|
@ -460,7 +464,7 @@ public class AnnotationTransactionAttributeSourceTests {
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
static class TestBean1 implements ITestBean, Serializable {
|
static class TestBean1 implements ITestBean1, Serializable {
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
|
@ -497,7 +501,7 @@ public class AnnotationTransactionAttributeSourceTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static class TestBean2 implements ITestBean2 {
|
static class TestBean2 implements ITestBean2X {
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
|
@ -635,6 +639,7 @@ public class AnnotationTransactionAttributeSourceTests {
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Transactional(rollbackFor = Exception.class, noRollbackFor = IOException.class)
|
@Transactional(rollbackFor = Exception.class, noRollbackFor = IOException.class)
|
||||||
@interface TxWithAttribute {
|
@interface TxWithAttribute {
|
||||||
|
|
||||||
boolean readOnly();
|
boolean readOnly();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -689,23 +694,7 @@ public class AnnotationTransactionAttributeSourceTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
interface Foo<T> {
|
static class Ejb3AnnotatedBean1 implements ITestBean1 {
|
||||||
|
|
||||||
void doSomething(T theArgument);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static class MyFoo implements Foo<String> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Transactional
|
|
||||||
public void doSomething(String theArgument) {
|
|
||||||
System.out.println(theArgument);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static class Ejb3AnnotatedBean1 implements ITestBean {
|
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
|
@ -736,7 +725,7 @@ public class AnnotationTransactionAttributeSourceTests {
|
||||||
|
|
||||||
|
|
||||||
@javax.ejb.TransactionAttribute(TransactionAttributeType.SUPPORTS)
|
@javax.ejb.TransactionAttribute(TransactionAttributeType.SUPPORTS)
|
||||||
static class Ejb3AnnotatedBean2 implements ITestBean {
|
static class Ejb3AnnotatedBean2 implements ITestBean1 {
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
|
@ -807,7 +796,7 @@ public class AnnotationTransactionAttributeSourceTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static class JtaAnnotatedBean1 implements ITestBean {
|
static class JtaAnnotatedBean1 implements ITestBean1 {
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
|
@ -838,7 +827,7 @@ public class AnnotationTransactionAttributeSourceTests {
|
||||||
|
|
||||||
|
|
||||||
@javax.transaction.Transactional(javax.transaction.Transactional.TxType.SUPPORTS)
|
@javax.transaction.Transactional(javax.transaction.Transactional.TxType.SUPPORTS)
|
||||||
static class JtaAnnotatedBean2 implements ITestBean {
|
static class JtaAnnotatedBean2 implements ITestBean1 {
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
|
@ -910,7 +899,7 @@ public class AnnotationTransactionAttributeSourceTests {
|
||||||
|
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
static class GroovyTestBean implements ITestBean, GroovyObject {
|
static class GroovyTestBean implements ITestBean1, GroovyObject {
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -158,8 +158,9 @@ public class EnableTransactionManagementTests {
|
||||||
CallCountingTransactionManager txManager = ctx.getBean(CallCountingTransactionManager.class);
|
CallCountingTransactionManager txManager = ctx.getBean(CallCountingTransactionManager.class);
|
||||||
|
|
||||||
bean.saveFoo();
|
bean.saveFoo();
|
||||||
assertThat(txManager.begun, equalTo(1));
|
bean.saveBar();
|
||||||
assertThat(txManager.commits, equalTo(1));
|
assertThat(txManager.begun, equalTo(2));
|
||||||
|
assertThat(txManager.commits, equalTo(2));
|
||||||
assertThat(txManager.rollbacks, equalTo(0));
|
assertThat(txManager.rollbacks, equalTo(0));
|
||||||
|
|
||||||
ctx.close();
|
ctx.close();
|
||||||
|
|
@ -172,8 +173,9 @@ public class EnableTransactionManagementTests {
|
||||||
CallCountingTransactionManager txManager = ctx.getBean(CallCountingTransactionManager.class);
|
CallCountingTransactionManager txManager = ctx.getBean(CallCountingTransactionManager.class);
|
||||||
|
|
||||||
bean.saveFoo();
|
bean.saveFoo();
|
||||||
assertThat(txManager.begun, equalTo(1));
|
bean.saveBar();
|
||||||
assertThat(txManager.commits, equalTo(1));
|
assertThat(txManager.begun, equalTo(2));
|
||||||
|
assertThat(txManager.commits, equalTo(2));
|
||||||
assertThat(txManager.rollbacks, equalTo(0));
|
assertThat(txManager.rollbacks, equalTo(0));
|
||||||
|
|
||||||
ctx.close();
|
ctx.close();
|
||||||
|
|
@ -298,7 +300,15 @@ public class EnableTransactionManagementTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public interface TransactionalTestInterface {
|
public interface BaseTransactionalInterface {
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
default void saveBar() {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public interface TransactionalTestInterface extends BaseTransactionalInterface {
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
void saveFoo();
|
void saveFoo();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue