Search in sources :

Example 6 with CamelContext

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

the class InitiatorCamelCallTest method testInitiatorCamelCall.

@Deployment
public void testInitiatorCamelCall() throws Exception {
    CamelContext ctx = applicationContext.getBean(CamelContext.class);
    ProducerTemplate tpl = ctx.createProducerTemplate();
    String body = "body text";
    Exchange exchange = ctx.getEndpoint("direct:startWithInitiatorHeader").createExchange();
    exchange.getIn().setBody(body);
    tpl.send("direct:startWithInitiatorHeader", exchange);
    String instanceId = (String) exchange.getProperty("PROCESS_ID_PROPERTY");
    String initiator = (String) runtimeService.getVariable(instanceId, "initiator");
    assertEquals("kermit", initiator);
    Object camelInitiatorHeader = runtimeService.getVariable(instanceId, "CamelProcessInitiatorHeader");
    assertNull(camelInitiatorHeader);
}
Also used : CamelContext(org.apache.camel.CamelContext) Exchange(org.apache.camel.Exchange) ProducerTemplate(org.apache.camel.ProducerTemplate) Deployment(org.activiti.engine.test.Deployment)

Example 7 with CamelContext

use of org.apache.camel.CamelContext 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 8 with CamelContext

use of org.apache.camel.CamelContext 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 9 with CamelContext

use of org.apache.camel.CamelContext 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 10 with CamelContext

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

the class CamelBehavior method setAppropriateCamelContext.

protected void setAppropriateCamelContext(ActivityExecution execution) {
    //Check to see if the springConfiguration has been set. If not, set it.
    if (springConfiguration == null) {
        //Get the ProcessEngineConfiguration object.
        ProcessEngineConfiguration engineConfiguration = Context.getProcessEngineConfiguration();
        // (ActivitiException extends RuntimeException.)
        try {
            springConfiguration = (SpringProcessEngineConfiguration) engineConfiguration;
        } catch (Exception e) {
            throw new ActivitiException("Expecting a SpringProcessEngineConfiguration for the Activiti Camel module.", e);
        }
    }
    //Get the appropriate String representation of the CamelContext object from ActivityExecution (if available).
    String camelContextValue = getStringFromField(camelContext, execution);
    //If the String representation of the CamelContext object from ActivityExecution is empty, use the default.
    if (StringUtils.isEmpty(camelContextValue) && camelContextObj != null) {
    //No processing required. No custom CamelContext & the default is already set.
    } else {
        if (StringUtils.isEmpty(camelContextValue) && camelContextObj == null) {
            camelContextValue = springConfiguration.getDefaultCamelContext();
        }
        //Get the CamelContext object and set the super's member variable.
        Object ctx = springConfiguration.getApplicationContext().getBean(camelContextValue);
        if (ctx == null || ctx instanceof CamelContext == false) {
            throw new ActivitiException("Could not find CamelContext named " + camelContextValue + ".");
        }
        camelContextObj = (CamelContext) ctx;
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) ActivitiException(org.activiti.engine.ActivitiException) SpringProcessEngineConfiguration(org.activiti.spring.SpringProcessEngineConfiguration) ProcessEngineConfiguration(org.activiti.engine.ProcessEngineConfiguration) ActivitiException(org.activiti.engine.ActivitiException)

Aggregations

CamelContext (org.apache.camel.CamelContext)1478 Test (org.junit.Test)691 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)684 RouteBuilder (org.apache.camel.builder.RouteBuilder)448 ProducerTemplate (org.apache.camel.ProducerTemplate)434 ConnectionFactory (javax.jms.ConnectionFactory)220 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)210 Exchange (org.apache.camel.Exchange)109 HashMap (java.util.HashMap)93 Endpoint (org.apache.camel.Endpoint)52 DefaultExchange (org.apache.camel.impl.DefaultExchange)50 IOException (java.io.IOException)46 Map (java.util.Map)45 SimpleRegistry (org.apache.camel.impl.SimpleRegistry)44 CountDownLatch (java.util.concurrent.CountDownLatch)42 SpringCamelContext (org.apache.camel.spring.SpringCamelContext)42 ArrayList (java.util.ArrayList)41 Processor (org.apache.camel.Processor)40 PropertiesComponent (org.apache.camel.component.properties.PropertiesComponent)37 CamelExecutionException (org.apache.camel.CamelExecutionException)33