Search in sources :

Example 1 with TxTimeoutCondition

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

the class VariableTimeoutCondition_constructionTest method testConstruction.

@Test
public void testConstruction() {
    TxTimeoutCondition cond1 = mock(TxTimeoutCondition.class);
    TxTimeoutCondition cond2 = mock(TxTimeoutCondition.class);
    VariableTimeoutCondition cond = new VariableTimeoutCondition(cond1, cond2);
    assertEquals(cond1, cond.timelyExpression);
    assertEquals(cond2, cond.generalExpression);
}
Also used : TxTimeoutCondition(org.nhindirect.monitor.condition.TxTimeoutCondition) Test(org.junit.Test)

Example 2 with TxTimeoutCondition

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

the class VariableTimeoutCondition_constructionTest method testConstruction_nullTimelyCondition_assertException.

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

Example 3 with TxTimeoutCondition

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

the class VariableTimeoutCondition_constructionTest method testConstruction_nullGeneralCondition_assertException.

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

Example 4 with TxTimeoutCondition

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

the class VariableTimeoutCondition_getTimeoutTest method testGetTimeoutTest_nullMessageToTrack_assertUsesGeneralCondtion.

@SuppressWarnings("unchecked")
@Test
public void testGetTimeoutTest_nullMessageToTrack_assertUsesGeneralCondtion() {
    TxTimeoutCondition timelyCond = mock(TxTimeoutCondition.class);
    TxTimeoutCondition generalCond = mock(TxTimeoutCondition.class);
    VariableTimeoutCondition cond = new VariableTimeoutCondition(timelyCond, generalCond);
    VariableTimeoutCondition spy = spy(cond);
    when(spy.getMessageToTrack((Collection<Tx>) any())).thenReturn(null);
    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)

Example 5 with TxTimeoutCondition

use of org.nhindirect.monitor.condition.TxTimeoutCondition 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

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