Delete remaining SimpleJdbcTemplate usage
This commit deletes all remaining usage of the deprecated SimpleJdbcTemplate class within the framework itself. Issue: SPR-11895
This commit is contained in:
parent
0c1249fe42
commit
f1517f03ff
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2014 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.
|
||||||
|
|
@ -18,6 +18,7 @@ package org.springframework.orm.jpa;
|
||||||
|
|
||||||
import java.lang.reflect.Proxy;
|
import java.lang.reflect.Proxy;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.EntityNotFoundException;
|
import javax.persistence.EntityNotFoundException;
|
||||||
import javax.persistence.FlushModeType;
|
import javax.persistence.FlushModeType;
|
||||||
|
|
@ -144,7 +145,7 @@ public abstract class AbstractContainerEntityManagerFactoryIntegrationTests
|
||||||
|
|
||||||
protected final void insertPerson(String firstName) {
|
protected final void insertPerson(String firstName) {
|
||||||
String INSERT_PERSON = "INSERT INTO PERSON (ID, FIRST_NAME, LAST_NAME) VALUES (?, ?, ?)";
|
String INSERT_PERSON = "INSERT INTO PERSON (ID, FIRST_NAME, LAST_NAME) VALUES (?, ?, ?)";
|
||||||
simpleJdbcTemplate.update(INSERT_PERSON, 1, firstName, "Blair");
|
jdbcTemplate.update(INSERT_PERSON, 1, firstName, "Blair");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testEntityManagerProxyRejectsProgrammaticTxManagement() {
|
public void testEntityManagerProxyRejectsProgrammaticTxManagement() {
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ import org.springframework.transaction.support.TransactionSynchronizationManager
|
||||||
* @author Rod Johnson
|
* @author Rod Johnson
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public abstract class AbstractEntityManagerFactoryIntegrationTests extends AbstractJpaTests {
|
public abstract class AbstractEntityManagerFactoryIntegrationTests extends AbstractJpaTests {
|
||||||
|
|
||||||
public static final String[] ECLIPSELINK_CONFIG_LOCATIONS = new String[] {
|
public static final String[] ECLIPSELINK_CONFIG_LOCATIONS = new String[] {
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||||
* @author Rod Johnson
|
* @author Rod Johnson
|
||||||
* @since 2.0
|
* @since 2.0
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public class ApplicationManagedEntityManagerIntegrationTests extends AbstractEntityManagerFactoryIntegrationTests {
|
public class ApplicationManagedEntityManagerIntegrationTests extends AbstractEntityManagerFactoryIntegrationTests {
|
||||||
|
|
||||||
@NotTransactional
|
@NotTransactional
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2014 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.
|
||||||
|
|
@ -36,6 +36,7 @@ import org.springframework.test.annotation.NotTransactional;
|
||||||
* @author Rod Johnson
|
* @author Rod Johnson
|
||||||
* @since 2.0
|
* @since 2.0
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public class ContainerManagedEntityManagerIntegrationTests extends AbstractEntityManagerFactoryIntegrationTests {
|
public class ContainerManagedEntityManagerIntegrationTests extends AbstractEntityManagerFactoryIntegrationTests {
|
||||||
|
|
||||||
@NotTransactional
|
@NotTransactional
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2014 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.
|
||||||
|
|
@ -26,6 +26,7 @@ import org.springframework.orm.jpa.EntityManagerFactoryInfo;
|
||||||
*
|
*
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public class EclipseLinkEntityManagerFactoryIntegrationTests extends AbstractContainerEntityManagerFactoryIntegrationTests {
|
public class EclipseLinkEntityManagerFactoryIntegrationTests extends AbstractContainerEntityManagerFactoryIntegrationTests {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2014 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.
|
||||||
|
|
@ -35,6 +35,7 @@ import org.springframework.test.annotation.IfProfileValue;
|
||||||
*/
|
*/
|
||||||
// Essentially @Ignore-d since AnnotationBeanConfigurerAspect cannot be found
|
// Essentially @Ignore-d since AnnotationBeanConfigurerAspect cannot be found
|
||||||
@IfProfileValue(name="test-group", value="broken")
|
@IfProfileValue(name="test-group", value="broken")
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public class HibernateEntityManagerFactoryIntegrationTests extends
|
public class HibernateEntityManagerFactoryIntegrationTests extends
|
||||||
AbstractContainerEntityManagerFactoryIntegrationTests {
|
AbstractContainerEntityManagerFactoryIntegrationTests {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2014 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.
|
||||||
|
|
@ -26,6 +26,7 @@ import org.springframework.orm.jpa.AbstractContainerEntityManagerFactoryIntegrat
|
||||||
*
|
*
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public class HibernateMultiEntityManagerFactoryIntegrationTests extends
|
public class HibernateMultiEntityManagerFactoryIntegrationTests extends
|
||||||
AbstractContainerEntityManagerFactoryIntegrationTests {
|
AbstractContainerEntityManagerFactoryIntegrationTests {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2014 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.
|
||||||
|
|
@ -37,6 +37,7 @@ import org.springframework.transaction.support.TransactionTemplate;
|
||||||
*
|
*
|
||||||
* @author Costin Leau
|
* @author Costin Leau
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public class OpenJpaEntityManagerFactoryIntegrationTests extends AbstractContainerEntityManagerFactoryIntegrationTests {
|
public class OpenJpaEntityManagerFactoryIntegrationTests extends AbstractContainerEntityManagerFactoryIntegrationTests {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2007 the original author or authors.
|
* Copyright 2002-2014 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.
|
||||||
|
|
@ -27,6 +27,7 @@ import org.springframework.orm.jpa.support.PersistenceInjectionTests.DefaultPubl
|
||||||
* @author Rod Johnson
|
* @author Rod Johnson
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public class PersistenceInjectionIntegrationTests extends AbstractEntityManagerFactoryIntegrationTests {
|
public class PersistenceInjectionIntegrationTests extends AbstractEntityManagerFactoryIntegrationTests {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2014 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.
|
||||||
|
|
@ -20,12 +20,9 @@ import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
|
|
||||||
import junit.framework.AssertionFailedError;
|
import junit.framework.AssertionFailedError;
|
||||||
|
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
|
||||||
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
|
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
|
||||||
import org.springframework.transaction.TransactionDefinition;
|
import org.springframework.transaction.TransactionDefinition;
|
||||||
import org.springframework.transaction.annotation.AnnotationTransactionAttributeSource;
|
import org.springframework.transaction.annotation.AnnotationTransactionAttributeSource;
|
||||||
|
|
@ -35,8 +32,8 @@ import org.springframework.util.Assert;
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* Java 5 specific subclass of
|
* Java 5 specific subclass of
|
||||||
* {@link AbstractTransactionalDataSourceSpringContextTests}, exposing a
|
* {@link AbstractTransactionalDataSourceSpringContextTests}, obeying annotations
|
||||||
* {@link SimpleJdbcTemplate} and obeying annotations for transaction control.
|
* for transaction control.
|
||||||
* </p>
|
* </p>
|
||||||
* <p>
|
* <p>
|
||||||
* For example, test methods can be annotated with the regular Spring
|
* For example, test methods can be annotated with the regular Spring
|
||||||
|
|
@ -74,8 +71,6 @@ import org.springframework.util.Assert;
|
||||||
public abstract class AbstractAnnotationAwareTransactionalTests extends
|
public abstract class AbstractAnnotationAwareTransactionalTests extends
|
||||||
AbstractTransactionalDataSourceSpringContextTests {
|
AbstractTransactionalDataSourceSpringContextTests {
|
||||||
|
|
||||||
protected SimpleJdbcTemplate simpleJdbcTemplate;
|
|
||||||
|
|
||||||
private final TransactionAttributeSource transactionAttributeSource = new AnnotationTransactionAttributeSource();
|
private final TransactionAttributeSource transactionAttributeSource = new AnnotationTransactionAttributeSource();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -109,13 +104,6 @@ public abstract class AbstractAnnotationAwareTransactionalTests extends
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setDataSource(DataSource dataSource) {
|
|
||||||
super.setDataSource(dataSource);
|
|
||||||
// JdbcTemplate will be identically configured
|
|
||||||
this.simpleJdbcTemplate = new SimpleJdbcTemplate(this.jdbcTemplate);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Search for a unique {@link ProfileValueSource} in the supplied
|
* Search for a unique {@link ProfileValueSource} in the supplied
|
||||||
* {@link ApplicationContext}. If found, the
|
* {@link ApplicationContext}. If found, the
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2014 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.
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
package org.springframework.test.context.junit4;
|
package org.springframework.test.context.junit4;
|
||||||
|
|
||||||
import org.springframework.dao.DataAccessException;
|
import org.springframework.dao.DataAccessException;
|
||||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
|
@ -31,7 +31,6 @@ import org.springframework.transaction.annotation.Transactional;
|
||||||
* @see MethodLevelTransactionalSpringRunnerTests
|
* @see MethodLevelTransactionalSpringRunnerTests
|
||||||
* @see Transactional
|
* @see Transactional
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@ContextConfiguration("transactionalTests-context.xml")
|
@ContextConfiguration("transactionalTests-context.xml")
|
||||||
public abstract class AbstractTransactionalSpringRunnerTests {
|
public abstract class AbstractTransactionalSpringRunnerTests {
|
||||||
|
|
||||||
|
|
@ -43,29 +42,29 @@ public abstract class AbstractTransactionalSpringRunnerTests {
|
||||||
protected static final String YODA = "yoda";
|
protected static final String YODA = "yoda";
|
||||||
|
|
||||||
|
|
||||||
protected static int clearPersonTable(SimpleJdbcTemplate simpleJdbcTemplate) {
|
protected static int clearPersonTable(JdbcTemplate jdbcTemplate) {
|
||||||
return simpleJdbcTemplate.update("DELETE FROM person");
|
return jdbcTemplate.update("DELETE FROM person");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void createPersonTable(SimpleJdbcTemplate simpleJdbcTemplate) {
|
protected static void createPersonTable(JdbcTemplate jdbcTemplate) {
|
||||||
try {
|
try {
|
||||||
simpleJdbcTemplate.update("CREATE TABLE person (name VARCHAR(20) NOT NULL, PRIMARY KEY(name))");
|
jdbcTemplate.update("CREATE TABLE person (name VARCHAR(20) NOT NULL, PRIMARY KEY(name))");
|
||||||
}
|
}
|
||||||
catch (DataAccessException dae) {
|
catch (DataAccessException dae) {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static int countRowsInPersonTable(SimpleJdbcTemplate simpleJdbcTemplate) {
|
protected static int countRowsInPersonTable(JdbcTemplate jdbcTemplate) {
|
||||||
return simpleJdbcTemplate.queryForInt("SELECT COUNT(0) FROM person");
|
return jdbcTemplate.queryForObject("SELECT COUNT(0) FROM person", Integer.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static int addPerson(SimpleJdbcTemplate simpleJdbcTemplate, String name) {
|
protected static int addPerson(JdbcTemplate jdbcTemplate, String name) {
|
||||||
return simpleJdbcTemplate.update("INSERT INTO person VALUES(?)", name);
|
return jdbcTemplate.update("INSERT INTO person VALUES(?)", name);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static int deletePerson(SimpleJdbcTemplate simpleJdbcTemplate, String name) {
|
protected static int deletePerson(JdbcTemplate jdbcTemplate, String name) {
|
||||||
return simpleJdbcTemplate.update("DELETE FROM person WHERE name=?", name);
|
return jdbcTemplate.update("DELETE FROM person WHERE name=?", name);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2008 the original author or authors.
|
* Copyright 2002-2014 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.
|
||||||
|
|
@ -16,9 +16,6 @@
|
||||||
|
|
||||||
package org.springframework.test.context.junit4;
|
package org.springframework.test.context.junit4;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.springframework.test.transaction.TransactionTestUtils.assertInTransaction;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
|
@ -27,7 +24,7 @@ import org.junit.Before;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.TestExecutionListeners;
|
import org.springframework.test.context.TestExecutionListeners;
|
||||||
import org.springframework.test.context.transaction.AfterTransaction;
|
import org.springframework.test.context.transaction.AfterTransaction;
|
||||||
|
|
@ -35,6 +32,9 @@ import org.springframework.test.context.transaction.BeforeTransaction;
|
||||||
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
|
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import static org.springframework.test.transaction.TransactionTestUtils.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JUnit 4 based integration test which verifies
|
* JUnit 4 based integration test which verifies
|
||||||
* {@link BeforeTransaction @BeforeTransaction} and
|
* {@link BeforeTransaction @BeforeTransaction} and
|
||||||
|
|
@ -43,13 +43,12 @@ import org.springframework.transaction.annotation.Transactional;
|
||||||
* @author Sam Brannen
|
* @author Sam Brannen
|
||||||
* @since 2.5
|
* @since 2.5
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration
|
@ContextConfiguration
|
||||||
@TestExecutionListeners({ TransactionalTestExecutionListener.class })
|
@TestExecutionListeners(TransactionalTestExecutionListener.class)
|
||||||
public class BeforeAndAfterTransactionAnnotationTests extends AbstractTransactionalSpringRunnerTests {
|
public class BeforeAndAfterTransactionAnnotationTests extends AbstractTransactionalSpringRunnerTests {
|
||||||
|
|
||||||
protected static SimpleJdbcTemplate simpleJdbcTemplate;
|
protected static JdbcTemplate jdbcTemplate;
|
||||||
|
|
||||||
protected static int numBeforeTransactionCalls = 0;
|
protected static int numBeforeTransactionCalls = 0;
|
||||||
protected static int numAfterTransactionCalls = 0;
|
protected static int numAfterTransactionCalls = 0;
|
||||||
|
|
@ -66,7 +65,7 @@ public class BeforeAndAfterTransactionAnnotationTests extends AbstractTransactio
|
||||||
@AfterClass
|
@AfterClass
|
||||||
public static void afterClass() {
|
public static void afterClass() {
|
||||||
assertEquals("Verifying the final number of rows in the person table after all tests.", 3,
|
assertEquals("Verifying the final number of rows in the person table after all tests.", 3,
|
||||||
countRowsInPersonTable(simpleJdbcTemplate));
|
countRowsInPersonTable(jdbcTemplate));
|
||||||
assertEquals("Verifying the total number of calls to beforeTransaction().", 2,
|
assertEquals("Verifying the total number of calls to beforeTransaction().", 2,
|
||||||
BeforeAndAfterTransactionAnnotationTests.numBeforeTransactionCalls);
|
BeforeAndAfterTransactionAnnotationTests.numBeforeTransactionCalls);
|
||||||
assertEquals("Verifying the total number of calls to afterTransaction().", 2,
|
assertEquals("Verifying the total number of calls to afterTransaction().", 2,
|
||||||
|
|
@ -78,8 +77,8 @@ public class BeforeAndAfterTransactionAnnotationTests extends AbstractTransactio
|
||||||
assertInTransaction(false);
|
assertInTransaction(false);
|
||||||
this.inTransaction = true;
|
this.inTransaction = true;
|
||||||
BeforeAndAfterTransactionAnnotationTests.numBeforeTransactionCalls++;
|
BeforeAndAfterTransactionAnnotationTests.numBeforeTransactionCalls++;
|
||||||
clearPersonTable(simpleJdbcTemplate);
|
clearPersonTable(jdbcTemplate);
|
||||||
assertEquals("Adding yoda", 1, addPerson(simpleJdbcTemplate, YODA));
|
assertEquals("Adding yoda", 1, addPerson(jdbcTemplate, YODA));
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterTransaction
|
@AfterTransaction
|
||||||
|
|
@ -87,44 +86,44 @@ public class BeforeAndAfterTransactionAnnotationTests extends AbstractTransactio
|
||||||
assertInTransaction(false);
|
assertInTransaction(false);
|
||||||
this.inTransaction = false;
|
this.inTransaction = false;
|
||||||
BeforeAndAfterTransactionAnnotationTests.numAfterTransactionCalls++;
|
BeforeAndAfterTransactionAnnotationTests.numAfterTransactionCalls++;
|
||||||
assertEquals("Deleting yoda", 1, deletePerson(simpleJdbcTemplate, YODA));
|
assertEquals("Deleting yoda", 1, deletePerson(jdbcTemplate, YODA));
|
||||||
assertEquals("Verifying the number of rows in the person table after a transactional test method.", 0,
|
assertEquals("Verifying the number of rows in the person table after a transactional test method.", 0,
|
||||||
countRowsInPersonTable(simpleJdbcTemplate));
|
countRowsInPersonTable(jdbcTemplate));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void before() {
|
public void before() {
|
||||||
assertEquals("Verifying the number of rows in the person table before a test method.", (this.inTransaction ? 1
|
assertEquals("Verifying the number of rows in the person table before a test method.", (this.inTransaction ? 1
|
||||||
: 0), countRowsInPersonTable(simpleJdbcTemplate));
|
: 0), countRowsInPersonTable(jdbcTemplate));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Transactional
|
@Transactional
|
||||||
public void transactionalMethod1() {
|
public void transactionalMethod1() {
|
||||||
assertInTransaction(true);
|
assertInTransaction(true);
|
||||||
assertEquals("Adding jane", 1, addPerson(simpleJdbcTemplate, JANE));
|
assertEquals("Adding jane", 1, addPerson(jdbcTemplate, JANE));
|
||||||
assertEquals("Verifying the number of rows in the person table within transactionalMethod1().", 2,
|
assertEquals("Verifying the number of rows in the person table within transactionalMethod1().", 2,
|
||||||
countRowsInPersonTable(simpleJdbcTemplate));
|
countRowsInPersonTable(jdbcTemplate));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Transactional
|
@Transactional
|
||||||
public void transactionalMethod2() {
|
public void transactionalMethod2() {
|
||||||
assertInTransaction(true);
|
assertInTransaction(true);
|
||||||
assertEquals("Adding jane", 1, addPerson(simpleJdbcTemplate, JANE));
|
assertEquals("Adding jane", 1, addPerson(jdbcTemplate, JANE));
|
||||||
assertEquals("Adding sue", 1, addPerson(simpleJdbcTemplate, SUE));
|
assertEquals("Adding sue", 1, addPerson(jdbcTemplate, SUE));
|
||||||
assertEquals("Verifying the number of rows in the person table within transactionalMethod2().", 3,
|
assertEquals("Verifying the number of rows in the person table within transactionalMethod2().", 3,
|
||||||
countRowsInPersonTable(simpleJdbcTemplate));
|
countRowsInPersonTable(jdbcTemplate));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nonTransactionalMethod() {
|
public void nonTransactionalMethod() {
|
||||||
assertInTransaction(false);
|
assertInTransaction(false);
|
||||||
assertEquals("Adding luke", 1, addPerson(simpleJdbcTemplate, LUKE));
|
assertEquals("Adding luke", 1, addPerson(jdbcTemplate, LUKE));
|
||||||
assertEquals("Adding leia", 1, addPerson(simpleJdbcTemplate, LEIA));
|
assertEquals("Adding leia", 1, addPerson(jdbcTemplate, LEIA));
|
||||||
assertEquals("Adding yoda", 1, addPerson(simpleJdbcTemplate, YODA));
|
assertEquals("Adding yoda", 1, addPerson(jdbcTemplate, YODA));
|
||||||
assertEquals("Verifying the number of rows in the person table without a transaction.", 3,
|
assertEquals("Verifying the number of rows in the person table without a transaction.", 3,
|
||||||
countRowsInPersonTable(simpleJdbcTemplate));
|
countRowsInPersonTable(jdbcTemplate));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -132,8 +131,8 @@ public class BeforeAndAfterTransactionAnnotationTests extends AbstractTransactio
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
void setDataSource(DataSource dataSource) {
|
void setDataSource(DataSource dataSource) {
|
||||||
simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
|
jdbcTemplate = new JdbcTemplate(dataSource);
|
||||||
createPersonTable(simpleJdbcTemplate);
|
createPersonTable(jdbcTemplate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,6 @@
|
||||||
|
|
||||||
package org.springframework.test.context.junit4;
|
package org.springframework.test.context.junit4;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.springframework.test.transaction.TransactionTestUtils.assertInTransaction;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
|
@ -26,7 +23,7 @@ import org.junit.AfterClass;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.TestExecutionListener;
|
import org.springframework.test.context.TestExecutionListener;
|
||||||
import org.springframework.test.context.TestExecutionListeners;
|
import org.springframework.test.context.TestExecutionListeners;
|
||||||
|
|
@ -36,6 +33,9 @@ import org.springframework.test.context.transaction.TransactionalTestExecutionLi
|
||||||
import org.springframework.transaction.annotation.Propagation;
|
import org.springframework.transaction.annotation.Propagation;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import static org.springframework.test.transaction.TransactionTestUtils.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* JUnit 4 based integration test which verifies support of Spring's
|
* JUnit 4 based integration test which verifies support of Spring's
|
||||||
|
|
@ -59,48 +59,47 @@ import org.springframework.transaction.annotation.Transactional;
|
||||||
* @since 2.5
|
* @since 2.5
|
||||||
* @see MethodLevelTransactionalSpringRunnerTests
|
* @see MethodLevelTransactionalSpringRunnerTests
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration
|
@ContextConfiguration
|
||||||
@Transactional
|
@Transactional
|
||||||
public class ClassLevelTransactionalSpringRunnerTests extends AbstractTransactionalSpringRunnerTests {
|
public class ClassLevelTransactionalSpringRunnerTests extends AbstractTransactionalSpringRunnerTests {
|
||||||
|
|
||||||
protected static SimpleJdbcTemplate simpleJdbcTemplate;
|
protected static JdbcTemplate jdbcTemplate;
|
||||||
|
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
public static void verifyFinalTestData() {
|
public static void verifyFinalTestData() {
|
||||||
assertEquals("Verifying the final number of rows in the person table after all tests.", 4,
|
assertEquals("Verifying the final number of rows in the person table after all tests.", 4,
|
||||||
countRowsInPersonTable(simpleJdbcTemplate));
|
countRowsInPersonTable(jdbcTemplate));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void verifyInitialTestData() {
|
public void verifyInitialTestData() {
|
||||||
clearPersonTable(simpleJdbcTemplate);
|
clearPersonTable(jdbcTemplate);
|
||||||
assertEquals("Adding bob", 1, addPerson(simpleJdbcTemplate, BOB));
|
assertEquals("Adding bob", 1, addPerson(jdbcTemplate, BOB));
|
||||||
assertEquals("Verifying the initial number of rows in the person table.", 1,
|
assertEquals("Verifying the initial number of rows in the person table.", 1,
|
||||||
countRowsInPersonTable(simpleJdbcTemplate));
|
countRowsInPersonTable(jdbcTemplate));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void modifyTestDataWithinTransaction() {
|
public void modifyTestDataWithinTransaction() {
|
||||||
assertInTransaction(true);
|
assertInTransaction(true);
|
||||||
assertEquals("Deleting bob", 1, deletePerson(simpleJdbcTemplate, BOB));
|
assertEquals("Deleting bob", 1, deletePerson(jdbcTemplate, BOB));
|
||||||
assertEquals("Adding jane", 1, addPerson(simpleJdbcTemplate, JANE));
|
assertEquals("Adding jane", 1, addPerson(jdbcTemplate, JANE));
|
||||||
assertEquals("Adding sue", 1, addPerson(simpleJdbcTemplate, SUE));
|
assertEquals("Adding sue", 1, addPerson(jdbcTemplate, SUE));
|
||||||
assertEquals("Verifying the number of rows in the person table within a transaction.", 2,
|
assertEquals("Verifying the number of rows in the person table within a transaction.", 2,
|
||||||
countRowsInPersonTable(simpleJdbcTemplate));
|
countRowsInPersonTable(jdbcTemplate));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Transactional(propagation = Propagation.NOT_SUPPORTED)
|
@Transactional(propagation = Propagation.NOT_SUPPORTED)
|
||||||
public void modifyTestDataWithoutTransaction() {
|
public void modifyTestDataWithoutTransaction() {
|
||||||
assertInTransaction(false);
|
assertInTransaction(false);
|
||||||
assertEquals("Adding luke", 1, addPerson(simpleJdbcTemplate, LUKE));
|
assertEquals("Adding luke", 1, addPerson(jdbcTemplate, LUKE));
|
||||||
assertEquals("Adding leia", 1, addPerson(simpleJdbcTemplate, LEIA));
|
assertEquals("Adding leia", 1, addPerson(jdbcTemplate, LEIA));
|
||||||
assertEquals("Adding yoda", 1, addPerson(simpleJdbcTemplate, YODA));
|
assertEquals("Adding yoda", 1, addPerson(jdbcTemplate, YODA));
|
||||||
assertEquals("Verifying the number of rows in the person table without a transaction.", 4,
|
assertEquals("Verifying the number of rows in the person table without a transaction.", 4,
|
||||||
countRowsInPersonTable(simpleJdbcTemplate));
|
countRowsInPersonTable(jdbcTemplate));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -108,8 +107,8 @@ public class ClassLevelTransactionalSpringRunnerTests extends AbstractTransactio
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
public void setDataSource(DataSource dataSource) {
|
public void setDataSource(DataSource dataSource) {
|
||||||
simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
|
jdbcTemplate = new JdbcTemplate(dataSource);
|
||||||
createPersonTable(simpleJdbcTemplate);
|
createPersonTable(jdbcTemplate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2014 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.
|
||||||
|
|
@ -16,9 +16,6 @@
|
||||||
|
|
||||||
package org.springframework.test.context.junit4;
|
package org.springframework.test.context.junit4;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.springframework.test.transaction.TransactionTestUtils.assertInTransaction;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
|
@ -26,11 +23,14 @@ import org.junit.AfterClass;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.transaction.TransactionConfiguration;
|
import org.springframework.test.context.transaction.TransactionConfiguration;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import static org.springframework.test.transaction.TransactionTestUtils.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* JUnit 4 based integration test which verifies proper transactional behavior when the
|
* JUnit 4 based integration test which verifies proper transactional behavior when the
|
||||||
|
|
@ -44,38 +44,37 @@ import org.springframework.transaction.annotation.Transactional;
|
||||||
* @since 2.5
|
* @since 2.5
|
||||||
* @see TransactionConfiguration
|
* @see TransactionConfiguration
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration
|
@ContextConfiguration
|
||||||
@TransactionConfiguration(transactionManager = "txMgr", defaultRollback = false)
|
@TransactionConfiguration(transactionManager = "txMgr", defaultRollback = false)
|
||||||
@Transactional
|
@Transactional
|
||||||
public class DefaultRollbackFalseTransactionalSpringRunnerTests extends AbstractTransactionalSpringRunnerTests {
|
public class DefaultRollbackFalseTransactionalSpringRunnerTests extends AbstractTransactionalSpringRunnerTests {
|
||||||
|
|
||||||
protected static SimpleJdbcTemplate simpleJdbcTemplate;
|
protected static JdbcTemplate jdbcTemplate;
|
||||||
|
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
public static void verifyFinalTestData() {
|
public static void verifyFinalTestData() {
|
||||||
assertEquals("Verifying the final number of rows in the person table after all tests.", 2,
|
assertEquals("Verifying the final number of rows in the person table after all tests.", 2,
|
||||||
countRowsInPersonTable(simpleJdbcTemplate));
|
countRowsInPersonTable(jdbcTemplate));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void verifyInitialTestData() {
|
public void verifyInitialTestData() {
|
||||||
clearPersonTable(simpleJdbcTemplate);
|
clearPersonTable(jdbcTemplate);
|
||||||
assertEquals("Adding bob", 1, addPerson(simpleJdbcTemplate, BOB));
|
assertEquals("Adding bob", 1, addPerson(jdbcTemplate, BOB));
|
||||||
assertEquals("Verifying the initial number of rows in the person table.", 1,
|
assertEquals("Verifying the initial number of rows in the person table.", 1,
|
||||||
countRowsInPersonTable(simpleJdbcTemplate));
|
countRowsInPersonTable(jdbcTemplate));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void modifyTestDataWithinTransaction() {
|
public void modifyTestDataWithinTransaction() {
|
||||||
assertInTransaction(true);
|
assertInTransaction(true);
|
||||||
assertEquals("Deleting bob", 1, deletePerson(simpleJdbcTemplate, BOB));
|
assertEquals("Deleting bob", 1, deletePerson(jdbcTemplate, BOB));
|
||||||
assertEquals("Adding jane", 1, addPerson(simpleJdbcTemplate, JANE));
|
assertEquals("Adding jane", 1, addPerson(jdbcTemplate, JANE));
|
||||||
assertEquals("Adding sue", 1, addPerson(simpleJdbcTemplate, SUE));
|
assertEquals("Adding sue", 1, addPerson(jdbcTemplate, SUE));
|
||||||
assertEquals("Verifying the number of rows in the person table within a transaction.", 2,
|
assertEquals("Verifying the number of rows in the person table within a transaction.", 2,
|
||||||
countRowsInPersonTable(simpleJdbcTemplate));
|
countRowsInPersonTable(jdbcTemplate));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -83,8 +82,8 @@ public class DefaultRollbackFalseTransactionalSpringRunnerTests extends Abstract
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
public void setDataSource(DataSource dataSource) {
|
public void setDataSource(DataSource dataSource) {
|
||||||
simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
|
jdbcTemplate = new JdbcTemplate(dataSource);
|
||||||
createPersonTable(simpleJdbcTemplate);
|
createPersonTable(jdbcTemplate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2014 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.
|
||||||
|
|
@ -16,9 +16,6 @@
|
||||||
|
|
||||||
package org.springframework.test.context.junit4;
|
package org.springframework.test.context.junit4;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.springframework.test.transaction.TransactionTestUtils.assertInTransaction;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
|
@ -26,11 +23,14 @@ import org.junit.AfterClass;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.transaction.TransactionConfiguration;
|
import org.springframework.test.context.transaction.TransactionConfiguration;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import static org.springframework.test.transaction.TransactionTestUtils.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JUnit 4 based integration test which verifies proper transactional behavior when the
|
* JUnit 4 based integration test which verifies proper transactional behavior when the
|
||||||
* {@link TransactionConfiguration#defaultRollback() defaultRollback} attribute
|
* {@link TransactionConfiguration#defaultRollback() defaultRollback} attribute
|
||||||
|
|
@ -40,7 +40,6 @@ import org.springframework.transaction.annotation.Transactional;
|
||||||
* @since 2.5
|
* @since 2.5
|
||||||
* @see TransactionConfiguration
|
* @see TransactionConfiguration
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration
|
@ContextConfiguration
|
||||||
@TransactionConfiguration(defaultRollback = true)
|
@TransactionConfiguration(defaultRollback = true)
|
||||||
|
|
@ -48,31 +47,31 @@ public class DefaultRollbackTrueTransactionalSpringRunnerTests extends AbstractT
|
||||||
|
|
||||||
protected static int originalNumRows;
|
protected static int originalNumRows;
|
||||||
|
|
||||||
protected static SimpleJdbcTemplate simpleJdbcTemplate;
|
protected static JdbcTemplate jdbcTemplate;
|
||||||
|
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
public static void verifyFinalTestData() {
|
public static void verifyFinalTestData() {
|
||||||
assertEquals("Verifying the final number of rows in the person table after all tests.", originalNumRows,
|
assertEquals("Verifying the final number of rows in the person table after all tests.", originalNumRows,
|
||||||
countRowsInPersonTable(simpleJdbcTemplate));
|
countRowsInPersonTable(jdbcTemplate));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void verifyInitialTestData() {
|
public void verifyInitialTestData() {
|
||||||
originalNumRows = clearPersonTable(simpleJdbcTemplate);
|
originalNumRows = clearPersonTable(jdbcTemplate);
|
||||||
assertEquals("Adding bob", 1, addPerson(simpleJdbcTemplate, BOB));
|
assertEquals("Adding bob", 1, addPerson(jdbcTemplate, BOB));
|
||||||
assertEquals("Verifying the initial number of rows in the person table.", 1,
|
assertEquals("Verifying the initial number of rows in the person table.", 1,
|
||||||
countRowsInPersonTable(simpleJdbcTemplate));
|
countRowsInPersonTable(jdbcTemplate));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeout = 1000)
|
@Test(timeout = 1000)
|
||||||
@Transactional
|
@Transactional
|
||||||
public void modifyTestDataWithinTransaction() {
|
public void modifyTestDataWithinTransaction() {
|
||||||
assertInTransaction(true);
|
assertInTransaction(true);
|
||||||
assertEquals("Adding jane", 1, addPerson(simpleJdbcTemplate, JANE));
|
assertEquals("Adding jane", 1, addPerson(jdbcTemplate, JANE));
|
||||||
assertEquals("Adding sue", 1, addPerson(simpleJdbcTemplate, SUE));
|
assertEquals("Adding sue", 1, addPerson(jdbcTemplate, SUE));
|
||||||
assertEquals("Verifying the number of rows in the person table within a transaction.", 3,
|
assertEquals("Verifying the number of rows in the person table within a transaction.", 3,
|
||||||
countRowsInPersonTable(simpleJdbcTemplate));
|
countRowsInPersonTable(jdbcTemplate));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -80,8 +79,8 @@ public class DefaultRollbackTrueTransactionalSpringRunnerTests extends AbstractT
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
public void setDataSource(DataSource dataSource) {
|
public void setDataSource(DataSource dataSource) {
|
||||||
simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
|
jdbcTemplate = new JdbcTemplate(dataSource);
|
||||||
createPersonTable(simpleJdbcTemplate);
|
createPersonTable(jdbcTemplate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,6 @@
|
||||||
|
|
||||||
package org.springframework.test.context.junit4;
|
package org.springframework.test.context.junit4;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.springframework.test.transaction.TransactionTestUtils.assertInTransaction;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
|
@ -26,7 +23,7 @@ import org.junit.AfterClass;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.TestExecutionListener;
|
import org.springframework.test.context.TestExecutionListener;
|
||||||
import org.springframework.test.context.TestExecutionListeners;
|
import org.springframework.test.context.TestExecutionListeners;
|
||||||
|
|
@ -35,6 +32,9 @@ import org.springframework.test.context.support.DirtiesContextTestExecutionListe
|
||||||
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
|
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import static org.springframework.test.transaction.TransactionTestUtils.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* JUnit 4 based integration test which verifies support of Spring's
|
* JUnit 4 based integration test which verifies support of Spring's
|
||||||
|
|
@ -60,49 +60,48 @@ import org.springframework.transaction.annotation.Transactional;
|
||||||
* @since 2.5
|
* @since 2.5
|
||||||
* @see ClassLevelTransactionalSpringRunnerTests
|
* @see ClassLevelTransactionalSpringRunnerTests
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration
|
@ContextConfiguration
|
||||||
@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class,
|
@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class,
|
||||||
TransactionalTestExecutionListener.class })
|
TransactionalTestExecutionListener.class })
|
||||||
public class MethodLevelTransactionalSpringRunnerTests extends AbstractTransactionalSpringRunnerTests {
|
public class MethodLevelTransactionalSpringRunnerTests extends AbstractTransactionalSpringRunnerTests {
|
||||||
|
|
||||||
protected static SimpleJdbcTemplate simpleJdbcTemplate;
|
protected static JdbcTemplate jdbcTemplate;
|
||||||
|
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
public static void verifyFinalTestData() {
|
public static void verifyFinalTestData() {
|
||||||
assertEquals("Verifying the final number of rows in the person table after all tests.", 4,
|
assertEquals("Verifying the final number of rows in the person table after all tests.", 4,
|
||||||
countRowsInPersonTable(simpleJdbcTemplate));
|
countRowsInPersonTable(jdbcTemplate));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void verifyInitialTestData() {
|
public void verifyInitialTestData() {
|
||||||
clearPersonTable(simpleJdbcTemplate);
|
clearPersonTable(jdbcTemplate);
|
||||||
assertEquals("Adding bob", 1, addPerson(simpleJdbcTemplate, BOB));
|
assertEquals("Adding bob", 1, addPerson(jdbcTemplate, BOB));
|
||||||
assertEquals("Verifying the initial number of rows in the person table.", 1,
|
assertEquals("Verifying the initial number of rows in the person table.", 1,
|
||||||
countRowsInPersonTable(simpleJdbcTemplate));
|
countRowsInPersonTable(jdbcTemplate));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Transactional("transactionManager2")
|
@Transactional("transactionManager2")
|
||||||
public void modifyTestDataWithinTransaction() {
|
public void modifyTestDataWithinTransaction() {
|
||||||
assertInTransaction(true);
|
assertInTransaction(true);
|
||||||
assertEquals("Deleting bob", 1, deletePerson(simpleJdbcTemplate, BOB));
|
assertEquals("Deleting bob", 1, deletePerson(jdbcTemplate, BOB));
|
||||||
assertEquals("Adding jane", 1, addPerson(simpleJdbcTemplate, JANE));
|
assertEquals("Adding jane", 1, addPerson(jdbcTemplate, JANE));
|
||||||
assertEquals("Adding sue", 1, addPerson(simpleJdbcTemplate, SUE));
|
assertEquals("Adding sue", 1, addPerson(jdbcTemplate, SUE));
|
||||||
assertEquals("Verifying the number of rows in the person table within a transaction.", 2,
|
assertEquals("Verifying the number of rows in the person table within a transaction.", 2,
|
||||||
countRowsInPersonTable(simpleJdbcTemplate));
|
countRowsInPersonTable(jdbcTemplate));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void modifyTestDataWithoutTransaction() {
|
public void modifyTestDataWithoutTransaction() {
|
||||||
assertInTransaction(false);
|
assertInTransaction(false);
|
||||||
assertEquals("Adding luke", 1, addPerson(simpleJdbcTemplate, LUKE));
|
assertEquals("Adding luke", 1, addPerson(jdbcTemplate, LUKE));
|
||||||
assertEquals("Adding leia", 1, addPerson(simpleJdbcTemplate, LEIA));
|
assertEquals("Adding leia", 1, addPerson(jdbcTemplate, LEIA));
|
||||||
assertEquals("Adding yoda", 1, addPerson(simpleJdbcTemplate, YODA));
|
assertEquals("Adding yoda", 1, addPerson(jdbcTemplate, YODA));
|
||||||
assertEquals("Verifying the number of rows in the person table without a transaction.", 4,
|
assertEquals("Verifying the number of rows in the person table without a transaction.", 4,
|
||||||
countRowsInPersonTable(simpleJdbcTemplate));
|
countRowsInPersonTable(jdbcTemplate));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -110,8 +109,8 @@ public class MethodLevelTransactionalSpringRunnerTests extends AbstractTransacti
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
public void setDataSource2(DataSource dataSource) {
|
public void setDataSource2(DataSource dataSource) {
|
||||||
simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
|
jdbcTemplate = new JdbcTemplate(dataSource);
|
||||||
createPersonTable(simpleJdbcTemplate);
|
createPersonTable(jdbcTemplate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2008 the original author or authors.
|
* Copyright 2002-2014 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.
|
||||||
|
|
@ -16,19 +16,19 @@
|
||||||
|
|
||||||
package org.springframework.test.context.junit4;
|
package org.springframework.test.context.junit4;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.springframework.test.transaction.TransactionTestUtils.assertInTransaction;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.test.annotation.Rollback;
|
import org.springframework.test.annotation.Rollback;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import static org.springframework.test.transaction.TransactionTestUtils.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extension of {@link DefaultRollbackFalseTransactionalSpringRunnerTests} which
|
* Extension of {@link DefaultRollbackFalseTransactionalSpringRunnerTests} which
|
||||||
* tests method-level <em>rollback override</em> behavior via the
|
* tests method-level <em>rollback override</em> behavior via the
|
||||||
|
|
@ -38,29 +38,28 @@ import org.springframework.test.context.ContextConfiguration;
|
||||||
* @since 2.5
|
* @since 2.5
|
||||||
* @see Rollback
|
* @see Rollback
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@ContextConfiguration
|
@ContextConfiguration
|
||||||
public class RollbackOverrideDefaultRollbackFalseTransactionalSpringRunnerTests extends
|
public class RollbackOverrideDefaultRollbackFalseTransactionalSpringRunnerTests extends
|
||||||
DefaultRollbackFalseTransactionalSpringRunnerTests {
|
DefaultRollbackFalseTransactionalSpringRunnerTests {
|
||||||
|
|
||||||
protected static int originalNumRows;
|
protected static int originalNumRows;
|
||||||
|
|
||||||
protected static SimpleJdbcTemplate simpleJdbcTemplate;
|
protected static JdbcTemplate jdbcTemplate;
|
||||||
|
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
public static void verifyFinalTestData() {
|
public static void verifyFinalTestData() {
|
||||||
assertEquals("Verifying the final number of rows in the person table after all tests.", originalNumRows,
|
assertEquals("Verifying the final number of rows in the person table after all tests.", originalNumRows,
|
||||||
countRowsInPersonTable(simpleJdbcTemplate));
|
countRowsInPersonTable(jdbcTemplate));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@Override
|
@Override
|
||||||
public void verifyInitialTestData() {
|
public void verifyInitialTestData() {
|
||||||
originalNumRows = clearPersonTable(simpleJdbcTemplate);
|
originalNumRows = clearPersonTable(jdbcTemplate);
|
||||||
assertEquals("Adding bob", 1, addPerson(simpleJdbcTemplate, BOB));
|
assertEquals("Adding bob", 1, addPerson(jdbcTemplate, BOB));
|
||||||
assertEquals("Verifying the initial number of rows in the person table.", 1,
|
assertEquals("Verifying the initial number of rows in the person table.", 1,
|
||||||
countRowsInPersonTable(simpleJdbcTemplate));
|
countRowsInPersonTable(jdbcTemplate));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -68,11 +67,11 @@ public class RollbackOverrideDefaultRollbackFalseTransactionalSpringRunnerTests
|
||||||
@Override
|
@Override
|
||||||
public void modifyTestDataWithinTransaction() {
|
public void modifyTestDataWithinTransaction() {
|
||||||
assertInTransaction(true);
|
assertInTransaction(true);
|
||||||
assertEquals("Deleting bob", 1, deletePerson(simpleJdbcTemplate, BOB));
|
assertEquals("Deleting bob", 1, deletePerson(jdbcTemplate, BOB));
|
||||||
assertEquals("Adding jane", 1, addPerson(simpleJdbcTemplate, JANE));
|
assertEquals("Adding jane", 1, addPerson(jdbcTemplate, JANE));
|
||||||
assertEquals("Adding sue", 1, addPerson(simpleJdbcTemplate, SUE));
|
assertEquals("Adding sue", 1, addPerson(jdbcTemplate, SUE));
|
||||||
assertEquals("Verifying the number of rows in the person table within a transaction.", 2,
|
assertEquals("Verifying the number of rows in the person table within a transaction.", 2,
|
||||||
countRowsInPersonTable(simpleJdbcTemplate));
|
countRowsInPersonTable(jdbcTemplate));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -80,8 +79,8 @@ public class RollbackOverrideDefaultRollbackFalseTransactionalSpringRunnerTests
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
public void setDataSource(DataSource dataSource) {
|
public void setDataSource(DataSource dataSource) {
|
||||||
simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
|
jdbcTemplate = new JdbcTemplate(dataSource);
|
||||||
createPersonTable(simpleJdbcTemplate);
|
createPersonTable(jdbcTemplate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2014 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.
|
||||||
|
|
@ -16,20 +16,20 @@
|
||||||
|
|
||||||
package org.springframework.test.context.junit4;
|
package org.springframework.test.context.junit4;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.springframework.test.transaction.TransactionTestUtils.assertInTransaction;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.test.annotation.Rollback;
|
import org.springframework.test.annotation.Rollback;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import static org.springframework.test.transaction.TransactionTestUtils.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extension of {@link DefaultRollbackTrueTransactionalSpringRunnerTests} which
|
* Extension of {@link DefaultRollbackTrueTransactionalSpringRunnerTests} which
|
||||||
* tests method-level <em>rollback override</em> behavior via the
|
* tests method-level <em>rollback override</em> behavior via the
|
||||||
|
|
@ -39,27 +39,26 @@ import org.springframework.transaction.annotation.Transactional;
|
||||||
* @since 2.5
|
* @since 2.5
|
||||||
* @see Rollback
|
* @see Rollback
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@ContextConfiguration
|
@ContextConfiguration
|
||||||
public class RollbackOverrideDefaultRollbackTrueTransactionalSpringRunnerTests extends
|
public class RollbackOverrideDefaultRollbackTrueTransactionalSpringRunnerTests extends
|
||||||
DefaultRollbackTrueTransactionalSpringRunnerTests {
|
DefaultRollbackTrueTransactionalSpringRunnerTests {
|
||||||
|
|
||||||
protected static SimpleJdbcTemplate simpleJdbcTemplate;
|
protected static JdbcTemplate jdbcTemplate;
|
||||||
|
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
public static void verifyFinalTestData() {
|
public static void verifyFinalTestData() {
|
||||||
assertEquals("Verifying the final number of rows in the person table after all tests.", 3,
|
assertEquals("Verifying the final number of rows in the person table after all tests.", 3,
|
||||||
countRowsInPersonTable(simpleJdbcTemplate));
|
countRowsInPersonTable(jdbcTemplate));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Before
|
@Before
|
||||||
public void verifyInitialTestData() {
|
public void verifyInitialTestData() {
|
||||||
clearPersonTable(simpleJdbcTemplate);
|
clearPersonTable(jdbcTemplate);
|
||||||
assertEquals("Adding bob", 1, addPerson(simpleJdbcTemplate, BOB));
|
assertEquals("Adding bob", 1, addPerson(jdbcTemplate, BOB));
|
||||||
assertEquals("Verifying the initial number of rows in the person table.", 1,
|
assertEquals("Verifying the initial number of rows in the person table.", 1,
|
||||||
countRowsInPersonTable(simpleJdbcTemplate));
|
countRowsInPersonTable(jdbcTemplate));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -68,10 +67,10 @@ public class RollbackOverrideDefaultRollbackTrueTransactionalSpringRunnerTests e
|
||||||
@Rollback(false)
|
@Rollback(false)
|
||||||
public void modifyTestDataWithinTransaction() {
|
public void modifyTestDataWithinTransaction() {
|
||||||
assertInTransaction(true);
|
assertInTransaction(true);
|
||||||
assertEquals("Adding jane", 1, addPerson(simpleJdbcTemplate, JANE));
|
assertEquals("Adding jane", 1, addPerson(jdbcTemplate, JANE));
|
||||||
assertEquals("Adding sue", 1, addPerson(simpleJdbcTemplate, SUE));
|
assertEquals("Adding sue", 1, addPerson(jdbcTemplate, SUE));
|
||||||
assertEquals("Verifying the number of rows in the person table within a transaction.", 3,
|
assertEquals("Verifying the number of rows in the person table within a transaction.", 3,
|
||||||
countRowsInPersonTable(simpleJdbcTemplate));
|
countRowsInPersonTable(jdbcTemplate));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -79,8 +78,8 @@ public class RollbackOverrideDefaultRollbackTrueTransactionalSpringRunnerTests e
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
public void setDataSource(DataSource dataSource) {
|
public void setDataSource(DataSource dataSource) {
|
||||||
simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
|
jdbcTemplate = new JdbcTemplate(dataSource);
|
||||||
createPersonTable(simpleJdbcTemplate);
|
createPersonTable(jdbcTemplate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue