use of org.apache.camel.spring.SpringCamelContext in project syndesis by syndesisio.
the class ExtensionStepHandlerTest method testEndpointExtensionStepHandler.
@Test
public void testEndpointExtensionStepHandler() throws Exception {
final CamelContext context = new SpringCamelContext(applicationContext);
try {
final RouteBuilder routes = newIntegrationRouteBuilder(new io.syndesis.common.model.integration.Step.Builder().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().stepKind(StepKind.extension).action(new StepAction.Builder().descriptor(new StepDescriptor.Builder().kind(StepAction.Kind.ENDPOINT).entrypoint("log:myLog").build()).build()).putConfiguredProperty("Property-1", "Val-1").putConfiguredProperty("Property-2", "Val-2").build(), new io.syndesis.common.model.integration.Step.Builder().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.setAutoStartup(false);
context.start();
// Dump routes as XML for troubleshooting
dumpRoutes(context);
RouteDefinition routeDefinition = context.getRouteDefinition("test-integration");
assertThat(routeDefinition).isNotNull();
List<ProcessorDefinition<?>> processors = routeDefinition.getOutputs();
assertThat(processors).hasSize(7);
assertThat(processors.get(1)).isInstanceOf(SetHeaderDefinition.class);
assertThat(SetHeaderDefinition.class.cast(processors.get(1)).getHeaderName()).isEqualTo("Property-1");
assertThat(processors.get(2)).isInstanceOf(SetHeaderDefinition.class);
assertThat(SetHeaderDefinition.class.cast(processors.get(2)).getHeaderName()).isEqualTo("Property-2");
assertThat(processors.get(3)).isInstanceOf(ToDefinition.class);
assertThat(ToDefinition.class.cast(processors.get(3)).getUri()).isEqualTo("log:myLog");
} finally {
context.stop();
}
}
use of org.apache.camel.spring.SpringCamelContext in project syndesis by syndesisio.
the class ExtensionStepHandlerTest method testStepExtensionStepHandler.
@Test
public void testStepExtensionStepHandler() throws Exception {
final CamelContext context = new SpringCamelContext(applicationContext);
try {
final RouteBuilder routes = newIntegrationRouteBuilder(new io.syndesis.common.model.integration.Step.Builder().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().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().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.setAutoStartup(false);
context.start();
// Dump routes as XML for troubleshooting
dumpRoutes(context);
RouteDefinition routeDefinition = context.getRouteDefinition("test-integration");
assertThat(routeDefinition).isNotNull();
assertThat(routeDefinition).hasFieldOrPropertyWithValue("id", "test-integration");
List<ProcessorDefinition<?>> processors = routeDefinition.getOutputs();
assertThat(processors).hasSize(6);
assertThat(processors.get(1)).isInstanceOf(SetHeaderDefinition.class);
assertThat(SetHeaderDefinition.class.cast(processors.get(1)).getHeaderName()).isEqualTo("param1");
assertThat(SetHeaderDefinition.class.cast(processors.get(1)).getExpression()).isInstanceOf(ConstantExpression.class);
assertThat(SetHeaderDefinition.class.cast(processors.get(1)).getExpression().getExpression()).isEqualTo("Val-1");
assertThat(processors.get(2)).isInstanceOf(SetHeaderDefinition.class);
assertThat(SetHeaderDefinition.class.cast(processors.get(2)).getHeaderName()).isEqualTo("param2");
assertThat(SetHeaderDefinition.class.cast(processors.get(2)).getExpression()).isInstanceOf(ConstantExpression.class);
assertThat(SetHeaderDefinition.class.cast(processors.get(2)).getExpression().getExpression()).isEqualTo("Val-2");
} finally {
context.stop();
}
}
use of org.apache.camel.spring.SpringCamelContext in project syndesis by syndesisio.
the class ExtensionStepHandlerTest method testBeanExtensionStepHandler.
@Test
public void testBeanExtensionStepHandler() throws Exception {
final CamelContext context = new SpringCamelContext(applicationContext);
try {
final RouteBuilder routes = newIntegrationRouteBuilder(new io.syndesis.common.model.integration.Step.Builder().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().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().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.setAutoStartup(false);
context.start();
// Dump routes as XML for troubleshooting
dumpRoutes(context);
RouteDefinition routeDefinition = context.getRouteDefinition("test-integration");
assertThat(routeDefinition).isNotNull();
List<ProcessorDefinition<?>> processors = routeDefinition.getOutputs();
assertThat(processors).hasSize(5);
assertThat(processors.get(1)).isInstanceOf(ToDefinition.class);
assertThat(processors.get(1)).hasFieldOrPropertyWithValue("uri", "class:io.syndesis.integration.runtime.handlers.ExtensionStepHandlerTest$MyExtension?method=action&bean.param1=Val-1&bean.param2=Val-2");
} finally {
context.stop();
}
}
use of org.apache.camel.spring.SpringCamelContext in project syndesis by syndesisio.
the class SimpleEndpointStepHandlerTest method testSimpleEndpointStepWithSplit.
@Test
public void testSimpleEndpointStepWithSplit() throws Exception {
final CamelContext context = new SpringCamelContext(applicationContext);
try {
final RouteBuilder routes = newIntegrationRouteBuilder(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").split(new Split.Builder().language("tokenize").expression("|").build()).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.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();
} finally {
context.stop();
}
}
use of org.apache.camel.spring.SpringCamelContext in project syndesis by syndesisio.
the class SplitStepHandlerTest method testTokenizeBodyStep.
@Test
public void testTokenizeBodyStep() throws Exception {
final CamelContext context = new SpringCamelContext(applicationContext);
try {
final RouteBuilder routes = newIntegrationRouteBuilder(new Step.Builder().stepKind(StepKind.endpoint).action(new ConnectorAction.Builder().descriptor(new ConnectorDescriptor.Builder().componentScheme("direct").putConfiguredProperty("name", "expression").build()).build()).build(), new Step.Builder().stepKind(StepKind.split).build(), new Step.Builder().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.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();
} finally {
context.stop();
}
}
Aggregations