use of org.apache.camel.Exchange in project nhin-d by DirectProject.
the class DSNMailSender_sendMailTest method testSendMail_nullWriter_assertException.
@Test
public void testSendMail_nullWriter_assertException() throws Exception {
MimeMessage msg = TestUtils.readMimeMessageFromFile("MessageWithAttachment.txt");
final SMTPClient client = mock(SMTPClient.class);
when(client.setSender((String) any())).thenReturn(true);
when(client.addRecipient((String) any())).thenReturn(true);
when(client.sendMessageData()).thenReturn(null);
when(client.getReplyCode()).thenReturn(250);
final SMTPClientFactory factory = createFactory(client);
DSNMailSender sender = new DSNMailSender("smtp://localhost", factory);
Exchange exchange = new DefaultExchange(mock(CamelContext.class));
exchange.getIn().setBody(msg);
boolean exceptionOccurred = false;
try {
sender.sendMail(exchange);
} catch (IOException e) {
exceptionOccurred = true;
}
assertTrue(exceptionOccurred);
verify(client, times(1)).sendMessageData();
verify(client, never()).completePendingCommand();
}
use of org.apache.camel.Exchange in project nhin-d by DirectProject.
the class DSNMessageGenerator_generateDSNFailureMessageTest method testGenerateDSNFailureMessage_assertMessageCreated_noCopiedSubject.
@Test
public void testGenerateDSNFailureMessage_assertMessageCreated_noCopiedSubject() throws Exception {
Exchange exchange = new DefaultExchange(mock(CamelContext.class));
String message = TestUtils.readMessageFromFile("MessageWithAttachment.txt");
DefaultTxDetailParser parser = new DefaultTxDetailParser();
InputStream str = IOUtils.toInputStream(message);
try {
// send original message
final MimeMessage mimeMessage = new MimeMessage(null, str);
mimeMessage.setHeader(MailStandard.Headers.Subject, "");
// change the message id
mimeMessage.saveChanges();
Map<String, TxDetail> details = parser.getMessageDetails(mimeMessage);
Tx originalMessage = new Tx(TxMessageType.IMF, details);
Collection<Tx> txs = new ArrayList<Tx>();
txs.add(originalMessage);
DSNMessageGenerator generator = createGenerator();
generator.generateDSNFailureMessage(txs, exchange);
MimeMessage dsnMessage = (MimeMessage) exchange.getIn().getBody();
assertNotNull(dsnMessage);
// check the subject
String newSubject = MailStandard.getHeader(dsnMessage, MailStandard.Headers.Subject);
assertEquals("Not Delivered:", newSubject);
} finally {
IOUtils.closeQuietly(str);
}
}
use of org.apache.camel.Exchange in project nhin-d by DirectProject.
the class TestFailedAddUpdateExchangeMonitorRoute method testSingleRecipMDNReceived_assertConditionComplete.
@SuppressWarnings("unchecked")
@Test
public void testSingleRecipMDNReceived_assertConditionComplete() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
// send original message
final String originalMessageId = UUID.randomUUID().toString();
Tx originalMessage = TestUtils.makeMessage(TxMessageType.IMF, originalMessageId, "", "gm2552@cerner.com", "gm2552@direct.securehealthemail.com,ah4626@direct.securehealthemail.com", "");
template.sendBody("direct:start", originalMessage);
// send MDN to original messages
Tx mdnMessage = TestUtils.makeMessage(TxMessageType.MDN, UUID.randomUUID().toString(), originalMessageId, "gm2552@direct.securehealthemail.com", "gm2552@cerner.com", "gm2552@direct.securehealthemail.com");
template.sendBody("direct:start", mdnMessage);
mdnMessage = TestUtils.makeMessage(TxMessageType.MDN, UUID.randomUUID().toString(), originalMessageId, "ah4626@direct.securehealthemail.com", "gm2552@cerner.com", "ah4626@direct.securehealthemail.com");
template.sendBody("direct:start", mdnMessage);
List<Exchange> exchanges = mock.getReceivedExchanges();
assertEquals(1, exchanges.size());
// validate the content of the exchange
Collection<Tx> exBody = (Collection<Tx>) exchanges.iterator().next().getIn().getBody();
assertEquals(3, exBody.size());
}
use of org.apache.camel.Exchange in project nhin-d by DirectProject.
the class TestMultithreadedAddUpdateFailureMonitoringRoute method testMultithreadedMDNResponseHandling_assertAllMDNsHandled.
@SuppressWarnings("unchecked")
@Test
public void testMultithreadedMDNResponseHandling_assertAllMDNsHandled() throws Exception {
final StringBuilder recipBuilder = new StringBuilder();
final Collection<String> recips = new ArrayList<String>();
// create a list of 100 recipients
for (int i = 0; i < 100; ++i) {
final String recip = "recip" + (i + 1) + "@test.com";
recips.add(recip);
recipBuilder.append(recip);
if (i != 99)
recipBuilder.append(",");
}
MockEndpoint mock = getMockEndpoint("mock:result");
// send original message
final String originalMessageId = UUID.randomUUID().toString();
Tx originalMessage = TestUtils.makeMessage(TxMessageType.IMF, originalMessageId, "", "gm2552@cerner.com", recipBuilder.toString(), "");
template.sendBody("seda:start", originalMessage);
// now send the recipient MDN messages
for (String recip : recips) {
// send MDN to original messages
Tx mdnMessage = TestUtils.makeMessage(TxMessageType.MDN, UUID.randomUUID().toString(), originalMessageId, recip, "gm2552@cerner.com", recip);
template.sendBody("seda:start", mdnMessage);
}
boolean exchangeFound = false;
int cnt = 0;
List<Exchange> exchanges = null;
while (cnt < 10) {
exchanges = mock.getReceivedExchanges();
if (exchanges.size() == 1) {
exchangeFound = true;
break;
}
++cnt;
Thread.sleep(2000);
}
assertTrue(exchangeFound);
// validate the content of the exchange
Collection<Tx> exBody = (Collection<Tx>) exchanges.iterator().next().getIn().getBody();
assertEquals(101, exBody.size());
}
use of org.apache.camel.Exchange in project nhin-d by DirectProject.
the class TestRecoveryMonitorRoute method testRecoverFromRepository.
@Test
public void testRecoverFromRepository() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
boolean exchangeFound = false;
int cnt = 0;
List<Exchange> exchanges = null;
while (cnt < 10) {
exchanges = mock.getReceivedExchanges();
if (exchanges.size() == 1) {
exchangeFound = true;
break;
}
++cnt;
Thread.sleep(2000);
}
assertTrue(exchangeFound);
Tx originalMessage = (Tx) exchanges.iterator().next().getIn().getBody();
assertEquals("gm2552@cerner.com", originalMessage.getDetail(TxDetailType.FROM).getDetailValue());
// make sure everything got confirmed
final AggregationDAO dao = (AggregationDAO) context.getRegistry().lookup("aggregationDAO");
assertEquals(0, dao.getAggregationKeys().size());
assertEquals(0, dao.getAggregationCompletedKeys().size());
}
Aggregations