Search in sources :

Example 16 with StartFormData

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

the class FormPropertyDefaultValueTest method testStartFormDefaultValue.

@Deployment
public void testStartFormDefaultValue() throws Exception {
    String processDefinitionId = repositoryService.createProcessDefinitionQuery().processDefinitionKey("FormPropertyDefaultValueTest.testDefaultValue").latestVersion().singleResult().getId();
    StartFormData startForm = formService.getStartFormData(processDefinitionId);
    List<FormProperty> formProperties = startForm.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);
        }
    }
    // Override 2 properties. The others should pe posted as the default-value
    Map<String, String> formDataUpdate = new HashMap<String, String>();
    formDataUpdate.put("longExpressionProperty", "1");
    formDataUpdate.put("booleanProperty", "false");
    ProcessInstance processInstance = formService.submitStartFormData(processDefinitionId, 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 : FormProperty(org.camunda.bpm.engine.form.FormProperty) HashMap(java.util.HashMap) StartFormData(org.camunda.bpm.engine.form.StartFormData) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 17 with StartFormData

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

the class FormServiceTest method testFormPropertyDetails.

@SuppressWarnings("unchecked")
@Deployment
@Test
public void testFormPropertyDetails() {
    String procDefId = repositoryService.createProcessDefinitionQuery().singleResult().getId();
    StartFormData startFormData = formService.getStartFormData(procDefId);
    FormProperty property = startFormData.getFormProperties().get(0);
    assertEquals("speaker", property.getId());
    assertNull(property.getValue());
    assertTrue(property.isReadable());
    assertTrue(property.isWritable());
    assertFalse(property.isRequired());
    assertEquals("string", property.getType().getName());
    property = startFormData.getFormProperties().get(1);
    assertEquals("start", property.getId());
    assertNull(property.getValue());
    assertTrue(property.isReadable());
    assertTrue(property.isWritable());
    assertFalse(property.isRequired());
    assertEquals("date", property.getType().getName());
    assertEquals("dd-MMM-yyyy", property.getType().getInformation("datePattern"));
    property = startFormData.getFormProperties().get(2);
    assertEquals("direction", property.getId());
    assertNull(property.getValue());
    assertTrue(property.isReadable());
    assertTrue(property.isWritable());
    assertFalse(property.isRequired());
    assertEquals("enum", property.getType().getName());
    Map<String, String> values = (Map<String, String>) property.getType().getInformation("values");
    Map<String, String> expectedValues = new LinkedHashMap<String, String>();
    expectedValues.put("left", "Go Left");
    expectedValues.put("right", "Go Right");
    expectedValues.put("up", "Go Up");
    expectedValues.put("down", "Go Down");
    // ACT-1023: check if ordering is retained
    Iterator<Entry<String, String>> expectedValuesIterator = expectedValues.entrySet().iterator();
    for (Entry<String, String> entry : values.entrySet()) {
        Entry<String, String> expectedEntryAtLocation = expectedValuesIterator.next();
        assertEquals(expectedEntryAtLocation.getKey(), entry.getKey());
        assertEquals(expectedEntryAtLocation.getValue(), entry.getValue());
    }
    assertEquals(expectedValues, values);
}
Also used : Entry(java.util.Map.Entry) FormProperty(org.camunda.bpm.engine.form.FormProperty) StartFormData(org.camunda.bpm.engine.form.StartFormData) Map(java.util.Map) VariableMap(org.camunda.bpm.engine.variable.VariableMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 18 with StartFormData

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

the class FormServiceTest method testGetStartFormWithoutLabels.

@Deployment
@Test
public void testGetStartFormWithoutLabels() {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    runtimeService.startProcessInstanceById(processDefinition.getId());
    // form data can be retrieved
    StartFormData formData = formService.getStartFormData(processDefinition.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.getRenderedStartForm(processDefinition.getId());
    assertNotNull(startForm);
}
Also used : StartFormData(org.camunda.bpm.engine.form.StartFormData) ArrayList(java.util.ArrayList) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) FormField(org.camunda.bpm.engine.form.FormField) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 19 with StartFormData

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

the class FormAuthorizationTest method testGetStartFormData.

public void testGetStartFormData() {
    // given
    String processDefinitionId = selectProcessDefinitionByKey(FORM_PROCESS_KEY).getId();
    createGrantAuthorization(PROCESS_DEFINITION, FORM_PROCESS_KEY, userId, READ);
    // when
    StartFormData startFormData = formService.getStartFormData(processDefinitionId);
    // then
    assertNotNull(startFormData);
    assertEquals("deployment:org/camunda/bpm/engine/test/api/form/start.form", startFormData.getFormKey());
}
Also used : StartFormData(org.camunda.bpm.engine.form.StartFormData)

Aggregations

StartFormData (org.camunda.bpm.engine.form.StartFormData)19 Test (org.junit.Test)10 Deployment (org.camunda.bpm.engine.test.Deployment)5 FormField (org.camunda.bpm.engine.form.FormField)4 FormProperty (org.camunda.bpm.engine.form.FormProperty)4 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)3 VariableMap (org.camunda.bpm.engine.variable.VariableMap)3 LinkedHashMap (java.util.LinkedHashMap)2 FormType (org.camunda.bpm.engine.form.FormType)2 AbstractFoxPlatformIntegrationTest (org.camunda.bpm.integrationtest.util.AbstractFoxPlatformIntegrationTest)2 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 AuthorizationException (org.camunda.bpm.engine.AuthorizationException)1 FormService (org.camunda.bpm.engine.FormService)1 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)1 ScriptEvaluationException (org.camunda.bpm.engine.ScriptEvaluationException)1 TaskFormData (org.camunda.bpm.engine.form.TaskFormData)1