org.apache.camel.model.PipelineDefinition Java Examples

The following examples show how to use org.apache.camel.model.PipelineDefinition. 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: IntegrationRouteBuilder.java    From syndesis with Apache License 2.0 6 votes vote down vote up
private ProcessorDefinition<?> closeParent(final ProcessorDefinition<?> parent, final String stepId,
    final BiFunction<ProcessorDefinition<?>, String, ProcessorDefinition<?>> fallback) {
    ProcessorDefinition<?> definition;

    if (parent instanceof PipelineDefinition) {
        definition = captureOutMessage(parent, stepId);
        definition = parent.end();
    } else if (parent instanceof ExpressionNode) {
        definition = captureOutMessage(parent, stepId);
        definition = parent.endParent();
    } else {
        definition = fallback.apply(parent, stepId);
    }

    return definition;
}
 
Example #2
Source File: IntegrationRouteBuilder.java    From syndesis with Apache License 2.0 6 votes vote down vote up
/**
 * Adds out message capture message processor to save current message to memory for later usage.
 */
private ProcessorDefinition<?> captureOutMessage(final ProcessorDefinition<?> parent, String stepId) {
    ProcessorDefinition<?> definition;
    if (parent instanceof PipelineDefinition &&
            ObjectHelper.isNotEmpty(parent.getOutputs())) {
        ProcessorDefinition<?> lastInPipeline = parent.getOutputs().get(parent.getOutputs().size() - 1);
        if (lastInPipeline instanceof LogDefinition) {
            // skip our message capture for log steps
            return parent;
        }
    } else {
        // not in a pipeline so set the step id header to be sure it is there
        definition = parent.setHeader(IntegrationLoggingConstants.STEP_ID, constant(stepId));
    }

    definition = parent.process(OutMessageCaptureProcessor.INSTANCE)
                    .id(String.format("capture-out:%s", stepId));
    return definition;
}
 
Example #3
Source File: TracingInterceptStrategy.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@Override
public Processor wrapProcessorInInterceptors(CamelContext context, NamedNode definition, Processor target, Processor nextTarget) throws Exception {
    if (definition instanceof PipelineDefinition) {
        final String id = definition.getId();
        if (ObjectHelper.isEmpty(id)) {
            return target;
        }

        final String stepId = StringHelper.after(id, "step:");
        if (ObjectHelper.isEmpty(stepId)) {
            return target;
        }

        return new EventProcessor(target, stepId);
    }
    return target;
}
 
Example #4
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 #5
Source File: PipelineStepParser.java    From camel-k-runtime with Apache License 2.0 5 votes vote down vote up
@Override
public ProcessorDefinition<?> toProcessor(Context context) {
    final Definition definition = context.node(Definition.class);
    final PipelineDefinition answer = new PipelineDefinition();

    StepParserSupport.notNull(definition.steps, "steps");

    return StepParserSupport.convertSteps(
        context,
        answer,
        definition.steps
    );
}
 
