org.apache.camel.spring.SpringCamelContext Java Examples

The following examples show how to use org.apache.camel.spring.SpringCamelContext. 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: SpringExplicitConfigurationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@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();
    }
}
 
Example #2
Source File: SpringCamelContextBootstrap.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes the Spring {@link GenericApplicationContext} and returns all instances of {@link SpringCamelContext} beans.
 *
 * Note that {@link SpringCamelContext} instances are created in the <b>stopped</b> state. Starting the {@link SpringCamelContext}
 * is left to the caller.
 *
 * @return Unmodifiable list of {@link SpringCamelContext} instances
 * @throws Exception
 */
public List<SpringCamelContext> createSpringCamelContexts() throws Exception {
    if (applicationContext.isActive()) {
        throw new IllegalStateException("Unable to refresh Spring application context. Context is already initialized");
    }

    SpringCamelContext.setNoStart(true);
    ProxyUtils.invokeProxied(new ProxiedAction() {
        @Override
        public void run() throws Exception {
            applicationContext.refresh();
        }
    }, applicationContext.getClassLoader());
    SpringCamelContext.setNoStart(false);

    return getSpringCamelContexts();
}
 
Example #3
Source File: SyncopeCamelContext.java    From syncope with Apache License 2.0 6 votes vote down vote up
public SpringCamelContext getCamelContext() {
    synchronized (this) {
        if (camelContext == null) {
            camelContext = ApplicationContextProvider.getBeanFactory().getBean(SpringCamelContext.class);
            camelContext.addRoutePolicyFactory(new MetricsRoutePolicyFactory());
        }

        if (camelContext.getRoutes().isEmpty()) {
            List<CamelRoute> routes = routeDAO.findAll();
            LOG.debug("{} route(s) are going to be loaded ", routes.size());

            loadRouteDefinitions(routes.stream().map(CamelRoute::getContent).collect(Collectors.toList()));
        }
    }

    return camelContext;
}
 
Example #4
Source File: ODataReadRouteSplitResultsTest.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@Test
public void testReferenceODataRouteWithCertificate() throws Exception {
    String resourcePath = "People";
    String queryParam = "$count=true";

    context = new SpringCamelContext(applicationContext);

    Connector odataConnector = createODataConnector(new PropertyBuilder<String>()
                                                        .property(SERVICE_URI, REF_SERVICE_URI)
                                                        .property(QUERY_PARAMS, queryParam)
                                                        .property(SERVER_CERTIFICATE, ODataTestServer.referenceServiceCertificate()));

    Step odataStep = createODataStep(odataConnector, resourcePath);
    Integration odataIntegration = createIntegration(odataStep, mockStep);

    RouteBuilder routes = newIntegrationRouteBuilder(odataIntegration);
    context.addRoutes(routes);
    MockEndpoint result = initMockEndpoint();
    result.setMinimumExpectedMessageCount(1);

    context.start();

    result.assertIsSatisfied();
    testResult(result, 0, REF_SERVER_PEOPLE_DATA_1);
}
 
Example #5
Source File: ODataReadRouteSplitResultsTest.java    From syndesis with Apache License 2.0 6 votes vote down vote up
/**
 * The reference server has a certificate trusted by the root certificates already
 * in the java cacerts keystore. Therefore, it should not be necessary to supply
 * a server certifcate.
 */
@Test
public void testReferenceODataRouteWithoutCertificate() throws Exception {
    String resourcePath = "People";
    String queryParam = "$count=true";

    context = new SpringCamelContext(applicationContext);

    Connector odataConnector = createODataConnector(new PropertyBuilder<String>()
                                                        .property(SERVICE_URI, REF_SERVICE_URI)
                                                        .property(QUERY_PARAMS, queryParam));

    Step odataStep = createODataStep(odataConnector, resourcePath);
    Integration odataIntegration = createIntegration(odataStep, mockStep);

    RouteBuilder routes = newIntegrationRouteBuilder(odataIntegration);
    context.addRoutes(routes);
    MockEndpoint result = initMockEndpoint();
    result.setMinimumExpectedMessageCount(1);

    context.start();

    result.assertIsSatisfied();
    testResult(result, 0, REF_SERVER_PEOPLE_DATA_1);
}
 
