本文整理匯總了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());
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}
示例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));
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}