Search in sources :

Example 41 with SpringCamelContext

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();
    }
}
Also used : SpringCamelContext(org.apache.camel.spring.SpringCamelContext) CamelContext(org.apache.camel.CamelContext) ToDefinition(org.apache.camel.model.ToDefinition) RouteBuilder(org.apache.camel.builder.RouteBuilder) RouteBuilder(org.apache.camel.builder.RouteBuilder) SpringCamelContext(org.apache.camel.spring.SpringCamelContext) ProcessorDefinition(org.apache.camel.model.ProcessorDefinition) RouteDefinition(org.apache.camel.model.RouteDefinition) StepAction(io.syndesis.common.model.action.StepAction) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) SetHeaderDefinition(org.apache.camel.model.SetHeaderDefinition) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 42 with SpringCamelContext

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();
    }
}
Also used : SpringCamelContext(org.apache.camel.spring.SpringCamelContext) CamelContext(org.apache.camel.CamelContext) RouteBuilder(org.apache.camel.builder.RouteBuilder) RouteBuilder(org.apache.camel.builder.RouteBuilder) SpringCamelContext(org.apache.camel.spring.SpringCamelContext) ProcessorDefinition(org.apache.camel.model.ProcessorDefinition) RouteDefinition(org.apache.camel.model.RouteDefinition) StepAction(io.syndesis.common.model.action.StepAction) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) SetHeaderDefinition(org.apache.camel.model.SetHeaderDefinition) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 43 with SpringCamelContext

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();
    }
}
Also used : SpringCamelContext(org.apache.camel.spring.SpringCamelContext) CamelContext(org.apache.camel.CamelContext) RouteBuilder(org.apache.camel.builder.RouteBuilder) RouteBuilder(org.apache.camel.builder.RouteBuilder) SpringCamelContext(org.apache.camel.spring.SpringCamelContext) ProcessorDefinition(org.apache.camel.model.ProcessorDefinition) RouteDefinition(org.apache.camel.model.RouteDefinition) StepAction(io.syndesis.common.model.action.StepAction) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 44 with SpringCamelContext

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();
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) SpringCamelContext(org.apache.camel.spring.SpringCamelContext) ProducerTemplate(org.apache.camel.ProducerTemplate) RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) RouteBuilder(org.apache.camel.builder.RouteBuilder) SpringCamelContext(org.apache.camel.spring.SpringCamelContext) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 45 with SpringCamelContext

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();
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) SpringCamelContext(org.apache.camel.spring.SpringCamelContext) ProducerTemplate(org.apache.camel.ProducerTemplate) RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) RouteBuilder(org.apache.camel.builder.RouteBuilder) SpringCamelContext(org.apache.camel.spring.SpringCamelContext) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) Step(io.syndesis.common.model.integration.Step) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

SpringCamelContext (org.apache.camel.spring.SpringCamelContext)49 CamelContext (org.apache.camel.CamelContext)21 Test (org.junit.Test)21 RouteBuilder (org.apache.camel.builder.RouteBuilder)17 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)16 ConnectorAction (io.syndesis.common.model.action.ConnectorAction)15 ProducerTemplate (org.apache.camel.ProducerTemplate)15 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)14 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)12 RouteDefinition (org.apache.camel.model.RouteDefinition)7 StepAction (io.syndesis.common.model.action.StepAction)6 Step (io.syndesis.common.model.integration.Step)6 DoToSpringCamelContextsStrategy (org.apache.camel.test.spring.CamelSpringTestHelper.DoToSpringCamelContextsStrategy)5 Method (java.lang.reflect.Method)4 LinkedList (java.util.LinkedList)4 PropertiesComponent (org.apache.camel.component.properties.PropertiesComponent)4 ProcessorDefinition (org.apache.camel.model.ProcessorDefinition)4 Breakpoint (org.apache.camel.spi.Breakpoint)4 Exchange (org.apache.camel.Exchange)3 ConnectorDescriptor (io.syndesis.common.model.action.ConnectorDescriptor)2