org.apache.camel.model.SplitDefinition Java Examples

The following examples show how to use org.apache.camel.model.SplitDefinition. 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: IntegrationRouteBuilderTest.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Test
public void testIntegrationRouteBuilder() throws Exception {
    String configurationLocation = "classpath:syndesis/integration/integration.json";

    IntegrationRouteBuilder routeBuilder = new IntegrationRouteBuilder(configurationLocation, Resources.loadServices(IntegrationStepHandler.class), policyFactories);

    // initialize routes
    routeBuilder.configure();

    // Dump routes as XML for troubleshooting
    dumpRoutes(new DefaultCamelContext(), routeBuilder.getRouteCollection());

    RoutesDefinition routes = routeBuilder.getRouteCollection();

    assertThat(routes.getRoutes()).hasSize(1);

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

    assertThat(route.getRoutePolicies()).hasSize(1);

    assertThat(route.getInput()).isNotNull();
    assertThat(route.getInput()).hasFieldOrPropertyWithValue("uri", "direct:expression");
    assertThat(route.getOutputs()).hasSize(2);
    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(3);
    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, 2).getOutputs()).hasSize(3);
    assertThat(getOutput(route, 1, 2, 0)).isInstanceOf(SetHeaderDefinition.class);
    assertThat(getOutput(route, 1, 2, 1)).isInstanceOf(ToDefinition.class);
    assertThat(getOutput(route, 1, 2, 1)).hasFieldOrPropertyWithValue("uri", "mock:expression");
    assertThat(getOutput(route, 1, 2, 2)).isInstanceOf(ProcessDefinition.class);
}
 
Example #2
Source File: WeaveByTypeTest.java    From camelinaction2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testWeaveByType() throws Exception {
    RouteDefinition route = context.getRouteDefinition("quotes");
    route.adviceWith(context, new AdviceWithRouteBuilder() {
        @Override
        public void configure() throws Exception {
            // find the splitter and insert the route snippet before it
            weaveByType(SplitDefinition.class)
                .before()
                    .filter(body().contains("Donkey"))
                    .transform(simple("${body},Mules cannot do this"));
        }
    });

    context.start();

    getMockEndpoint("mock:line").expectedBodiesReceived("camel rules", "donkey is bad", "mules cannot do this");
    getMockEndpoint("mock:combined").expectedMessageCount(1);
    getMockEndpoint("mock:combined").message(0).body().isInstanceOf(List.class);

    template.sendBody("seda:quotes", "Camel Rules,Donkey is Bad");

    assertMockEndpointsSatisfied();

    resetMocks();

    // try again without the donkeys

    getMockEndpoint("mock:line").expectedBodiesReceived("beer is good", "whiskey is better");
    getMockEndpoint("mock:combined").expectedMessageCount(1);
    getMockEndpoint("mock:combined").message(0).body().isInstanceOf(List.class);

    template.sendBody("seda:quotes", "Beer is good,Whiskey is better");

    assertMockEndpointsSatisfied();
}
 
