Search in sources :

Example 41 with ProcessInstance

use of org.camunda.bpm.engine.runtime.ProcessInstance in project camunda-bpm-platform by camunda.

the class ScopingTest method run.

/**
 * this code instantiates a business process that in turn delegates to a few Spring beans that in turn inject a process scoped object, {@link StatefulObject}.
 *
 * @return the StatefulObject that was injected across different components, that all share the same state.
 * @throws Throwable if anythign goes wrong
 */
private StatefulObject run() throws Throwable {
    logger.info("----------------------------------------------");
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put(customerIdProcVarName, CUSTOMER_ID_PROC_VAR_VALUE);
    ProcessInstance processInstance = processEngine.getRuntimeService().startProcessInstanceByKey("component-waiter", vars);
    StatefulObject scopedObject = (StatefulObject) processEngine.getRuntimeService().getVariable(processInstance.getId(), "scopedTarget.c1");
    Assert.assertNotNull("the scopedObject can't be null", scopedObject);
    Assert.assertTrue("the 'name' property can't be null.", StringUtils.hasText(scopedObject.getName()));
    Assert.assertEquals(scopedObject.getVisitedCount(), 2);
    // the process has paused
    String procId = processInstance.getProcessInstanceId();
    List<Task> tasks = taskService.createTaskQuery().executionId(procId).list();
    Assert.assertEquals("there should be 1 (one) task enqueued at this point.", tasks.size(), 1);
    Task t = tasks.iterator().next();
    this.taskService.claim(t.getId(), "me");
    logger.info("sleeping for 10 seconds while a user performs his task. " + "The first transaction has committed. A new one will start in 10 seconds");
    Thread.sleep(1000 * 5);
    this.taskService.complete(t.getId());
    scopedObject = (StatefulObject) processEngine.getRuntimeService().getVariable(processInstance.getId(), "scopedTarget.c1");
    Assert.assertEquals(scopedObject.getVisitedCount(), 3);
    Assert.assertEquals("the customerId injected should " + "be what was given as a processVariable parameter.", ScopingTest.CUSTOMER_ID_PROC_VAR_VALUE, scopedObject.getCustomerId());
    return scopedObject;
}
Also used : Task(org.camunda.bpm.engine.task.Task) HashMap(java.util.HashMap) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance)

Example 42 with ProcessInstance

use of org.camunda.bpm.engine.runtime.ProcessInstance in project camunda-bpm-platform by camunda.

the class JPASpringTest method testJpaVariableHappyPath.

@Deployment(resources = { "org/camunda/bpm/engine/spring/test/jpa/JPASpringTest.bpmn20.xml" })
public void testJpaVariableHappyPath() {
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("customerName", "John Doe");
    variables.put("amount", 15000L);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("LoanRequestProcess", variables);
    // Variable should be present containing the loanRequest created by the spring bean
    Object value = runtimeService.getVariable(processInstance.getId(), "loanRequest");
    assertNotNull(value);
    assertTrue(value instanceof LoanRequest);
    LoanRequest request = (LoanRequest) value;
    assertEquals("John Doe", request.getCustomerName());
    assertEquals(15000L, request.getAmount().longValue());
    assertFalse(request.isApproved());
    // We will approve the request, which will update the entity
    variables = new HashMap<String, Object>();
    variables.put("approvedByManager", Boolean.TRUE);
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(task);
    taskService.complete(task.getId(), variables);
    // If approved, the processsInstance should be finished, gateway based on loanRequest.approved value
    assertEquals(0, runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId()).count());
}
Also used : Task(org.camunda.bpm.engine.task.Task) HashMap(java.util.HashMap) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 43 with ProcessInstance

use of org.camunda.bpm.engine.runtime.ProcessInstance in project camunda-bpm-platform by camunda.

the class ProcessStartingMethodInterceptor method invoke.

