Search in sources :

Example 1 with NotificationDuplicationDAO

use of org.nhindirect.monitor.dao.NotificationDuplicationDAO 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"));
}
Also used : Exchange(org.apache.camel.Exchange) Tx(org.nhindirect.common.tx.model.Tx) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MimeMessage(javax.mail.internet.MimeMessage) NotificationDuplicationDAO(org.nhindirect.monitor.dao.NotificationDuplicationDAO) Test(org.junit.Test)

Example 2 with NotificationDuplicationDAO

use of org.nhindirect.monitor.dao.NotificationDuplicationDAO in project nhin-d by DirectProject.

the class DefaultDuplicateNotificationStateManager_purgeTest method testPurgeNotification_daoError_assertException.

@Test
public void testPurgeNotification_daoError_assertException() throws Exception {
    DefaultDuplicateNotificationStateManager mgr = new DefaultDuplicateNotificationStateManager();
    NotificationDuplicationDAO spyDao = mock(NotificationDuplicationDAO.class);
    doThrow(new NotificationDAOException("")).when(spyDao).purgeNotifications((Calendar) any());
    mgr.setDao(spyDao);
    mgr.purge();
}
Also used : NotificationDAOException(org.nhindirect.monitor.dao.NotificationDAOException) NotificationDuplicationDAO(org.nhindirect.monitor.dao.NotificationDuplicationDAO) Test(org.junit.Test)

Example 3 with NotificationDuplicationDAO

use of org.nhindirect.monitor.dao.NotificationDuplicationDAO in project nhin-d by DirectProject.

the class DefaultDuplicateNotificationStateManager_suppressNotificationTest method testAddNotification_daoError_assertException.

@SuppressWarnings("unchecked")
@Test
public void testAddNotification_daoError_assertException() throws Exception {
    DefaultDuplicateNotificationStateManager mgr = new DefaultDuplicateNotificationStateManager();
    boolean execptionOccured = false;
    NotificationDuplicationDAO spyDao = mock(NotificationDuplicationDAO.class);
    doThrow(new NotificationDAOException("")).when(spyDao).getReceivedAddresses((String) any(), (Collection<String>) any());
    mgr.setDao(spyDao);
    try {
        Tx tx = TestUtils.makeMessage(TxMessageType.DSN, "1234", "5678", "", "", "gm2552@cerner.com,ah4626@cerner.com");
        mgr.suppressNotification(tx);
    } catch (DuplicateNotificationStateManagerException e) {
        execptionOccured = true;
    }
    assertTrue(execptionOccured);
}
Also used : Tx(org.nhindirect.common.tx.model.Tx) NotificationDAOException(org.nhindirect.monitor.dao.NotificationDAOException) NotificationDuplicationDAO(org.nhindirect.monitor.dao.NotificationDuplicationDAO) DuplicateNotificationStateManagerException(org.nhindirect.monitor.processor.DuplicateNotificationStateManagerException) Test(org.junit.Test)

Example 4 with NotificationDuplicationDAO

use of org.nhindirect.monitor.dao.NotificationDuplicationDAO in project nhin-d by DirectProject.

the class TimeoutDupStateManager_addNotificationForOriginalRecipsTest method testAddNotificationForOriginalRecips_noOrigMsg_assertNotificationNotAdded.

@Test
public void testAddNotificationForOriginalRecips_noOrigMsg_assertNotificationNotAdded() throws Exception {
    TimeoutDupStateManager mgr = new TimeoutDupStateManager();
    NotificationDuplicationDAO dao = mock(NotificationDuplicationDAO.class);
    mgr.setDao(dao);
    final Tx tx = TestUtils.makeMessage(TxMessageType.MDN, "1234", "", "test@test.com", "me@you.com", "test@test.com");
    mgr.addNotificationForOriginalRecips(Arrays.asList(tx));
    verify(dao, never()).addNotification((String) any(), (String) any());
}
Also used : Tx(org.nhindirect.common.tx.model.Tx) NotificationDuplicationDAO(org.nhindirect.monitor.dao.NotificationDuplicationDAO) Test(org.junit.Test)

Example 5 with NotificationDuplicationDAO

use of org.nhindirect.monitor.dao.NotificationDuplicationDAO in project nhin-d by DirectProject.

the class TestTimeoutToDupStateManager method testTimeoutReliableMessage_conditionNotComplete_msgNotReliable_assertDupNotAdded.

@Test
public void testTimeoutReliableMessage_conditionNotComplete_msgNotReliable_assertDupNotAdded() 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.makeMessage(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 messages = exchange.getIn().getBody(MimeMessage.class);
    assertNotNull(messages);
    assertEquals("timeout", exchange.getProperty(Exchange.AGGREGATED_COMPLETED_BY));
    Set<String> addresses = dao.getReceivedAddresses(originalMessageId, Arrays.asList("gm2552@direct.securehealthemail.com"));
    assertEquals(0, addresses.size());
}
Also used : Exchange(org.apache.camel.Exchange) Tx(org.nhindirect.common.tx.model.Tx) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MimeMessage(javax.mail.internet.MimeMessage) NotificationDuplicationDAO(org.nhindirect.monitor.dao.NotificationDuplicationDAO) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)8 NotificationDuplicationDAO (org.nhindirect.monitor.dao.NotificationDuplicationDAO)8 Tx (org.nhindirect.common.tx.model.Tx)7 NotificationDAOException (org.nhindirect.monitor.dao.NotificationDAOException)3 MimeMessage (javax.mail.internet.MimeMessage)2 Exchange (org.apache.camel.Exchange)2 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)2 DuplicateNotificationStateManagerException (org.nhindirect.monitor.processor.DuplicateNotificationStateManagerException)2