I have discovered an issue when I run multiple tests on a route using
weaveByToUri on the same endpoint.  I have it replicated in my sample app.
https://github.com/owain68/camel-spring-boot-examples

It looks as though the .replace() replaces the endpoint for the whole test
class, not just the individual test.  
Each test passes individually but mockTestOneNotFound() fails when both are
run together.  If I comment out the weaveByToUri in mockTestOneNotFound()
then both tests pass when run together.

Is this something to do with the routes being generated by Rest DSL and then
not being regenerated for each test?  I can't think of anything else.

The route is. RestRoute

@Override
public void configure() throws Exception {

rest("/")
.get("{body}")
.id("getRoute")
.produces("application/json")
.to("direct:RouteB");
}

and the test class is: RestMockTests

@RunWith(CamelSpringBootRunner.class)
@MockEndpoints
@UseAdviceWith
@SpringBootTest(classes =
mydomain.springbootcamel.SpringBootCamelExamples.class, webEnvironment =
SpringBootTest.WebEnvironment.RANDOM_PORT)
public class RestMockTests {

@Autowired
private CamelContext camelContext;

@Autowired
private TestRestTemplate restTemplate;

@Test
public void mockTestOneNotFound() throws Exception {

camelContext.getRouteDefinition("getRoute")
.adviceWith(camelContext, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
// send the outgoing message to mock
weaveByToUri("direct:RouteB").replace().inOut("mock:routeB");
}
});

camelContext.start();
MockEndpoint mockOut = camelContext.getEndpoint("mock:routeB",
MockEndpoint.class);
mockOut.expectedMessageCount(0);
ResponseEntity<String> response = restTemplate.getForEntity("/dummy",
String.class);
mockOut.assertIsSatisfied();
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
}

@Test
public void mockTestTwoFound() throws Exception {

camelContext.getRouteDefinition("getRoute")
.adviceWith(camelContext, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
// send the outgoing message to mock
weaveByToUri("direct:RouteB").replace().inOut("mock:routeB");
}
});

camelContext.start();
MockEndpoint mockOut = camelContext.getEndpoint("mock:routeB",
MockEndpoint.class);
mockOut.expectedMessageCount(1);
ResponseEntity<String> response =
restTemplate.getForEntity("/api/something", String.class);
mockOut.assertIsSatisfied();
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
}
}

The error on the second test is:

https://gist.github.com/owain68/58aa626ac4a17db3ce47dce21e7c12ab

java.lang.IllegalArgumentException: There are no outputs which matches:
direct:RouteB in the route:
Route(getRoute)[[From[rest:get:/:{body}?routeId=getRoute&produces=application%2Fjson]]
-> [RestBinding, pipeline -> [[To[mock:routeB]]]]]

at org.apache.camel.builder.AdviceWithTasks$1.task(AdviceWithTasks.java:194)
at
org.apache.camel.model.RouteDefinition.adviceWith(RouteDefinition.java:280)
at
org.apache.camel.model.RouteDefinition.adviceWith(RouteDefinition.java:215)
at
mydomain.springbootcamel.RestMockTests.mockTestOneNotFound(RestMockTests.java:33)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at
org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at
org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at
org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at
org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at
org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at
com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at
com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
at
com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)



--
View this message in context: 
http://camel.465427.n5.nabble.com/2-18-3-Rest-DSL-MockEndpoint-second-unit-test-weaveByToUri-fails-with-no-output-which-matches-direct-tp5798402.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to