Java Code Examples for org.apache.camel.builder.RouteBuilder#getRouteCollection()

The following examples show how to use org.apache.camel.builder.RouteBuilder#getRouteCollection() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IntegrationRouteLoaderTest.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@Test
public void integrationRouteLoaderTest() throws Exception {
    IntegrationRouteLoader irl = new IntegrationRouteLoader();
    TestRuntime runtime = new TestRuntime();

    irl.load(runtime,
        Sources.fromURI("classpath:/syndesis/integration/integration.syndesis?language=syndesis"));

    assertThat(runtime.builders).hasSize(1);
    final RoutesBuilder routeBuilder = runtime.builders.get(0);
    assertThat(routeBuilder).isInstanceOf(RouteBuilder.class);

    RouteBuilder rb = (RouteBuilder) routeBuilder;
    // initialize routes
    rb.configure();
    final RoutesDefinition routeCollection = rb.getRouteCollection();
    final List<RouteDefinition> routes = routeCollection.getRoutes();
    assertThat(routes).hasSize(1);
    final RouteDefinition route = routes.get(0);
    final FromDefinition input = route.getInput();
    assertThat(input).isNotNull();
    assertThat(input.getEndpointUri()).isEqualTo("direct:expression");
}
 
Example 2
Source File: IntegrationRouteTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Test
public void integrationWithSchedulerTest() throws Exception {
    final RouteBuilder routeBuilder = new IntegrationRouteBuilder("", Resources.loadServices(IntegrationStepHandler.class)) {
        @Override
        protected Integration loadIntegration() {
            Integration integration = newIntegration(
                new Step.Builder()
                    .id("step-1")
                    .stepKind(StepKind.endpoint)
                    .action(new ConnectorAction.Builder()
                        .descriptor(new ConnectorDescriptor.Builder()
                            .componentScheme("log")
                            .putConfiguredProperty("loggerName", "timer")
                            .build())
                        .build())
                    .build(),
                new Step.Builder()
                    .id("step-2")
                    .stepKind(StepKind.endpoint)
                    .action(new ConnectorAction.Builder()
                        .descriptor(new ConnectorDescriptor.Builder()
                            .componentScheme("mock")
                            .putConfiguredProperty("name", "timer")
                            .build())
                        .build())
                    .build());

            final Flow flow = integration.getFlows().get(0);
            final Flow flowWithScheduler = flow.builder()
                .scheduler(new Scheduler.Builder()
                    .type(Scheduler.Type.timer)
                    .expression("1s")
                    .build())
                .build();

            return new Integration.Builder()
                .createFrom(integration)
                .flows(singleton(flowWithScheduler))
                .build();
        }
    };

    // initialize routes
    routeBuilder.configure();

    dumpRoutes(new DefaultCamelContext(), routeBuilder.getRouteCollection());

    RoutesDefinition routes = routeBuilder.getRouteCollection();
    assertThat(routes.getRoutes()).hasSize(1);

    RouteDefinition route = routes.getRoutes().get(0);

    // Timer
    assertThat(route.getInput()).isNotNull();
    assertThat(route.getInput()).hasFieldOrPropertyWithValue("uri", "timer:integration?period=1s");
    assertThat(route.getOutputs()).hasSize(5);
    assertThat(getOutput(route, 0)).isInstanceOf(PipelineDefinition.class);
    assertThat(getOutput(route, 0).getOutputs()).hasSize(2);
    assertThat(getOutput(route, 0, 0)).isInstanceOf(SetHeaderDefinition.class);
    assertThat(getOutput(route, 0, 1)).isInstanceOf(SetHeaderDefinition.class);
    assertThat(getOutput(route, 1)).isInstanceOf(ToDefinition.class);
    assertThat(getOutput(route, 1)).hasFieldOrPropertyWithValue("uri", "log:timer");
    assertThat(getOutput(route, 2)).isInstanceOf(SetHeaderDefinition.class);
    assertThat(getOutput(route, 3)).isInstanceOf(ProcessDefinition.class);
    assertThat(getOutput(route, 4)).isInstanceOf(PipelineDefinition.class);
    assertThat(getOutput(route, 4).getOutputs()).hasSize(3);
    assertThat(getOutput(route, 4, 0)).isInstanceOf(SetHeaderDefinition.class);
    assertThat(getOutput(route, 4, 1)).isInstanceOf(ToDefinition.class);
    assertThat(getOutput(route, 4, 1)).hasFieldOrPropertyWithValue("uri", "mock:timer");
    assertThat(getOutput(route, 4, 2)).isInstanceOf(ProcessDefinition.class);
}
 
