use of org.apache.camel.Exchange in project camel by apache.
the class MimeMultipartDataFormatTest method roundtripWithoutAttachments.
@Test
public void roundtripWithoutAttachments() throws IOException {
in.setBody("Body text");
Exchange result = template.send("direct:roundtrip", exchange);
Message out = result.getOut();
assertEquals("Body text", out.getBody(String.class));
assertFalse(out.hasAttachments());
}
use of org.apache.camel.Exchange in project camel by apache.
the class MimeMultipartDataFormatTest method roundtripWithTextAttachmentsAndSpecialCharacters.
@Test
@Ignore("Fails on CI servers and some platforms - maybe due locale or something")
public void roundtripWithTextAttachmentsAndSpecialCharacters() throws IOException {
String attContentType = "text/plain";
String attText = "Attachment Text with special characters: ©";
String attFileName = "Attachment File Name with special characters: ©";
in.setBody("Body text with special characters: ©");
in.setHeader(Exchange.CONTENT_TYPE, "text/plain");
in.setHeader(Exchange.CONTENT_ENCODING, "UTF8");
addAttachment(attContentType, attText, attFileName);
Exchange result = template.send("direct:roundtrip", exchange);
Message out = result.getOut();
assertEquals("Body text with special characters: ©", out.getBody(String.class));
assertThat(out.getHeader(Exchange.CONTENT_TYPE, String.class), startsWith("text/plain"));
assertEquals("UTF8", out.getHeader(Exchange.CONTENT_ENCODING));
assertTrue(out.hasAttachments());
assertEquals(1, out.getAttachmentNames().size());
assertThat(out.getAttachmentNames(), hasItem(attFileName));
DataHandler dh = out.getAttachment(attFileName);
assertNotNull(dh);
assertEquals(attContentType, dh.getContentType());
InputStream is = dh.getInputStream();
ByteArrayOutputStream os = new ByteArrayOutputStream();
IOHelper.copyAndCloseInput(is, os);
assertEquals(attText, new String(os.toByteArray()));
}
use of org.apache.camel.Exchange in project camel by apache.
the class MimeMultipartDataFormatTest method roundtripWithTextAttachmentsAndBinaryContent.
@Test
public void roundtripWithTextAttachmentsAndBinaryContent() throws IOException {
String attContentType = "text/plain";
String attText = "Attachment Text";
String attFileName = "Attachment File Name";
in.setBody("Body text");
in.setHeader(Exchange.CONTENT_TYPE, "text/plain;charset=iso8859-1;other-parameter=true");
addAttachment(attContentType, attText, attFileName);
Exchange result = template.send("direct:roundtripbinarycontent", exchange);
Message out = result.getOut();
assertEquals("Body text", out.getBody(String.class));
assertThat(out.getHeader(Exchange.CONTENT_TYPE, String.class), startsWith("text/plain"));
assertEquals("iso8859-1", out.getHeader(Exchange.CONTENT_ENCODING));
assertTrue(out.hasAttachments());
assertEquals(1, out.getAttachmentNames().size());
assertThat(out.getAttachmentNames(), hasItem(attFileName));
DataHandler dh = out.getAttachment(attFileName);
assertNotNull(dh);
assertEquals(attContentType, dh.getContentType());
InputStream is = dh.getInputStream();
ByteArrayOutputStream os = new ByteArrayOutputStream();
IOHelper.copyAndCloseInput(is, os);
assertEquals(attText, new String(os.toByteArray()));
}
use of org.apache.camel.Exchange in project camel by apache.
the class MimeMultipartDataFormatTest method unmarshalInlineHeadersNonMimeBody.
@Test
public void unmarshalInlineHeadersNonMimeBody() {
in.setBody("This is not a MIME-Multipart");
Exchange out = template.send("direct:unmarshalonlyinlineheaders", exchange);
assertNotNull(out.getOut());
String bodyStr = out.getOut().getBody(String.class);
assertEquals("This is not a MIME-Multipart", bodyStr);
}
use of org.apache.camel.Exchange in project camel by apache.
the class MimeMultipartDataFormatTest method roundtripWithTextAttachmentsHeadersInline.
@Test
public void roundtripWithTextAttachmentsHeadersInline() throws IOException {
String attContentType = "text/plain";
String attText = "Attachment Text";
String attFileName = "Attachment File Name";
in.setBody("Body text");
in.setHeader(Exchange.CONTENT_TYPE, "text/plain;charset=iso8859-1;other-parameter=true");
in.setHeader(Exchange.CONTENT_ENCODING, "UTF8");
addAttachment(attContentType, attText, attFileName);
Exchange result = template.send("direct:roundtripinlineheaders", exchange);
Message out = result.getOut();
assertEquals("Body text", out.getBody(String.class));
assertThat(out.getHeader(Exchange.CONTENT_TYPE, String.class), startsWith("text/plain"));
assertEquals("UTF8", out.getHeader(Exchange.CONTENT_ENCODING));
assertTrue(out.hasAttachments());
assertEquals(1, out.getAttachmentNames().size());
assertThat(out.getAttachmentNames(), hasItem(attFileName));
DataHandler dh = out.getAttachment(attFileName);
assertNotNull(dh);
assertEquals(attContentType, dh.getContentType());
InputStream is = dh.getInputStream();
ByteArrayOutputStream os = new ByteArrayOutputStream();
IOHelper.copyAndCloseInput(is, os);
assertEquals(attText, new String(os.toByteArray()));
}
Aggregations