use of org.apache.camel.spring.SpringCamelContext 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.spring.SpringCamelContext in project camel by apache.
the class ServiceCallConfigurationTest method testServiceDiscoveryConfiguration.
@Test
public void testServiceDiscoveryConfiguration() {
SpringCamelContext context = createContext("org/apache/camel/spring/cloud/ServiceCallConfigurationTest.xml");
ServiceCallConfigurationDefinition conf1 = context.getServiceCallConfiguration("conf1");
assertNotNull("No ServiceCallConfiguration (1)", conf1);
assertNotNull("No ServiceDiscoveryConfiguration (1)", conf1.getServiceDiscoveryConfiguration());
assertNotNull("No ServiceCallLoadBalancerConfiguration (1)", conf1.getLoadBalancerConfiguration());
assertTrue(conf1.getLoadBalancerConfiguration() instanceof DefaultServiceCallLoadBalancerConfiguration);
StaticServiceCallServiceDiscoveryConfiguration discovery1 = (StaticServiceCallServiceDiscoveryConfiguration) conf1.getServiceDiscoveryConfiguration();
assertEquals(1, discovery1.getServers().size());
assertEquals("localhost:9091", discovery1.getServers().get(0));
ServiceCallConfigurationDefinition conf2 = context.getServiceCallConfiguration("conf2");
assertNotNull("No ServiceCallConfiguration (2)", conf2);
assertNotNull("No ServiceDiscoveryConfiguration (2)", conf2.getServiceDiscoveryConfiguration());
assertNull(conf2.getLoadBalancerConfiguration());
ChainedServiceCallServiceDiscoveryConfiguration discovery2 = (ChainedServiceCallServiceDiscoveryConfiguration) conf2.getServiceDiscoveryConfiguration();
assertEquals(2, discovery2.getServiceDiscoveryConfigurations().size());
assertTrue(discovery2.getServiceDiscoveryConfigurations().get(0) instanceof StaticServiceCallServiceDiscoveryConfiguration);
assertTrue(discovery2.getServiceDiscoveryConfigurations().get(1) instanceof StaticServiceCallServiceDiscoveryConfiguration);
StaticServiceCallServiceDiscoveryConfiguration sconf1 = (StaticServiceCallServiceDiscoveryConfiguration) discovery2.getServiceDiscoveryConfigurations().get(0);
assertEquals(1, sconf1.getServers().size());
assertEquals("localhost:9092", sconf1.getServers().get(0));
StaticServiceCallServiceDiscoveryConfiguration sconf2 = (StaticServiceCallServiceDiscoveryConfiguration) discovery2.getServiceDiscoveryConfigurations().get(1);
assertEquals(1, sconf2.getServers().size());
assertEquals("localhost:9093,localhost:9094,localhost:9095,localhost:9096", sconf2.getServers().get(0));
ChainedServiceCallServiceFilterConfiguration filter = (ChainedServiceCallServiceFilterConfiguration) conf2.getServiceFilterConfiguration();
assertEquals(2, filter.getServiceFilterConfigurations().size());
assertTrue(filter.getServiceFilterConfigurations().get(0) instanceof HealthyServiceCallServiceFilterConfiguration);
assertTrue(filter.getServiceFilterConfigurations().get(1) instanceof BlacklistServiceCallServiceFilterConfiguration);
}
use of org.apache.camel.spring.SpringCamelContext in project camel by apache.
the class ErrorHandlerTest method testEndpointConfiguration.
public void testEndpointConfiguration() throws Exception {
SpringCamelContext context = applicationContext.getBeansOfType(SpringCamelContext.class).values().iterator().next();
List<Route> list = context.getRoutes();
assertEquals("Number routes created" + list, 2, list.size());
for (Route route : list) {
EventDrivenConsumerRoute consumerRoute = assertIsInstanceOf(EventDrivenConsumerRoute.class, route);
Channel channel = unwrapChannel(consumerRoute.getProcessor());
DeadLetterChannel deadLetterChannel = assertIsInstanceOf(DeadLetterChannel.class, channel.getErrorHandler());
RedeliveryPolicy redeliveryPolicy = deadLetterChannel.getRedeliveryPolicy();
assertEquals("getMaximumRedeliveries()", 1, redeliveryPolicy.getMaximumRedeliveries());
assertEquals("isUseExponentialBackOff()", true, redeliveryPolicy.isUseExponentialBackOff());
}
}
use of org.apache.camel.spring.SpringCamelContext in project camel by apache.
the class SpringXmlRouteBuilderTest method getRoutesFromContext.
protected List<Route> getRoutesFromContext(String classpathConfigFile) {
applicationContext = new ClassPathXmlApplicationContext(classpathConfigFile);
SpringCamelContext context = applicationContext.getBeansOfType(SpringCamelContext.class).values().iterator().next();
assertNotNull("No Camel Context in file: " + classpathConfigFile, context);
List<Route> routes = context.getRoutes();
assertNotNull("No routes available for context: " + context.getName() + " in file: " + classpathConfigFile, routes);
return routes;
}
use of org.apache.camel.spring.SpringCamelContext in project camel by apache.
the class RouteAutoStartupPropertiesTest method testAutoStartupTrue.
public void testAutoStartupTrue() throws Exception {
ac = new ClassPathXmlApplicationContext("org/apache/camel/spring/config/RouteAutoStartupTrueTest.xml");
SpringCamelContext camel = ac.getBeansOfType(SpringCamelContext.class).values().iterator().next();
assertEquals(true, camel.getRouteStatus("bar").isStarted());
// and now we can send a message to the route and see that it works
MockEndpoint mock = camel.getEndpoint("mock:result", MockEndpoint.class);
mock.expectedMessageCount(1);
ProducerTemplate template = camel.createProducerTemplate();
template.start();
template.sendBody("direct:start", "Hello World");
template.stop();
mock.assertIsSatisfied();
}
Aggregations