use of org.camunda.bpm.engine.cdi.ProcessEngineCdiException 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.ProcessEngineCdiException 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.ProcessEngineCdiException 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.ProcessEngineCdiException 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());
}
use of org.camunda.bpm.engine.cdi.ProcessEngineCdiException 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());
}
Aggregations