I have an application running Apache Camel and now I'm implementing tests built into it.
I have here a class that does the route function:
@Component
public class CoreRouteBuilder extends AbstractMensageiroRouteBuilder {
@Value("${core.endpoint.in.consumer}")
private String endpointEntrada;
@Value("${core.endpoint.out.producer}")
private String endpointSaida;
@Override
public void configureRoute() {
// @formatter:off
from(endpointEntrada)
.unmarshal().json(JsonLibrary.Jackson, MensagemDto.class)
.marshal().json(JsonLibrary.Jackson)
.to(endpointSaida);
// @formatter:on
}
}
CoreRouteBuilder test class:
public class CoreRouteBuilderTest extends CamelTestSupport {
@Produce(uri = "jms:topic:quote")
protected ProducerTemplate template;
@EndpointInject(uri = "mock:quote")
protected MockEndpoint resultEndpoint;
@Override
protected CamelContext createCamelContext() throws Exception {
CamelContext context = super.createCamelContext();
context.addComponent("jms", context.getComponent("seda"));
return context;
}
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
CoreRouteBuilder coreRouteBuilder = new CoreRouteBuilder();
ReflectionTestUtils.setField(coreRouteBuilder, "endpointEntrada", "jms:topic:quote");
ReflectionTestUtils.setField(coreRouteBuilder, "endpointSaida", "mock:quote");
return coreRouteBuilder;
}
@Test
public void test() throws Exception {
MensagemDto mensagemDto = new MensagemDto();
mensagemDto.setAssunto("opa");
// resultEndpoint.expectedMessageCount(1);
resultEndpoint.expectedBodiesReceived(mensagemDto);
MensagemDto mensagemDto2 = new MensagemDto();
mensagemDto2.setAssunto("opa");
template.sendBody("jms:topic:quote", mensagemDto2);
resultEndpoint.assertIsSatisfied();
}
When I test, it returns the error:
java.lang.NoClassDefFoundError: org/apache/camel/support/ServiceSupport
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
.
.
.
Caused by: java.lang.ClassNotFoundException: org.apache.camel.support.ServiceSupport
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
Do you know why you made this mistake? If I take the json conversion, the test works. However, I need the conversion to add other beans on the route.