Example #6
Source File: ODataReadRouteSplitResultsTest.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@Test
public void testReferenceODataRouteKeyPredicate() throws Exception {
    String resourcePath = "Airports";
    String keyPredicate = "KLAX";

    context = new SpringCamelContext(applicationContext);

    Connector odataConnector = createODataConnector(new PropertyBuilder<String>()
                                                        .property(SERVICE_URI, REF_SERVICE_URI)
                                                        .property(KEY_PREDICATE, keyPredicate));

    Step odataStep = createODataStep(odataConnector, resourcePath);
    Integration odataIntegration = createIntegration(odataStep, mockStep);

    RouteBuilder routes = newIntegrationRouteBuilder(odataIntegration);
    context.addRoutes(routes);
    MockEndpoint result = initMockEndpoint();
    result.setMinimumExpectedMessageCount(1);

    context.start();

    result.assertIsSatisfied();
    testResult(result, 0, REF_SERVER_AIRPORT_DATA_KLAX);
}
 
Example #7
Source File: ODataReadRouteSplitResultsTest.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@Test
public void testReferenceODataRouteKeyPredicateAndSubPredicate() throws Exception {
    String resourcePath = "Airports";
    String keyPredicate = "('KLAX')/Location";

    context = new SpringCamelContext(applicationContext);

    Connector odataConnector = createODataConnector(new PropertyBuilder<String>()
                                                        .property(SERVICE_URI, REF_SERVICE_URI)
                                                        .property(KEY_PREDICATE, keyPredicate));

    Step odataStep = createODataStep(odataConnector, resourcePath);
    Integration odataIntegration = createIntegration(odataStep, mockStep);

    RouteBuilder routes = newIntegrationRouteBuilder(odataIntegration);
    context.addRoutes(routes);
    MockEndpoint result = initMockEndpoint();
    result.setMinimumExpectedMessageCount(1);

    context.start();

    result.assertIsSatisfied();
    testResult(result, 0, REF_SERVER_PEOPLE_DATA_KLAX_LOC);
}
 
Example #8
Source File: ODataReadRouteSplitResultsTest.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@Test
public void testReferenceODataRouteComplexValue() throws Exception {
    String resourcePath = "Airports";

    context = new SpringCamelContext(applicationContext);

    Connector odataConnector = createODataConnector(new PropertyBuilder<String>()
                                                        .property(SERVICE_URI, REF_SERVICE_URI));

    Step odataStep = createODataStep(odataConnector, resourcePath);
    Integration odataIntegration = createIntegration(odataStep, mockStep);

    RouteBuilder routes = newIntegrationRouteBuilder(odataIntegration);
    context.addRoutes(routes);
    MockEndpoint result = initMockEndpoint();
    result.setMinimumExpectedMessageCount(1);

    context.start();

    result.assertIsSatisfied();
    testResult(result, 0, REF_SERVER_AIRPORT_DATA_1);
}
 
Example #9
Source File: ODataReadRouteSplitResultsTest.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@Test
public void testReferenceODataRouteQueryWithFilterAndExpand() throws Exception {
    String resourcePath = "People";

    context = new SpringCamelContext(applicationContext);

    Connector odataConnector = createODataConnector(new PropertyBuilder<String>()
                                                        .property(SERVICE_URI, REF_SERVICE_URI)
                                                        .property(QUERY_PARAMS, "$filter=LastName eq 'Whyte'&$expand=Trips"));

    Step odataStep = createODataStep(odataConnector, resourcePath);
    Integration odataIntegration = createIntegration(odataStep, mockStep);

    RouteBuilder routes = newIntegrationRouteBuilder(odataIntegration);
    context.addRoutes(routes);
    MockEndpoint result = initMockEndpoint();
    result.setMinimumExpectedMessageCount(1);

    context.start();

    result.assertIsSatisfied();
    testResult(result, 0, REF_SERVER_PEOPLE_DATA_1_EXPANDED_TRIPS);
}
 
Example #10
Source File: SpringBootXmlCamelContextConfigurer.java    From camel-spring-boot with Apache License 2.0 5 votes vote down vote up
@Override
public void configure(ApplicationContext applicationContext, SpringCamelContext camelContext) {
    CamelConfigurationProperties config = applicationContext.getBean(CamelConfigurationProperties.class);
    if (config != null) {
        try {
            LOG.debug("Merging XML based CamelContext with Spring Boot configuration properties");
            CamelAutoConfiguration.doConfigureCamelContext(applicationContext, camelContext, config);
        } catch (Exception e) {
            throw RuntimeCamelException.wrapRuntimeCamelException(e);
        }
    }
}
 
