org.apache.camel.component.mock.MockEndpoint

Here are the examples of the java api class org.apache.camel.component.mock.MockEndpoint taken from open source projects.

1. CamelJaxbTest#testUnmarshal()

Project: camel
Source File: CamelJaxbTest.java
View license
@Test
public void testUnmarshal() throws Exception {
    final String xml = "<Person><firstName>FOO</firstName><lastName>BAR</lastName></Person>";
    PersonType expected = new PersonType();
    expected.setFirstName("FOO");
    expected.setLastName("BAR");
    MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
    resultEndpoint.expectedBodiesReceived(expected);
    resultEndpoint.expectedHeaderReceived("foo", "bar");
    template.sendBodyAndHeader("direct:getJAXBElementValue", xml, "foo", "bar");
    resultEndpoint.assertIsSatisfied();
    resultEndpoint.reset();
    resultEndpoint.expectedMessageCount(1);
    template.sendBody("direct:getJAXBElement", xml);
    resultEndpoint.assertIsSatisfied();
    assertTrue("We should get the JAXBElement here", resultEndpoint.getExchanges().get(0).getIn().getBody() instanceof JAXBElement);
    resultEndpoint.reset();
    resultEndpoint.expectedMessageCount(1);
    resultEndpoint.expectedBodiesReceived(expected);
    template.sendBody("direct:unmarshall", xml);
    resultEndpoint.assertIsSatisfied();
}

2. QuartzTwoCamelContextSuspendResumeTest#testTwoCamelContextRestart()

View license
@Test
public void testTwoCamelContextRestart() throws Exception {
    MockEndpoint mock1 = camel1.getEndpoint("mock:one", MockEndpoint.class);
    mock1.expectedMinimumMessageCount(2);
    MockEndpoint mock2 = camel2.getEndpoint("mock:two", MockEndpoint.class);
    mock2.expectedMinimumMessageCount(6);
    mock1.assertIsSatisfied();
    camel1.suspend();
    mock2.assertIsSatisfied();
    // should resume triggers when we start camel 1 again
    mock1.reset();
    mock1.expectedMinimumMessageCount(2);
    camel1.resume();
    mock1.assertIsSatisfied();
}

3. QuartzTwoCamelContextSuspendResumeTest#testTwoCamelContextRestart()

View license
@Test
public void testTwoCamelContextRestart() throws Exception {
    MockEndpoint mock1 = camel1.getEndpoint("mock:one", MockEndpoint.class);
    mock1.expectedMinimumMessageCount(2);
    MockEndpoint mock2 = camel2.getEndpoint("mock:two", MockEndpoint.class);
    mock2.expectedMinimumMessageCount(6);
    mock1.assertIsSatisfied();
    camel1.suspend();
    mock2.assertIsSatisfied();
    // should resume triggers when we start camel 1 again
    mock1.reset();
    mock1.expectedMinimumMessageCount(2);
    camel1.resume();
    mock1.assertIsSatisfied();
}

4. JmsSelectorOptionTest#testJmsMessageWithSelector()

Project: camel
Source File: JmsSelectorOptionTest.java
View license
@Test
public void testJmsMessageWithSelector() throws Exception {
    MockEndpoint endpointA = getMockEndpoint("mock:a");
    MockEndpoint endpointB = getMockEndpoint("mock:b");
    MockEndpoint endpointC = getMockEndpoint("mock:c");
    endpointA.expectedBodiesReceivedInAnyOrder("A blue car!", "A blue car, again!");
    endpointA.expectedHeaderReceived("color", "blue");
    endpointB.expectedHeaderReceived("color", "red");
    endpointB.expectedBodiesReceived("A red car!");
    endpointC.expectedBodiesReceived("Message1", "Message2");
    endpointC.expectedMessageCount(2);
    template.sendBodyAndHeader("sjms:queue:hello", "A blue car!", "color", "blue");
    template.sendBodyAndHeader("sjms:queue:hello", "A red car!", "color", "red");
    template.sendBodyAndHeader("sjms:queue:hello", "A blue car, again!", "color", "blue");
    template.sendBodyAndHeader("sjms:queue:hello", "Message1", "SIZE_NUMBER", 1505);
    template.sendBodyAndHeader("sjms:queue:hello", "Message3", "SIZE_NUMBER", 1300);
    template.sendBodyAndHeader("sjms:queue:hello", "Message2", "SIZE_NUMBER", 1600);
    assertMockEndpointsSatisfied();
}

5. FilteringSpringTest#testFirstFilter()

View license
@Test
public void testFirstFilter() throws Exception {
    final MockEndpoint mockEndpointC = getMockEndpoint("mock:C");
    mockEndpointC.expectedMessageCount(1);
    mockEndpointC.expectedPropertyReceived(Exchange.FILTER_MATCHED, true);
    final MockEndpoint mockEndpointAfterC = getMockEndpoint("mock:afterC");
    mockEndpointAfterC.expectedMessageCount(1);
    // FILTER_MATCHED set to true if message matched previous Filter Predicate
    mockEndpointAfterC.expectedPropertyReceived(Exchange.FILTER_MATCHED, true);
    getMockEndpoint("mock:amel").expectedMessageCount(0);
    final MockEndpoint mockEndpointOther = getMockEndpoint("mock:other");
    mockEndpointOther.expectedMessageCount(1);
    // FILTER_MATCHED set to true if message matched previous Filter Predicate
    mockEndpointOther.expectedPropertyReceived(Exchange.FILTER_MATCHED, false);
    template.sendBody("direct:start", "Cooks Rocks");
    assertMockEndpointsSatisfied();
}

6. FilteringSpringTest#testSecondFilter()

View license
@Test
public void testSecondFilter() throws Exception {
    getMockEndpoint("mock:C").expectedMessageCount(0);
    final MockEndpoint mockEndpointAfterC = getMockEndpoint("mock:afterC");
    mockEndpointAfterC.expectedMessageCount(1);
    // FILTER_MATCHED set to true if message matched previous Filter Predicate
    mockEndpointAfterC.expectedPropertyReceived(Exchange.FILTER_MATCHED, false);
    final MockEndpoint mockEndpointAmel = getMockEndpoint("mock:amel");
    mockEndpointAmel.expectedMessageCount(1);
    mockEndpointAmel.expectedPropertyReceived(Exchange.FILTER_MATCHED, true);
    final MockEndpoint mockEndpointOther = getMockEndpoint("mock:other");
    mockEndpointOther.expectedMessageCount(1);
    // FILTER_MATCHED set to true if message matched previous Filter Predicate
    mockEndpointOther.expectedPropertyReceived(Exchange.FILTER_MATCHED, true);
    template.sendBody("direct:start", "amel is in Belgium");
    assertMockEndpointsSatisfied();
}

7. FilteringTest#testFirstFilter()

View license
@Test
public void testFirstFilter() throws Exception {
    final MockEndpoint mockEndpointC = getMockEndpoint("mock:C");
    mockEndpointC.expectedMessageCount(1);
    mockEndpointC.expectedPropertyReceived(Exchange.FILTER_MATCHED, true);
    final MockEndpoint mockEndpointAfterC = getMockEndpoint("mock:afterC");
    mockEndpointAfterC.expectedMessageCount(1);
    // FILTER_MATCHED set to true if message matched previous Filter Predicate
    mockEndpointAfterC.expectedPropertyReceived(Exchange.FILTER_MATCHED, true);
    getMockEndpoint("mock:amel").expectedMessageCount(0);
    final MockEndpoint mockEndpointOther = getMockEndpoint("mock:other");
    mockEndpointOther.expectedMessageCount(1);
    // FILTER_MATCHED set to true if message matched previous Filter Predicate
    mockEndpointOther.expectedPropertyReceived(Exchange.FILTER_MATCHED, false);
    template.sendBody("direct:start", "Cooks Rocks");
    assertMockEndpointsSatisfied();
}

8. FilteringTest#testSecondFilter()

View license
@Test
public void testSecondFilter() throws Exception {
    getMockEndpoint("mock:C").expectedMessageCount(0);
    final MockEndpoint mockEndpointAfterC = getMockEndpoint("mock:afterC");
    mockEndpointAfterC.expectedMessageCount(1);
    // FILTER_MATCHED set to true if message matched previous Filter Predicate
    mockEndpointAfterC.expectedPropertyReceived(Exchange.FILTER_MATCHED, false);
    final MockEndpoint mockEndpointAmel = getMockEndpoint("mock:amel");
    mockEndpointAmel.expectedMessageCount(1);
    mockEndpointAmel.expectedPropertyReceived(Exchange.FILTER_MATCHED, true);
    final MockEndpoint mockEndpointOther = getMockEndpoint("mock:other");
    mockEndpointOther.expectedMessageCount(1);
    // FILTER_MATCHED set to true if message matched previous Filter Predicate
    mockEndpointOther.expectedPropertyReceived(Exchange.FILTER_MATCHED, true);
    template.sendBody("direct:start", "amel is in Belgium");
    assertMockEndpointsSatisfied();
}

9. JmsSelectorOptionTest#testJmsMessageWithSelector()

Project: camel
Source File: JmsSelectorOptionTest.java
View license
@Test
public void testJmsMessageWithSelector() throws Exception {
    MockEndpoint endpointA = getMockEndpoint("mock:a");
    MockEndpoint endpointB = getMockEndpoint("mock:b");
    MockEndpoint endpointC = getMockEndpoint("mock:c");
    endpointA.expectedBodiesReceivedInAnyOrder("A blue car!", "A blue car, again!");
    endpointA.expectedHeaderReceived("color", "blue");
    endpointB.expectedHeaderReceived("color", "red");
    endpointB.expectedBodiesReceived("A red car!");
    endpointC.expectedBodiesReceived("Message1", "Message2");
    endpointC.expectedMessageCount(2);
    template.sendBodyAndHeader("activemq:queue:hello", "A blue car!", "color", "blue");
    template.sendBodyAndHeader("activemq:queue:hello", "A red car!", "color", "red");
    template.sendBodyAndHeader("activemq:queue:hello", "A blue car, again!", "color", "blue");
    template.sendBodyAndHeader("activemq:queue:hello", "Message1", "SIZE_NUMBER", 1505);
    template.sendBodyAndHeader("activemq:queue:hello", "Message3", "SIZE_NUMBER", 1300);
    template.sendBodyAndHeader("activemq:queue:hello", "Message2", "SIZE_NUMBER", 1600);
    assertMockEndpointsSatisfied();
}

10. GroovySetHeaderTest#testSetHeader()

Project: camel
Source File: GroovySetHeaderTest.java
View license
@Test
public void testSetHeader() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    mock.expectedBodiesReceived("Hello World");
    mock.expectedHeaderReceived("one", "einz");
    mock.expectedHeaderReceived("two", "twei");
    mock.expectedHeaderReceived("beer", "Carlsberg");
    mock.expectedHeaderReceived("drink", "Carlsberg");
    mock.expectedHeaderReceived("camelId", context.getName());
    Map<String, Object> headers = new HashMap<String, Object>();
    headers.put("one", "einz");
    headers.put("two", "twei");
    headers.put("beer", "Carlsberg");
    template.sendBodyAndHeaders("direct:start", "Hello World", headers);
    assertMockEndpointsSatisfied();
}

11. MailProcessOnlyUnseenMessagesTest#testProcessOnlyUnseenMessages()

View license
@Test
public void testProcessOnlyUnseenMessages() throws Exception {
    sendBody("direct:a", "Message 3");
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    mock.expectedBodiesReceived("Message 3");
    mock.assertIsSatisfied();
    // reset mock so we can make new assertions
    mock.reset();
    // send a new message, now we should only receive this new massages as all the others has been SEEN
    sendBody("direct:a", "Message 4");
    mock.expectedMessageCount(1);
    mock.expectedBodiesReceived("Message 4");
    mock.assertIsSatisfied();
}

12. ZookeeperDoubleRouteAndDoublePolicyTest#routeDoublePoliciesAndTwoRoutes()

View license
@Test
public void routeDoublePoliciesAndTwoRoutes() throws Exception {
    // set up the parent used to control the election
    client.createPersistent("/someapp", "App node to contain policy election nodes...");
    client.createPersistent("/someapp/somepolicy", "Policy node used by route policy to control routes...");
    client.createPersistent("/someapp/someotherpolicy", "Policy node used by route policy to control routes...");
    context.addRoutes(new ZooKeeperPolicyEnforcedRoute());
    MockEndpoint mockedpolicy = getMockEndpoint("mock:controlled");
    mockedpolicy.setExpectedMessageCount(1);
    sendBody("direct:policy-controlled", "This is a test");
    mockedpolicy.await(5, TimeUnit.SECONDS);
    mockedpolicy.assertIsSatisfied();
    MockEndpoint mockedpolicy1 = getMockEndpoint("mock:controlled-1");
    mockedpolicy1.setExpectedMessageCount(1);
    sendBody("direct:policy-controlled-1", "This is a test");
    mockedpolicy1.await(5, TimeUnit.SECONDS);
    mockedpolicy1.assertIsSatisfied();
}

13. DoTrySpringTest#testDoTryHappy()

View license
@Test
public void testDoTryHappy() throws Exception {
    final MockEndpoint mockBefore = getMockEndpoint("mock:before");
    mockBefore.expectedBodiesReceived("Foo");
    final MockEndpoint mockError = getMockEndpoint("mock:error");
    mockError.expectedMessageCount(0);
    final MockEndpoint mockFinally = getMockEndpoint("mock:finally");
    mockFinally.expectedBodiesReceived("Made it!");
    final MockEndpoint mockAfter = getMockEndpoint("mock:after");
    mockAfter.expectedBodiesReceived("Made it!");
    String response = null;
    try {
        response = template.requestBody("direct:start", "Foo", String.class);
    } catch (Throwable e) {
        fail("Shouldn't get here");
    }
    assertEquals("Made it!", response);
    assertMockEndpointsSatisfied();
}

14. DoTrySpringTest#testDoTryError()

View license
@Test
public void testDoTryError() throws Exception {
    final MockEndpoint mockBefore = getMockEndpoint("mock:before");
    mockBefore.expectedBodiesReceived("Kaboom");
    final MockEndpoint mockError = getMockEndpoint("mock:error");
    mockError.expectedBodiesReceived("Kaboom");
    final MockEndpoint mockFinally = getMockEndpoint("mock:finally");
    mockFinally.expectedBodiesReceived("Something Bad Happened!");
    final MockEndpoint mockAfter = getMockEndpoint("mock:after");
    mockAfter.expectedBodiesReceived("Something Bad Happened!");
    String response = null;
    try {
        response = template.requestBody("direct:start", "Kaboom", String.class);
    } catch (Throwable e) {
        fail("Shouldn't get here");
    }
    assertEquals("Something Bad Happened!", response);
    assertMockEndpointsSatisfied();
}

15. DoTryTest#testDoTryHappy()

View license
@Test
public void testDoTryHappy() throws Exception {
    final MockEndpoint mockBefore = getMockEndpoint("mock:before");
    mockBefore.expectedBodiesReceived("Foo");
    final MockEndpoint mockError = getMockEndpoint("mock:error");
    mockError.expectedMessageCount(0);
    final MockEndpoint mockFinally = getMockEndpoint("mock:finally");
    mockFinally.expectedBodiesReceived("Made it!");
    final MockEndpoint mockAfter = getMockEndpoint("mock:after");
    mockAfter.expectedBodiesReceived("Made it!");
    String response = null;
    try {
        response = template.requestBody("direct:start", "Foo", String.class);
    } catch (Throwable e) {
        fail("Shouldn't get here");
    }
    assertEquals("Made it!", response);
    assertMockEndpointsSatisfied();
}

16. DoTryTest#testDoTryError()

View license
@Test
public void testDoTryError() throws Exception {
    final MockEndpoint mockBefore = getMockEndpoint("mock:before");
    mockBefore.expectedBodiesReceived("Kaboom");
    final MockEndpoint mockError = getMockEndpoint("mock:error");
    mockError.expectedBodiesReceived("Kaboom");
    final MockEndpoint mockFinally = getMockEndpoint("mock:finally");
    mockFinally.expectedBodiesReceived("Something Bad Happened!");
    final MockEndpoint mockAfter = getMockEndpoint("mock:after");
    mockAfter.expectedBodiesReceived("Something Bad Happened!");
    String response = null;
    try {
        response = template.requestBody("direct:start", "Kaboom", String.class);
    } catch (Throwable e) {
        fail("Shouldn't get here");
    }
    assertEquals("Something Bad Happened!", response);
    assertMockEndpointsSatisfied();
}

17. OnCompletionMultipleSpringTest#testOnCompletionDefinedAtRouteLevel()

View license
@Test
public void testOnCompletionDefinedAtRouteLevel() throws InterruptedException {
    // this block is defined first, the definition of the failure only will be considered
    MockEndpoint mockCompleted = getMockEndpoint("mock:completed");
    mockCompleted.setExpectedMessageCount(0);
    MockEndpoint mockFailed = getMockEndpoint("mock:failed");
    mockFailed.setExpectedMessageCount(0);
    // neither of the global completion blocks should be triggered
    MockEndpoint mockGlobalCompleted = getMockEndpoint("mock:globalCompleted");
    mockGlobalCompleted.setExpectedMessageCount(0);
    MockEndpoint mockGlobalFailed = getMockEndpoint("mock:globalFailed");
    mockGlobalFailed.setExpectedMessageCount(0);
    template.asyncSendBody("direct:in", "this message should be fine");
    assertMockEndpointsSatisfied();
}

18. OnCompletionMultipleSpringTest#testOnCompletionFailureAtRouteLevel()

View license
@Test
public void testOnCompletionFailureAtRouteLevel() throws InterruptedException {
    MockEndpoint mockFailed = getMockEndpoint("mock:failed");
    mockFailed.setExpectedMessageCount(1);
    mockFailed.message(0).body().isEqualTo("this message should explode");
    MockEndpoint mockCompleted = getMockEndpoint("mock:completed");
    mockCompleted.setExpectedMessageCount(0);
    // neither of the global completion blocks should be triggered
    MockEndpoint mockGlobalCompleted = getMockEndpoint("mock:globalCompleted");
    mockGlobalCompleted.setExpectedMessageCount(0);
    MockEndpoint mockGlobalFailed = getMockEndpoint("mock:globalFailed");
    mockGlobalFailed.setExpectedMessageCount(0);
    template.asyncSendBody("direct:in", "this message should explode");
    assertMockEndpointsSatisfied();
}

19. OnCompletionMultipleTest#testOnCompletionDefinedAtRouteLevel()

View license
@Test
public void testOnCompletionDefinedAtRouteLevel() throws InterruptedException {
    // this block is defined first, the definition of the failure only will be considered
    MockEndpoint mockCompleted = getMockEndpoint("mock:completed");
    mockCompleted.setExpectedMessageCount(0);
    MockEndpoint mockFailed = getMockEndpoint("mock:failed");
    mockFailed.setExpectedMessageCount(0);
    // neither of the global completion blocks should be triggered
    MockEndpoint mockGlobalCompleted = getMockEndpoint("mock:globalCompleted");
    mockGlobalCompleted.setExpectedMessageCount(0);
    MockEndpoint mockGlobalFailed = getMockEndpoint("mock:globalFailed");
    mockGlobalFailed.setExpectedMessageCount(0);
    template.asyncSendBody("direct:in", "this message should be fine");
    assertMockEndpointsSatisfied();
}

20. OnCompletionMultipleTest#testOnCompletionFailureAtRouteLevel()

View license
@Test
public void testOnCompletionFailureAtRouteLevel() throws InterruptedException {
    MockEndpoint mockFailed = getMockEndpoint("mock:failed");
    mockFailed.setExpectedMessageCount(1);
    mockFailed.message(0).body().isEqualTo("this message should explode");
    MockEndpoint mockCompleted = getMockEndpoint("mock:completed");
    mockCompleted.setExpectedMessageCount(0);
    // neither of the global completion blocks should be triggered
    MockEndpoint mockGlobalCompleted = getMockEndpoint("mock:globalCompleted");
    mockGlobalCompleted.setExpectedMessageCount(0);
    MockEndpoint mockGlobalFailed = getMockEndpoint("mock:globalFailed");
    mockGlobalFailed.setExpectedMessageCount(0);
    template.asyncSendBody("direct:in", "this message should explode");
    assertMockEndpointsSatisfied();
}

21. QuartzTwoCamelContextRestartTest#testTwoCamelContextRestart()

View license
@Test
public void testTwoCamelContextRestart() throws Exception {
    MockEndpoint mock1 = camel1.getEndpoint("mock:one", MockEndpoint.class);
    mock1.expectedMinimumMessageCount(2);
    MockEndpoint mock2 = camel2.getEndpoint("mock:two", MockEndpoint.class);
    mock2.expectedMinimumMessageCount(6);
    mock1.assertIsSatisfied();
    camel1.stop();
    mock2.assertIsSatisfied();
    // should resume triggers when we start camel 1 again
    // fetch mock endpoint again because we have stopped camel context
    mock1 = camel1.getEndpoint("mock:one", MockEndpoint.class);
    mock1.expectedMinimumMessageCount(3);
    camel1.start();
    mock1.assertIsSatisfied();
}

22. QuartzTwoCamelContextRestartTest#testTwoCamelContextRestart()

View license
@Test
public void testTwoCamelContextRestart() throws Exception {
    MockEndpoint mock1 = camel1.getEndpoint("mock:one", MockEndpoint.class);
    mock1.expectedMinimumMessageCount(2);
    MockEndpoint mock2 = camel2.getEndpoint("mock:two", MockEndpoint.class);
    mock2.expectedMinimumMessageCount(6);
    mock1.assertIsSatisfied();
    camel1.stop();
    mock2.assertIsSatisfied();
    // should resume triggers when we start camel 1 again
    // fetch mock endpoint again because we have stopped camel context
    mock1 = camel1.getEndpoint("mock:one", MockEndpoint.class);
    mock1.expectedMinimumMessageCount(3);
    camel1.start();
    mock1.assertIsSatisfied();
}

23. FileToFileWithFlattenTest#testFlatternConsumer()

View license
public void testFlatternConsumer() throws Exception {
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("file://target/flatten-in?recursive=true&flatten=true").to("file://target/flatten-out", "mock:result");
        }
    });
    context.start();
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(3);
    // flatten files
    mock.expectedFileExists("target/flatten-out/bye.txt");
    mock.expectedFileExists("target/flatten-out/hello.txt");
    mock.expectedFileExists("target/flatten-out/goodday.txt");
    // default move files
    mock.expectedFileExists("target/flatten-in/.camel/bye.txt");
    mock.expectedFileExists("target/flatten-in/sub/.camel/hello.txt");
    mock.expectedFileExists("target/flatten-in/sub/sub2/.camel/goodday.txt");
    assertMockEndpointsSatisfied();
}

24. FileToFileWithFlattenTest#testFlatternProducer()

View license
public void testFlatternProducer() throws Exception {
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("file://target/flatten-in?recursive=true").to("file://target/flatten-out?flatten=true", "mock:result");
        }
    });
    context.start();
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(3);
    // flatten files
    mock.expectedFileExists("target/flatten-out/bye.txt");
    mock.expectedFileExists("target/flatten-out/hello.txt");
    mock.expectedFileExists("target/flatten-out/goodday.txt");
    // default move files
    mock.expectedFileExists("target/flatten-in/.camel/bye.txt");
    mock.expectedFileExists("target/flatten-in/sub/.camel/hello.txt");
    mock.expectedFileExists("target/flatten-in/sub/sub2/.camel/goodday.txt");
    assertMockEndpointsSatisfied();
}

25. ThrottlerTest#testSendLotsOfMessagesWithRejectExecution()

Project: camel
Source File: ThrottlerTest.java
View license
public void testSendLotsOfMessagesWithRejectExecution() throws Exception {
    if (!canTest()) {
        return;
    }
    MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
    resultEndpoint.expectedMessageCount(2);
    resultEndpoint.setResultWaitTime(2000);
    MockEndpoint errorEndpoint = resolveMandatoryEndpoint("mock:error", MockEndpoint.class);
    errorEndpoint.expectedMessageCount(4);
    errorEndpoint.setResultWaitTime(2000);
    for (int i = 0; i < 6; i++) {
        template.sendBody("direct:start", "<message>" + i + "</message>");
    }
    // lets pause to give the requests time to be processed
    // to check that the throttle really does kick in
    resultEndpoint.assertIsSatisfied();
    errorEndpoint.assertIsSatisfied();
}

26. SplitParallelProcessingTimeoutSpringTest#testSplittingInParallel()

View license
@Test
public void testSplittingInParallel() throws InterruptedException {
    List<String> messageFragments = new ArrayList<String>();
    int fragmentCount = 50;
    for (int i = 0; i < fragmentCount; i++) {
        messageFragments.add("fragment" + i);
    }
    MockEndpoint mockSplit = getMockEndpoint("mock:split");
    mockSplit.setExpectedMessageCount(fragmentCount - 1);
    ArrayList<String> expectedFragments = new ArrayList<String>(messageFragments);
    int indexDelayed = 20;
    expectedFragments.remove(indexDelayed);
    mockSplit.expectedBodiesReceivedInAnyOrder(expectedFragments);
    MockEndpoint mockDelayed = getMockEndpoint("mock:delayed");
    mockDelayed.setExpectedMessageCount(1);
    MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.setExpectedMessageCount(1);
    template.sendBody("direct:in", messageFragments);
    assertMockEndpointsSatisfied();
}

27. FtpConsumerMaxMessagesPerPollTest#testMaxMessagesPerPoll()

View license
@Test
public void testMaxMessagesPerPoll() throws Exception {
    // start route
    context.startRoute("foo");
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("Bye World", "Godday World");
    mock.setResultWaitTime(4000);
    mock.expectedPropertyReceived(Exchange.BATCH_SIZE, 2);
    assertMockEndpointsSatisfied();
    mock.reset();
    mock.expectedBodiesReceived("Hello World");
    mock.expectedPropertyReceived(Exchange.BATCH_SIZE, 1);
    assertMockEndpointsSatisfied();
}

28. FtpConsumerNotEagerMaxMessagesPerPollTest#testMaxMessagesPerPoll()

View license
@Test
public void testMaxMessagesPerPoll() throws Exception {
    // start route
    context.startRoute("foo");
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("AAA", "BBB");
    mock.setResultWaitTime(4000);
    mock.expectedPropertyReceived(Exchange.BATCH_SIZE, 2);
    assertMockEndpointsSatisfied();
    mock.reset();
    mock.expectedBodiesReceived("CCC");
    mock.expectedPropertyReceived(Exchange.BATCH_SIZE, 1);
    assertMockEndpointsSatisfied();
}

29. SpringContextScopeOnExceptionTest#testOrderOk()

View license
public void testOrderOk() throws Exception {
    MockEndpoint result = getMockEndpoint("mock:result");
    result.expectedBodiesReceived("Order OK");
    result.expectedHeaderReceived("orderid", "123");
    MockEndpoint error = getMockEndpoint("mock:error");
    error.expectedMessageCount(0);
    MockEndpoint dead = getMockEndpoint("mock:dead");
    dead.expectedMessageCount(0);
    Object out = template.requestBodyAndHeader("direct:start", "Order: MacBook Pro", "customerid", "444");
    assertEquals("Order OK", out);
    assertMockEndpointsSatisfied();
}

30. SpringContextScopeOnExceptionTest#testOrderError()

View license
public void testOrderError() throws Exception {
    MockEndpoint error = getMockEndpoint("mock:error");
    error.expectedBodiesReceived("Order ERROR");
    error.expectedHeaderReceived("orderid", "failed");
    MockEndpoint result = getMockEndpoint("mock:result");
    result.expectedMessageCount(0);
    MockEndpoint dead = getMockEndpoint("mock:dead");
    dead.expectedMessageCount(0);
    Object out = template.requestBodyAndHeader("direct:start", "Order: kaboom", "customerid", "555");
    assertEquals("Order ERROR", out);
    assertMockEndpointsSatisfied();
}

31. SpringOnExceptionSubRouteTest#testOrderOk()

View license
public void testOrderOk() throws Exception {
    MockEndpoint result = getMockEndpoint("mock:result");
    result.expectedBodiesReceived("Order OK");
    result.expectedHeaderReceived("orderid", "123");
    MockEndpoint error = getMockEndpoint("mock:error");
    error.expectedMessageCount(0);
    MockEndpoint dead = getMockEndpoint("mock:dead");
    dead.expectedMessageCount(0);
    Object out = template.requestBodyAndHeader("direct:start", "Order: MacBook Pro", "customerid", "444");
    assertEquals("Order OK", out);
    assertMockEndpointsSatisfied();
}

32. SpringOnExceptionSubRouteTest#testOrderError()

View license
public void testOrderError() throws Exception {
    MockEndpoint error = getMockEndpoint("mock:error");
    error.expectedBodiesReceived("Order ERROR");
    error.expectedHeaderReceived("orderid", "failed");
    MockEndpoint result = getMockEndpoint("mock:result");
    result.expectedMessageCount(0);
    MockEndpoint dead = getMockEndpoint("mock:dead");
    dead.expectedMessageCount(0);
    Object out = template.requestBodyAndHeader("direct:start", "Order: kaboom", "customerid", "555");
    assertEquals("Order ERROR", out);
    assertMockEndpointsSatisfied();
}

33. MailHeaderOverrulePreConfigurationRecipientsTest#testSendWithRecipientsInHeaders()

View license
@Test
public void testSendWithRecipientsInHeaders() throws Exception {
    Mailbox.clearAll();
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    mock.expectedBodiesReceived("Hello World");
    mock.expectedHeaderReceived("to", "[email protected]");
    mock.expectedHeaderReceived("cc", "[email protected]");
    mock.expectedHeaderReceived("bcc", "[email protected]");
    Map<String, Object> headers = new HashMap<String, Object>();
    headers.put("to", "[email protected]");
    headers.put("cc", "[email protected]");
    headers.put("bcc", "[email protected]");
    template.sendBodyAndHeaders("smtp://[email protected]", "Hello World", headers);
    mock.assertIsSatisfied();
}

34. MailMaxMessagesPerPollTest#testBatchConsumer()

View license
@Test
public void testBatchConsumer() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.setResultWaitTime(2000);
    mock.expectedMessageCount(3);
    mock.message(0).body().isEqualTo("Message 0");
    mock.message(1).body().isEqualTo("Message 1");
    mock.message(2).body().isEqualTo("Message 2");
    mock.expectedPropertyReceived(Exchange.BATCH_SIZE, 3);
    assertMockEndpointsSatisfied();
    mock.reset();
    mock.expectedMessageCount(2);
    mock.expectedPropertyReceived(Exchange.BATCH_SIZE, 2);
    mock.message(0).body().isEqualTo("Message 3");
    mock.message(1).body().isEqualTo("Message 4");
    assertMockEndpointsSatisfied();
}

35. FileConsumeNotEagerMaxMessagesPerPollTest#testMaxMessagesPerPoll()

View license
public void testMaxMessagesPerPoll() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("AAA", "BBB");
    mock.setResultWaitTime(4000);
    mock.expectedPropertyReceived(Exchange.BATCH_SIZE, 2);
    assertMockEndpointsSatisfied();
    mock.reset();
    mock.expectedBodiesReceived("CCC");
    mock.expectedPropertyReceived(Exchange.BATCH_SIZE, 1);
    assertMockEndpointsSatisfied();
}

36. SedaRemoveRouteThenAddAgainTest#testRemoveRouteAndThenAddAgain()

View license
public void testRemoveRouteAndThenAddAgain() throws Exception {
    MockEndpoint out = getMockEndpoint("mock:out");
    out.expectedMessageCount(1);
    out.expectedBodiesReceived("before removing the route");
    template.sendBody("seda:in", "before removing the route");
    out.assertIsSatisfied();
    // now stop & remove the route
    context.stopRoute("sedaToMock");
    context.removeRoute("sedaToMock");
    // and then add it back again
    context.addRoutes(createRouteBuilder());
    // the mock endpoint was removed, so need to grab it again
    out = getMockEndpoint("mock:out");
    out.expectedMessageCount(1);
    out.expectedBodiesReceived("after removing the route");
    template.sendBody("seda:in", "after removing the route");
    out.assertIsSatisfied();
}

37. BeanWithExchangeExceptionAnnotationTest#testBeanWithAnnotationAndExchangeTest()

