Search in sources :

Example 36 with Tx

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

the class MessageIdCorrelationExpression_evaluateTest method testEvaluate_MDNMessage_noParentMsgId_assertNullId.

@Test
public void testEvaluate_MDNMessage_noParentMsgId_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.MDN, 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 37 with Tx

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

the class MessageIdCorrelationExpression_evaluateTest method testEvaluate_DNSMessage_noParentMsgId_assertNullId.

@Test
public void testEvaluate_DNSMessage_noParentMsgId_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.MDN, 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 38 with Tx

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

the class MessageIdCorrelationExpression_evaluateTest method testEvaluate_MDNMessage_parentMsgIdExists_assertMessageIdEvaluated.

@Test
public void testEvaluate_MDNMessage_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.MDN, 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)

Example 39 with Tx

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

the class ConcurrentJPAAggregationRepository_addTest method testAdd_existingExchange_updateBody_assertExchangeAdded.

@Test
@SuppressWarnings("unchecked")
public void testAdd_existingExchange_updateBody_assertExchangeAdded() {
    final Tx tx = TestUtils.makeMessage(TxMessageType.IMF, "12345", "", "me@test.com", "you@test.com", "", "", "");
    final Exchange exchange = new DefaultExchange(context);
    exchange.getIn().setBody(tx);
    final ConcurrentJPAAggregationRepository repo = new ConcurrentJPAAggregationRepository(notifDao);
    repo.add(context, "12345", exchange);
    // now update it
    Exchange retrievedEx = repo.get(context, "12345");
    final Tx tx1 = TestUtils.makeMessage(TxMessageType.IMF, "12345", "", "me@test.com", "you@test.com", "", "", "");
    final Tx tx2 = TestUtils.makeMessage(TxMessageType.IMF, "67890", "", "me@test2.com", "you@test2.com", "", "", "");
    final Collection<Tx> txs = Arrays.asList(tx1, tx2);
    retrievedEx.getIn().setBody(txs);
    repo.add(context, "12345", retrievedEx);
    retrievedEx = repo.get(context, "12345");
    final Collection<Tx> retrievedTxs = (Collection<Tx>) retrievedEx.getIn().getBody();
    assertEquals(2, retrievedTxs.size());
    assertEquals("12345", retrievedTxs.iterator().next().getDetail(TxDetailType.MSG_ID).getDetailValue());
    final Integer version = (Integer) retrievedEx.getProperty(ConcurrentJPAAggregationRepository.AGGREGATION_ENTITY_VERSON);
    assertEquals(3, version.intValue());
}
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) Collection(java.util.Collection) ConcurrentJPAAggregationRepository(org.nhindirect.monitor.aggregator.repository.ConcurrentJPAAggregationRepository) Test(org.junit.Test)

Example 40 with Tx

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

the class ConcurrentJPAAggregationRepository_confirmTest method testConfirm_completedExchangeInRepository_assertExchangeRemoved.

@Test
public void testConfirm_completedExchangeInRepository_assertExchangeRemoved() {
    final Tx tx = TestUtils.makeMessage(TxMessageType.IMF, "12345", "", "me@test.com", "you@test.com", "", "", "");
    final Exchange exchange = new DefaultExchange(context);
    exchange.getIn().setBody(tx);
    final ConcurrentJPAAggregationRepository repo = new ConcurrentJPAAggregationRepository(notifDao);
    repo.add(context, "12345", exchange);
    repo.remove(context, "12345", exchange);
    assertNull(repo.get(context, "12345"));
    final Exchange completedExchange = repo.recover(context, exchange.getExchangeId());
    assertNotNull(completedExchange);
    repo.confirm(context, exchange.getExchangeId());
    assertNull(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) ConcurrentJPAAggregationRepository(org.nhindirect.monitor.aggregator.repository.ConcurrentJPAAggregationRepository) 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