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

The following examples show how to use org.apache.camel.component.mock.MockEndpoint#expectedBodiesReceivedInAnyOrder() . 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: SplitParallelProcessingTimeoutSpringTest.java    From camel-cookbook-examples with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example 2
Source File: SplitExecutorServiceSpringTest.java    From camel-cookbook-examples with Apache License 2.0 6 votes vote down vote up
@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);
    mockSplit.expectedBodiesReceivedInAnyOrder(messageFragments);

    MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.setExpectedMessageCount(1);
    mockOut.message(0).body().isEqualTo(messageFragments);

    template.sendBody("direct:in", messageFragments);

    assertMockEndpointsSatisfied();
}
 
Example 3
Source File: SplitParallelProcessingTest.java    From camel-cookbook-examples with Apache License 2.0 6 votes vote down vote up
@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);
    mockSplit.expectedBodiesReceivedInAnyOrder(messageFragments);

    MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.setExpectedMessageCount(1);
    mockOut.message(0).body().isEqualTo(messageFragments);

    template.sendBody("direct:in", messageFragments);

    assertMockEndpointsSatisfied();
}
 
Example 4
Source File: SplitParallelProcessingTimeoutTest.java    From camel-cookbook-examples with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example 5
Source File: SplitParallelProcessingSpringTest.java    From camel-cookbook-examples with Apache License 2.0 6 votes vote down vote up
@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);
    mockSplit.expectedBodiesReceivedInAnyOrder(messageFragments);

    MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.setExpectedMessageCount(1);
    mockOut.message(0).body().isEqualTo(messageFragments);

    template.sendBody("direct:in", messageFragments);

    assertMockEndpointsSatisfied();
}
 
Example 6
Source File: SplitExecutorServiceTest.java    From camel-cookbook-examples with Apache License 2.0 6 votes vote down vote up
@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);
    mockSplit.expectedBodiesReceivedInAnyOrder(messageFragments);

    MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.setExpectedMessageCount(1);
    mockOut.message(0).body().isEqualTo(messageFragments);

    template.sendBody("direct:in", messageFragments);

    assertMockEndpointsSatisfied();
}
 
Example 7
Source File: SplitNaturalSpringTest.java    From camel-cookbook-examples with Apache License 2.0 6 votes vote down vote up
@Test
public void testSplitIterable() throws Exception {
    Set<String> set = new TreeSet<String>();
    set.add("one");
    set.add("two");
    set.add("three");
    Iterator<String> iterator = set.iterator();

    MockEndpoint mockSplit = getMockEndpoint("mock:split");
    mockSplit.expectedMessageCount(3);
    mockSplit.expectedBodiesReceivedInAnyOrder("one", "two", "three");

    MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.expectedMessageCount(1);
    mockOut.message(0).body().isEqualTo(iterator);

    template.sendBody("direct:in", iterator);

    assertMockEndpointsSatisfied();
}
 
Example 8
Source File: SplitNaturalTest.java    From camel-cookbook-examples with Apache License 2.0 6 votes vote down vote up
@Test
public void testSplitIterable() throws Exception {
    Set<String> set = new TreeSet<String>();
    set.add("one");
    set.add("two");
    set.add("three");
    Iterator<String> iterator = set.iterator();

    MockEndpoint mockSplit = getMockEndpoint("mock:split");
    mockSplit.expectedMessageCount(3);
    mockSplit.expectedBodiesReceivedInAnyOrder("one", "two", "three");

    MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.expectedMessageCount(1);
    mockOut.message(0).body().isEqualTo(iterator);

    template.sendBody("direct:in", iterator);

    assertMockEndpointsSatisfied();
}
 
Example 9
Source File: SecondMockTest.java    From camelinaction2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testTwoMessages() throws Exception {
    // get the mock endpoint
    MockEndpoint quote = getMockEndpoint("mock:quote");
    // set expectations the two messages arrives in any order
    quote.expectedBodiesReceivedInAnyOrder("Camel rocks", "Hello Camel");

    // fire in a messages to Camel
    template.sendBody("stub:jms:topic:quote", "Hello Camel");
    template.sendBody("stub:jms:topic:quote", "Camel rocks");

    // verify the result
    quote.assertIsSatisfied();
}
 
