I want to unit test Camel code using ScalaTest and the FunSpec test style.
To do so, I need to extend from both FunSpec and CamelTestSupport. However, both these are classes and at least one needs to be a trait in order to do this in Scala. For example, this does not work:
class MySpec extends FunSpec with CamelTestSupport {}
Note: It appears that many online references to FunSpec suggest it is a trait, but it is a class in scalatest_2.11-3.0.0-M15.
How can I use ScalaTest FunSpec to test Camel?
The same test written using JUnit would look as follows:
public class DataLakeEventListenerRouteIT extends CamelTestSupport {
@Autowired
private MyRouteBuilder myRouteBuilder;
private MockEndpoint myEndpointMock;
@Override
public boolean isUseAdviceWith() {
return true;
}
@Override
protected JndiRegistry createRegistry() throws Exception {
JndiRegistry registry = super.createRegistry();
//do some required bindings here
return registry;
}
@Before
public void startup() throws Exception {
AdviceWithRouteBuilder mock = new AdviceWithRouteBuilder() {
public void configure() throws Exception {
mockEndpointsAndSkip(myRouteBuilder.MY_ROUTE_URI);
}
};
context.addRoutes(myRouteBuilder);
context.getRouteDefinition(myRouteBuilder.MY_ROUTE_ID)
.adviceWith(context, mock);
myEndpointMock = getMockEndpoint(
"mock:" + myRouteBuilder.MY_ROUTE_URI);
}
@Test
public void timerRouteShouldSendMessage() throws Exception {
// Arrange
context.start();
myEndpointMock.expectedMessageCount(1);
myEndpointMock.assertIsSatisfied();
context.stop();
}
}