View license
public void testBeanWithAnnotationAndExchangeTest() throws Exception {
    MockEndpoint result = getMockEndpoint("mock:result");
    MockEndpoint error = getMockEndpoint("mock:error");
    result.expectedMessageCount(0);
    error.expectedMessageCount(1);
    error.expectedBodiesReceived("The Body");
    template.requestBody("direct:start", "The Body");
    result.assertIsSatisfied();
    error.assertIsSatisfied();
}

38. DelayerAsyncDelayedTest#testSendingMessageGetsDelayed()

Project: camel
Source File: DelayerAsyncDelayedTest.java
View license
public void testSendingMessageGetsDelayed() throws Exception {
    MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
    // do not wait for the first message
    resultEndpoint.expectedMessageCount(0);
    resultEndpoint.setResultWaitTime(500);
    template.sendBodyAndHeader("seda:a", "<hello>world!</hello>", "MyDelay", 1000);
    // we should not receive it as we wait at most 0.5 sec and it take 1 sec to send
    resultEndpoint.assertIsSatisfied();
    // now if we wait a bit longer we should receive the message!
    resultEndpoint.reset();
    resultEndpoint.expectedMessageCount(1);
    resultEndpoint.assertIsSatisfied();
}

39. DelayerTest#testSendingMessageGetsDelayed()

Project: camel
Source File: DelayerTest.java
View license
public void testSendingMessageGetsDelayed() throws Exception {
    MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
    // do not wait for the first message
    resultEndpoint.expectedMessageCount(0);
    resultEndpoint.setResultWaitTime(500);
    template.sendBodyAndHeader("seda:a", "<hello>world!</hello>", "MyDelay", 1000);
    // we should not receive it as we wait at most 0.5 sec and it take 1 sec to send
    resultEndpoint.assertIsSatisfied();
    // now if we wait a bit longer we should receive the message!
    resultEndpoint.reset();
    resultEndpoint.expectedMessageCount(1);
    resultEndpoint.assertIsSatisfied();
}

40. DynamicOnCompletionTest#testOnCompletionFailed()

View license
@Test
public void testOnCompletionFailed() throws InterruptedException {
    MockEndpoint mockStart = getMockEndpoint("mock:start");
    mockStart.setExpectedMessageCount(1);
    mockStart.message(0).body().isEqualTo(FAILING_BODY);
    MockEndpoint mockCancel = getMockEndpoint("mock:cancel");
    mockCancel.setExpectedMessageCount(1);
    mockCancel.message(0).body().isEqualTo(FAILING_BODY);
    MockEndpoint mockConfirm = getMockEndpoint("mock:confirm");
    mockConfirm.setExpectedMessageCount(0);
    template.asyncSendBody("direct:in", FAILING_BODY);
    assertMockEndpointsSatisfied();
}

41. IdempotentConsumerSkipDuplicateTest#testReplayOfSameMessageWillTriggerDuplicateEndpoint()

View license
@Test
public void testReplayOfSameMessageWillTriggerDuplicateEndpoint() throws InterruptedException {
    MockEndpoint mockWs = getMockEndpoint("mock:ws");
    mockWs.setExpectedMessageCount(1);
    MockEndpoint mockDuplicate = getMockEndpoint("mock:duplicate");
    mockDuplicate.setExpectedMessageCount(1);
    MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.setExpectedMessageCount(2);
    template.sendBodyAndHeader("direct:in", "Insert", "messageId", 1);
    // again
    template.sendBodyAndHeader("direct:in", "Insert", "messageId", 1);
    assertMockEndpointsSatisfied();
}

42. IdempotentConsumerSkipDuplicateSpringTest#testReplayOfSameMessageWillTriggerDuplicateEndpoint()

View license
@Test
public void testReplayOfSameMessageWillTriggerDuplicateEndpoint() throws InterruptedException {
    MockEndpoint mockWs = getMockEndpoint("mock:ws");
    mockWs.setExpectedMessageCount(1);
    MockEndpoint mockDuplicate = getMockEndpoint("mock:duplicate");
    mockDuplicate.setExpectedMessageCount(1);
    MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.setExpectedMessageCount(2);
    template.sendBodyAndHeader("direct:in", "Insert", "messageId", 1);
    // again
    template.sendBodyAndHeader("direct:in", "Insert", "messageId", 1);
    assertMockEndpointsSatisfied();
}

43. ContentBasedRouterTest#testWhen()

View license
@Test
public void testWhen() throws Exception {
    MockEndpoint mockCamel = getMockEndpoint("mock:camel");
    mockCamel.expectedMessageCount(2);
    mockCamel.message(0).body().isEqualTo("Camel Rocks");
    mockCamel.message(0).header("verified").isEqualTo(true);
    mockCamel.message(0).arrives().noLaterThan(50).millis().beforeNext();
    mockCamel.message(0).simple("${header[verified]} == true");
    MockEndpoint mockOther = getMockEndpoint("mock:other");
    mockOther.expectedMessageCount(0);
    template.sendBody("direct:start", "Camel Rocks");
    template.sendBody("direct:start", "Loving the Camel");
    mockCamel.assertIsSatisfied();
    mockOther.assertIsSatisfied();
    Exchange exchange0 = mockCamel.assertExchangeReceived(0);
    Exchange exchange1 = mockCamel.assertExchangeReceived(1);
    assertEquals(exchange0.getIn().getHeader("verified"), exchange1.getIn().getHeader("verified"));
}

44. FreemarkerContentCacheTest#testCached()

View license
@Test
public void testCached() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("Hello London");
    template.sendBodyAndHeader("direct:b", "Body", "name", "London");
    mock.assertIsSatisfied();
    // now change content in the file in the classpath and try again
    template.sendBodyAndHeader("file://target/test-classes/org/apache/camel/component/freemarker?fileExist=Override", "Bye ${headers.name}", Exchange.FILE_NAME, "hello.ftl");
    mock.reset();
    // we must expected the original filecontent as the cache is enabled, so its Hello and not Bye
    mock.expectedBodiesReceived("Hello Paris");
    template.sendBodyAndHeader("direct:b", "Body", "name", "Paris");
    mock.assertIsSatisfied();
}

45. FreemarkerContentCacheTest#testNotCached()

View license
@Test
public void testNotCached() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("Hello London");
    template.sendBodyAndHeader("direct:a", "Body", "name", "London");
    mock.assertIsSatisfied();
    // now change content in the file in the classpath and try again
    template.sendBodyAndHeader("file://target/test-classes/org/apache/camel/component/freemarker?fileExist=Override", "Bye ${headers.name}", Exchange.FILE_NAME, "hello.ftl");
    mock.reset();
    mock.expectedBodiesReceived("Bye Paris");
    template.sendBodyAndHeader("direct:a", "Body", "name", "Paris");
    mock.assertIsSatisfied();
}

46. EtcdWatchTest#testWatch()

Project: camel
Source File: EtcdWatchTest.java
View license
private void testWatch(String mockEndpoint, final String key, int updates) throws Exception {
    final String[] values = new String[updates];
    for (int i = 0; i < updates; i++) {
        values[i] = key + "=myValue-" + i;
    }
    MockEndpoint mock = getMockEndpoint(mockEndpoint);
    mock.expectedMessageCount(2);
    mock.expectedHeaderReceived(EtcdConstants.ETCD_NAMESPACE, EtcdNamespace.watch.name());
    mock.expectedHeaderReceived(EtcdConstants.ETCD_PATH, key);
    mock.expectedBodiesReceived(values);
    final EtcdClient client = getClient();
    for (int i = 0; i < updates; i++) {
        client.put(key, "myValue-" + i).send().get();
    }
    mock.assertIsSatisfied();
}

47. FilteringTest#testOther()

View license
@Test
public void testOther() throws Exception {
    getMockEndpoint("mock:C").expectedMessageCount(0);
    final MockEndpoint mockEndpointAfterC = getMockEndpoint("mock:afterC");
    mockEndpointAfterC.expectedMessageCount(1);
    // FILTER_MATCHED set to true if message matched previous Filter Predicate
    mockEndpointAfterC.expectedPropertyReceived(Exchange.FILTER_MATCHED, false);
    getMockEndpoint("mock:amel").expectedMessageCount(0);
    final MockEndpoint mockEndpointOther = getMockEndpoint("mock:other");
    mockEndpointOther.expectedMessageCount(1);
    // FILTER_MATCHED set to true if message matched previous Filter Predicate
    mockEndpointOther.expectedPropertyReceived(Exchange.FILTER_MATCHED, false);
    template.sendBody("direct:start", "Hello World");
    assertMockEndpointsSatisfied();
}

48. FilteringSpringTest#testOther()

View license
@Test
public void testOther() throws Exception {
    getMockEndpoint("mock:C").expectedMessageCount(0);
    final MockEndpoint mockEndpointAfterC = getMockEndpoint("mock:afterC");
    mockEndpointAfterC.expectedMessageCount(1);
    // FILTER_MATCHED set to true if message matched previous Filter Predicate
    mockEndpointAfterC.expectedPropertyReceived(Exchange.FILTER_MATCHED, false);
    getMockEndpoint("mock:amel").expectedMessageCount(0);
    final MockEndpoint mockEndpointOther = getMockEndpoint("mock:other");
    mockEndpointOther.expectedMessageCount(1);
    // FILTER_MATCHED set to true if message matched previous Filter Predicate
    mockEndpointOther.expectedPropertyReceived(Exchange.FILTER_MATCHED, false);
    template.sendBody("direct:start", "Hello World");
    assertMockEndpointsSatisfied();
}

49. DynamicOnCompletionTest#testOnCompletionCompleted()

View license
@Test
public void testOnCompletionCompleted() throws InterruptedException {
    MockEndpoint mockStart = getMockEndpoint("mock:start");
    mockStart.setExpectedMessageCount(1);
    mockStart.message(0).body().isEqualTo(COMPLETING_BODY);
    MockEndpoint mockCancel = getMockEndpoint("mock:cancel");
    mockCancel.setExpectedMessageCount(0);
    MockEndpoint mockConfirm = getMockEndpoint("mock:confirm");
    mockConfirm.setExpectedMessageCount(1);
    mockConfirm.message(0).body().isEqualTo(COMPLETING_BODY);
    template.asyncSendBody("direct:in", COMPLETING_BODY);
    assertMockEndpointsSatisfied();
}

50. DlcTest#testDlqUseOriginal()

View license
@Test
public void testDlqUseOriginal() throws Exception {
    final MockEndpoint mockResult = getMockEndpoint("mock:result");
    mockResult.expectedMessageCount(1);
    mockResult.expectedBodiesReceived("Foo");
    mockResult.message(0).exchangeProperty(Exchange.EXCEPTION_CAUGHT).isNull();
    mockResult.message(0).header("myHeader").isEqualTo("changed");
    final MockEndpoint mockError = getMockEndpoint("mock:error");
    mockError.expectedMessageCount(1);
    mockError.expectedBodiesReceived("KaBoom");
    mockError.message(0).exchangeProperty(Exchange.EXCEPTION_CAUGHT).isNotNull();
    mockError.message(0).exchangeProperty(Exchange.FAILURE_ROUTE_ID).isEqualTo("myDlcOriginalRoute");
    mockError.message(0).header("myHeader").isEqualTo("original");
    template.sendBodyAndHeader("direct:useOriginal", "Foo", "myHeader", "original");
    template.sendBodyAndHeader("direct:useOriginal", "KaBoom", "myHeader", "original");
    assertMockEndpointsSatisfied();
}

