use of org.camunda.bpm.engine.cdi.BusinessProcess in project camunda-bpm-platform by camunda.
the class BusinessProcessBeanTest method testGetCachedLocalVariableMap.
@Test
@Deployment(resources = "org/camunda/bpm/engine/cdi/test/api/BusinessProcessBeanTest.test.bpmn20.xml")
public void testGetCachedLocalVariableMap() {
BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);
// initially the variable cache is empty
assertEquals(Collections.EMPTY_MAP, businessProcess.getCachedLocalVariableMap());
// 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());
}
businessProcess.startProcessByKey("businessProcessBeanTest");
// now the variable cache is empty again:
assertEquals(Collections.EMPTY_MAP, businessProcess.getCachedLocalVariableMap());
// set a variable
businessProcess.setVariableLocal("anotherVariableName", "aVariableValue");
// now the variable is set
assertEquals(Collections.singletonMap("anotherVariableName", "aVariableValue"), businessProcess.getCachedLocalVariableMap());
// getting the variable cache does not empty it:
assertEquals(Collections.singletonMap("anotherVariableName", "aVariableValue"), businessProcess.getCachedLocalVariableMap());
}
use of org.camunda.bpm.engine.cdi.BusinessProcess in project camunda-bpm-platform by camunda.
the class BusinessProcessBeanTest method testResolveProcessInstanceBean.
@Test
@Deployment(resources = "org/camunda/bpm/engine/cdi/test/api/BusinessProcessBeanTest.test.bpmn20.xml")
public void testResolveProcessInstanceBean() {
BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);
assertNull(getBeanInstance(ProcessInstance.class));
assertNull(getBeanInstance("processInstanceId"));
assertNull(getBeanInstance(Execution.class));
assertNull(getBeanInstance("executionId"));
String pid = businessProcess.startProcessByKey("businessProcessBeanTest").getId();
// assert that now we can resolve the ProcessInstance-bean
assertEquals(pid, getBeanInstance(ProcessInstance.class).getId());
assertEquals(pid, getBeanInstance("processInstanceId"));
assertEquals(pid, getBeanInstance(Execution.class).getId());
assertEquals(pid, getBeanInstance("executionId"));
taskService.complete(taskService.createTaskQuery().singleResult().getId());
}
use of org.camunda.bpm.engine.cdi.BusinessProcess in project camunda-bpm-platform by camunda.
the class BusinessProcessBeanTest method testGetAndClearVariableCache.
@Test
@Deployment(resources = "org/camunda/bpm/engine/cdi/test/api/BusinessProcessBeanTest.test.bpmn20.xml")
@SuppressWarnings("deprecation")
public void testGetAndClearVariableCache() {
BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);
// initially the variable cache is empty
assertEquals(Collections.EMPTY_MAP, businessProcess.getAndClearVariableCache());
// set a variable
businessProcess.setVariable("aVariableName", "aVariableValue");
// now the variable is set
assertEquals(Collections.singletonMap("aVariableName", "aVariableValue"), businessProcess.getAndClearVariableCache());
// now the variable cache is empty
assertEquals(Collections.EMPTY_MAP, businessProcess.getAndClearVariableCache());
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());
}
use of org.camunda.bpm.engine.cdi.BusinessProcess in project camunda-bpm-platform by camunda.
the class BusinessProcessBeanTest method testGetVariableLocalCache.
@Test
@Deployment(resources = "org/camunda/bpm/engine/cdi/test/api/BusinessProcessBeanTest.test.bpmn20.xml")
@SuppressWarnings("deprecation")
public void testGetVariableLocalCache() {
BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);
// initially the variable cache is empty
assertEquals(Collections.EMPTY_MAP, businessProcess.getVariableLocalCache());
// 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());
}
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());
// getting the variable cache does not empty it:
assertEquals(Collections.singletonMap("anotherVariableName", "aVariableValue"), businessProcess.getVariableLocalCache());
}
use of org.camunda.bpm.engine.cdi.BusinessProcess in project camunda-bpm-platform by camunda.
the class BusinessProcessBeanTest method test.
/* General test asserting that the business process bean is functional */
@Test
@Deployment
public void test() throws Exception {
BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);
// start the process
businessProcess.startProcessByKey("businessProcessBeanTest").getId();
// ensure that the process is started:
assertNotNull(processEngine.getRuntimeService().createProcessInstanceQuery().singleResult());
// ensure that there is a single task waiting
Task task = processEngine.getTaskService().createTaskQuery().singleResult();
assertNotNull(task);
String value = "value";
businessProcess.setVariable("key", Variables.stringValue(value));
assertEquals(value, businessProcess.getVariable("key"));
// Typed variable API
TypedValue typedValue = businessProcess.getVariableTyped("key");
assertEquals(ValueType.STRING, typedValue.getType());
assertEquals(value, typedValue.getValue());
// Local variables
String localValue = "localValue";
businessProcess.setVariableLocal("localKey", Variables.stringValue(localValue));
assertEquals(localValue, businessProcess.getVariableLocal("localKey"));
// Local typed variable API
TypedValue typedLocalValue = businessProcess.getVariableLocalTyped("localKey");
assertEquals(ValueType.STRING, typedLocalValue.getType());
assertEquals(localValue, typedLocalValue.getValue());
// complete the task
assertEquals(task.getId(), businessProcess.startTask(task.getId()).getId());
businessProcess.completeTask();
// assert the task is completed
assertNull(processEngine.getTaskService().createTaskQuery().singleResult());
// assert that the process is ended:
assertNull(processEngine.getRuntimeService().createProcessInstanceQuery().singleResult());
}
Aggregations