use of org.camunda.bpm.engine.form.TaskFormData in project camunda-bpm-platform by camunda.
the class ElResolveTaskFormDataTest method testTaskFormDataWithDefaultValueExpression.
@Test
public void testTaskFormDataWithDefaultValueExpression() {
ProcessInstance instance = runtimeService.startProcessInstanceByKey("elTaskFormProcess");
Task task = taskService.createTaskQuery().processInstanceId(instance.getId()).singleResult();
TaskFormData formData = formService.getTaskFormData(task.getId());
Object defaultValue = formData.getFormFields().get(0).getValue().getValue();
Assert.assertNotNull(defaultValue);
Assert.assertEquals("testString123", defaultValue);
}
use of org.camunda.bpm.engine.form.TaskFormData in project camunda-bpm-platform by camunda.
the class ElResolveTaskFormDataTest method testTaskFormDataWithLabelExpression.
@Test
public void testTaskFormDataWithLabelExpression() {
ProcessInstance instance = runtimeService.startProcessInstanceByKey("elTaskFormProcess");
Task task = taskService.createTaskQuery().processInstanceId(instance.getId()).singleResult();
TaskFormData formData = formService.getTaskFormData(task.getId());
String label = formData.getFormFields().get(0).getLabel();
Assert.assertNotNull(label);
Assert.assertEquals("testString123", label);
}
use of org.camunda.bpm.engine.form.TaskFormData in project camunda-bpm-platform by camunda.
the class FormServiceTest method testFormPropertyHandling.
@Deployment
@Test
public void testFormPropertyHandling() {
Map<String, Object> properties = new HashMap<String, Object>();
// default
properties.put("room", "5b");
// variable name mapping
properties.put("speaker", "Mike");
// type conversion
properties.put("duration", 45L);
// type conversion
properties.put("free", "true");
String procDefId = repositoryService.createProcessDefinitionQuery().singleResult().getId();
String processInstanceId = formService.submitStartForm(procDefId, properties).getId();
Map<String, Object> expectedVariables = new HashMap<String, Object>();
expectedVariables.put("room", "5b");
expectedVariables.put("SpeakerName", "Mike");
expectedVariables.put("duration", new Long(45));
expectedVariables.put("free", Boolean.TRUE);
Map<String, Object> variables = runtimeService.getVariables(processInstanceId);
assertEquals(expectedVariables, variables);
Address address = new Address();
address.setStreet("broadway");
runtimeService.setVariable(processInstanceId, "address", address);
String taskId = taskService.createTaskQuery().singleResult().getId();
TaskFormData taskFormData = formService.getTaskFormData(taskId);
List<FormProperty> formProperties = taskFormData.getFormProperties();
FormProperty propertyRoom = formProperties.get(0);
assertEquals("room", propertyRoom.getId());
assertEquals("5b", propertyRoom.getValue());
FormProperty propertyDuration = formProperties.get(1);
assertEquals("duration", propertyDuration.getId());
assertEquals("45", propertyDuration.getValue());
FormProperty propertySpeaker = formProperties.get(2);
assertEquals("speaker", propertySpeaker.getId());
assertEquals("Mike", propertySpeaker.getValue());
FormProperty propertyStreet = formProperties.get(3);
assertEquals("street", propertyStreet.getId());
assertEquals("broadway", propertyStreet.getValue());
FormProperty propertyFree = formProperties.get(4);
assertEquals("free", propertyFree.getId());
assertEquals("true", propertyFree.getValue());
assertEquals(5, formProperties.size());
try {
formService.submitTaskForm(taskId, new HashMap<String, Object>());
fail("expected exception about required form property 'street'");
} catch (ProcessEngineException e) {
// OK
}
try {
properties = new HashMap<String, Object>();
properties.put("speaker", "its not allowed to update speaker!");
formService.submitTaskForm(taskId, properties);
fail("expected exception about a non writable form property 'speaker'");
} catch (ProcessEngineException e) {
// OK
}
properties = new HashMap<String, Object>();
properties.put("street", "rubensstraat");
formService.submitTaskForm(taskId, properties);
expectedVariables = new HashMap<String, Object>();
expectedVariables.put("room", "5b");
expectedVariables.put("SpeakerName", "Mike");
expectedVariables.put("duration", new Long(45));
expectedVariables.put("free", Boolean.TRUE);
variables = runtimeService.getVariables(processInstanceId);
address = (Address) variables.remove("address");
assertEquals("rubensstraat", address.getStreet());
assertEquals(expectedVariables, variables);
}
use of org.camunda.bpm.engine.form.TaskFormData in project camunda-bpm-platform by camunda.
the class FormServiceTest method testGetTaskFormWithoutLabels.
@Deployment
@Test
public void testGetTaskFormWithoutLabels() {
runtimeService.startProcessInstanceByKey("testProcess");
Task task = taskService.createTaskQuery().singleResult();
// form data can be retrieved
TaskFormData formData = formService.getTaskFormData(task.getId());
List<FormField> formFields = formData.getFormFields();
assertEquals(3, formFields.size());
List<String> formFieldIds = new ArrayList<String>();
for (FormField field : formFields) {
assertNull(field.getLabel());
formFieldIds.add(field.getId());
}
assertTrue(formFieldIds.containsAll(Arrays.asList("stringField", "customField", "longField")));
// the form can be rendered
Object startForm = formService.getRenderedTaskForm(task.getId());
assertNotNull(startForm);
}
use of org.camunda.bpm.engine.form.TaskFormData in project camunda-bpm-platform by camunda.
the class FormDataTest method testMissingFormVariables.
@Deployment
public void testMissingFormVariables() {
// given process definition with defined form varaibles
// when start process instance with no variables
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("date-form-property-test");
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
// then taskFormData contains form variables with null as values
TaskFormData taskFormData = formService.getTaskFormData(task.getId());
assertNotNull(taskFormData);
assertEquals(5, taskFormData.getFormFields().size());
for (FormField field : taskFormData.getFormFields()) {
assertNotNull(field);
assertNull(field.getValue().getValue());
}
}
Aggregations