Java Code Examples for org.apache.camel.impl.DefaultCamelContext#stop()
The following examples show how to use
org.apache.camel.impl.DefaultCamelContext#stop() .
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 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 2
Source File: SplitStepHandlerJsonTest.java From syndesis with Apache License 2.0 | 5 votes |
/** * Test multiple split steps in an integration, both split operating to the very end of an integration - no aggregate * direct -> split -> log -> split -> mock */ @Test public void testMultipleSplit() throws Exception { final DefaultCamelContext context = new DefaultCamelContext(); try { final RouteBuilder routes = new IntegrationRouteBuilder( "classpath:/syndesis/integration/multiple-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("a", "b", "c", "de", "f", "g"); 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 filter step that lives inside of a split/aggregate. Only the filtered matches should be aggregated. * direct -> split -> filter -> log -> aggregate -> mock */ @Test public void testFilterInSplitAggregate() throws Exception { final DefaultCamelContext context = new DefaultCamelContext(); try { final RouteBuilder routes = new IntegrationRouteBuilder( "classpath:/syndesis/integration/filter-in-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(); List<?> bodyReceived = result.getExchanges().get(0).getIn().getBody(List.class); assertThat(bodyReceived).hasSize(1); assertThat(bodyReceived.get(0)).isEqualTo("{\"task\": \"Wash the dog\"}"); } finally { context.stop(); } }
Example 4
Source File: SplitStepHandlerJsonTest.java From syndesis with Apache License 2.0 | 5 votes |
/** * Test simple split/aggregate use case. * direct -> split -> log -> aggregate -> mock */ @Test public void testSplitAggregate() throws Exception { final DefaultCamelContext context = new DefaultCamelContext(); try { final RouteBuilder routes = new IntegrationRouteBuilder( "classpath:/syndesis/integration/split-aggregate.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"); result.expectedMessageCount(1); template.sendBody("direct:expression", body); result.assertIsSatisfied(); List<?> bodyReceived = result.getExchanges().get(0).getIn().getBody(List.class); assertThat(bodyReceived).hasSize(3); assertThat(bodyReceived.get(0)).isEqualTo("a"); assertThat(bodyReceived.get(1)).isEqualTo("b"); assertThat(bodyReceived.get(2)).isEqualTo("c"); } finally { context.stop(); } }
Example 5
Source File: ODataSerializerTest.java From syndesis with Apache License 2.0 | 5 votes |
@Test public void testSchemaAlignmentToResult() throws Exception { context = new DefaultCamelContext(); context.disableJMX(); context.start(); try { String serviceURI = defaultTestServer.servicePlainUri(); String resourcePath = defaultTestServer.resourcePath(); String keyPredicate = "1"; // Fetch the actual json as will be returned by the camel context String jsonResult = fetchReferenceEntity( serviceURI + FORWARD_SLASH + resourcePath + OPEN_BRACKET + keyPredicate + CLOSE_BRACKET); JsonNode jsonResultNode = OBJECT_MAPPER.readTree(jsonResult); // Fetch the json schema as created by metadata retrieval String schema = getMetadataSchema(serviceURI, resourcePath, keyPredicate); JsonNode schemaNode = OBJECT_MAPPER.readTree(schema); // Validate the result against the schema validateResultAgainstSchema(jsonResultNode, schemaNode); } finally { if (context != null) { context.stop(); context = null; } } }
Example 6
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 7
Source File: FilterStepHandlerTest.java From syndesis with Apache License 2.0 | 4 votes |
@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 8
Source File: DataMapperStepHandlerTest.java From syndesis with Apache License 2.0 | 4 votes |
@Test public void testJsonTypeProcessors() throws Exception { final DefaultCamelContext context = new DefaultCamelContext(); try { final RouteBuilder routeBuilder = newIntegrationRouteBuilder(getTestSteps("{" + "\"AtlasMapping\":{" + "\"dataSource\":[" + "{\"jsonType\":\"" + DataMapperStepHandler.ATLASMAP_JSON_DATA_SOURCE + "\",\"id\":\"source\",\"uri\":\"atlas:json:source\",\"dataSourceType\":\"SOURCE\"}," + "{\"jsonType\":\"" + DataMapperStepHandler.ATLASMAP_JSON_DATA_SOURCE + "\",\"id\":\"target\",\"uri\":\"atlas:json:target\",\"dataSourceType\":\"TARGET\",\"template\":null}" + "]," + "\"mappings\":{}" + "}" + "}")); // Set up the camel context context.addRoutes(routeBuilder); context.start(); // Dump routes as XML for troubleshooting dumpRoutes(context); List<RouteDefinition> routes = context.getRouteDefinitions(); assertThat(routes).hasSize(1); RouteDefinition route = context.getRouteDefinitions().get(0); assertThat(route).isNotNull(); assertThat(route.getInput()).isNotNull(); assertThat(route.getInput()).hasFieldOrPropertyWithValue("uri", "direct:start"); assertThat(route.getOutputs()).hasSize(5); assertThat(route.getOutputs().get(0)).isInstanceOf(PipelineDefinition.class); assertThat(route.getOutputs().get(0).getOutputs()).hasSize(2); assertThat(route.getOutputs().get(0).getOutputs().get(0)).isInstanceOf(SetHeaderDefinition.class); assertThat(route.getOutputs().get(0).getOutputs().get(1)).isInstanceOf(SetHeaderDefinition.class); assertThat(route.getOutputs().get(1)).isInstanceOf(SetHeaderDefinition.class); assertThat(route.getOutputs().get(2)).isInstanceOf(ProcessDefinition.class); // Atlas assertThat(route.getOutputs().get(3)).isInstanceOf(PipelineDefinition.class); assertThat(route.getOutputs().get(3).getOutputs()).hasSize(5); assertThat(route.getOutputs().get(3).getOutputs().get(0)).isInstanceOf(SetHeaderDefinition.class); assertThat(route.getOutputs().get(3).getOutputs().get(1)).isInstanceOf(ProcessDefinition.class); assertThat(route.getOutputs().get(3).getOutputs().get(2)).isInstanceOf(ToDefinition.class); assertThat(route.getOutputs().get(3).getOutputs().get(2)).hasFieldOrPropertyWithValue( "uri", "atlas:mapping-flow-0-step-1.json?encoding=UTF-8&sourceMapName=" + OutMessageCaptureProcessor.CAPTURED_OUT_MESSAGES_MAP ); assertThat(route.getOutputs().get(3).getOutputs().get(3)).isInstanceOf(ProcessDefinition.class); assertThat(route.getOutputs().get(3).getOutputs().get(4)).isInstanceOf(ProcessDefinition.class); assertThat(route.getOutputs().get(4)).isInstanceOf(PipelineDefinition.class); assertThat(route.getOutputs().get(4).getOutputs()).hasSize(3); assertThat(route.getOutputs().get(4).getOutputs().get(0)).isInstanceOf(SetHeaderDefinition.class); assertThat(route.getOutputs().get(4).getOutputs().get(1)).isInstanceOf(ToDefinition.class); assertThat(route.getOutputs().get(4).getOutputs().get(1)).hasFieldOrPropertyWithValue("uri", "mock:result"); assertThat(route.getOutputs().get(4).getOutputs().get(2)).isInstanceOf(ProcessDefinition.class); } finally { context.stop(); } }
Example 9
Source File: DataMapperStepHandlerTest.java From syndesis with Apache License 2.0 | 4 votes |
@Test public void testJsonTypeProcessorsSkip() throws Exception { final DefaultCamelContext context = new DefaultCamelContext(); try { final RouteBuilder routeBuilder = newIntegrationRouteBuilder(getTestSteps("{" + "\"AtlasMapping\":{" + "\"dataSource\":[" + "{\"jsonType\":\"io.atlasmap.v2.DataSource\",\"id\":\"source\",\"uri\":\"atlas:java?className=twitter4j.Status\",\"dataSourceType\":\"SOURCE\"}," + "{\"jsonType\":\"io.atlasmap.v2.DataSource\",\"id\":\"target\",\"uri\":\"atlas:java?className=io.syndesis.connector.gmail.GmailMessageModel\",\"dataSourceType\":\"TARGET\",\"template\":null}" + "]," + "\"mappings\":{}" + "}" + "}")); // Set up the camel context context.addRoutes(routeBuilder); context.start(); // Dump routes as XML for troubleshooting dumpRoutes(context); List<RouteDefinition> routes = context.getRouteDefinitions(); assertThat(routes).hasSize(1); RouteDefinition route = context.getRouteDefinitions().get(0); assertThat(route).isNotNull(); assertThat(route.getInput()).isNotNull(); assertThat(route.getInput()).hasFieldOrPropertyWithValue("uri", "direct:start"); assertThat(route.getOutputs()).hasSize(5); assertThat(route.getOutputs().get(0)).isInstanceOf(PipelineDefinition.class); assertThat(route.getOutputs().get(0).getOutputs()).hasSize(2); assertThat(route.getOutputs().get(0).getOutputs().get(0)).isInstanceOf(SetHeaderDefinition.class); assertThat(route.getOutputs().get(0).getOutputs().get(1)).isInstanceOf(SetHeaderDefinition.class); assertThat(route.getOutputs().get(1)).isInstanceOf(SetHeaderDefinition.class); assertThat(route.getOutputs().get(2)).isInstanceOf(ProcessDefinition.class); // Atlas assertThat(route.getOutputs().get(3)).isInstanceOf(PipelineDefinition.class); assertThat(route.getOutputs().get(3).getOutputs()).hasSize(3); assertThat(route.getOutputs().get(3).getOutputs().get(0)).isInstanceOf(SetHeaderDefinition.class); assertThat(route.getOutputs().get(3).getOutputs().get(1)).isInstanceOf(ToDefinition.class); assertThat(route.getOutputs().get(3).getOutputs().get(1)).hasFieldOrPropertyWithValue( "uri", "atlas:mapping-flow-0-step-1.json?encoding=UTF-8&sourceMapName=" + OutMessageCaptureProcessor.CAPTURED_OUT_MESSAGES_MAP ); assertThat(route.getOutputs().get(3).getOutputs().get(2)).isInstanceOf(ProcessDefinition.class); assertThat(route.getOutputs().get(4)).isInstanceOf(PipelineDefinition.class); assertThat(route.getOutputs().get(4).getOutputs()).hasSize(3); assertThat(route.getOutputs().get(4).getOutputs().get(0)).isInstanceOf(SetHeaderDefinition.class); assertThat(route.getOutputs().get(4).getOutputs().get(1)).isInstanceOf(ToDefinition.class); assertThat(route.getOutputs().get(4).getOutputs().get(1)).hasFieldOrPropertyWithValue("uri", "mock:result"); assertThat(route.getOutputs().get(4).getOutputs().get(2)).isInstanceOf(ProcessDefinition.class); } finally { context.stop(); } }
Example 10
Source File: FilterStepHandlerTest.java From syndesis with Apache License 2.0 | 4 votes |
@Test public void testRuleFilterStepWithPOJO() 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<User> matchingMessages = Arrays.asList(new User("James"), new User("Roland")); final List<User> notMatchingMessages = Collections.singletonList(new User("Jimmy")); final ProducerTemplate template = context.createProducerTemplate(); final MockEndpoint result = context.getEndpoint("mock:result", MockEndpoint.class); List<User> 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 11
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 12
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 13
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 14
Source File: ExtensionStepHandlerTest.java From syndesis with Apache License 2.0 | 4 votes |
@Test public void testBeanExtensionStepHandler() throws Exception { final DefaultCamelContext context = new DefaultCamelContext(); try { final RouteBuilder routeBuilder = newIntegrationRouteBuilder( new io.syndesis.common.model.integration.Step.Builder() .id("step-1") .stepKind(StepKind.endpoint) .action(new ConnectorAction.Builder() .descriptor(new ConnectorDescriptor.Builder() .componentScheme("direct") .putConfiguredProperty("name", "start") .build()) .build()) .build(), new io.syndesis.common.model.integration.Step.Builder() .id("step-2") .stepKind(StepKind.extension) .action(new StepAction.Builder() .descriptor(new StepDescriptor.Builder() .kind(StepAction.Kind.BEAN) .entrypoint("io.syndesis.integration.runtime.handlers.ExtensionStepHandlerTest$MyExtension::action") .build()) .build()) .putConfiguredProperty("param1", "Val-1") .putConfiguredProperty("param2", "Val-2") .build(), new io.syndesis.common.model.integration.Step.Builder() .id("step-3") .stepKind(StepKind.endpoint) .action(new ConnectorAction.Builder() .descriptor(new ConnectorDescriptor.Builder() .componentScheme("mock") .putConfiguredProperty("name", "result") .build()) .build()) .build() ); // Set up the camel context context.addRoutes(routeBuilder); context.setAutoStartup(false); context.start(); // Dump routes as XML for troubleshooting dumpRoutes(context); List<RouteDefinition> routes = context.getRouteDefinitions(); assertThat(routes).hasSize(1); RouteDefinition route = context.getRouteDefinitions().get(0); assertThat(route).isNotNull(); assertThat(route.getInput()).isNotNull(); assertThat(route.getInput()).hasFieldOrPropertyWithValue("uri", "direct:start"); assertThat(route.getOutputs()).hasSize(5); assertThat(route.getOutputs().get(0)).isInstanceOf(PipelineDefinition.class); assertThat(route.getOutputs().get(0).getOutputs()).hasSize(2); assertThat(route.getOutputs().get(0).getOutputs().get(0)).isInstanceOf(SetHeaderDefinition.class); assertThat(route.getOutputs().get(0).getOutputs().get(1)).isInstanceOf(SetHeaderDefinition.class); assertThat(route.getOutputs().get(1)).isInstanceOf(SetHeaderDefinition.class); assertThat(route.getOutputs().get(2)).isInstanceOf(ProcessDefinition.class); assertThat(route.getOutputs().get(3)).isInstanceOf(PipelineDefinition.class); assertThat(route.getOutputs().get(3).getOutputs()).hasSize(3); assertThat(route.getOutputs().get(3).getOutputs().get(0)).isInstanceOf(SetHeaderDefinition.class); assertThat(route.getOutputs().get(3).getOutputs().get(1)).isInstanceOf(ToDefinition.class); assertThat(route.getOutputs().get(3).getOutputs().get(1)).hasFieldOrPropertyWithValue( "uri", "class:io.syndesis.integration.runtime.handlers.ExtensionStepHandlerTest$MyExtension?method=action&bean.param1=Val-1&bean.param2=Val-2" ); assertThat(route.getOutputs().get(3).getOutputs().get(2)).isInstanceOf(ProcessDefinition.class); assertThat(route.getOutputs().get(4)).isInstanceOf(PipelineDefinition.class); assertThat(route.getOutputs().get(4).getOutputs()).hasSize(3); assertThat(route.getOutputs().get(4).getOutputs().get(0)).isInstanceOf(SetHeaderDefinition.class); assertThat(route.getOutputs().get(4).getOutputs().get(1)).isInstanceOf(ToDefinition.class); assertThat(route.getOutputs().get(4).getOutputs().get(1)).hasFieldOrPropertyWithValue("uri", "mock:result"); assertThat(route.getOutputs().get(4).getOutputs().get(2)).isInstanceOf(ProcessDefinition.class); } finally { context.stop(); } }
Example 15
Source File: ExtensionStepHandlerTest.java From syndesis with Apache License 2.0 | 4 votes |
@Test public void testStepExtensionStepHandler() throws Exception { final DefaultCamelContext context = new DefaultCamelContext(); try { final RouteBuilder routeBuilder = newIntegrationRouteBuilder( new io.syndesis.common.model.integration.Step.Builder() .id("step-1") .stepKind(StepKind.endpoint) .action(new ConnectorAction.Builder() .descriptor(new ConnectorDescriptor.Builder() .componentScheme("direct") .putConfiguredProperty("name", "start") .build()) .build()) .build(), new io.syndesis.common.model.integration.Step.Builder() .id("step-2") .stepKind(StepKind.extension) .action(new StepAction.Builder() .descriptor(new StepDescriptor.Builder() .kind(StepAction.Kind.STEP) .entrypoint("io.syndesis.integration.runtime.handlers.ExtensionStepHandlerTest$MyStepExtension") .build()) .build()) .putConfiguredProperty("param1", "Val-1") .putConfiguredProperty("param2", "Val-2") .build(), new io.syndesis.common.model.integration.Step.Builder() .id("step-3") .stepKind(StepKind.endpoint) .action(new ConnectorAction.Builder() .descriptor(new ConnectorDescriptor.Builder() .componentScheme("mock") .putConfiguredProperty("name", "result") .build()) .build()) .build() ); // Set up the camel context context.addRoutes(routeBuilder); context.setAutoStartup(false); context.start(); // Dump routes as XML for troubleshooting dumpRoutes(context); RouteDefinition route = context.getRouteDefinitions().get(0); assertThat(route).isNotNull(); assertThat(route.getInput()).isNotNull(); assertThat(route.getInput()).hasFieldOrPropertyWithValue("uri", "direct:start"); assertThat(route.getOutputs()).hasSize(5); assertThat(route.getOutputs().get(0)).isInstanceOf(PipelineDefinition.class); assertThat(route.getOutputs().get(0).getOutputs()).hasSize(2); assertThat(route.getOutputs().get(0).getOutputs().get(0)).isInstanceOf(SetHeaderDefinition.class); assertThat(route.getOutputs().get(0).getOutputs().get(1)).isInstanceOf(SetHeaderDefinition.class); assertThat(route.getOutputs().get(1)).isInstanceOf(SetHeaderDefinition.class); assertThat(route.getOutputs().get(2)).isInstanceOf(ProcessDefinition.class); assertThat(route.getOutputs().get(3)).isInstanceOf(PipelineDefinition.class); assertThat(route.getOutputs().get(3).getOutputs()).hasSize(4); assertThat(route.getOutputs().get(3).getOutputs().get(0)).isInstanceOf(SetHeaderDefinition.class); assertThat(route.getOutputs().get(3).getOutputs().get(1)).isInstanceOf(SetHeaderDefinition.class); assertThat(route.getOutputs().get(3).getOutputs().get(1)).hasFieldOrPropertyWithValue("name", "param1"); assertThat(SetHeaderDefinition.class.cast(route.getOutputs().get(3).getOutputs().get(1)).getExpression()).hasFieldOrPropertyWithValue("expression", "Val-1"); assertThat(route.getOutputs().get(3).getOutputs().get(2)).isInstanceOf(SetHeaderDefinition.class); assertThat(route.getOutputs().get(3).getOutputs().get(2)).hasFieldOrPropertyWithValue("name", "param2"); assertThat(SetHeaderDefinition.class.cast(route.getOutputs().get(3).getOutputs().get(2)).getExpression()).hasFieldOrPropertyWithValue("expression", "Val-2"); assertThat(route.getOutputs().get(3).getOutputs().get(3)).isInstanceOf(ProcessDefinition.class); assertThat(route.getOutputs().get(4)).isInstanceOf(PipelineDefinition.class); assertThat(route.getOutputs().get(4).getOutputs()).hasSize(3); assertThat(route.getOutputs().get(4).getOutputs().get(0)).isInstanceOf(SetHeaderDefinition.class); assertThat(route.getOutputs().get(4).getOutputs().get(1)).isInstanceOf(ToDefinition.class); assertThat(route.getOutputs().get(4).getOutputs().get(1)).hasFieldOrPropertyWithValue("uri", "mock:result"); assertThat(route.getOutputs().get(4).getOutputs().get(2)).isInstanceOf(ProcessDefinition.class); } finally { context.stop(); } }
Example 16
Source File: SplitAggregateStepHandlerTest.java From syndesis with Apache License 2.0 | 4 votes |
@Test public void testSplitAggregate() 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", "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("a", "b", "c"); List<?> response = template.requestBody("direct:expression", body, List.class); result.assertIsSatisfied(); Assert.assertEquals(body, 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: 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 18
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 19
Source File: SplitStepHandlerJsonTest.java From syndesis with Apache License 2.0 | 4 votes |
/** * Test subsequent split/aggregate where a 1st split operates on a initial collection of elements and a * 2nd split operates on a completely new collection provided by some mock endpoint. * direct -> split -> log -> aggregate -> bean:myMock -> split -> log -> aggregate -> mock */ @Test public void testSubsequentSplitAggregate() throws Exception { final DefaultCamelContext context = new DefaultCamelContext(); try { final RouteBuilder routes = new IntegrationRouteBuilder( "classpath:/syndesis/integration/subsequent-split.json", Resources.loadServices(IntegrationStepHandler.class) ); // Set up the camel context context.addRoutes(routes); SimpleRegistry beanRegistry = new SimpleRegistry(); beanRegistry.bind("bodyLogger", new BodyLogger.Default()); beanRegistry.bind("myMock", (Processor) exchange -> exchange.getIn().setBody(Arrays.asList("d", "e", "f"))); context.setRegistry(beanRegistry); 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(1); template.sendBody("direct:expression", body); result.assertIsSatisfied(); List<?> bodyReceived = result.getExchanges().get(0).getIn().getBody(List.class); assertThat(bodyReceived).hasSize(3); assertThat(bodyReceived.get(0)).isEqualTo("d"); assertThat(bodyReceived.get(1)).isEqualTo("e"); assertThat(bodyReceived.get(2)).isEqualTo("f"); } finally { context.stop(); } }
Example 20
Source File: ChoiceStepHandlerTest.java From syndesis with Apache License 2.0 | 4 votes |
@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(); } }