Java Code Examples for org.apache.camel.spring.SpringCamelContext#start()

The following examples show how to use org.apache.camel.spring.SpringCamelContext#start() . 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: 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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 9
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 10
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 11
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 12
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();
    }
}