use of org.camunda.bpm.engine.test.Deployment 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());
}
use of org.camunda.bpm.engine.test.Deployment 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.test.Deployment 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());
}
use of org.camunda.bpm.engine.test.Deployment 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());
}
use of org.camunda.bpm.engine.test.Deployment in project camunda-bpm-platform by camunda.
the class ExecutionIdTest method testExecutionIdInjectableByQualifier.
@Test
@Deployment
public void testExecutionIdInjectableByQualifier() {
getBeanInstance(BusinessProcess.class).startProcessByKey("keyOfTheProcess");
Set<Bean<?>> beans = beanManager.getBeans(String.class, new ExecutionIdLiteral());
Bean<String> bean = (Bean<java.lang.String>) beanManager.resolve(beans);
CreationalContext<String> ctx = beanManager.createCreationalContext(bean);
String executionId = (String) beanManager.getReference(bean, String.class, ctx);
Assert.assertNotNull(executionId);
String processInstanceId = (String) getBeanInstance("processInstanceId");
Assert.assertNotNull(processInstanceId);
assertEquals(processInstanceId, executionId);
}
Aggregations