I am struggling to get some tests I wrote to roll back transaction. My test passes and works ok. However when I try to make it transactional (so i can roll back the test) I am getting the following error
java.lang.IllegalStateException: Cannot start a new transaction without ending the existing transaction.
at org.springframework.test.context.transaction.TransactionalTestExecutionListener.beforeTestMethod(TransactionalTestExecutionListener.java:175) ~[spring-test-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.test.context.TestContextManager.beforeTestMethod(TestContextManager.java:249) [spring-test-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at
If I throw an exception in my routing it will undo any database saves so the transaction I have does work... It just does not seem to attach itself to the test and rollback?
My test looks like this.
@RunWith(CamelSpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {TestAppConfig.class})
@Transactional
public class RouteTest
{
@Autowired SignUpRoute signUpRoute;
@Test
public void basicTest() throws Exception{
ModelCamelContext signUpRouteContext = signUpRoute.getContext();
MessageDto messageDto = new MessageDto();
messageDto.setFirstName();
messageDto.setLastName();
// etc
ObjectMapper mapper = new ObjectMapper();
String jsonMessage = mapper.writeValueAsString(messageDto);
String rabbitURL = "rabbitmq://docker:5672/ignUp.exchange?queue=...etc...";
ProducerTemplate producerTemplate = supplierSignUpRouteContext.createProducerTemplate();
producerTemplate.setDefaultEndpoint(END_POINT_MOCK);
producerTemplate.sendBody(rabbitmqURL, jsonMessage);
END_POINT_MOCK.expectedMessageCount(1);
END_POINT_MOCK.assertIsSatisfied();
}
}