Java Code Examples for org.apache.camel.impl.DefaultCamelContext#setUuidGenerator()

The following examples show how to use org.apache.camel.impl.DefaultCamelContext#setUuidGenerator() . 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: AbstractActivityLoggingTest.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@Before
public void before() throws Exception {
    activityEvents = new ArrayList<>();

    activityTracker = items -> {
        try {
            String json = JsonSupport.toJsonObject(items);
            LOGGER.debug(json);
            ActivityEvent event = JsonUtils.reader().forType(ActivityEvent.class).readValue(json);

            activityEvents.add(event);
        } catch (IOException e) {
            LOGGER.warn("Errors during activity tracking", e);
        }
    };

    context = new DefaultCamelContext();
    context.setUuidGenerator(KeyGenerator::createKey);
    context.addLogListener(new IntegrationLoggingListener(activityTracker));
    context.addInterceptStrategy(new ActivityTrackingInterceptStrategy(activityTracker));
    context.addRoutes(createTestRoutes());

    context.start();
}
 
Example 2
Source File: ChoiceStepHandlerTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Test
public void testChoiceStepWithRuleBasedConditions() throws Exception {
    final DefaultCamelContext context = new DefaultCamelContext();

    try {
        final RouteBuilder integrationRoute = newIntegrationRouteBuilder(activityTracker,
                new Step.Builder()
                        .id(START_STEP)
                        .stepKind(StepKind.endpoint)
                        .action(new ConnectorAction.Builder()
                                .descriptor(new ConnectorDescriptor.Builder()
                                        .componentScheme("direct")
                                        .putConfiguredProperty("name", "flow")
                                        .build())
                                .build())
                        .build(),
                new Step.Builder()
                        .id(CHOICE_STEP)
                        .stepKind(StepKind.choice)
                        .putConfiguredProperty("routingScheme", "mock")
                        .putConfiguredProperty("flows", "[" +
                                    "{\"condition\": \"\", \"path\": \"text\", \"op\": \"contains\", \"value\": \"Hello\", \"flow\": \"hello-flow\"}," +
                                    "{\"condition\": \"\", \"path\": \"text\", \"op\": \"contains\", \"value\": \"Bye\", \"flow\": \"bye-flow\"}" +
                                "]")
                        .build(),
                new Step.Builder()
                        .id(MOCK_STEP)
                        .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.setUuidGenerator(KeyGenerator::createKey);
        context.addLogListener(new IntegrationLoggingListener(activityTracker));
        context.addInterceptStrategy(new ActivityTrackingInterceptStrategy(activityTracker));
        context.addRoutes(integrationRoute);

        SimpleRegistry beanRegistry = new SimpleRegistry();
        beanRegistry.bind("bodyLogger", new BodyLogger.Default());
        context.setRegistry(beanRegistry);
        context.start();

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

        final ProducerTemplate template = context.createProducerTemplate();
        final MockEndpoint result = context.getEndpoint("mock:result", MockEndpoint.class);
        final MockEndpoint helloResult = context.getEndpoint("mock:hello-flow", MockEndpoint.class);
        final MockEndpoint byeResult = context.getEndpoint("mock:bye-flow", MockEndpoint.class);

        final List<String> messages = Arrays.asList("{\"text\": \"Hello Camel!\"}", "{\"text\": \"Bye Camel!\"}", "{\"text\": \"And Now for Something Completely Different\"}");

        result.expectedBodiesReceived(messages);
        helloResult.expectedBodiesReceived("{\"text\": \"Hello Camel!\"}");
        byeResult.expectedBodiesReceived("{\"text\": \"Bye Camel!\"}");

        for (String message : messages) {
            template.sendBody("direct:flow", message);
        }

        result.assertIsSatisfied();
        helloResult.assertIsSatisfied();
        byeResult.assertIsSatisfied();

        verify(activityTracker, times(3)).startTracking(any(Exchange.class));
        verifyActivityStepTracking(CHOICE_STEP, 3);
        verifyActivityStepTracking(MOCK_STEP, 3);
        verify(activityTracker, times(3)).finishTracking(any(Exchange.class));

    } finally {
        context.stop();
    }
}
 
Example 3
Source File: FilterStepHandlerTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Test
public void testExpressionFilterStepOnArray() throws Exception {
    final DefaultCamelContext context = new DefaultCamelContext();

    try {
        final RouteBuilder routes = newIntegrationRouteBuilder(activityTracker,
                new Step.Builder()
                        .id(START_STEP)
                        .stepKind(StepKind.endpoint)
                        .action(new ConnectorAction.Builder()
                                .descriptor(new ConnectorDescriptor.Builder()
                                        .componentScheme("direct")
                                        .putConfiguredProperty("name", "start")
                                        .build())
                                .build())
                        .build(),
                new Step.Builder()
                        .id(FILTER_STEP)
                        .stepKind(StepKind.expressionFilter)
                        .putConfiguredProperty("filter", "${body.size()} > 0 && ${body[0].name} == 'James'")
                        .build(),
                new Step.Builder()
                        .id(MOCK_STEP)
                        .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.setUuidGenerator(KeyGenerator::createKey);
        context.addLogListener(new IntegrationLoggingListener(activityTracker));
        context.addInterceptStrategy(new ActivityTrackingInterceptStrategy(activityTracker));
        context.addRoutes(routes);
        context.start();

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

        final List<String> matchingMessages = Collections.singletonList(buildPersonJsonArray("James"));
        final List<String> notMatchingMessages = Arrays.asList(buildPersonJsonArray(),
                                                               buildPersonJsonArray("Jimmi"));
        final ProducerTemplate template = context.createProducerTemplate();
        final MockEndpoint result = context.getEndpoint("mock:result", MockEndpoint.class);

        List<String> allMessages = new ArrayList<>();
        allMessages.addAll(matchingMessages);
        allMessages.addAll(notMatchingMessages);

        result.expectedBodiesReceived(matchingMessages);

        for (Object body : allMessages) {
            template.sendBody("direct:start", body);
        }

        result.assertIsSatisfied();

        verify(activityTracker, times(allMessages.size())).startTracking(any(Exchange.class));
        verifyActivityStepTracking(MOCK_STEP, matchingMessages.size());
        verifyActivityStepTracking(FILTER_STEP, allMessages.size());
        verify(activityTracker, times(allMessages.size())).finishTracking(any(Exchange.class));
    } finally {
        context.stop();
    }
}
 
Example 4
Source File: FilterStepHandlerTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Test
public void testExpressionFilterStep() throws Exception {
    final DefaultCamelContext context = new DefaultCamelContext();

    try {
        final RouteBuilder routes = newIntegrationRouteBuilder(activityTracker,
                new Step.Builder()
                        .id(START_STEP)
                        .stepKind(StepKind.endpoint)
                        .action(new ConnectorAction.Builder()
                                .descriptor(new ConnectorDescriptor.Builder()
                                        .componentScheme("direct")
                                        .putConfiguredProperty("name", "start")
                                        .build())
                                .build())
                        .build(),
                new Step.Builder()
                        .id(FILTER_STEP)
                        .stepKind(StepKind.expressionFilter)
                        .putConfiguredProperty("filter", "${body.name} == 'James'")
                        .build(),
                new Step.Builder()
                        .id(MOCK_STEP)
                        .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.setUuidGenerator(KeyGenerator::createKey);
        context.addLogListener(new IntegrationLoggingListener(activityTracker));
        context.addInterceptStrategy(new ActivityTrackingInterceptStrategy(activityTracker));
        context.addRoutes(routes);
        context.start();

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

        final List<String> matchingMessages = Collections.singletonList(buildPersonJson("James"));
        final List<String> notMatchingMessages = Collections.singletonList(buildPersonJson("Jimmi"));
        final ProducerTemplate template = context.createProducerTemplate();
        final MockEndpoint result = context.getEndpoint("mock:result", MockEndpoint.class);

        List<String> allMessages = new ArrayList<>();
        allMessages.addAll(matchingMessages);
        allMessages.addAll(notMatchingMessages);

        result.expectedBodiesReceived(matchingMessages);

        for (Object body : allMessages) {
            template.sendBody("direct:start", body);
        }

        result.assertIsSatisfied();

        verify(activityTracker, times(allMessages.size())).startTracking(any(Exchange.class));
        verifyActivityStepTracking(MOCK_STEP, matchingMessages.size());
        verifyActivityStepTracking(FILTER_STEP, allMessages.size());
        verify(activityTracker, times(allMessages.size())).finishTracking(any(Exchange.class));
    } finally {
        context.stop();
    }
}
 
Example 5
Source File: FilterStepHandlerTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Test
public void testPlaintextFilterStep() throws Exception {
    final DefaultCamelContext context = new DefaultCamelContext();

    try {
        final RouteBuilder routes = newIntegrationRouteBuilder(activityTracker,
            new Step.Builder()
                .id(START_STEP)
                .stepKind(StepKind.endpoint)
                .action(new ConnectorAction.Builder()
                    .descriptor(new ConnectorDescriptor.Builder()
                        .componentScheme("direct")
                        .putConfiguredProperty("name", "start")
                        .build())
                    .build())
                .build(),
            new Step.Builder()
                .id(FILTER_STEP)
                .stepKind(StepKind.expressionFilter)
                .putConfiguredProperty("filter", "${body} contains 'number'")
                .build(),
            new Step.Builder()
                .id(MOCK_STEP)
                .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.setUuidGenerator(KeyGenerator::createKey);
        context.addLogListener(new IntegrationLoggingListener(activityTracker));
        context.addInterceptStrategy(new ActivityTrackingInterceptStrategy(activityTracker));
        context.addRoutes(routes);
        context.start();

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

        final List<String> matchingMessages = Collections.singletonList("Body: [number:9436] Log zo syndesisu");
        final List<String> notMatchingMessages = Collections.singletonList("something else");
        final ProducerTemplate template = context.createProducerTemplate();
        final MockEndpoint result = context.getEndpoint("mock:result", MockEndpoint.class);

        List<String> allMessages = new ArrayList<>();
        allMessages.addAll(matchingMessages);
        allMessages.addAll(notMatchingMessages);

        result.expectedBodiesReceived(matchingMessages);

        for (Object body : allMessages) {
            template.sendBody("direct:start", body);
        }

        result.assertIsSatisfied();

        verify(activityTracker, times(allMessages.size())).startTracking(any(Exchange.class));
        verifyActivityStepTracking(MOCK_STEP, matchingMessages.size());
        verifyActivityStepTracking(FILTER_STEP, allMessages.size());
        verify(activityTracker, times(allMessages.size())).finishTracking(any(Exchange.class));
    } finally {
        context.stop();
    }
}
 
Example 6
Source File: SplitStepHandlerTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Test
@Parameters({"/person-unified-schema.json",
             "/person-unified-schema-draft-4.json",
             "/person-unified-schema-draft-6.json"})
public void testSplitUnifiedJsonStep(final String schemaPath) throws Exception {
    final DefaultCamelContext context = new DefaultCamelContext();

    try {
        final RouteBuilder routes = newIntegrationRouteBuilder(activityTracker,
                new Step.Builder()
                        .id(START_STEP)
                        .stepKind(StepKind.endpoint)
                        .action(new ConnectorAction.Builder()
                                .descriptor(new ConnectorDescriptor.Builder()
                                        .componentScheme("direct")
                                        .putConfiguredProperty("name", "expression")
                                        .build())
                                .build())
                        .build(),
                new Step.Builder()
                        .id(SPLIT_STEP)
                        .stepKind(StepKind.split)
                        .action(new StepAction.Builder()
                                .descriptor(new StepDescriptor.Builder()
                                        .outputDataShape(new DataShape.Builder()
                                                .kind(DataShapeKinds.JSON_SCHEMA)
                                                .putMetadata(DataShapeMetaData.UNIFIED, "true")
                                                .specification(IOStreams.readText(getPersonUnifiedSchema(schemaPath)))
                                                .build())
                                        .build())
                                .build())
                        .build(),
                new Step.Builder()
                        .id(MOCK_STEP)
                        .stepKind(StepKind.endpoint)
                        .action(new ConnectorAction.Builder()
                                .descriptor(new ConnectorDescriptor.Builder()
                                        .componentScheme("mock")
                                        .putConfiguredProperty("name", "expression")
                                        .build())
                                .build())
                        .build()
        );

        // Set up the camel context
        context.setUuidGenerator(KeyGenerator::createKey);
        context.addLogListener(new IntegrationLoggingListener(activityTracker));
        context.addInterceptStrategy(new ActivityTrackingInterceptStrategy(activityTracker));
        context.addRoutes(routes);

        context.start();

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

        final ProducerTemplate template = context.createProducerTemplate();
        final MockEndpoint result = context.getEndpoint("mock:expression", MockEndpoint.class);
        final String body = "{" +
                    "\"parameters\": {" +
                        "\"a\": \"value\"," +
                        "\"b\": \"other value\"" +
                    "}," +
                    "\"body\": [" +
                        "{\"id\":1,\"name\":\"a\"}," +
                        "{\"id\":2,\"name\":\"b\"}," +
                        "{\"id\":3,\"name\":\"c\"}" +
                    "]" +
                "}";

        result.expectedMessageCount(3);
        result.expectedBodiesReceived("{\"id\":1,\"name\":\"a\"}", "{\"id\":2,\"name\":\"b\"}", "{\"id\":3,\"name\":\"c\"}");

        template.sendBody("direct:expression", body);

        result.assertIsSatisfied();

        verify(activityTracker).startTracking(any(Exchange.class));
        verifyActivityStepTracking(SPLIT_STEP, 0);
        verifyActivityStepTracking(MOCK_STEP, 3);
        verify(activityTracker).finishTracking(any(Exchange.class));
    } finally {
        context.stop();
    }
}
 
Example 7
Source File: SplitStepHandlerTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Test
public void testSplitJsonArrayInpuStream() throws Exception {
    final DefaultCamelContext context = new DefaultCamelContext();

    try {
        final RouteBuilder routes = newIntegrationRouteBuilder(activityTracker,
                new Step.Builder()
                    .id(START_STEP)
                    .stepKind(StepKind.endpoint)
                    .action(new ConnectorAction.Builder()
                        .descriptor(new ConnectorDescriptor.Builder()
                            .componentScheme("direct")
                            .putConfiguredProperty("name", "expression")
                            .build())
                        .build())
                    .build(),
                new Step.Builder()
                    .id(SPLIT_STEP)
                    .stepKind(StepKind.split)
                    .build(),
                new Step.Builder()
                    .id(MOCK_STEP)
                    .stepKind(StepKind.endpoint)
                    .action(new ConnectorAction.Builder()
                        .descriptor(new ConnectorDescriptor.Builder()
                            .componentScheme("mock")
                            .putConfiguredProperty("name", "expression")
                            .build())
                        .build())
                    .build()
        );

        // Set up the camel context
        context.setUuidGenerator(KeyGenerator::createKey);
        context.addLogListener(new IntegrationLoggingListener(activityTracker));
        context.addInterceptStrategy(new ActivityTrackingInterceptStrategy(activityTracker));
        context.addRoutes(routes);

        context.start();

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

        final ProducerTemplate template = context.createProducerTemplate();
        final MockEndpoint result = context.getEndpoint("mock:expression", MockEndpoint.class);
        final String body = "[{\"id\": 1, \"name\": \"a\"},{\"id\": 2, \"name\": \"b\"},{\"id\": 3, \"name\": \"c\"}]";

        result.expectedMessageCount(3);
        result.expectedBodiesReceived("{\"id\":1,\"name\":\"a\"}", "{\"id\":2,\"name\":\"b\"}", "{\"id\":3,\"name\":\"c\"}");

        template.sendBody("direct:expression", new ByteArrayInputStream(body.getBytes(StandardCharsets.UTF_8)));

        result.assertIsSatisfied();

        verify(activityTracker).startTracking(any(Exchange.class));
        verifyActivityStepTracking(SPLIT_STEP, 0);
        verifyActivityStepTracking(MOCK_STEP, 3);
        verify(activityTracker).finishTracking(any(Exchange.class));
    } finally {
        context.stop();
    }
}
 
Example 8
Source File: LogStepHandlerTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldAddLogStepActivityLogging() throws Exception {
    final ActivityTracker activityTracker = Mockito.mock(ActivityTracker.class);
    final DefaultCamelContext context = new DefaultCamelContext();

    doAnswer(invocation -> {
        ActivityTracker.initializeTracking(invocation.getArgument(0));
        return null;
    }).when(activityTracker).startTracking(any(Exchange.class));

    doAnswer(invocation -> {
        LOGGER.debug(JsonSupport.toJsonObject(invocation.getArguments()));
        return null;
    }).when(activityTracker).track(any());

    try {
        final RouteBuilder routes = newIntegrationRouteBuilder(activityTracker,
                new Step.Builder()
                        .id(START_STEP)
                        .stepKind(StepKind.endpoint)
                        .action(new ConnectorAction.Builder()
                                .descriptor(new ConnectorDescriptor.Builder()
                                        .componentScheme("direct")
                                        .putConfiguredProperty("name", "start")
                                        .build())
                                .build())
                        .build(),
                new Step.Builder()
                        .id(LOG_STEP)
                        .stepKind(StepKind.log)
                        .putConfiguredProperty("bodyLoggingEnabled", "true")
                        .putConfiguredProperty("customText", "Log me baby one more time")
                        .build(),
                new Step.Builder()
                        .id(MOCK_STEP)
                        .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.setUuidGenerator(KeyGenerator::createKey);
        context.addLogListener(new IntegrationLoggingListener(activityTracker));
        context.addInterceptStrategy(new ActivityTrackingInterceptStrategy(activityTracker));
        context.addRoutes(routes);

        SimpleRegistry beanRegistry = new SimpleRegistry();
        beanRegistry.bind("bodyLogger", new BodyLogger.Default());
        context.setRegistry(beanRegistry);

        context.start();

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

        final ProducerTemplate template = context.createProducerTemplate();
        final MockEndpoint result = context.getEndpoint("mock:result", MockEndpoint.class);

        List<String> messages = Arrays.asList("Hi", "Hello");

        result.expectedBodiesReceived(messages);

        for (Object body : messages) {
            template.sendBody("direct:start", body);
        }

        result.assertIsSatisfied();

        verify(activityTracker, times(messages.size())).startTracking(any(Exchange.class));
        verify(activityTracker, times(messages.size())).track(eq("exchange"), anyString(), eq("step"), eq(START_STEP), eq("id"), anyString(), eq("duration"), anyLong(), eq("failure"), isNull());
        verify(activityTracker).track(eq("exchange"), anyString(), eq("step"), eq(LOG_STEP), eq("id"), anyString(), eq("message"), eq("Body: [Hi] Log me baby one more time"));
        verify(activityTracker).track(eq("exchange"), anyString(), eq("step"), eq(LOG_STEP), eq("id"), anyString(), eq("message"), eq("Body: [Hello] Log me baby one more time"));
        verify(activityTracker, times(messages.size())).track(eq("exchange"), anyString(), eq("step"), eq(LOG_STEP), eq("id"), anyString(), eq("duration"), anyLong(), eq("failure"), isNull());
        verify(activityTracker, times(messages.size())).track(eq("exchange"), anyString(), eq("step"), eq(MOCK_STEP), eq("id"), anyString(), eq("duration"), anyLong(), eq("failure"), isNull());
        verify(activityTracker, times(6)).track(eq("exchange"), anyString(), eq("step"), anyString(), eq("id"), anyString(), eq("duration"), anyLong(), eq("failure"), isNull());
        verify(activityTracker, times(messages.size())).finishTracking(any(Exchange.class));
    } finally {
        context.stop();
    }
}
 
Example 9
Source File: FilterStepHandlerTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Test
public void testRuleFilterStepWithJsonComplexPath() throws Exception {
    final DefaultCamelContext context = new DefaultCamelContext();

    try {
        final RouteBuilder routes = newIntegrationRouteBuilder(activityTracker,
            new Step.Builder()
                .id(START_STEP)
                .stepKind(StepKind.endpoint)
                .action(new ConnectorAction.Builder()
                    .descriptor(new ConnectorDescriptor.Builder()
                        .componentScheme("direct")
                        .putConfiguredProperty("name", "start")
                        .build())
                    .build())
                .build(),
            new Step.Builder()
                .id(FILTER_STEP)
                .stepKind(StepKind.ruleFilter)
                .putConfiguredProperty("type", "rule")
                .putConfiguredProperty("predicate", "OR")
                .putConfiguredProperty("rules", "[{\"path\":\"user.name\",\"op\":\"==\",\"value\":\"James\"}, {\"path\":\"user.name\",\"op\":\"==\",\"value\":\"Roland\"}]")
                .build(),
            new Step.Builder()
                .id(MOCK_STEP)
                .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.setUuidGenerator(KeyGenerator::createKey);
        context.addLogListener(new IntegrationLoggingListener(activityTracker));
        context.addInterceptStrategy(new ActivityTrackingInterceptStrategy(activityTracker));
        context.addRoutes(routes);
        context.start();

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

        final List<String> matchingMessages = Arrays.asList(buildUserJson("James"), buildUserJson("Roland"));
        final List<String> notMatchingMessages = Collections.singletonList(buildUserJson("Jimmi"));
        final ProducerTemplate template = context.createProducerTemplate();
        final MockEndpoint result = context.getEndpoint("mock:result", MockEndpoint.class);

        List<String> allMessages = new ArrayList<>();
        allMessages.addAll(matchingMessages);
        allMessages.addAll(notMatchingMessages);

        result.expectedBodiesReceived(matchingMessages);

        for (Object body : allMessages) {
            template.sendBody("direct:start", body);
        }

        result.assertIsSatisfied();

        verify(activityTracker, times(allMessages.size())).startTracking(any(Exchange.class));
        verifyActivityStepTracking(MOCK_STEP, matchingMessages.size());
        verifyActivityStepTracking(FILTER_STEP, allMessages.size());
        verify(activityTracker, times(allMessages.size())).finishTracking(any(Exchange.class));
    } finally {
        context.stop();
    }
}
 
Example 10
Source File: SplitStepHandlerTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Test
public void testSplitBody() throws Exception {
    final DefaultCamelContext context = new DefaultCamelContext();

    try {
        final RouteBuilder routes = newIntegrationRouteBuilder(activityTracker,
            new Step.Builder()
                .id(START_STEP)
                .stepKind(StepKind.endpoint)
                .action(new ConnectorAction.Builder()
                    .descriptor(new ConnectorDescriptor.Builder()
                        .componentScheme("direct")
                        .putConfiguredProperty("name", "expression")
                        .build())
                    .build())
                .build(),
            new Step.Builder()
                .id(SPLIT_STEP)
                .stepKind(StepKind.split)
                .build(),
            new Step.Builder()
                .id(MOCK_STEP)
                .stepKind(StepKind.endpoint)
                .action(new ConnectorAction.Builder()
                    .descriptor(new ConnectorDescriptor.Builder()
                        .componentScheme("mock")
                        .putConfiguredProperty("name", "expression")
                        .build())
                    .build())
                .build()
        );

        // Set up the camel context
        context.setUuidGenerator(KeyGenerator::createKey);
        context.addLogListener(new IntegrationLoggingListener(activityTracker));
        context.addInterceptStrategy(new ActivityTrackingInterceptStrategy(activityTracker));
        context.addRoutes(routes);
        context.start();

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

        final ProducerTemplate template = context.createProducerTemplate();
        final MockEndpoint result = context.getEndpoint("mock:expression", MockEndpoint.class);
        final List<String> body = Arrays.asList("a","b","c");

        result.expectedMessageCount(3);
        result.expectedBodiesReceived(body);

        template.sendBody("direct:expression", body);

        result.assertIsSatisfied();

        verify(activityTracker).startTracking(any(Exchange.class));
        verifyActivityStepTracking(SPLIT_STEP, 0);
        verifyActivityStepTracking(MOCK_STEP, 3);
        verify(activityTracker).finishTracking(any(Exchange.class));
    } finally {
        context.stop();
    }
}
 
Example 11
Source File: ChoiceStepHandlerTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Test
public void testChoiceStepNoConfiguredFlows() throws Exception {
    final DefaultCamelContext context = new DefaultCamelContext();

    try {
        final RouteBuilder integrationRoute = newIntegrationRouteBuilder(activityTracker,
                new Step.Builder()
                        .id(START_STEP)
                        .stepKind(StepKind.endpoint)
                        .action(new ConnectorAction.Builder()
                                .descriptor(new ConnectorDescriptor.Builder()
                                        .componentScheme("direct")
                                        .putConfiguredProperty("name", "flow")
                                        .build())
                                .build())
                        .build(),
                new Step.Builder()
                        .id(CHOICE_STEP)
                        .stepKind(StepKind.choice)
                        .build(),
                new Step.Builder()
                        .id(MOCK_STEP)
                        .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.setUuidGenerator(KeyGenerator::createKey);
        context.addLogListener(new IntegrationLoggingListener(activityTracker));
        context.addInterceptStrategy(new ActivityTrackingInterceptStrategy(activityTracker));
        context.addRoutes(integrationRoute);
        context.start();

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

        final ProducerTemplate template = context.createProducerTemplate();
        final MockEndpoint result = context.getEndpoint("mock:result", MockEndpoint.class);

        final List<String> messages = Arrays.asList("Hello Camel!", "Bye Camel!", "And Now for Something Completely Different");

        result.expectedBodiesReceived(messages);

        for (String message : messages) {
            template.sendBody("direct:flow", message);
        }

        result.assertIsSatisfied();

        verify(activityTracker, times(3)).startTracking(any(Exchange.class));
        verifyActivityStepTracking(CHOICE_STEP, 3);
        verifyActivityStepTracking(MOCK_STEP, 3);
        verify(activityTracker, times(3)).finishTracking(any(Exchange.class));

    } finally {
        context.stop();
    }
}
 
Example 12
Source File: ChoiceStepHandlerTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Test
public void testChoiceStepWithDefaultFlow() throws Exception {
    final DefaultCamelContext context = new DefaultCamelContext();

    try {
        final RouteBuilder integrationRoute = newIntegrationRouteBuilder(activityTracker,
                new Step.Builder()
                        .id(START_STEP)
                        .stepKind(StepKind.endpoint)
                        .action(new ConnectorAction.Builder()
                                .descriptor(new ConnectorDescriptor.Builder()
                                        .componentScheme("direct")
                                        .putConfiguredProperty("name", "flow")
                                        .build())
                                .build())
                        .build(),
                new Step.Builder()
                        .id(CHOICE_STEP)
                        .stepKind(StepKind.choice)
                        .putConfiguredProperty("routingScheme", "mock")
                        .putConfiguredProperty("default", "default-flow")
                        .putConfiguredProperty("flows", "[" +
                                "{\"condition\": \"${body} contains 'Hello'\", \"flow\": \"hello-flow\"}," +
                                "{\"condition\": \"${body} contains 'Bye'\", \"flow\": \"bye-flow\"}" +
                                "]")
                        .build(),
                new Step.Builder()
                        .id(MOCK_STEP)
                        .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.setUuidGenerator(KeyGenerator::createKey);
        context.addLogListener(new IntegrationLoggingListener(activityTracker));
        context.addInterceptStrategy(new ActivityTrackingInterceptStrategy(activityTracker));
        context.addRoutes(integrationRoute);
        context.start();

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

        final ProducerTemplate template = context.createProducerTemplate();
        final MockEndpoint result = context.getEndpoint("mock:result", MockEndpoint.class);
        final MockEndpoint defaultResult = context.getEndpoint("mock:default-flow", MockEndpoint.class);
        final MockEndpoint helloResult = context.getEndpoint("mock:hello-flow", MockEndpoint.class);
        final MockEndpoint byeResult = context.getEndpoint("mock:bye-flow", MockEndpoint.class);

        final List<String> messages = Arrays.asList("Hello Camel!", "Bye Camel!", "And Now for Something Completely Different");

        result.expectedBodiesReceived(messages);
        defaultResult.expectedBodiesReceived("And Now for Something Completely Different");
        helloResult.expectedBodiesReceived("Hello Camel!");
        byeResult.expectedBodiesReceived("Bye Camel!");

        for (String message : messages) {
            template.sendBody("direct:flow", message);
        }

        result.assertIsSatisfied();
        helloResult.assertIsSatisfied();
        byeResult.assertIsSatisfied();

        verify(activityTracker, times(3)).startTracking(any(Exchange.class));
        verifyActivityStepTracking(CHOICE_STEP, 3);
        verifyActivityStepTracking(MOCK_STEP, 3);
        verify(activityTracker, times(3)).finishTracking(any(Exchange.class));

    } finally {
        context.stop();
    }
}
 
Example 13
Source File: ChoiceStepHandlerTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Test
public void testChoiceStep() throws Exception {
    final DefaultCamelContext context = new DefaultCamelContext();

    try {
        final RouteBuilder integrationRoute = newIntegrationRouteBuilder(activityTracker,
            new Step.Builder()
                .id(START_STEP)
                .stepKind(StepKind.endpoint)
                .action(new ConnectorAction.Builder()
                    .descriptor(new ConnectorDescriptor.Builder()
                        .componentScheme("direct")
                        .putConfiguredProperty("name", "flow")
                        .build())
                    .build())
                .build(),
            new Step.Builder()
                .id(CHOICE_STEP)
                .stepKind(StepKind.choice)
                .putConfiguredProperty("flows", "[" +
                                    "{\"condition\": \"${body} contains 'Hello'\", \"flow\": \"hello-flow\"}," +
                                    "{\"condition\": \"${body} contains 'Bye'\", \"flow\": \"bye-flow\"}" +
                                "]")
                .build(),
            new Step.Builder()
                .id(MOCK_STEP)
                .stepKind(StepKind.endpoint)
                .action(new ConnectorAction.Builder()
                    .descriptor(new ConnectorDescriptor.Builder()
                        .componentScheme("mock")
                        .putConfiguredProperty("name", "result")
                        .build())
                    .build())
                .build()
        );

        final RouteBuilder helloRoute = new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from("direct:hello-flow")
                        .to("mock:hello");
            }
        };

        final RouteBuilder byeRoute = new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from("direct:bye-flow")
                        .to("mock:bye");
            }
        };

        // Set up the camel context
        context.setUuidGenerator(KeyGenerator::createKey);
        context.addLogListener(new IntegrationLoggingListener(activityTracker));
        context.addInterceptStrategy(new ActivityTrackingInterceptStrategy(activityTracker));
        context.addRoutes(helloRoute);
        context.addRoutes(byeRoute);
        context.addRoutes(integrationRoute);

        SimpleRegistry beanRegistry = new SimpleRegistry();
        beanRegistry.bind("bodyLogger", new BodyLogger.Default());
        context.setRegistry(beanRegistry);
        context.start();

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

        final ProducerTemplate template = context.createProducerTemplate();
        final MockEndpoint result = context.getEndpoint("mock:result", MockEndpoint.class);
        final MockEndpoint helloResult = context.getEndpoint("mock:hello", MockEndpoint.class);
        final MockEndpoint byeResult = context.getEndpoint("mock:bye", MockEndpoint.class);

        final List<String> messages = Arrays.asList("Hello Camel!", "Bye Camel!", "And Now for Something Completely Different");

        result.expectedBodiesReceived(messages);
        helloResult.expectedBodiesReceived("Hello Camel!");
        byeResult.expectedBodiesReceived("Bye Camel!");

        for (String message : messages) {
            template.sendBody("direct:flow", message);
        }

        result.assertIsSatisfied();
        helloResult.assertIsSatisfied();
        byeResult.assertIsSatisfied();

        verify(activityTracker, times(3)).startTracking(any(Exchange.class));
        verifyActivityStepTracking(CHOICE_STEP, 3);
        verifyActivityStepTracking(MOCK_STEP, 3);
        verify(activityTracker, times(3)).finishTracking(any(Exchange.class));
    } finally {
        context.stop();
    }
}
 
Example 14
Source File: FilterStepHandlerTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Test
public void testRuleFilterStepWithJsonArrayPath() throws Exception {
    final DefaultCamelContext context = new DefaultCamelContext();

    try {
        final RouteBuilder routes = newIntegrationRouteBuilder(activityTracker,
                new Step.Builder()
                        .id(START_STEP)
                        .stepKind(StepKind.endpoint)
                        .action(new ConnectorAction.Builder()
                                .descriptor(new ConnectorDescriptor.Builder()
                                        .componentScheme("direct")
                                        .putConfiguredProperty("name", "start")
                                        .build())
                                .build())
                        .build(),
                new Step.Builder()
                        .id(FILTER_STEP)
                        .stepKind(StepKind.ruleFilter)
                        .putConfiguredProperty("type", "rule")
                        .putConfiguredProperty("predicate", "AND")
                        .putConfiguredProperty("rules", "[{\"path\":\"size()\",\"op\":\"==\",\"value\":\"2\"}, {\"path\":\"[0].user.name\",\"op\":\"==\",\"value\":\"James\"}, {\"path\":\"[1].user.name\",\"op\":\"==\",\"value\":\"Roland\"}]")
                        .build(),
                new Step.Builder()
                        .id(MOCK_STEP)
                        .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.setUuidGenerator(KeyGenerator::createKey);
        context.addLogListener(new IntegrationLoggingListener(activityTracker));
        context.addInterceptStrategy(new ActivityTrackingInterceptStrategy(activityTracker));
        context.addRoutes(routes);
        context.start();

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

        final List<String> matchingMessages = Collections.singletonList(buildUserJsonArray("James", "Roland"));
        final List<String> notMatchingMessages = Arrays.asList(buildUserJsonArray(),
                                                                buildUserJsonArray("Jimmi"),
                                                                buildUserJsonArray("Jimmi", "Roland"),
                                                                buildUserJsonArray("James", "Roland", "Jimmi"));
        final ProducerTemplate template = context.createProducerTemplate();
        final MockEndpoint result = context.getEndpoint("mock:result", MockEndpoint.class);

        List<String> allMessages = new ArrayList<>();
        allMessages.addAll(matchingMessages);
        allMessages.addAll(notMatchingMessages);

        result.expectedBodiesReceived(matchingMessages);

        for (Object body : allMessages) {
            template.sendBody("direct:start", body);
        }

        result.assertIsSatisfied();

        verify(activityTracker, times(allMessages.size())).startTracking(any(Exchange.class));
        verifyActivityStepTracking(MOCK_STEP, matchingMessages.size());
        verifyActivityStepTracking(FILTER_STEP, allMessages.size());
        verify(activityTracker, times(allMessages.size())).finishTracking(any(Exchange.class));
    } finally {
        context.stop();
    }
}
 
Example 15
Source File: SplitAggregateStepHandlerTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Test
public void testSplitAggregateWithLatestAggregationStrategy() throws Exception {
    final DefaultCamelContext context = new DefaultCamelContext();

    try {
        final RouteBuilder routes = newIntegrationRouteBuilder(activityTracker,
            new Step.Builder()
                .id(START_STEP)
                .stepKind(StepKind.endpoint)
                .action(new ConnectorAction.Builder()
                    .descriptor(new ConnectorDescriptor.Builder()
                        .componentScheme("direct")
                        .putConfiguredProperty("name", "expression")
                        .build())
                    .build())
                .build(),
            new Step.Builder()
                .id(SPLIT_STEP)
                .stepKind(StepKind.split)
                .putConfiguredProperty("aggregationStrategy", "latest")
                .build(),
            new Step.Builder()
                .id(MOCK_STEP)
                .stepKind(StepKind.endpoint)
                .action(new ConnectorAction.Builder()
                    .descriptor(new ConnectorDescriptor.Builder()
                        .componentScheme("mock")
                        .putConfiguredProperty("name", "split")
                        .build())
                    .build())
                .build(),
            new Step.Builder()
                .id(AGGREGATE_STEP)
                .stepKind(StepKind.aggregate)
                .build()

        );

        // Set up the camel context
        context.setUuidGenerator(KeyGenerator::createKey);
        context.addLogListener(new IntegrationLoggingListener(activityTracker));
        context.addInterceptStrategy(new ActivityTrackingInterceptStrategy(activityTracker));
        context.addRoutes(routes);
        context.start();

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

        final ProducerTemplate template = context.createProducerTemplate();
        final MockEndpoint result = context.getEndpoint("mock:split", MockEndpoint.class);
        final List<String> body = Arrays.asList("a","b","c");

        result.expectedBodiesReceived(body);

        String response = template.requestBody("direct:expression", body, String.class);

        result.assertIsSatisfied();
        Assert.assertEquals("c", response);

        verify(activityTracker).startTracking(any(Exchange.class));
        verifyActivityStepTracking(START_STEP, 1);
        verifyActivityStepTracking(SPLIT_STEP, 0);
        verifyActivityStepTracking(MOCK_STEP, 3);
        verifyActivityStepTracking(AGGREGATE_STEP, 0);
        verify(activityTracker, times(4)).track(eq("exchange"), anyString(), eq("step"), anyString(), eq("id"), anyString(), eq("duration"), anyLong(), eq("failure"), isNull());
        verify(activityTracker).finishTracking(any(Exchange.class));
    } finally {
        context.stop();
    }
}
 
Example 16
Source File: SplitAggregateStepHandlerTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Test
public void testSplitAggregateWithOriginalAggregationStrategy() throws Exception {
    final DefaultCamelContext context = new DefaultCamelContext();

    try {
        final RouteBuilder routes = newIntegrationRouteBuilder(activityTracker,
            new Step.Builder()
                .id(START_STEP)
                .stepKind(StepKind.endpoint)
                .action(new ConnectorAction.Builder()
                    .descriptor(new ConnectorDescriptor.Builder()
                        .componentScheme("direct")
                        .putConfiguredProperty("name", "expression")
                        .build())
                    .build())
                .build(),
            new Step.Builder()
                .id(SPLIT_STEP)
                .stepKind(StepKind.split)
                .putConfiguredProperty("language", "tokenize")
                .putConfiguredProperty("expression", "|")
                .putConfiguredProperty("aggregationStrategy", "original")
                .build(),
            new Step.Builder()
                .id(MOCK_STEP)
                .stepKind(StepKind.endpoint)
                .action(new ConnectorAction.Builder()
                    .descriptor(new ConnectorDescriptor.Builder()
                        .componentScheme("mock")
                        .putConfiguredProperty("name", "split")
                        .build())
                    .build())
                .build(),
            new Step.Builder()
                .id(AGGREGATE_STEP)
                .stepKind(StepKind.aggregate)
                .build()
        );

        // Set up the camel context
        context.setUuidGenerator(KeyGenerator::createKey);
        context.addLogListener(new IntegrationLoggingListener(activityTracker));
        context.addInterceptStrategy(new ActivityTrackingInterceptStrategy(activityTracker));
        context.addRoutes(routes);
        context.start();

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

        final ProducerTemplate template = context.createProducerTemplate();
        final MockEndpoint result = context.getEndpoint("mock:split", MockEndpoint.class);
        final String body = "a|b|c";

        result.expectedBodiesReceived((Object[])body.split("|"));

        String response = template.requestBody("direct:expression", body, String.class);

        result.assertIsSatisfied();
        Assert.assertEquals(body, response);

        verify(activityTracker).startTracking(any(Exchange.class));
        verifyActivityStepTracking(START_STEP, 1);
        verifyActivityStepTracking(SPLIT_STEP, 0);
        verifyActivityStepTracking(MOCK_STEP, 5);
        verifyActivityStepTracking(AGGREGATE_STEP, 0);
        verify(activityTracker, times(6)).track(eq("exchange"), anyString(), eq("step"), anyString(), eq("id"), anyString(), eq("duration"), anyLong(), eq("failure"), isNull());
        verify(activityTracker).finishTracking(any(Exchange.class));
    } finally {
        context.stop();
    }
}
 
Example 17
Source File: SplitAggregateStepHandlerTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Test
public void testSplitAggregateTokenize() throws Exception {
    final DefaultCamelContext context = new DefaultCamelContext();

    try {
        final RouteBuilder routes = newIntegrationRouteBuilder(activityTracker,
            new Step.Builder()
                .id(START_STEP)
                .stepKind(StepKind.endpoint)
                .action(new ConnectorAction.Builder()
                    .descriptor(new ConnectorDescriptor.Builder()
                        .componentScheme("direct")
                        .putConfiguredProperty("name", "expression")
                        .build())
                    .build())
                .build(),
            new Step.Builder()
                .id(SPLIT_STEP)
                .stepKind(StepKind.split)
                .putConfiguredProperty("language", "tokenize")
                .putConfiguredProperty("expression", "|")
                .build(),
            new Step.Builder()
                .id(MOCK_STEP)
                .stepKind(StepKind.endpoint)
                .action(new ConnectorAction.Builder()
                    .descriptor(new ConnectorDescriptor.Builder()
                        .componentScheme("mock")
                        .putConfiguredProperty("name", "split")
                        .build())
                    .build())
                .build(),
            new Step.Builder()
                .id(AGGREGATE_STEP)
                .stepKind(StepKind.aggregate)
                .build()
        );

        // Set up the camel context
        context.setUuidGenerator(KeyGenerator::createKey);
        context.addLogListener(new IntegrationLoggingListener(activityTracker));
        context.addInterceptStrategy(new ActivityTrackingInterceptStrategy(activityTracker));
        context.addRoutes(routes);
        context.start();

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

        final ProducerTemplate template = context.createProducerTemplate();
        final MockEndpoint result = context.getEndpoint("mock:split", MockEndpoint.class);
        final String body = "a|b|c";

        result.expectedBodiesReceived((Object[])body.split("|"));

        List<?> response = template.requestBody("direct:expression", body, List.class);

        result.assertIsSatisfied();
        Assert.assertEquals(5, response.size());
        Assert.assertEquals(body, response.stream().map(Object::toString).collect(Collectors.joining()));

        verify(activityTracker).startTracking(any(Exchange.class));
        verifyActivityStepTracking(START_STEP, 1);
        verifyActivityStepTracking(SPLIT_STEP, 0);
        verifyActivityStepTracking(MOCK_STEP, 5);
        verifyActivityStepTracking(AGGREGATE_STEP, 0);
        verify(activityTracker, times(6)).track(eq("exchange"), anyString(), eq("step"), anyString(), eq("id"), anyString(), eq("duration"), anyLong(), eq("failure"), isNull());
        verify(activityTracker).finishTracking(any(Exchange.class));
    } finally {
        context.stop();
    }
}
 
Example 18
Source File: ActivityTracingWithSplitTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Before
public void before() throws Exception {

    activityEvents = new ArrayList<>();

    Tracer tracer = new JaegerTracer.Builder(getClass().getName()).withReporter(new Reporter() {
        @Override
        public void report(JaegerSpan span) {
            activityEvents.add(span);
        }

        @Override
        public void close() {
            // no resource to dispose
        }
    }).withSampler(new ConstSampler(true)).build();

    final RouteBuilder routeBuilder = new IntegrationRouteBuilder("", Resources.loadServices(IntegrationStepHandler.class),
        Arrays.asList(new TracingActivityTrackingPolicyFactory(tracer))) {

        @Override
        protected Integration loadIntegration() {
            return newIntegration(
                new Step.Builder()
                    .id("source")
                    .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-1")
                    .stepKind(StepKind.log)
                    .putConfiguredProperty("contextLoggingEnabled", "true")
                    .putConfiguredProperty("customText", "Log me baby one more time").build(),
                new Step.Builder()
                    .id("step-2")
                    .stepKind(StepKind.endpoint)
                    .action(new ConnectorAction.Builder()
                        .descriptor(new ConnectorDescriptor.Builder()
                            .componentScheme("class")
                            .putConfiguredProperty("beanName", TestBean.class.getName())
                            .build())
                        .build())
                    .build(),
                new Step.Builder()
                    .id("step-3")
                    .stepKind(StepKind.log)
                    .putConfiguredProperty("contextLoggingEnabled", "true")
                    .putConfiguredProperty("customText", "Log me baby one more time").build(),
                new Step.Builder()
                    .id("step-4")
                    .stepKind(StepKind.endpoint)
                    .action(new ConnectorAction.Builder()
                        .descriptor(new ConnectorDescriptor.Builder()
                            .componentScheme("mock")
                            .putConfiguredProperty("name", "end")
                            .build())
                        .build())
                    .build());
        }
    };

    context = new DefaultCamelContext();
    context.setUuidGenerator(KeyGenerator::createKey);
    context.addLogListener(new TracingLogListener(tracer));
    context.addInterceptStrategy(new TracingInterceptStrategy(tracer));
    context.addRoutes(routeBuilder);
    context.getShutdownStrategy().setTimeout(1);
    context.start();

    dumpRoutes(context, routeBuilder.getRouteCollection());
}
 
Example 19
Source File: FilterStepHandlerTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Test
public void testRuleFilterStepWithJsonSimplePath() throws Exception {
    final DefaultCamelContext context = new DefaultCamelContext();

    try {
        final RouteBuilder routes = newIntegrationRouteBuilder(activityTracker,
            new Step.Builder()
                .id(START_STEP)
                .stepKind(StepKind.endpoint)
                .action(new ConnectorAction.Builder()
                    .descriptor(new ConnectorDescriptor.Builder()
                        .componentScheme("direct")
                        .putConfiguredProperty("name", "start")
                        .build())
                    .build())
                .build(),
            new Step.Builder()
                .id(FILTER_STEP)
                .stepKind(StepKind.ruleFilter)
                .putConfiguredProperty("type", "rule")
                .putConfiguredProperty("predicate", "OR")
                .putConfiguredProperty("rules", "[{\"path\":\"name\",\"op\":\"==\",\"value\":\"James\"}, {\"path\":\"name\",\"op\":\"==\",\"value\":\"Roland\"}]")
                .build(),
            new Step.Builder()
                .id(MOCK_STEP)
                .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.setUuidGenerator(KeyGenerator::createKey);
        context.addLogListener(new IntegrationLoggingListener(activityTracker));
        context.addInterceptStrategy(new ActivityTrackingInterceptStrategy(activityTracker));
        context.addRoutes(routes);
        context.start();

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

        final List<String> matchingMessages = Arrays.asList(buildPersonJson("James"), buildPersonJson("Roland"));
        final List<String> notMatchingMessages = Collections.singletonList(buildPersonJson("Jimmi"));
        final ProducerTemplate template = context.createProducerTemplate();
        final MockEndpoint result = context.getEndpoint("mock:result", MockEndpoint.class);

        List<String> allMessages = new ArrayList<>();
        allMessages.addAll(matchingMessages);
        allMessages.addAll(notMatchingMessages);

        result.expectedBodiesReceived(matchingMessages);

        for (Object body : allMessages) {
            template.sendBody("direct:start", body);
        }

        result.assertIsSatisfied();

        verify(activityTracker, times(allMessages.size())).startTracking(any(Exchange.class));
        verifyActivityStepTracking(MOCK_STEP, matchingMessages.size());
        verifyActivityStepTracking(FILTER_STEP, allMessages.size());
        verify(activityTracker, times(allMessages.size())).finishTracking(any(Exchange.class));
    } finally {
        context.stop();
    }
}
 
Example 20
Source File: SimpleEndpointStepHandlerTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Test
public void testSimpleEndpointStep() throws Exception {
    final DefaultCamelContext context = getDefaultCamelContextWithMyBeanInRegistry();

    try {
        final RouteBuilder routes = newIntegrationRouteBuilder(activityTracker,
            new Step.Builder()
                .stepKind(StepKind.endpoint)
                .action(new ConnectorAction.Builder()
                    .descriptor(new ConnectorDescriptor.Builder()
                        .componentScheme("direct")
                        .putConfiguredProperty("name", "start")
                        .build())
                    .build())
                .build(),
            new Step.Builder()
                .stepKind(StepKind.endpoint)
                .action(new ConnectorAction.Builder()
                    .descriptor(new ConnectorDescriptor.Builder()
                        .componentScheme("bean")
                        .putConfiguredProperty("beanName", "myBean")
                        .putConfiguredProperty("method", "myProcessor")
                        .build())
                    .build())
                .build(),
            new Step.Builder()
                .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.setUuidGenerator(KeyGenerator::createKey);
        context.addLogListener(new IntegrationLoggingListener(activityTracker));
        context.addInterceptStrategy(new ActivityTrackingInterceptStrategy(activityTracker));
        context.addRoutes(routes);
        context.start();

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

        final ProducerTemplate template = context.createProducerTemplate();
        final MockEndpoint result = context.getEndpoint("mock:result", MockEndpoint.class);
        final String body = "testSimpleEndpointStep";

        result.expectedBodiesReceived(body.toUpperCase());
        template.sendBody("direct:start", body);

        result.assertIsSatisfied();

        verify(activityTracker).startTracking(any(Exchange.class));
        verify(activityTracker, times(3)).track(eq("exchange"), anyString(), eq("step"), anyString(), eq("id"), anyString(), eq("duration"), anyLong(), eq("failure"), isNull());
        verify(activityTracker).finishTracking(any(Exchange.class));
    } finally {
        context.stop();
    }
}