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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations