org.springframework.transaction.MockCallbackPreferringTransactionManager Java Examples

The following examples show how to use org.springframework.transaction.MockCallbackPreferringTransactionManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractTransactionAspectTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Check that a transaction is created and committed using
 * CallbackPreferringPlatformTransactionManager.
 */
@Test
public void transactionShouldSucceedWithCallbackPreference() throws Exception {
	TransactionAttribute txatt = new DefaultTransactionAttribute();

	MapTransactionAttributeSource tas = new MapTransactionAttributeSource();
	tas.register(getNameMethod, txatt);

	MockCallbackPreferringTransactionManager ptm = new MockCallbackPreferringTransactionManager();

	TestBean tb = new TestBean();
	ITestBean itb = (ITestBean) advised(tb, ptm, tas);

	checkTransactionStatus(false);
	itb.getName();
	checkTransactionStatus(false);

	assertSame(txatt, ptm.getDefinition());
	assertFalse(ptm.getStatus().isRollbackOnly());
}
 
Example #2
Source File: AbstractTransactionAspectTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void transactionExceptionPropagatedWithCallbackPreference() throws Throwable {
	TransactionAttribute txatt = new DefaultTransactionAttribute();

	MapTransactionAttributeSource tas = new MapTransactionAttributeSource();
	tas.register(exceptionalMethod, txatt);

	MockCallbackPreferringTransactionManager ptm = new MockCallbackPreferringTransactionManager();

	TestBean tb = new TestBean();
	ITestBean itb = (ITestBean) advised(tb, ptm, tas);

	checkTransactionStatus(false);
	try {
		itb.exceptional(new OptimisticLockingFailureException(""));
		fail("Should have thrown OptimisticLockingFailureException");
	}
	catch (OptimisticLockingFailureException ex) {
		// expected
	}
	checkTransactionStatus(false);

	assertSame(txatt, ptm.getDefinition());
	assertFalse(ptm.getStatus().isRollbackOnly());
}
 
Example #3
Source File: AbstractTransactionAspectTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Check that a transaction is created and committed using
 * CallbackPreferringPlatformTransactionManager.
 */
@Test
public void transactionShouldSucceedWithCallbackPreference() throws Exception {
	TransactionAttribute txatt = new DefaultTransactionAttribute();

	MapTransactionAttributeSource tas = new MapTransactionAttributeSource();
	tas.register(getNameMethod, txatt);

	MockCallbackPreferringTransactionManager ptm = new MockCallbackPreferringTransactionManager();

	TestBean tb = new TestBean();
	ITestBean itb = (ITestBean) advised(tb, ptm, tas);

	checkTransactionStatus(false);
	itb.getName();
	checkTransactionStatus(false);

	assertSame(txatt, ptm.getDefinition());
	assertFalse(ptm.getStatus().isRollbackOnly());
}
 
Example #4
Source File: AbstractTransactionAspectTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void transactionExceptionPropagatedWithCallbackPreference() throws Throwable {
	TransactionAttribute txatt = new DefaultTransactionAttribute();

	MapTransactionAttributeSource tas = new MapTransactionAttributeSource();
	tas.register(exceptionalMethod, txatt);

	MockCallbackPreferringTransactionManager ptm = new MockCallbackPreferringTransactionManager();

	TestBean tb = new TestBean();
	ITestBean itb = (ITestBean) advised(tb, ptm, tas);

	checkTransactionStatus(false);
	try {
		itb.exceptional(new OptimisticLockingFailureException(""));
		fail("Should have thrown OptimisticLockingFailureException");
	}
	catch (OptimisticLockingFailureException ex) {
		// expected
	}
	checkTransactionStatus(false);

	assertSame(txatt, ptm.getDefinition());
	assertFalse(ptm.getStatus().isRollbackOnly());
}
 
Example #5
Source File: AbstractTransactionAspectTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Check that a transaction is created and committed using
 * CallbackPreferringPlatformTransactionManager.
 */
@Test
public void transactionShouldSucceedWithCallbackPreference() throws Exception {
	TransactionAttribute txatt = new DefaultTransactionAttribute();

	MapTransactionAttributeSource tas = new MapTransactionAttributeSource();
	tas.register(getNameMethod, txatt);

	MockCallbackPreferringTransactionManager ptm = new MockCallbackPreferringTransactionManager();

	TestBean tb = new TestBean();
	ITestBean itb = (ITestBean) advised(tb, ptm, tas);

	checkTransactionStatus(false);
	itb.getName();
	checkTransactionStatus(false);

	assertSame(txatt, ptm.getDefinition());
	assertFalse(ptm.getStatus().isRollbackOnly());
}
 
Example #6
Source File: AbstractTransactionAspectTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void transactionExceptionPropagatedWithCallbackPreference() throws Throwable {
	TransactionAttribute txatt = new DefaultTransactionAttribute();

	MapTransactionAttributeSource tas = new MapTransactionAttributeSource();
	tas.register(exceptionalMethod, txatt);

	MockCallbackPreferringTransactionManager ptm = new MockCallbackPreferringTransactionManager();

	TestBean tb = new TestBean();
	ITestBean itb = (ITestBean) advised(tb, ptm, tas);

	checkTransactionStatus(false);
	try {
		itb.exceptional(new OptimisticLockingFailureException(""));
		fail("Should have thrown OptimisticLockingFailureException");
	}
	catch (OptimisticLockingFailureException ex) {
		// expected
	}
	checkTransactionStatus(false);

	assertSame(txatt, ptm.getDefinition());
	assertFalse(ptm.getStatus().isRollbackOnly());
}