51. DlcTest#testDlqMultistepOriginal()

View license
@Test
public void testDlqMultistepOriginal() throws Exception {
    final MockEndpoint mockResult = getMockEndpoint("mock:result");
    mockResult.expectedMessageCount(1);
    mockResult.expectedBodiesReceived("Foo");
    mockResult.message(0).exchangeProperty(Exchange.EXCEPTION_CAUGHT).isNull();
    mockResult.message(0).header("myHeader").isEqualTo("changed");
    final MockEndpoint mockError = getMockEndpoint("mock:error");
    mockError.expectedMessageCount(1);
    mockError.expectedBodiesReceived("KaBoom");
    mockError.message(0).exchangeProperty(Exchange.EXCEPTION_CAUGHT).isNotNull();
    mockError.message(0).exchangeProperty(Exchange.FAILURE_ROUTE_ID).isEqualTo("myFlakyRouteOriginal");
    mockError.message(0).header("myHeader").isEqualTo("multistep");
    template.sendBodyAndHeader("direct:multirouteOriginal", "Foo", "myHeader", "original");
    template.sendBodyAndHeader("direct:multirouteOriginal", "KaBoom", "myHeader", "original");
    assertMockEndpointsSatisfied();
}

52. DlcTest#testDlqMultistep()

View license
@Test
public void testDlqMultistep() throws Exception {
    final MockEndpoint mockResult = getMockEndpoint("mock:result");
    mockResult.expectedMessageCount(1);
    mockResult.expectedBodiesReceived("Foo");
    mockResult.message(0).exchangeProperty(Exchange.EXCEPTION_CAUGHT).isNull();
    mockResult.message(0).header("myHeader").isEqualTo("changed");
    final MockEndpoint mockError = getMockEndpoint("mock:error");
    mockError.expectedMessageCount(1);
    mockError.expectedBodiesReceived("KaBoom");
    mockError.message(0).exchangeProperty(Exchange.EXCEPTION_CAUGHT).isNotNull();
    mockError.message(0).exchangeProperty(Exchange.FAILURE_ROUTE_ID).isEqualTo("myFlakyRoute");
    mockError.message(0).header("myHeader").isEqualTo("flaky");
    template.sendBodyAndHeader("direct:multiroute", "Foo", "myHeader", "original");
    template.sendBodyAndHeader("direct:multiroute", "KaBoom", "myHeader", "original");
    assertMockEndpointsSatisfied();
}

53. DlcTest#testDlq()

View license
@Test
public void testDlq() throws Exception {
    final MockEndpoint mockResult = getMockEndpoint("mock:result");
    mockResult.expectedMessageCount(1);
    mockResult.expectedBodiesReceived("Foo");
    mockResult.message(0).exchangeProperty(Exchange.EXCEPTION_CAUGHT).isNull();
    mockResult.message(0).header("myHeader").isEqualTo("changed");
    final MockEndpoint mockError = getMockEndpoint("mock:error");
    mockError.expectedMessageCount(1);
    mockError.expectedBodiesReceived("KaBoom");
    mockError.message(0).exchangeProperty(Exchange.EXCEPTION_CAUGHT).isNotNull();
    mockError.message(0).exchangeProperty(Exchange.FAILURE_ROUTE_ID).isEqualTo("myDlcRoute");
    mockError.message(0).header("myHeader").isEqualTo("changed");
    template.sendBodyAndHeader("direct:start", "Foo", "myHeader", "original");
    template.sendBodyAndHeader("direct:start", "KaBoom", "myHeader", "original");
    assertMockEndpointsSatisfied();
}

54. DlcSpringTest#testDlqUseOriginal()

View license
@Test
public void testDlqUseOriginal() throws Exception {
    final MockEndpoint mockResult = getMockEndpoint("mock:result");
    mockResult.expectedMessageCount(1);
    mockResult.expectedBodiesReceived("Foo");
    mockResult.message(0).exchangeProperty(Exchange.EXCEPTION_CAUGHT).isNull();
    mockResult.message(0).header("myHeader").isEqualTo("changed");
    final MockEndpoint mockError = getMockEndpoint("mock:error");
    mockError.expectedMessageCount(1);
    mockError.expectedBodiesReceived("KaBoom");
    mockError.message(0).exchangeProperty(Exchange.EXCEPTION_CAUGHT).isNotNull();
    mockError.message(0).exchangeProperty(Exchange.FAILURE_ROUTE_ID).isEqualTo("myDlcOriginalRoute");
    mockError.message(0).header("myHeader").isEqualTo("original");
    template.sendBodyAndHeader("direct:useOriginal", "Foo", "myHeader", "original");
    template.sendBodyAndHeader("direct:useOriginal", "KaBoom", "myHeader", "original");
    assertMockEndpointsSatisfied();
}

55. DlcSpringTest#testDlqMultistepOriginal()

View license
@Test
public void testDlqMultistepOriginal() throws Exception {
    final MockEndpoint mockResult = getMockEndpoint("mock:result");
    mockResult.expectedMessageCount(1);
    mockResult.expectedBodiesReceived("Foo");
    mockResult.message(0).exchangeProperty(Exchange.EXCEPTION_CAUGHT).isNull();
    mockResult.message(0).header("myHeader").isEqualTo("changed");
    final MockEndpoint mockError = getMockEndpoint("mock:error");
    mockError.expectedMessageCount(1);
    mockError.expectedBodiesReceived("KaBoom");
    mockError.message(0).exchangeProperty(Exchange.EXCEPTION_CAUGHT).isNotNull();
    mockError.message(0).exchangeProperty(Exchange.FAILURE_ROUTE_ID).isEqualTo("myFlakyRouteOriginal");
    mockError.message(0).header("myHeader").isEqualTo("multistep");
    template.sendBodyAndHeader("direct:multirouteOriginal", "Foo", "myHeader", "original");
    template.sendBodyAndHeader("direct:multirouteOriginal", "KaBoom", "myHeader", "original");
    assertMockEndpointsSatisfied();
}

56. DlcSpringTest#testDlqMultistep()

View license
@Test
public void testDlqMultistep() throws Exception {
    final MockEndpoint mockResult = getMockEndpoint("mock:result");
    mockResult.expectedMessageCount(1);
    mockResult.expectedBodiesReceived("Foo");
    mockResult.message(0).exchangeProperty(Exchange.EXCEPTION_CAUGHT).isNull();
    mockResult.message(0).header("myHeader").isEqualTo("changed");
    final MockEndpoint mockError = getMockEndpoint("mock:error");
    mockError.expectedMessageCount(1);
    mockError.expectedBodiesReceived("KaBoom");
    mockError.message(0).exchangeProperty(Exchange.EXCEPTION_CAUGHT).isNotNull();
    mockError.message(0).exchangeProperty(Exchange.FAILURE_ROUTE_ID).isEqualTo("myFlakyRoute");
    mockError.message(0).header("myHeader").isEqualTo("flaky");
    template.sendBodyAndHeader("direct:multiroute", "Foo", "myHeader", "original");
    template.sendBodyAndHeader("direct:multiroute", "KaBoom", "myHeader", "original");
    assertMockEndpointsSatisfied();
}

57. DlcSpringTest#testDlq()

View license
@Test
public void testDlq() throws Exception {
    final MockEndpoint mockResult = getMockEndpoint("mock:result");
    mockResult.expectedMessageCount(1);
    mockResult.expectedBodiesReceived("Foo");
    mockResult.message(0).exchangeProperty(Exchange.EXCEPTION_CAUGHT).isNull();
    mockResult.message(0).header("myHeader").isEqualTo("changed");
    final MockEndpoint mockError = getMockEndpoint("mock:error");
    mockError.expectedMessageCount(1);
    mockError.expectedBodiesReceived("KaBoom");
    mockError.message(0).exchangeProperty(Exchange.EXCEPTION_CAUGHT).isNotNull();
    mockError.message(0).exchangeProperty(Exchange.FAILURE_ROUTE_ID).isEqualTo("myDlcRoute");
    mockError.message(0).header("myHeader").isEqualTo("changed");
    template.sendBodyAndHeader("direct:start", "Foo", "myHeader", "original");
    template.sendBodyAndHeader("direct:start", "KaBoom", "myHeader", "original");
    assertMockEndpointsSatisfied();
}

58. XmlJsonDataFormatTest#testMarshalAndUnmarshalInline()

Project: camel
Source File: XmlJsonDataFormatTest.java
View license
@Test
public void testMarshalAndUnmarshalInline() throws Exception {
    InputStream inStream = getClass().getResourceAsStream("testMessage1.xml");
    String in = context.getTypeConverter().convertTo(String.class, inStream);
    MockEndpoint mockJSON = getMockEndpoint("mock:jsonInline");
    mockJSON.expectedMessageCount(1);
    mockJSON.message(0).body().isInstanceOf(byte[].class);
    MockEndpoint mockXML = getMockEndpoint("mock:xmlInline");
    mockXML.expectedMessageCount(1);
    mockXML.message(0).body().isInstanceOf(String.class);
    Object json = template.requestBody("direct:marshalInline", in);
    String jsonString = context.getTypeConverter().convertTo(String.class, json);
    JSONObject obj = (JSONObject) JSONSerializer.toJSON(jsonString);
    assertEquals("JSONObject doesn't contain 7 keys", 7, obj.entrySet().size());
    template.sendBody("direct:unmarshalInline", jsonString);
    mockJSON.assertIsSatisfied();
    mockXML.assertIsSatisfied();
}

59. XmlJsonDataFormatTest#testMarshalAndUnmarshal()

Project: camel
Source File: XmlJsonDataFormatTest.java
View license
@Test
public void testMarshalAndUnmarshal() throws Exception {
    InputStream inStream = getClass().getResourceAsStream("testMessage1.xml");
    String in = context.getTypeConverter().convertTo(String.class, inStream);
    MockEndpoint mockJSON = getMockEndpoint("mock:json");
    mockJSON.expectedMessageCount(1);
    mockJSON.message(0).body().isInstanceOf(byte[].class);
    MockEndpoint mockXML = getMockEndpoint("mock:xml");
    mockXML.expectedMessageCount(1);
    mockXML.message(0).body().isInstanceOf(String.class);
    Object json = template.requestBody("direct:marshal", in);
    String jsonString = context.getTypeConverter().convertTo(String.class, json);
    JSONObject obj = (JSONObject) JSONSerializer.toJSON(jsonString);
    assertEquals("JSONObject doesn't contain 7 keys", 7, obj.entrySet().size());
    template.sendBody("direct:unmarshal", jsonString);
    mockJSON.assertIsSatisfied();
    mockXML.assertIsSatisfied();
}

60. SpringXmlJsonDataFormatTest#testMarshalAndUnmarshal()

