Search in sources :

Example 1 with DefaultDebugger

use of org.apache.camel.impl.DefaultDebugger in project camel by apache.

the class CamelTestSupport method doSetUp.

private void doSetUp() throws Exception {
    log.debug("setUp test");
    if (!useJmx()) {
        disableJMX();
    } else {
        enableJMX();
    }
    CamelContext c2 = createCamelContext();
    if (c2 instanceof ModelCamelContext) {
        context = (ModelCamelContext) c2;
    } else {
        throw new Exception("Context must be a ModelCamelContext");
    }
    threadCamelContext.set(context);
    assertNotNull(context, "No context found!");
    // reduce default shutdown timeout to avoid waiting for 300 seconds
    context.getShutdownStrategy().setTimeout(getShutdownTimeout());
    // set debugger if enabled
    if (isUseDebugger()) {
        context.setDebugger(new DefaultDebugger());
        context.getDebugger().addBreakpoint(breakpoint);
    // note: when stopping CamelContext it will automatic remove the breakpoint
    }
    template = context.createProducerTemplate();
    template.start();
    consumer = context.createConsumerTemplate();
    consumer.start();
    threadTemplate.set(template);
    threadConsumer.set(consumer);
    // enable auto mocking if enabled
    String pattern = isMockEndpoints();
    if (pattern != null) {
        context.addRegisterEndpointCallback(new InterceptSendToMockEndpointStrategy(pattern));
    }
    pattern = isMockEndpointsAndSkip();
    if (pattern != null) {
        context.addRegisterEndpointCallback(new InterceptSendToMockEndpointStrategy(pattern, true));
    }
    // configure properties component (mandatory for testing)
    context.getComponent("properties", PropertiesComponent.class);
    postProcessTest();
    if (isUseRouteBuilder()) {
        RoutesBuilder[] builders = createRouteBuilders();
        for (RoutesBuilder builder : builders) {
            log.debug("Using created route builder: " + builder);
            context.addRoutes(builder);
        }
        boolean skip = "true".equalsIgnoreCase(System.getProperty("skipStartingCamelContext"));
        if (skip) {
            log.info("Skipping starting CamelContext as system property skipStartingCamelContext is set to be true.");
        } else if (isUseAdviceWith()) {
            log.info("Skipping starting CamelContext as isUseAdviceWith is set to true.");
        } else {
            startCamelContext();
        }
    } else {
        log.debug("Using route builder from the created context: " + context);
    }
    log.debug("Routing Rules are: " + context.getRoutes());
    assertValidContext(context);
    INIT.set(true);
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) ModelCamelContext(org.apache.camel.model.ModelCamelContext) DefaultDebugger(org.apache.camel.impl.DefaultDebugger) InterceptSendToMockEndpointStrategy(org.apache.camel.impl.InterceptSendToMockEndpointStrategy) NoSuchEndpointException(org.apache.camel.NoSuchEndpointException) RoutesBuilder(org.apache.camel.RoutesBuilder) ModelCamelContext(org.apache.camel.model.ModelCamelContext)

Example 2 with DefaultDebugger

use of org.apache.camel.impl.DefaultDebugger in project camel by apache.

the class CamelSpringTestContextLoader method handleProvidesBreakpoint.

/**
     * Handles the processing of the {@link ProvidesBreakpoint} annotation on a test class.  Exists here
     * as it is needed in 
     *
     * @param context the initialized Spring context containing the Camel context(s) to insert breakpoints into 
     * @param testClass the test class being processed
     *
     * @throws Exception if there is an error processing the class
     */
