Java Code Examples for org.apache.camel.component.mock.MockEndpoint#assertIsNotSatisfied()

The following examples show how to use org.apache.camel.component.mock.MockEndpoint#assertIsNotSatisfied() . 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: GapJava8Test.java    From camelinaction2 with Apache License 2.0 5 votes vote down vote up
/**
 * Same as the unit test above but using mock to know it should fail
 */
@Test
public void testGapDetectedExpected() throws Exception {
    final MockEndpoint mock = getMockEndpoint("mock:quote");
    mock.expectedMessageCount(3);

    // add our own expectation
    mock.expects(() -> {
        // loop the received exchanges and detect gaps
        mock.getExchanges().stream()
            // use reduce as a fold to fold in the last counter value and then detect if there is any gap
            .reduce(0, (last, exchange) -> {
                int current = exchange.getIn().getHeader("Counter", Integer.class);
                // must be greater than the last number
                if (current <= last) {
                    fail("Counter is not greater than last counter");
                    // and the gap between must exactly be 1
                } else if (current - last != 1) {
                    fail("Gap detected: last: " + last + " current: " + current);
                }
                return current;
            }, (prev, current) -> current);
    });


    template.sendBodyAndHeader("stub:jms:topic:quote", "A", "Counter", 1);
    template.sendBodyAndHeader("stub:jms:topic:quote", "B", "Counter", 2);
    template.sendBodyAndHeader("stub:jms:topic:quote", "C", "Counter", 4);

    // assert that we fail using Is_Not_Satisfied
    mock.assertIsNotSatisfied();
}
 
Example 2
Source File: GapTest.java    From camelinaction2 with Apache License 2.0 5 votes vote down vote up
/**
 * Same as the unit test above but using mock to know it should fail
 */
@Test
public void testGapDetectedExpected() throws Exception {
    final MockEndpoint mock = getMockEndpoint("mock:quote");
    mock.expectedMessageCount(3);
    mock.expects(new Runnable() {
        public void run() {
            int last = 0;
            for (Exchange exchange : mock.getExchanges()) {
                int current = exchange.getIn().getHeader("Counter", Integer.class);
                if (current <= last) {
                    fail("Counter is not greater than last counter");
                } else if (current - last != 1) {
                    fail("Gap detected: last: " + last + " current: " + current);
                }
                last = current;
            }
        }
    });

    template.sendBodyAndHeader("stub:jms:topic:quote", "A", "Counter", 1);
    template.sendBodyAndHeader("stub:jms:topic:quote", "B", "Counter", 2);
    template.sendBodyAndHeader("stub:jms:topic:quote", "C", "Counter", 4);

    // assert that we fail using Is_Not_Satisfied
    mock.assertIsNotSatisfied();
}
 
Example 3
Source File: GapTest.java    From camelinaction with Apache License 2.0 5 votes vote down vote up
/**
 * Same as the unit test above but using mock to know it should fail
 */
@Test
public void testGapDetectedExpected() throws Exception {
    final MockEndpoint mock = getMockEndpoint("mock:quote");
    mock.expectedMessageCount(3);
    mock.expects(new Runnable() {
        public void run() {
            int last = 0;
            for (Exchange exchange : mock.getExchanges()) {
                int current = exchange.getIn().getHeader("Counter", Integer.class);
                if (current <= last) {
                    fail("Counter is not greater than last counter");
                } else if (current - last != 1) {
                    fail("Gap detected: last: " + last + " current: " + current);
                }
                last = current;
            }
        }
    });

    template.sendBodyAndHeader("jms:topic:quote", "A", "Counter", 1);
    template.sendBodyAndHeader("jms:topic:quote", "B", "Counter", 2);
    template.sendBodyAndHeader("jms:topic:quote", "C", "Counter", 4);

    // assert that we fail using Is_Not_Satisfied
    mock.assertIsNotSatisfied();
}
 
Example 4
Source File: OrderProcessingRouteSpringTest.java    From camel-cookbook-examples with Apache License 2.0 4 votes vote down vote up
@Test
public void testRoutingLogic() throws Exception {
    context.getRouteDefinition("ukOrders")
        .adviceWith(context, new AdviceWithRouteBuilder() {
            @Override
            public void configure() throws Exception {
                replaceFromWith("direct:uk");

                interceptSendToEndpoint("file:///orders/out/*")
                    .skipSendToOriginalEndpoint()
                    .to("mock:out");
            }
        });

    context.getRouteDefinition("usOrders")
        .adviceWith(context, new AdviceWithRouteBuilder() {
            @Override
            public void configure() throws Exception {
                replaceFromWith("direct:us");

                interceptSendToEndpoint("file:///orders/out/*")
                    .skipSendToOriginalEndpoint()
                    .to("mock:out");
            }
        });

    context.getRouteDefinition("jamaicaOrders")
        .adviceWith(context, new AdviceWithRouteBuilder() {
            @Override
            public void configure() throws Exception {
                replaceFromWith("direct:jamaica");

                interceptSendToEndpoint("file:///orders/out/*")
                    .skipSendToOriginalEndpoint()
                    .to("mock:out");
            }
        });

    context.start();

    final MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.setExpectedMessageCount(1);
    mockOut.message(0).body().startsWith("2013-11-23");
    mockOut.message(0).header(Exchange.FILE_NAME).isEqualTo("2013-11-23.csv");

    fluentTemplate().to("direct:uk").withBody("23-11-2013,1,Geology rocks t-shirt").send();

    mockOut.assertIsSatisfied();

    mockOut.reset();
    mockOut.setExpectedMessageCount(1);
    mockOut.message(0).body().startsWith("2013-11-23");
    mockOut.message(0).header(Exchange.FILE_NAME).isEqualTo("2013-11-23.csv");

    fluentTemplate().to("direct:us").withBody("11-23-2013,1,Geology rocks t-shirt").send();

    mockOut.assertIsSatisfied();

    mockOut.reset();
    mockOut.setExpectedMessageCount(1);
    mockOut.message(0).body().startsWith("2013-11-23");
    mockOut.message(0).header(Exchange.FILE_NAME).isEqualTo("2013-11-23.csv");

    fluentTemplate().to("direct:jamaica").withBody("23-11-2013,1,Geology rocks t-shirt").send();

    mockOut.assertIsSatisfied();

    mockOut.reset();
    mockOut.setExpectedMessageCount(1);
    mockOut.message(0).body().startsWith("2013-11-23");
    mockOut.message(0).header(Exchange.FILE_NAME).isEqualTo("2013-11-23.csv");

    fluentTemplate().to("direct:uk").withBody("11-23-2013,1,Geology rocks t-shirt").send();

    mockOut.assertIsNotSatisfied();
}