@Before public void setUp() throws Exception { log.info("********************************************************************************"); log.info("Testing: " + getTestMethodName() + "(" + getClass().getName() + ")"); log.info("********************************************************************************"); log.debug("setUp test"); if (!useJmx()) { disableJMX(); } else { enableJMX(); } context = createCamelContext(); assertValidContext(context); // reduce default shutdown timeout to avoid waiting for 300 seconds context.getShutdownStrategy().setTimeout(getShutdownTimeout()); // set debugger 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(); // enable auto mocking if enabled String pattern = isMockEndpoints(); if (pattern != null) { context.addRegisterEndpointCallback(new InterceptSendToMockEndpointStrategy(pattern)); } postProcessTest(); if (isUseRouteBuilder()) { RouteBuilder[] builders = createRouteBuilders(); for (RouteBuilder builder : builders) { log.debug("Using created route builder: " + builder); context.addRoutes(builder); } startCamelContext(); log.debug("Routing Rules are: " + context.getRoutes()); } else { log.debug("Using route builder from the created context: " + context); } log.debug("Routing Rules are: " + context.getRoutes()); }
/** * Dynamically find all {@link MllpTransactionEndpoint} containing a reference to this instance * and append it to the routeId list * * @param camelContext camel context */ private void collectTransactionTargets(CamelContext camelContext) { for (Route route : camelContext.getRoutes()) { if (route.getEndpoint() instanceof MllpTransactionEndpoint) { MllpTransactionEndpoint<?> endpoint = (MllpTransactionEndpoint<?>) route.getEndpoint(); if (endpoint.getDispatcher() == this) { addTransactionRoutes(route.getId()); } } } }
@Override protected void assertValidContext(CamelContext context) { super.assertValidContext(context); List<Route> routes = context.getRoutes(); int routeCount = getExpectedRouteCount(); if (routeCount > 0) { assertNotNull("Should have some routes defined", routes); assertTrue("Should have at least one route", routes.size() >= routeCount); } log.debug("Camel Routes: " + routes); }
@Test public void testPublishEndpointWithOption() throws Exception { SpringRouteBuilder route = new SpringRouteBuilder() { @Override public void configure() throws Exception { from("fabric:cheese:seda:bar").routeId(ROUTE_NAME).to("log:mylog"); } }; camelContext.addRoutes(route); List<Route> registeredRoutes = camelContext.getRoutes(); Assert.assertEquals("number of routes", 1, registeredRoutes.size()); Assert.assertEquals("route name", ROUTE_NAME, registeredRoutes.get(0).getId()); // make sure the parameters are passed to the child endpoint FabricPublisherEndpoint endpoint = (FabricPublisherEndpoint) registeredRoutes.get(0).getEndpoint(); Assert.assertEquals("wrong endpoint uri", "seda:bar", endpoint.getChild()); }