Example #11
Source File: CamelContextActivationService.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Override
public void stop(StopContext context) {
    Collections.reverse(bootstraps);
    for (SpringCamelContextBootstrap bootstrap: bootstraps) {
        List<SpringCamelContext> camelctxList = bootstrap.getSpringCamelContexts();
        for (CamelContext camelctx : camelctxList) {
            try {
                camelctx.close();
            } catch (Exception ex) {
                LOGGER.warn("Cannot stop camel context: " + camelctx.getName(), ex);
            }
        }
    }
}
 
Example #12
Source File: SpringCamelContextBootstrap.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
/**
 * Returns all beans of type {@link SpringCamelContext} that are present in the Spring bean factory.
 * @return Unmodifiable list of {@link SpringCamelContext} instances
 */
public List<SpringCamelContext> getSpringCamelContexts() {
    List<SpringCamelContext> beans = new ArrayList<>();
    for (String name : applicationContext.getBeanNamesForType(SpringCamelContext.class)) {
        beans.add(applicationContext.getBean(name, SpringCamelContext.class));
    }

    return Collections.unmodifiableList(beans);
}
 
Example #13
Source File: SpringCamelContextFactory.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
/**
 * Create a single {@link SpringCamelContext} from the given URL
 * @throws IllegalStateException if the given URL does not contain a single context definition
 */
public static SpringCamelContext createSingleCamelContext(URL contextUrl, ClassLoader classsLoader) throws Exception {
    SpringCamelContextBootstrap bootstrap = new SpringCamelContextBootstrap(contextUrl, classsLoader);
    List<SpringCamelContext> list = bootstrap.createSpringCamelContexts();
    IllegalStateAssertion.assertEquals(1, list.size(), "Single context expected in: " + contextUrl);
    return list.get(0);
}
 
Example #14
Source File: AbstractKuduTest.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Override
protected CamelContext createCamelContext() {
    applicationContext = new AnnotationConfigApplicationContext(MockedKuduConfiguration.class);

    final CamelContext ctx = new SpringCamelContext(applicationContext);
    PropertiesComponent pc = new PropertiesComponent();
    pc.addLocation("classpath:test-options.properties");
    ctx.setPropertiesComponent(pc);
    return ctx;
}
 
Example #15
Source File: AbstractODataTest.java    From syndesis with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a camel context complete with a properties component that handles
 * lookups of secret values such as passwords. Fetches the values from external
 * properties file.
 */
protected CamelContext createCamelContext() {
    CamelContext ctx = new SpringCamelContext(applicationContext);
    PropertiesComponent pc = new PropertiesComponent("classpath:odata-test-options.properties");
    ctx.setPropertiesComponent(pc);
    return ctx;
}
 
Example #16
Source File: ODataReadRouteNoSplitResultsTest.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Test
public void testReferenceODataRouteIssue4791_2() throws Exception {
    String resourcePath = "Airports";
    String keyPredicate = "('KLAX')/Location";

    context = new SpringCamelContext(applicationContext);

    Connector odataConnector = createODataConnector(new PropertyBuilder<String>()
                                                        .property(SERVICE_URI, REF_SERVICE_URI)
                                                        .property(KEY_PREDICATE, keyPredicate));

    Step odataStep = createODataStep(odataConnector, resourcePath);
    Integration odataIntegration = createIntegration(odataStep, mockStep);

    RouteBuilder routes = newIntegrationRouteBuilder(odataIntegration);
    context.addRoutes(routes);
    MockEndpoint result = initMockEndpoint();
    result.setMinimumExpectedMessageCount(1);

    context.start();

    result.assertIsSatisfied();
    //
    // Return singleton json object rather than list due to key predicate
    //
    testResult(result, 0, REF_SERVER_PEOPLE_DATA_KLAX_LOC);
}
 
