I have a Camel route defined as follows:
@Component
public class MyRoute extends RouteBuilder {
@Override
public void configure() {
onException(BeanValidationException.class)
.setBody(simple("${exception}"))
.to("{{route.mail}}")
.continued(true); // there's a validation issue just notify via mail and continue processing
// main flow
from("{{route.from}}")
.unmarshal(new BindyCsvDataFormat(MyClass.class))
.to("{{route.mail}}")
.to("{{route.to}}");
}
}
In my test case, how can I differentiate .to("{{route.mail}}")
in the onException
flow vs .to("{{route.mail}}")
in the main
flow?
I want to write a test that verifies the .to("{{route.mail}}")
in the onException(BeanValidationException.class)
is called. I can verify that route.mail
is called twice as follows:
@SpringBootTest(properties = {
"route.from = direct:from",
"route.mail = mock:mail",
"route.to = mock:to"
})
@CamelSpringBootTest
class RouteTest {
@Autowired
private ProducerTemplate template;
@EndpointInject("mock:to")
private MockEndpoint mockTo;
@EndpointInject("mock:mail")
private MockEndpoint mockMail;
@Test
@DirtiesContext
void beanValidationException() throws InterruptedException {
mockMail.expectedMessageCount(2);
template.sendBody("{{route.from}}", "dataToCauseBeanValidationException");
mockMail.assertIsSatisfied();
}
}
But I'm not sure how to test which route.mail
was called.