public Object invoke(MethodInvocation invocation) throws Throwable {
    Method method = invocation.getMethod();
    StartProcess startProcess = AnnotationUtils.getAnnotation(method, StartProcess.class);
    String processKey = startProcess.processKey();
    Assert.hasText(processKey, "you must provide the name of process to start");
    Object result;
    try {
        result = invocation.proceed();
        Map<String, Object> vars = this.processVariablesFromAnnotations(invocation);
        String businessKey = this.processBusinessKey(invocation);
        log.info("variables for the started process: " + vars.toString());
        RuntimeService runtimeService = this.processEngine.getRuntimeService();
        ProcessInstance pi;
        if (null != businessKey && StringUtils.hasText(businessKey)) {
            pi = runtimeService.startProcessInstanceByKey(processKey, businessKey, vars);
            log.info("the business key for the started process is '" + businessKey + "' ");
        } else {
            pi = runtimeService.startProcessInstanceByKey(processKey, vars);
        }
        String pId = pi.getId();
        if (invocation.getMethod().getReturnType().equals(void.class))
            return null;
        if (shouldReturnProcessInstance(startProcess, invocation, result))
            return pi;
        if (shouldReturnProcessInstanceId(startProcess, invocation, result))
            return pId;
        if (shouldReturnAsyncResultWithProcessInstance(startProcess, invocation, result)) {
            return new AsyncResult<ProcessInstance>(pi);
        }
    } catch (Throwable th) {
        throw new RuntimeException(th);
    }
    return result;
}
Also used : RuntimeService(org.camunda.bpm.engine.RuntimeService) StartProcess(org.camunda.bpm.engine.spring.annotations.StartProcess) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Method(java.lang.reflect.Method) AsyncResult(org.springframework.scheduling.annotation.AsyncResult)

Example 44 with ProcessInstance

use of org.camunda.bpm.engine.runtime.ProcessInstance in project camunda-bpm-platform by camunda.

the class ServiceTaskSpringDelegationTest method testDelegateClassNotABean.

@Deployment
public void testDelegateClassNotABean() {
    ProcessInstance procInst = runtimeService.startProcessInstanceByKey("delegateClassToSpringBean");
    assertEquals("DelegateClassNotABean was called", runtimeService.getVariable(procInst.getId(), "message"));
    assertTrue((Boolean) runtimeService.getVariable(procInst.getId(), "injectedFieldIsNull"));
}
Also used : ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 45 with ProcessInstance

use of org.camunda.bpm.engine.runtime.ProcessInstance in project camunda-bpm-platform by camunda.

the class ServiceTaskSpringDelegationTest method testMethodExpressionOnSpringBean.

@Deployment
public void testMethodExpressionOnSpringBean() {
    ProcessInstance procInst = runtimeService.startProcessInstanceByKey("methodExpressionOnSpringBean");
    assertEquals("ACTIVITI BPMN 2.0 PROCESS ENGINE", runtimeService.getVariable(procInst.getId(), "myVar"));
}
Also used : ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)2392 Deployment (org.camunda.bpm.engine.test.Deployment)1325 Test (org.junit.Test)1168 Task (org.camunda.bpm.engine.task.Task)660 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)415 ActivityInstance (org.camunda.bpm.engine.runtime.ActivityInstance)372 MigrationPlan (org.camunda.bpm.engine.migration.MigrationPlan)272 BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)258 HashMap (java.util.HashMap)235 TaskQuery (org.camunda.bpm.engine.task.TaskQuery)230 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)203 Job (org.camunda.bpm.engine.runtime.Job)189 ScenarioUnderTest (org.camunda.bpm.qa.upgrade.ScenarioUnderTest)184 ExecutionTree (org.camunda.bpm.engine.test.util.ExecutionTree)149 Execution (org.camunda.bpm.engine.runtime.Execution)144 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)130 ExecutionAssert.describeExecutionTree (org.camunda.bpm.engine.test.util.ExecutionAssert.describeExecutionTree)129 VariableInstance (org.camunda.bpm.engine.runtime.VariableInstance)122 HistoricActivityInstance (org.camunda.bpm.engine.history.HistoricActivityInstance)86 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)84