Example 3
Source File: IntegrationRouteTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Test
public void integrationWithSplitTest() throws Exception {
    final RouteBuilder routeBuilder = new IntegrationRouteBuilder("", Resources.loadServices(IntegrationStepHandler.class)) {
        @Override
        protected Integration loadIntegration() {
            return newIntegration(
                new Step.Builder()
                    .id("step-1")
                    .stepKind(StepKind.endpoint)
                    .action(new ConnectorAction.Builder()
                        .descriptor(new ConnectorDescriptor.Builder()
                            .componentScheme("direct")
                            .putConfiguredProperty("name", "start")
                            .build())
                        .build())
                    .build(),
                new Step.Builder()
                    .stepKind(StepKind.split)
                    .build(),
                new Step.Builder()
                    .id("step-2")
                    .stepKind(StepKind.endpoint)
                    .action(new ConnectorAction.Builder()
                        .descriptor(new ConnectorDescriptor.Builder()
                            .componentScheme("bean")
                            .putConfiguredProperty("beanName", "io.syndesis.integration.runtime.IntegrationRouteTest.TestConfiguration")
                            .build())
                        .build())
                    .build(),
                new Step.Builder()
                    .id("step-3")
                    .stepKind(StepKind.endpoint)
                    .action(new ConnectorAction.Builder()
                        .descriptor(new ConnectorDescriptor.Builder()
                            .componentScheme("mock")
                            .putConfiguredProperty("name", "result")
                            .build())
                        .build())
                    .build(),
                new Step.Builder()
                        .stepKind(StepKind.aggregate)
                        .build());
        }
    };

    // initialize routes
    routeBuilder.configure();

    dumpRoutes(new DefaultCamelContext(), routeBuilder.getRouteCollection());

    RoutesDefinition routes = routeBuilder.getRouteCollection();
    assertThat(routes.getRoutes()).hasSize(1);

    RouteDefinition route = routes.getRoutes().get(0);

    assertThat(route.getInput()).isNotNull();
    assertThat(route.getInput()).hasFieldOrPropertyWithValue("uri", "direct:start");
    assertThat(route.getOutputs()).hasSize(4);
    assertThat(getOutput(route, 0)).isInstanceOf(PipelineDefinition.class);
    assertThat(getOutput(route, 0).getOutputs()).hasSize(2);
    assertThat(getOutput(route, 0).getOutputs().get(0)).isInstanceOf(SetHeaderDefinition.class);
    assertThat(getOutput(route, 0).getOutputs().get(1)).isInstanceOf(SetHeaderDefinition.class);
    assertThat(getOutput(route, 1)).isInstanceOf(SplitDefinition.class);
    assertThat(getOutput(route, 1).getOutputs()).hasSize(4);
    assertThat(getOutput(route, 1, 0)).isInstanceOf(SetHeaderDefinition.class);
    assertThat(getOutput(route, 1, 1)).isInstanceOf(ProcessDefinition.class);
    assertThat(getOutput(route, 1, 2)).isInstanceOf(PipelineDefinition.class);
    assertThat(getOutput(route, 1, 3)).isInstanceOf(PipelineDefinition.class);
    assertThat(getOutput(route, 2)).isInstanceOf(SetHeaderDefinition.class);
    assertThat(getOutput(route, 3)).isInstanceOf(ProcessDefinition.class);
}
 
