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

The following examples show how to use org.apache.camel.component.mock.MockEndpoint#getReceivedExchanges() . 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: CustomThreadPoolRefRouteBuilderSpringTest.java    From camel-cookbook-examples with Apache License 2.0 6 votes vote down vote up
@Test
public void testProcessedByCustomThreadPool() throws InterruptedException {
    final int messageCount = 50;

    final MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.setExpectedMessageCount(messageCount);
    mockOut.setResultWaitTime(6000);

    for (int i = 0; i < messageCount; i++) {
        template.asyncSendBody("direct:in", "Message[" + i + "]");
    }

    assertMockEndpointsSatisfied();
    List<Exchange> receivedExchanges = mockOut.getReceivedExchanges();
    for (Exchange exchange : receivedExchanges) {
        assertTrue(exchange.getIn().getBody(String.class).endsWith("CustomThreadPool"));
    }
}
 
Example 2
Source File: SplitReaggregateSpringTest.java    From camel-cookbook-examples with Apache License 2.0 6 votes vote down vote up
@Test
public void testSplitAggregatesResponsesCombined() throws Exception {
    MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.expectedMessageCount(2);

    String filename = "target/classes/xml/books-extended.xml";
    assertFileExists(filename);
    InputStream booksStream = new FileInputStream(filename);

    template.sendBody("direct:combined", booksStream);

    assertMockEndpointsSatisfied();
    List<Exchange> receivedExchanges = mockOut.getReceivedExchanges();
    assertBooksByCategory(receivedExchanges.get(0));
    assertBooksByCategory(receivedExchanges.get(1));
}
 
Example 3
Source File: SplitReaggregateSpringTest.java    From camel-cookbook-examples with Apache License 2.0 6 votes vote down vote up
@Test
public void testSplitAggregatesResponses() throws Exception {
    MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.expectedMessageCount(2);

    String filename = "target/classes/xml/books-extended.xml";
    assertFileExists(filename);
    InputStream booksStream = new FileInputStream(filename);

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

    assertMockEndpointsSatisfied();
    List<Exchange> receivedExchanges = mockOut.getReceivedExchanges();
    assertBooksByCategory(receivedExchanges.get(0));
    assertBooksByCategory(receivedExchanges.get(1));
}
 
Example 4
Source File: CustomThreadPoolInlineTest.java    From camel-cookbook-examples with Apache License 2.0 6 votes vote down vote up
@Test
public void testProcessedByCustomThreadPool() throws InterruptedException {
    final int messageCount = 50;

    final MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.setExpectedMessageCount(messageCount);
    mockOut.setResultWaitTime(6000);

    for (int i = 0; i < messageCount; i++) {
        template.asyncSendBody("direct:in", "Message[" + i + "]");
    }

    assertMockEndpointsSatisfied();
    List<Exchange> receivedExchanges = mockOut.getReceivedExchanges();
    for (Exchange exchange : receivedExchanges) {
        assertTrue(exchange.getIn().getBody(String.class).endsWith("CustomThreadPool"));
    }
}
 
Example 5
Source File: SplitReaggregateTest.java    From camel-cookbook-examples with Apache License 2.0 6 votes vote down vote up
@Test
public void testSplitAggregatesResponsesCombined() throws Exception {
    MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.expectedMessageCount(2);

    String filename = "target/classes/xml/books-extended.xml";
    assertFileExists(filename);
    InputStream booksStream = new FileInputStream(filename);

    template.sendBody("direct:combined", booksStream);

    assertMockEndpointsSatisfied();
    List<Exchange> receivedExchanges = mockOut.getReceivedExchanges();
    assertBooksByCategory(receivedExchanges.get(0));
    assertBooksByCategory(receivedExchanges.get(1));
}
 
Example 6
Source File: KuduConsumerTest.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@Ignore
public void insertRow() throws KuduException, InterruptedException {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);

    assertMockEndpointsSatisfied();

    List<Exchange> exchanges = mock.getReceivedExchanges();
    assertEquals(1, exchanges.size());

    KuduScanner scanner = exchanges.get(0).getIn().getBody(KuduScanner.class);

    RowResultIterator results = scanner.nextRows();
    RowResult result = results.next();

    ColumnSchema columnByIndex = result.getSchema().getColumnByIndex(0);
    String name = columnByIndex.getName();

    assertEquals("id", name);
    assertEquals(46, result.getInt(0));
    assertEquals(10, result.getInt(1));
}
 
Example 7
Source File: CustomThreadPoolSpringTest.java    From camel-cookbook-examples with Apache License 2.0 6 votes vote down vote up
@Test
public void testProcessedByCustomThreadPool() throws InterruptedException {
    final int messageCount = 50;

    final MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.setExpectedMessageCount(messageCount);
    mockOut.setResultWaitTime(6000);

    for (int i = 0; i < messageCount; i++) {
        template.asyncSendBody("direct:in", "Message[" + i + "]");
    }

    assertMockEndpointsSatisfied();
    List<Exchange> receivedExchanges = mockOut.getReceivedExchanges();
    for (Exchange exchange : receivedExchanges) {
        assertTrue(exchange.getIn().getBody(String.class).endsWith("CustomThreadPool"));
    }
}
 
Example 8
Source File: SpringSecondMockTest.java    From camelinaction2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testIsCamelMessage() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:quote");
    mock.expectedMessageCount(2);

    template.sendBody("stub:jms:topic:quote", "Hello Camel");
    template.sendBody("stub:jms:topic:quote", "Camel rocks");

    assertMockEndpointsSatisfied();

    List<Exchange> list = mock.getReceivedExchanges();
    String body1 = list.get(0).getIn().getBody(String.class);
    String body2 = list.get(1).getIn().getBody(String.class);
    assertTrue(body1.contains("Camel"));
    assertTrue(body2.contains("Camel"));
}
 