Example #6
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 #7
Source File: ExtensionStepHandlerTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Test
public void testStepExtensionStepHandler() throws Exception {
    final DefaultCamelContext context = new DefaultCamelContext();

    try {
        final RouteBuilder routeBuilder = newIntegrationRouteBuilder(
            new io.syndesis.common.model.integration.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 io.syndesis.common.model.integration.Step.Builder()
                .id("step-2")
                .stepKind(StepKind.extension)
                .action(new StepAction.Builder()
                    .descriptor(new StepDescriptor.Builder()
                        .kind(StepAction.Kind.STEP)
                        .entrypoint("io.syndesis.integration.runtime.handlers.ExtensionStepHandlerTest$MyStepExtension")
                        .build())
                    .build())
                .putConfiguredProperty("param1", "Val-1")
                .putConfiguredProperty("param2", "Val-2")
                .build(),
            new io.syndesis.common.model.integration.Step.Builder()
                .id("step-3")
                .stepKind(StepKind.endpoint)
                .action(new ConnectorAction.Builder()
                    .descriptor(new ConnectorDescriptor.Builder()
                        .componentScheme("mock")
                        .putConfiguredProperty("name", "result")
                        .build())
                    .build())
                .build()
        );

        // Set up the camel context
        context.addRoutes(routeBuilder);
        context.setAutoStartup(false);
        context.start();

        // Dump routes as XML for troubleshooting
        dumpRoutes(context);

        RouteDefinition route = context.getRouteDefinitions().get(0);
        assertThat(route).isNotNull();
        assertThat(route.getInput()).isNotNull();
        assertThat(route.getInput()).hasFieldOrPropertyWithValue("uri", "direct:start");
        assertThat(route.getOutputs()).hasSize(5);
        assertThat(route.getOutputs().get(0)).isInstanceOf(PipelineDefinition.class);
        assertThat(route.getOutputs().get(0).getOutputs()).hasSize(2);
        assertThat(route.getOutputs().get(0).getOutputs().get(0)).isInstanceOf(SetHeaderDefinition.class);
        assertThat(route.getOutputs().get(0).getOutputs().get(1)).isInstanceOf(SetHeaderDefinition.class);
        assertThat(route.getOutputs().get(1)).isInstanceOf(SetHeaderDefinition.class);
        assertThat(route.getOutputs().get(2)).isInstanceOf(ProcessDefinition.class);
        assertThat(route.getOutputs().get(3)).isInstanceOf(PipelineDefinition.class);
        assertThat(route.getOutputs().get(3).getOutputs()).hasSize(4);
        assertThat(route.getOutputs().get(3).getOutputs().get(0)).isInstanceOf(SetHeaderDefinition.class);
        assertThat(route.getOutputs().get(3).getOutputs().get(1)).isInstanceOf(SetHeaderDefinition.class);
        assertThat(route.getOutputs().get(3).getOutputs().get(1)).hasFieldOrPropertyWithValue("name", "param1");
        assertThat(SetHeaderDefinition.class.cast(route.getOutputs().get(3).getOutputs().get(1)).getExpression()).hasFieldOrPropertyWithValue("expression", "Val-1");
        assertThat(route.getOutputs().get(3).getOutputs().get(2)).isInstanceOf(SetHeaderDefinition.class);
        assertThat(route.getOutputs().get(3).getOutputs().get(2)).hasFieldOrPropertyWithValue("name", "param2");
        assertThat(SetHeaderDefinition.class.cast(route.getOutputs().get(3).getOutputs().get(2)).getExpression()).hasFieldOrPropertyWithValue("expression", "Val-2");
        assertThat(route.getOutputs().get(3).getOutputs().get(3)).isInstanceOf(ProcessDefinition.class);
        assertThat(route.getOutputs().get(4)).isInstanceOf(PipelineDefinition.class);
        assertThat(route.getOutputs().get(4).getOutputs()).hasSize(3);
        assertThat(route.getOutputs().get(4).getOutputs().get(0)).isInstanceOf(SetHeaderDefinition.class);
        assertThat(route.getOutputs().get(4).getOutputs().get(1)).isInstanceOf(ToDefinition.class);
        assertThat(route.getOutputs().get(4).getOutputs().get(1)).hasFieldOrPropertyWithValue("uri", "mock:result");
        assertThat(route.getOutputs().get(4).getOutputs().get(2)).isInstanceOf(ProcessDefinition.class);
    } finally {
        context.stop();
    }
}
 
Example #8
Source File: ExtensionStepHandlerTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Test
public void testBeanExtensionStepHandler() throws Exception {
    final DefaultCamelContext context = new DefaultCamelContext();

    try {
        final RouteBuilder routeBuilder = newIntegrationRouteBuilder(
            new io.syndesis.common.model.integration.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 io.syndesis.common.model.integration.Step.Builder()
                .id("step-2")
                .stepKind(StepKind.extension)
                .action(new StepAction.Builder()
                    .descriptor(new StepDescriptor.Builder()
                        .kind(StepAction.Kind.BEAN)
                        .entrypoint("io.syndesis.integration.runtime.handlers.ExtensionStepHandlerTest$MyExtension::action")
                        .build())
                    .build())
                .putConfiguredProperty("param1", "Val-1")
                .putConfiguredProperty("param2", "Val-2")
                .build(),
            new io.syndesis.common.model.integration.Step.Builder()
                .id("step-3")
                .stepKind(StepKind.endpoint)
                .action(new ConnectorAction.Builder()
                    .descriptor(new ConnectorDescriptor.Builder()
                        .componentScheme("mock")
                        .putConfiguredProperty("name", "result")
                        .build())
                    .build())
                .build()
        );

        // Set up the camel context
        context.addRoutes(routeBuilder);
        context.setAutoStartup(false);
        context.start();

        // Dump routes as XML for troubleshooting
        dumpRoutes(context);

        List<RouteDefinition> routes = context.getRouteDefinitions();
        assertThat(routes).hasSize(1);

        RouteDefinition route = context.getRouteDefinitions().get(0);
        assertThat(route).isNotNull();
        assertThat(route.getInput()).isNotNull();
        assertThat(route.getInput()).hasFieldOrPropertyWithValue("uri", "direct:start");
        assertThat(route.getOutputs()).hasSize(5);
        assertThat(route.getOutputs().get(0)).isInstanceOf(PipelineDefinition.class);
        assertThat(route.getOutputs().get(0).getOutputs()).hasSize(2);
        assertThat(route.getOutputs().get(0).getOutputs().get(0)).isInstanceOf(SetHeaderDefinition.class);
        assertThat(route.getOutputs().get(0).getOutputs().get(1)).isInstanceOf(SetHeaderDefinition.class);
        assertThat(route.getOutputs().get(1)).isInstanceOf(SetHeaderDefinition.class);
        assertThat(route.getOutputs().get(2)).isInstanceOf(ProcessDefinition.class);
        assertThat(route.getOutputs().get(3)).isInstanceOf(PipelineDefinition.class);
        assertThat(route.getOutputs().get(3).getOutputs()).hasSize(3);
        assertThat(route.getOutputs().get(3).getOutputs().get(0)).isInstanceOf(SetHeaderDefinition.class);
        assertThat(route.getOutputs().get(3).getOutputs().get(1)).isInstanceOf(ToDefinition.class);
        assertThat(route.getOutputs().get(3).getOutputs().get(1)).hasFieldOrPropertyWithValue(
            "uri",
            "class:io.syndesis.integration.runtime.handlers.ExtensionStepHandlerTest$MyExtension?method=action&bean.param1=Val-1&bean.param2=Val-2"
        );
        assertThat(route.getOutputs().get(3).getOutputs().get(2)).isInstanceOf(ProcessDefinition.class);
        assertThat(route.getOutputs().get(4)).isInstanceOf(PipelineDefinition.class);
        assertThat(route.getOutputs().get(4).getOutputs()).hasSize(3);
        assertThat(route.getOutputs().get(4).getOutputs().get(0)).isInstanceOf(SetHeaderDefinition.class);
        assertThat(route.getOutputs().get(4).getOutputs().get(1)).isInstanceOf(ToDefinition.class);
        assertThat(route.getOutputs().get(4).getOutputs().get(1)).hasFieldOrPropertyWithValue("uri", "mock:result");
        assertThat(route.getOutputs().get(4).getOutputs().get(2)).isInstanceOf(ProcessDefinition.class);
    } finally {
        context.stop();
    }
}
 
Example #9
Source File: ExtensionStepHandlerTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Test
public void testEndpointExtensionStepHandler() throws Exception {
    final DefaultCamelContext context = new DefaultCamelContext();

    try {
        final RouteBuilder routeBuilder = newIntegrationRouteBuilder(
            new io.syndesis.common.model.integration.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 io.syndesis.common.model.integration.Step.Builder()
                .id("step-2")
                .stepKind(StepKind.extension)
                .action(new StepAction.Builder()
                    .descriptor(new StepDescriptor.Builder()
                        .kind(StepAction.Kind.ENDPOINT)
                        .entrypoint("log:myLog")
                        .build())
                    .build())
                .putConfiguredProperty("Property-1", "Val-1")
                .putConfiguredProperty("Property-2", "Val-2")
                .build(),
            new io.syndesis.common.model.integration.Step.Builder()
                .id("step-3")
                .stepKind(StepKind.endpoint)
                .action(new ConnectorAction.Builder()
                    .descriptor(new ConnectorDescriptor.Builder()
                        .componentScheme("mock")
                        .putConfiguredProperty("name", "result")
                        .build())
                    .build())
                .build()
        );

        // Set up the camel context
        context.addRoutes(routeBuilder);
        context.setAutoStartup(false);
        context.start();

        // Dump routes as XML for troubleshooting
        dumpRoutes(context);

        List<RouteDefinition> routes = context.getRouteDefinitions();
        assertThat(routes).hasSize(1);

        RouteDefinition route = context.getRouteDefinitions().get(0);
        assertThat(route).isNotNull();
        assertThat(route.getInput()).isNotNull();
        assertThat(route.getInput()).hasFieldOrPropertyWithValue("uri", "direct:start");
        assertThat(route.getOutputs()).hasSize(5);
        assertThat(route.getOutputs().get(0)).isInstanceOf(PipelineDefinition.class);
        assertThat(route.getOutputs().get(0).getOutputs()).hasSize(2);
        assertThat(route.getOutputs().get(0).getOutputs().get(0)).isInstanceOf(SetHeaderDefinition.class);
        assertThat(route.getOutputs().get(0).getOutputs().get(1)).isInstanceOf(SetHeaderDefinition.class);
        assertThat(route.getOutputs().get(1)).isInstanceOf(SetHeaderDefinition.class);
        assertThat(route.getOutputs().get(2)).isInstanceOf(ProcessDefinition.class);
        assertThat(route.getOutputs().get(3)).isInstanceOf(PipelineDefinition.class);
        assertThat(route.getOutputs().get(3).getOutputs()).hasSize(5);
        assertThat(route.getOutputs().get(3).getOutputs().get(0)).isInstanceOf(SetHeaderDefinition.class);
        assertThat(route.getOutputs().get(3).getOutputs().get(1)).isInstanceOf(SetHeaderDefinition.class);
        assertThat(route.getOutputs().get(3).getOutputs().get(1)).hasFieldOrPropertyWithValue("name", "Property-1");
        assertThat(SetHeaderDefinition.class.cast(route.getOutputs().get(3).getOutputs().get(1)).getExpression()).hasFieldOrPropertyWithValue("expression", "Val-1");
        assertThat(route.getOutputs().get(3).getOutputs().get(2)).isInstanceOf(SetHeaderDefinition.class);
        assertThat(route.getOutputs().get(3).getOutputs().get(2)).hasFieldOrPropertyWithValue("name", "Property-2");
        assertThat(SetHeaderDefinition.class.cast(route.getOutputs().get(3).getOutputs().get(2)).getExpression()).hasFieldOrPropertyWithValue("expression", "Val-2");
        assertThat(route.getOutputs().get(3).getOutputs().get(3)).isInstanceOf(ToDefinition.class);
        assertThat(route.getOutputs().get(3).getOutputs().get(3)).hasFieldOrPropertyWithValue(
            "uri",
            "log:myLog"
        );
        assertThat(route.getOutputs().get(3).getOutputs().get(4)).isInstanceOf(ProcessDefinition.class);
        assertThat(route.getOutputs().get(4)).isInstanceOf(PipelineDefinition.class);
        assertThat(route.getOutputs().get(4).getOutputs()).hasSize(3);
        assertThat(route.getOutputs().get(4).getOutputs().get(0)).isInstanceOf(SetHeaderDefinition.class);
        assertThat(route.getOutputs().get(4).getOutputs().get(1)).isInstanceOf(ToDefinition.class);
        assertThat(route.getOutputs().get(4).getOutputs().get(1)).hasFieldOrPropertyWithValue("uri", "mock:result");
        assertThat(route.getOutputs().get(4).getOutputs().get(2)).isInstanceOf(ProcessDefinition.class);
    } finally {
        context.stop();
    }
}
 
Example #10
Source File: DataMapperStepHandlerTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Test
public void testJsonTypeProcessorsSkip() throws Exception {
    final DefaultCamelContext context = new DefaultCamelContext();

    try {
        final RouteBuilder routeBuilder = newIntegrationRouteBuilder(getTestSteps("{" +
                                "\"AtlasMapping\":{" +
                                    "\"dataSource\":[" +
                                        "{\"jsonType\":\"io.atlasmap.v2.DataSource\",\"id\":\"source\",\"uri\":\"atlas:java?className=twitter4j.Status\",\"dataSourceType\":\"SOURCE\"}," +
                                        "{\"jsonType\":\"io.atlasmap.v2.DataSource\",\"id\":\"target\",\"uri\":\"atlas:java?className=io.syndesis.connector.gmail.GmailMessageModel\",\"dataSourceType\":\"TARGET\",\"template\":null}" +
                                    "]," +
                                    "\"mappings\":{}" +
                                    "}" +
                                "}"));

        // Set up the camel context
        context.addRoutes(routeBuilder);
        context.start();

        // Dump routes as XML for troubleshooting
        dumpRoutes(context);

        List<RouteDefinition> routes = context.getRouteDefinitions();
        assertThat(routes).hasSize(1);

        RouteDefinition route = context.getRouteDefinitions().get(0);
        assertThat(route).isNotNull();
        assertThat(route.getInput()).isNotNull();
        assertThat(route.getInput()).hasFieldOrPropertyWithValue("uri", "direct:start");
        assertThat(route.getOutputs()).hasSize(5);
        assertThat(route.getOutputs().get(0)).isInstanceOf(PipelineDefinition.class);
        assertThat(route.getOutputs().get(0).getOutputs()).hasSize(2);
        assertThat(route.getOutputs().get(0).getOutputs().get(0)).isInstanceOf(SetHeaderDefinition.class);
        assertThat(route.getOutputs().get(0).getOutputs().get(1)).isInstanceOf(SetHeaderDefinition.class);
        assertThat(route.getOutputs().get(1)).isInstanceOf(SetHeaderDefinition.class);
        assertThat(route.getOutputs().get(2)).isInstanceOf(ProcessDefinition.class);

        // Atlas
        assertThat(route.getOutputs().get(3)).isInstanceOf(PipelineDefinition.class);
        assertThat(route.getOutputs().get(3).getOutputs()).hasSize(3);
        assertThat(route.getOutputs().get(3).getOutputs().get(0)).isInstanceOf(SetHeaderDefinition.class);
        assertThat(route.getOutputs().get(3).getOutputs().get(1)).isInstanceOf(ToDefinition.class);
        assertThat(route.getOutputs().get(3).getOutputs().get(1)).hasFieldOrPropertyWithValue(
                "uri",
                "atlas:mapping-flow-0-step-1.json?encoding=UTF-8&sourceMapName=" + OutMessageCaptureProcessor.CAPTURED_OUT_MESSAGES_MAP
        );
        assertThat(route.getOutputs().get(3).getOutputs().get(2)).isInstanceOf(ProcessDefinition.class);
        assertThat(route.getOutputs().get(4)).isInstanceOf(PipelineDefinition.class);
        assertThat(route.getOutputs().get(4).getOutputs()).hasSize(3);
        assertThat(route.getOutputs().get(4).getOutputs().get(0)).isInstanceOf(SetHeaderDefinition.class);
        assertThat(route.getOutputs().get(4).getOutputs().get(1)).isInstanceOf(ToDefinition.class);
        assertThat(route.getOutputs().get(4).getOutputs().get(1)).hasFieldOrPropertyWithValue("uri", "mock:result");
        assertThat(route.getOutputs().get(4).getOutputs().get(2)).isInstanceOf(ProcessDefinition.class);
    } finally {
        context.stop();
    }
}
 
