Search in sources :

Example 21 with Tx

use of org.nhindirect.common.tx.model.Tx in project nhin-d by DirectProject.

the class TxResource_suppressNotificationTest method testSuppressNotification_mgrException_assert500StatusCode.

@Test
public void testSuppressNotification_mgrException_assert500StatusCode() throws Exception {
    Tx tx = mock(Tx.class);
    DuplicateNotificationStateManager dupMgr = mock(DuplicateNotificationStateManager.class);
    when(dupMgr.suppressNotification(tx)).thenThrow(new DuplicateNotificationStateManagerException());
    TxsResource resource = new TxsResource(null, dupMgr);
    Response res = resource.supressNotification(tx);
    assertEquals(500, res.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) DuplicateNotificationStateManager(org.nhindirect.monitor.processor.DuplicateNotificationStateManager) Tx(org.nhindirect.common.tx.model.Tx) DuplicateNotificationStateManagerException(org.nhindirect.monitor.processor.DuplicateNotificationStateManagerException) Test(org.junit.Test)

Example 22 with Tx

use of org.nhindirect.common.tx.model.Tx 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 23 with Tx

use of org.nhindirect.common.tx.model.Tx 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 24 with Tx

use of org.nhindirect.common.tx.model.Tx 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)

Example 25 with Tx

use of org.nhindirect.common.tx.model.Tx in project nhin-d by DirectProject.

the class TestRecoveryMonitorRoute method postProcessTest.

@Override
public void postProcessTest() throws Exception {
    super.postProcessTest();
    final AggregationDAO dao = (AggregationDAO) context.getRegistry().lookup("shortRecoveryIntervalAggregationDAO");
    dao.purgeAll();
    assertEquals(0, dao.getAggregationKeys().size());
    assertEquals(0, dao.getAggregationCompletedKeys().size());
    // pre populate some recovery data
    // send original message
    final String originalMessageId = UUID.randomUUID().toString();
    final Tx originalMessage = TestUtils.makeMessage(TxMessageType.IMF, originalMessageId, "", "gm2552@cerner.com", "gm2552@direct.securehealthemail.com,ah4626@direct.securehealthemail.com", "");
    final Exchange exchange = new DefaultExchange(context);
    exchange.getIn().setBody(originalMessage);
    final ConcurrentJPAAggregationRepository repo = (ConcurrentJPAAggregationRepository) context.getRegistry().lookup("monitoringRepo");
    repo.add(context, originalMessageId, exchange);
    repo.remove(context, originalMessageId, exchange);
    // lock the row to create a delay and ensure we recover 
    // exchange ids that return null at some point
    repo.recover(context, exchange.getExchangeId());
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) Tx(org.nhindirect.common.tx.model.Tx) AggregationDAO(org.nhindirect.monitor.dao.AggregationDAO) ConcurrentJPAAggregationRepository(org.nhindirect.monitor.aggregator.repository.ConcurrentJPAAggregationRepository)

Aggregations

Tx (org.nhindirect.common.tx.model.Tx)174 Test (org.junit.Test)156 Exchange (org.apache.camel.Exchange)83 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)49 TxDetail (org.nhindirect.common.tx.model.TxDetail)35 DefaultExchange (org.apache.camel.impl.DefaultExchange)32 ArrayList (java.util.ArrayList)26 HashMap (java.util.HashMap)19 MimeMessage (javax.mail.internet.MimeMessage)17 CamelContext (org.apache.camel.CamelContext)17 ConcurrentJPAAggregationRepository (org.nhindirect.monitor.aggregator.repository.ConcurrentJPAAggregationRepository)15 TxCompletionCondition (org.nhindirect.monitor.condition.TxCompletionCondition)14 TxTimeoutCondition (org.nhindirect.monitor.condition.TxTimeoutCondition)8 Collection (java.util.Collection)7 NotificationDuplicationDAO (org.nhindirect.monitor.dao.NotificationDuplicationDAO)7 NHINDAddress (org.nhindirect.stagent.NHINDAddress)6 NHINDAddressCollection (org.nhindirect.stagent.NHINDAddressCollection)6 Response (javax.ws.rs.core.Response)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 MessagingException (javax.mail.MessagingException)4