Example 9
Source File: AggregateSimpleSpringTest.java    From camel-cookbook-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void testAggregation() throws InterruptedException {
    MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.setExpectedMessageCount(2);

    template.sendBodyAndHeader("direct:in", "One", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Two", "group", "even");
    template.sendBodyAndHeader("direct:in", "Three", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Four", "group", "even");
    template.sendBodyAndHeader("direct:in", "Five", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Six", "group", "even");
    template.sendBodyAndHeader("direct:in", "Seven", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Eight", "group", "even");
    template.sendBodyAndHeader("direct:in", "Nine", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Ten", "group", "even");

    assertMockEndpointsSatisfied();

    List<Exchange> receivedExchanges = mockOut.getReceivedExchanges();
    @SuppressWarnings("unchecked")
    Set<String> odd = Collections.checkedSet(receivedExchanges.get(0).getIn().getBody(Set.class), String.class);
    assertTrue(odd.containsAll(Arrays.asList("One", "Three", "Five", "Seven", "Nine")));

    @SuppressWarnings("unchecked")
    Set<String> even = Collections.checkedSet(receivedExchanges.get(1).getIn().getBody(Set.class), String.class);
    assertTrue(even.containsAll(Arrays.asList("Two", "Four", "Six", "Eight", "Ten")));
}
 
Example 10
Source File: AggregateDynamicCompletionSizeTest.java    From camel-cookbook-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void testAggregation() throws InterruptedException {
    MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.setExpectedMessageCount(2);

    Map<String, Object> oddHeaders = new HashMap<String, Object>();
    oddHeaders.put("group", "odd");
    oddHeaders.put("batchSize", "5");

    Map<String, Object> evenHeaders = new HashMap<String, Object>();
    evenHeaders.put("group", "even");
    evenHeaders.put("batchSize", "4");

    template.sendBodyAndHeaders("direct:in", "One", oddHeaders);
    template.sendBodyAndHeaders("direct:in", "Two", evenHeaders);
    template.sendBodyAndHeaders("direct:in", "Three", oddHeaders);
    template.sendBodyAndHeaders("direct:in", "Four", evenHeaders);
    template.sendBodyAndHeaders("direct:in", "Five", oddHeaders);
    template.sendBodyAndHeaders("direct:in", "Six", evenHeaders);
    template.sendBodyAndHeaders("direct:in", "Seven", oddHeaders);
    template.sendBodyAndHeaders("direct:in", "Eight", evenHeaders);
    template.sendBodyAndHeaders("direct:in", "Nine", oddHeaders);

    assertMockEndpointsSatisfied();

    List<Exchange> receivedExchanges = mockOut.getReceivedExchanges();
    @SuppressWarnings("unchecked")
    Set<String> even = Collections.checkedSet(receivedExchanges.get(0).getIn().getBody(Set.class), String.class);
    assertTrue(even.containsAll(Arrays.asList("Two", "Four", "Six", "Eight")));

    @SuppressWarnings("unchecked")
    Set<String> odd = Collections.checkedSet(receivedExchanges.get(1).getIn().getBody(Set.class), String.class);
    assertTrue(odd.containsAll(Arrays.asList("One", "Three", "Five", "Seven", "Nine")));
}
 
Example 11
Source File: UndertowWsIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void wsClientMultipleText() throws Exception {
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            final int port = getPort();
            from("undertow:ws://localhost:" + port + "/app1")
                    .log(">>> Message received from WebSocket Client : ${body}").to("mock:result1");
        }

    });

    camelctx.start();
    try {
        TestClient websocket1 = new TestClient("ws://localhost:" + getPort() + "/app1").connect();
        TestClient websocket2 = new TestClient("ws://localhost:" + getPort() + "/app1").connect();

        MockEndpoint result = camelctx.getEndpoint("mock:result1", MockEndpoint.class);
        result.expectedMessageCount(2);

        websocket1.sendTextMessage("Test1");
        websocket2.sendTextMessage("Test2");

        result.await(60, TimeUnit.SECONDS);
        result.assertIsSatisfied();
        List<Exchange> exchanges = result.getReceivedExchanges();
        Set<String> actual = new HashSet<>();
        actual.add(exchanges.get(0).getIn().getBody(String.class));
        actual.add(exchanges.get(1).getIn().getBody(String.class));
        Assert.assertEquals(new HashSet<String>(Arrays.asList("Test1", "Test2")), actual);

        websocket1.close();
        websocket2.close();
    } finally {
        camelctx.close();
    }
}
 
Example 12
Source File: AggregateCompletionConditionSpringTest.java    From camel-cookbook-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void testAggregation() throws InterruptedException {
    MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.setExpectedMessageCount(2);

    template.sendBodyAndHeader("direct:in", "One", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Two", "group", "even");
    template.sendBodyAndHeader("direct:in", "Three", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Four", "group", "even");
    template.sendBodyAndHeader("direct:in", "Five", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Six", "group", "even");
    template.sendBodyAndHeader("direct:in", "Seven", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Eight", "group", "even");
    template.sendBodyAndHeader("direct:in", "Nine", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Ten", "group", "even");

    assertMockEndpointsSatisfied();

    List<Exchange> receivedExchanges = mockOut.getReceivedExchanges();
    @SuppressWarnings("unchecked")
    Set<String> odd = Collections.checkedSet(receivedExchanges.get(0).getIn().getBody(Set.class), String.class);
    assertTrue(odd.containsAll(Arrays.asList("One", "Three", "Five", "Seven", "Nine")));

    @SuppressWarnings("unchecked")
    Set<String> even = Collections.checkedSet(receivedExchanges.get(1).getIn().getBody(Set.class), String.class);
    assertTrue(even.containsAll(Arrays.asList("Two", "Four", "Six", "Eight", "Ten")));
}
 
Example 13
Source File: AggregateDynamicCompletionSizeSpringTest.java    From camel-cookbook-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void testAggregation() throws InterruptedException {
    MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.setExpectedMessageCount(2);

    Map<String, Object> oddHeaders = new HashMap<String, Object>();
    oddHeaders.put("group", "odd");
    oddHeaders.put("batchSize", "5");

    Map<String, Object> evenHeaders = new HashMap<String, Object>();
    evenHeaders.put("group", "even");
    evenHeaders.put("batchSize", "4");

    template.sendBodyAndHeaders("direct:in", "One", oddHeaders);
    template.sendBodyAndHeaders("direct:in", "Two", evenHeaders);
    template.sendBodyAndHeaders("direct:in", "Three", oddHeaders);
    template.sendBodyAndHeaders("direct:in", "Four", evenHeaders);
    template.sendBodyAndHeaders("direct:in", "Five", oddHeaders);
    template.sendBodyAndHeaders("direct:in", "Six", evenHeaders);
    template.sendBodyAndHeaders("direct:in", "Seven", oddHeaders);
    template.sendBodyAndHeaders("direct:in", "Eight", evenHeaders);
    template.sendBodyAndHeaders("direct:in", "Nine", oddHeaders);

    assertMockEndpointsSatisfied();

    List<Exchange> receivedExchanges = mockOut.getReceivedExchanges();
    @SuppressWarnings("unchecked")
    Set<String> even = Collections.checkedSet(receivedExchanges.get(0).getIn().getBody(Set.class), String.class);
    assertTrue(even.containsAll(Arrays.asList("Two", "Four", "Six", "Eight")));

    @SuppressWarnings("unchecked")
    Set<String> odd = Collections.checkedSet(receivedExchanges.get(1).getIn().getBody(Set.class), String.class);
    assertTrue(odd.containsAll(Arrays.asList("One", "Three", "Five", "Seven", "Nine")));
}
 
Example 14
Source File: UndertowWsIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void wsClientSingleBytesStreaming() throws Exception {
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            final int port = getPort();
            from("undertow:ws://localhost:" + port + "/app2?useStreaming=true").to("mock:result2");
        }
    });

    camelctx.start();
    try {
        TestClient websocket = new TestClient("ws://localhost:" + getPort() + "/app2").connect();

        MockEndpoint result = camelctx.getEndpoint("mock:result2", MockEndpoint.class);
        result.expectedMessageCount(1);

        final byte[] testmessage = "Test".getBytes("utf-8");
        websocket.sendBytesMessage(testmessage);

        result.await(60, TimeUnit.SECONDS);
        List<Exchange> exchanges = result.getReceivedExchanges();
        Assert.assertEquals(1, exchanges.size());
        Object body = result.getReceivedExchanges().get(0).getIn().getBody();
        Assert.assertTrue("body is " + body.getClass().getName(), body instanceof InputStream);
        InputStream in = (InputStream) body;
        Assert.assertArrayEquals(testmessage, IOConverter.toBytes(in));

        websocket.close();
    } finally {
        camelctx.close();
    }
}
 
Example 15
Source File: AggregateCompletionTimeoutSpringTest.java    From camel-cookbook-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void testAggregation() throws InterruptedException {
    MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.setExpectedMessageCount(2);

    template.sendBodyAndHeader("direct:in", "One", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Two", "group", "even");
    template.sendBodyAndHeader("direct:in", "Three", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Four", "group", "even");
    template.sendBodyAndHeader("direct:in", "Five", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Six", "group", "even");
    template.sendBodyAndHeader("direct:in", "Seven", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Eight", "group", "even");
    template.sendBodyAndHeader("direct:in", "Nine", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Ten", "group", "even");

    assertMockEndpointsSatisfied();

    for (Exchange exchange : mockOut.getReceivedExchanges()) {
        @SuppressWarnings("unchecked")
        Set<String> set = Collections.checkedSet(exchange.getIn().getBody(Set.class), String.class);
        if (set.contains("One")) { // odd
            assertTrue(set.containsAll(Arrays.asList("One", "Three", "Five", "Seven", "Nine")));
        } else { // even
            assertTrue(set.containsAll(Arrays.asList("Two", "Four", "Six", "Eight", "Ten")));
        }
    }
}
 
Example 16
Source File: AggregateCompletionConditionTest.java    From camel-cookbook-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void testAggregation() throws InterruptedException {
    MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.setExpectedMessageCount(2);

    template.sendBodyAndHeader("direct:in", "One", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Two", "group", "even");
    template.sendBodyAndHeader("direct:in", "Three", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Four", "group", "even");
    template.sendBodyAndHeader("direct:in", "Five", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Six", "group", "even");
    template.sendBodyAndHeader("direct:in", "Seven", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Eight", "group", "even");
    template.sendBodyAndHeader("direct:in", "Nine", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Ten", "group", "even");

    assertMockEndpointsSatisfied();

    List<Exchange> receivedExchanges = mockOut.getReceivedExchanges();
    @SuppressWarnings("unchecked")
    Set<String> odd = Collections.checkedSet(receivedExchanges.get(0).getIn().getBody(Set.class), String.class);
    assertTrue(odd.containsAll(Arrays.asList("One", "Three", "Five", "Seven", "Nine")));

    @SuppressWarnings("unchecked")
    Set<String> even = Collections.checkedSet(receivedExchanges.get(1).getIn().getBody(Set.class), String.class);
    assertTrue(even.containsAll(Arrays.asList("Two", "Four", "Six", "Eight", "Ten")));
}
 
Example 17
Source File: AggregateExecutorServiceSpringTest.java    From camel-cookbook-examples with Apache License 2.0 4 votes vote down vote up
@Test
public void testAggregation() throws InterruptedException {
    MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.setExpectedMessageCount(2);

    template.sendBodyAndHeader("direct:in", "One", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Two", "group", "even");
    template.sendBodyAndHeader("direct:in", "Three", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Four", "group", "even");
    template.sendBodyAndHeader("direct:in", "Five", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Six", "group", "even");
    template.sendBodyAndHeader("direct:in", "Seven", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Eight", "group", "even");
    template.sendBodyAndHeader("direct:in", "Nine", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Ten", "group", "even");

    assertMockEndpointsSatisfied();

    final List<Exchange> receivedExchanges = mockOut.getReceivedExchanges();
    final Message message1 = receivedExchanges.get(0).getIn();
    final Message message2 = receivedExchanges.get(1).getIn();

    log.info("exchange(0).header.group = {}", message1.getHeader("group"));
    log.info("exchange(0).property.CamelAggregatedCompletedBy = {}", message1.getExchange().getProperty("CamelAggregatedCompletedBy"));
    log.info("exchange(1).header.group = {}", message2.getHeader("group"));
    log.info("exchange(1).property.CamelAggregatedCompletedBy = {}", message2.getExchange().getProperty("CamelAggregatedCompletedBy"));

    final List<String> odd = Arrays.asList("One", "Three", "Five", "Seven", "Nine");
    final List<String> even = Arrays.asList("Two", "Four", "Six", "Eight", "Ten");

    @SuppressWarnings("unchecked")
    final Set<String> set1 = Collections.checkedSet(message1.getBody(Set.class), String.class);
    @SuppressWarnings("unchecked")
    final Set<String> set2 = Collections.checkedSet(message2.getBody(Set.class), String.class);

    if ("odd".equals(message1.getHeader("group"))) {
        assertTrue(set1.containsAll(odd));
        assertTrue(set2.containsAll(even));
    } else {
        assertTrue(set1.containsAll(even));
        assertTrue(set2.containsAll(odd));
    }
}
 
Example 18
Source File: AggregateParallelProcessingTest.java    From camel-cookbook-examples with Apache License 2.0 4 votes vote down vote up
@Test
public void testAggregation() throws InterruptedException {
    MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.setExpectedMessageCount(2);

    template.sendBodyAndHeader("direct:in", "One", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Two", "group", "even");
    template.sendBodyAndHeader("direct:in", "Three", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Four", "group", "even");
    template.sendBodyAndHeader("direct:in", "Five", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Six", "group", "even");
    template.sendBodyAndHeader("direct:in", "Seven", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Eight", "group", "even");
    template.sendBodyAndHeader("direct:in", "Nine", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Ten", "group", "even");

    assertMockEndpointsSatisfied();

    final List<Exchange> receivedExchanges = mockOut.getReceivedExchanges();
    final Message message1 = receivedExchanges.get(0).getIn();
    final Message message2 = receivedExchanges.get(1).getIn();

    log.info("exchange(0).header.group = {}", message1.getHeader("group"));
    log.info("exchange(0).property.CamelAggregatedCompletedBy = {}", message1.getExchange().getProperty("CamelAggregatedCompletedBy"));
    log.info("exchange(1).header.group = {}", message2.getHeader("group"));
    log.info("exchange(1).property.CamelAggregatedCompletedBy = {}", message2.getExchange().getProperty("CamelAggregatedCompletedBy"));

    final List<String> odd = Arrays.asList("One", "Three", "Five", "Seven", "Nine");
    final List<String> even = Arrays.asList("Two", "Four", "Six", "Eight", "Ten");

    @SuppressWarnings("unchecked")
    final Set<String> set1 = Collections.checkedSet(message1.getBody(Set.class), String.class);
    @SuppressWarnings("unchecked")
    final Set<String> set2 = Collections.checkedSet(message2.getBody(Set.class), String.class);

    if ("odd".equals(message1.getHeader("group"))) {
        assertTrue(set1.containsAll(odd));
        assertTrue(set2.containsAll(even));
    } else {
        assertTrue(set1.containsAll(even));
        assertTrue(set2.containsAll(odd));
    }
}
 
Example 19
Source File: AggregateParallelProcessingSpringTest.java    From camel-cookbook-examples with Apache License 2.0 4 votes vote down vote up
@Test
public void testAggregation() throws InterruptedException {
    MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.setExpectedMessageCount(2);

    template.sendBodyAndHeader("direct:in", "One", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Two", "group", "even");
    template.sendBodyAndHeader("direct:in", "Three", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Four", "group", "even");
    template.sendBodyAndHeader("direct:in", "Five", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Six", "group", "even");
    template.sendBodyAndHeader("direct:in", "Seven", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Eight", "group", "even");
    template.sendBodyAndHeader("direct:in", "Nine", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Ten", "group", "even");

    assertMockEndpointsSatisfied();

    final List<Exchange> receivedExchanges = mockOut.getReceivedExchanges();
    final Message message1 = receivedExchanges.get(0).getIn();
    final Message message2 = receivedExchanges.get(1).getIn();

    log.info("exchange(0).header.group = {}", message1.getHeader("group"));
    log.info("exchange(0).property.CamelAggregatedCompletedBy = {}", message1.getExchange().getProperty("CamelAggregatedCompletedBy"));
    log.info("exchange(1).header.group = {}", message2.getHeader("group"));
    log.info("exchange(1).property.CamelAggregatedCompletedBy = {}", message2.getExchange().getProperty("CamelAggregatedCompletedBy"));

    final List<String> odd = Arrays.asList("One", "Three", "Five", "Seven", "Nine");
    final List<String> even = Arrays.asList("Two", "Four", "Six", "Eight", "Ten");

    @SuppressWarnings("unchecked")
    final Set<String> set1 = Collections.checkedSet(message1.getBody(Set.class), String.class);
    @SuppressWarnings("unchecked")
    final Set<String> set2 = Collections.checkedSet(message2.getBody(Set.class), String.class);

    if ("odd".equals(message1.getHeader("group"))) {
        assertTrue(set1.containsAll(odd));
        assertTrue(set2.containsAll(even));
    } else {
        assertTrue(set1.containsAll(even));
        assertTrue(set2.containsAll(odd));
    }
}
 
Example 20
Source File: UndertowWsIntegrationTest.java    From wildfly-camel with Apache License 2.0 4 votes vote down vote up
@Test
public void fireWebSocketChannelEvents() throws Exception {
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            final int port = getPort();
            /* sendToAll */
            from("undertow:ws://localhost:" + port + "/app5?fireWebSocketChannelEvents=true") //
                    .to("mock:result5") //
                    .to("undertow:ws://localhost:" + port + "/app5");
        }

    });

    camelctx.start();
    try {

        MockEndpoint result = camelctx.getEndpoint("mock:result5", MockEndpoint.class);
        result.expectedMessageCount(6);

        TestClient wsclient1 = new TestClient("ws://localhost:" + getPort() + "/app5", 2);
        TestClient wsclient2 = new TestClient("ws://localhost:" + getPort() + "/app5", 2);
        wsclient1.connect();
        wsclient2.connect();

        wsclient1.sendTextMessage("Gambas");
        wsclient2.sendTextMessage("Calamares");

        wsclient1.close();
        wsclient2.close();

        result.await(60, TimeUnit.SECONDS);

        final List<Exchange> exchanges = result.getReceivedExchanges();
        final Map<String, List<String>> connections = new HashMap<>();
        for (Exchange exchange : exchanges) {
            final Message in = exchange.getIn();
            final String key = (String) in.getHeader(UndertowConstants.CONNECTION_KEY);
            Assert.assertNotNull(key);
            List<String> messages = connections.get(key);
            if (messages == null) {
                messages = new ArrayList<String>();
                connections.put(key, messages);
            }
            String body = in.getBody(String.class);
            if (body != null) {
                messages.add(body);
            } else {
                messages.add(in.getHeader(UndertowConstants.EVENT_TYPE_ENUM, EventType.class).name());
            }
        }

        final List<String> expected1 = Arrays.asList(EventType.ONOPEN.name(), "Gambas", EventType.ONCLOSE.name());
        final List<String> expected2 = Arrays.asList(EventType.ONOPEN.name(), "Calamares",
                EventType.ONCLOSE.name());

        Assert.assertEquals(2, connections.size());
        final Iterator<List<String>> it = connections.values().iterator();
        final List<String> actual1 = it.next();
        Assert.assertTrue("actual " + actual1, actual1.equals(expected1) || actual1.equals(expected2));
        final List<String> actual2 = it.next();
        Assert.assertTrue("actual " + actual2, actual2.equals(expected1) || actual2.equals(expected2));
    } finally {
        camelctx.close();
    }

}