Search in sources :

Example 56 with ProducerTemplate

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

the class CamelVariableTransferTest method testCamelHeadersAll.

@Deployment(resources = { "org/activiti/camel/variables/CamelVariableTransferTest.testCamelPropertiesAll.bpmn20.xml" })
public void testCamelHeadersAll() throws Exception {
    ProducerTemplate tpl = camelContext.createProducerTemplate();
    Exchange exchange = camelContext.getEndpoint("direct:startAllProperties").createExchange();
    tpl.send("direct:startAllProperties", exchange);
    assertNotNull(taskService);
    assertNotNull(runtimeService);
    assertEquals(1, taskService.createTaskQuery().count());
    Task task = taskService.createTaskQuery().singleResult();
    assertNotNull(task);
    Map<String, Object> variables = runtimeService.getVariables(task.getExecutionId());
    assertEquals("sampleValueForProperty1", variables.get("property1"));
    assertEquals("sampleValueForProperty2", variables.get("property2"));
    assertEquals("sampleValueForProperty3", variables.get("property3"));
}
Also used : Exchange(org.apache.camel.Exchange) ProducerTemplate(org.apache.camel.ProducerTemplate) Task(org.activiti.engine.task.Task) Deployment(org.activiti.engine.test.Deployment)

Example 57 with ProducerTemplate

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

the class CustomContextTest method testRunProcess.

@Deployment(resources = { "process/custom.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();
    @SuppressWarnings("rawtypes") 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) Map(java.util.Map) Deployment(org.activiti.engine.test.Deployment)

Example 58 with ProducerTemplate

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

the class EmptyProcessTest method testRunProcessWithHeader.

@Deployment(resources = { "process/empty.bpmn20.xml" })
public void testRunProcessWithHeader() throws Exception {
    CamelContext ctx = applicationContext.getBean(CamelContext.class);
    ProducerTemplate tpl = camelContext.createProducerTemplate();
    String body = "body text";
    Exchange exchange = ctx.getEndpoint("direct:startEmptyWithHeader").createExchange();
    exchange.getIn().setBody(body);
    tpl.send("direct:startEmptyWithHeader", exchange);
    String instanceId = (String) exchange.getProperty("PROCESS_ID_PROPERTY");
    assertProcessEnded(instanceId);
    HistoricVariableInstance var = processEngine.getHistoryService().createHistoricVariableInstanceQuery().variableName("camelBody").singleResult();
    assertNotNull(var);
    assertEquals(body, var.getValue());
    var = processEngine.getHistoryService().createHistoricVariableInstanceQuery().variableName("MyVar").singleResult();
    assertNotNull(var);
    assertEquals("Foo", var.getValue());
}
Also used : CamelContext(org.apache.camel.CamelContext) Exchange(org.apache.camel.Exchange) ProducerTemplate(org.apache.camel.ProducerTemplate) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) Deployment(org.activiti.engine.test.Deployment)

Example 59 with ProducerTemplate

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

the class EmptyProcessTest method testObjectAsVariable.

@Deployment(resources = { "process/empty.bpmn20.xml" })
public void testObjectAsVariable() throws Exception {
    CamelContext ctx = applicationContext.getBean(CamelContext.class);
    ProducerTemplate tpl = ctx.createProducerTemplate();
    Object expectedObj = new Long(99);
    Exchange exchange = ctx.getEndpoint("direct:startEmpty").createExchange();
    exchange.getIn().setBody(expectedObj);
    tpl.send("direct:startEmpty", exchange);
    String instanceId = (String) exchange.getProperty("PROCESS_ID_PROPERTY");
    assertProcessEnded(instanceId);
    HistoricVariableInstance var = processEngine.getHistoryService().createHistoricVariableInstanceQuery().variableName("camelBody").singleResult();
    assertNotNull(var);
    assertEquals(expectedObj, var.getValue());
}
Also used : CamelContext(org.apache.camel.CamelContext) Exchange(org.apache.camel.Exchange) ProducerTemplate(org.apache.camel.ProducerTemplate) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) Deployment(org.activiti.engine.test.Deployment)

Example 60 with ProducerTemplate

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

the class SimpleProcessTest method testRunProcessByKey.

@Deployment(resources = { "process/example.bpmn20.xml" })
public void testRunProcessByKey() throws Exception {
    CamelContext ctx = applicationContext.getBean(CamelContext.class);
    ProducerTemplate tpl = ctx.createProducerTemplate();
    MockEndpoint me = (MockEndpoint) ctx.getEndpoint("mock:service1");
    me.expectedBodiesReceived("ala");
    tpl.sendBodyAndProperty("direct:start", Collections.singletonMap("var1", "ala"), ActivitiProducer.PROCESS_KEY_PROPERTY, "key1");
    String instanceId = runtimeService.createProcessInstanceQuery().processInstanceBusinessKey("key1").singleResult().getProcessInstanceId();
    tpl.sendBodyAndProperty("direct:receive", null, ActivitiProducer.PROCESS_KEY_PROPERTY, "key1");
    assertProcessEnded(instanceId);
    me.assertIsSatisfied();
}
Also used : CamelContext(org.apache.camel.CamelContext) ProducerTemplate(org.apache.camel.ProducerTemplate) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Deployment(org.activiti.engine.test.Deployment)

Aggregations

ProducerTemplate (org.apache.camel.ProducerTemplate)130 Test (org.junit.Test)58 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)53 CamelContext (org.apache.camel.CamelContext)48 Exchange (org.apache.camel.Exchange)36 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)27 Deployment (org.activiti.engine.test.Deployment)16 RouteBuilder (org.apache.camel.builder.RouteBuilder)16 Processor (org.apache.camel.Processor)8 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)8 HashMap (java.util.HashMap)7 Task (org.activiti.engine.task.Task)7 Endpoint (org.apache.camel.Endpoint)7 File (java.io.File)6 ArrayList (java.util.ArrayList)5 Message (org.apache.camel.Message)4 List (java.util.List)3 ExecutorService (java.util.concurrent.ExecutorService)3 HistoricVariableInstance (org.activiti.engine.history.HistoricVariableInstance)3 ConsumerTemplate (org.apache.camel.ConsumerTemplate)3