Example 10
Source File: SpringSecondMockTest.java    From camelinaction2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testTwoMessages() throws Exception {
    // get the mock endpoint
    MockEndpoint quote = getMockEndpoint("mock:quote");
    // set expectations the two messages arrives in any order
    quote.expectedBodiesReceivedInAnyOrder("Camel rocks", "Hello Camel");

    // fire in a messages to Camel
    template.sendBody("stub:jms:topic:quote", "Hello Camel");
    template.sendBody("stub:jms:topic:quote", "Camel rocks");

    // verify the result
    quote.assertIsSatisfied();
}
 
Example 11
Source File: FirstMockTest.java    From camelinaction with Apache License 2.0 5 votes vote down vote up
@Test
public void testTwoMessages() throws Exception {
    // get the mock endpoint
    MockEndpoint quote = getMockEndpoint("mock:quote");
    // set expectations the two messages arrives in any order
    quote.expectedBodiesReceivedInAnyOrder("Camel rocks", "Hello Camel");

    // fire in a messages to Camel
    template.sendBody("jms:topic:quote", "Hello Camel");
    template.sendBody("jms:topic:quote", "Camel rocks");

    // verify the result
    quote.assertIsSatisfied();
}
 
Example 12
Source File: ReactiveStreamsIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testStreamPublishSubscribe() throws Exception {
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start")
            .to("reactive-streams:pub");

            from("reactive-streams:sub")
            .to("mock:result");
        }
    });

    MockEndpoint mockEndpoint = camelctx.getEndpoint("mock:result", MockEndpoint.class);
    mockEndpoint.expectedBodiesReceivedInAnyOrder(1, 2, 3, 4, 5);

    camelctx.start();
    try {
        Subscriber<Integer> sub = CamelReactiveStreams.get(camelctx).streamSubscriber("sub", Integer.class);
        Publisher<Integer> pub = CamelReactiveStreams.get(camelctx).fromStream("pub", Integer.class);
        pub.subscribe(sub);

        ProducerTemplate template = camelctx.createProducerTemplate();
        for (int i = 1; i <= 5; i++) {
            template.sendBody("direct:start", i);
        }

        mockEndpoint.assertIsSatisfied();
    } finally {
        camelctx.close();
    }
}
 
Example 13
Source File: HdfsIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testHdfsComponent() throws Exception {

    Assume.assumeFalse("[#1961] HdfsIntegrationTest fails on Windows", EnvironmentUtils.isWindows());

    String dataDir = Paths.get(System.getProperty("jboss.server.data.dir"), "hadoop").toString();
    String port = AvailablePortFinder.readServerData("hdfs-port");

    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start")
            .toF("hdfs://localhost:%s%s?fileSystemType=HDFS&splitStrategy=BYTES:5,IDLE:1000", port, dataDir);

            fromF("hdfs://localhost:%s%s?pattern=*&fileSystemType=HDFS&chunkSize=5", port, dataDir).id("hdfs-consumer").autoStartup(false)
            .to("mock:result");
        }
    });

    camelctx.start();
    try {
        ProducerTemplate template = camelctx.createProducerTemplate();

        List<String> bodies = new ArrayList<>();
        for (int i = 0; i < 10; ++i) {
            String body = "CIAO" + i;
            bodies.add(body);
            template.sendBody("direct:start", body);
        }

        camelctx.getRouteController().startRoute("hdfs-consumer");

        MockEndpoint mockEndpoint = camelctx.getEndpoint("mock:result", MockEndpoint.class);
        mockEndpoint.expectedBodiesReceivedInAnyOrder(bodies);
        mockEndpoint.assertIsSatisfied();
    } finally {
        camelctx.close();
    }
}