use of javax.mail.internet.MimeMultipart in project nhin-d by DirectProject.
the class NotificationTest method testWarning_AssertWarning.
public void testWarning_AssertWarning() throws Exception {
Notification noti = new Notification(NotificationType.Processed);
MimeMultipart mm = noti.getAsMultipart();
assertNotNull(mm);
assertEquals(2, mm.getCount());
BodyPart part = mm.getBodyPart(1);
assertTrue(part.getContentType().startsWith("message/disposition-notification"));
InternetHeaders headers = noti.getNotificationFieldsAsHeaders();
assertNull(headers.getHeader(MDNStandard.Headers.FinalRecipient));
// set a new gateway
noti.setWarning("junit warning");
mm = noti.getAsMultipart();
assertNotNull(mm);
assertEquals(2, mm.getCount());
part = mm.getBodyPart(1);
assertTrue(part.getContentType().startsWith("message/disposition-notification"));
headers = noti.getNotificationFieldsAsHeaders();
assertNotNull(headers.getHeader(MDNStandard.Headers.Warning));
assertEquals("junit warning", headers.getHeader(MDNStandard.Headers.Warning, ","));
}
use of javax.mail.internet.MimeMultipart in project nhin-d by DirectProject.
the class NotificationTest method testSetExplanation_AssertExplanation.
public void testSetExplanation_AssertExplanation() throws Exception {
Notification noti = new Notification(NotificationType.Processed);
MimeMultipart mm = noti.getAsMultipart();
assertNotNull(mm);
assertEquals(2, mm.getCount());
BodyPart part = mm.getBodyPart(0);
assertTrue(part.getContentType().startsWith("text/plain"));
assertEquals("Your message was successfully processed.", part.getContent().toString());
// set a new explanation
noti.setExplanation("Testing this explantation");
mm = noti.getAsMultipart();
assertNotNull(mm);
assertEquals(2, mm.getCount());
part = mm.getBodyPart(0);
assertTrue(part.getContentType().startsWith("text/plain"));
assertEquals("Testing this explantation", noti.getExplanation());
assertEquals(noti.getExplanation(), part.getContent().toString());
// make sure this didn't change
part = mm.getBodyPart(1);
assertTrue(part.getContentType().startsWith("message/disposition-notification"));
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
part.writeTo(outStream);
String content = new String(outStream.toByteArray());
assertTrue(content.contains("automatic-action/MDN-sent-automatically;processed"));
}
use of javax.mail.internet.MimeMultipart in project jdk8u_jdk by JetBrains.
the class MailTest method sendMail.
void sendMail() {
try {
Properties props = new Properties();
props.put("mail.smtp.host", host);
props.put("mail.smtp.auth", "true");
Session session = Session.getInstance(props);
session.setDebug(true);
// Define message
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipients(Message.RecipientType.TO, to);
message.setSubject("this is a multipart test");
Multipart multipart = new MimeMultipart();
BodyPart messageBodyPart1 = new MimeBodyPart();
messageBodyPart1.setText("please send also this Content\n ciao!");
multipart.addBodyPart(messageBodyPart1);
BodyPart messageBodyPart2 = new MimeBodyPart();
messageBodyPart2.setContent("<b>please</b> send also this Content <br>ciao!", "text/html; charset=UTF-8");
multipart.addBodyPart(messageBodyPart2);
message.setContent(multipart);
/*
Transport tr = session.getTransport("smtp");
tr.connect(host,user, password);
tr.sendMessage(message,InternetAddress.parse(to));
tr.close();
*/
ByteArrayOutputStream baos = new ByteArrayOutputStream();
message.writeTo(baos);
String output = baos.toString();
System.out.println("output = " + output);
if (output.contains("also this Content")) {
System.out.println("Test PASSED.");
} else {
System.out.println("Test FAILED, missing content.");
throw new IllegalStateException("Test FAILED, missing content.");
}
} catch (MessagingException ignored) {
} catch (IOException ignored) {
}
}
use of javax.mail.internet.MimeMultipart in project nhin-d by DirectProject.
the class NotificationTest method testFailedNotification.
public void testFailedNotification() throws Exception {
Notification noti = new Notification(NotificationType.Failed);
System.out.println(noti);
MimeMultipart mm = noti.getAsMultipart();
assertNotNull(mm);
assertEquals(2, mm.getCount());
BodyPart part = mm.getBodyPart(0);
assertTrue(part.getContentType().startsWith("text/plain"));
assertEquals(Notification.DefaultExplanationFailed, part.getContent().toString());
part = mm.getBodyPart(1);
assertTrue(part.getContentType().startsWith("message/disposition-notification"));
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
part.writeTo(outStream);
String content = new String(outStream.toByteArray());
assertTrue(content.contains("automatic-action/MDN-sent-automatically;failed"));
}
use of javax.mail.internet.MimeMultipart in project voldemort by voldemort.
the class CoordinatorRestAPITest method doGet.
private TestVersionedValue doGet(String key, Map<String, Object> options) {
HttpURLConnection conn = null;
String response = null;
TestVersionedValue responseObj = null;
int expectedResponseCode = 200;
try {
// Create the right URL and Http connection
String base64Key = new String(Base64.encodeBase64(key.getBytes()));
URL url = new URL(this.coordinatorURL + "/" + STORE_NAME + "/" + base64Key);
conn = (HttpURLConnection) url.openConnection();
// Set the right headers
conn.setRequestMethod("GET");
conn.setDoInput(true);
conn.setRequestProperty(RestMessageHeaders.X_VOLD_REQUEST_TIMEOUT_MS, "1000");
conn.setRequestProperty(RestMessageHeaders.X_VOLD_REQUEST_ORIGIN_TIME_MS, Long.toString(System.currentTimeMillis()));
// options
if (options != null) {
if (options.get("timeout") != null && options.get("timeout") instanceof String) {
conn.setRequestProperty(RestMessageHeaders.X_VOLD_REQUEST_TIMEOUT_MS, (String) options.get("timeout"));
}
if (options.get("responseCode") != null && options.get("responseCode") instanceof Integer) {
expectedResponseCode = (Integer) options.get("responseCode");
}
}
// Check for the right response code
if (conn.getResponseCode() != expectedResponseCode) {
System.err.println("Illegal response during GET : " + conn.getResponseMessage());
fail("Incorrect response received for a HTTP GET request :" + conn.getResponseCode());
}
if (conn.getResponseCode() == 404 || conn.getResponseCode() == 408) {
return null;
}
// Buffer the result into a string
ByteArrayDataSource ds = new ByteArrayDataSource(conn.getInputStream(), "multipart/mixed");
MimeMultipart mp = new MimeMultipart(ds);
assertEquals("The number of body parts expected is not 1", 1, mp.getCount());
MimeBodyPart part = (MimeBodyPart) mp.getBodyPart(0);
VectorClock vc = RestUtils.deserializeVectorClock(part.getHeader(RestMessageHeaders.X_VOLD_VECTOR_CLOCK)[0]);
int contentLength = Integer.parseInt(part.getHeader(RestMessageHeaders.CONTENT_LENGTH)[0]);
byte[] bodyPartBytes = new byte[contentLength];
part.getInputStream().read(bodyPartBytes);
response = new String(bodyPartBytes);
responseObj = new TestVersionedValue(response, vc);
} catch (Exception e) {
e.printStackTrace();
fail("Error in sending the REST request");
} finally {
if (conn != null) {
conn.disconnect();
}
}
return responseObj;
}
Aggregations