Example #17
Source File: ODataReadRouteNoSplitResultsTest.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Test
public void testReferenceODataRouteIssue4791_1() throws Exception {
    String resourcePath = "Airports";
    String keyPredicate = "KLAX";

    context = new SpringCamelContext(applicationContext);

    Connector odataConnector = createODataConnector(new PropertyBuilder<String>()
                                                        .property(SERVICE_URI, REF_SERVICE_URI)
                                                        .property(KEY_PREDICATE, keyPredicate));

    Step odataStep = createODataStep(odataConnector, resourcePath);
    Integration odataIntegration = createIntegration(odataStep, mockStep);

    RouteBuilder routes = newIntegrationRouteBuilder(odataIntegration);
    context.addRoutes(routes);
    MockEndpoint result = initMockEndpoint();
    result.setMinimumExpectedMessageCount(1);

    context.start();

    result.assertIsSatisfied();
    //
    // Return singleton json object rather than list due to key predicate
    //
    testResult(result, 0, REF_SERVER_AIRPORT_DATA_KLAX);
}
 
Example #18
Source File: ODataReadRouteNoSplitResultsTest.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Test
@Ignore("Run manually as not strictly required")
public void testReferenceODataRoute() throws Exception {
    String resourcePath = "People";
    String queryParam = "$count=true";

    context = new SpringCamelContext(applicationContext);

    Connector odataConnector = createODataConnector(new PropertyBuilder<String>()
                                                        .property(SERVICE_URI, REF_SERVICE_URI)
                                                        .property(QUERY_PARAMS, queryParam)
                                                        .property(SERVER_CERTIFICATE, ODataTestServer.referenceServiceCertificate()));

    Step odataStep = createODataStep(odataConnector, resourcePath);
    Integration odataIntegration = createIntegration(odataStep, mockStep);

    RouteBuilder routes = newIntegrationRouteBuilder(odataIntegration);
    context.addRoutes(routes);
    MockEndpoint result = initMockEndpoint();
    result.setMinimumExpectedMessageCount(1);

    context.start();

    result.assertIsSatisfied();

    @SuppressWarnings( "unchecked" )
    List<String> json = extractJsonFromExchgMsg(result, 0, List.class);
    assertEquals(20, json.size());

    String expected = testData(REF_SERVER_PEOPLE_DATA_1);
    assertThatJson(json.get(0)).isEqualTo(expected);
    expected = testData(REF_SERVER_PEOPLE_DATA_2);
    assertThatJson(json.get(1)).isEqualTo(expected);
    expected = testData(REF_SERVER_PEOPLE_DATA_3);
    assertThatJson(json.get(2)).isEqualTo(expected);
}
 
Example #19
Source File: AbstractEmailTest.java    From syndesis with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a camel context complete with a properties component that handles
 * lookups of secret values such as passwords. Fetches the values from external
 * properties file.
 *
 * @return CamelContext
 */
protected CamelContext createCamelContext() {
    CamelContext ctx = new SpringCamelContext(applicationContext);
    ctx.disableJMX();
    ctx.init();

    PropertiesComponent pc = new PropertiesComponent();
    pc.addLocation(new PropertiesLocation("classpath:mail-test-options.properties"));
    ctx.setPropertiesComponent(pc);
    return ctx;
}
 
Example #20
Source File: CamelSteps.java    From yaks with Apache License 2.0 5 votes vote down vote up
@Given("^New Spring Camel context$")
public void camelContext(String beans) {
    destroyCamelContext();

    try {
        ApplicationContext ctx = new GenericXmlApplicationContext(new ByteArrayResource(beans.getBytes(StandardCharsets.UTF_8)));
        camelContext = ctx.getBean(SpringCamelContext.class);
        camelContext.start();
    } catch (Exception e) {
        throw new IllegalStateException("Failed to start Spring Camel context", e);
    }
}
 
Example #21
Source File: TestHelloCamelStartForContextInitialized.java    From bamboobsc with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(ServletContextEvent event) throws Exception {
	CamelContext context = new SpringCamelContext( AppContext.getApplicationContext() );
	context.start();		
}
 
Example #22
Source File: JpaTest.java    From camelinaction with Apache License 2.0 4 votes vote down vote up
@Override
protected CamelContext createCamelContext() throws Exception {
    applicationContext = new ClassPathXmlApplicationContext("META-INF/spring/camel-context.xml");
    return SpringCamelContext.springCamelContext(applicationContext);
}
 
Example #23
Source File: SpringCamelContextFactory.java    From wildfly-camel with Apache License 2.0 4 votes vote down vote up
/**
 * Create a {@link SpringCamelContext} list from the given URL
 */
