Spring integration test transaction not rollback

Writing an integration test for a spring-based application arose because of a problem with a transaction rollback - the data is inserted, but after the transaction is rolled back, the data is still in the database table ... Spring 3.0.5, JUnit 4.8.2

Integration Test Code

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:/applicationContext.xml" })
@TransactionConfiguration(transactionManager="txManager",defaultRollback=true)
@Transactional
public class GenerateCodeStrategyTest {

  @Autowired
  @Qualifier(value = "generateCodeStrategy")
  private Strategy generateCodeStrategy;

  @Test
  @Transactional
  public void genCodeIntegrationTestCommunicationFailure() {
  //generate some parameters
  SMPPSession mockedSession = mock(SMPPSession.class);
  generateCodeStrategy.setSession(mockedSession);
  generateCodeStrategy.sendRequest(params);
  final SubscribeInfo subscribeInfo = subscribeDao.getUserByPhone(phone);
  assertNotNull(subscribeInfo);
  assertEquals(phone, subscribeInfo.getPhone());
  assertEquals(Status.BAD_STATUS, subscribeInfo.getStatus());
  }
}

In DEBUG mode in the logs, I see that the transaction has started and rollback

INFO: Began transaction (1): transaction manager [org.springframework.jdbc.datasource.DataSourceTransactionManager@1edd9b3]; rollback [true]
[main] DEBUG org.hibernate.SQL - insert into sms_subscribe (phone_cell, status, ts_subscribe, subscription_status, ts_unsubscribe, receiverIdentification, user_id) values (?, ?, ?, ?, ?, ?, ?) 
INFO: Rolled back transaction after test execution for test context [[TestContext@1f18cbe testClass = GenerateCodeStrategyTest, locations = array<String>['classpath:/applicationContext.xml'], testInstance = lv.mrb.server.service.GenerateCodeStrategyTest@14f1726, testMethod = genCodeIntegrationTestCommunicationFailure@GenerateCodeStrategyTest, testException = [null]]]

Maybe someone has an idea why this is happening? Thank you for your help.

UPDATED: This integration test generates some parameters, and then the use of the Mockito mock session object is inserted into the Strategy service. This mock object simply throws an exception, and in this exception, the data from the strategy service is stored in the database through the DAO layer. Then test the query to the database through the DAO layer and confirm the saved values.

Hibernate, DAO

final Session currentSession = sessionFactory.getCurrentSession();
currentSession.save(object);

sessionFactory - AnnotationSessionFactoryBean, datasource - c3p0 ComboPooledDataSource

2: Mysql, MyISAM, InnoDB, .

+3
2

, , @Transactional, REQUIRES_NEW. , .

, DAO @Transactional. , . DAO.

+4

@Transactional .

, .

0

All Articles