Ich habe wahrscheinlich etwas verpasst, aber ich kann es nicht schaffen, meine Route so zu testen, wie ich es möchte.Camel Prozessor Unit/Integration Test
Ich habe die folgende Bohne bekommt:
@Component("fileProcessor")
public class FileProcessor {
public boolean valid(@Header("customObject) CustomObject customObject,Exchange exchange) throws IOException{
return false;
}
Ich habe einen Weg meine Bohne Aufruf wie folgt:
from("direct:validationFile").routeId("validationFile").validate().method("fileProcessor","valid")
// Other stuff
.end();
Hier ist mein Unit-Test, basierend auf einem Beispiel, das ich gefunden:
@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class})
@ContextConfiguration(locations = { "classpath:/tu-dao-beans.xml" })
public class FileProcessorTest extends CamelTestSupport {
@EndpointInject(uri = "mock:result")
protected MockEndpoint resultEndpoint;
@Produce(uri = "direct:start")
protected ProducerTemplate template;
@Override
public boolean isDumpRouteCoverage() {
return true;
}
@Test
public void testSendMatchingMessage() throws Exception {
String expectedBody = "<matched/>";
resultEndpoint.expectedBodiesReceived(expectedBody);
template.sendBodyAndHeader(expectedBody, "foo", "bar");
resultEndpoint.assertIsSatisfied();
}
@Test
public void testSendNotMatchingMessage() throws Exception {
resultEndpoint.expectedMessageCount(0);
template.sendBodyAndHeader("<notMatched/>", "foo", "notMatchedHeaderValue");
resultEndpoint.assertIsSatisfied();
}
@Override
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
// from("direct:start").filter(header("foo").isEqualTo("bar")).to("mock:result");
from("direct:start").routeId("validationFile").validate().method("fileProcessor","valid").to("mock:result");
}
};
}
}
Der Test schlägt fehl, weil fileProcessor
nicht gefunden, aber ich bin mir ziemlich sicher, dass meine spring context
ist richtig geladen, ich verwende die gleiche beans.xml
Datei für meine dbunit
Tests und meine DAO-Komponenten sind gut gefunden ... Was fehlt mir?
EDIT: Dank Jérémis B Antwort habe ich mein Problem leicht behoben. Falls jemand stolpern, wie ich hier getan hat, ist der Code ich hinzugefügt:
@Autowired
private FileProcessor fileProcessor;
@Override
protected JndiRegistry createRegistry() throws Exception {
JndiRegistry registry = super.createRegistry();
registry.bind("fileProcessor", fileProcessor);
return registry;
}
Ich habe einen Artikel darüber veröffentlicht, hoffe es hilft: https://dev.to/matthieusb/integration-testing-on-existing-routes-with-apache-camel-and-spring-and-dbunit – matthieusb