Search in sources :

Example 6 with BusinessProcess

use of org.camunda.bpm.engine.cdi.BusinessProcess in project camunda-bpm-platform by camunda.

the class BusinessProcessBeanTest method testGetAndClearCachedVariableMap.

@Test
@Deployment(resources = "org/camunda/bpm/engine/cdi/test/api/BusinessProcessBeanTest.test.bpmn20.xml")
public void testGetAndClearCachedVariableMap() {
    BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);
    // initially the variable cache is empty
    assertEquals(Collections.EMPTY_MAP, businessProcess.getAndClearCachedVariableMap());
    // set a variable
    businessProcess.setVariable("aVariableName", "aVariableValue");
    // now the variable is set
    assertEquals(Collections.singletonMap("aVariableName", "aVariableValue"), businessProcess.getAndClearCachedVariableMap());
    // now the variable cache is empty
    assertEquals(Collections.EMPTY_MAP, businessProcess.getAndClearCachedVariableMap());
    businessProcess.startProcessByKey("businessProcessBeanTest");
    // now the variable cache is empty again:
    assertEquals(Collections.EMPTY_MAP, businessProcess.getAndClearCachedVariableMap());
    // set a variable
    businessProcess.setVariable("anotherVariableName", "aVariableValue");
    // now the variable is set
    assertEquals(Collections.singletonMap("anotherVariableName", "aVariableValue"), businessProcess.getAndClearCachedVariableMap());
}
Also used : BusinessProcess(org.camunda.bpm.engine.cdi.BusinessProcess) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 7 with BusinessProcess

use of org.camunda.bpm.engine.cdi.BusinessProcess in project camunda-bpm-platform by camunda.

the class BusinessProcessBeanTest method testSaveTask.

@Test
@Deployment(resources = "org/camunda/bpm/engine/cdi/test/api/BusinessProcessBeanTest.test.bpmn20.xml")
public void testSaveTask() {
    BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);
    // cannot save task in absence of an association:
    try {
        businessProcess.saveTask();
        fail();
    } catch (ProcessEngineCdiException e) {
        assertEquals("No task associated. Call businessProcess.startTask() first.", e.getMessage());
    }
    // start the process
    String processInstanceId = businessProcess.startProcessByKey("businessProcessBeanTest", Collections.singletonMap("key", (Object) "value")).getId();
    assertEquals("value", runtimeService.getVariable(processInstanceId, "key"));
    businessProcess.startTask(taskService.createTaskQuery().singleResult().getId());
    // assignee is not set to jonny
    assertNull(taskService.createTaskQuery().taskAssignee("jonny").singleResult());
    Task task = businessProcess.getTask();
    task.setAssignee("jonny");
    assertNull(taskService.createTaskQuery().taskAssignee("jonny").singleResult());
    // if we save the task
    businessProcess.saveTask();
    // THEN
    // assignee is now set to jonny
    assertNotNull(taskService.createTaskQuery().taskAssignee("jonny").singleResult());
    // business process is still associated with task:
    assertTrue(businessProcess.isTaskAssociated());
}
Also used : ProcessEngineCdiException(org.camunda.bpm.engine.cdi.ProcessEngineCdiException) Task(org.camunda.bpm.engine.task.Task) BusinessProcess(org.camunda.bpm.engine.cdi.BusinessProcess) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 8 with BusinessProcess

use of org.camunda.bpm.engine.cdi.BusinessProcess in project camunda-bpm-platform by camunda.

the class BusinessProcessBeanTest method testGetAndClearVariableLocalCache.

@Test
@Deployment(resources = "org/camunda/bpm/engine/cdi/test/api/BusinessProcessBeanTest.test.bpmn20.xml")
@SuppressWarnings("deprecation")
public void testGetAndClearVariableLocalCache() {
    BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);
    // initially the variable cache is empty
    assertEquals(Collections.EMPTY_MAP, businessProcess.getAndClearVariableLocalCache());
    // set a variable - this should fail before the process is started
    try {
        businessProcess.setVariableLocal("aVariableName", "aVariableValue");
        fail("exception expected!");
    } catch (ProcessEngineCdiException e) {
        assertEquals("Cannot set a local cached variable: neither a Task nor an Execution is associated.", e.getMessage());
    }
    // the variable cache is still empty
    assertEquals(Collections.EMPTY_MAP, businessProcess.getAndClearVariableLocalCache());
    businessProcess.startProcessByKey("businessProcessBeanTest");
    // now the variable cache is empty again:
    assertEquals(Collections.EMPTY_MAP, businessProcess.getVariableLocalCache());
    // set a variable
    businessProcess.setVariableLocal("anotherVariableName", "aVariableValue");
    // now the variable is set
    assertEquals(Collections.singletonMap("anotherVariableName", "aVariableValue"), businessProcess.getVariableLocalCache());
}
Also used : ProcessEngineCdiException(org.camunda.bpm.engine.cdi.ProcessEngineCdiException) BusinessProcess(org.camunda.bpm.engine.cdi.BusinessProcess) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 9 with BusinessProcess

