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"));
}
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"));
}
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"));
}
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"));
}
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;
}
Aggregations