Remove bogus DataSource test from JpaTransactionManagerTests

This commit is contained in:
Juergen Hoeller 2018-04-10 00:40:51 +02:00
parent 9fbab791a0
commit ff53d78e96
3 changed files with 8 additions and 43 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 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.
@ -65,7 +65,7 @@ public class DataSourceTransactionManagerTests {
@Before @Before
public void setUp() throws Exception { public void setup() throws Exception {
ds = mock(DataSource.class); ds = mock(DataSource.class);
con = mock(Connection.class); con = mock(Connection.class);
given(ds.getConnection()).willReturn(con); given(ds.getConnection()).willReturn(con);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2018 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.
@ -49,7 +49,7 @@ import static org.mockito.BDDMockito.*;
public class JmsTransactionManagerTests { public class JmsTransactionManagerTests {
@After @After
public void verifyTransactionSynchronizationManager() { public void verifyTransactionSynchronizationManagerState() {
assertTrue(TransactionSynchronizationManager.getResourceMap().isEmpty()); assertTrue(TransactionSynchronizationManager.getResourceMap().isEmpty());
assertFalse(TransactionSynchronizationManager.isSynchronizationActive()); assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2018 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,14 +16,12 @@
package org.springframework.orm.jpa; package org.springframework.orm.jpa;
import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory; import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction; import javax.persistence.EntityTransaction;
import javax.persistence.RollbackException; import javax.persistence.RollbackException;
import javax.sql.DataSource;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
@ -47,7 +45,7 @@ import static org.mockito.BDDMockito.*;
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Phillip Webb * @author Phillip Webb
*/ */
@SuppressWarnings({ "unchecked", "rawtypes" }) @SuppressWarnings({"unchecked", "rawtypes"})
public class JpaTransactionManagerTests { public class JpaTransactionManagerTests {
private EntityManagerFactory factory; private EntityManagerFactory factory;
@ -62,7 +60,7 @@ public class JpaTransactionManagerTests {
@Before @Before
public void setUp() throws Exception { public void setup() {
factory = mock(EntityManagerFactory.class); factory = mock(EntityManagerFactory.class);
manager = mock(EntityManager.class); manager = mock(EntityManager.class);
tx = mock(EntityTransaction.class); tx = mock(EntityTransaction.class);
@ -76,7 +74,7 @@ public class JpaTransactionManagerTests {
} }
@After @After
public void tearDown() throws Exception { public void verifyTransactionSynchronizationManagerState() {
assertTrue(TransactionSynchronizationManager.getResourceMap().isEmpty()); assertTrue(TransactionSynchronizationManager.getResourceMap().isEmpty());
assertFalse(TransactionSynchronizationManager.isSynchronizationActive()); assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly()); assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
@ -758,39 +756,6 @@ public class JpaTransactionManagerTests {
verify(manager).clear(); verify(manager).clear();
} }
@Test
public void testTransactionCommitWithDataSource() throws SQLException {
DataSource ds = mock(DataSource.class);
tm.setDataSource(ds);
given(manager.getTransaction()).willReturn(tx);
final List<String> l = new ArrayList<>();
l.add("test");
assertTrue(!TransactionSynchronizationManager.hasResource(factory));
assertTrue(!TransactionSynchronizationManager.isSynchronizationActive());
Object result = tt.execute(new TransactionCallback() {
@Override
public Object doInTransaction(TransactionStatus status) {
assertTrue(TransactionSynchronizationManager.hasResource(factory));
assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
EntityManagerFactoryUtils.getTransactionalEntityManager(factory).flush();
return l;
}
});
assertTrue(result == l);
assertTrue(!TransactionSynchronizationManager.hasResource(factory));
assertTrue(!TransactionSynchronizationManager.isSynchronizationActive());
verify(tx).commit();
verify(manager).flush();
verify(manager).close();
}
@Test @Test
public void testInvalidIsolation() { public void testInvalidIsolation() {
tt.setIsolationLevel(TransactionDefinition.ISOLATION_SERIALIZABLE); tt.setIsolationLevel(TransactionDefinition.ISOLATION_SERIALIZABLE);