Search in sources :

Example 76 with Exchange

use of org.apache.camel.Exchange in project Activiti by Activiti.

the class SimpleProcessTest method testRunProcess.

@Deployment(resources = { "process/example.bpmn20.xml" })
public void testRunProcess() throws Exception {
    CamelContext ctx = applicationContext.getBean(CamelContext.class);
    ProducerTemplate tpl = ctx.createProducerTemplate();
    service1.expectedBodiesReceived("ala");
    Exchange exchange = ctx.getEndpoint("direct:start").createExchange();
    exchange.getIn().setBody(Collections.singletonMap("var1", "ala"));
    tpl.send("direct:start", exchange);
    String instanceId = (String) exchange.getProperty("PROCESS_ID_PROPERTY");
    tpl.sendBodyAndProperty("direct:receive", null, ActivitiProducer.PROCESS_ID_PROPERTY, instanceId);
    assertProcessEnded(instanceId);
    service1.assertIsSatisfied();
    Map<?, ?> m = service2.getExchanges().get(0).getIn().getBody(Map.class);
    assertEquals("ala", m.get("var1"));
    assertEquals("var2", m.get("var2"));
}
Also used : CamelContext(org.apache.camel.CamelContext) Exchange(org.apache.camel.Exchange) ProducerTemplate(org.apache.camel.ProducerTemplate) Deployment(org.activiti.engine.test.Deployment)

Example 77 with Exchange

use of org.apache.camel.Exchange in project Activiti by Activiti.

the class SimpleSpringProcessTest method testRunProcess.

@Deployment(resources = { "process/example.bpmn20.xml" })
public void testRunProcess() throws Exception {
    CamelContext ctx = applicationContext.getBean(CamelContext.class);
    ProducerTemplate tpl = ctx.createProducerTemplate();
    service1.expectedBodiesReceived("ala");
    Exchange exchange = ctx.getEndpoint("direct:start").createExchange();
    exchange.getIn().setBody(Collections.singletonMap("var1", "ala"));
    tpl.send("direct:start", exchange);
    String instanceId = (String) exchange.getProperty("PROCESS_ID_PROPERTY");
    tpl.sendBodyAndProperty("direct:receive", null, ActivitiProducer.PROCESS_ID_PROPERTY, instanceId);
    assertProcessEnded(instanceId);
    service1.assertIsSatisfied();
    Map<?, ?> m = service2.getExchanges().get(0).getIn().getBody(Map.class);
    assertEquals("ala", m.get("var1"));
    assertEquals("var2", m.get("var2"));
}
Also used : CamelContext(org.apache.camel.CamelContext) Exchange(org.apache.camel.Exchange) ProducerTemplate(org.apache.camel.ProducerTemplate) Deployment(org.activiti.engine.test.Deployment)

Example 78 with Exchange

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

the class DSNMessageGenerator_generateDSNFailureMessageTest method testGenerateDSNFailureMessage_fromJson_incomingAndCompleteRecips.

@Test
public void testGenerateDSNFailureMessage_fromJson_incomingAndCompleteRecips() throws Exception {
    Exchange exchange = new DefaultExchange(mock(CamelContext.class));
    final String json = FileUtils.readFileToString(new File("./src/test/resources/json/multiRecipEmailSingleDNSAndMDN.json"));
    final ObjectMapper jsonMapper = new ObjectMapper();
    jsonMapper.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, false);
    List<Tx> txs = jsonMapper.readValue(json, TypeFactory.collectionType(ArrayList.class, Tx.class));
    DSNMessageGenerator generator = createGenerator();
    generator.generateDSNFailureMessage(txs, exchange);
    MimeMessage dsnMessage = (MimeMessage) exchange.getIn().getBody();
    assertNotNull(dsnMessage);
    ByteArrayOutputStream oStr = new ByteArrayOutputStream();
    dsnMessage.writeTo(oStr);
    final String dsnStr = new String(oStr.toByteArray());
    assertTrue(dsnStr.contains("gm2552@direct.securehealthemail.com"));
    assertFalse(dsnStr.contains("test@aol.com"));
}
Also used : Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) CamelContext(org.apache.camel.CamelContext) Tx(org.nhindirect.common.tx.model.Tx) MimeMessage(javax.mail.internet.MimeMessage) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) File(java.io.File) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 79 with Exchange

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

the class TestTimeoutToDupStateManager method testTimeoutReliableMessage_conditionNotComplete_assertDupAdded.

@Test
public void testTimeoutReliableMessage_conditionNotComplete_assertDupAdded() throws Exception {
    NotificationDuplicationDAO dao = context.getRegistry().lookup("notificationDuplicationDAO", NotificationDuplicationDAO.class);
    assertNotNull(dao);
    purgeNotifDAO(dao);
    MockEndpoint mock = getMockEndpoint("mock:result");
    // send original message
    final String originalMessageId = UUID.randomUUID().toString();
    Tx originalMessage = TestUtils.makeReliableMessage(TxMessageType.IMF, originalMessageId, "", "gm2552@cerner.com", "gm2552@direct.securehealthemail.com", "", "", "");
    template.sendBody("direct:start", originalMessage);
    // no MDN sent... messages should timeout after 2 seconds
    // sleep 3 seconds to make sure it completes
    Thread.sleep(3000);
    List<Exchange> exchanges = mock.getReceivedExchanges();
    assertEquals(1, exchanges.size());
    Exchange exchange = exchanges.iterator().next();
    // make sure there is only 1 message in the exchange
    MimeMessage message = exchange.getIn().getBody(MimeMessage.class);
    assertNotNull(message);
    assertEquals("timeout", exchange.getProperty(Exchange.AGGREGATED_COMPLETED_BY));
    Set<String> addresses = dao.getReceivedAddresses(originalMessageId + "\t" + message.getMessageID(), Arrays.asList("gm2552@direct.securehealthemail.com"));
    assertEquals(1, addresses.size());
    assertTrue(addresses.contains("gm2552@direct.securehealthemail.com"));
    addresses = dao.getReceivedAddresses(originalMessageId, Arrays.asList("gm2552@direct.securehealthemail.com"));
    assertEquals(1, addresses.size());
    assertTrue(addresses.contains("gm2552@direct.securehealthemail.com"));
}
Also used : Exchange(org.apache.camel.Exchange) Tx(org.nhindirect.common.tx.model.Tx) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MimeMessage(javax.mail.internet.MimeMessage) NotificationDuplicationDAO(org.nhindirect.monitor.dao.NotificationDuplicationDAO) Test(org.junit.Test)

Example 80 with Exchange

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

the class ConcurrentJPAAggregationRepository method recover.

/**
	 * {@inheritDoc}
	 * This specific implementation locks the recovered exchange for a period of time specified by the DAO.
	 * If the exchange is locked by the DAO, then null is returned.
	 */
@Override
public Exchange recover(CamelContext camelContext, String exchangeId) {
    Exchange retVal = null;
    try {
        // recover the exchnage from the repository
        final AggregationCompleted agg = dao.getAggregationCompleted(exchangeId, true);
        // not found or is locked... return null
        if (agg == null)
            return null;
        // deserialize exchange 
        retVal = codec.unmarshallExchange(camelContext, new Buffer(agg.getExchangeBlob()));
        // set the version number of the exchange
        retVal.setProperty(AGGREGATION_COMPLETE_ENTITY_VERSON, agg.getVersion());
    } catch (Exception e) {
        // wrap exception in a runtime exception
        throw new RuntimeException("Error recovering exchange from repository with exchangeId " + exchangeId, e);
    }
    return retVal;
}
Also used : Exchange(org.apache.camel.Exchange) Buffer(org.fusesource.hawtbuf.Buffer) AggregationCompleted(org.nhindirect.monitor.dao.entity.AggregationCompleted)

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