use of jakarta.mail.util.ByteArrayDataSource in project simple-java-mail by bbottema.
the class MimeMessageParserTest method testMoveInvalidEmbeddedResourcesToAttachments_NoHtmlNoInvalid.
@Test
public void testMoveInvalidEmbeddedResourcesToAttachments_NoHtmlNoInvalid() throws IOException {
ParsedMimeMessageComponents parsedComponents = new ParsedMimeMessageComponents();
parsedComponents.cidMap.put("moo1", new ByteArrayDataSource("moomoo", "text/plain"));
parsedComponents.cidMap.put("moo2", new ByteArrayDataSource("moomoo", "text/plain"));
moveInvalidEmbeddedResourcesToAttachments(parsedComponents);
assertThat(parsedComponents.cidMap).isEmpty();
assertThat(parsedComponents.attachmentList).extracting("key").containsOnly("moo1", "moo2");
}
use of jakarta.mail.util.ByteArrayDataSource in project simple-java-mail by bbottema.
the class EmailPopulatingBuilderImpl1Test method testWithEmbeddedImages.
@Test
public void testWithEmbeddedImages() throws IOException {
List<AttachmentResource> embeddedImages = new ArrayList<>();
embeddedImages.add(new AttachmentResource("attachment1", getDataSource("blahblah.txt")));
embeddedImages.add(new AttachmentResource(null, getDataSource("blahblah.txt")));
embeddedImages.add(new AttachmentResource("attachment1", new ByteArrayDataSource("", "text/text")));
Email email = builder.withEmbeddedImages(embeddedImages).buildEmail();
EmailAssert.assertThat(email).hasOnlyEmbeddedImages(embeddedImages);
}
use of jakarta.mail.util.ByteArrayDataSource in project simple-java-mail by bbottema.
the class EmailPopulatingBuilderImpl1Test method testBuilderEmbeddingImages_UnhappyScenario.
@Test
public void testBuilderEmbeddingImages_UnhappyScenario() {
builder.withEmbeddedImage("a", new ByteArrayDataSource(new byte[3], "")).withEmbeddedImage(null, new DataSourceWithDummyName()).withEmbeddedImage("a", new byte[3], "mimetype");
try {
builder.withEmbeddedImage(null, new ByteArrayDataSource(new byte[3], ""));
failBecauseExceptionWasNotThrown(EmailException.class);
} catch (EmailException e) {
// ok
}
try {
// noinspection ConstantConditions
builder.withEmbeddedImage(null, new byte[3], "mimetype");
failBecauseExceptionWasNotThrown(IllegalArgumentException.class);
} catch (IllegalArgumentException e) {
// ok
}
}
use of jakarta.mail.util.ByteArrayDataSource in project simple-java-mail by bbottema.
the class EmailPopulatingBuilderUsingDefaultsFromPropertyFileTest method testBuilderSimpleBuildWithStandardEmail_PlusOptionals.
@Test
public void testBuilderSimpleBuildWithStandardEmail_PlusOptionals() throws IOException {
ByteArrayDataSource namedAttachment = new ByteArrayDataSource("Black Tie Optional", "text/plain");
namedAttachment.setName("dresscode-ignored-because-of-override.txt");
String base64String = "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAABeElEQVRYw2NgoAAYGxu3GxkZ7TY1NZVloDcAWq4MxH+B+D8Qv3FwcOCgtwM6oJaDMTAUXOhmuYqKCjvQ0pdoDrCnmwNMTEwakC0H4u8GBgYC9Ap6DSD+iewAoIPm0ctyLqBlp9F8/x+YE4zpYT8T0LL16JYD8U26+B7oyz4sloPwenpYno3DchCeROsUbwa05A8eB3wB4kqgIxOAuArIng7EW4H4EhC/B+JXQLwDaI4ryZaDSjeg5mt4LCcFXyIn1fdSyXJQVt1OtMWGhoai0OD8T0W8GohZifE1PxD/o7LlsPLiFNAKRrwOABWptLAcqc6QGDAHQEOAYaAc8BNotsJAOgAUAosG1AFA/AtUoY3YEFhKMAvS2AE7iC1+WaG1H6gY3gzE36hUFJ8mqzbU1dUVBBqQBzTgIDQRkWo5qCZdpaenJ0Zx1aytrc0DDB0foIG1oAYKqC0IZK8D4n1AfA6IzwPxXpCFoGoZVEUDaRGGUTAKRgEeAAA2eGJC+ETCiAAAAABJRU5ErkJggg==";
final Email email = EmailBuilder.startingBlank().from("lollypop", "lol.pop@somemail.com").withReplyTo("lollypop-reply", "lol.pop.reply@somemail.com").withBounceTo("lollypop-bounce", "lol.pop.bounce@somemail.com").to("C.Cane", "candycane@candyshop.org").withPlainText("We should meet up!").withHTMLText("<b>We should meet up!</b><img src='cid:thumbsup'>").withSubject("hey").withAttachment("dresscode.txt", namedAttachment).withAttachment("location.txt", "On the moon!".getBytes(Charset.defaultCharset()), "text/plain").withEmbeddedImage("thumbsup", parseBase64Binary(base64String), "image/png").withDispositionNotificationTo("simple@address.com").withReturnReceiptTo("Complex Email", "simple@address.com").withHeader("dummyHeader", "dummyHeaderValue").withHeader("dummyHeader", "dummyHeaderValueSecond").withHeader("anotherDummyHeader", "anotherDummyHeaderValue").buildEmail();
assertThat(EmailHelper.createDummyEmailBuilder(true, false, true, false, false, false).buildEmail()).isEqualTo(email);
}
use of jakarta.mail.util.ByteArrayDataSource in project tomee by apache.
the class AttachmentTest method testAttachmentViaWsInterface.
// END SNIPPET: setup
/**
* Create a webservice client using wsdl url
*
* @throws Exception
*/
// START SNIPPET: webservice
public void testAttachmentViaWsInterface() throws Exception {
Service service = Service.create(new URL("http://localhost:" + port + "/webservice-attachments/AttachmentImpl?wsdl"), new QName("http://superbiz.org/wsdl", "AttachmentWsService"));
assertNotNull(service);
AttachmentWs ws = service.getPort(AttachmentWs.class);
// retrieve the SOAPBinding
SOAPBinding binding = (SOAPBinding) ((BindingProvider) ws).getBinding();
binding.setMTOMEnabled(true);
String request = "tsztelak@gmail.com";
// Byte array
String response = ws.stringFromBytes(request.getBytes());
assertEquals(request, response);
// Data Source
DataSource source = new ByteArrayDataSource(request.getBytes(), "text/plain; charset=UTF-8");
// not yet supported !
// response = ws.stringFromDataSource(source);
// assertEquals(request, response);
// Data Handler
response = ws.stringFromDataHandler(new DataHandler(source));
assertEquals(request, response);
}
Aggregations