Search in sources :

Example 6 with TaskFormData

use of org.camunda.bpm.engine.form.TaskFormData in project camunda-bpm-platform by camunda.

the class FormAuthorizationTest method testProcessTaskGetTaskFormData.

public void testProcessTaskGetTaskFormData() {
    // given
    startProcessInstanceByKey(FORM_PROCESS_KEY);
    String taskId = selectSingleTask().getId();
    createGrantAuthorization(TASK, taskId, userId, READ);
    createGrantAuthorization(PROCESS_DEFINITION, FORM_PROCESS_KEY, userId, READ_TASK);
    // when
    TaskFormData taskFormData = formService.getTaskFormData(taskId);
    // then
    assertNotNull(taskFormData);
}
Also used : TaskFormData(org.camunda.bpm.engine.form.TaskFormData)

Example 7 with TaskFormData

use of org.camunda.bpm.engine.form.TaskFormData in project camunda-bpm-platform by camunda.

the class DelegationAuthorizationTest method testCustomTaskFormHandlerExecutesQuery.

@Deployment
public void testCustomTaskFormHandlerExecutesQuery() {
    // given
    startProcessInstancesByKey(DEFAULT_PROCESS_KEY, 5);
    String taskId = selectAnyTask().getId();
    createGrantAuthorization(TASK, taskId, userId, READ);
    // when
    TaskFormData taskFormData = formService.getTaskFormData(taskId);
    // then
    assertNotNull(taskFormData);
    assertNotNull(MyDelegationService.CURRENT_AUTHENTICATION);
    assertEquals(userId, MyDelegationService.CURRENT_AUTHENTICATION.getUserId());
    assertEquals(Long.valueOf(5), MyDelegationService.INSTANCES_COUNT);
}
Also used : TaskFormData(org.camunda.bpm.engine.form.TaskFormData) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 8 with TaskFormData

use of org.camunda.bpm.engine.form.TaskFormData in project camunda-bpm-platform by camunda.

the class FormPropertyDefaultValueTest method testDefaultValue.

@Deployment
public void testDefaultValue() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("FormPropertyDefaultValueTest.testDefaultValue");
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    TaskFormData formData = formService.getTaskFormData(task.getId());
    List<FormProperty> formProperties = formData.getFormProperties();
    assertEquals(4, formProperties.size());
    for (FormProperty prop : formProperties) {
        if ("booleanProperty".equals(prop.getId())) {
            assertEquals("true", prop.getValue());
        } else if ("stringProperty".equals(prop.getId())) {
            assertEquals("someString", prop.getValue());
        } else if ("longProperty".equals(prop.getId())) {
            assertEquals("42", prop.getValue());
        } else if ("longExpressionProperty".equals(prop.getId())) {
            assertEquals("23", prop.getValue());
        } else {
            assertTrue("Invalid form property: " + prop.getId(), false);
        }
    }
    Map<String, String> formDataUpdate = new HashMap<String, String>();
    formDataUpdate.put("longExpressionProperty", "1");
    formDataUpdate.put("booleanProperty", "false");
    formService.submitTaskFormData(task.getId(), formDataUpdate);
    assertEquals(false, runtimeService.getVariable(processInstance.getId(), "booleanProperty"));
    assertEquals("someString", runtimeService.getVariable(processInstance.getId(), "stringProperty"));
    assertEquals(42L, runtimeService.getVariable(processInstance.getId(), "longProperty"));
    assertEquals(1L, runtimeService.getVariable(processInstance.getId(), "longExpressionProperty"));
}
Also used : Task(org.camunda.bpm.engine.task.Task) FormProperty(org.camunda.bpm.engine.form.FormProperty) HashMap(java.util.HashMap) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) TaskFormData(org.camunda.bpm.engine.form.TaskFormData) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 9 with TaskFormData

use of org.camunda.bpm.engine.form.TaskFormData in project camunda-bpm-platform by camunda.

the class FormServiceTest method testTaskFormPropertyDefaultsAndFormRendering.

