Migrate JUnit 3 tests to JUnit 4

This commit migrates all remaining tests from JUnit 3 to JUnit 4, with
the exception of Spring's legacy JUnit 3.8 based testing framework that
is still in use in the spring-orm module.

Issue: SPR-13514
This commit is contained in:
Sam Brannen
2015-09-26 00:10:58 +02:00
parent 1580288815
commit d5ee787e1e
213 changed files with 4879 additions and 3939 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,7 +22,7 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.persistence.PersistenceException;
import junit.framework.TestCase;
import org.junit.Test;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.dao.DataAccessException;
@@ -31,6 +31,8 @@ import org.springframework.dao.support.DataAccessUtilsTests.MapPersistenceExcept
import org.springframework.dao.support.PersistenceExceptionTranslator;
import org.springframework.stereotype.Repository;
import static org.junit.Assert.*;
/**
* Tests for PersistenceExceptionTranslationAdvisor's exception translation, as applied by
* PersistenceExceptionTranslationPostProcessor.
@@ -38,7 +40,7 @@ import org.springframework.stereotype.Repository;
* @author Rod Johnson
* @author Juergen Hoeller
*/
public class PersistenceExceptionTranslationAdvisorTests extends TestCase {
public class PersistenceExceptionTranslationAdvisorTests {
private RuntimeException doNotTranslate = new RuntimeException();
@@ -57,7 +59,8 @@ public class PersistenceExceptionTranslationAdvisorTests extends TestCase {
pf.addAdvisor(new PersistenceExceptionTranslationAdvisor(pet, Repository.class));
}
public void testNoTranslationNeeded() {
@Test
public void noTranslationNeeded() {
RepositoryInterfaceImpl target = new RepositoryInterfaceImpl();
RepositoryInterface ri = createProxy(target);
@@ -81,7 +84,8 @@ public class PersistenceExceptionTranslationAdvisorTests extends TestCase {
}
}
public void testTranslationNotNeededForTheseExceptions() {
@Test
public void translationNotNeededForTheseExceptions() {
RepositoryInterfaceImpl target = new StereotypedRepositoryInterfaceImpl();
RepositoryInterface ri = createProxy(target);
@@ -105,23 +109,28 @@ public class PersistenceExceptionTranslationAdvisorTests extends TestCase {
}
}
public void testTranslationNeededForTheseExceptions() {
@Test
public void translationNeededForTheseExceptions() {
doTestTranslationNeededForTheseExceptions(new StereotypedRepositoryInterfaceImpl());
}
public void testTranslationNeededForTheseExceptionsOnSuperclass() {
@Test
public void translationNeededForTheseExceptionsOnSuperclass() {
doTestTranslationNeededForTheseExceptions(new MyStereotypedRepositoryInterfaceImpl());
}
public void testTranslationNeededForTheseExceptionsWithCustomStereotype() {
@Test
public void translationNeededForTheseExceptionsWithCustomStereotype() {
doTestTranslationNeededForTheseExceptions(new CustomStereotypedRepositoryInterfaceImpl());
}
public void testTranslationNeededForTheseExceptionsOnInterface() {
@Test
public void translationNeededForTheseExceptionsOnInterface() {
doTestTranslationNeededForTheseExceptions(new MyInterfaceStereotypedRepositoryInterfaceImpl());
}
public void testTranslationNeededForTheseExceptionsOnInheritedInterface() {
@Test
public void translationNeededForTheseExceptionsOnInheritedInterface() {
doTestTranslationNeededForTheseExceptions(new MyInterfaceInheritedStereotypedRepositoryInterfaceImpl());
}
@@ -158,7 +167,6 @@ public class PersistenceExceptionTranslationAdvisorTests extends TestCase {
void throwsPersistenceException() throws PersistenceException;
}
public static class RepositoryInterfaceImpl implements RepositoryInterface {
private RuntimeException runtimeException;
@@ -182,52 +190,37 @@ public class PersistenceExceptionTranslationAdvisorTests extends TestCase {
}
}
@Repository
public static class StereotypedRepositoryInterfaceImpl extends RepositoryInterfaceImpl {
// Extends above class just to add repository annotation
}
public static class MyStereotypedRepositoryInterfaceImpl extends StereotypedRepositoryInterfaceImpl {
}
@MyRepository
public static class CustomStereotypedRepositoryInterfaceImpl extends RepositoryInterfaceImpl {
}
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Repository
public @interface MyRepository {
}
@Repository
public interface StereotypedInterface {
}
public static class MyInterfaceStereotypedRepositoryInterfaceImpl extends RepositoryInterfaceImpl
implements StereotypedInterface {
}
public interface StereotypedInheritingInterface extends StereotypedInterface {
}
public static class MyInterfaceInheritedStereotypedRepositoryInterfaceImpl extends RepositoryInterfaceImpl
implements StereotypedInheritingInterface {
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,11 +18,10 @@ package org.springframework.dao.annotation;
import javax.persistence.PersistenceException;
import junit.framework.TestCase;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.junit.Test;
import org.springframework.aop.Advisor;
import org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator;
import org.springframework.aop.framework.Advised;
@@ -38,13 +37,17 @@ import org.springframework.dao.annotation.PersistenceExceptionTranslationAdvisor
import org.springframework.dao.support.PersistenceExceptionTranslator;
import org.springframework.stereotype.Repository;
import static org.junit.Assert.*;
/**
* @author Rod Johnson
* @author Juergen Hoeller
*/
public class PersistenceExceptionTranslationPostProcessorTests extends TestCase {
public class PersistenceExceptionTranslationPostProcessorTests {
public void testProxiesCorrectly() {
@Test
@SuppressWarnings("resource")
public void proxiesCorrectly() {
GenericApplicationContext gac = new GenericApplicationContext();
gac.registerBeanDefinition("translator",
new RootBeanDefinition(PersistenceExceptionTranslationPostProcessor.class));
@@ -122,7 +125,6 @@ public class PersistenceExceptionTranslationPostProcessorTests extends TestCase
public static class MyPersistenceExceptionTranslator implements PersistenceExceptionTranslator {
@Override
public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
if (ex instanceof PersistenceException) {
@@ -136,7 +138,6 @@ public class PersistenceExceptionTranslationPostProcessorTests extends TestCase
@Aspect
public static class LogAllAspect {
//@Before("execution(* *())")
@Before("execution(void *.additionalMethod())")
public void log(JoinPoint jp) {
System.out.println("Before " + jp.getSignature().getName());

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,26 +16,30 @@
package org.springframework.dao.support;
import junit.framework.TestCase;
import org.junit.Test;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.dao.OptimisticLockingFailureException;
import org.springframework.dao.support.DataAccessUtilsTests.MapPersistenceExceptionTranslator;
import static org.junit.Assert.*;
/**
* @author Rod Johnson
* @since 2.0
*/
public class ChainedPersistenceExceptionTranslatorTests extends TestCase {
public class ChainedPersistenceExceptionTranslatorTests {
public void testEmpty() {
@Test
public void empty() {
ChainedPersistenceExceptionTranslator pet = new ChainedPersistenceExceptionTranslator();
//MapPersistenceExceptionTranslator mpet = new MapPersistenceExceptionTranslator();
RuntimeException in = new RuntimeException("in");
assertSame(in, DataAccessUtils.translateIfNecessary(in, pet));
}
public void testExceptionTranslationWithTranslation() {
@Test
public void exceptionTranslationWithTranslation() {
MapPersistenceExceptionTranslator mpet1 = new MapPersistenceExceptionTranslator();
RuntimeException in1 = new RuntimeException("in");
InvalidDataAccessApiUsageException out1 = new InvalidDataAccessApiUsageException("out");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,20 +23,23 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import junit.framework.TestCase;
import org.junit.Test;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.IncorrectResultSizeDataAccessException;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.dao.TypeMismatchDataAccessException;
import static org.junit.Assert.*;
/**
* @author Juergen Hoeller
* @since 20.10.2004
*/
public class DataAccessUtilsTests extends TestCase {
public class DataAccessUtilsTests {
public void testWithEmptyCollection() {
@Test
public void withEmptyCollection() {
Collection<String> col = new HashSet<String>();
assertNull(DataAccessUtils.uniqueResult(col));
@@ -82,7 +85,8 @@ public class DataAccessUtilsTests extends TestCase {
}
}
public void testWithTooLargeCollection() {
@Test
public void withTooLargeCollection() {
Collection<String> col = new HashSet<String>(2);
col.add("test1");
col.add("test2");
@@ -138,7 +142,8 @@ public class DataAccessUtilsTests extends TestCase {
}
}
public void testWithInteger() {
@Test
public void withInteger() {
Collection<Integer> col = new HashSet<Integer>(1);
col.add(5);
@@ -150,7 +155,8 @@ public class DataAccessUtilsTests extends TestCase {
assertEquals(5, DataAccessUtils.longResult(col));
}
public void testWithSameIntegerInstanceTwice() {
@Test
public void withSameIntegerInstanceTwice() {
Integer i = 5;
Collection<Integer> col = new ArrayList<Integer>(1);
col.add(i);
@@ -164,7 +170,8 @@ public class DataAccessUtilsTests extends TestCase {
assertEquals(5, DataAccessUtils.longResult(col));
}
public void testWithEquivalentIntegerInstanceTwice() {
@Test
public void withEquivalentIntegerInstanceTwice() {
Collection<Integer> col = new ArrayList<Integer>(2);
col.add(new Integer(5));
col.add(new Integer(5));
@@ -180,7 +187,8 @@ public class DataAccessUtilsTests extends TestCase {
}
}
public void testWithLong() {
@Test
public void withLong() {
Collection<Long> col = new HashSet<Long>(1);
col.add(5L);
@@ -192,7 +200,8 @@ public class DataAccessUtilsTests extends TestCase {
assertEquals(5, DataAccessUtils.longResult(col));
}
public void testWithString() {
@Test
public void withString() {
Collection<String> col = new HashSet<String>(1);
col.add("test1");
@@ -217,7 +226,8 @@ public class DataAccessUtilsTests extends TestCase {
}
}
public void testWithDate() {
@Test
public void withDate() {
Date date = new Date();
Collection<Date> col = new HashSet<Date>(1);
col.add(date);
@@ -244,13 +254,15 @@ public class DataAccessUtilsTests extends TestCase {
}
}
public void testExceptionTranslationWithNoTranslation() {
@Test
public void exceptionTranslationWithNoTranslation() {
MapPersistenceExceptionTranslator mpet = new MapPersistenceExceptionTranslator();
RuntimeException in = new RuntimeException();
assertSame(in, DataAccessUtils.translateIfNecessary(in, mpet));
}
public void testExceptionTranslationWithTranslation() {
@Test
public void exceptionTranslationWithTranslation() {
MapPersistenceExceptionTranslator mpet = new MapPersistenceExceptionTranslator();
RuntimeException in = new RuntimeException("in");
InvalidDataAccessApiUsageException out = new InvalidDataAccessApiUsageException("out");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,7 +20,8 @@ import javax.transaction.Status;
import javax.transaction.TransactionManager;
import javax.transaction.UserTransaction;
import junit.framework.TestCase;
import org.junit.After;
import org.junit.Test;
import org.springframework.tests.mock.jndi.ExpectedLookupTemplate;
import org.springframework.transaction.jta.JtaTransactionManager;
@@ -29,27 +30,32 @@ import org.springframework.transaction.support.TransactionCallbackWithoutResult;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import org.springframework.transaction.support.TransactionTemplate;
import static org.junit.Assert.*;
import static org.mockito.BDDMockito.*;
/**
* @author Juergen Hoeller
* @since 05.08.2005
*/
public class JndiJtaTransactionManagerTests extends TestCase {
public class JndiJtaTransactionManagerTests {
public void testJtaTransactionManagerWithDefaultJndiLookups1() throws Exception {
@Test
public void jtaTransactionManagerWithDefaultJndiLookups1() throws Exception {
doTestJtaTransactionManagerWithDefaultJndiLookups("java:comp/TransactionManager", true, true);
}
public void testJtaTransactionManagerWithDefaultJndiLookups2() throws Exception {
@Test
public void jtaTransactionManagerWithDefaultJndiLookups2() throws Exception {
doTestJtaTransactionManagerWithDefaultJndiLookups("java:/TransactionManager", true, true);
}
public void testJtaTransactionManagerWithDefaultJndiLookupsAndNoTmFound() throws Exception {
@Test
public void jtaTransactionManagerWithDefaultJndiLookupsAndNoTmFound() throws Exception {
doTestJtaTransactionManagerWithDefaultJndiLookups("java:/tm", false, true);
}
public void testJtaTransactionManagerWithDefaultJndiLookupsAndNoUtFound() throws Exception {
@Test
public void jtaTransactionManagerWithDefaultJndiLookupsAndNoUtFound() throws Exception {
doTestJtaTransactionManagerWithDefaultJndiLookups("java:/TransactionManager", true, false);
}
@@ -116,7 +122,8 @@ public class JndiJtaTransactionManagerTests extends TestCase {
}
public void testJtaTransactionManagerWithCustomJndiLookups() throws Exception {
@Test
public void jtaTransactionManagerWithCustomJndiLookups() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
given(ut.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE, Status.STATUS_ACTIVE);
@@ -152,7 +159,8 @@ public class JndiJtaTransactionManagerTests extends TestCase {
verify(ut).commit();
}
public void testJtaTransactionManagerWithNotCacheUserTransaction() throws Exception {
@Test
public void jtaTransactionManagerWithNotCacheUserTransaction() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
given(ut.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE, Status.STATUS_ACTIVE);
@@ -201,8 +209,8 @@ public class JndiJtaTransactionManagerTests extends TestCase {
* Prevent any side-effects due to this test modifying ThreadLocals that might
* affect subsequent tests when all tests are run in the same JVM, as with Eclipse.
*/
@Override
protected void tearDown() {
@After
public void tearDown() {
assertTrue(TransactionSynchronizationManager.getResourceMap().isEmpty());
assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
assertNull(TransactionSynchronizationManager.getCurrentTransactionName());

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,7 +26,8 @@ import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
import javax.transaction.UserTransaction;
import junit.framework.TestCase;
import org.junit.After;
import org.junit.Test;
import org.springframework.dao.OptimisticLockingFailureException;
import org.springframework.tests.transaction.MockJtaTransaction;
@@ -38,15 +39,17 @@ import org.springframework.transaction.support.TransactionSynchronizationAdapter
import org.springframework.transaction.support.TransactionSynchronizationManager;
import org.springframework.transaction.support.TransactionTemplate;
import static org.junit.Assert.*;
import static org.mockito.BDDMockito.*;
/**
* @author Juergen Hoeller
* @since 12.05.2003
*/
public class JtaTransactionManagerTests extends TestCase {
public class JtaTransactionManagerTests {
public void testJtaTransactionManagerWithCommit() throws Exception {
@Test
public void jtaTransactionManagerWithCommit() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
given(ut.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE, Status.STATUS_ACTIVE);
@@ -82,7 +85,8 @@ public class JtaTransactionManagerTests extends TestCase {
verify(synch).afterCompletion(TransactionSynchronization.STATUS_COMMITTED);
}
public void testJtaTransactionManagerWithCommitAndSynchronizationOnActual() throws Exception {
@Test
public void jtaTransactionManagerWithCommitAndSynchronizationOnActual() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
given(ut.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE, Status.STATUS_ACTIVE);
@@ -110,7 +114,8 @@ public class JtaTransactionManagerTests extends TestCase {
verify(synch).afterCompletion(TransactionSynchronization.STATUS_COMMITTED);
}
public void testJtaTransactionManagerWithCommitAndSynchronizationNever() throws Exception {
@Test
public void jtaTransactionManagerWithCommitAndSynchronizationNever() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
given(ut.getStatus()).willReturn(
Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE, Status.STATUS_ACTIVE);
@@ -133,7 +138,8 @@ public class JtaTransactionManagerTests extends TestCase {
verify(ut).commit();
}
public void testJtaTransactionManagerWithRollback() throws Exception {
@Test
public void jtaTransactionManagerWithRollback() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
given(ut.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE);
final TransactionSynchronization synch = mock(TransactionSynchronization.class);
@@ -167,7 +173,8 @@ public class JtaTransactionManagerTests extends TestCase {
verify(synch).afterCompletion(TransactionSynchronization.STATUS_ROLLED_BACK);
}
public void testJtaTransactionManagerWithRollbackAndSynchronizationOnActual() throws Exception {
@Test
public void jtaTransactionManagerWithRollbackAndSynchronizationOnActual() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
given(ut.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE);
final TransactionSynchronization synch = mock(TransactionSynchronization.class);
@@ -194,7 +201,8 @@ public class JtaTransactionManagerTests extends TestCase {
verify(synch).afterCompletion(TransactionSynchronization.STATUS_ROLLED_BACK);
}
public void testJtaTransactionManagerWithRollbackAndSynchronizationNever() throws Exception {
@Test
public void jtaTransactionManagerWithRollbackAndSynchronizationNever() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
given(ut.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE);
@@ -220,7 +228,8 @@ public class JtaTransactionManagerTests extends TestCase {
verify(ut).rollback();
}
public void testJtaTransactionManagerWithExistingTransactionAndRollbackOnly() throws Exception {
@Test
public void jtaTransactionManagerWithExistingTransactionAndRollbackOnly() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
given(ut.getStatus()).willReturn(Status.STATUS_ACTIVE);
@@ -244,7 +253,8 @@ public class JtaTransactionManagerTests extends TestCase {
verify(synch).afterCompletion(TransactionSynchronization.STATUS_UNKNOWN);
}
public void testJtaTransactionManagerWithExistingTransactionAndException() throws Exception {
@Test
public void jtaTransactionManagerWithExistingTransactionAndException() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
given(ut.getStatus()).willReturn(Status.STATUS_ACTIVE);
@@ -274,7 +284,8 @@ public class JtaTransactionManagerTests extends TestCase {
verify(synch).afterCompletion(TransactionSynchronization.STATUS_UNKNOWN);
}
public void testJtaTransactionManagerWithExistingTransactionAndCommitException() throws Exception {
@Test
public void jtaTransactionManagerWithExistingTransactionAndCommitException() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
given(ut.getStatus()).willReturn(Status.STATUS_ACTIVE);
@@ -304,7 +315,8 @@ public class JtaTransactionManagerTests extends TestCase {
verify(synch).afterCompletion(TransactionSynchronization.STATUS_UNKNOWN);
}
public void testJtaTransactionManagerWithExistingTransactionAndRollbackOnlyAndNoGlobalRollback() throws Exception {
@Test
public void jtaTransactionManagerWithExistingTransactionAndRollbackOnlyAndNoGlobalRollback() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
given(ut.getStatus()).willReturn(Status.STATUS_ACTIVE);
@@ -329,7 +341,8 @@ public class JtaTransactionManagerTests extends TestCase {
verify(synch).afterCompletion(TransactionSynchronization.STATUS_UNKNOWN);
}
public void testJtaTransactionManagerWithExistingTransactionAndExceptionAndNoGlobalRollback() throws Exception {
@Test
public void jtaTransactionManagerWithExistingTransactionAndExceptionAndNoGlobalRollback() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
given(ut.getStatus()).willReturn(Status.STATUS_ACTIVE);
final TransactionSynchronization synch = mock(TransactionSynchronization.class);
@@ -358,7 +371,8 @@ public class JtaTransactionManagerTests extends TestCase {
verify(synch).afterCompletion(TransactionSynchronization.STATUS_UNKNOWN);
}
public void testJtaTransactionManagerWithExistingTransactionAndJtaSynchronization() throws Exception {
@Test
public void jtaTransactionManagerWithExistingTransactionAndJtaSynchronization() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
TransactionManager tm = mock(TransactionManager.class);
MockJtaTransaction tx = new MockJtaTransaction();
@@ -389,7 +403,8 @@ public class JtaTransactionManagerTests extends TestCase {
verify(synch).afterCompletion(TransactionSynchronization.STATUS_ROLLED_BACK);
}
public void testJtaTransactionManagerWithExistingTransactionAndSynchronizationOnActual() throws Exception {
@Test
public void jtaTransactionManagerWithExistingTransactionAndSynchronizationOnActual() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
given(ut.getStatus()).willReturn(Status.STATUS_ACTIVE);
@@ -414,7 +429,8 @@ public class JtaTransactionManagerTests extends TestCase {
verify(synch).afterCompletion(TransactionSynchronization.STATUS_UNKNOWN);
}
public void testJtaTransactionManagerWithExistingTransactionAndSynchronizationNever() throws Exception {
@Test
public void jtaTransactionManagerWithExistingTransactionAndSynchronizationNever() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
given(ut.getStatus()).willReturn(Status.STATUS_ACTIVE);
@@ -436,7 +452,8 @@ public class JtaTransactionManagerTests extends TestCase {
verify(ut).setRollbackOnly();
}
public void testJtaTransactionManagerWithExistingAndPropagationSupports() throws Exception {
@Test
public void jtaTransactionManagerWithExistingAndPropagationSupports() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
given(ut.getStatus()).willReturn(Status.STATUS_ACTIVE);
@@ -461,7 +478,8 @@ public class JtaTransactionManagerTests extends TestCase {
verify(synch).afterCompletion(TransactionSynchronization.STATUS_UNKNOWN);
}
public void testJtaTransactionManagerWithPropagationSupports() throws Exception {
@Test
public void jtaTransactionManagerWithPropagationSupports() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
given(ut.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION);
@@ -485,7 +503,8 @@ public class JtaTransactionManagerTests extends TestCase {
verify(synch).afterCompletion(TransactionSynchronization.STATUS_ROLLED_BACK);
}
public void testJtaTransactionManagerWithPropagationSupportsAndSynchronizationOnActual() throws Exception {
@Test
public void jtaTransactionManagerWithPropagationSupportsAndSynchronizationOnActual() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
given(ut.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION);
@@ -506,7 +525,8 @@ public class JtaTransactionManagerTests extends TestCase {
assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
}
public void testJtaTransactionManagerWithPropagationSupportsAndSynchronizationNever() throws Exception {
@Test
public void jtaTransactionManagerWithPropagationSupportsAndSynchronizationNever() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
given(ut.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION);
@@ -527,7 +547,8 @@ public class JtaTransactionManagerTests extends TestCase {
assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
}
public void testJtaTransactionManagerWithPropagationNotSupported() throws Exception {
@Test
public void jtaTransactionManagerWithPropagationNotSupported() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
TransactionManager tm = mock(TransactionManager.class);
Transaction tx = mock(Transaction.class);
@@ -550,7 +571,8 @@ public class JtaTransactionManagerTests extends TestCase {
verify(tm).resume(tx);
}
public void testJtaTransactionManagerWithPropagationRequiresNew() throws Exception {
@Test
public void jtaTransactionManagerWithPropagationRequiresNew() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
TransactionManager tm = mock(TransactionManager.class);
Transaction tx = mock(Transaction.class);
@@ -597,7 +619,8 @@ public class JtaTransactionManagerTests extends TestCase {
verify(tm).resume(tx);
}
public void testJtaTransactionManagerWithPropagationRequiresNewWithinSupports() throws Exception {
@Test
public void jtaTransactionManagerWithPropagationRequiresNewWithinSupports() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
given(ut.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION,
Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE, Status.STATUS_ACTIVE);
@@ -636,7 +659,8 @@ public class JtaTransactionManagerTests extends TestCase {
verify(ut).commit();
}
public void testJtaTransactionManagerWithPropagationRequiresNewAndExisting() throws Exception {
@Test
public void jtaTransactionManagerWithPropagationRequiresNewAndExisting() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
TransactionManager tm = mock(TransactionManager.class);
Transaction tx = mock(Transaction.class);
@@ -660,7 +684,8 @@ public class JtaTransactionManagerTests extends TestCase {
verify(tm).resume(tx);
}
public void testJtaTransactionManagerWithPropagationRequiresNewAndExistingWithSuspendException() throws Exception {
@Test
public void jtaTransactionManagerWithPropagationRequiresNewAndExistingWithSuspendException() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
TransactionManager tm = mock(TransactionManager.class);
given(ut.getStatus()).willReturn(Status.STATUS_ACTIVE);
@@ -685,7 +710,8 @@ public class JtaTransactionManagerTests extends TestCase {
assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
}
public void testJtaTransactionManagerWithPropagationRequiresNewAndExistingWithBeginException() throws Exception {
@Test
public void jtaTransactionManagerWithPropagationRequiresNewAndExistingWithBeginException() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
TransactionManager tm = mock(TransactionManager.class);
Transaction tx = mock(Transaction.class);
@@ -713,7 +739,8 @@ public class JtaTransactionManagerTests extends TestCase {
verify(tm).resume(tx);
}
public void testJtaTransactionManagerWithPropagationRequiresNewAndAdapter() throws Exception {
@Test
public void jtaTransactionManagerWithPropagationRequiresNewAndAdapter() throws Exception {
TransactionManager tm = mock(TransactionManager.class);
Transaction tx = mock(Transaction.class);
given(tm.getStatus()).willReturn(Status.STATUS_ACTIVE);
@@ -736,7 +763,8 @@ public class JtaTransactionManagerTests extends TestCase {
verify(tm).resume(tx);
}
public void testJtaTransactionManagerWithPropagationRequiresNewAndSuspensionNotSupported() throws Exception {
@Test
public void jtaTransactionManagerWithPropagationRequiresNewAndSuspensionNotSupported() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
given(ut.getStatus()).willReturn(Status.STATUS_ACTIVE);
@@ -758,7 +786,8 @@ public class JtaTransactionManagerTests extends TestCase {
assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
}
public void testJtaTransactionManagerWithIsolationLevel() throws Exception {
@Test
public void jtaTransactionManagerWithIsolationLevel() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
given(ut.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION);
@@ -779,7 +808,8 @@ public class JtaTransactionManagerTests extends TestCase {
}
}
public void testJtaTransactionManagerWithSystemExceptionOnIsExisting() throws Exception {
@Test
public void jtaTransactionManagerWithSystemExceptionOnIsExisting() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
given(ut.getStatus()).willThrow(new SystemException("system exception"));
@@ -799,7 +829,8 @@ public class JtaTransactionManagerTests extends TestCase {
}
}
public void testJtaTransactionManagerWithNestedBegin() throws Exception {
@Test
public void jtaTransactionManagerWithNestedBegin() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
given(ut.getStatus()).willReturn(Status.STATUS_ACTIVE);
@@ -817,7 +848,8 @@ public class JtaTransactionManagerTests extends TestCase {
verify(ut).commit();
}
public void testJtaTransactionManagerWithNotSupportedExceptionOnNestedBegin() throws Exception {
@Test
public void jtaTransactionManagerWithNotSupportedExceptionOnNestedBegin() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
given(ut.getStatus()).willReturn(Status.STATUS_ACTIVE);
willThrow(new NotSupportedException("not supported")).given(ut).begin();
@@ -839,7 +871,8 @@ public class JtaTransactionManagerTests extends TestCase {
}
}
public void testJtaTransactionManagerWithUnsupportedOperationExceptionOnNestedBegin() throws Exception {
@Test
public void jtaTransactionManagerWithUnsupportedOperationExceptionOnNestedBegin() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
given(ut.getStatus()).willReturn(Status.STATUS_ACTIVE);
willThrow(new UnsupportedOperationException("not supported")).given(ut).begin();
@@ -861,7 +894,8 @@ public class JtaTransactionManagerTests extends TestCase {
}
}
public void testJtaTransactionManagerWithSystemExceptionOnBegin() throws Exception {
@Test
public void jtaTransactionManagerWithSystemExceptionOnBegin() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
given(ut.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION);
willThrow(new SystemException("system exception")).given(ut).begin();
@@ -882,7 +916,8 @@ public class JtaTransactionManagerTests extends TestCase {
}
}
public void testJtaTransactionManagerWithRollbackExceptionOnCommit() throws Exception {
@Test
public void jtaTransactionManagerWithRollbackExceptionOnCommit() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
given(ut.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION,
Status.STATUS_ACTIVE, Status.STATUS_ACTIVE);
@@ -912,11 +947,13 @@ public class JtaTransactionManagerTests extends TestCase {
verify(ut).begin();
}
public void testJtaTransactionManagerWithNoExceptionOnGlobalRollbackOnly() throws Exception {
@Test
public void jtaTransactionManagerWithNoExceptionOnGlobalRollbackOnly() throws Exception {
doTestJtaTransactionManagerWithNoExceptionOnGlobalRollbackOnly(false);
}
public void testJtaTransactionManagerWithNoExceptionOnGlobalRollbackOnlyAndFailEarly() throws Exception {
@Test
public void jtaTransactionManagerWithNoExceptionOnGlobalRollbackOnlyAndFailEarly() throws Exception {
doTestJtaTransactionManagerWithNoExceptionOnGlobalRollbackOnly(true);
}
@@ -977,7 +1014,8 @@ public class JtaTransactionManagerTests extends TestCase {
}
}
public void testJtaTransactionManagerWithHeuristicMixedExceptionOnCommit() throws Exception {
@Test
public void jtaTransactionManagerWithHeuristicMixedExceptionOnCommit() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
given(ut.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION,
Status.STATUS_ACTIVE, Status.STATUS_ACTIVE);
@@ -1008,7 +1046,8 @@ public class JtaTransactionManagerTests extends TestCase {
verify(ut).begin();
}
public void testJtaTransactionManagerWithHeuristicRollbackExceptionOnCommit() throws Exception {
@Test
public void jtaTransactionManagerWithHeuristicRollbackExceptionOnCommit() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
given(ut.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION,
Status.STATUS_ACTIVE, Status.STATUS_ACTIVE);
@@ -1039,7 +1078,8 @@ public class JtaTransactionManagerTests extends TestCase {
verify(ut).begin();
}
public void testJtaTransactionManagerWithSystemExceptionOnCommit() throws Exception {
@Test
public void jtaTransactionManagerWithSystemExceptionOnCommit() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
given(ut.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION,
Status.STATUS_ACTIVE, Status.STATUS_ACTIVE);
@@ -1069,7 +1109,8 @@ public class JtaTransactionManagerTests extends TestCase {
verify(ut).begin();
}
public void testJtaTransactionManagerWithSystemExceptionOnRollback() throws Exception {
@Test
public void jtaTransactionManagerWithSystemExceptionOnRollback() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
given(ut.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE);
willThrow(new SystemException("system exception")).given(ut).rollback();
@@ -1098,7 +1139,8 @@ public class JtaTransactionManagerTests extends TestCase {
verify(ut).begin();
}
public void testJtaTransactionManagerWithIllegalStateExceptionOnRollbackOnly() throws Exception {
@Test
public void jtaTransactionManagerWithIllegalStateExceptionOnRollbackOnly() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
given(ut.getStatus()).willReturn(Status.STATUS_ACTIVE);
willThrow(new IllegalStateException("no existing transaction")).given(ut).setRollbackOnly();
@@ -1119,7 +1161,8 @@ public class JtaTransactionManagerTests extends TestCase {
}
}
public void testJtaTransactionManagerWithSystemExceptionOnRollbackOnly() throws Exception {
@Test
public void jtaTransactionManagerWithSystemExceptionOnRollbackOnly() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
given(ut.getStatus()).willReturn(Status.STATUS_ACTIVE);
willThrow(new SystemException("system exception")).given(ut).setRollbackOnly();
@@ -1146,7 +1189,8 @@ public class JtaTransactionManagerTests extends TestCase {
}
}
public void testJtaTransactionManagerWithDoubleCommit() throws Exception {
@Test
public void jtaTransactionManagerWithDoubleCommit() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
given(ut.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION,
Status.STATUS_ACTIVE, Status.STATUS_ACTIVE);
@@ -1171,7 +1215,8 @@ public class JtaTransactionManagerTests extends TestCase {
verify(ut).commit();
}
public void testJtaTransactionManagerWithDoubleRollback() throws Exception {
@Test
public void jtaTransactionManagerWithDoubleRollback() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
given(ut.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE);
@@ -1195,7 +1240,8 @@ public class JtaTransactionManagerTests extends TestCase {
verify(ut).rollback();
}
public void testJtaTransactionManagerWithRollbackAndCommit() throws Exception {
@Test
public void jtaTransactionManagerWithRollbackAndCommit() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
given(ut.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE);
@@ -1237,8 +1283,8 @@ public class JtaTransactionManagerTests extends TestCase {
* Prevent any side-effects due to this test modifying ThreadLocals that might
* affect subsequent tests when all tests are run in the same JVM, as with Eclipse.
*/
@Override
protected void tearDown() {
@After
public void tearDown() {
assertTrue(TransactionSynchronizationManager.getResourceMap().isEmpty());
assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
assertNull(TransactionSynchronizationManager.getCurrentTransactionName());

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,8 @@
package org.springframework.transaction;
import junit.framework.TestCase;
import org.junit.After;
import org.junit.Test;
import org.springframework.transaction.support.DefaultTransactionDefinition;
import org.springframework.transaction.support.DefaultTransactionStatus;
@@ -24,13 +25,16 @@ import org.springframework.transaction.support.TransactionCallbackWithoutResult;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import org.springframework.transaction.support.TransactionTemplate;
import static org.junit.Assert.*;
/**
* @author Juergen Hoeller
* @since 29.04.2003
*/
public class TransactionSupportTests extends TestCase {
public class TransactionSupportTests {
public void testNoExistingTransaction() {
@Test
public void noExistingTransaction() {
PlatformTransactionManager tm = new TestTransactionManager(false, true);
DefaultTransactionStatus status1 = (DefaultTransactionStatus)
tm.getTransaction(new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_SUPPORTS));
@@ -50,7 +54,8 @@ public class TransactionSupportTests extends TestCase {
}
}
public void testExistingTransaction() {
@Test
public void existingTransaction() {
PlatformTransactionManager tm = new TestTransactionManager(true, true);
DefaultTransactionStatus status1 = (DefaultTransactionStatus)
tm.getTransaction(new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_SUPPORTS));
@@ -73,7 +78,8 @@ public class TransactionSupportTests extends TestCase {
}
}
public void testCommitWithoutExistingTransaction() {
@Test
public void commitWithoutExistingTransaction() {
TestTransactionManager tm = new TestTransactionManager(false, true);
TransactionStatus status = tm.getTransaction(null);
tm.commit(status);
@@ -83,7 +89,8 @@ public class TransactionSupportTests extends TestCase {
assertTrue("no rollbackOnly", !tm.rollbackOnly);
}
public void testRollbackWithoutExistingTransaction() {
@Test
public void rollbackWithoutExistingTransaction() {
TestTransactionManager tm = new TestTransactionManager(false, true);
TransactionStatus status = tm.getTransaction(null);
tm.rollback(status);
@@ -93,7 +100,8 @@ public class TransactionSupportTests extends TestCase {
assertTrue("no rollbackOnly", !tm.rollbackOnly);
}
public void testRollbackOnlyWithoutExistingTransaction() {
@Test
public void rollbackOnlyWithoutExistingTransaction() {
TestTransactionManager tm = new TestTransactionManager(false, true);
TransactionStatus status = tm.getTransaction(null);
status.setRollbackOnly();
@@ -104,7 +112,8 @@ public class TransactionSupportTests extends TestCase {
assertTrue("no rollbackOnly", !tm.rollbackOnly);
}
public void testCommitWithExistingTransaction() {
@Test
public void commitWithExistingTransaction() {
TestTransactionManager tm = new TestTransactionManager(true, true);
TransactionStatus status = tm.getTransaction(null);
tm.commit(status);
@@ -114,7 +123,8 @@ public class TransactionSupportTests extends TestCase {
assertTrue("no rollbackOnly", !tm.rollbackOnly);
}
public void testRollbackWithExistingTransaction() {
@Test
public void rollbackWithExistingTransaction() {
TestTransactionManager tm = new TestTransactionManager(true, true);
TransactionStatus status = tm.getTransaction(null);
tm.rollback(status);
@@ -124,7 +134,8 @@ public class TransactionSupportTests extends TestCase {
assertTrue("triggered rollbackOnly", tm.rollbackOnly);
}
public void testRollbackOnlyWithExistingTransaction() {
@Test
public void rollbackOnlyWithExistingTransaction() {
TestTransactionManager tm = new TestTransactionManager(true, true);
TransactionStatus status = tm.getTransaction(null);
status.setRollbackOnly();
@@ -135,7 +146,8 @@ public class TransactionSupportTests extends TestCase {
assertTrue("triggered rollbackOnly", tm.rollbackOnly);
}
public void testTransactionTemplate() {
@Test
public void transactionTemplate() {
TestTransactionManager tm = new TestTransactionManager(false, true);
TransactionTemplate template = new TransactionTemplate(tm);
template.execute(new TransactionCallbackWithoutResult() {
@@ -149,7 +161,8 @@ public class TransactionSupportTests extends TestCase {
assertTrue("no rollbackOnly", !tm.rollbackOnly);
}
public void testTransactionTemplateWithCallbackPreference() {
@Test
public void transactionTemplateWithCallbackPreference() {
MockCallbackPreferringTransactionManager ptm = new MockCallbackPreferringTransactionManager();
TransactionTemplate template = new TransactionTemplate(ptm);
template.execute(new TransactionCallbackWithoutResult() {
@@ -161,7 +174,8 @@ public class TransactionSupportTests extends TestCase {
assertFalse(ptm.getStatus().isRollbackOnly());
}
public void testTransactionTemplateWithException() {
@Test
public void transactionTemplateWithException() {
TestTransactionManager tm = new TestTransactionManager(false, true);
TransactionTemplate template = new TransactionTemplate(tm);
final RuntimeException ex = new RuntimeException("Some application exception");
@@ -185,7 +199,8 @@ public class TransactionSupportTests extends TestCase {
}
@SuppressWarnings("serial")
public void testTransactionTemplateWithRollbackException() {
@Test
public void transactionTemplateWithRollbackException() {
final TransactionSystemException tex = new TransactionSystemException("system exception");
TestTransactionManager tm = new TestTransactionManager(false, true) {
@Override
@@ -215,7 +230,8 @@ public class TransactionSupportTests extends TestCase {
}
}
public void testTransactionTemplateWithError() {
@Test
public void transactionTemplateWithError() {
TestTransactionManager tm = new TestTransactionManager(false, true);
TransactionTemplate template = new TransactionTemplate(tm);
try {
@@ -236,7 +252,8 @@ public class TransactionSupportTests extends TestCase {
}
}
public void testTransactionTemplateInitialization() {
@Test
public void transactionTemplateInitialization() {
TestTransactionManager tm = new TestTransactionManager(false, true);
TransactionTemplate template = new TransactionTemplate();
template.setTransactionManager(tm);
@@ -283,8 +300,9 @@ public class TransactionSupportTests extends TestCase {
assertTrue("Correct isolation level set", template.getIsolationLevel() == TransactionDefinition.ISOLATION_REPEATABLE_READ);
}
@Override
protected void tearDown() {
@After
public void tearDown() {
assertTrue(TransactionSynchronizationManager.getResourceMap().isEmpty());
assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,8 @@
package org.springframework.transaction;
import junit.framework.TestCase;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
import org.springframework.beans.factory.parsing.ComponentDefinition;
@@ -25,27 +26,31 @@ import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.ClassPathResource;
import org.springframework.tests.beans.CollectingReaderEventListener;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
/**
* @author Torsten Juergeleit
* @author Juergen Hoeller
*/
public class TxNamespaceHandlerEventTests extends TestCase {
public class TxNamespaceHandlerEventTests {
private DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
private CollectingReaderEventListener eventListener = new CollectingReaderEventListener();
@Override
@Before
public void setUp() throws Exception {
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this.beanFactory);
reader.setEventListener(this.eventListener);
reader.loadBeanDefinitions(new ClassPathResource("txNamespaceHandlerTests.xml", getClass()));
}
public void testComponentEventReceived() {
@Test
public void componentEventReceived() {
ComponentDefinition component = this.eventListener.getComponentDefinition("txAdvice");
assertTrue(component instanceof BeanComponentDefinition);
assertThat(component, instanceOf(BeanComponentDefinition.class));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,7 +18,8 @@ package org.springframework.transaction;
import java.lang.reflect.Method;
import junit.framework.TestCase;
import org.junit.Before;
import org.junit.Test;
import org.springframework.aop.support.AopUtils;
import org.springframework.context.ApplicationContext;
@@ -29,11 +30,13 @@ import org.springframework.transaction.interceptor.TransactionAttribute;
import org.springframework.transaction.interceptor.TransactionAttributeSource;
import org.springframework.transaction.interceptor.TransactionInterceptor;
import static org.junit.Assert.*;
/**
* @author Rob Harrop
* @author Adrian Colyer
*/
public class TxNamespaceHandlerTests extends TestCase {
public class TxNamespaceHandlerTests {
private ApplicationContext context;
@@ -41,19 +44,22 @@ public class TxNamespaceHandlerTests extends TestCase {
private Method setAgeMethod;
@Override
@Before
public void setUp() throws Exception {
this.context = new ClassPathXmlApplicationContext("txNamespaceHandlerTests.xml", getClass());
this.getAgeMethod = ITestBean.class.getMethod("getAge", new Class[0]);
this.setAgeMethod = ITestBean.class.getMethod("setAge", new Class[] {int.class});
}
public void testIsProxy() throws Exception {
@Test
public void isProxy() throws Exception {
ITestBean bean = getTestBean();
assertTrue("testBean is not a proxy", AopUtils.isAopProxy(bean));
}
public void testInvokeTransactional() throws Exception {
@Test
public void invokeTransactional() throws Exception {
ITestBean testBean = getTestBean();
CallCountingTransactionManager ptm = (CallCountingTransactionManager) context.getBean("transactionManager");
@@ -79,7 +85,8 @@ public class TxNamespaceHandlerTests extends TestCase {
}
}
public void testRollbackRules() {
@Test
public void rollbackRules() {
TransactionInterceptor txInterceptor = (TransactionInterceptor) context.getBean("txRollbackAdvice");
TransactionAttributeSource txAttrSource = txInterceptor.getTransactionAttributeSource();
TransactionAttribute txAttr = txAttrSource.getTransactionAttribute(getAgeMethod,ITestBean.class);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,35 +16,30 @@
package org.springframework.transaction.annotation;
import junit.framework.TestCase;
import org.junit.Test;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.tests.transaction.CallCountingTransactionManager;
import org.springframework.transaction.interceptor.TransactionInterceptor;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import static org.junit.Assert.*;
/**
* @author Rob Harrop
* @author Juergen Hoeller
*/
public class AnnotationTransactionInterceptorTests extends TestCase {
public class AnnotationTransactionInterceptorTests {
private CallCountingTransactionManager ptm;
private final CallCountingTransactionManager ptm = new CallCountingTransactionManager();
private AnnotationTransactionAttributeSource source;
private final AnnotationTransactionAttributeSource source = new AnnotationTransactionAttributeSource();
private TransactionInterceptor ti;
private final TransactionInterceptor ti = new TransactionInterceptor(this.ptm, this.source);
@Override
public void setUp() {
this.ptm = new CallCountingTransactionManager();
this.source = new AnnotationTransactionAttributeSource();
this.ti = new TransactionInterceptor(this.ptm, this.source);
}
public void testClassLevelOnly() {
@Test
public void classLevelOnly() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestClassLevelOnly());
proxyFactory.addAdvice(this.ti);
@@ -64,7 +59,8 @@ public class AnnotationTransactionInterceptorTests extends TestCase {
assertGetTransactionAndCommitCount(4);
}
public void testWithSingleMethodOverride() {
@Test
public void withSingleMethodOverride() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithSingleMethodOverride());
proxyFactory.addAdvice(this.ti);
@@ -84,7 +80,8 @@ public class AnnotationTransactionInterceptorTests extends TestCase {
assertGetTransactionAndCommitCount(4);
}
public void testWithSingleMethodOverrideInverted() {
@Test
public void withSingleMethodOverrideInverted() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithSingleMethodOverrideInverted());
proxyFactory.addAdvice(this.ti);
@@ -104,7 +101,8 @@ public class AnnotationTransactionInterceptorTests extends TestCase {
assertGetTransactionAndCommitCount(4);
}
public void testWithMultiMethodOverride() {
@Test
public void withMultiMethodOverride() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithMultiMethodOverride());
proxyFactory.addAdvice(this.ti);
@@ -124,8 +122,8 @@ public class AnnotationTransactionInterceptorTests extends TestCase {
assertGetTransactionAndCommitCount(4);
}
public void testWithRollback() {
@Test
public void withRollback() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithRollback());
proxyFactory.addAdvice(this.ti);
@@ -149,7 +147,8 @@ public class AnnotationTransactionInterceptorTests extends TestCase {
}
}
public void testWithInterface() {
@Test
public void withInterface() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithInterfaceImpl());
proxyFactory.addInterface(TestWithInterface.class);
@@ -170,7 +169,8 @@ public class AnnotationTransactionInterceptorTests extends TestCase {
assertGetTransactionAndCommitCount(4);
}
public void testCrossClassInterfaceMethodLevelOnJdkProxy() throws Exception {
@Test
public void crossClassInterfaceMethodLevelOnJdkProxy() throws Exception {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new SomeServiceImpl());
proxyFactory.addInterface(SomeService.class);
@@ -188,7 +188,8 @@ public class AnnotationTransactionInterceptorTests extends TestCase {
assertGetTransactionAndCommitCount(3);
}
public void testCrossClassInterfaceOnJdkProxy() throws Exception {
@Test
public void crossClassInterfaceOnJdkProxy() throws Exception {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new OtherServiceImpl());
proxyFactory.addInterface(OtherService.class);
@@ -364,7 +365,7 @@ public class AnnotationTransactionInterceptorTests extends TestCase {
}
public static interface OtherService {
public interface OtherService {
void foo();
}

View File

@@ -22,7 +22,8 @@ import java.util.Map;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import junit.framework.TestCase;
import org.junit.After;
import org.junit.Test;
import org.springframework.aop.support.AopUtils;
import org.springframework.context.ConfigurableApplicationContext;
@@ -34,34 +35,33 @@ import org.springframework.tests.transaction.CallCountingTransactionManager;
import org.springframework.transaction.config.TransactionManagementConfigUtils;
import org.springframework.transaction.event.TransactionalEventListenerFactory;
import static org.junit.Assert.*;
/**
* @author Rob Harrop
* @author Juergen Hoeller
* @author Sam Brannen
*/
public class AnnotationTransactionNamespaceHandlerTests extends TestCase {
public class AnnotationTransactionNamespaceHandlerTests {
private ConfigurableApplicationContext context;
private final ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(
"org/springframework/transaction/annotation/annotationTransactionNamespaceHandlerTests.xml");
@Override
public void setUp() {
this.context = new ClassPathXmlApplicationContext(
"org/springframework/transaction/annotation/annotationTransactionNamespaceHandlerTests.xml");
}
@Override
protected void tearDown() {
@After
public void tearDown() {
this.context.close();
}
public void testIsProxy() throws Exception {
@Test
public void isProxy() throws Exception {
TransactionalTestBean bean = getTestBean();
assertTrue("testBean is not a proxy", AopUtils.isAopProxy(bean));
Map<String, Object> services = this.context.getBeansWithAnnotation(Service.class);
assertTrue("Stereotype annotation not visible", services.containsKey("testBean"));
}
public void testInvokeTransactional() throws Exception {
@Test
public void invokeTransactional() throws Exception {
TransactionalTestBean testBean = getTestBean();
CallCountingTransactionManager ptm = (CallCountingTransactionManager) context.getBean("transactionManager");
@@ -83,11 +83,11 @@ public class AnnotationTransactionNamespaceHandlerTests extends TestCase {
catch (Throwable throwable) {
assertEquals("Should have another started transaction", 2, ptm.begun);
assertEquals("Should have 1 rolled back transaction", 1, ptm.rollbacks);
}
}
public void testNonPublicMethodsNotAdvised() {
@Test
public void nonPublicMethodsNotAdvised() {
TransactionalTestBean testBean = getTestBean();
CallCountingTransactionManager ptm = (CallCountingTransactionManager) context.getBean("transactionManager");
@@ -96,13 +96,15 @@ public class AnnotationTransactionNamespaceHandlerTests extends TestCase {
assertEquals("Should not have any started transactions", 0, ptm.begun);
}
public void testMBeanExportAlsoWorks() throws Exception {
@Test
public void mBeanExportAlsoWorks() throws Exception {
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
assertEquals("done",
server.invoke(ObjectName.getInstance("test:type=TestBean"), "doSomething", new Object[0], new String[0]));
}
public void testTransactionalEventListenerRegisteredProperly() {
@Test
public void transactionalEventListenerRegisteredProperly() {
assertTrue(this.context.containsBean(TransactionManagementConfigUtils
.TRANSACTIONAL_EVENT_LISTENER_FACTORY_BEAN_NAME));
assertEquals(1, this.context.getBeansOfType(TransactionalEventListenerFactory.class).size());

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,10 +18,11 @@ package org.springframework.transaction.config;
import java.io.Serializable;
import junit.framework.TestCase;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.junit.Test;
import org.springframework.aop.support.AopUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
@@ -30,18 +31,22 @@ import org.springframework.tests.transaction.CallCountingTransactionManager;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import org.springframework.util.SerializationTestUtils;
import static org.junit.Assert.*;
/**
* @author Rob Harrop
* @author Juergen Hoeller
*/
public class AnnotationDrivenTests extends TestCase {
public class AnnotationDrivenTests {
public void testWithProxyTargetClass() throws Exception {
@Test
public void withProxyTargetClass() throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("annotationDrivenProxyTargetClassTests.xml", getClass());
doTestWithMultipleTransactionManagers(context);
}
public void testWithConfigurationClass() throws Exception {
@Test
public void withConfigurationClass() throws Exception {
AnnotationConfigApplicationContext parent = new AnnotationConfigApplicationContext();
parent.register(TransactionManagerConfiguration.class);
parent.refresh();
@@ -68,7 +73,9 @@ public class AnnotationDrivenTests extends TestCase {
assertEquals(2, tm2.commits);
}
public void testSerializableWithPreviousUsage() throws Exception {
@Test
@SuppressWarnings("resource")
public void serializableWithPreviousUsage() throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("annotationDrivenProxyTargetClassTests.xml", getClass());
TransactionalService service = context.getBean("service", TransactionalService.class);
service.setSomething("someName");
@@ -76,7 +83,9 @@ public class AnnotationDrivenTests extends TestCase {
service.setSomething("someName");
}
public void testSerializableWithoutPreviousUsage() throws Exception {
@Test
@SuppressWarnings("resource")
public void serializableWithoutPreviousUsage() throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("annotationDrivenProxyTargetClassTests.xml", getClass());
TransactionalService service = context.getBean("service", TransactionalService.class);
service = (TransactionalService) SerializationTestUtils.serializeAndDeserialize(service);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,7 +18,7 @@ package org.springframework.transaction.interceptor;
import java.io.IOException;
import junit.framework.TestCase;
import org.junit.Test;
import org.springframework.beans.FatalBeanException;
@@ -31,32 +31,38 @@ import static org.junit.Assert.*;
* @author Rod Johnson
* @author Rick Evans
* @author Chris Beams
* @author Sam Brannen
* @since 09.04.2003
*/
public class RollbackRuleTests extends TestCase {
public class RollbackRuleTests {
public void testFoundImmediatelyWithString() {
@Test
public void foundImmediatelyWithString() {
RollbackRuleAttribute rr = new RollbackRuleAttribute(java.lang.Exception.class.getName());
assertTrue(rr.getDepth(new Exception()) == 0);
assertEquals(0, rr.getDepth(new Exception()));
}
public void testFoundImmediatelyWithClass() {
@Test
public void foundImmediatelyWithClass() {
RollbackRuleAttribute rr = new RollbackRuleAttribute(Exception.class);
assertTrue(rr.getDepth(new Exception()) == 0);
assertEquals(0, rr.getDepth(new Exception()));
}
public void testNotFound() {
@Test
public void notFound() {
RollbackRuleAttribute rr = new RollbackRuleAttribute(java.io.IOException.class.getName());
assertTrue(rr.getDepth(new MyRuntimeException("")) == -1);
assertEquals(-1, rr.getDepth(new MyRuntimeException("")));
}
public void testAncestry() {
@Test
public void ancestry() {
RollbackRuleAttribute rr = new RollbackRuleAttribute(java.lang.Exception.class.getName());
// Exception -> Runtime -> NestedRuntime -> MyRuntimeException
assertThat(rr.getDepth(new MyRuntimeException("")), equalTo(3));
}
public void testAlwaysTrueForThrowable() {
@Test
public void alwaysTrueForThrowable() {
RollbackRuleAttribute rr = new RollbackRuleAttribute(java.lang.Throwable.class.getName());
assertTrue(rr.getDepth(new MyRuntimeException("")) > 0);
assertTrue(rr.getDepth(new IOException()) > 0);
@@ -64,31 +70,19 @@ public class RollbackRuleTests extends TestCase {
assertTrue(rr.getDepth(new RuntimeException()) > 0);
}
public void testCtorArgMustBeAThrowableClassWithNonThrowableType() {
try {
new RollbackRuleAttribute(StringBuffer.class);
fail("Cannot construct a RollbackRuleAttribute with a non-Throwable type");
}
catch (IllegalArgumentException expected) {
}
@Test(expected = IllegalArgumentException.class)
public void ctorArgMustBeAThrowableClassWithNonThrowableType() {
new RollbackRuleAttribute(StringBuffer.class);
}
public void testCtorArgMustBeAThrowableClassWithNullThrowableType() {
try {
new RollbackRuleAttribute((Class<?>) null);
fail("Cannot construct a RollbackRuleAttribute with a null-Throwable type");
}
catch (IllegalArgumentException expected) {
}
@Test(expected = IllegalArgumentException.class)
public void ctorArgMustBeAThrowableClassWithNullThrowableType() {
new RollbackRuleAttribute((Class<?>) null);
}
public void testCtorArgExceptionStringNameVersionWithNull() {
try {
new RollbackRuleAttribute((String) null);
fail("Cannot construct a RollbackRuleAttribute with a null-Throwable type");
}
catch (IllegalArgumentException expected) {
}
@Test(expected = IllegalArgumentException.class)
public void ctorArgExceptionStringNameVersionWithNull() {
new RollbackRuleAttribute((String) null);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,21 +18,17 @@ package org.springframework.transaction.interceptor;
import java.util.Properties;
import junit.framework.TestCase;
import org.junit.Test;
import org.springframework.util.SerializationTestUtils;
/**
*
* @author Rod Johnson
*/
public class TransactionAttributeSourceAdvisorTests extends TestCase {
public class TransactionAttributeSourceAdvisorTests {
public TransactionAttributeSourceAdvisorTests(String s) {
super(s);
}
public void testSerializability() throws Exception {
@Test
public void serializability() throws Exception {
TransactionInterceptor ti = new TransactionInterceptor();
ti.setTransactionAttributes(new Properties());
TransactionAttributeSourceAdvisor tas = new TransactionAttributeSourceAdvisor(ti);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,49 +18,49 @@ package org.springframework.transaction.interceptor;
import java.lang.reflect.Method;
import junit.framework.TestCase;
import org.junit.Test;
import org.springframework.transaction.TransactionDefinition;
import static org.junit.Assert.*;
/**
* Format is
* {@code FQN.Method=tx attribute representation}
* Unit tests for {@link TransactionAttributeSourceEditor}.
*
* <p>Format is: {@code FQN.Method=tx attribute representation}
*
* @author Rod Johnson
* @author Sam Brannen
* @since 26.04.2003
*/
public class TransactionAttributeSourceEditorTests extends TestCase {
public class TransactionAttributeSourceEditorTests {
public void testNull() throws Exception {
TransactionAttributeSourceEditor pe = new TransactionAttributeSourceEditor();
pe.setAsText(null);
TransactionAttributeSource tas = (TransactionAttributeSource) pe.getValue();
private final TransactionAttributeSourceEditor editor = new TransactionAttributeSourceEditor();
@Test
public void nullValue() throws Exception {
editor.setAsText(null);
TransactionAttributeSource tas = (TransactionAttributeSource) editor.getValue();
Method m = Object.class.getMethod("hashCode", (Class[]) null);
assertTrue(tas.getTransactionAttribute(m, null) == null);
assertNull(tas.getTransactionAttribute(m, null));
}
public void testInvalid() throws Exception {
TransactionAttributeSourceEditor pe = new TransactionAttributeSourceEditor();
try {
pe.setAsText("foo=bar");
fail();
}
catch (IllegalArgumentException ex) {
// Ok
}
@Test(expected = IllegalArgumentException.class)
public void invalidFormat() throws Exception {
editor.setAsText("foo=bar");
}
public void testMatchesSpecific() throws Exception {
TransactionAttributeSourceEditor pe = new TransactionAttributeSourceEditor();
// TODO need FQN?
pe.setAsText(
@Test
public void matchesSpecific() throws Exception {
editor.setAsText(
"java.lang.Object.hashCode=PROPAGATION_REQUIRED\n" +
"java.lang.Object.equals=PROPAGATION_MANDATORY\n" +
"java.lang.Object.*it=PROPAGATION_SUPPORTS\n" +
"java.lang.Object.notify=PROPAGATION_SUPPORTS\n" +
"java.lang.Object.not*=PROPAGATION_REQUIRED");
TransactionAttributeSource tas = (TransactionAttributeSource) pe.getValue();
TransactionAttributeSource tas = (TransactionAttributeSource) editor.getValue();
checkTransactionProperties(tas, Object.class.getMethod("hashCode", (Class[]) null),
TransactionDefinition.PROPAGATION_REQUIRED);
@@ -79,10 +79,10 @@ public class TransactionAttributeSourceEditorTests extends TestCase {
checkTransactionProperties(tas, Object.class.getMethod("toString", (Class[]) null), -1);
}
public void testMatchesAll() throws Exception {
TransactionAttributeSourceEditor pe = new TransactionAttributeSourceEditor();
pe.setAsText("java.lang.Object.*=PROPAGATION_REQUIRED");
TransactionAttributeSource tas = (TransactionAttributeSource) pe.getValue();
@Test
public void matchesAll() throws Exception {
editor.setAsText("java.lang.Object.*=PROPAGATION_REQUIRED");
TransactionAttributeSource tas = (TransactionAttributeSource) editor.getValue();
checkTransactionProperties(tas, Object.class.getMethod("hashCode", (Class[]) null),
TransactionDefinition.PROPAGATION_REQUIRED);
@@ -105,12 +105,12 @@ public class TransactionAttributeSourceEditorTests extends TestCase {
private void checkTransactionProperties(TransactionAttributeSource tas, Method method, int propagationBehavior) {
TransactionAttribute ta = tas.getTransactionAttribute(method, null);
if (propagationBehavior >= 0) {
assertTrue(ta != null);
assertTrue(ta.getIsolationLevel() == TransactionDefinition.ISOLATION_DEFAULT);
assertTrue(ta.getPropagationBehavior() == propagationBehavior);
assertNotNull(ta);
assertEquals(TransactionDefinition.ISOLATION_DEFAULT, ta.getIsolationLevel());
assertEquals(propagationBehavior, ta.getPropagationBehavior());
}
else {
assertTrue(ta == null);
assertNull(ta);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2006 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,11 +17,8 @@
package org.springframework.transaction.interceptor;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.transaction.TransactionDefinition;
@@ -41,7 +38,7 @@ import static org.junit.Assert.*;
public final class TransactionAttributeSourceTests {
@Test
public void testMatchAlwaysTransactionAttributeSource() throws Exception {
public void matchAlwaysTransactionAttributeSource() throws Exception {
MatchAlwaysTransactionAttributeSource tas = new MatchAlwaysTransactionAttributeSource();
TransactionAttribute ta = tas.getTransactionAttribute(
Object.class.getMethod("hashCode", (Class[]) null), null);
@@ -56,7 +53,7 @@ public final class TransactionAttributeSourceTests {
}
@Test
public void testMatchAlwaysTransactionAttributeSourceWithNulls() throws Exception {
public void matchAlwaysTransactionAttributeSourceWithNulls() throws Exception {
MatchAlwaysTransactionAttributeSource tas = new MatchAlwaysTransactionAttributeSource();
TransactionDefinition definition = tas.getTransactionAttribute(null, null);
assertEquals(TransactionDefinition.PROPAGATION_REQUIRED, definition.getPropagationBehavior());
@@ -65,65 +62,9 @@ public final class TransactionAttributeSourceTests {
assertFalse(definition.isReadOnly());
}
@SuppressWarnings("unchecked")
@Ignore // no longer works now that setMethodMap has been parameterized
@Test
public void testMethodMapTransactionAttributeSource() throws NoSuchMethodException {
MethodMapTransactionAttributeSource tas = new MethodMapTransactionAttributeSource();
Map methodMap = new HashMap();
methodMap.put(Object.class.getName() + ".hashCode", TransactionDefinition.PROPAGATION_REQUIRED);
methodMap.put(Object.class.getName() + ".toString",
new DefaultTransactionAttribute(TransactionDefinition.PROPAGATION_SUPPORTS));
tas.setMethodMap(methodMap);
tas.afterPropertiesSet();
TransactionAttribute ta = tas.getTransactionAttribute(
Object.class.getMethod("hashCode", (Class[]) null), null);
assertNotNull(ta);
assertEquals(TransactionDefinition.PROPAGATION_REQUIRED, ta.getPropagationBehavior());
ta = tas.getTransactionAttribute(Object.class.getMethod("toString", (Class[]) null), null);
assertNotNull(ta);
assertEquals(TransactionDefinition.PROPAGATION_SUPPORTS, ta.getPropagationBehavior());
}
@SuppressWarnings("unchecked")
@Ignore // no longer works now that setMethodMap has been parameterized
@Test
public void testMethodMapTransactionAttributeSourceWithLazyInit() throws NoSuchMethodException {
MethodMapTransactionAttributeSource tas = new MethodMapTransactionAttributeSource();
Map methodMap = new HashMap();
methodMap.put(Object.class.getName() + ".hashCode", "PROPAGATION_REQUIRED");
methodMap.put(Object.class.getName() + ".toString",
new DefaultTransactionAttribute(TransactionDefinition.PROPAGATION_SUPPORTS));
tas.setMethodMap(methodMap);
TransactionAttribute ta = tas.getTransactionAttribute(
Object.class.getMethod("hashCode", (Class[]) null), null);
assertNotNull(ta);
assertEquals(TransactionDefinition.PROPAGATION_REQUIRED, ta.getPropagationBehavior());
ta = tas.getTransactionAttribute(Object.class.getMethod("toString", (Class[]) null), null);
assertNotNull(ta);
assertEquals(TransactionDefinition.PROPAGATION_SUPPORTS, ta.getPropagationBehavior());
}
@SuppressWarnings("unchecked")
@Ignore // no longer works now that setMethodMap has been parameterized
@Test
public void testNameMatchTransactionAttributeSource() throws NoSuchMethodException {
NameMatchTransactionAttributeSource tas = new NameMatchTransactionAttributeSource();
Map methodMap = new HashMap();
methodMap.put("hashCode", "PROPAGATION_REQUIRED");
methodMap.put("toString", new DefaultTransactionAttribute(TransactionDefinition.PROPAGATION_SUPPORTS));
tas.setNameMap(methodMap);
TransactionAttribute ta = tas.getTransactionAttribute(
Object.class.getMethod("hashCode", (Class[]) null), null);
assertNotNull(ta);
assertEquals(TransactionDefinition.PROPAGATION_REQUIRED, ta.getPropagationBehavior());
ta = tas.getTransactionAttribute(Object.class.getMethod("toString", (Class[]) null), null);
assertNotNull(ta);
assertEquals(TransactionDefinition.PROPAGATION_SUPPORTS, ta.getPropagationBehavior());
}
@Test
public void testNameMatchTransactionAttributeSourceWithStarAtStartOfMethodName() throws NoSuchMethodException {
public void nameMatchTransactionAttributeSourceWithStarAtStartOfMethodName()
throws NoSuchMethodException {
NameMatchTransactionAttributeSource tas = new NameMatchTransactionAttributeSource();
Properties attributes = new Properties();
attributes.put("*ashCode", "PROPAGATION_REQUIRED");
@@ -135,7 +76,8 @@ public final class TransactionAttributeSourceTests {
}
@Test
public void testNameMatchTransactionAttributeSourceWithStarAtEndOfMethodName() throws NoSuchMethodException {
public void nameMatchTransactionAttributeSourceWithStarAtEndOfMethodName()
throws NoSuchMethodException {
NameMatchTransactionAttributeSource tas = new NameMatchTransactionAttributeSource();
Properties attributes = new Properties();
attributes.put("hashCod*", "PROPAGATION_REQUIRED");
@@ -147,7 +89,8 @@ public final class TransactionAttributeSourceTests {
}
@Test
public void testNameMatchTransactionAttributeSourceMostSpecificMethodNameIsDefinitelyMatched() throws NoSuchMethodException {
public void nameMatchTransactionAttributeSourceMostSpecificMethodNameIsDefinitelyMatched()
throws NoSuchMethodException {
NameMatchTransactionAttributeSource tas = new NameMatchTransactionAttributeSource();
Properties attributes = new Properties();
attributes.put("*", "PROPAGATION_REQUIRED");
@@ -160,7 +103,8 @@ public final class TransactionAttributeSourceTests {
}
@Test
public void testNameMatchTransactionAttributeSourceWithEmptyMethodName() throws NoSuchMethodException {
public void nameMatchTransactionAttributeSourceWithEmptyMethodName()
throws NoSuchMethodException {
NameMatchTransactionAttributeSource tas = new NameMatchTransactionAttributeSource();
Properties attributes = new Properties();
attributes.put("", "PROPAGATION_MANDATORY");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -128,7 +128,7 @@ public class MockUOWManager implements UOWManager {
this.synchronizations.add(sync);
}
public List getSynchronizations() {
public List<Synchronization> getSynchronizations() {
return this.synchronizations;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,10 +20,7 @@ import javax.transaction.RollbackException;
import javax.transaction.Status;
import javax.transaction.UserTransaction;
import com.ibm.wsspi.uow.UOWAction;
import com.ibm.wsspi.uow.UOWException;
import com.ibm.wsspi.uow.UOWManager;
import junit.framework.TestCase;
import org.junit.Test;
import org.springframework.dao.OptimisticLockingFailureException;
import org.springframework.tests.mock.jndi.ExpectedLookupTemplate;
@@ -36,14 +33,20 @@ import org.springframework.transaction.support.DefaultTransactionDefinition;
import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import com.ibm.wsspi.uow.UOWAction;
import com.ibm.wsspi.uow.UOWException;
import com.ibm.wsspi.uow.UOWManager;
import static org.junit.Assert.*;
import static org.mockito.BDDMockito.*;
/**
* @author Juergen Hoeller
*/
public class WebSphereUowTransactionManagerTests extends TestCase {
public class WebSphereUowTransactionManagerTests {
public void testUowManagerFoundInJndi() {
@Test
public void uowManagerFoundInJndi() {
MockUOWManager manager = new MockUOWManager();
ExpectedLookupTemplate jndiTemplate =
new ExpectedLookupTemplate(WebSphereUowTransactionManager.DEFAULT_UOW_MANAGER_NAME, manager);
@@ -64,7 +67,8 @@ public class WebSphereUowTransactionManagerTests extends TestCase {
assertFalse(manager.getRollbackOnly());
}
public void testUowManagerAndUserTransactionFoundInJndi() throws Exception {
@Test
public void uowManagerAndUserTransactionFoundInJndi() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
given(ut.getStatus()).willReturn( Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE, Status.STATUS_ACTIVE);
@@ -93,7 +97,8 @@ public class WebSphereUowTransactionManagerTests extends TestCase {
verify(ut).commit();
}
public void testPropagationMandatoryFailsInCaseOfNoExistingTransaction() {
@Test
public void propagationMandatoryFailsInCaseOfNoExistingTransaction() {
MockUOWManager manager = new MockUOWManager();
WebSphereUowTransactionManager ptm = new WebSphereUowTransactionManager(manager);
DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
@@ -113,47 +118,56 @@ public class WebSphereUowTransactionManagerTests extends TestCase {
}
}
public void testNewTransactionSynchronizationUsingPropagationSupports() {
@Test
public void newTransactionSynchronizationUsingPropagationSupports() {
doTestNewTransactionSynchronization(
TransactionDefinition.PROPAGATION_SUPPORTS, WebSphereUowTransactionManager.SYNCHRONIZATION_ALWAYS);
}
public void testNewTransactionSynchronizationUsingPropagationNotSupported() {
@Test
public void newTransactionSynchronizationUsingPropagationNotSupported() {
doTestNewTransactionSynchronization(
TransactionDefinition.PROPAGATION_NOT_SUPPORTED, WebSphereUowTransactionManager.SYNCHRONIZATION_ALWAYS);
}
public void testNewTransactionSynchronizationUsingPropagationNever() {
@Test
public void newTransactionSynchronizationUsingPropagationNever() {
doTestNewTransactionSynchronization(
TransactionDefinition.PROPAGATION_NEVER, WebSphereUowTransactionManager.SYNCHRONIZATION_ALWAYS);
}
public void testNewTransactionSynchronizationUsingPropagationSupportsAndSynchOnActual() {
@Test
public void newTransactionSynchronizationUsingPropagationSupportsAndSynchOnActual() {
doTestNewTransactionSynchronization(
TransactionDefinition.PROPAGATION_SUPPORTS, WebSphereUowTransactionManager.SYNCHRONIZATION_ON_ACTUAL_TRANSACTION);
}
public void testNewTransactionSynchronizationUsingPropagationNotSupportedAndSynchOnActual() {
@Test
public void newTransactionSynchronizationUsingPropagationNotSupportedAndSynchOnActual() {
doTestNewTransactionSynchronization(
TransactionDefinition.PROPAGATION_NOT_SUPPORTED, WebSphereUowTransactionManager.SYNCHRONIZATION_ON_ACTUAL_TRANSACTION);
}
public void testNewTransactionSynchronizationUsingPropagationNeverAndSynchOnActual() {
@Test
public void newTransactionSynchronizationUsingPropagationNeverAndSynchOnActual() {
doTestNewTransactionSynchronization(
TransactionDefinition.PROPAGATION_NEVER, WebSphereUowTransactionManager.SYNCHRONIZATION_ON_ACTUAL_TRANSACTION);
}
public void testNewTransactionSynchronizationUsingPropagationSupportsAndSynchNever() {
@Test
public void newTransactionSynchronizationUsingPropagationSupportsAndSynchNever() {
doTestNewTransactionSynchronization(
TransactionDefinition.PROPAGATION_SUPPORTS, WebSphereUowTransactionManager.SYNCHRONIZATION_NEVER);
}
public void testNewTransactionSynchronizationUsingPropagationNotSupportedAndSynchNever() {
@Test
public void newTransactionSynchronizationUsingPropagationNotSupportedAndSynchNever() {
doTestNewTransactionSynchronization(
TransactionDefinition.PROPAGATION_NOT_SUPPORTED, WebSphereUowTransactionManager.SYNCHRONIZATION_NEVER);
}
public void testNewTransactionSynchronizationUsingPropagationNeverAndSynchNever() {
@Test
public void newTransactionSynchronizationUsingPropagationNeverAndSynchNever() {
doTestNewTransactionSynchronization(
TransactionDefinition.PROPAGATION_NEVER, WebSphereUowTransactionManager.SYNCHRONIZATION_NEVER);
}
@@ -197,47 +211,56 @@ public class WebSphereUowTransactionManagerTests extends TestCase {
assertFalse(manager.getRollbackOnly());
}
public void testNewTransactionWithCommitUsingPropagationRequired() {
@Test
public void newTransactionWithCommitUsingPropagationRequired() {
doTestNewTransactionWithCommit(
TransactionDefinition.PROPAGATION_REQUIRED, WebSphereUowTransactionManager.SYNCHRONIZATION_ALWAYS);
}
public void testNewTransactionWithCommitUsingPropagationRequiresNew() {
@Test
public void newTransactionWithCommitUsingPropagationRequiresNew() {
doTestNewTransactionWithCommit(
TransactionDefinition.PROPAGATION_REQUIRES_NEW, WebSphereUowTransactionManager.SYNCHRONIZATION_ALWAYS);
}
public void testNewTransactionWithCommitUsingPropagationNested() {
@Test
public void newTransactionWithCommitUsingPropagationNested() {
doTestNewTransactionWithCommit(
TransactionDefinition.PROPAGATION_NESTED, WebSphereUowTransactionManager.SYNCHRONIZATION_ALWAYS);
}
public void testNewTransactionWithCommitUsingPropagationRequiredAndSynchOnActual() {
@Test
public void newTransactionWithCommitUsingPropagationRequiredAndSynchOnActual() {
doTestNewTransactionWithCommit(
TransactionDefinition.PROPAGATION_REQUIRED, WebSphereUowTransactionManager.SYNCHRONIZATION_ON_ACTUAL_TRANSACTION);
}
public void testNewTransactionWithCommitUsingPropagationRequiresNewAndSynchOnActual() {
@Test
public void newTransactionWithCommitUsingPropagationRequiresNewAndSynchOnActual() {
doTestNewTransactionWithCommit(
TransactionDefinition.PROPAGATION_REQUIRES_NEW, WebSphereUowTransactionManager.SYNCHRONIZATION_ON_ACTUAL_TRANSACTION);
}
public void testNewTransactionWithCommitUsingPropagationNestedAndSynchOnActual() {
@Test
public void newTransactionWithCommitUsingPropagationNestedAndSynchOnActual() {
doTestNewTransactionWithCommit(
TransactionDefinition.PROPAGATION_NESTED, WebSphereUowTransactionManager.SYNCHRONIZATION_ON_ACTUAL_TRANSACTION);
}
public void testNewTransactionWithCommitUsingPropagationRequiredAndSynchNever() {
@Test
public void newTransactionWithCommitUsingPropagationRequiredAndSynchNever() {
doTestNewTransactionWithCommit(
TransactionDefinition.PROPAGATION_REQUIRED, WebSphereUowTransactionManager.SYNCHRONIZATION_NEVER);
}
public void testNewTransactionWithCommitUsingPropagationRequiresNewAndSynchNever() {
@Test
public void newTransactionWithCommitUsingPropagationRequiresNewAndSynchNever() {
doTestNewTransactionWithCommit(
TransactionDefinition.PROPAGATION_REQUIRES_NEW, WebSphereUowTransactionManager.SYNCHRONIZATION_NEVER);
}
public void testNewTransactionWithCommitUsingPropagationNestedAndSynchNever() {
@Test
public void newTransactionWithCommitUsingPropagationNestedAndSynchNever() {
doTestNewTransactionWithCommit(
TransactionDefinition.PROPAGATION_NESTED, WebSphereUowTransactionManager.SYNCHRONIZATION_NEVER);
}
@@ -281,7 +304,8 @@ public class WebSphereUowTransactionManagerTests extends TestCase {
assertFalse(manager.getRollbackOnly());
}
public void testNewTransactionWithCommitAndTimeout() {
@Test
public void newTransactionWithCommitAndTimeout() {
MockUOWManager manager = new MockUOWManager();
WebSphereUowTransactionManager ptm = new WebSphereUowTransactionManager(manager);
DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
@@ -312,7 +336,8 @@ public class WebSphereUowTransactionManagerTests extends TestCase {
assertFalse(manager.getRollbackOnly());
}
public void testNewTransactionWithCommitException() {
@Test
public void newTransactionWithCommitException() {
final RollbackException rex = new RollbackException();
MockUOWManager manager = new MockUOWManager() {
@Override
@@ -353,7 +378,8 @@ public class WebSphereUowTransactionManagerTests extends TestCase {
assertEquals(0, manager.getUOWTimeout());
}
public void testNewTransactionWithRollback() {
@Test
public void newTransactionWithRollback() {
MockUOWManager manager = new MockUOWManager();
WebSphereUowTransactionManager ptm = new WebSphereUowTransactionManager(manager);
DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
@@ -388,7 +414,8 @@ public class WebSphereUowTransactionManagerTests extends TestCase {
assertTrue(manager.getRollbackOnly());
}
public void testNewTransactionWithRollbackOnly() {
@Test
public void newTransactionWithRollbackOnly() {
MockUOWManager manager = new MockUOWManager();
WebSphereUowTransactionManager ptm = new WebSphereUowTransactionManager(manager);
DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
@@ -418,7 +445,8 @@ public class WebSphereUowTransactionManagerTests extends TestCase {
assertTrue(manager.getRollbackOnly());
}
public void testExistingNonSpringTransaction() {
@Test
public void existingNonSpringTransaction() {
MockUOWManager manager = new MockUOWManager();
manager.setUOWStatus(UOWManager.UOW_STATUS_ACTIVE);
WebSphereUowTransactionManager ptm = new WebSphereUowTransactionManager(manager);
@@ -448,7 +476,8 @@ public class WebSphereUowTransactionManagerTests extends TestCase {
assertFalse(manager.getRollbackOnly());
}
public void testPropagationNeverFailsInCaseOfExistingTransaction() {
@Test
public void propagationNeverFailsInCaseOfExistingTransaction() {
MockUOWManager manager = new MockUOWManager();
manager.setUOWStatus(UOWManager.UOW_STATUS_ACTIVE);
WebSphereUowTransactionManager ptm = new WebSphereUowTransactionManager(manager);
@@ -469,7 +498,8 @@ public class WebSphereUowTransactionManagerTests extends TestCase {
}
}
public void testPropagationNestedFailsInCaseOfExistingTransaction() {
@Test
public void propagationNestedFailsInCaseOfExistingTransaction() {
MockUOWManager manager = new MockUOWManager();
manager.setUOWStatus(UOWManager.UOW_STATUS_ACTIVE);
WebSphereUowTransactionManager ptm = new WebSphereUowTransactionManager(manager);
@@ -490,15 +520,18 @@ public class WebSphereUowTransactionManagerTests extends TestCase {
}
}
public void testExistingTransactionWithParticipationUsingPropagationRequired() {
@Test
public void existingTransactionWithParticipationUsingPropagationRequired() {
doTestExistingTransactionWithParticipation(TransactionDefinition.PROPAGATION_REQUIRED);
}
public void testExistingTransactionWithParticipationUsingPropagationSupports() {
@Test
public void existingTransactionWithParticipationUsingPropagationSupports() {
doTestExistingTransactionWithParticipation(TransactionDefinition.PROPAGATION_SUPPORTS);
}
public void testExistingTransactionWithParticipationUsingPropagationMandatory() {
@Test
public void existingTransactionWithParticipationUsingPropagationMandatory() {
doTestExistingTransactionWithParticipation(TransactionDefinition.PROPAGATION_MANDATORY);
}
@@ -543,11 +576,13 @@ public class WebSphereUowTransactionManagerTests extends TestCase {
assertFalse(manager.getRollbackOnly());
}
public void testExistingTransactionWithSuspensionUsingPropagationRequiresNew() {
@Test
public void existingTransactionWithSuspensionUsingPropagationRequiresNew() {
doTestExistingTransactionWithSuspension(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
}
public void testExistingTransactionWithSuspensionUsingPropagationNotSupported() {
@Test
public void existingTransactionWithSuspensionUsingPropagationNotSupported() {
doTestExistingTransactionWithSuspension(TransactionDefinition.PROPAGATION_NOT_SUPPORTED);
}
@@ -598,7 +633,8 @@ public class WebSphereUowTransactionManagerTests extends TestCase {
assertFalse(manager.getRollbackOnly());
}
public void testExistingTransactionUsingPropagationNotSupported() {
@Test
public void existingTransactionUsingPropagationNotSupported() {
MockUOWManager manager = new MockUOWManager();
final WebSphereUowTransactionManager ptm = new WebSphereUowTransactionManager(manager);
DefaultTransactionDefinition definition = new DefaultTransactionDefinition();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,20 +19,22 @@ package org.springframework.transaction.support;
import javax.transaction.TransactionManager;
import javax.transaction.UserTransaction;
import junit.framework.TestCase;
import org.junit.Test;
import org.springframework.tests.mock.jndi.SimpleNamingContextBuilder;
import org.springframework.transaction.jta.JtaTransactionManager;
import org.springframework.util.SerializationTestUtils;
import static org.mockito.BDDMockito.*;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
/**
* @author Rod Johnson
*/
public class JtaTransactionManagerSerializationTests extends TestCase {
public class JtaTransactionManagerSerializationTests {
public void testSerializable() throws Exception {
@Test
public void serializable() throws Exception {
UserTransaction ut1 = mock(UserTransaction.class);
UserTransaction ut2 = mock(UserTransaction.class);
TransactionManager tm = mock(TransactionManager.class);

View File

@@ -32,6 +32,7 @@ import static org.junit.Assert.*;
public class SimpleTransactionScopeTests {
@Test
@SuppressWarnings("resource")
public void getFromScope() throws Exception {
GenericApplicationContext context = new GenericApplicationContext();
context.getBeanFactory().registerScope("tx", new SimpleTransactionScope());