Error testing a route with Apache Camel

Asked

Viewed 265 times

0

I have an application running Apache Camel and now I’m implementing tests integrated in 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
    }
}

Class to test Coreroutebuilder:

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 do the 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 this error? If I take out the json conversion, the test works. However, I need the conversion to add other Bens on the route.

  • How do you manage the dependencies of your application? Probably in Test Time the version of camel-core is different from the one used to compile.

  • Com spring. I organized this class by what I read in the documentation. My problem is different now. The solution of that part, I put here: http://answall.com/questions/111116/n%C3%A3o-can-inject-Depend%C3%Aancia-do-spring-during-the-test-integrates%C3%A7%C3%A3o-do-Camel

1 answer

0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.