use of org.simplejavamail.internal.util.NamedDataSource in project simple-java-mail by bbottema.
the class MimeMessageParserTest method getBodyPartFromDatasource.
private static BodyPart getBodyPartFromDatasource(final AttachmentResource attachmentResource, final String dispositionType) throws MessagingException {
final BodyPart attachmentPart = new MimeBodyPart();
// setting headers isn't working nicely using the javax mail API, so let's do that manually
final String resourceName = "htgfiytityf.txt";
final String fileName = "proper-name.txt";
attachmentPart.setDataHandler(new DataHandler(new NamedDataSource(fileName, attachmentResource.getDataSource())));
attachmentPart.setFileName(fileName);
final String contentType = attachmentResource.getDataSource().getContentType();
ParameterList pl = new ParameterList();
pl.set("filename", fileName);
pl.set("name", fileName);
attachmentPart.setHeader("Content-Type", contentType + pl);
attachmentPart.setHeader("Content-ID", format("<%s>", resourceName));
attachmentPart.setDisposition(dispositionType);
return attachmentPart;
}
use of org.simplejavamail.internal.util.NamedDataSource in project simple-java-mail by bbottema.
the class NamedDataSourceTest method outputStreamWillBeTheSame1.
@Test
public void outputStreamWillBeTheSame1() throws Exception {
DataSource testDataSource = new NamedDataSource("newName", dataSource);
testDataSource.getOutputStream();
verify(dataSource).getOutputStream();
}
use of org.simplejavamail.internal.util.NamedDataSource in project simple-java-mail by bbottema.
the class NamedDataSourceTest method renameWillWork.
@Test
public void renameWillWork() {
DataSource testDataSource = new NamedDataSource("newName", dataSource);
assertThat(testDataSource.getName()).isEqualTo("newName");
verifyZeroInteractions(dataSource);
}
use of org.simplejavamail.internal.util.NamedDataSource in project simple-java-mail by bbottema.
the class NamedDataSourceTest method contentTypeStreamWillBeTheSame1.
@Test
public void contentTypeStreamWillBeTheSame1() {
DataSource testDataSource = new NamedDataSource("newName", dataSource);
testDataSource.getContentType();
verify(dataSource).getContentType();
}
use of org.simplejavamail.internal.util.NamedDataSource in project simple-java-mail by bbottema.
the class EmailTest method testEqualsEmail_EqualityEmbeddedImages.
@Test
public void testEqualsEmail_EqualityEmbeddedImages() throws IOException {
assertEmailEqual(b().withEmbeddedImage("name", new byte[] { 'a' }, "image/png").buildEmail(), b().withEmbeddedImage("name", new byte[] { 'a' }, "image/png").buildEmail(), true);
assertEmailEqual(b().withEmbeddedImage(null, new NamedDataSource("n1", new ByteArrayDataSource("data", "image/png"))).buildEmail(), b().withEmbeddedImage(null, new NamedDataSource("n1", new ByteArrayDataSource("data", "image/png"))).buildEmail(), true);
assertEmailEqual(b().withEmbeddedImage("name", new ByteArrayDataSource("data", "image/png")).buildEmail(), b().withEmbeddedImage("name", new ByteArrayDataSource("data", "image/png")).buildEmail(), true);
assertEmailEqual(b().withEmbeddedImage("name", new byte[] { 'a' }, "image/png").withEmbeddedImage("name2", new byte[] { 'b' }, "image/bmp").buildEmail(), b().withEmbeddedImage("name", new byte[] { 'a' }, "image/png").withEmbeddedImage("name2", new byte[] { 'b' }, "image/bmp").buildEmail(), true);
assertEmailEqual(b().withEmbeddedImage(null, new NamedDataSource("n1", new ByteArrayDataSource("data", "image/png"))).buildEmail(), b().withEmbeddedImage(null, new NamedDataSource("n2", new ByteArrayDataSource("data", "image/png"))).buildEmail(), false);
assertEmailEqual(b().withEmbeddedImage(null, new NamedDataSource("n1", new ByteArrayDataSource("data", "image/png"))).buildEmail(), b().withEmbeddedImage(null, new NamedDataSource("n1", new ByteArrayDataSource("data", "image/jpg"))).buildEmail(), false);
assertEmailEqual(b().withEmbeddedImage("name", new ByteArrayDataSource("data", "image/png")).buildEmail(), b().withEmbeddedImage("nameOther", new ByteArrayDataSource("data", "image/png")).buildEmail(), false);
assertEmailEqual(b().withEmbeddedImage("name", new ByteArrayDataSource("data", "image/png")).buildEmail(), b().withEmbeddedImage("name", new ByteArrayDataSource("data", "image/jpg")).buildEmail(), false);
assertEmailEqual(b().withEmbeddedImage("name", new byte[] { 'a' }, "image/png").withEmbeddedImage("name2", new byte[] { 'b' }, "image/bmp").buildEmail(), b().withEmbeddedImage("name", new byte[] { 'a' }, "image/png").buildEmail(), false);
assertEmailEqual(b().withEmbeddedImage("name", new byte[] { 'a' }, "image/png").withEmbeddedImage("name2", new byte[] { 'b' }, "image/bmp").buildEmail(), b().withEmbeddedImage("name", new byte[] { 'a' }, "image/png").withEmbeddedImage("name3", new byte[] { 'b' }, "image/bmp").buildEmail(), false);
assertEmailEqual(b().withEmbeddedImage("name", new byte[] { 'a' }, "image/png").buildEmail(), b().buildEmail(), false);
}
Aggregations