Java Code Examples for org.apache.camel.impl.DefaultCamelContext#getEndpoint()
The following examples show how to use
org.apache.camel.impl.DefaultCamelContext#getEndpoint() .
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: SplitStepHandlerJsonTest.java From syndesis with Apache License 2.0 | 5 votes |
/** * Test inconsistent split aggregate combination where some additional aggregate steps are added to the integration. * direct -> split -> log -> aggregate -> aggregate -> split -> log -> aggregate -> aggregate -> mock */ @Test public void testInconsistentSplitAggregate() throws Exception { final DefaultCamelContext context = new DefaultCamelContext(); try { final RouteBuilder routes = new IntegrationRouteBuilder( "classpath:/syndesis/integration/inconsistent-split.json", Resources.loadServices(IntegrationStepHandler.class) ); // Set up the camel context context.addRoutes(routes); addBodyLogger(context); 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", "de", "f,g"); result.expectedBodiesReceived(body); template.sendBody("direct:expression", body); result.assertIsSatisfied(); } finally { context.stop(); } }
Example 2
Source File: SplitStepHandlerJsonTest.java From syndesis with Apache License 2.0 | 5 votes |
/** * Test chains of split/aggregate where a 2nd split directly follows on the 1st aggregate. * direct -> split -> log -> aggregate -> split -> log -> aggregate -> mock */ @Test public void testSplitAggregateChain() throws Exception { final DefaultCamelContext context = new DefaultCamelContext(); try { final RouteBuilder routes = new IntegrationRouteBuilder( "classpath:/syndesis/integration/split-chain.json", Resources.loadServices(IntegrationStepHandler.class) ); // Set up the camel context context.addRoutes(routes); addBodyLogger(context); 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", "de", "f,g"); result.expectedBodiesReceived(body); template.sendBody("direct:expression", body); result.assertIsSatisfied(); } finally { context.stop(); } }
Example 3
Source File: SplitStepHandlerJsonTest.java From syndesis with Apache License 2.0 | 5 votes |
/** * Test split to the very end of the integration - no aggregate * direct -> split -> mock */ @Test public void testSplitToEnd() throws Exception { final DefaultCamelContext context = new DefaultCamelContext(); try { final RouteBuilder routes = new IntegrationRouteBuilder( "classpath:/syndesis/integration/split-to-end.json", Resources.loadServices(IntegrationStepHandler.class) ); // Set up the camel context 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[] expected = { "a","b","c" }; final List<String> body = Arrays.asList(expected); result.expectedMessageCount(3); result.expectedBodiesReceived((Object[])expected); template.sendBody("direct:expression", body); result.assertIsSatisfied(); } finally { context.stop(); } }
Example 4
Source File: EtcdIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testEtcdComponent() throws Exception { DefaultCamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { String dockerHost = TestUtils.getDockerHost(); from("direct:start") .toF("etcd:keys?uris=http://%s:23379,http://%s:40001", dockerHost, dockerHost) .to("mock:result"); } }); String path = "/camel/" + UUID.randomUUID().toString(); String value = UUID.randomUUID().toString(); Map<String, Object> headers = new HashMap<>(); headers.put(EtcdConstants.ETCD_ACTION, EtcdConstants.ETCD_KEYS_ACTION_SET); headers.put(EtcdConstants.ETCD_PATH, path); MockEndpoint mockEndpoint = camelctx.getEndpoint("mock:result", MockEndpoint.class); mockEndpoint.expectedMinimumMessageCount(1); mockEndpoint.expectedHeaderReceived(EtcdConstants.ETCD_PATH, path); camelctx.start(); try { ProducerTemplate template = camelctx.createProducerTemplate(); template.sendBodyAndHeaders("direct:start", value, headers); mockEndpoint.assertIsSatisfied(); } finally { camelctx.close(); } }
Example 5
Source File: SplitStepHandlerJsonTest.java From syndesis with Apache License 2.0 | 5 votes |
/** * Test filter step that lives after a split - no aggregate * direct -> split -> filter -> log -> mock */ @Test public void testFilterAfterSplit() throws Exception { final DefaultCamelContext context = new DefaultCamelContext(); try { final RouteBuilder routes = new IntegrationRouteBuilder( "classpath:/syndesis/integration/filter-after-split.json", Resources.loadServices(IntegrationStepHandler.class) ); // Set up the camel context context.addRoutes(routes); addBodyLogger(context); 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("{\"task\": \"Play with the dog\"}", "{\"task\": \"Wash the dog\"}", "{\"task\": \"Feed the dog\"}", "{\"task\": \"Walk the dog\"}"); result.expectedMessageCount(1); template.sendBody("direct:expression", body); result.assertIsSatisfied(); assertThat(result.getExchanges().get(0).getIn().getBody(String.class)).isEqualTo("{\"task\": \"Feed the dog\"}"); } finally { context.stop(); } }
Example 6
Source File: ChoiceStepHandlerTest.java From syndesis with Apache License 2.0 | 4 votes |
@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 7
Source File: SplitStepHandlerTest.java From syndesis with Apache License 2.0 | 4 votes |
@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: FilterStepHandlerTest.java From syndesis with Apache License 2.0 | 4 votes |
@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 9
Source File: SplitStepHandlerTest.java From syndesis with Apache License 2.0 | 4 votes |
@Test public void testTokenizeSplitStep() 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", "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 = "a|b|c"; result.expectedMessageCount(3); result.expectedBodiesReceived((Object[])body.split("|")); template.sendBody("direct:expression", body); result.assertIsSatisfied(); verify(activityTracker).startTracking(any(Exchange.class)); verifyActivityStepTracking(SPLIT_STEP, 0); verifyActivityStepTracking(MOCK_STEP, 5); verify(activityTracker).finishTracking(any(Exchange.class)); } finally { context.stop(); } }
Example 10
Source File: SplitStepHandlerTest.java From syndesis with Apache License 2.0 | 4 votes |
@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: FilterStepHandlerTest.java From syndesis with Apache License 2.0 | 4 votes |
@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 12
Source File: FilterStepHandlerTest.java From syndesis with Apache License 2.0 | 4 votes |
@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 13
Source File: HeadersStepHandlerTest.java From syndesis with Apache License 2.0 | 4 votes |
@Test public void testRemoveHeadersStepHandler() throws Exception { final DefaultCamelContext context = new DefaultCamelContext(); try { final RouteBuilder routes = newIntegrationRouteBuilder( new Step.Builder() .stepKind(StepKind.endpoint) .action(new ConnectorAction.Builder() .id(KeyGenerator.createKey()) .descriptor(new ConnectorDescriptor.Builder() .connectorId("new") .componentScheme("direct") .putConfiguredProperty("name", "start") .build()) .build()) .build(), new Step.Builder() .stepKind(StepKind.headers) .putConfiguredProperty("action", "set") .putConfiguredProperty("MyHeader1", "1") .putConfiguredProperty("MyHeader2", "2") .build(), new Step.Builder() .stepKind(StepKind.headers) .putConfiguredProperty("action", "remove") .putConfiguredProperty("MyHeader1", "") .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.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); result.expectedMessageCount(1); result.expectedMessagesMatches(e -> !e.getIn().getHeaders().containsKey("Myheader1")); result.expectedMessagesMatches(e -> e.getIn().getHeaders().containsKey("Myheader2")); template.sendBody("direct:start", ""); result.assertIsSatisfied(); } finally { context.stop(); } }
Example 14
Source File: ChoiceStepHandlerTest.java From syndesis with Apache License 2.0 | 4 votes |
@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 15
Source File: SplitAggregateStepHandlerTest.java From syndesis with Apache License 2.0 | 4 votes |
@Test public void testSplitAggregateScriptAggregationStrategy() 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", "script") .putConfiguredProperty("aggregationScriptLanguage", "nashorn") .putConfiguredProperty("aggregationScript", "newExchange.in.body += oldExchange ? oldExchange.in.body : '';\n" + "newExchange;") .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("c|b|a", 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 16
Source File: SplitAggregateStepHandlerTest.java From syndesis with Apache License 2.0 | 4 votes |
@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 17
Source File: SplitAggregateStepHandlerTest.java From syndesis with Apache License 2.0 | 4 votes |
@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: SplitStepHandlerJsonTest.java From syndesis with Apache License 2.0 | 4 votes |
/** * Test nested split/aggregate where a 2nd split lives inside the 1st split/aggregate * direct -> split -> log -> split -> log -> mock -> aggregate -> log -> aggregate -> mock */ @Test public void testNestedSplitAggregate() throws Exception { final DefaultCamelContext context = new DefaultCamelContext(); try { final RouteBuilder routes = new IntegrationRouteBuilder( "classpath:/syndesis/integration/nested-split.json", Resources.loadServices(IntegrationStepHandler.class) ); // Set up the camel context context.addRoutes(routes); addBodyLogger(context); 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 MockEndpoint nestedResult = context.getEndpoint("mock:nested-mock", MockEndpoint.class); final List<String> body = Arrays.asList("a,b,c", "de", "f,g"); result.expectedMessageCount(1); nestedResult.expectedBodiesReceived("a", "b", "c", "de", "f", "g"); template.sendBody("direct:expression", body); result.assertIsSatisfied(); nestedResult.assertIsSatisfied(); List<?> bodyReceived = result.getExchanges().get(0).getIn().getBody(List.class); assertThat(bodyReceived).hasSize(3); assertThat(bodyReceived.get(0)).isEqualTo(Arrays.asList("a","b","c")); assertThat(bodyReceived.get(1)).isEqualTo(Collections.singletonList("de")); assertThat(bodyReceived.get(2)).isEqualTo(Arrays.asList("f","g")); } finally { context.stop(); } }
Example 19
Source File: SimpleEndpointStepHandlerTest.java From syndesis with Apache License 2.0 | 4 votes |
@Test public void testSimpleEndpointStepWithSplitAggregate() 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.split) .putConfiguredProperty("language", "tokenize") .putConfiguredProperty("expression", "|") .build(), new Step.Builder() .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() ); // 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 = "a|b|c"; final String[] expected = body.toUpperCase().split("|"); result.expectedMessageCount(3); result.expectedBodiesReceived((Object[])expected); template.sendBody("direct:start", body); result.assertIsSatisfied(); verify(activityTracker).startTracking(any(Exchange.class)); verify(activityTracker, times(7)).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 20
Source File: SimpleEndpointStepHandlerTest.java From syndesis with Apache License 2.0 | 4 votes |
@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(); } }