use of javax.mail.internet.MimeMessage in project nhin-d by DirectProject.
the class NHINDAgentTest method testEndToEndMessageBase64AttachmentOnly.
public void testEndToEndMessageBase64AttachmentOnly() throws Exception {
DefaultNHINDAgent agent = TestUtils.getStockAgent(Arrays.asList(new String[] { "messaging.cernerdemos.com" }));
String testMessage = TestUtils.readResource("raw2.txt");
MimeMessage originalMsg = new MimeMessage(null, new ByteArrayInputStream(testMessage.getBytes("ASCII")));
OutgoingMessage SMIMEenvMessage = agent.processOutgoing(testMessage);
assertNotNull(SMIMEenvMessage);
assertTrue(SMIMEenvMessage.getMessage().toString().length() > 0);
// verify the message
// need a new agent because this is a different domain
agent = TestUtils.getStockAgent(Arrays.asList(new String[] { "securehealthemail.com" }));
IncomingMessage strippedAndVerifiesMessage = agent.processIncoming(SMIMEenvMessage);
assertNotNull(strippedAndVerifiesMessage);
assertTrue(strippedAndVerifiesMessage.getMessage().toString().length() > 0);
MimeMessage processedMsg = new MimeMessage(null, new ByteArrayInputStream(strippedAndVerifiesMessage.getMessage().toString().getBytes("ASCII")));
assertNotNull(processedMsg);
// can't do a direct compare on headers because the processing may strip some of the recipients
assertTrue(processedMsg.getContentType().compareTo(originalMsg.getContentType()) == 0);
assertTrue(originalMsg.getSubject().compareTo(processedMsg.getSubject()) == 0);
// get the message data and compare
ByteArrayOutputStream oStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int count = 0;
InputStream inStream = originalMsg.getInputStream();
while ((count = inStream.read(buffer)) > -1) oStream.write(buffer, 0, count);
oStream = new ByteArrayOutputStream();
count = 0;
inStream = processedMsg.getInputStream();
while ((count = inStream.read(buffer)) > -1) oStream.write(buffer, 0, count);
}
use of javax.mail.internet.MimeMessage in project nhin-d by DirectProject.
the class NotificationTest method testParseFieldsFromMimeMessage_NonMDNMessage_AssertExecption.
public void testParseFieldsFromMimeMessage_NonMDNMessage_AssertExecption() throws Exception {
String testMessage = TestUtils.readResource("MessageWithAttachment.txt");
MimeMessage msg = new MimeMessage(null, new ByteArrayInputStream(testMessage.getBytes("ASCII")));
boolean exceptionOccured = false;
try {
Notification.getNotificationFieldsAsHeaders(msg);
} catch (IllegalArgumentException e) {
exceptionOccured = true;
}
assertTrue(exceptionOccured);
}
use of javax.mail.internet.MimeMessage in project nhin-d by DirectProject.
the class NotificationTest method testParseFieldsFromMimeMessage.
public void testParseFieldsFromMimeMessage() throws Exception {
String testMessage = TestUtils.readResource("MDNMessage.txt");
MimeMessage msg = new MimeMessage(null, new ByteArrayInputStream(testMessage.getBytes("ASCII")));
InternetHeaders headers = Notification.getNotificationFieldsAsHeaders(msg);
assertNotNull(headers.getHeader(MDNStandard.Headers.Disposition));
assertEquals("automatic-action/MDN-sent-automatically;processed", headers.getHeader(MDNStandard.Headers.Disposition, ","));
assertNotNull(headers.getHeader(MDNStandard.Headers.ReportingAgent));
assertEquals("starugh-stateline.com;NHIN Direct Security Agent", headers.getHeader(MDNStandard.Headers.ReportingAgent, ","));
assertNotNull(headers.getHeader(MDNStandard.Headers.FinalRecipient));
assertEquals("externUser1@starugh-stateline.com", headers.getHeader(MDNStandard.Headers.FinalRecipient, ","));
assertNotNull(headers.getHeader(MDNStandard.Headers.OriginalMessageID));
assertEquals("<9501051053.aa04167@IETF.CNR I.Reston.VA.US>", headers.getHeader(MDNStandard.Headers.OriginalMessageID, ","));
}
use of javax.mail.internet.MimeMessage in project nhin-d by DirectProject.
the class DSNMessageGenerator_generateDSNFailureMessageTest method testGenerateDSNFailureMessage_fromJson_incomingAndCompleteRecips.
@Test
public void testGenerateDSNFailureMessage_fromJson_incomingAndCompleteRecips() throws Exception {
Exchange exchange = new DefaultExchange(mock(CamelContext.class));
final String json = FileUtils.readFileToString(new File("./src/test/resources/json/multiRecipEmailSingleDNSAndMDN.json"));
final ObjectMapper jsonMapper = new ObjectMapper();
jsonMapper.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, false);
List<Tx> txs = jsonMapper.readValue(json, TypeFactory.collectionType(ArrayList.class, Tx.class));
DSNMessageGenerator generator = createGenerator();
generator.generateDSNFailureMessage(txs, exchange);
MimeMessage dsnMessage = (MimeMessage) exchange.getIn().getBody();
assertNotNull(dsnMessage);
ByteArrayOutputStream oStr = new ByteArrayOutputStream();
dsnMessage.writeTo(oStr);
final String dsnStr = new String(oStr.toByteArray());
assertTrue(dsnStr.contains("gm2552@direct.securehealthemail.com"));
assertFalse(dsnStr.contains("test@aol.com"));
}
use of javax.mail.internet.MimeMessage in project nhin-d by DirectProject.
the class TestTimeoutToDupStateManager method testTimeoutReliableMessage_conditionNotComplete_assertDupAdded.
@Test
public void testTimeoutReliableMessage_conditionNotComplete_assertDupAdded() throws Exception {
NotificationDuplicationDAO dao = context.getRegistry().lookup("notificationDuplicationDAO", NotificationDuplicationDAO.class);
assertNotNull(dao);
purgeNotifDAO(dao);
MockEndpoint mock = getMockEndpoint("mock:result");
// send original message
final String originalMessageId = UUID.randomUUID().toString();
Tx originalMessage = TestUtils.makeReliableMessage(TxMessageType.IMF, originalMessageId, "", "gm2552@cerner.com", "gm2552@direct.securehealthemail.com", "", "", "");
template.sendBody("direct:start", originalMessage);
// no MDN sent... messages should timeout after 2 seconds
// sleep 3 seconds to make sure it completes
Thread.sleep(3000);
List<Exchange> exchanges = mock.getReceivedExchanges();
assertEquals(1, exchanges.size());
Exchange exchange = exchanges.iterator().next();
// make sure there is only 1 message in the exchange
MimeMessage message = exchange.getIn().getBody(MimeMessage.class);
assertNotNull(message);
assertEquals("timeout", exchange.getProperty(Exchange.AGGREGATED_COMPLETED_BY));
Set<String> addresses = dao.getReceivedAddresses(originalMessageId + "\t" + message.getMessageID(), Arrays.asList("gm2552@direct.securehealthemail.com"));
assertEquals(1, addresses.size());
assertTrue(addresses.contains("gm2552@direct.securehealthemail.com"));
addresses = dao.getReceivedAddresses(originalMessageId, Arrays.asList("gm2552@direct.securehealthemail.com"));
assertEquals(1, addresses.size());
assertTrue(addresses.contains("gm2552@direct.securehealthemail.com"));
}
Aggregations