use of org.camunda.bpm.engine.cdi.BusinessProcess in project camunda-bpm-platform by camunda.

the class ProcessVariableMapTest method testProcessVariableMapLocal.

@Test
@Deployment(resources = "org/camunda/bpm/engine/cdi/test/api/BusinessProcessBeanTest.test.bpmn20.xml")
public void testProcessVariableMapLocal() {
    BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);
    businessProcess.startProcessByKey("businessProcessBeanTest");
    VariableMap variables = (VariableMap) getBeanInstance("processVariableMapLocal");
    assertNotNull(variables);
    // /////////////////////////////////////////////////////////////////
    // Put a variable via BusinessProcess and get it via VariableMap //
    // /////////////////////////////////////////////////////////////////
    String aValue = "aValue";
    businessProcess.setVariableLocal(VARNAME_1, Variables.stringValue(aValue));
    // Legacy API
    assertEquals(aValue, variables.get(VARNAME_1));
    // Typed variable API
    TypedValue aTypedValue = variables.getValueTyped(VARNAME_1);
    assertEquals(ValueType.STRING, aTypedValue.getType());
    assertEquals(aValue, aTypedValue.getValue());
    assertEquals(aValue, variables.getValue(VARNAME_1, String.class));
    // Type API with wrong type
    try {
        variables.getValue(VARNAME_1, Integer.class);
        fail("ClassCastException expected!");
    } catch (ClassCastException ex) {
        assertEquals("Cannot cast variable named 'aVariable' with value 'aValue' to type 'class java.lang.Integer'.", ex.getMessage());
    }
    // /////////////////////////////////////////////////////////////////
    // Put a variable via VariableMap and get it via BusinessProcess //
    // /////////////////////////////////////////////////////////////////
    String anotherValue = "anotherValue";
    variables.put(VARNAME_2, Variables.stringValue(anotherValue));
    // Legacy API
    assertEquals(anotherValue, businessProcess.getVariableLocal(VARNAME_2));
    // Typed variable API
    TypedValue anotherTypedValue = businessProcess.getVariableLocalTyped(VARNAME_2);
    assertEquals(ValueType.STRING, anotherTypedValue.getType());
    assertEquals(anotherValue, anotherTypedValue.getValue());
}
Also used : VariableMap(org.camunda.bpm.engine.variable.VariableMap) BusinessProcess(org.camunda.bpm.engine.cdi.BusinessProcess) TypedValue(org.camunda.bpm.engine.variable.value.TypedValue) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 10 with BusinessProcess

use of org.camunda.bpm.engine.cdi.BusinessProcess in project camunda-bpm-platform by camunda.

the class CompleteTaskTest method testCompleteTask.

@Test
@Deployment(resources = "org/camunda/bpm/engine/cdi/test/api/annotation/CompleteTaskTest.bpmn20.xml")
public void testCompleteTask() {
    BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);
    businessProcess.startProcessByKey("keyOfTheProcess");
    Task task = taskService.createTaskQuery().singleResult();
    // associate current unit of work with the task:
    businessProcess.startTask(task.getId());
    getBeanInstance(DeclarativeProcessController.class).completeTask();
    // assert that now the task is completed
    assertNull(taskService.createTaskQuery().singleResult());
}
Also used : Task(org.camunda.bpm.engine.task.Task) DeclarativeProcessController(org.camunda.bpm.engine.cdi.test.impl.beans.DeclarativeProcessController) BusinessProcess(org.camunda.bpm.engine.cdi.BusinessProcess) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

BusinessProcess (org.camunda.bpm.engine.cdi.BusinessProcess)28 Test (org.junit.Test)26 Deployment (org.camunda.bpm.engine.test.Deployment)25 ProcessEngineCdiException (org.camunda.bpm.engine.cdi.ProcessEngineCdiException)7 Task (org.camunda.bpm.engine.task.Task)6 TypedValue (org.camunda.bpm.engine.variable.value.TypedValue)6 DeclarativeProcessController (org.camunda.bpm.engine.cdi.test.impl.beans.DeclarativeProcessController)4 VariableMap (org.camunda.bpm.engine.variable.VariableMap)4 StringValue (org.camunda.bpm.engine.variable.value.StringValue)3 Bean (javax.enterprise.inject.spi.Bean)2 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)2 HashMap (java.util.HashMap)1 TaskService (org.camunda.bpm.engine.TaskService)1 CreditCard (org.camunda.bpm.engine.cdi.test.impl.beans.CreditCard)1 Execution (org.camunda.bpm.engine.runtime.Execution)1 Ignore (org.junit.Ignore)1