Search in sources :

Example 1 with BusinessProcess

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

the class BusinessProcessBeanTest method testGetCachedVariableMap.

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

Example 2 with BusinessProcess

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

the class BusinessProcessBeanTest method testGetAndClearCachedLocalVariableMap.

@Test
@Deployment(resources = "org/camunda/bpm/engine/cdi/test/api/BusinessProcessBeanTest.test.bpmn20.xml")
public void testGetAndClearCachedLocalVariableMap() {
    BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);
    // initially the variable cache is empty
    assertEquals(Collections.EMPTY_MAP, businessProcess.getAndClearCachedLocalVariableMap());
    // 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.getAndClearCachedLocalVariableMap());
    businessProcess.startProcessByKey("businessProcessBeanTest");
    // now the variable cache is empty again:
    assertEquals(Collections.EMPTY_MAP, businessProcess.getAndClearCachedLocalVariableMap());
    // set a variable
    businessProcess.setVariableLocal("anotherVariableName", "aVariableValue");
    // now the variable is set
    assertEquals(Collections.singletonMap("anotherVariableName", "aVariableValue"), businessProcess.getAndClearCachedLocalVariableMap());
}
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 3 with BusinessProcess

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

the class BusinessProcessBeanTest method testFlushVariableCache.

@Test
@Deployment(resources = "org/camunda/bpm/engine/cdi/test/api/BusinessProcessBeanTest.test.bpmn20.xml")
public void testFlushVariableCache() {
    BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);
    // cannot flush variable cache in absence of an association:
    try {
        businessProcess.flushVariableCache();
        fail("exception expected!");
    } catch (ProcessEngineCdiException e) {
        assertEquals("Cannot flush variable cache: neither a Task nor an Execution is associated.", e.getMessage());
    }
    businessProcess.startProcessByKey("businessProcessBeanTest");
    // set a variable
    businessProcess.setVariable("aVariableName", "aVariable");
    // the variable is not yet present in the execution:
    assertNull(runtimeService.getVariable(businessProcess.getExecutionId(), "aVariableName"));
    // set a local variable
    businessProcess.setVariableLocal("aVariableLocalName", "aVariableLocal");
    // the local variable is not yet present in the execution:
    assertNull(runtimeService.getVariable(businessProcess.getExecutionId(), "aVariableLocalName"));
    // flush the cache
    businessProcess.flushVariableCache();
    // the variable is flushed to the execution
    assertNotNull(runtimeService.getVariable(businessProcess.getExecutionId(), "aVariableName"));
    // the local variable is flushed to the execution
    assertNotNull(runtimeService.getVariable(businessProcess.getExecutionId(), "aVariableLocalName"));
    // the cache is empty
    assertEquals(Collections.EMPTY_MAP, businessProcess.getCachedVariableMap());
    // the cache is empty
    assertEquals(Collections.EMPTY_MAP, businessProcess.getCachedLocalVariableMap());
}
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 4 with BusinessProcess

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

the class BusinessProcessBeanTest method testStopTask.

@Test
@Deployment(resources = "org/camunda/bpm/engine/cdi/test/api/BusinessProcessBeanTest.test.bpmn20.xml")
public void testStopTask() {
    BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);
    // cannot stop task in absence of an association:
    try {
        businessProcess.stopTask();
        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");
    // if we stop the task
    businessProcess.stopTask();
    // THEN
    // assignee is not set to jonny
    assertNull(taskService.createTaskQuery().taskAssignee("jonny").singleResult());
    // business process is not associated with task:
    assertFalse(businessProcess.isTaskAssociated());
    assertFalse(businessProcess.isAssociated());
}
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 5 with BusinessProcess

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

the class BusinessProcessBeanTest method testGetVariableCache.

@Test
@Deployment(resources = "org/camunda/bpm/engine/cdi/test/api/BusinessProcessBeanTest.test.bpmn20.xml")
@SuppressWarnings("deprecation")
public void testGetVariableCache() {
    BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);
    // initially the variable cache is empty
    assertEquals(Collections.EMPTY_MAP, businessProcess.getVariableCache());
    // set a variable
    businessProcess.setVariable("aVariableName", "aVariableValue");
    // now the variable is set
    assertEquals(Collections.singletonMap("aVariableName", "aVariableValue"), businessProcess.getVariableCache());
    // getting the variable cache does not empty it:
    assertEquals(Collections.singletonMap("aVariableName", "aVariableValue"), businessProcess.getVariableCache());
    businessProcess.startProcessByKey("businessProcessBeanTest");
    // now the variable cache is empty again:
    assertEquals(Collections.EMPTY_MAP, businessProcess.getVariableCache());
    // set a variable
    businessProcess.setVariable("anotherVariableName", "aVariableValue");
    // now the variable is set
    assertEquals(Collections.singletonMap("anotherVariableName", "aVariableValue"), businessProcess.getVariableCache());
}
Also used : 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