@Test
public void testTaskFormPropertyDefaultsAndFormRendering() {
    final String deploymentId = testRule.deploy("org/camunda/bpm/engine/test/api/form/FormsProcess.bpmn20.xml", "org/camunda/bpm/engine/test/api/form/start.form", "org/camunda/bpm/engine/test/api/form/task.form").getId();
    String procDefId = repositoryService.createProcessDefinitionQuery().singleResult().getId();
    StartFormData startForm = formService.getStartFormData(procDefId);
    assertNotNull(startForm);
    assertEquals(deploymentId, startForm.getDeploymentId());
    assertEquals("org/camunda/bpm/engine/test/api/form/start.form", startForm.getFormKey());
    assertEquals(new ArrayList<FormProperty>(), startForm.getFormProperties());
    assertEquals(procDefId, startForm.getProcessDefinition().getId());
    Object renderedStartForm = formService.getRenderedStartForm(procDefId, "juel");
    assertEquals("start form content", renderedStartForm);
    Map<String, String> properties = new HashMap<String, String>();
    properties.put("room", "5b");
    properties.put("speaker", "Mike");
    String processInstanceId = formService.submitStartFormData(procDefId, properties).getId();
    Map<String, Object> expectedVariables = new HashMap<String, Object>();
    expectedVariables.put("room", "5b");
    expectedVariables.put("speaker", "Mike");
    Map<String, Object> variables = runtimeService.getVariables(processInstanceId);
    assertEquals(expectedVariables, variables);
    Task task = taskService.createTaskQuery().singleResult();
    String taskId = task.getId();
    TaskFormData taskForm = formService.getTaskFormData(taskId);
    assertEquals(deploymentId, taskForm.getDeploymentId());
    assertEquals("org/camunda/bpm/engine/test/api/form/task.form", taskForm.getFormKey());
    assertEquals(new ArrayList<FormProperty>(), taskForm.getFormProperties());
    assertEquals(taskId, taskForm.getTask().getId());
    assertEquals("Mike is speaking in room 5b", formService.getRenderedTaskForm(taskId, "juel"));
    properties = new HashMap<String, String>();
    properties.put("room", "3f");
    formService.submitTaskFormData(taskId, properties);
    expectedVariables = new HashMap<String, Object>();
    expectedVariables.put("room", "3f");
    expectedVariables.put("speaker", "Mike");
    variables = runtimeService.getVariables(processInstanceId);
    assertEquals(expectedVariables, variables);
}
Also used : Task(org.camunda.bpm.engine.task.Task) FormProperty(org.camunda.bpm.engine.form.FormProperty) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) StartFormData(org.camunda.bpm.engine.form.StartFormData) TaskFormData(org.camunda.bpm.engine.form.TaskFormData) Test(org.junit.Test)

Example 10 with TaskFormData

use of org.camunda.bpm.engine.form.TaskFormData in project camunda-bpm-platform by camunda.

the class FormServiceTest method testFormPropertyHandlingDeprecated.

@Deployment
@Test
public void testFormPropertyHandlingDeprecated() {
    Map<String, String> properties = new HashMap<String, String>();
    // default
    properties.put("room", "5b");
    // variable name mapping
    properties.put("speaker", "Mike");
    // type conversion
    properties.put("duration", "45");
    // type conversion
    properties.put("free", "true");
    String procDefId = repositoryService.createProcessDefinitionQuery().singleResult().getId();
    String processInstanceId = formService.submitStartFormData(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.submitTaskFormData(taskId, new HashMap<String, String>());
        fail("expected exception about required form property 'street'");
    } catch (ProcessEngineException e) {
    // OK
    }
    try {
        properties = new HashMap<String, String>();
        properties.put("speaker", "its not allowed to update speaker!");
        formService.submitTaskFormData(taskId, properties);
        fail("expected exception about a non writable form property 'speaker'");
    } catch (ProcessEngineException e) {
    // OK
    }
    properties = new HashMap<String, String>();
    properties.put("street", "rubensstraat");
    formService.submitTaskFormData(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)

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