Search in sources :

Example 91 with VariableMap

use of org.camunda.bpm.engine.variable.VariableMap in project camunda-bpm-platform by camunda.

the class RepetitionRuleTest method testDefaultVariableBasedRepetitionRuleEvaluatesToFalse.

@Deployment(resources = "org/camunda/bpm/engine/test/cmmn/repetition/RepetitionRuleTest.testDefaultVariableBasedRule.cmmn")
public void testDefaultVariableBasedRepetitionRuleEvaluatesToFalse() {
    // given
    VariableMap variables = Variables.createVariables().putValue("repeat", false);
    createCaseInstanceByKey("case", variables);
    String humanTask1 = queryCaseExecutionByActivityId("PI_HumanTask_1").getId();
    // when
    complete(humanTask1);
    // then
    CaseExecutionQuery query = caseService.createCaseExecutionQuery().activityId("PI_HumanTask_2");
    assertEquals(1, query.count());
    assertEquals(1, query.active().count());
}
Also used : VariableMap(org.camunda.bpm.engine.variable.VariableMap) CaseExecutionQuery(org.camunda.bpm.engine.runtime.CaseExecutionQuery) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 92 with VariableMap

use of org.camunda.bpm.engine.variable.VariableMap in project camunda-bpm-platform by camunda.

the class MultiInstanceTest method testCatchErrorThrownByExecuteOfParallelDelegateExpression.

@Deployment(resources = { "org/camunda/bpm/engine/test/bpmn/multiinstance/MultiInstanceTest.testCatchErrorThrownByParallelDelegateExpression.bpmn20.xml" })
public void testCatchErrorThrownByExecuteOfParallelDelegateExpression() {
    VariableMap variables = Variables.createVariables().putValue("myDelegate", new ThrowErrorDelegate());
    variables.putAll(throwError());
    String pi = runtimeService.startProcessInstanceByKey("testProcess", variables).getId();
    assertTrue((Boolean) runtimeService.getVariable(pi, "executed"));
    assertNull(runtimeService.getVariable(pi, "signaled"));
    Task userTask = taskService.createTaskQuery().processInstanceId(pi).singleResult();
    assertNotNull(userTask);
    assertEquals("userTaskError", userTask.getTaskDefinitionKey());
    taskService.complete(userTask.getId());
}
Also used : ThrowErrorDelegate(org.camunda.bpm.engine.test.bpmn.event.error.ThrowErrorDelegate) Task(org.camunda.bpm.engine.task.Task) VariableMap(org.camunda.bpm.engine.variable.VariableMap) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 93 with VariableMap

use of org.camunda.bpm.engine.variable.VariableMap in project camunda-bpm-platform by camunda.

the class MultiInstanceTest method testCatchErrorThrownBySignalOfSequentialDelegateExpression.

@Deployment(resources = { "org/camunda/bpm/engine/test/bpmn/multiinstance/MultiInstanceTest.testCatchErrorThrownBySequentialDelegateExpression.bpmn20.xml" })
public void testCatchErrorThrownBySignalOfSequentialDelegateExpression() {
    VariableMap variables = Variables.createVariables().putValue("myDelegate", new ThrowErrorDelegate());
    String pi = runtimeService.startProcessInstanceByKey("testProcess", variables).getId();
    assertTrue((Boolean) runtimeService.getVariable(pi, "executed"));
    assertNull(runtimeService.getVariable(pi, "signaled"));
    // signal 2 times to execute first sequential behaviors
    runtimeService.setVariables(pi, leaveExecution());
    runtimeService.signal(runtimeService.createExecutionQuery().processInstanceId(pi).activityId("serviceTask").singleResult().getId());
    runtimeService.setVariables(pi, leaveExecution());
    runtimeService.signal(runtimeService.createExecutionQuery().processInstanceId(pi).activityId("serviceTask").singleResult().getId());
    Execution serviceTask = runtimeService.createExecutionQuery().processInstanceId(pi).activityId("serviceTask").singleResult();
    assertNotNull(serviceTask);
    runtimeService.setVariables(pi, throwError());
    runtimeService.signal(serviceTask.getId());
    assertTrue((Boolean) runtimeService.getVariable(pi, "executed"));
    assertTrue((Boolean) runtimeService.getVariable(pi, "signaled"));
    Task userTask = taskService.createTaskQuery().processInstanceId(pi).singleResult();
    assertNotNull(userTask);
    assertEquals("userTaskError", userTask.getTaskDefinitionKey());
    taskService.complete(userTask.getId());
}
Also used : ThrowErrorDelegate(org.camunda.bpm.engine.test.bpmn.event.error.ThrowErrorDelegate) Task(org.camunda.bpm.engine.task.Task) ThrowErrorDelegate.leaveExecution(org.camunda.bpm.engine.test.bpmn.event.error.ThrowErrorDelegate.leaveExecution) Execution(org.camunda.bpm.engine.runtime.Execution) VariableMap(org.camunda.bpm.engine.variable.VariableMap) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 94 with VariableMap

use of org.camunda.bpm.engine.variable.VariableMap in project camunda-bpm-platform by camunda.

the class RetryIntervalsConfigurationTest method testlocalConfigurationWithNestedChangingExpression.