Example #11
Source File: DataMapperStepHandlerTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Test
public void testJsonTypeProcessors() throws Exception {
    final DefaultCamelContext context = new DefaultCamelContext();

    try {
        final RouteBuilder routeBuilder = newIntegrationRouteBuilder(getTestSteps("{" +
                                "\"AtlasMapping\":{" +
                                    "\"dataSource\":[" +
                                        "{\"jsonType\":\"" + DataMapperStepHandler.ATLASMAP_JSON_DATA_SOURCE + "\",\"id\":\"source\",\"uri\":\"atlas:json:source\",\"dataSourceType\":\"SOURCE\"}," +
                                        "{\"jsonType\":\"" + DataMapperStepHandler.ATLASMAP_JSON_DATA_SOURCE + "\",\"id\":\"target\",\"uri\":\"atlas:json:target\",\"dataSourceType\":\"TARGET\",\"template\":null}" +
                                    "]," +
                                    "\"mappings\":{}" +
                                    "}" +
                                "}"));

        // Set up the camel context
        context.addRoutes(routeBuilder);
        context.start();

        // Dump routes as XML for troubleshooting
        dumpRoutes(context);

        List<RouteDefinition> routes = context.getRouteDefinitions();
        assertThat(routes).hasSize(1);

        RouteDefinition route = context.getRouteDefinitions().get(0);
        assertThat(route).isNotNull();
        assertThat(route.getInput()).isNotNull();
        assertThat(route.getInput()).hasFieldOrPropertyWithValue("uri", "direct:start");
        assertThat(route.getOutputs()).hasSize(5);
        assertThat(route.getOutputs().get(0)).isInstanceOf(PipelineDefinition.class);
        assertThat(route.getOutputs().get(0).getOutputs()).hasSize(2);
        assertThat(route.getOutputs().get(0).getOutputs().get(0)).isInstanceOf(SetHeaderDefinition.class);
        assertThat(route.getOutputs().get(0).getOutputs().get(1)).isInstanceOf(SetHeaderDefinition.class);
        assertThat(route.getOutputs().get(1)).isInstanceOf(SetHeaderDefinition.class);
        assertThat(route.getOutputs().get(2)).isInstanceOf(ProcessDefinition.class);

        // Atlas
        assertThat(route.getOutputs().get(3)).isInstanceOf(PipelineDefinition.class);
        assertThat(route.getOutputs().get(3).getOutputs()).hasSize(5);
        assertThat(route.getOutputs().get(3).getOutputs().get(0)).isInstanceOf(SetHeaderDefinition.class);
        assertThat(route.getOutputs().get(3).getOutputs().get(1)).isInstanceOf(ProcessDefinition.class);
        assertThat(route.getOutputs().get(3).getOutputs().get(2)).isInstanceOf(ToDefinition.class);
        assertThat(route.getOutputs().get(3).getOutputs().get(2)).hasFieldOrPropertyWithValue(
                "uri",
                "atlas:mapping-flow-0-step-1.json?encoding=UTF-8&sourceMapName=" + OutMessageCaptureProcessor.CAPTURED_OUT_MESSAGES_MAP
        );
        assertThat(route.getOutputs().get(3).getOutputs().get(3)).isInstanceOf(ProcessDefinition.class);
        assertThat(route.getOutputs().get(3).getOutputs().get(4)).isInstanceOf(ProcessDefinition.class);
        assertThat(route.getOutputs().get(4)).isInstanceOf(PipelineDefinition.class);
        assertThat(route.getOutputs().get(4).getOutputs()).hasSize(3);
        assertThat(route.getOutputs().get(4).getOutputs().get(0)).isInstanceOf(SetHeaderDefinition.class);
        assertThat(route.getOutputs().get(4).getOutputs().get(1)).isInstanceOf(ToDefinition.class);
        assertThat(route.getOutputs().get(4).getOutputs().get(1)).hasFieldOrPropertyWithValue("uri", "mock:result");
        assertThat(route.getOutputs().get(4).getOutputs().get(2)).isInstanceOf(ProcessDefinition.class);
    } finally {
        context.stop();
    }
}
 
