Search in sources :

Example 31 with Tx

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

the class TestTimedOutMonitorRoute method testTimeoutReliableMessage_conditionNotComplete_assertTimedOutAndAggregatedTimeoutDecayed.

@Test
public void testTimeoutReliableMessage_conditionNotComplete_assertTimedOutAndAggregatedTimeoutDecayed() throws Exception {
    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);
    // sleep .5 second then send the next part of the message
    Thread.sleep(500);
    // send MDN processed to original message
    Tx mdnMessage = TestUtils.makeReliableMessage(TxMessageType.MDN, UUID.randomUUID().toString(), originalMessageId, "gm2552@direct.securehealthemail.com", "gm2552@cerner.com", "gm2552@direct.securehealthemail.com", "", MDNStandard.Disposition_Processed);
    template.sendBody("direct:start", mdnMessage);
    // no MDN sent... messages should timeout after 1 second from now
    // sleep 2 seconds to make sure it completes
    Thread.sleep(2000);
    List<Exchange> exchanges = mock.getReceivedExchanges();
    assertEquals(1, exchanges.size());
    Exchange exchange = exchanges.iterator().next();
    // make sure there are 2 messages in the exchange
    @SuppressWarnings("unchecked") Collection<Tx> messages = exchange.getIn().getBody(Collection.class);
    assertEquals(2, messages.size());
    assertEquals("timeout", exchange.getProperty(Exchange.AGGREGATED_COMPLETED_BY));
    // make sure the aggregated timeout decayed properly... it should now be < 500 ms
    assertTrue((Long) exchange.getProperty(Exchange.AGGREGATED_TIMEOUT) < 500);
}
Also used : Exchange(org.apache.camel.Exchange) Tx(org.nhindirect.common.tx.model.Tx) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 32 with Tx

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

the class TestTimedOutMonitorRoute method testTimeoutNonReliableMessage_conditionNotComplete_assertTimedOut.

@Test
public void testTimeoutNonReliableMessage_conditionNotComplete_assertTimedOut() 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", "");
    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();
    assertEquals("timeout", exchange.getProperty(Exchange.AGGREGATED_COMPLETED_BY));
}
Also used : Exchange(org.apache.camel.Exchange) Tx(org.nhindirect.common.tx.model.Tx) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 33 with Tx

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

the class MessageIdCorrelationExpression_evaluateTest method testEvaluate_emptyDetails_assertNullId.

@Test
public void testEvaluate_emptyDetails_assertNullId() {
    MessageIdCorrelationExpression exp = new MessageIdCorrelationExpression();
    Tx tx = new Tx(TxMessageType.IMF, new HashMap<String, TxDetail>());
    CamelContext context = mock(CamelContext.class);
    Exchange exchange = new DefaultExchange(context);
    exchange.getIn().setBody(tx);
    assertNull(exp.evaluate(exchange, String.class));
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) Tx(org.nhindirect.common.tx.model.Tx) TxDetail(org.nhindirect.common.tx.model.TxDetail) Test(org.junit.Test)

Example 34 with Tx

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

the class MessageIdCorrelationExpression_evaluateTest method testEvaluate_IMFMessage_noMsgId_assertNullId.

@Test
public void testEvaluate_IMFMessage_noMsgId_assertNullId() {
    MessageIdCorrelationExpression exp = new MessageIdCorrelationExpression();
    Map<String, TxDetail> details = new HashMap<String, TxDetail>();
    details.put(TxDetailType.FROM.getType(), new TxDetail(TxDetailType.FROM, "me@test.com"));
    Tx tx = new Tx(TxMessageType.IMF, details);
    CamelContext context = mock(CamelContext.class);
    Exchange exchange = new DefaultExchange(context);
    exchange.getIn().setBody(tx);
    assertNull(exp.evaluate(exchange, String.class));
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) Tx(org.nhindirect.common.tx.model.Tx) HashMap(java.util.HashMap) TxDetail(org.nhindirect.common.tx.model.TxDetail) Test(org.junit.Test)

Example 35 with Tx

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

the class MessageIdCorrelationExpression_evaluateTest method testEvaluate_DSNMessage_parentMsgIdExists_assertMessageIdEvaluated.

@Test
public void testEvaluate_DSNMessage_parentMsgIdExists_assertMessageIdEvaluated() {
    MessageIdCorrelationExpression exp = new MessageIdCorrelationExpression();
    String msgId = UUID.randomUUID().toString();
    Map<String, TxDetail> details = new HashMap<String, TxDetail>();
    details.put(TxDetailType.PARENT_MSG_ID.getType(), new TxDetail(TxDetailType.PARENT_MSG_ID, msgId));
    Tx tx = new Tx(TxMessageType.DSN, details);
    CamelContext context = mock(CamelContext.class);
    Exchange exchange = new DefaultExchange(context);
    exchange.getIn().setBody(tx);
    assertEquals(msgId, exp.evaluate(exchange, String.class));
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) Tx(org.nhindirect.common.tx.model.Tx) HashMap(java.util.HashMap) TxDetail(org.nhindirect.common.tx.model.TxDetail) Test(org.junit.Test)

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