0
ScalaTestとFunSpecテストスタイルを使用して単体テストのキャメルコードを作成します。ScalaTestを使用してCamelをテストするには
これを行うには、FunSpecとCamelTestSupportの両方から拡張する必要があります。しかし、これらは両方ともクラスであり、Scalaでこれを行うには、少なくとも1つは特性である必要があります。たとえば、これは動作しません:
class MySpec extends FunSpec with CamelTestSupport {}
注:FunSpecに多くのオンラインの参照は、それが特色であることを示唆しているように見えるが、それはscalatest_2.11-3.0.0-M15でクラスです。
ScalaTest FunSpecを使用してCamelをテストするにはどうすればよいですか?次のように
のJUnitを使って書かれた同じテストがなります
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();
}
}