protected void handleProvidesBreakpoint(GenericApplicationContext context, Class<?> testClass) throws Exception {
    Collection<Method> methods = getAllMethods(testClass);
    final List<Breakpoint> breakpoints = new LinkedList<Breakpoint>();
    for (Method method : methods) {
        if (AnnotationUtils.findAnnotation(method, ProvidesBreakpoint.class) != null) {
            Class<?>[] argTypes = method.getParameterTypes();
            if (argTypes.length != 0) {
                throw new IllegalArgumentException("Method [" + method.getName() + "] is annotated with ProvidesBreakpoint but is not a no-argument method.");
            } else if (!Breakpoint.class.isAssignableFrom(method.getReturnType())) {
                throw new IllegalArgumentException("Method [" + method.getName() + "] is annotated with ProvidesBreakpoint but does not return a Breakpoint.");
            } else if (!Modifier.isStatic(method.getModifiers())) {
                throw new IllegalArgumentException("Method [" + method.getName() + "] is annotated with ProvidesBreakpoint but is not static.");
            } else if (!Modifier.isPublic(method.getModifiers())) {
                throw new IllegalArgumentException("Method [" + method.getName() + "] is annotated with ProvidesBreakpoint but is not public.");
            }
            try {
                breakpoints.add((Breakpoint) method.invoke(null));
            } catch (Exception e) {
                throw new RuntimeException("Method [" + method.getName() + "] threw exception during evaluation.", e);
            }
        }
    }
    if (breakpoints.size() != 0) {
        CamelSpringTestHelper.doToSpringCamelContexts(context, new DoToSpringCamelContextsStrategy() {

            @Override
            public void execute(String contextName, SpringCamelContext camelContext) throws Exception {
                Debugger debugger = camelContext.getDebugger();
                if (debugger == null) {
                    debugger = new DefaultDebugger();
                    camelContext.setDebugger(debugger);
                }
                for (Breakpoint breakpoint : breakpoints) {
                    LOG.info("Adding Breakpoint [{}] to CamelContext with name [{}].", breakpoint, contextName);
                    debugger.addBreakpoint(breakpoint);
                }
            }
        });
    }
}
Also used : Debugger(org.apache.camel.spi.Debugger) DefaultDebugger(org.apache.camel.impl.DefaultDebugger) Breakpoint(org.apache.camel.spi.Breakpoint) SpringCamelContext(org.apache.camel.spring.SpringCamelContext) Method(java.lang.reflect.Method) LinkedList(java.util.LinkedList) DefaultDebugger(org.apache.camel.impl.DefaultDebugger) DoToSpringCamelContextsStrategy(org.apache.camel.test.spring.CamelSpringTestHelper.DoToSpringCamelContextsStrategy)

Example 3 with DefaultDebugger

use of org.apache.camel.impl.DefaultDebugger in project camel by apache.

the class DebugTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            // use debugger
            context.setDebugger(new DefaultDebugger());
            from("direct:start").to("log:foo").to("mock:result");
        }
    };
}
Also used : DefaultDebugger(org.apache.camel.impl.DefaultDebugger) RouteBuilder(org.apache.camel.builder.RouteBuilder)

Example 4 with DefaultDebugger

use of org.apache.camel.impl.DefaultDebugger in project camel by apache.

the class DebugExceptionBreakpointTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            // use debugger
            context.setDebugger(new DefaultDebugger());
            from("direct:start").to("log:foo").choice().when(body().contains("Camel")).throwException(new IllegalArgumentException("Damn")).end().to("mock:result");
        }
    };
}
Also used : DefaultDebugger(org.apache.camel.impl.DefaultDebugger) RouteBuilder(org.apache.camel.builder.RouteBuilder)

Example 5 with DefaultDebugger

use of org.apache.camel.impl.DefaultDebugger in project camel by apache.

the class DebugSingleStepConditionTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            // use debugger
            context.setDebugger(new DefaultDebugger());
            from("direct:start").routeId("foo").to("log:foo").to("log:bar").to("mock:result");
            from("direct:beer").routeId("beer").to("log:beer").to("mock:result");
        }
    };
}
Also used : DefaultDebugger(org.apache.camel.impl.DefaultDebugger) RouteBuilder(org.apache.camel.builder.RouteBuilder)

Aggregations

DefaultDebugger (org.apache.camel.impl.DefaultDebugger)9 RouteBuilder (org.apache.camel.builder.RouteBuilder)5 Method (java.lang.reflect.Method)2 LinkedList (java.util.LinkedList)2 RoutesBuilder (org.apache.camel.RoutesBuilder)2 InterceptSendToMockEndpointStrategy (org.apache.camel.impl.InterceptSendToMockEndpointStrategy)2 Breakpoint (org.apache.camel.spi.Breakpoint)2 Debugger (org.apache.camel.spi.Debugger)2 SpringCamelContext (org.apache.camel.spring.SpringCamelContext)2 Properties (java.util.Properties)1 CamelContext (org.apache.camel.CamelContext)1 NoSuchEndpointException (org.apache.camel.NoSuchEndpointException)1 PropertiesComponent (org.apache.camel.component.properties.PropertiesComponent)1 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)1 ModelCamelContext (org.apache.camel.model.ModelCamelContext)1 DoToSpringCamelContextsStrategy (org.apache.camel.test.spring.CamelSpringTestHelper.DoToSpringCamelContextsStrategy)1