當前位置: 首頁>>代碼示例>>Java>>正文


Java MockEndpoint.getReceivedExchanges方法代碼示例

本文整理匯總了Java中org.apache.camel.component.mock.MockEndpoint.getReceivedExchanges方法的典型用法代碼示例。如果您正苦於以下問題:Java MockEndpoint.getReceivedExchanges方法的具體用法?Java MockEndpoint.getReceivedExchanges怎麽用?Java MockEndpoint.getReceivedExchanges使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.camel.component.mock.MockEndpoint的用法示例。


在下文中一共展示了MockEndpoint.getReceivedExchanges方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testBeverage

import org.apache.camel.component.mock.MockEndpoint; //導入方法依賴的package包/類
@Test
public void testBeverage() throws Exception {
	MockEndpoint mock = getMockEndpoint("mock:result");

	mock.expectedMinimumMessageCount(2);
    mock.setAssertPeriod(500);
    
    assertMockEndpointsSatisfied();
    
    List<Exchange> exchanges = mock.getReceivedExchanges();
    int drinks = 0;
    for (Exchange exchange : exchanges) {
        drinks += 2;
        Message message = exchange.getIn();
        String body = message.getBody().toString();
	
        assertEquals("Total " + drinks + " of gintonic ordered", body);
    }
}
 
開發者ID:fabric8io,項目名稱:django-examples,代碼行數:20,代碼來源:BeverageTest.java

示例2: assertErrorHandlingWorks