View license
@Test
public void testMarshalAndUnmarshal() throws Exception {
    InputStream inStream = getClass().getResourceAsStream("testMessage1.xml");
    String in = context.getTypeConverter().convertTo(String.class, inStream);
    MockEndpoint mockJSON = getMockEndpoint("mock:json");
    mockJSON.expectedMessageCount(1);
    mockJSON.message(0).body().isInstanceOf(byte[].class);
    MockEndpoint mockXML = getMockEndpoint("mock:xml");
    mockXML.expectedMessageCount(1);
    mockXML.message(0).body().isInstanceOf(String.class);
    Object json = template.requestBody("direct:marshal", in);
    String jsonString = context.getTypeConverter().convertTo(String.class, json);
    JSONObject obj = (JSONObject) JSONSerializer.toJSON(jsonString);
    assertEquals("JSONObject doesn't contain 7 keys", 7, obj.entrySet().size());
    template.sendBody("direct:unmarshal", jsonString);
    mockJSON.assertIsSatisfied();
    mockXML.assertIsSatisfied();
}

61. VelocitySetTemplateViaHeaderTest#testVelocityLetter()

View license
@Test
public void testVelocityLetter() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    mock.message(0).body(String.class).contains("Thanks for the order of Camel in Action");
    template.send("direct:a", createLetter("org/apache/camel/component/velocity/letter.vm"));
    mock.assertIsSatisfied();
    mock.reset();
    mock.expectedMessageCount(1);
    mock.message(0).body(String.class).contains("Regards Apache Camel Riders Bookstore");
    template.send("direct:a", createLetter("org/apache/camel/component/velocity/letter2.vm"));
    mock.assertIsSatisfied();
}

62. VelocityDynamicTemplateTest#testVelocityLetter()

View license
@Test
public void testVelocityLetter() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    mock.message(0).body(String.class).contains("Thanks for the order of Camel in Action");
    template.send("direct:a", createLetter());
    mock.assertIsSatisfied();
    mock.reset();
    mock.expectedMessageCount(1);
    mock.message(0).body(String.class).contains("Regards Apache Camel Riders Bookstore");
    template.send("direct:a", createLetter());
    mock.assertIsSatisfied();
}

63. VelocityContentCacheTest#testCachedIsDefault()

Project: camel
Source File: VelocityContentCacheTest.java
View license
@Test
public void testCachedIsDefault() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("Hello London");
    template.sendBodyAndHeader("direct:c", "Body", "name", "London");
    mock.assertIsSatisfied();
    // now change content in the file in the classpath and try again
    template.sendBodyAndHeader("file://target/test-classes/org/apache/camel/component/velocity?fileExist=Override", "Bye $headers.name", Exchange.FILE_NAME, "hello.vm");
    mock.reset();
    // we must expected the original filecontent as the cache is enabled, so its Hello and not Bye
    mock.expectedBodiesReceived("Hello Paris");
    template.sendBodyAndHeader("direct:c", "Body", "name", "Paris");
    mock.assertIsSatisfied();
}

64. VelocityContentCacheTest#testCached()

Project: camel
Source File: VelocityContentCacheTest.java
View license
@Test
public void testCached() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("Hello London");
    template.sendBodyAndHeader("direct:b", "Body", "name", "London");
    mock.assertIsSatisfied();
    // now change content in the file in the classpath and try again
    template.sendBodyAndHeader("file://target/test-classes/org/apache/camel/component/velocity?fileExist=Override", "Bye $headers.name", Exchange.FILE_NAME, "hello.vm");
    mock.reset();
    // we must expected the original filecontent as the cache is enabled, so its Hello and not Bye
    mock.expectedBodiesReceived("Hello Paris");
    template.sendBodyAndHeader("direct:b", "Body", "name", "Paris");
    mock.assertIsSatisfied();
}

65. VelocityContentCacheTest#testNotCached()

Project: camel
Source File: VelocityContentCacheTest.java
View license
@Test
public void testNotCached() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("Hello London");
    template.sendBodyAndHeader("direct:a", "Body", "name", "London");
    mock.assertIsSatisfied();
    // now change content in the file in the classpath and try again
    template.sendBodyAndHeader("file://target/test-classes/org/apache/camel/component/velocity?fileExist=Override", "Bye $headers.name", Exchange.FILE_NAME, "hello.vm");
    mock.reset();
    mock.expectedBodiesReceived("Bye Paris");
    template.sendBodyAndHeader("direct:a", "Body", "name", "Paris");
    mock.assertIsSatisfied();
}

66. StringTemplateContentCacheTest#testCached()

View license
@Test
public void testCached() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("Hello London");
    template.sendBodyAndHeader("direct:b", "Body", "name", "London");
    mock.assertIsSatisfied();
    // now change content in the file in the classpath and try again
    template.sendBodyAndHeader("file://target/test-classes/org/apache/camel/component/stringtemplate", "Bye <headers.name>", Exchange.FILE_NAME, "hello.tm");
    mock.reset();
    // we must expected the original filecontent as the cache is enabled, so its Hello and not Bye
    mock.expectedBodiesReceived("Hello Paris");
    template.sendBodyAndHeader("direct:b", "Body", "name", "Paris");
    mock.assertIsSatisfied();
}

67. StringTemplateContentCacheTest#testNotCached()

View license
@Test
public void testNotCached() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("Hello London");
    template.sendBodyAndHeader("direct:a", "Body", "name", "London");
    mock.assertIsSatisfied();
    // now change content in the file in the classpath and try again
    template.sendBodyAndHeader("file://target/test-classes/org/apache/camel/component/stringtemplate", "Bye <headers.name>", Exchange.FILE_NAME, "hello.tm");
    mock.reset();
    mock.expectedBodiesReceived("Bye Paris");
    template.sendBodyAndHeader("direct:a", "Body", "name", "Paris");
    mock.assertIsSatisfied();
}

68. SshComponentProducerTest#testReconnect()

Project: camel
Source File: SshComponentProducerTest.java
View license
@Test
public void testReconnect() throws Exception {
    final String msg = "test\n";
    MockEndpoint mock = getMockEndpoint("mock:password");
    mock.expectedMinimumMessageCount(1);
    mock.expectedBodiesReceived(msg);
    template.sendBody("direct:ssh", msg);
    assertMockEndpointsSatisfied();
    sshd.stop();
    sshd.start();
    mock.reset();
    mock.expectedMinimumMessageCount(1);
    mock.expectedBodiesReceived(msg);
    template.sendBody("direct:ssh", msg);
    assertMockEndpointsSatisfied();
}

69. SshComponentErrorHandlingTest#testRedelivery()

View license
@Test
public void testRedelivery() throws Exception {
    final String msg = "test\n";
    MockEndpoint mockError = getMockEndpoint("mock:error");
    mockError.expectedMinimumMessageCount(0);
    MockEndpoint mock = getMockEndpoint("mock:success");
    mock.expectedMinimumMessageCount(1);
    mock.expectedBodiesReceived(msg);
    mock.expectedHeaderReceived(Exchange.REDELIVERED, true);
    sshd.stop();
    template.sendBody("direct:redeliver", msg);
    assertMockEndpointsSatisfied();
}

70. JdbcAggregateDiscardOnTimeoutTest#testAggregateDiscardOnTimeout()

View license
@Test
public void testAggregateDiscardOnTimeout() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:aggregated");
    mock.expectedMessageCount(0);
    template.sendBodyAndHeader("direct:start", "A", "id", 123);
    template.sendBodyAndHeader("direct:start", "B", "id", 123);
    // wait 4 seconds
    Thread.sleep(4000);
    mock.assertIsSatisfied();
    // now send 3 which does not timeout
    mock.reset();
    mock.expectedBodiesReceived("C+D+E");
    template.sendBodyAndHeader("direct:start", "A", "id", 123);
    template.sendBodyAndHeader("direct:start", "B", "id", 123);
    template.sendBodyAndHeader("direct:start", "C", "id", 123);
    // should complete before timeout
    mock.await(1500, TimeUnit.MILLISECONDS);
}

71. SqlRouteTest#testQueryAsHeader()

Project: camel
Source File: SqlRouteTest.java
View license
@Test
public void testQueryAsHeader() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    template.sendBodyAndHeader("direct:simple", "Camel", SqlConstants.SQL_QUERY, "select * from projects where project = ? order by id");
    mock.assertIsSatisfied();
    List<?> received = assertIsInstanceOf(List.class, mock.getReceivedExchanges().get(0).getIn().getBody());
    Map<?, ?> row = assertIsInstanceOf(Map.class, received.get(0));
    assertEquals(1, row.get("id"));
    assertEquals("ASF", row.get("license"));
    mock.reset();
    mock.expectedMessageCount(1);
    template.sendBodyAndHeader("direct:simple", 3, SqlConstants.SQL_QUERY, "select * from projects where id = ? order by id");
    mock.assertIsSatisfied();
    received = assertIsInstanceOf(List.class, mock.getReceivedExchanges().get(0).getIn().getBody());
    row = assertIsInstanceOf(Map.class, received.get(0));
    assertEquals("Linux", row.get("PROJECT"));
    assertEquals("XXX", row.get("license"));
}

72. MainTest#runTests()

Project: camel
Source File: MainTest.java
View license
private void runTests(CamelContext context) throws Exception {
    MockEndpoint resultEndpoint = context.getEndpoint("mock:result", MockEndpoint.class);
    ProducerTemplate template = context.createProducerTemplate();
    String expectedBody = "<matched/>";
    resultEndpoint.expectedBodiesReceived(expectedBody);
    template.sendBodyAndHeader("direct:start", expectedBody, "foo", "bar");
    resultEndpoint.assertIsSatisfied();
    resultEndpoint.reset();
    resultEndpoint.expectedMessageCount(0);
    template.sendBodyAndHeader("direct:start", "<notMatched/>", "foo", "notMatchedHeaderValue");
    resultEndpoint.assertIsSatisfied();
}

73. SpringOnExceptionSubRouteTest#testOrderErrorWithNoExceptionClause()

View license
public void testOrderErrorWithNoExceptionClause() throws Exception {
    MockEndpoint error = getMockEndpoint("mock:error");
    error.expectedMessageCount(0);
    MockEndpoint result = getMockEndpoint("mock:result");
    result.expectedMessageCount(0);
    MockEndpoint dead = getMockEndpoint("mock:dead");
    dead.expectedMessageCount(0);
    try {
        template.requestBodyAndHeader("direct:start_with_no_handler", "Order: kaboom", "customerid", "555");
        fail("Should throw an Exception");
    } catch (Exception e) {
        assertEquals("Cannot order: kaboom", e.getCause().getMessage());
    }
    assertMockEndpointsSatisfied();
}

74. PojoDualCamelContextConsumerTest#testCamel2RecipientList()

