I've got a question to Spring, hibernate and testng.
I am developing an app and try to write a transactional unit test. The question is how could I rollback my database operation when my buissnes method is marked as "transactional"?
The code:
@Test
@ContextConfiguration(locations = { "classpath:applicationContext.xml" })
@TransactionConfiguration(defaultRollback = true)
public class SampleTest extends
AbstractTransactionalTestNGSpringContextTests {
@Autowired
private AuthorDao authorDao;
@BeforeTest
void createAppCtx() {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
"/applicationContext.xml");
}
@Test
void testStg() {
Person person = new Author();
person.setFirstName("Edward");
person.setLastName("Kowalski");
authorDao.createAuthor(person);
}
In my authorDao I've following method:
@PersistenceContext
private EntityManager entityManager;
@Transactional
public Author createAuthor(Person author) {
entityManager.persist(author);
return (Author) author;
}
If the application context is needed, I can also attach it.
So as you can see the buisness method is transactional so there is a commit after calling. So point is how to avoid commit in the test class? Is it possible?
Many thanks for help.
Aucun commentaire:
Enregistrer un commentaire