public static List<SpringCamelContext> createCamelContextList(URL contextUrl, ClassLoader classsLoader) throws Exception {
    SpringCamelContextBootstrap bootstrap = new SpringCamelContextBootstrap(contextUrl, classsLoader);
    return bootstrap.createSpringCamelContexts();
}
 
Example #24
Source File: SpringCamelContextFactory.java    From wildfly-camel with Apache License 2.0 4 votes vote down vote up
/**
 * Create a {@link SpringCamelContext} list from the given bytes
 */
public static List<SpringCamelContext> createCamelContextList(byte[] bytes, ClassLoader classsLoader) throws Exception {
    SpringCamelContextBootstrap bootstrap = new SpringCamelContextBootstrap(bytes, classsLoader);
    return bootstrap.createSpringCamelContexts();
}
 
Example #25
Source File: OutMessageCaptureProcessorTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Test
public void testCaptureWithSplitAggregateAndSchedule() throws Exception {
    final SpringCamelContext context = new SpringCamelContext(applicationContext);

    try {
        Integration integration = newIntegration(
            new Step.Builder()
                .id("s1")
                .stepKind(StepKind.endpoint)
                .action(new ConnectorAction.Builder()
                    .descriptor(new ConnectorDescriptor.Builder()
                        .componentScheme("direct")
                        .putConfiguredProperty("name", "getdata")
                        .build())
                    .build())
                .build(),
            new Step.Builder()
                .id("s-split")
                .stepKind(StepKind.split)
                .build(),
            new Step.Builder()
                .id("s2")
                .stepKind(StepKind.extension)
                .action(new StepAction.Builder()
                    .descriptor(new StepDescriptor.Builder()
                        .kind(StepAction.Kind.BEAN)
                        .entrypoint(Bean1.class.getName())
                        .build())
                    .build())
                .build(),
            new Step.Builder()
                .id("s3")
                .stepKind(StepKind.endpoint)
                .action(new ConnectorAction.Builder()
                    .descriptor(new ConnectorDescriptor.Builder()
                        .componentScheme("mock")
                        .putConfiguredProperty("name", "expression")
                        .build())
                    .build())
                .build(),
            new Step.Builder()
                .id("s-aggregate")
                .stepKind(StepKind.aggregate)
                .build()
        );

        final Flow flow = integration.getFlows().get(0);
        final Flow flowWithScheduler = flow.builder()
            .scheduler(new Scheduler.Builder()
                .expression("60s")
                .build())
        .build();

        integration = new Integration.Builder()
            .createFrom(integration)
            .flows(singleton(flowWithScheduler))
            .build();

        IntegrationRouteBuilder routes = newIntegrationRouteBuilder(integration);
        routes.from("direct:getdata").bean(new Bean3());

        // Set up the camel context

        context.addRoutes(routes);
        context.start();

        // Dump routes as XML for troubleshooting
        dumpRoutes(context);

        final MockEndpoint result = context.getEndpoint("mock:expression", MockEndpoint.class);
        result.expectedBodiesReceived("Hello Hiram", "Hello World");
        result.assertIsSatisfied();

        Exchange exchange1 = result.getExchanges().get(0);
        Map<String, Message> messages = OutMessageCaptureProcessor.getCapturedMessageMap(exchange1);
        assertThat(messages.get("s-split").getBody()).isEqualTo("Hiram");
        assertThat(messages.get("s2").getBody()).isEqualTo("Hello Hiram");

        Exchange exchange2 = result.getExchanges().get(1);
        Map<String, Message> messages2 = OutMessageCaptureProcessor.getCapturedMessageMap(exchange2);
        assertThat(messages2.get("s-split").getBody()).isEqualTo("World");
        assertThat(messages2.get("s2").getBody()).isEqualTo("Hello World");
    } finally {
        context.stop();
    }
}
 
