Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring integration test transaction is not rolled back
    primarykey
    data
    text
    <p>Writing integration test for spring based application got problem with transaction rollback - data is inserted, but after transaction rolled back, data are still in database table... Spring 3.0.5, JUnit 4.8.2</p> <p>Integration Test code</p> <pre><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()); } } </code></pre> <p>In DEBUG mode in logs I can see transaction started and rolled back</p> <pre><code>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&lt;String&gt;['classpath:/applicationContext.xml'], testInstance = lv.mrb.server.service.GenerateCodeStrategyTest@14f1726, testMethod = genCodeIntegrationTestCommunicationFailure@GenerateCodeStrategyTest, testException = [null]]] </code></pre> <p>Maybe someone have idea why this happens ? Thank you for help.</p> <p>UPDATED: This integration test generate some parameters, then using Mockito mock of the session object is inserted into Strategy service. This mock object is just throwing exception and on this exception in that Strategy service data is saved to database via DAO layer. Then test make request to database via DAO layer and assert saved values.</p> <p>Data is persisted via Hibernate so basically in my DAO object object is saved that way </p> <pre><code>final Session currentSession = sessionFactory.getCurrentSession(); currentSession.save(object); </code></pre> <p>sessionFactory is AnnotationSessionFactoryBean where datasource is c3p0 ComboPooledDataSource class</p> <p>UPDATE 2 : The problem was with Mysql engine, by default it was MyISAM, so I just needed to switch it to InnoDB and now all works.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload