Search in sources :

Example 86 with Exchange

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();
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) CamelContext(org.apache.camel.CamelContext) SMTPClient(org.apache.commons.net.smtp.SMTPClient) MimeMessage(javax.mail.internet.MimeMessage) IOException(java.io.IOException) Test(org.junit.Test)

Example 87 with Exchange

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);
    }
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) CamelContext(org.apache.camel.CamelContext) Tx(org.nhindirect.common.tx.model.Tx) InputStream(java.io.InputStream) TxDetail(org.nhindirect.common.tx.model.TxDetail) ArrayList(java.util.ArrayList) DefaultTxDetailParser(org.nhindirect.common.tx.impl.DefaultTxDetailParser) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) MimeMessage(javax.mail.internet.MimeMessage) Test(org.junit.Test)

Example 88 with Exchange

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());
}
Also used : Exchange(org.apache.camel.Exchange) Tx(org.nhindirect.common.tx.model.Tx) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Collection(java.util.Collection) Test(org.junit.Test)

Example 89 with Exchange

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());
}
Also used : Exchange(org.apache.camel.Exchange) Tx(org.nhindirect.common.tx.model.Tx) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) ArrayList(java.util.ArrayList) Collection(java.util.Collection) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 90 with Exchange

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());
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) Tx(org.nhindirect.common.tx.model.Tx) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) AggregationDAO(org.nhindirect.monitor.dao.AggregationDAO) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Aggregations

Exchange (org.apache.camel.Exchange)3446 Test (org.junit.Test)1735 Processor (org.apache.camel.Processor)1405 RouteBuilder (org.apache.camel.builder.RouteBuilder)666 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)640 DefaultExchange (org.apache.camel.impl.DefaultExchange)473 Message (org.apache.camel.Message)379 Endpoint (org.apache.camel.Endpoint)235 HashMap (java.util.HashMap)190 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)155 Producer (org.apache.camel.Producer)150 File (java.io.File)120 ArrayList (java.util.ArrayList)117 CamelContext (org.apache.camel.CamelContext)117 List (java.util.List)99 Map (java.util.Map)96 ProducerTemplate (org.apache.camel.ProducerTemplate)94 IOException (java.io.IOException)92 Tx (org.nhindirect.common.tx.model.Tx)83 Predicate (org.apache.camel.Predicate)78