Search in sources :

Example 16 with TaskFormData

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);
}
Also used : Task(org.camunda.bpm.engine.task.Task) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) TaskFormData(org.camunda.bpm.engine.form.TaskFormData) AbstractFoxPlatformIntegrationTest(org.camunda.bpm.integrationtest.util.AbstractFoxPlatformIntegrationTest) Test(org.junit.Test)

Example 17 with TaskFormData

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);
}
Also used : Task(org.camunda.bpm.engine.task.Task) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) TaskFormData(org.camunda.bpm.engine.form.TaskFormData) AbstractFoxPlatformIntegrationTest(org.camunda.bpm.integrationtest.util.AbstractFoxPlatformIntegrationTest) Test(org.junit.Test)

Example 18 with TaskFormData

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);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FormProperty(org.camunda.bpm.engine.form.FormProperty) TaskFormData(org.camunda.bpm.engine.form.TaskFormData) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 19 with TaskFormData

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);
}
Also used : Task(org.camunda.bpm.engine.task.Task) ArrayList(java.util.ArrayList) TaskFormData(org.camunda.bpm.engine.form.TaskFormData) FormField(org.camunda.bpm.engine.form.FormField) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 20 with TaskFormData

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());
    }
}
Also used : Task(org.camunda.bpm.engine.task.Task) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) TaskFormData(org.camunda.bpm.engine.form.TaskFormData) FormField(org.camunda.bpm.engine.form.FormField) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

TaskFormData (org.camunda.bpm.engine.form.TaskFormData)26 Task (org.camunda.bpm.engine.task.Task)10 Deployment (org.camunda.bpm.engine.test.Deployment)10 Test (org.junit.Test)9 FormField (org.camunda.bpm.engine.form.FormField)8 FormProperty (org.camunda.bpm.engine.form.FormProperty)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)4 LinkedHashMap (java.util.LinkedHashMap)3 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)2 FormType (org.camunda.bpm.engine.form.FormType)2 TaskEntity (org.camunda.bpm.engine.impl.persistence.entity.TaskEntity)2 TaskManager (org.camunda.bpm.engine.impl.persistence.entity.TaskManager)2 AbstractFoxPlatformIntegrationTest (org.camunda.bpm.integrationtest.util.AbstractFoxPlatformIntegrationTest)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 ProcessApplicationService (org.camunda.bpm.ProcessApplicationService)1