PentahoTransactionManager extends LocalTransactionManager { public boolean isCreatingTransaction() { if ( activeTransactionDefinition.get() == null ) { return false; } switch ( activeTransactionDefinition.get().getPropagationBehavior() ) { case TransactionDefinition.PROPAGATION_NESTED: case TransactionDefinition.PROPAGATION_REQUIRED: case TransactionDefinition.PROPAGATION_REQUIRES_NEW: return true; default: return false; } }  TransactionDefinition getTransactionDefinition(); boolean isCreatingTransaction();  }
@Test public void isCreatingTransaction() throws Exception { PentahoTransactionManager transactionManager = new PentahoTransactionManager(); SessionFactory sessionFactory = mock( SessionFactory.class ); XASession xaSession = mock( XASession.class ); when( xaSession.getXAResource() ).thenReturn( mock( XAResource.class ) ); transactionManager.setSessionFactory( sessionFactory ); TransactionDefinition transactionDefinition = mock( TransactionDefinition.class ); when( transactionDefinition.getIsolationLevel() ).thenReturn( -1 ); when( sessionFactory.getSession() ).then( invocation -> { List<Integer> transDefs = Arrays .asList( TransactionDefinition.PROPAGATION_NESTED, TransactionDefinition.PROPAGATION_REQUIRED, TransactionDefinition.PROPAGATION_REQUIRES_NEW ); for ( Integer transDef : transDefs ) { when( transactionDefinition.getPropagationBehavior() ).thenReturn( transDef ); assertTrue( transactionManager.isCreatingTransaction() ); } return xaSession; } ); transactionManager.getTransaction( transactionDefinition ); }