Search in sources :

Example 11 with TxTimeoutCondition

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

the class BasicTxAggregator_getAggregationTimeTest method testIsComplete_txsExists_emptyInitialTimeProperty_assertNull.

@Test
public void testIsComplete_txsExists_emptyInitialTimeProperty_assertNull() {
    TxTimeoutCondition condition = mock(TxTimeoutCondition.class);
    BasicTxAggregator aggr = new BasicTxAggregator(null, condition);
    Tx tx = mock(Tx.class);
    Collection<Tx> oldTxs = new ArrayList<Tx>();
    oldTxs.add(tx);
    Message msg = mock(Message.class);
    when(msg.getBody(Collection.class)).thenReturn(oldTxs);
    Exchange exchange = mock(Exchange.class);
    when(exchange.getIn()).thenReturn(msg);
    when(exchange.getProperty(Exchange.CREATED_TIMESTAMP, Date.class)).thenReturn(null);
    assertNull(aggr.getAggregationTime(exchange));
    verify(exchange, times(1)).getProperty(Exchange.CREATED_TIMESTAMP, Date.class);
}
Also used : Exchange(org.apache.camel.Exchange) Tx(org.nhindirect.common.tx.model.Tx) Message(org.apache.camel.Message) TxTimeoutCondition(org.nhindirect.monitor.condition.TxTimeoutCondition) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 12 with TxTimeoutCondition

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

the class VariableTimeoutCondition_getTimeoutTest method testGetTimeoutTest_timelyMessage_assertUsesTimelyCondtion.

@SuppressWarnings("unchecked")
@Test
public void testGetTimeoutTest_timelyMessage_assertUsesTimelyCondtion() {
    TxTimeoutCondition timelyCond = mock(TxTimeoutCondition.class);
    TxTimeoutCondition generalCond = mock(TxTimeoutCondition.class);
    VariableTimeoutCondition cond = new VariableTimeoutCondition(timelyCond, generalCond);
    VariableTimeoutCondition spy = spy(cond);
    Tx tx = mock(Tx.class);
    when(spy.getMessageToTrack((Collection<Tx>) any())).thenReturn(tx);
    when(spy.isRelAndTimelyRequired((Tx) any())).thenReturn(true);
    assertEquals(0, spy.getTimeout(new ArrayList<Tx>(), 1000));
    verify(timelyCond, times(1)).getTimeout((ArrayList<Tx>) any(), eq((long) 1000));
    verify(generalCond, never()).getTimeout((ArrayList<Tx>) any(), eq((long) 1000));
}
Also used : Tx(org.nhindirect.common.tx.model.Tx) TxTimeoutCondition(org.nhindirect.monitor.condition.TxTimeoutCondition) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 13 with TxTimeoutCondition

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

the class VariableTimeoutCondition_getTimeoutTest method testGetTimeoutTest_nonTimelyMessage_assertUsesGeneralCondtion.

@SuppressWarnings("unchecked")
@Test
public void testGetTimeoutTest_nonTimelyMessage_assertUsesGeneralCondtion() {
    TxTimeoutCondition timelyCond = mock(TxTimeoutCondition.class);
    TxTimeoutCondition generalCond = mock(TxTimeoutCondition.class);
    VariableTimeoutCondition cond = new VariableTimeoutCondition(timelyCond, generalCond);
    VariableTimeoutCondition spy = spy(cond);
    Tx tx = mock(Tx.class);
    when(spy.getMessageToTrack((Collection<Tx>) any())).thenReturn(tx);
    when(spy.isRelAndTimelyRequired((Tx) any())).thenReturn(false);
    assertEquals(0, spy.getTimeout(new ArrayList<Tx>(), 1000));
    verify(timelyCond, never()).getTimeout((ArrayList<Tx>) any(), eq((long) 1000));
    verify(generalCond, times(1)).getTimeout((ArrayList<Tx>) any(), eq((long) 1000));
}
Also used : Tx(org.nhindirect.common.tx.model.Tx) TxTimeoutCondition(org.nhindirect.monitor.condition.TxTimeoutCondition) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

TxTimeoutCondition (org.nhindirect.monitor.condition.TxTimeoutCondition)13 Test (org.junit.Test)12 Tx (org.nhindirect.common.tx.model.Tx)8 ArrayList (java.util.ArrayList)6 Exchange (org.apache.camel.Exchange)5 Message (org.apache.camel.Message)3 TxCompletionCondition (org.nhindirect.monitor.condition.TxCompletionCondition)3 CamelContext (org.apache.camel.CamelContext)2 DefaultExchange (org.apache.camel.impl.DefaultExchange)2 Date (java.util.Date)1