RouteFactory { public static List<RouteDefinition> createRoute(String className) { return createRoute(className, null, null); } private  RouteFactory(); static List<RouteDefinition> getRoutes(CamelComponentImplementationModel model, SwitchYardCamelContext camelContext); static List<RouteDefinition> loadRoute(String xmlPath, SwitchYardCamelContext camelContext,
            PropertyResolver propertyResolver); static List<RouteDefinition> loadRoute(String xmlPath); static List<RouteDefinition> createRoute(String className); static List<RouteDefinition> createRoute(String className, String namespace); static List<RouteDefinition> createRoute(String className, SwitchYardCamelContext camelContext, String namespace); static List<RouteDefinition> createRoute(Class<?> routeClass); static List<RouteDefinition> createRoute(Class<?> routeClass, SwitchYardCamelContext camelContext, String namespace); static List<RouteDefinition> createRoute(RouteBuilder routeBuilder, SwitchYardCamelContext camelContext, String namespace);  }
@Test public void createRouteFromClass() { List<RouteDefinition> routes = RouteFactory.createRoute(SingleRouteService.class.getName()); Assert.assertNotNull(routes); Assert.assertEquals(1, routes.size()); RouteDefinition route = routes.get(0); Assert.assertEquals(1, route.getInputs().size()); Assert.assertEquals(2, route.getOutputs().size()); }
@Test public void doesntExtendRouteBuilder() { try { RouteFactory.createRoute(DoesntExtendRouteBuilder.class.getName()); Assert.fail("Java DSL class does not extend RouteBuilder " + DoesntExtendRouteBuilder.class.getName()); } catch (RuntimeException ex) { System.err.println("Route class that does not extend RouteBuilder was rejected: " + ex.toString()); } }
@Test public void noRoutesDefined() { try { RouteFactory.createRoute(NoRoutesDefined.class.getName()); Assert.fail("No routes defined in Java DSL class " + NoRoutesDefined.class.getName()); } catch (RuntimeException ex) { System.err.println("Java DSL class without a route was rejected: " + ex.toString()); } }
@Test public void testExecutorServiceShutdown() throws Exception { SwitchYardCamelContextImpl context = new SwitchYardCamelContextImpl(); Assert.assertEquals(null, CustomExecutorRoute.customPool); List<RouteDefinition> routes = RouteFactory.createRoute(CustomExecutorRoute.class.getName(), context, null); context.addRouteDefinitions(routes); context.start(); Assert.assertEquals(false, CustomExecutorRoute.customPool.isShutdown()); context.stop(); Assert.assertEquals(true, CustomExecutorRoute.customPool.isShutdown()); }