The following test cases are functionally working properly, but one of the test methods having to create a new article in the database doesn't rollback at the end of the test case execution.
I expect it to work that way. For a test case that update article actually rollbacks the update at the end of test case execution.
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(value = "/applicationContext-test.xml")
@TransactionConfiguration(transactionManager = "txManager", defaultRollback = true)
@Transactional
public class PriceRepositoryTest {
@Resource(name ="repository")
private PriceRepository repository;
@Test
public void testGetAll() throws Exception {
Assert.assertEquals(8, repository.getAll().size());
}
@Test
@Rollback
public void shouldSaveNewArticle(){
Article article = new Article();
article.setName("Article");
article.setPrice(33);
repository.save(article);
Assert.assertEquals(9, repository.getAll().size());
}
@Test
@Rollback
public void shouldUpdateArticle(){
Article article = repository.getArticle(4);
article.setPrice(33);
repository.update(article);
Assert.assertEquals(String.valueOf(33.0), String.valueOf(repository.getArticle(4).getPrice()));
}
}