Example #26
Source File: OutMessageCaptureProcessorTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Test
public void testCaptureWithSplitAggregate() throws Exception {
    final SpringCamelContext context = new SpringCamelContext(applicationContext);

    try {
        final RouteBuilder routes = newIntegrationRouteBuilder(
            new Step.Builder()
                .id("s1")
                .stepKind(StepKind.endpoint)
                .action(new ConnectorAction.Builder()
                    .descriptor(new ConnectorDescriptor.Builder()
                        .componentScheme("direct")
                        .putConfiguredProperty("name", "expression")
                        .build())
                    .build())
                .build(),
            new Step.Builder()
                .id("s-split")
                .stepKind(StepKind.split)
                .build(),
            new Step.Builder()
                .id("s2")
                .stepKind(StepKind.extension)
                .action(new StepAction.Builder()
                    .descriptor(new StepDescriptor.Builder()
                        .kind(StepAction.Kind.BEAN)
                        .entrypoint(Bean1.class.getName())
                        .build())
                    .build())
                .build(),
            new Step.Builder()
                .id("s3")
                .stepKind(StepKind.extension)
                .action(new StepAction.Builder()
                    .descriptor(new StepDescriptor.Builder()
                        .kind(StepAction.Kind.BEAN)
                        .entrypoint(Bean2.class.getName())
                        .build())
                    .build())
                .build(),
            new Step.Builder()
                .id("s4")
                .stepKind(StepKind.endpoint)
                .action(new ConnectorAction.Builder()
                    .descriptor(new ConnectorDescriptor.Builder()
                        .componentScheme("mock")
                        .putConfiguredProperty("name", "expression")
                        .build())
                    .build())
                .build(),
            new Step.Builder()
                .id("s-aggregate")
                .stepKind(StepKind.aggregate)
                .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);

        result.expectedBodiesReceived("-862545276");
        template.sendBody("direct:expression", "World");
        result.assertIsSatisfied();

        Exchange exchange1 = result.getExchanges().get(0);
        Map<String, Message> messages = OutMessageCaptureProcessor.getCapturedMessageMap(exchange1);
        assertThat(messages).hasSize(5);
        assertThat(messages.get("s-split").getBody()).isEqualTo("World");
        assertThat(messages.get("s2").getBody()).isEqualTo("Hello World");
        assertThat(messages.get("s3").getBody()).isEqualTo(-862545276);
        assertThat(messages.get("s4").getBody()).isEqualTo(-862545276);
        assertThat(messages.get("s-aggregate").getBody()).isEqualTo(Collections.singletonList(-862545276));
    } finally {
        context.stop();
    }
}
 
Example #27
Source File: OutMessageCaptureProcessorTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Test
public void testCapture() throws Exception {
    final SpringCamelContext context = new SpringCamelContext(applicationContext);

    try {
        final RouteBuilder routes = newIntegrationRouteBuilder(
            new Step.Builder()
                .id("s1")
                .stepKind(StepKind.endpoint)
                .action(new ConnectorAction.Builder()
                    .descriptor(new ConnectorDescriptor.Builder()
                        .componentScheme("direct")
                        .putConfiguredProperty("name", "expression")
                        .build())
                    .build())
                .build(),
            new Step.Builder()
                .id("s2")
                .stepKind(StepKind.extension)
                .action(new StepAction.Builder()
                    .descriptor(new StepDescriptor.Builder()
                        .kind(StepAction.Kind.BEAN)
                        .entrypoint(Bean1.class.getName())
                        .build())
                    .build())
                .build(),
            new Step.Builder()
                .id("s3")
                .stepKind(StepKind.extension)
                .action(new StepAction.Builder()
                    .descriptor(new StepDescriptor.Builder()
                        .kind(StepAction.Kind.BEAN)
                        .entrypoint(Bean2.class.getName())
                        .build())
                    .build())
                .build(),
            new Step.Builder()
                .id("s4")
                .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);

        result.expectedBodiesReceived("-862545276");
        template.sendBody("direct:expression", "World");
        result.assertIsSatisfied();

        Exchange exchange1 = result.getExchanges().get(0);
        Map<String, Message> messages = OutMessageCaptureProcessor.getCapturedMessageMap(exchange1);
        assertThat(messages).hasSize(4);
        assertThat(messages.get("s1").getBody()).isEqualTo("World");
        assertThat(messages.get("s2").getBody()).isEqualTo("Hello World");
        assertThat(messages.get("s3").getBody()).isEqualTo(-862545276);
        assertThat(messages.get("s4").getBody()).isEqualTo(-862545276);
    } finally {
        context.stop();
    }
}
 
Example #28
Source File: SpringUtils.java    From wildfly-camel with Apache License 2.0 4 votes vote down vote up
public static ApplicationContext getApplicationContext(CamelContext camelctx) {
    IllegalArgumentAssertion.assertTrue(camelctx instanceof SpringCamelContext, "Not an SpringCamelContext: " + camelctx);
    return ((SpringCamelContext)camelctx).getApplicationContext();
}