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);
}
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);
}
}
});
}
}
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");
}
};
}
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");
}
};
}
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");
}
};
}
Aggregations