Search in sources :

Example 81 with Exchange

use of org.apache.camel.Exchange in project nhin-d by DirectProject.

the class ConcurrentJPAAggregationRepository method get.

/**
	 * {@inheritDoc}
	 */
@Override
public Exchange get(CamelContext camelContext, String key) {
    Exchange retVal = null;
    try {
        // get the aggregation
        final Aggregation agg = dao.getAggregation(key);
        if (agg == null)
            return null;
        // deserialized to an exchange object
        retVal = codec.unmarshallExchange(camelContext, new Buffer(agg.getExchangeBlob()));
        // set the version of the exchange for later consistency checking
        retVal.setProperty(AGGREGATION_ENTITY_VERSON, agg.getVersion());
    } catch (Exception e) {
        // wrap exception in a runtime exception
        throw new RuntimeException("Error retrieving from repository aggregation with key " + key, e);
    }
    return retVal;
}
Also used : Exchange(org.apache.camel.Exchange) Aggregation(org.nhindirect.monitor.dao.entity.Aggregation) Buffer(org.fusesource.hawtbuf.Buffer)

Example 82 with Exchange

use of org.apache.camel.Exchange in project nhin-d by DirectProject.

the class ConcurrentJPAAggregationRepository_recoverTest method testRecover_exchangeInRepo_assertRecovered.

@Test
public void testRecover_exchangeInRepo_assertRecovered() {
    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);
    final Exchange completedExchange = repo.recover(context, exchange.getExchangeId());
    assertNotNull(completedExchange);
    final Tx completedTx = (Tx) completedExchange.getIn().getBody();
    assertEquals("12345", completedTx.getDetail(TxDetailType.MSG_ID).getDetailValue());
}
Also used : Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) Tx(org.nhindirect.common.tx.model.Tx) ConcurrentJPAAggregationRepository(org.nhindirect.monitor.aggregator.repository.ConcurrentJPAAggregationRepository) Test(org.junit.Test)

Example 83 with Exchange

use of org.apache.camel.Exchange in project nhin-d by DirectProject.

the class ConcurrentJPAAggregationRepository_recoverTest method testRecover_exchangeWithCollectionBodyInRepo_assertRecovered.

@Test
@SuppressWarnings("unchecked")
public void testRecover_exchangeWithCollectionBodyInRepo_assertRecovered() {
    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);
    final Exchange exchange = new DefaultExchange(context);
    exchange.getIn().setBody(txs);
    final ConcurrentJPAAggregationRepository repo = new ConcurrentJPAAggregationRepository(notifDao);
    repo.add(context, "12345", exchange);
    repo.remove(context, "12345", exchange);
    final Exchange completedExchange = repo.recover(context, exchange.getExchangeId());
    assertNotNull(completedExchange);
    final Collection<Tx> retrievedTxs = (Collection<Tx>) completedExchange.getIn().getBody();
    assertEquals(2, retrievedTxs.size());
    assertEquals("12345", retrievedTxs.iterator().next().getDetail(TxDetailType.MSG_ID).getDetailValue());
}
Also used : Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) 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 84 with Exchange

use of org.apache.camel.Exchange in project nhin-d by DirectProject.

the class ConcurrentJPAAggregationRepository_removeTest method testRemove_exchangeNotInRepo_assertException.

@Test
public void testRemove_exchangeNotInRepo_assertException() {
    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);
    boolean exceptionOccured = false;
    try {
        repo.remove(context, "12345", exchange);
    } catch (RuntimeException e) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
}
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)

Example 85 with Exchange

use of org.apache.camel.Exchange in project nhin-d by DirectProject.

the class DSNMailSender_sendMailTest method testSendMail_emptyFactory.

@Test
public void testSendMail_emptyFactory() throws Exception {
    Exchange exchange = new DefaultExchange(mock(CamelContext.class));
    DSNMailSender sender = new DSNMailSender("smtp://localhost", null);
    boolean exceptionOccurred = false;
    try {
        sender.sendMail(exchange);
    } catch (IllegalStateException e) {
        exceptionOccurred = true;
    }
    assertTrue(exceptionOccurred);
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) CamelContext(org.apache.camel.CamelContext) Test(org.junit.Test)

Aggregations

Exchange (org.apache.camel.Exchange)3446 Test (org.junit.Test)1735 Processor (org.apache.camel.Processor)1405 RouteBuilder (org.apache.camel.builder.RouteBuilder)666 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)640 DefaultExchange (org.apache.camel.impl.DefaultExchange)473 Message (org.apache.camel.Message)379 Endpoint (org.apache.camel.Endpoint)235 HashMap (java.util.HashMap)190 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)155 Producer (org.apache.camel.Producer)150 File (java.io.File)120 ArrayList (java.util.ArrayList)117 CamelContext (org.apache.camel.CamelContext)117 List (java.util.List)99 Map (java.util.Map)96 ProducerTemplate (org.apache.camel.ProducerTemplate)94 IOException (java.io.IOException)92 Tx (org.nhindirect.common.tx.model.Tx)83 Predicate (org.apache.camel.Predicate)78