View license
public void testCamel2RecipientList() throws Exception {
    String body = "<bye>world!</bye>";
    MockEndpoint result = camel2.getEndpoint("mock:result", MockEndpoint.class);
    result.expectedBodiesReceived(body);
    MockEndpoint foo = camel2.getEndpoint("mock:foo", MockEndpoint.class);
    foo.expectedBodiesReceived(body);
    ProducerTemplate template = camel2.createProducerTemplate();
    template.start();
    template.sendBody("direct:foo", body);
    template.stop();
    result.assertIsSatisfied();
    foo.assertIsSatisfied();
}

75. XsltLosesHeaderTest#testXsltLosesHeader()

Project: camel
Source File: XsltLosesHeaderTest.java
View license
@Test
public void testXsltLosesHeader() throws Exception {
    MockEndpoint endpointAfter = getMockEndpoint("mock:After");
    MockEndpoint endpointBefore = getMockEndpoint("mock:Before");
    endpointBefore.expectedBodiesReceived("header:hello");
    endpointAfter.expectedBodiesReceived("header:hello");
    template.send("seda:xslttest", new Processor() {

        public void process(Exchange exchange) {
            Message in = exchange.getIn();
            in.setBody("dummy");
        }
    });
    endpointBefore.assertIsSatisfied();
    endpointAfter.assertIsSatisfied();
}

76. JmsRouteWithInOnlyAndMultipleAcksTest#testSendOrderWithMultipleAcks()

View license
@Test
public void testSendOrderWithMultipleAcks() throws Exception {
    MockEndpoint inbox = getMockEndpoint("mock:inbox");
    inbox.expectedBodiesReceived("Camel in Action");
    String orderId = "1";
    MockEndpoint notifCollector = getMockEndpoint("mock:orderNotificationAckCollector");
    notifCollector.expectedMessageCount(2);
    notifCollector.expectedHeaderReceived("JMSCorrelationID", orderId);
    notifCollector.setResultWaitTime(10000);
    Object out = template.requestBodyAndHeader("amq:queue:inbox", "Camel in Action", "JMSCorrelationID", orderId);
    assertEquals("OK: Camel in Action", out);
    assertMockEndpointsSatisfied();
}

77. HttpRedirectTest#testHttpRedirectFromCamelRoute()

Project: camel
Source File: HttpRedirectTest.java
View license
@Test
public void testHttpRedirectFromCamelRoute() throws Exception {
    MockEndpoint errorEndpoint = context.getEndpoint("mock:error", MockEndpoint.class);
    errorEndpoint.expectedMessageCount(1);
    MockEndpoint resultEndpoint = context.getEndpoint("mock:result", MockEndpoint.class);
    resultEndpoint.expectedMessageCount(0);
    try {
        template.requestBody("direct:start", "Hello World", String.class);
        fail("Should have thrown an exception");
    } catch (RuntimeCamelException e) {
        HttpOperationFailedException cause = assertIsInstanceOf(HttpOperationFailedException.class, e.getCause());
        assertEquals(302, cause.getStatusCode());
    }
    errorEndpoint.assertIsSatisfied();
    resultEndpoint.assertIsSatisfied();
}

78. JcloudsMultipleBlobStoreTest#testWithMultipleServices()

View license
@Test
public void testWithMultipleServices() throws InterruptedException {
    String message1 = "Blob 1";
    String message2 = "Blob 2";
    MockEndpoint mockEndpoint1 = resolveMandatoryEndpoint("mock:results1", MockEndpoint.class);
    mockEndpoint1.expectedBodiesReceived(message1);
    MockEndpoint mockEndpoint2 = resolveMandatoryEndpoint("mock:results2", MockEndpoint.class);
    mockEndpoint2.expectedBodiesReceived(message2);
    JcloudsBlobStoreHelper.writeBlob(blobStore1, TEST_CONTAINER, TEST_BLOB1, new StringPayload(message1));
    JcloudsBlobStoreHelper.writeBlob(blobStore2, TEST_CONTAINER, TEST_BLOB2, new StringPayload(message2));
    mockEndpoint1.assertIsSatisfied();
    mockEndpoint2.assertIsSatisfied();
}

79. HawtDBAggregateDiscardOnTimeoutTest#testAggregateDiscardOnTimeout()

View license
@Test
public void testAggregateDiscardOnTimeout() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:aggregated");
    mock.expectedMessageCount(0);
    template.sendBodyAndHeader("direct:start", "A", "id", 123);
    template.sendBodyAndHeader("direct:start", "B", "id", 123);
    // wait 4 seconds
    Thread.sleep(4000);
    mock.assertIsSatisfied();
    // now send 3 which does not timeout
    mock.reset();
    mock.expectedBodiesReceived("C+D+E");
    template.sendBodyAndHeader("direct:start", "A", "id", 123);
    template.sendBodyAndHeader("direct:start", "B", "id", 123);
    template.sendBodyAndHeader("direct:start", "C", "id", 123);
    // should complete before timeout
    mock.await(1500, TimeUnit.MILLISECONDS);
}

80. RouteRefPropertyPlaceholderMultipleCamelContextRefsTest#testSpringTwoCamelContextDirectEndpoint()

View license
public void testSpringTwoCamelContextDirectEndpoint() throws Exception {
    AbstractXmlApplicationContext ac = createApplicationContext();
    ac.start();
    CamelContext camel1 = ac.getBean("myCamel-1", CamelContext.class);
    CamelContext camel2 = ac.getBean("myCamel-2", CamelContext.class);
    Endpoint start1 = camel1.getEndpoint("direct:start");
    Endpoint start2 = camel2.getEndpoint("direct:start");
    assertNotSame(start1, start2);
    MockEndpoint mock1 = camel1.getEndpoint("mock:end-1", MockEndpoint.class);
    mock1.expectedBodiesReceived("Hello World");
    MockEndpoint mock2 = camel2.getEndpoint("mock:end-2", MockEndpoint.class);
    mock2.expectedBodiesReceived("Bye World");
    camel1.createProducerTemplate().sendBody("direct:start", "Hello World");
    camel2.createProducerTemplate().sendBody("direct:start", "Bye World");
    mock1.assertIsSatisfied();
    mock2.assertIsSatisfied();
    ac.stop();
}

81. RouteRefMultipleCamelContextRefsTest#testSpringTwoCamelContextDirectEndpoint()

View license
public void testSpringTwoCamelContextDirectEndpoint() throws Exception {
    AbstractXmlApplicationContext ac = createApplicationContext();
    ac.start();
    CamelContext camel1 = ac.getBean("myCamel-1", CamelContext.class);
    CamelContext camel2 = ac.getBean("myCamel-2", CamelContext.class);
    Endpoint start1 = camel1.getEndpoint("direct:start");
    Endpoint start2 = camel2.getEndpoint("direct:start");
    assertNotSame(start1, start2);
    MockEndpoint mock1 = camel1.getEndpoint("mock:result", MockEndpoint.class);
    mock1.expectedBodiesReceived("Hello World");
    MockEndpoint mock2 = camel2.getEndpoint("mock:result", MockEndpoint.class);
    mock2.expectedBodiesReceived("Bye World");
    camel1.createProducerTemplate().sendBody("direct:start", "Hello World");
    camel2.createProducerTemplate().sendBody("direct:start", "Bye World");
    mock1.assertIsSatisfied();
    mock2.assertIsSatisfied();
    ac.stop();
}

82. DualCamelContextEndpointOutsideTest#testDualCamelContextEndpoint()

View license
public void testDualCamelContextEndpoint() throws Exception {
    CamelContext camelA = applicationContext.getBean("camel-A", CamelContext.class);
    assertNotNull(camelA);
    CamelContext camelB = applicationContext.getBean("camel-B", CamelContext.class);
    assertNotNull(camelB);
    MockEndpoint mockA = camelA.getEndpoint("mock:mock1", MockEndpoint.class);
    mockA.expectedBodiesReceived("Hello A");
    MockEndpoint mockB = camelB.getEndpoint("mock:mock2", MockEndpoint.class);
    mockB.expectedBodiesReceived("Hello B");
    ProducerTemplate producer1 = camelA.createProducerTemplate();
    producer1.sendBody("direct:start1", "Hello A");
    ProducerTemplate producer2 = camelB.createProducerTemplate();
    producer2.sendBody("direct:start2", "Hello B");
    // make sure we properly stop the services we created
    ServiceHelper.stopServices(producer1, producer2);
    mockA.assertIsSatisfied();
    mockB.assertIsSatisfied();
}

83. DeadLetterChannelRedeliveryConfigTest#testDLCSpringConfiguredRedeliveryPolicy()

View license
@Test
public void testDLCSpringConfiguredRedeliveryPolicy() throws Exception {
    MockEndpoint dead = context.getEndpoint("mock:dead", MockEndpoint.class);
    MockEndpoint result = context.getEndpoint("mock:result", MockEndpoint.class);
    dead.expectedBodiesReceived("Hello World");
    // no traces of redelivery headers as DLC handles the exception when moving to DLQ
    dead.message(0).header(Exchange.REDELIVERED).isNull();
    dead.message(0).header(Exchange.REDELIVERY_COUNTER).isNull();
    result.expectedMessageCount(0);
    template.sendBody("direct:in", "Hello World");
    result.assertIsSatisfied();
    dead.assertIsSatisfied();
}

84. RoutesFromXmlTest#testRoutes()

Project: camel
Source File: RoutesFromXmlTest.java
View license
@Test
public void testRoutes() throws Exception {
    CamelContext context = getCamelContext();
    assertNotNull(context);
    assertEquals("MyCamel", context.getName());
    assertEquals(2, context.getRoutes().size());
    ProducerTemplate template = context.createProducerTemplate();
    MockEndpoint mock = context.getEndpoint("mock:foo", MockEndpoint.class);
    mock.expectedMessageCount(1);
    MockEndpoint mock2 = context.getEndpoint("mock:bar", MockEndpoint.class);
    mock2.expectedMessageCount(1);
    template.sendBody("direct:foo", "Hello World");
    template.sendBody("direct:bar", "Bye World");
    mock.assertIsSatisfied();
    mock2.assertIsSatisfied();
    template.stop();
}

85. RoutesFromPackageScanTest#testRoutes()

View license
@Test
public void testRoutes() throws Exception {
    CamelContext context = getCamelContext();
    assertNotNull(context);
    assertEquals("MyCamel", context.getName());
    assertEquals(2, context.getRoutes().size());
    assertNotNull(context.getRoute("foo"));
    assertNotNull(context.getRoute("bar"));
    ProducerTemplate template = context.createProducerTemplate();
    MockEndpoint mock = context.getEndpoint("mock:foo", MockEndpoint.class);
    mock.expectedMessageCount(1);
    MockEndpoint mock2 = context.getEndpoint("mock:bar", MockEndpoint.class);
    mock2.expectedMessageCount(1);
    template.sendBody("direct:foo", "Hello World");
    template.sendBody("direct:bar", "Bye World");
    mock.assertIsSatisfied();
    mock2.assertIsSatisfied();
    template.stop();
}

86. MultipleRoutesTest#testCamelContext()

