Search in sources :

Example 46 with SpringCamelContext

use of org.apache.camel.spring.SpringCamelContext in project syndesis by syndesisio.

the class StepWithIdTest method testWithIdStep.

@Test
public void testWithIdStep() throws Exception {
    final CamelContext context = new SpringCamelContext(applicationContext);
    try {
        final RouteBuilder routes = newIntegrationRouteBuilder(new Step.Builder().id("endpoint-1").stepKind(StepKind.endpoint).action(new ConnectorAction.Builder().descriptor(new ConnectorDescriptor.Builder().componentScheme("direct").putConfiguredProperty("name", "expression").build()).build()).build(), new Step.Builder().id("split-1").stepKind(StepKind.split).build(), new Step.Builder().id("endpoint-2").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);
        RouteDefinition routeDefinition = context.getRouteDefinition("test-integration");
        assertThat(routeDefinition).isNotNull();
        assertThat(routeDefinition).hasFieldOrPropertyWithValue("id", "test-integration");
        assertThat(routeDefinition.getInputs()).hasSize(1);
        assertThat(routeDefinition.getInputs().get(0)).hasFieldOrPropertyWithValue("id", "endpoint-1");
        assertThat(routeDefinition.getOutputs()).hasSize(2);
        assertThat(routeDefinition.getOutputs().get(1)).hasFieldOrPropertyWithValue("id", "split-1");
        assertThat(routeDefinition.getOutputs().get(1).getOutputs()).hasSize(3);
        assertThat(routeDefinition.getOutputs().get(1).getOutputs().get(1)).hasFieldOrPropertyWithValue("id", "endpoint-2");
    } finally {
        context.stop();
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) SpringCamelContext(org.apache.camel.spring.SpringCamelContext) RouteBuilder(org.apache.camel.builder.RouteBuilder) RouteDefinition(org.apache.camel.model.RouteDefinition) 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)

Example 47 with SpringCamelContext

use of org.apache.camel.spring.SpringCamelContext in project syndesis by syndesisio.

the class IntegrationSchedulerTest method integrationSchedulerTest.

@Test
public void integrationSchedulerTest() throws Exception {
    final CamelContext context = new SpringCamelContext(applicationContext);
    try {
        final RouteBuilder routes = new IntegrationRouteBuilder("", Collections.emptyList()) {

            @Override
            protected Integration loadIntegration() throws IOException {
                Integration integration = newIntegration(new Step.Builder().id("step-1").stepKind(StepKind.endpoint).action(new ConnectorAction.Builder().descriptor(new ConnectorDescriptor.Builder().componentScheme("log").putConfiguredProperty("loggerName", "timer").build()).build()).build(), new Step.Builder().id("step-2").stepKind(StepKind.endpoint).action(new ConnectorAction.Builder().descriptor(new ConnectorDescriptor.Builder().componentScheme("mock").putConfiguredProperty("name", "timer").build()).build()).build());
                return new Integration.Builder().createFrom(integration).scheduler(new Scheduler.Builder().type(Scheduler.Type.timer).expression("1s").build()).build();
            }
        };
        // Set up the camel context
        context.addRoutes(routes);
        context.start();
        dumpRoutes(context);
        RouteDefinition routeDefinition = context.getRouteDefinition("test-integration");
        assertThat(routeDefinition).isNotNull();
        assertThat(routeDefinition).hasFieldOrPropertyWithValue("id", "test-integration");
        assertThat(routeDefinition.getInputs()).hasSize(1);
        assertThat(routeDefinition.getInputs().get(0).getEndpointUri()).isEqualTo("timer:integration?period=1s");
        assertThat(routeDefinition.getOutputs()).hasSize(4);
        assertThat(routeDefinition.getOutputs().get(0)).hasFieldOrPropertyWithValue("endpointUri", "log:timer");
        assertThat(routeDefinition.getOutputs().get(1)).isInstanceOf(ProcessDefinition.class);
        assertThat(routeDefinition.getOutputs().get(2)).hasFieldOrPropertyWithValue("endpointUri", "mock:timer");
        assertThat(routeDefinition.getOutputs().get(3)).isInstanceOf(ProcessDefinition.class);
        assertThat(routeDefinition.getInputs().get(0)).hasFieldOrPropertyWithValue("id", "integration-scheduler");
        assertThat(routeDefinition.getOutputs().get(0)).hasFieldOrPropertyWithValue("id", "step-1");
        assertThat(routeDefinition.getOutputs().get(1)).hasFieldOrPropertyWithValue("id", "step-1-capture");
        assertThat(routeDefinition.getOutputs().get(2)).hasFieldOrPropertyWithValue("id", "step-2");
        assertThat(routeDefinition.getOutputs().get(3)).hasFieldOrPropertyWithValue("id", "step-2-capture");
    } finally {
        context.stop();
    }
}
Also used : SpringCamelContext(org.apache.camel.spring.SpringCamelContext) CamelContext(org.apache.camel.CamelContext) Integration(io.syndesis.common.model.integration.Integration) RouteBuilder(org.apache.camel.builder.RouteBuilder) Scheduler(io.syndesis.common.model.integration.Scheduler) RouteBuilder(org.apache.camel.builder.RouteBuilder) SpringCamelContext(org.apache.camel.spring.SpringCamelContext) Step(io.syndesis.common.model.integration.Step) RouteDefinition(org.apache.camel.model.RouteDefinition) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 48 with SpringCamelContext

use of org.apache.camel.spring.SpringCamelContext in project citrus-samples by christophd.

the class EndpointConfig method camelContext.

@Bean
public CamelContext camelContext() throws Exception {
    SpringCamelContext context = new SpringCamelContext();
    context.addRouteDefinition(new RouteDefinition().from("jms:queue:JMS.Queue.News").to("log:com.consol.citrus.camel?level=INFO").to("spring-ws:http://localhost:18009?soapAction=newsFeed"));
    return context;
}
Also used : RouteDefinition(org.apache.camel.model.RouteDefinition) SpringCamelContext(org.apache.camel.spring.SpringCamelContext)

Example 49 with SpringCamelContext

use of org.apache.camel.spring.SpringCamelContext in project wildfly-camel by wildfly-extras.

the class SpringExplicitConfigurationTest method testSpringJavaConfig.

@Test
public void testSpringJavaConfig() throws Exception {
    AnnotationConfigApplicationContext appctx = new AnnotationConfigApplicationContext(MyConfiguration.class);
    CamelContext camelctx = new SpringCamelContext(appctx);
    camelctx.addRoutes(appctx.getBean(RouteBuilder.class));
    camelctx.start();
    try {
        ProducerTemplate producer = camelctx.createProducerTemplate();
        String result = producer.requestBody("direct:start", "Kermit", String.class);
        Assert.assertEquals("Hello Kermit", result);
    } finally {
        camelctx.close();
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) SpringCamelContext(org.apache.camel.spring.SpringCamelContext) ProducerTemplate(org.apache.camel.ProducerTemplate) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) RouteBuilder(org.apache.camel.builder.RouteBuilder) SpringCamelContext(org.apache.camel.spring.SpringCamelContext) Test(org.junit.Test)

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