ContextSourceTransactionManager extends
        AbstractPlatformTransactionManager implements InitializingBean { public void setContextSource(ContextSource contextSource) { delegate.setContextSource(contextSource); }  ContextSource getContextSource(); void setContextSource(ContextSource contextSource); void setRenamingStrategy(TempEntryRenamingStrategy renamingStrategy); void afterPropertiesSet();  }
@Test public void testTransactionSuspension_UnconnectableDataSource() throws Exception { Connection connectionMock = mock(Connection.class); DataSource dataSourceMock = mock(DataSource.class); when(dataSourceMock.getConnection()).thenReturn(connectionMock); when(connectionMock.getAutoCommit()).thenReturn(false); ContextSource unconnectableContextSourceMock = mock(ContextSource.class); UncategorizedLdapException connectException = new UncategorizedLdapException("dummy"); when(unconnectableContextSourceMock.getReadWriteContext()).thenThrow(connectException); try { final PlatformTransactionManager txMgrOuter = new DataSourceTransactionManager(dataSourceMock); final TransactionStatus txOuter = txMgrOuter.getTransaction(new DefaultTransactionDefinition()); try { final ContextSourceTransactionManager txMgrInner = new ContextSourceTransactionManager(); txMgrInner.setContextSource(unconnectableContextSourceMock); final TransactionStatus txInner = txMgrInner.getTransaction(new DefaultTransactionDefinition( TransactionDefinition.PROPAGATION_REQUIRES_NEW)); try { txMgrInner.commit(txInner); } catch (Exception e) { txMgrInner.rollback(txInner); throw e; } txMgrOuter.commit(txOuter); } catch (Exception e) { txMgrOuter.rollback(txOuter); throw e; } fail("Exception should be thrown"); } catch (CannotCreateTransactionException expected) { assertThat(expected.getCause()).as("Should be thrown exception").isSameAs(connectException); } verify(connectionMock).rollback(); }