Project: camel
Source File: MultipleRoutesTest.java
View license
@Test
public void testCamelContext() throws Exception {
    CamelContext context = getCamelContext();
    assertNotNull(context);
    assertEquals("MyCamel", context.getName());
    assertEquals(2, context.getRoutes().size());
    ProducerTemplate template = context.createProducerTemplate();
    MockEndpoint mock = context.getEndpoint("mock:foo", MockEndpoint.class);
    mock.expectedMessageCount(1);
    MockEndpoint mock2 = context.getEndpoint("mock:bar", MockEndpoint.class);
    mock2.expectedMessageCount(1);
    template.sendBody("seda:foo", "Hello World");
    template.sendBody("direct:bar", "Bye World");
    mock.assertIsSatisfied();
    mock2.assertIsSatisfied();
    template.stop();
}

87. QuartzTwoCamelContextTest#testTwoCamelContext()

View license
@Test
public void testTwoCamelContext() throws Exception {
    MockEndpoint mock1 = camel1.getEndpoint("mock:one", MockEndpoint.class);
    mock1.expectedMinimumMessageCount(2);
    MockEndpoint mock2 = camel2.getEndpoint("mock:two", MockEndpoint.class);
    mock2.expectedMinimumMessageCount(6);
    mock1.assertIsSatisfied();
    camel1.stop();
    mock2.assertIsSatisfied();
    camel2.stop();
}

88. QuartzTwoCamelContextSameNameClashTest#testTwoCamelContext()

View license
@Test
public void testTwoCamelContext() throws Exception {
    assertNotSame(camel1.getManagementName(), camel2.getManagementName());
    MockEndpoint mock1 = camel1.getEndpoint("mock:one", MockEndpoint.class);
    mock1.expectedMinimumMessageCount(2);
    MockEndpoint mock2 = camel2.getEndpoint("mock:two", MockEndpoint.class);
    mock2.expectedMinimumMessageCount(6);
    mock1.assertIsSatisfied();
    camel1.stop();
    mock2.assertIsSatisfied();
    camel2.stop();
}

89. QuartzRouteRestartTest#testQuartzCronRoute()

Project: camel
Source File: QuartzRouteRestartTest.java
View license
@Test
public void testQuartzCronRoute() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMinimumMessageCount(2);
    assertMockEndpointsSatisfied();
    // restart route
    context().stopRoute("trigger");
    mock.reset();
    mock.expectedMessageCount(0);
    // wait a bit
    Thread.sleep(2000);
    assertMockEndpointsSatisfied();
    // start route, and we got messages again
    mock.reset();
    mock.expectedMinimumMessageCount(1);
    context().startRoute("trigger");
    assertMockEndpointsSatisfied();
}

90. QuartzOneCamelContextSuspendResumeTest#testOneCamelContextSuspendResume()

View license
@Test
public void testOneCamelContextSuspendResume() throws Exception {
    MockEndpoint mock1 = camel1.getEndpoint("mock:one", MockEndpoint.class);
    mock1.expectedMinimumMessageCount(2);
    mock1.assertIsSatisfied();
    camel1.suspend();
    // should resume triggers when we start camel 1 again
    mock1.reset();
    mock1.expectedMinimumMessageCount(2);
    camel1.resume();
    mock1.assertIsSatisfied();
}

91. QuartzComponentCamelContextSharedSchedulerTest#testTwoCamelContext()

View license
@Test
public void testTwoCamelContext() throws Exception {
    MockEndpoint mock1 = camel1.getEndpoint("mock:one", MockEndpoint.class);
    mock1.expectedMinimumMessageCount(2);
    MockEndpoint mock2 = camel2.getEndpoint("mock:two", MockEndpoint.class);
    mock2.expectedMinimumMessageCount(6);
    mock1.assertIsSatisfied();
    JobDetail detail = mock1.getReceivedExchanges().get(0).getIn().getHeader("jobDetail", JobDetail.class);
    Assert.assertThat(detail.getJobDataMap().get(QuartzConstants.QUARTZ_TRIGGER_CRON_EXPRESSION).equals("0/2 * * * * ?"), CoreMatchers.is(true));
    camel1.stop();
    mock2.assertIsSatisfied();
    detail = mock2.getReceivedExchanges().get(0).getIn().getHeader("jobDetail", JobDetail.class);
    Assert.assertThat(detail.getJobDataMap().get(QuartzConstants.QUARTZ_TRIGGER_CRON_EXPRESSION).equals("0/1 * * * * ?"), CoreMatchers.is(true));
    camel2.stop();
}

92. QuartzTwoCamelContextTest#testTwoCamelContext()

View license
@Test
public void testTwoCamelContext() throws Exception {
    MockEndpoint mock1 = camel1.getEndpoint("mock:one", MockEndpoint.class);
    mock1.expectedMinimumMessageCount(2);
    MockEndpoint mock2 = camel2.getEndpoint("mock:two", MockEndpoint.class);
    mock2.expectedMinimumMessageCount(6);
    mock1.assertIsSatisfied();
    camel1.stop();
    mock2.assertIsSatisfied();
    camel2.stop();
}

93. QuartzTwoCamelContextSameNameClashTest#testTwoCamelContext()

View license
@Test
public void testTwoCamelContext() throws Exception {
    assertNotSame(camel1.getManagementName(), camel2.getManagementName());
    MockEndpoint mock1 = camel1.getEndpoint("mock:one", MockEndpoint.class);
    mock1.expectedMinimumMessageCount(2);
    MockEndpoint mock2 = camel2.getEndpoint("mock:two", MockEndpoint.class);
    mock2.expectedMinimumMessageCount(6);
    mock1.assertIsSatisfied();
    camel1.stop();
    mock2.assertIsSatisfied();
    camel2.stop();
}

94. QuartzRouteRestartTest#testQuartzCronRoute()

Project: camel
Source File: QuartzRouteRestartTest.java
View license
@Test
public void testQuartzCronRoute() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMinimumMessageCount(2);
    assertMockEndpointsSatisfied();
    // restart route
    context().stopRoute("trigger");
    mock.reset();
    mock.expectedMessageCount(0);
    // wait a bit
    Thread.sleep(2000);
    assertMockEndpointsSatisfied();
    // start route, and we got messages again
    mock.reset();
    mock.expectedMinimumMessageCount(1);
    context().startRoute("trigger");
    assertMockEndpointsSatisfied();
}

95. ExceptionTest#testExceptionWithHandler()

Project: camel
Source File: ExceptionTest.java
View license
public void testExceptionWithHandler() throws Exception {
    MockEndpoint errorEndpoint = getMockEndpoint("mock:error");
    MockEndpoint resultEndpoint = getMockEndpoint("mock:result");
    MockEndpoint exceptionEndpoint = getMockEndpoint("mock:exception");
    errorEndpoint.expectedMessageCount(0);
    exceptionEndpoint.expectedBodiesReceived("<exception/>");
    resultEndpoint.expectedMessageCount(0);
    try {
        template.sendBody("direct:start", "<body/>");
        fail("Should have thrown exception");
    } catch (Exception e) {
    }
    assertMockEndpointsSatisfied();
}

96. InterceptFromPredicateProceedAndStopTest#testInterceptorNoPredicate()

View license
public void testInterceptorNoPredicate() throws Exception {
    context.addRoutes(new RouteBuilder() {

        public void configure() throws Exception {
            interceptFrom().to("mock:test");
            from("seda:order").to("mock:ok");
        }
    });
    MockEndpoint mockTest = getMockEndpoint("mock:test");
    mockTest.expectedBodiesReceived("Camel in Action");
    MockEndpoint mockOk = getMockEndpoint("mock:ok");
    mockOk.expectedBodiesReceived("Camel in Action");
    template.sendBodyAndHeader("seda:order", "Camel in Action", "user", "test");
    mockTest.assertIsSatisfied();
    mockOk.assertIsSatisfied();
}

97. ExceptionTest#testLongRouteWithHandler()

Project: camel
Source File: ExceptionTest.java
View license
public void testLongRouteWithHandler() throws Exception {
    MockEndpoint errorEndpoint = getMockEndpoint("mock:error");
    MockEndpoint resultEndpoint = getMockEndpoint("mock:result");
    MockEndpoint exceptionEndpoint = getMockEndpoint("mock:exception");
    errorEndpoint.expectedMessageCount(0);
    exceptionEndpoint.expectedBodiesReceived("<exception/>");
    resultEndpoint.expectedMessageCount(0);
    try {
        template.sendBody("direct:start2", "<body/>");
        fail("Should have thrown exception");
    } catch (Exception e) {
    }
    assertMockEndpointsSatisfied();
}

98. ExceptionTest#testExceptionWithLongHandler()

Project: camel
Source File: ExceptionTest.java
View license
public void testExceptionWithLongHandler() throws Exception {
    MockEndpoint errorEndpoint = getMockEndpoint("mock:error");
    MockEndpoint resultEndpoint = getMockEndpoint("mock:result");
    MockEndpoint exceptionEndpoint = getMockEndpoint("mock:exception");
    errorEndpoint.expectedMessageCount(0);
    exceptionEndpoint.expectedBodiesReceived("<not-handled/>");
    resultEndpoint.expectedMessageCount(0);
    try {
        template.sendBody("direct:start", "<body/>");
        fail("Should have thrown exception");
    } catch (Exception e) {
    }
    assertMockEndpointsSatisfied();
}

99. InterceptFromPredicateProceedAndStopTest#testInterceptorNoPredicateAndProceed()

View license
public void testInterceptorNoPredicateAndProceed() throws Exception {
    context.addRoutes(new RouteBuilder() {

        public void configure() throws Exception {
            interceptFrom().to("mock:test");
            from("seda:order").to("mock:ok");
        }
    });
    MockEndpoint mockTest = getMockEndpoint("mock:test");
    mockTest.expectedBodiesReceived("Camel in Action");
    MockEndpoint mockOk = getMockEndpoint("mock:ok");
    mockOk.expectedBodiesReceived("Camel in Action");
    template.sendBodyAndHeader("seda:order", "Camel in Action", "user", "test");
    mockTest.assertIsSatisfied();
    mockOk.assertIsSatisfied();
}

100. ExceptionTest#testExceptionWithoutHandler()

Project: camel
Source File: ExceptionTest.java
View license
public void testExceptionWithoutHandler() throws Exception {
    MockEndpoint errorEndpoint = getMockEndpoint("mock:error");
    MockEndpoint resultEndpoint = getMockEndpoint("mock:result");
    MockEndpoint exceptionEndpoint = getMockEndpoint("mock:exception");
    errorEndpoint.expectedBodiesReceived("<exception/>");
    exceptionEndpoint.expectedMessageCount(0);
    resultEndpoint.expectedMessageCount(0);
    // we don't expect any thrown exception here as there's no onException clause defined for this test
    // so that the general purpose dead letter channel will come into the play and then when all the attempts
    // to redelivery fails the exchange will be moved to "mock:error" and then from the client point of
    // view the exchange is completed.
    template.sendBody("direct:start", "<body/>");
    assertMockEndpointsSatisfied();
}