Search in sources :

Example 6 with TxCompletionCondition

use of org.nhindirect.monitor.condition.TxCompletionCondition in project nhin-d by DirectProject.

the class VariableCompletionCondition_constructionTest method testConstruction_nullTimelyCondition_assertException.

@Test
public void testConstruction_nullTimelyCondition_assertException() {
    TxCompletionCondition cond = mock(TxCompletionCondition.class);
    boolean exceptionOccured = false;
    try {
        new VariableCompletionCondition(null, cond);
    } catch (IllegalArgumentException e) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
}
Also used : TxCompletionCondition(org.nhindirect.monitor.condition.TxCompletionCondition) Test(org.junit.Test)

Example 7 with TxCompletionCondition

use of org.nhindirect.monitor.condition.TxCompletionCondition in project nhin-d by DirectProject.

the class VariableCompletionCondition_constructionTest method testConstruction_nullGeneralCondition_assertException.

@Test
public void testConstruction_nullGeneralCondition_assertException() {
    TxCompletionCondition cond = mock(TxCompletionCondition.class);
    boolean exceptionOccured = false;
    try {
        new VariableCompletionCondition(cond, null);
    } catch (IllegalArgumentException e) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
}
Also used : TxCompletionCondition(org.nhindirect.monitor.condition.TxCompletionCondition) Test(org.junit.Test)

Example 8 with TxCompletionCondition

use of org.nhindirect.monitor.condition.TxCompletionCondition in project nhin-d by DirectProject.

the class VariableCompletionCondition_isCompleteTest method testIsComplete_isNotTimely_assertNotComplete.

@SuppressWarnings("unchecked")
@Test
public void testIsComplete_isNotTimely_assertNotComplete() {
    TxCompletionCondition timelyCond = mock(TxCompletionCondition.class);
    when(timelyCond.isComplete((Collection<Tx>) any())).thenReturn(true);
    TxCompletionCondition generalCond = mock(TxCompletionCondition.class);
    VariableCompletionCondition cond = new VariableCompletionCondition(timelyCond, generalCond);
    VariableCompletionCondition spy = spy(cond);
    Tx msgToTrack = mock(Tx.class);
    when(spy.getMessageToTrackInternal((Collection<Tx>) any())).thenReturn(msgToTrack);
    when(spy.isRelAndTimelyRequired((Tx) any())).thenReturn(false);
    assertFalse(spy.isComplete(null));
    verify(timelyCond, never()).isComplete((Collection<Tx>) any());
    verify(generalCond, times(1)).isComplete((Collection<Tx>) any());
}
Also used : TxCompletionCondition(org.nhindirect.monitor.condition.TxCompletionCondition) Tx(org.nhindirect.common.tx.model.Tx) Test(org.junit.Test)

Example 9 with TxCompletionCondition

use of org.nhindirect.monitor.condition.TxCompletionCondition in project nhin-d by DirectProject.

the class VariableCompletionCondition_isCompleteTest method testIsComplete_isNotTimely_assertComplete.

@SuppressWarnings("unchecked")
@Test
public void testIsComplete_isNotTimely_assertComplete() {
    TxCompletionCondition timelyCond = mock(TxCompletionCondition.class);
    TxCompletionCondition generalCond = mock(TxCompletionCondition.class);
    when(generalCond.isComplete((Collection<Tx>) any())).thenReturn(true);
    VariableCompletionCondition cond = new VariableCompletionCondition(timelyCond, generalCond);
    VariableCompletionCondition spy = spy(cond);
    Tx msgToTrack = mock(Tx.class);
    when(spy.getMessageToTrackInternal((Collection<Tx>) any())).thenReturn(msgToTrack);
    when(spy.isRelAndTimelyRequired((Tx) any())).thenReturn(false);
    assertTrue(spy.isComplete(null));
    verify(timelyCond, never()).isComplete((Collection<Tx>) any());
    verify(generalCond, times(1)).isComplete((Collection<Tx>) any());
}
Also used : TxCompletionCondition(org.nhindirect.monitor.condition.TxCompletionCondition) Tx(org.nhindirect.common.tx.model.Tx) Test(org.junit.Test)

Example 10 with TxCompletionCondition

use of org.nhindirect.monitor.condition.TxCompletionCondition in project nhin-d by DirectProject.

the class BasicTxAggregator_aggregateTest method testAggregate_singleEntryExchanged_addSingleTx.

@Test
public void testAggregate_singleEntryExchanged_addSingleTx() {
    TxTimeoutCondition timoutCondition = mock(TxTimeoutCondition.class);
    TxCompletionCondition condition = mock(TxCompletionCondition.class);
    BasicTxAggregator aggr = new BasicTxAggregator(condition, timoutCondition);
    CamelContext context = mock(CamelContext.class);
    DefaultExchange oldExchange = new DefaultExchange(context);
    Tx tx = mock(Tx.class);
    Collection<Tx> oldTxs = new ArrayList<Tx>();
    oldTxs.add(tx);
    oldExchange.getIn().setBody(oldTxs);
    DefaultExchange newExchange = new DefaultExchange(context);
    tx = mock(Tx.class);
    newExchange.getIn().setBody(tx);
    Exchange ex = aggr.aggregate(oldExchange, newExchange);
    @SuppressWarnings("unchecked") Collection<Tx> txs = ex.getIn().getBody(Collection.class);
    assertEquals(2, txs.size());
}
Also used : TxCompletionCondition(org.nhindirect.monitor.condition.TxCompletionCondition) CamelContext(org.apache.camel.CamelContext) DefaultExchange(org.apache.camel.impl.DefaultExchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) Tx(org.nhindirect.common.tx.model.Tx) TxTimeoutCondition(org.nhindirect.monitor.condition.TxTimeoutCondition) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

TxCompletionCondition (org.nhindirect.monitor.condition.TxCompletionCondition)21 Test (org.junit.Test)20 Tx (org.nhindirect.common.tx.model.Tx)14 Exchange (org.apache.camel.Exchange)5 ArrayList (java.util.ArrayList)4 TxDetail (org.nhindirect.common.tx.model.TxDetail)4 HashMap (java.util.HashMap)3 Message (org.apache.camel.Message)3 TxTimeoutCondition (org.nhindirect.monitor.condition.TxTimeoutCondition)3 CamelContext (org.apache.camel.CamelContext)2 DefaultExchange (org.apache.camel.impl.DefaultExchange)2 DSNFailureTextBodyPartGenerator (org.nhindirect.common.mail.dsn.DSNFailureTextBodyPartGenerator)1 DSNGenerator (org.nhindirect.common.mail.dsn.DSNGenerator)1 DefaultDSNFailureTextBodyPartGenerator (org.nhindirect.common.mail.dsn.impl.DefaultDSNFailureTextBodyPartGenerator)1 GeneralCompletionCondition (org.nhindirect.monitor.condition.impl.GeneralCompletionCondition)1