import org.apache.camel.component.mock.MockEndpoint; //導入方法依賴的package包/類
protected void assertErrorHandlingWorks(String route) throws Exception {
    MockEndpoint resultEndpoint = getMockEndpoint("mock:result");
    MockEndpoint exceptionEndpoint = getMockEndpoint("mock:exception");

    resultEndpoint.expectedMessageCount(0);
    exceptionEndpoint.expectedBodiesReceived("<exception/>");

    try {
        template.sendBodyAndHeader("direct:start", "<body/>", "route", route);
        fail("Should have thrown exception");
    } catch (RuntimeCamelException e) {
        assertTrue(e.getCause() instanceof IllegalArgumentException);
        assertEquals("Exception thrown intentionally.", e.getCause().getMessage());
    }

    assertMockEndpointsSatisfied();

    List<Exchange> list = exceptionEndpoint.getReceivedExchanges();
    Exchange exchange = list.get(0);
    LOG.debug("Received: " + exchange.getIn());
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:22,代碼來源:RomeksExceptionTest.java

示例3: testSendXmlAndUnmarshal

import org.apache.camel.component.mock.MockEndpoint; //導入方法依賴的package包/類
@Test
public void testSendXmlAndUnmarshal() throws Exception {

    MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
    resultEndpoint.expectedMessageCount(1);

    PurchaseOrder expectedBody = new PurchaseOrder();
    expectedBody.setAmount(20.0);
    expectedBody.setName("Wine");
    expectedBody.setPrice(5.0);

    template.sendBody("direct:start", expectedBody);

    resultEndpoint.assertIsSatisfied();

    List<Exchange> list = resultEndpoint.getReceivedExchanges();
    Exchange exchange = list.get(0);
    Object actualBody = exchange.getIn().getBody();

    log.debug("Received: " + actualBody);
    assertEquals("Received body", expectedBody, actualBody);
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:23,代碼來源:UnmarshalThenMarshalTest.java

示例4: sendMessageAndHaveItTransformed

import org.apache.camel.component.mock.MockEndpoint; //導入方法依賴的package包/類
private void sendMessageAndHaveItTransformed(Object body) throws Exception {
    MockEndpoint endpoint = getMockEndpoint("mock:result");
    endpoint.expectedMessageCount(1);

    template.sendBody("direct:start", body);

    assertMockEndpointsSatisfied();

    List<Exchange> list = endpoint.getReceivedExchanges();
    Exchange exchange = list.get(0);
    String xml = exchange.getIn().getBody(String.class);
   
    assertNotNull("The transformed XML should not be null", xml);
    assertTrue(xml.indexOf("transformed") > -1);
    // the cheese tag is in the transform.xsl
    assertTrue(xml.indexOf("cheese") > -1);
    assertTrue(xml.indexOf("<subject>Hey</subject>") > -1);
    assertTrue(xml.indexOf("<body>Hello world!</body>") > -1);

    TestBean bean = context.getRegistry().lookupByNameAndType("testBean", TestBean.class);
    assertNotNull(bean);
    assertEquals("bean.subject", "Hey", bean.getSubject());
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:24,代碼來源:XsltRouteTest.java

示例5: testSendingByteMessages

import org.apache.camel.component.mock.MockEndpoint; //導入方法依賴的package包/類
@Test
public void testSendingByteMessages() throws Exception {
    MockEndpoint endpoint = getMockEndpoint("mock:result");
    endpoint.expectedMessageCount(1);

    byte[] in = "Hello from bytes".getBytes();
    template.sendBody(String.format("mina2:udp://127.0.0.1:%1$s?sync=false", getPort()), in);

    assertMockEndpointsSatisfied();
    List<Exchange> list = endpoint.getReceivedExchanges();
    byte[] out = list.get(0).getIn().getBody(byte[].class);

    for (int i = 0; i < in.length; i++) {
        assertEquals("Thew bytes should be the same", in[i], out[i]);
    }
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:17,代碼來源:Mina2UdpUsingTemplateTest.java

示例6: testConsume

import org.apache.camel.component.mock.MockEndpoint; //導入方法依賴的package包/類
@Test
public void testConsume() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMinimumMessageCount(3);

    assertMockEndpointsSatisfied();

    List<Exchange> exchanges = mock.getReceivedExchanges();
    assertTrue(exchanges.size() >= 3);

    assertEquals(1, exchanges.get(0).getIn().getBody(Map.class).get("ID"));
    assertEquals("Camel", exchanges.get(0).getIn().getBody(Map.class).get("PROJECT"));
    assertEquals(2, exchanges.get(1).getIn().getBody(Map.class).get("ID"));
    assertEquals("AMQ", exchanges.get(1).getIn().getBody(Map.class).get("PROJECT"));
    assertEquals(3, exchanges.get(2).getIn().getBody(Map.class).get("ID"));
    assertEquals("Linux", exchanges.get(2).getIn().getBody(Map.class).get("PROJECT"));
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:18,代碼來源:ElSqlConsumerTest.java

示例7: testOutputType

import org.apache.camel.component.mock.MockEndpoint; //導入方法依賴的package包/類
@Test
public void testOutputType() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMinimumMessageCount(3);

    assertMockEndpointsSatisfied();

    List<Exchange> exchanges = mock.getReceivedExchanges();
    assertTrue(exchanges.size() >= 3);

    ProjectModel row = assertIsInstanceOf(ProjectModel.class, exchanges.get(0).getIn().getBody());
    assertEquals(1, row.getId());
    assertEquals("Camel", row.getProject());
    assertEquals("ASF", row.getLicense());

    ProjectModel row2 = assertIsInstanceOf(ProjectModel.class, exchanges.get(1).getIn().getBody());
    assertEquals(2, row2.getId());
    assertEquals("AMQ", row2.getProject());
    assertEquals("ASF", row2.getLicense());

    ProjectModel row3 = assertIsInstanceOf(ProjectModel.class, exchanges.get(2).getIn().getBody());
    assertEquals(3, row3.getId());
    assertEquals("Linux", row3.getProject());
    assertEquals("XXX", row3.getLicense());
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:26,代碼來源:SqlConsumerOutputTypeSelectListWithClassTest.java

示例8: testProducer

import org.apache.camel.component.mock.MockEndpoint; //導入方法依賴的package包/類
@Test
public void testProducer() throws Exception {
    Person person = new Person("David", "Greco");
    //act
    template.requestBodyAndHeader("direct:input", person, "testHeading", "value");

    //assert
    MockEndpoint ep = context.getEndpoint("mock:test", MockEndpoint.class);
    List<Exchange> exchanges = ep.getReceivedExchanges();
    for (Exchange exchange : exchanges) {
        Message message = exchange.getIn();
        Person person1 = (Person) message.getBody();
        assertEquals("David", person1.getName());
        assertEquals("Greco", person1.getSurname());
    }
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:17,代碼來源:CometdProducerConsumerTest.java

示例9: testSendingByteMessages

import org.apache.camel.component.mock.MockEndpoint; //導入方法依賴的package包/類
@Test
public void testSendingByteMessages() throws Exception {
    MockEndpoint endpoint = getMockEndpoint("mock:result");
    endpoint.expectedMessageCount(1);

    byte[] in = "Hello from bytes".getBytes();
    template.sendBody("mina:udp://127.0.0.1:{{port}}?sync=false", in);

    assertMockEndpointsSatisfied();
    List<Exchange> list = endpoint.getReceivedExchanges();
    byte[] out = list.get(0).getIn().getBody(byte[].class);

    for (int i = 0; i < in.length; i++) {
        assertEquals("Thew bytes should be the same", in[i], out[i]);
    }
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:17,代碼來源:MinaUdpUsingTemplateTest.java

示例10: testSelectOneWithoutClass

import org.apache.camel.component.mock.MockEndpoint; //導入方法依賴的package包/類
@Test
public void testSelectOneWithoutClass() throws Exception {
    camel1.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("sql:select * from projects where id=3?outputType=SelectOne")
                    .to("mock:result");
        }
    });
    camel1.start();

    MockEndpoint mock = (MockEndpoint) camel1.getEndpoint("mock:result");
    mock.expectedMessageCount(1);
    mock.assertIsSatisfied(2000);

    List<Exchange> exchanges = mock.getReceivedExchanges();
    Assert.assertThat(exchanges.size(), CoreMatchers.is(1));

    Map<String, Object> result = exchanges.get(0).getIn().getBody(Map.class);
    Assert.assertThat((Integer) result.get("ID"), CoreMatchers.is(3));
    Assert.assertThat((String) result.get("PROJECT"), CoreMatchers.is("Linux"));
    Assert.assertThat((String) result.get("LICENSE"), CoreMatchers.is("XXX"));
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:24,代碼來源:SqlConsumerOutputTypeSelectOneTest.java

示例11: testConvertPayloadToInputStream

import org.apache.camel.component.mock.MockEndpoint; //導入方法依賴的package包/類
@Test
public void testConvertPayloadToInputStream() throws Exception {
    MockEndpoint mockEndpoint = getMockEndpoint("mock:result");
    mockEndpoint.expectedMessageCount(1);

    template.requestBodyAndHeader("netty4-http:http://localhost:{{port}}/test", expectedBody, "Content-Type", "application/xml");

    mockEndpoint.assertIsSatisfied();
    List<Exchange> list = mockEndpoint.getReceivedExchanges();
    Exchange exchange = list.get(0);
    assertNotNull("exchange", exchange);

    Message in = exchange.getIn();
    assertNotNull("in", in);

    Object actual = in.getBody();
    InputStream value = assertIsInstanceOf(InputStream.class, actual);
    assertNotNull("InputStream", value);
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:20,代碼來源:NettyHttpConvertPayloadToInputStreamTest.java

示例12: testEndpoint

import org.apache.camel.component.mock.MockEndpoint; //導入方法依賴的package包/類
@Test
public void testEndpoint() throws Exception {
    // these tests does not run well on Windows
    if (isPlatform("windows")) {
        return;
    }

    MockEndpoint mockEndpointA = resolveMandatoryEndpoint("mock:a", MockEndpoint.class);
    mockEndpointA.expectedBodiesReceived(expectedBody);
    MockEndpoint mockEndpointB = resolveMandatoryEndpoint("mock:b", MockEndpoint.class);
    mockEndpointB.expectedBodiesReceived(expectedBody);

    invokeHttpEndpoint();

    mockEndpointA.assertIsSatisfied();
    mockEndpointB.assertIsSatisfied();
    List<Exchange> list = mockEndpointA.getReceivedExchanges();
    Exchange exchange = list.get(0);
    assertNotNull("exchange", exchange);

    Message in = exchange.getIn();
    assertNotNull("in", in);

    Map<String, Object> headers = in.getHeaders();

    log.info("Headers: " + headers);

    assertTrue("Should be more than one header but was: " + headers, headers.size() > 0);
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:30,代碼來源:HttpsRouteTest.java

示例13: testSendMatchingMessage

import org.apache.camel.component.mock.MockEndpoint; //導入方法依賴的package包/類
public void testSendMatchingMessage() throws Exception {
    MockEndpoint resultEndpoint = getMockEndpoint("mock:result");
    resultEndpoint.expectedMessageCount(1);

    sendBody("direct:start", matchingBody);

    assertMockEndpointsSatisfied();
    List<Exchange> list = resultEndpoint.getReceivedExchanges();
    Exchange exchange = list.get(0);
    Object value = exchange.getIn().getHeader("foo");
    assertEquals("foo header", "London", value);
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:13,代碼來源:SetHeaderTest.java

示例14: testHttpGetConnectionClose

import org.apache.camel.component.mock.MockEndpoint; //導入方法依賴的package包/類
@Test
@Ignore("ignore online tests")
public void testHttpGetConnectionClose() throws Exception {
    MockEndpoint mockEndpoint = resolveMandatoryEndpoint("mock:results", MockEndpoint.class);
    mockEndpoint.expectedMessageCount(1);

    template.sendBody("direct:start", null);

    mockEndpoint.assertIsSatisfied();
    List<Exchange> list = mockEndpoint.getReceivedExchanges();
    Exchange exchange = list.get(0);
    assertNotNull("exchange", exchange);

    Message in = exchange.getIn();
    assertNotNull("in", in);

    Map<String, Object> headers = in.getHeaders();

    log.debug("Headers: " + headers);
    checkHeaders(headers);       

    String body = in.getBody(String.class);

    log.debug("Body: " + body);
    assertNotNull("Should have a body!", body);
    assertTrue("body should contain: " + expectedText, body.contains(expectedText));
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:28,代碼來源:HttpExplicitConnectionCloseTest.java

示例15: testProducer

import org.apache.camel.component.mock.MockEndpoint; //導入方法依賴的package包/類
@Test
public void testProducer() throws Exception {
    Person person = new Person("David", "Greco");
    template.requestBody("direct:input", person);
    MockEndpoint ep = context.getEndpoint("mock:test", MockEndpoint.class);
    List<Exchange> exchanges = ep.getReceivedExchanges();
    for (Exchange exchange : exchanges) {
        Person person1 = (Person) exchange.getIn().getBody();
        assertEquals("David", person1.getName());
        assertEquals("Greco", person1.getSurname());
    }
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:13,代碼來源:SslContextParametersCometdProducerConsumerTest.java


注:本文中的org.apache.camel.component.mock.MockEndpoint.getReceivedExchanges方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。