Example 4
Source File: IntegrationRouteTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Test
public void integrationWithSchedulerAndSplitTest() throws Exception {
    final RouteBuilder routeBuilder = new IntegrationRouteBuilder("", Resources.loadServices(IntegrationStepHandler.class)) {
        @Override
        protected Integration loadIntegration() {
            Integration integration = newIntegration(
                new Step.Builder()
                    .id("step-1")
                    .stepKind(StepKind.endpoint)
                    .action(new ConnectorAction.Builder()
                        .descriptor(new ConnectorDescriptor.Builder()
                            .componentScheme("log")
                            .putConfiguredProperty("loggerName", "timer")
                            .build())
                        .build())
                    .build(),
                new Step.Builder()
                    .stepKind(StepKind.split)
                    .build(),
                new Step.Builder()
                    .id("step-2")
                    .stepKind(StepKind.endpoint)
                    .action(new ConnectorAction.Builder()
                        .descriptor(new ConnectorDescriptor.Builder()
                            .componentScheme("mock")
                            .putConfiguredProperty("name", "timer")
                            .build())
                        .build())
                    .build(),
                new Step.Builder()
                    .stepKind(StepKind.aggregate)
                    .build());

            final Flow flow = integration.getFlows().get(0);
            final Flow flowWithScheduler = flow.builder()
                .scheduler(new Scheduler.Builder()
                    .type(Scheduler.Type.timer)
                    .expression("1s")
                    .build())
                .build();

            return new Integration.Builder()
                .createFrom(integration)
                .flows(singleton(flowWithScheduler))
                .build();
        }
    };

    // initialize routes
    routeBuilder.configure();

    dumpRoutes(new DefaultCamelContext(), routeBuilder.getRouteCollection());

    RoutesDefinition routes = routeBuilder.getRouteCollection();
    assertThat(routes.getRoutes()).hasSize(1);

    RouteDefinition route = routes.getRoutes().get(0);

    assertThat(route.getInput()).isNotNull();
    assertThat(route.getInput()).hasFieldOrPropertyWithValue("uri", "timer:integration?period=1s");
    assertThat(route.getOutputs()).hasSize(5);
    assertThat(getOutput(route, 0)).isInstanceOf(PipelineDefinition.class);
    assertThat(getOutput(route, 0).getOutputs()).hasSize(2);
    assertThat(getOutput(route, 0, 0)).isInstanceOf(SetHeaderDefinition.class);
    assertThat(getOutput(route, 0, 1)).isInstanceOf(SetHeaderDefinition.class);
    assertThat(getOutput(route, 1)).isInstanceOf(ToDefinition.class);
    assertThat(getOutput(route, 1)).hasFieldOrPropertyWithValue("uri", "log:timer");
    assertThat(getOutput(route, 2)).isInstanceOf(SplitDefinition.class);
    assertThat(getOutput(route, 2).getOutputs()).hasSize(3);
    assertThat(getOutput(route, 2, 0)).isInstanceOf(SetHeaderDefinition.class);
    assertThat(getOutput(route, 2, 1)).isInstanceOf(ProcessDefinition.class);
    assertThat(getOutput(route, 2, 2)).isInstanceOf(PipelineDefinition.class);
    assertThat(getOutput(route, 2, 2).getOutputs()).hasSize(3);
    assertThat(getOutput(route, 2, 2, 0)).isInstanceOf(SetHeaderDefinition.class);
    assertThat(getOutput(route, 2, 2, 1)).isInstanceOf(ToDefinition.class);
    assertThat(getOutput(route, 2, 2, 1)).hasFieldOrPropertyWithValue("uri", "mock:timer");
    assertThat(getOutput(route, 2, 2, 2)).isInstanceOf(ProcessDefinition.class);
    assertThat(getOutput(route, 3)).isInstanceOf(SetHeaderDefinition.class);
    assertThat(getOutput(route, 4)).isInstanceOf(ProcessDefinition.class);
}