I wrote a Test for a MongoRepository in Spring Boot, and the test works fine. The only problem is that when the test is over, I want a rollback, so that there will be no change in the database caused by the test.
// package...
// imports...
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = MetistrafficApplication.class)
@Rollback(true)
public class AppRepositoryTests {
@Autowired
private AppRepository appRepository;
@Test
public void insertTest() {
App app = new App("test");
App appInserted = appRepository.save(app);
assertThat(appInserted.getName(), equalTo(app.getName()));
}
}
I put @Transactional before @Rollback, but get this error:
java.lang.illegalstateexception:Failed to retrieve PlatformTransactionManager for @Transactional test for test context
When I searched for the error, I couldn't find any code with MongoRepository. So, how can I solve this?
EDIT: After adding @Transactional("PlatformTransactionManager")
, the error I get is changed to this:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'PlatformTransactionManager' is defined: No matching PlatformTransactionManager bean found for qualifier 'PlatformTransactionManager' - neither qualifier match nor bean name match!