Example #3
Source File: IntegrationRouteBuilderTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Test
public void testMultiFlowIntegrationRouteBuilder() throws Exception {
    String configurationLocation = "classpath:syndesis/integration/multi-flow-integration.json";

    IntegrationRouteBuilder routeBuilder = new IntegrationRouteBuilder(configurationLocation, Resources.loadServices(IntegrationStepHandler.class), policyFactories);

    // initialize routes
    routeBuilder.configure();

    // Dump routes as XML for troubleshooting
    dumpRoutes(new DefaultCamelContext(), routeBuilder.getRouteCollection());

    RoutesDefinition routes = routeBuilder.getRouteCollection();

    assertThat(routes.getRoutes()).hasSize(3);

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

    assertThat(primaryRoute.getRoutePolicies()).hasSize(1);
    assertThat(primaryRoute.getRoutePolicies().get(0)).isInstanceOf(IntegrationActivityTrackingPolicy.class);

    assertThat(primaryRoute.getInput()).isNotNull();
    assertThat(primaryRoute.getInput()).hasFieldOrPropertyWithValue("uri", "direct:expression");
    assertThat(primaryRoute.getOutputs()).hasSize(2);
    assertThat(getOutput(primaryRoute, 0)).isInstanceOf(PipelineDefinition.class);
    assertThat(getOutput(primaryRoute, 0).getOutputs()).hasSize(2);
    assertThat(getOutput(primaryRoute, 0).getOutputs().get(0)).isInstanceOf(SetHeaderDefinition.class);
    assertThat(getOutput(primaryRoute, 0).getOutputs().get(1)).isInstanceOf(SetHeaderDefinition.class);
    assertThat(getOutput(primaryRoute, 1)).isInstanceOf(SplitDefinition.class);
    assertThat(getOutput(primaryRoute, 1).getOutputs()).hasSize(5);
    assertThat(getOutput(primaryRoute, 1, 0)).isInstanceOf(SetHeaderDefinition.class);
    assertThat(getOutput(primaryRoute, 1, 1)).isInstanceOf(ProcessDefinition.class);
    assertThat(getOutput(primaryRoute, 1, 2)).isInstanceOf(PipelineDefinition.class);
    assertThat(getOutput(primaryRoute, 1, 2).getOutputs()).hasSize(2);
    assertThat(getOutput(primaryRoute, 1, 2, 0)).isInstanceOf(SetHeaderDefinition.class);
    assertThat(getOutput(primaryRoute, 1, 2, 1)).isInstanceOf(LogDefinition.class);
    assertThat(getOutput(primaryRoute, 1, 2, 1)).hasFieldOrPropertyWithValue("message", "Body: [${bean:bodyLogger}] Before");
    assertThat(getOutput(primaryRoute, 1, 3)).isInstanceOf(PipelineDefinition.class);
    assertThat(getOutput(primaryRoute, 1, 3).getOutputs()).hasSize(3);
    assertThat(getOutput(primaryRoute, 1, 3, 0)).isInstanceOf(SetHeaderDefinition.class);
    assertThat(getOutput(primaryRoute, 1, 3, 1)).isInstanceOf(ChoiceDefinition.class);
    assertThat(getOutput(primaryRoute, 1, 3, 2)).isInstanceOf(ProcessDefinition.class);
    assertThat(getOutput(primaryRoute, 1, 4)).isInstanceOf(PipelineDefinition.class);
    assertThat(getOutput(primaryRoute, 1, 4).getOutputs()).hasSize(2);
    assertThat(getOutput(primaryRoute, 1, 4, 0)).isInstanceOf(SetHeaderDefinition.class);
    assertThat(getOutput(primaryRoute, 1, 4, 1)).isInstanceOf(LogDefinition.class);
    assertThat(getOutput(primaryRoute, 1, 4, 1)).hasFieldOrPropertyWithValue("message", "Body: [${bean:bodyLogger}] Finished");

    RouteDefinition conditionalRoute = routes.getRoutes().get(1);

    assertThat(conditionalRoute.getRoutePolicies()).hasSize(1);
    assertThat(conditionalRoute.getRoutePolicies().get(0)).isInstanceOf(FlowActivityTrackingPolicy.class);

    assertThat(conditionalRoute.getInput()).isNotNull();
    assertThat(conditionalRoute.getInput()).hasFieldOrPropertyWithValue("uri", "direct");
    assertThat(conditionalRoute.getOutputs()).hasSize(5);
    assertThat(getOutput(conditionalRoute, 0)).isInstanceOf(PipelineDefinition.class);
    assertThat(getOutput(conditionalRoute, 0).getOutputs()).hasSize(2);
    assertThat(getOutput(conditionalRoute, 0).getOutputs().get(0)).isInstanceOf(SetHeaderDefinition.class);
    assertThat(getOutput(conditionalRoute, 0).getOutputs().get(1)).isInstanceOf(SetHeaderDefinition.class);
    assertThat(getOutput(conditionalRoute, 1)).isInstanceOf(SetHeaderDefinition.class);
    assertThat(getOutput(conditionalRoute, 2)).isInstanceOf(ProcessDefinition.class);
    assertThat(getOutput(conditionalRoute, 3)).isInstanceOf(PipelineDefinition.class);
    assertThat(getOutput(conditionalRoute, 3).getOutputs()).hasSize(2);
    assertThat(getOutput(conditionalRoute, 3, 0)).isInstanceOf(SetHeaderDefinition.class);
    assertThat(getOutput(conditionalRoute, 3, 1)).isInstanceOf(LogDefinition.class);
    assertThat(getOutput(conditionalRoute, 3, 1)).hasFieldOrPropertyWithValue("message", "Body: [${bean:bodyLogger}] Found <Play>");
    assertThat(getOutput(conditionalRoute, 4)).isInstanceOf(PipelineDefinition.class);
    assertThat(getOutput(conditionalRoute, 4).getOutputs()).hasSize(3);
    assertThat(getOutput(conditionalRoute, 4, 0)).isInstanceOf(SetHeaderDefinition.class);
    assertThat(getOutput(conditionalRoute, 4, 1)).isInstanceOf(ToDefinition.class);
    assertThat(getOutput(conditionalRoute, 4, 1)).hasFieldOrPropertyWithValue("uri", "bean:io.syndesis.connector.flow.NoOpBean?method=process");
    assertThat(getOutput(conditionalRoute, 4, 2)).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 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 #5
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);
}