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


Java MockEndpoint.assertExchangeReceived方法代碼示例

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


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

示例1: testSoapMarshal

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

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

    assertMockEndpointsSatisfied();
    Exchange result = endpoint.assertExchangeReceived(0);

    byte[] body = (byte[])result.getIn().getBody();
    InputStream stream = new ByteArrayInputStream(body);
    SOAPMessage request = MessageFactory.newInstance().createMessage(null, stream);
    assertTrue("Expected headers", null != request.getSOAPHeader()
                                   && request.getSOAPHeader().extractAllHeaderElements().hasNext());
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:17,代碼來源:SoapToSoapDontIgnoreTest.java

示例2: testSoapMarshal

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

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

    assertMockEndpointsSatisfied();
    Exchange result = endpoint.assertExchangeReceived(0);

    byte[] body = (byte[])result.getIn().getBody();
    InputStream stream = new ByteArrayInputStream(body);
    SOAPMessage request = MessageFactory.newInstance().createMessage(null, stream);
    assertTrue("Expected no headers", null == request.getSOAPHeader()
                                      || !request.getSOAPHeader().extractAllHeaderElements().hasNext());
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:17,代碼來源:SoapToSoapIgnoreTest.java

示例3: verifyTheRecivedEmail

import org.apache.camel.component.mock.MockEndpoint; //導入方法依賴的package包/類
private void verifyTheRecivedEmail(String expectString) throws Exception {
    // need some time for the mail to arrive on the inbox (consumed and sent to the mock)
    Thread.sleep(1000);

    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.assertIsSatisfied();

    Exchange out = mock.assertExchangeReceived(0);
    ByteArrayOutputStream baos = new ByteArrayOutputStream(((MailMessage)out.getIn()).getMessage().getSize());
    ((MailMessage)out.getIn()).getMessage().writeTo(baos);
    String dumpedMessage = baos.toString();
    assertTrue("There should have the " + expectString, dumpedMessage.indexOf(expectString) > 0);
    log.trace("multipart alternative: \n{}", dumpedMessage);
     
    // plain text
    assertEquals(alternativeBody, out.getIn().getBody(String.class));

    // attachment
    Map<String, DataHandler> attachments = out.getIn().getAttachments();
    assertNotNull("Should not have null attachments", attachments);
    assertEquals(1, attachments.size());
    assertEquals("multipart body should have 2 parts", 2, out.getIn().getBody(MimeMultipart.class).getCount());
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:24,代碼來源:MimeMultipartAlternativeTest.java

示例4: verifyTheRecivedEmail

import org.apache.camel.component.mock.MockEndpoint; //導入方法依賴的package包/類
private void verifyTheRecivedEmail(String expectString) throws Exception {
    // need some time for the mail to arrive on the inbox (consumed and sent to the mock)
    Thread.sleep(1000);

    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.assertIsSatisfied();

    Exchange out = mock.assertExchangeReceived(0);
    ByteArrayOutputStream baos = new ByteArrayOutputStream(((MailMessage)out.getIn()).getMessage().getSize());
    ((MailMessage)out.getIn()).getMessage().writeTo(baos);
    String dumpedMessage = baos.toString();
    assertTrue("There should have the " + expectString, dumpedMessage.indexOf(expectString) > 0);
    log.trace("multipart alternative: \n{}", dumpedMessage);

    // plain text
    assertEquals(alternativeBody, out.getIn().getBody(String.class));

    // attachment
    Map<String, DataHandler> attachments = out.getIn().getAttachments();
    assertNotNull("Should not have null attachments", attachments);
    assertEquals(1, attachments.size());
    assertEquals("multipart body should have 2 parts", 2, out.getIn().getBody(MimeMultipart.class).getCount());
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:24,代碼來源:MimeMultipartAlternativeWithLongerFilenameTest.java

示例5: verifyTheRecivedEmail

import org.apache.camel.component.mock.MockEndpoint; //導入方法依賴的package包/類
private void verifyTheRecivedEmail(String expectString) throws Exception {

        MockEndpoint mock = getMockEndpoint("mock:result");
        mock.assertIsSatisfied();

        Exchange out = mock.assertExchangeReceived(0);
        ByteArrayOutputStream baos = new ByteArrayOutputStream(((MailMessage)out.getIn()).getMessage().getSize());
        ((MailMessage)out.getIn()).getMessage().writeTo(baos);
        String dumpedMessage = baos.toString();
        assertTrue("There should have the " + expectString, dumpedMessage.indexOf(expectString) > 0);
        log.trace("multipart alternative: \n{}", dumpedMessage);

        // plain text
        assertEquals(alternativeBody, out.getIn().getBody(String.class));

        assertEquals("multipart body should have 2 parts", 2, out.getIn().getBody(MimeMultipart.class).getCount());
    }
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:18,代碼來源:MimeMultipartAlternativeWithContentTypeTest.java

示例6: testSendAndReceiveMailWithAttachmentsRedelivery

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

    // create an exchange with a normal body and attachment to be produced as email
    Endpoint endpoint = context.getEndpoint("smtp://[email protected]?password=secret");

    // create the exchange with the mail message that is multipart with a file and a Hello World text/plain message.
    Exchange exchange = endpoint.createExchange();
    Message in = exchange.getIn();
    in.setBody("Hello World");
    in.addAttachment("logo.jpeg", new DataHandler(new FileDataSource("src/test/data/logo.jpeg")));

    // create a producer that can produce the exchange (= send the mail)
    Producer producer = endpoint.createProducer();
    // start the producer
    producer.start();
    // and let it go (processes the exchange by sending the email)
    producer.process(exchange);

    // need some time for the mail to arrive on the inbox (consumed and sent to the mock)
    Thread.sleep(2000);

    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    Exchange out = mock.assertExchangeReceived(0);
    mock.assertIsSatisfied();

    // plain text
    assertEquals("Hello World", out.getIn().getBody(String.class));

    // attachment
    Map<String, DataHandler> attachments = out.getIn().getAttachments();
    assertNotNull("Should have attachments", attachments);
    assertEquals(1, attachments.size());

    DataHandler handler = out.getIn().getAttachment("logo.jpeg");
    assertNotNull("The logo should be there", handler);

    // content type should match
    boolean match1 = "image/jpeg; name=logo.jpeg".equals(handler.getContentType());
    boolean match2 = "application/octet-stream; name=logo.jpeg".equals(handler.getContentType());
    assertTrue("Should match 1 or 2", match1 || match2);

    assertEquals("Handler name should be the file name", "logo.jpeg", handler.getName());

    producer.stop();

    assertEquals(3, names.size());
    assertEquals("logo.jpeg", names.get(0));
    assertEquals("logo.jpeg", names.get(1));
    assertEquals("logo.jpeg", names.get(2));
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:55,代碼來源:MailAttachmentRedeliveryTest.java

示例7: testSendAndReceiveMailWithAttachments

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

    // START SNIPPET: e1

    // create an exchange with a normal body and attachment to be produced as email
    Endpoint endpoint = context.getEndpoint("smtp://[email protected]?password=secret");

    // create the exchange with the mail message that is multipart with a file and a Hello World text/plain message.
    Exchange exchange = endpoint.createExchange();
    Message in = exchange.getIn();
    in.setBody("Hello World");
    in.addAttachment("logo.jpeg", new DataHandler(new FileDataSource("src/test/data/logo.jpeg")));

    // create a producer that can produce the exchange (= send the mail)
    Producer producer = endpoint.createProducer();
    // start the producer
    producer.start();
    // and let it go (processes the exchange by sending the email)
    producer.process(exchange);

    // END SNIPPET: e1

    // need some time for the mail to arrive on the inbox (consumed and sent to the mock)
    Thread.sleep(2000);

    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    Exchange out = mock.assertExchangeReceived(0);
    mock.assertIsSatisfied();

    // plain text
    assertEquals("Hello World", out.getIn().getBody(String.class));

    // attachment
    Map<String, DataHandler> attachments = out.getIn().getAttachments();
    assertNotNull("Should have attachments", attachments);
    assertEquals(1, attachments.size());

    DataHandler handler = out.getIn().getAttachment("logo.jpeg");
    assertNotNull("The logo should be there", handler);

    // content type should match
    boolean match1 = "image/jpeg; name=logo.jpeg".equals(handler.getContentType());
    boolean match2 = "application/octet-stream; name=logo.jpeg".equals(handler.getContentType());
    assertTrue("Should match 1 or 2", match1 || match2);

    assertEquals("Handler name should be the file name", "logo.jpeg", handler.getName());

    producer.stop();
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:54,代碼來源:MailAttachmentTest.java

示例8: testCustomContentTypeResolver

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

    // create an exchange with a normal body and attachment to be produced as email
    Endpoint endpoint = context.getEndpoint("smtp://[email protected]?password=secret");

    // create the exchange with the mail message that is multipart with a file and a Hello World text/plain message.
    Exchange exchange = endpoint.createExchange();
    Message in = exchange.getIn();
    in.setBody("Hello World");
    in.addAttachment("logo.jpeg", new DataHandler(new FileDataSource("src/test/data/logo.jpeg")));

    // create a producer that can produce the exchange (= send the mail)
    Producer producer = endpoint.createProducer();
    // start the producer
    producer.start();
    // and let it go (processes the exchange by sending the email)
    producer.process(exchange);

    // need some time for the mail to arrive on the inbox (consumed and sent to the mock)
    Thread.sleep(4000);

    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    Exchange out = mock.assertExchangeReceived(0);
    mock.assertIsSatisfied();

    // plain text
    assertEquals("Hello World", out.getIn().getBody(String.class));

    // attachment
    Map<String, DataHandler> attachments = out.getIn().getAttachments();
    assertNotNull("Should have attachments", attachments);
    assertEquals(1, attachments.size());

    DataHandler handler = out.getIn().getAttachment("logo.jpeg");
    assertNotNull("The logo should be there", handler);

    // as we use a custom content type resolver the content type should then be fixed and correct
    // content type should match
    boolean match1 = "image/jpeg; name=logo.jpeg".equals(handler.getContentType());
    boolean match2 = "application/octet-stream; name=logo.jpeg".equals(handler.getContentType());
    assertTrue("Should match 1 or 2", match1 || match2);

    producer.stop();
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:49,代碼來源:MailContentTypeResolverTest.java

示例9: testSendAndRecieveMailWithAttachmentsWithDuplicateNames

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

    // START SNIPPET: e1

    // create an exchange with a normal body and attachment to be produced as email
    Endpoint endpoint = context.getEndpoint("smtp://[email protected]?password=secret");

    // create the exchange with the mail message that is multipart with a file and a Hello World text/plain message.
    Exchange exchange = endpoint.createExchange();
    Message in = exchange.getIn();
    in.setBody("Hello World");
    in.addAttachment("logo.jpeg", new DataHandler(new FileDataSource("src/test/data/logo.jpeg")));
    in.addAttachment("logo.jpeg", new DataHandler(new FileDataSource("src/test/data/logo.jpeg")));

    // create a producer that can produce the exchange (= send the mail)
    Producer producer = endpoint.createProducer();
    // start the producer
    producer.start();
    // and let it go (processes the exchange by sending the email)
    producer.process(exchange);

    // END SNIPPET: e1

    // need some time for the mail to arrive on the inbox (consumed and sent to the mock)
    Thread.sleep(2000);

    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    Exchange out = mock.assertExchangeReceived(0);
    mock.assertIsSatisfied();

    // plain text
    assertEquals("Hello World", out.getIn().getBody(String.class));

    // attachment
    Map<String, DataHandler> attachments = out.getIn().getAttachments();
    assertNotNull("Should have attachments", attachments);
    assertEquals(1, attachments.size());

    DataHandler handler = out.getIn().getAttachment("logo.jpeg");
    assertNotNull("The logo should be there", handler);

    // content type should match
    boolean match1 = "image/jpeg; name=logo.jpeg".equals(handler.getContentType());
    boolean match2 = "application/octet-stream; name=logo.jpeg".equals(handler.getContentType());
    assertTrue("Should match 1 or 2", match1 || match2);

    producer.stop();
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:53,代碼來源:MailAttachmentDuplicateNamesTest.java

示例10: testSendAndRecieveMailWithAttachments

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

    // START SNIPPET: e1

    // create an exchange with a normal body and attachment to be produced as email
    Endpoint endpoint = context.getEndpoint("smtp://[email protected]?password=secret&contentType=text/html");

    // create the exchange with the mail message that is multipart with a file and a Hello World text/plain message.
    Exchange exchange = endpoint.createExchange();
    Message in = exchange.getIn();
    in.setBody("<html><body><h1>Hello</h1>World</body></html>");
    in.addAttachment("logo.jpeg", new DataHandler(new FileDataSource("src/test/data/logo.jpeg")));

    // create a producer that can produce the exchange (= send the mail)
    Producer producer = endpoint.createProducer();
    // start the producer
    producer.start();
    // and let it go (processes the exchange by sending the email)
    producer.process(exchange);

    // END SNIPPET: e1

    // need some time for the mail to arrive on the inbox (consumed and sent to the mock)
    Thread.sleep(2000);

    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    Exchange out = mock.assertExchangeReceived(0);
    mock.assertIsSatisfied();

    // plain text
    assertEquals("<html><body><h1>Hello</h1>World</body></html>", out.getIn().getBody(String.class));

    // attachment
    Map<String, DataHandler> attachments = out.getIn().getAttachments();
    assertNotNull("Should have attachments", attachments);
    assertEquals(1, attachments.size());

    DataHandler handler = out.getIn().getAttachment("logo.jpeg");
    assertNotNull("The logo should be there", handler);
    byte[] bytes = context.getTypeConverter().convertTo(byte[].class, handler.getInputStream());
    assertNotNull("content should be there", bytes);
    assertTrue("logo should be more than 1000 bytes", bytes.length > 1000);

    // content type should match
    boolean match1 = "image/jpeg; name=logo.jpeg".equals(handler.getContentType());
    boolean match2 = "application/octet-stream; name=logo.jpeg".equals(handler.getContentType());
    assertTrue("Should match 1 or 2", match1 || match2);

    // save logo for visual inspection
    template.sendBodyAndHeader("file://target", bytes, Exchange.FILE_NAME, "maillogo.jpg");

    producer.stop();
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:58,代碼來源:MailHtmlAttachmentTest.java

示例11: testSendAndReceiveMailWithAttachments

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

    // create an exchange with a normal body and attachment to be produced as email
    Endpoint endpoint = context.getEndpoint("smtp://[email protected]?password=secret");

    // create the exchange with the mail message that is multipart with a file and a Hello World text/plain message.
    Exchange exchange = endpoint.createExchange();
    Message in = exchange.getIn();
    in.setBody("Hello World");
    // unicode 00DC is german umlaut
    String name = "logo2\u00DC";
    // use existing logo.jpeg file, but lets name it with the umlaut
    in.addAttachment(name, new DataHandler(new FileDataSource("src/test/data/logo.jpeg")));

    // create a producer that can produce the exchange (= send the mail)
    Producer producer = endpoint.createProducer();
    // start the producer
    producer.start();
    // and let it go (processes the exchange by sending the email)
    producer.process(exchange);

    // need some time for the mail to arrive on the inbox (consumed and sent to the mock)
    Thread.sleep(2000);

    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    Exchange out = mock.assertExchangeReceived(0);
    mock.assertIsSatisfied();

    // plain text
    assertEquals("Hello World", out.getIn().getBody(String.class));

    // attachment
    Map<String, DataHandler> attachments = out.getIn().getAttachments();
    assertNotNull("Should have attachments", attachments);
    assertEquals(1, attachments.size());

    DataHandler handler = out.getIn().getAttachment(name);
    assertNotNull("The " + name + " should be there", handler);

    String nameURLEncoded = URLEncoder.encode(name, Charset.defaultCharset().name());
    assertTrue("Handler content type should end with URL-encoded name", handler.getContentType().endsWith(nameURLEncoded));

    assertEquals("Handler name should be the file name", name, handler.getName());

    producer.stop();
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:51,代碼來源:MailAttachmentsUmlautIssueTest.java


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