Example #12
Source File: DataMapperStepHandlerTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Test
public void testDataMapperStep() throws Exception {
    final DefaultCamelContext context = new DefaultCamelContext();

    try {
        final RouteBuilder routeBuilder = newIntegrationRouteBuilder(getTestSteps());

        // Set up the camel context
        context.addRoutes(routeBuilder);
        context.start();

        // Dump routes as XML for troubleshooting
        dumpRoutes(context);

        List<RouteDefinition> routes = context.getRouteDefinitions();
        assertThat(routes).hasSize(1);

        RouteDefinition route = context.getRouteDefinitions().get(0);
        assertThat(route).isNotNull();
        assertThat(route.getInput()).isNotNull();
        assertThat(route.getInput()).hasFieldOrPropertyWithValue("uri", "direct:start");
        assertThat(route.getOutputs()).hasSize(5);
        assertThat(route.getOutputs().get(0)).isInstanceOf(PipelineDefinition.class);
        assertThat(route.getOutputs().get(0).getOutputs()).hasSize(2);
        assertThat(route.getOutputs().get(0).getOutputs().get(0)).isInstanceOf(SetHeaderDefinition.class);
        assertThat(route.getOutputs().get(0).getOutputs().get(1)).isInstanceOf(SetHeaderDefinition.class);
        assertThat(route.getOutputs().get(1)).isInstanceOf(SetHeaderDefinition.class);
        assertThat(route.getOutputs().get(2)).isInstanceOf(ProcessDefinition.class);

        // Atlas
        assertThat(route.getOutputs().get(3)).isInstanceOf(PipelineDefinition.class);
        assertThat(route.getOutputs().get(3).getOutputs()).hasSize(3);
        assertThat(route.getOutputs().get(3).getOutputs().get(0)).isInstanceOf(SetHeaderDefinition.class);
        assertThat(route.getOutputs().get(3).getOutputs().get(1)).isInstanceOf(ToDefinition.class);
        assertThat(route.getOutputs().get(3).getOutputs().get(1)).hasFieldOrPropertyWithValue(
            "uri",
            "atlas:mapping-flow-0-step-1.json?encoding=UTF-8&sourceMapName=" + OutMessageCaptureProcessor.CAPTURED_OUT_MESSAGES_MAP
        );

        assertThat(route.getOutputs().get(3).getOutputs().get(2)).isInstanceOf(ProcessDefinition.class);
        assertThat(route.getOutputs().get(4)).isInstanceOf(PipelineDefinition.class);
        assertThat(route.getOutputs().get(4).getOutputs()).hasSize(3);
        assertThat(route.getOutputs().get(4).getOutputs().get(0)).isInstanceOf(SetHeaderDefinition.class);
        assertThat(route.getOutputs().get(4).getOutputs().get(1)).isInstanceOf(ToDefinition.class);
        assertThat(route.getOutputs().get(4).getOutputs().get(1)).hasFieldOrPropertyWithValue("uri", "mock:result");
        assertThat(route.getOutputs().get(4).getOutputs().get(2)).isInstanceOf(ProcessDefinition.class);
    } finally {
        context.stop();
    }
}
 
Example #13
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);
}
 
Example #14
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 #15
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 #16
Source File: IntegrationRouteBuilder.java    From syndesis with Apache License 2.0 4 votes vote down vote up
private ProcessorDefinition<PipelineDefinition> createPipeline(ProcessorDefinition<?> parent, String stepId) {
    return parent.pipeline()
        .id(getStepId(stepId))
        .setHeader(IntegrationLoggingConstants.STEP_ID, constant(stepId));
}
 
Example #17
Source File: ActivityTrackingInterceptStrategy.java    From syndesis with Apache License 2.0 4 votes vote down vote up
/**
 * Activity tracking is only active for pipelines.
 */
private static boolean shouldTrack(NamedNode definition) {
    return definition instanceof PipelineDefinition &&
            ObjectHelper.isNotEmpty(((PipelineDefinition) definition).getOutputs());
}