@Test
public void testlocalConfigurationWithNestedChangingExpression() throws ParseException {
    BpmnModelInstance bpmnModelInstance = Bpmn.createExecutableProcess("process").startEvent().serviceTask().camundaClass("foo").camundaAsyncBefore().camundaFailedJobRetryTimeCycle("${var}").endEvent().done();
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    Date startDate = simpleDateFormat.parse("2017-01-01T09:55:00");
    ClockUtil.setCurrentTime(startDate);
    testRule.deploy(bpmnModelInstance);
    VariableMap params = Variables.createVariables();
    params.putValue("var", "${nestedVar1},PT15M,${nestedVar3}");
    params.putValue("nestedVar", "PT13M");
    params.putValue("nestedVar1", "PT5M");
    params.putValue("nestedVar3", "PT25M");
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("process", params);
    ClockUtil.setCurrentTime(SIMPLE_DATE_FORMAT.parse("2017-01-01T09:55:00"));
    assertNotNull(pi);
    Date currentTime = SIMPLE_DATE_FORMAT.parse("2017-01-01T10:00:00");
    ClockUtil.setCurrentTime(currentTime);
    String processInstanceId = pi.getProcessInstanceId();
    int jobRetries = executeJob(processInstanceId);
    assertEquals(3, jobRetries);
    currentTime = DateUtils.addMinutes(currentTime, 5);
    assertLockExpirationTime(currentTime);
    ClockUtil.setCurrentTime(currentTime);
    jobRetries = executeJob(processInstanceId);
    assertEquals(2, jobRetries);
    currentTime = DateUtils.addMinutes(currentTime, 15);
    assertLockExpirationTime(currentTime);
    ClockUtil.setCurrentTime(currentTime);
    runtimeService.setVariable(pi.getProcessInstanceId(), "var", "${nestedVar}");
    jobRetries = executeJob(processInstanceId);
    assertEquals(1, jobRetries);
    currentTime = DateUtils.addMinutes(currentTime, 13);
    assertLockExpirationTime(currentTime);
    ClockUtil.setCurrentTime(currentTime);
    jobRetries = executeJob(processInstanceId);
    assertEquals(0, jobRetries);
}
Also used : VariableMap(org.camunda.bpm.engine.variable.VariableMap) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) AbstractAsyncOperationsTest(org.camunda.bpm.engine.test.api.AbstractAsyncOperationsTest) Test(org.junit.Test)

Example 95 with VariableMap

use of org.camunda.bpm.engine.variable.VariableMap in project camunda-bpm-platform by camunda.

the class InvoiceTestCase method testApproveInvoiceAssignment.

@Deployment(resources = { "invoice.v2.bpmn", "invoiceBusinessDecisions.dmn" })
public void testApproveInvoiceAssignment() {
    InputStream invoiceInputStream = InvoiceProcessApplication.class.getClassLoader().getResourceAsStream("invoice.pdf");
    VariableMap variables = Variables.createVariables().putValue("creditor", "Great Pizza for Everyone Inc.").putValue("amount", 300.0d).putValue("invoiceCategory", "Travel Expenses").putValue("invoiceNumber", "GPFE-23232323").putValue("invoiceDocument", fileValue("invoice.pdf").file(invoiceInputStream).mimeType("application/pdf").create()).putValue("approverGroups", Arrays.asList("sales", "accounting"));
    ProcessInstance pi = runtimeService.createProcessInstanceByKey("invoice").setVariables(variables).startBeforeActivity("approveInvoice").execute();
    // givent that the process instance is waiting at task "approveInvoice"
    Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
    assertEquals("approveInvoice", task.getTaskDefinitionKey());
    // and task has candidate groups
    List<IdentityLink> links = taskService.getIdentityLinksForTask(task.getId());
    Set<String> approverGroups = new HashSet<String>();
    for (IdentityLink link : links) {
        approverGroups.add(link.getGroupId());
    }
    assertEquals(2, approverGroups.size());
    assertTrue(approverGroups.contains("accounting"));
    assertTrue(approverGroups.contains("sales"));
    // and variable approver is null
    assertNull(taskService.getVariable(task.getId(), "approver"));
    // if mary claims the task
    taskService.claim(task.getId(), "mary");
    // then the variable "approver" exists and is set to mary
    assertEquals("mary", taskService.getVariable(task.getId(), "approver"));
}
Also used : Task(org.camunda.bpm.engine.task.Task) VariableMap(org.camunda.bpm.engine.variable.VariableMap) InputStream(java.io.InputStream) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) IdentityLink(org.camunda.bpm.engine.task.IdentityLink) HashSet(java.util.HashSet) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

VariableMap (org.camunda.bpm.engine.variable.VariableMap)228 Deployment (org.camunda.bpm.engine.test.Deployment)107 Test (org.junit.Test)57 Task (org.camunda.bpm.engine.task.Task)38 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)32 VariableInstance (org.camunda.bpm.engine.runtime.VariableInstance)30 VariableMapImpl (org.camunda.bpm.engine.variable.impl.VariableMapImpl)15 CaseExecutionEntity (org.camunda.bpm.engine.impl.cmmn.entity.runtime.CaseExecutionEntity)13 BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)13 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)12 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)12 HashMap (java.util.HashMap)11 ProcessInstanceWithVariables (org.camunda.bpm.engine.runtime.ProcessInstanceWithVariables)9 LockedExternalTask (org.camunda.bpm.engine.externaltask.LockedExternalTask)8 HistoricVariableInstance (org.camunda.bpm.engine.history.HistoricVariableInstance)8 RestException (org.camunda.bpm.engine.rest.exception.RestException)8 CaseExecutionQuery (org.camunda.bpm.engine.runtime.CaseExecutionQuery)8 Execution (org.camunda.bpm.engine.runtime.Execution)8 CaseExecution (org.camunda.bpm.engine.runtime.CaseExecution)7 ThrowErrorDelegate (org.camunda.bpm.engine.test.bpmn.event.error.ThrowErrorDelegate)7