CreateCamelRouteAction extends AbstractCamelRouteAction { public List<RouteDefinition> getRoutes() { return routes; } CreateCamelRouteAction(Builder builder); @Override void doExecute(TestContext context); JAXBContext getJaxbContext(); List<RouteDefinition> getRoutes(); String getRouteContext();  }
@Test public void testCreateRouteContext() throws Exception { reset(camelContext); when(camelContext.getName()).thenReturn("camel_context"); doAnswer(invocation -> { RouteBuilder routesBuilder = invocation.getArgument(0); routesBuilder.configure(); Assert.assertEquals(routesBuilder.getRouteCollection().getRoutes().size(), 2L); Assert.assertEquals(routesBuilder.getRouteCollection().getRoutes().get(0).getId(), "route_1"); Assert.assertEquals(routesBuilder.getRouteCollection().getRoutes().get(1).getId(), "route_2"); return null; }).when(camelContext).addRoutes(any(RouteBuilder.class)); CreateCamelRouteAction action = new CreateCamelRouteAction.Builder() .context(camelContext) .routeContext("<routeContext xmlns=\"http: "<route id=\"route_1\">\n" + "<from uri=\"direct:test1\"/>\n" + "<to uri=\"mock:test1\"/>\n" + "</route>\n" + "<route id=\"route_2\">\n" + "<from uri=\"direct:test2\"/>\n" + "<to uri=\"mock:test2\"/>\n" + "</route>\n" + "</routeContext>") .build(); action.execute(context); verify(camelContext).addRoutes(any(RouteBuilder.class)); }
@Test public void testCreateRouteContextVariableSupport() throws Exception { reset(camelContext); context.setVariable("routeId", "route_1"); context.setVariable("endpointUri", "test1"); when(camelContext.getName()).thenReturn("camel_context"); doAnswer(invocation -> { RouteBuilder routesBuilder = invocation.getArgument(0); routesBuilder.configure(); Assert.assertEquals(routesBuilder.getRouteCollection().getRoutes().size(), 1L); Assert.assertEquals(routesBuilder.getRouteCollection().getRoutes().get(0).getId(), "route_1"); return null; }).when(camelContext).addRoutes(any(RouteBuilder.class)); CreateCamelRouteAction action = new CreateCamelRouteAction.Builder() .context(camelContext) .routeContext("<routeContext xmlns=\"http: "<route id=\"${routeId}\">\n" + "<from uri=\"direct:${endpointUri}\"/>\n" + "<to uri=\"mock:${endpointUri}\"/>\n" + "</route>\n" + "</routeContext>") .build(); action.execute(context); verify(camelContext).addRoutes(any(RouteBuilder.class)); }
@Test public void testCreateRoute() throws Exception { reset(camelContext, route); when(camelContext.getName()).thenReturn("camel_context"); when(route.getId()).thenReturn("route_1"); doAnswer(invocation -> { RouteBuilder routesBuilder = invocation.getArgument(0); routesBuilder.configure(); Assert.assertEquals(routesBuilder.getRouteCollection().getRoutes().size(), 1L); Assert.assertEquals(routesBuilder.getRouteCollection().getRoutes().get(0), route); return null; }).when(camelContext).addRoutes(any(RouteBuilder.class)); CreateCamelRouteAction action = new CreateCamelRouteAction.Builder() .context(camelContext) .routes(Collections.singletonList(route)) .build(); action.execute(context); verify(camelContext).addRoutes(any(RouteBuilder.class)); }