Search in sources :

Example 6 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");
    // jmx is enabled if we have configured to use it, or if dump route coverage is enabled (it requires JMX)
    boolean jmx = useJmx() || isDumpRouteCoverage();
    if (jmx) {
        enableJMX();
    } else {
        disableJMX();
    }
    context = (ModelCamelContext) createCamelContext();
    threadCamelContext.set(context);
    assertNotNull("No context found!", context);
    // reduce default shutdown timeout to avoid waiting for 300 seconds
    context.getShutdownStrategy().setTimeout(getShutdownTimeout());
    // set debugger if enabled
    if (isUseDebugger()) {
        if (context.getStatus().equals(ServiceStatus.Started)) {
            log.info("Cannot setting the Debugger to the starting CamelContext, stop the CamelContext now.");
            // we need to stop the context first to setup the debugger
            context.stop();
        }
        context.setDebugger(new DefaultDebugger());
        context.getDebugger().addBreakpoint(breakpoint);
    // note: when stopping CamelContext it will automatic remove the breakpoint
    }
    template = context.createProducerTemplate();
    template.start();
    fluentTemplate = context.createFluentProducerTemplate();
    fluentTemplate.start();
    consumer = context.createConsumerTemplate();
    consumer.start();
    threadTemplate.set(template);
    threadFluentTemplate.set(fluentTemplate);
    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)
    PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class);
    Properties extra = useOverridePropertiesWithPropertiesComponent();
    if (extra != null && !extra.isEmpty()) {
        pc.setOverrideProperties(extra);
    }
    Boolean ignore = ignoreMissingLocationWithPropertiesComponent();
    if (ignore != null) {
        pc.setIgnoreMissingLocation(ignore);
    }
    postProcessTest();
    if (isUseRouteBuilder()) {
        RoutesBuilder[] builders = createRouteBuilders();
        for (RoutesBuilder builder : builders) {
            log.debug("Using created route builder: " + builder);
            context.addRoutes(builder);
        }
        replaceFromEndpoints();
        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 {
        replaceFromEndpoints();
        log.debug("Using route builder from the created context: " + context);
    }
    log.debug("Routing Rules are: " + context.getRoutes());
    assertValidContext(context);
    INIT.set(true);
}
Also used : DefaultDebugger(org.apache.camel.impl.DefaultDebugger) InterceptSendToMockEndpointStrategy(org.apache.camel.impl.InterceptSendToMockEndpointStrategy) Properties(java.util.Properties) PropertiesComponent(org.apache.camel.component.properties.PropertiesComponent) RoutesBuilder(org.apache.camel.RoutesBuilder)

Example 7 with DefaultDebugger

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

the class CamelAnnotationsHandler method handleProvidesBreakpoint.

public static void handleProvidesBreakpoint(ConfigurableApplicationContext 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 CamelSpringTestHelper.DoToSpringCamelContextsStrategy() {

            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) {
                    LOGGER.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)

Example 8 with DefaultDebugger

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

the class DebugSingleStepTest 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("log:bar").to("mock:result");
        }
    };
}
Also used : DefaultDebugger(org.apache.camel.impl.DefaultDebugger) RouteBuilder(org.apache.camel.builder.RouteBuilder)

Example 9 with DefaultDebugger

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

the class DebugExceptionEventBreakpointTest 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)

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