예제 #1
0
  /** Test getting a task variable. GET runtime/tasks/{taskId}/variables/{variableName}/data */
  public void testGetTaskVariableDataSerializable() throws Exception {
    try {
      TestSerializableVariable originalSerializable = new TestSerializableVariable();
      originalSerializable.setSomeField("This is some field");

      // Test variable behaviour on standalone tasks
      Task task = taskService.newTask();
      taskService.saveTask(task);
      taskService.setVariableLocal(task.getId(), "localTaskVariable", originalSerializable);

      ClientResource client =
          getAuthenticatedClient(
              RestUrls.createRelativeResourceUrl(
                  RestUrls.URL_TASK_VARIABLE_DATA, task.getId(), "localTaskVariable"));
      client.get();
      assertEquals(Status.SUCCESS_OK, client.getResponse().getStatus());

      // Read the serializable from the stream
      ObjectInputStream stream =
          new ObjectInputStream(client.getResponse().getEntity().getStream());
      Object readSerializable = stream.readObject();
      assertNotNull(readSerializable);
      assertTrue(readSerializable instanceof TestSerializableVariable);
      assertEquals(
          "This is some field", ((TestSerializableVariable) readSerializable).getSomeField());
      assertEquals(MediaType.APPLICATION_JAVA_OBJECT.getName(), getMediaType(client));
    } finally {
      // Clean adhoc-tasks even if test fails
      List<Task> tasks = taskService.createTaskQuery().list();
      for (Task task : tasks) {
        taskService.deleteTask(task.getId(), true);
      }
    }
  }
예제 #2
0
  /** Test getting a task variable. GET runtime/tasks/{taskId}/variables/{variableName}/data */
  public void testGetTaskVariableData() throws Exception {
    try {
      // Test variable behaviour on standalone tasks
      Task task = taskService.newTask();
      taskService.saveTask(task);
      taskService.setVariableLocal(
          task.getId(), "localTaskVariable", "This is a binary piece of text".getBytes());

      // Force content-type to TEXT_PLAIN to make sure this is ignored and application-octect-stream
      // is always returned
      ClientResource client =
          getAuthenticatedClient(
              RestUrls.createRelativeResourceUrl(
                  RestUrls.URL_TASK_VARIABLE_DATA, task.getId(), "localTaskVariable"));
      client.get(MediaType.TEXT_PLAIN);

      assertEquals(Status.SUCCESS_OK, client.getResponse().getStatus());
      String actualResponseBytesAsText = client.getResponse().getEntityAsText();
      assertEquals("This is a binary piece of text", actualResponseBytesAsText);
      assertEquals(MediaType.APPLICATION_OCTET_STREAM.getName(), getMediaType(client));
    } finally {
      // Clean adhoc-tasks even if test fails
      List<Task> tasks = taskService.createTaskQuery().list();
      for (Task task : tasks) {
        taskService.deleteTask(task.getId(), true);
      }
    }
  }
예제 #3
0
  public void postContent(String content) {
    ClientResource cr = null;

    try {
      cr = new ClientResource(uriShare + "?access_token=" + access_token + "&message=" + content);
      cr.post(content);
    } catch (ResourceException re) {
      System.err.println("Error when retrieving friends: " + cr.getResponse().getStatus());
      System.err.println(uri + "?access_token" + access_token);
    }
  }
예제 #4
0
  /**
   * Test updating a single task variable using a binary stream. PUT
   * runtime/tasks/{taskId}/variables/{variableName}
   */
  public void testUpdateBinaryTaskVariable() throws Exception {
    try {
      Task task = taskService.newTask();
      taskService.saveTask(task);
      taskService.setVariable(task.getId(), "binaryVariable", "Original value".getBytes());

      InputStream binaryContent = new ByteArrayInputStream("This is binary content".getBytes());

      // Add name, type and scope
      Map<String, String> additionalFields = new HashMap<String, String>();
      additionalFields.put("name", "binaryVariable");
      additionalFields.put("type", "binary");
      additionalFields.put("scope", "local");

      // Upload a valid BPMN-file using multipart-data
      Representation uploadRepresentation =
          new HttpMultipartRepresentation("value", binaryContent, additionalFields);

      ClientResource client =
          getAuthenticatedClient(
              RestUrls.createRelativeResourceUrl(
                  RestUrls.URL_TASK_VARIABLE, task.getId(), "binaryVariable"));
      Representation response = client.put(uploadRepresentation);
      assertEquals(Status.SUCCESS_OK, client.getResponse().getStatus());

      JsonNode responseNode = objectMapper.readTree(response.getStream());
      assertNotNull(responseNode);
      assertEquals("binaryVariable", responseNode.get("name").asText());
      assertTrue(responseNode.get("value").isNull());
      assertEquals("local", responseNode.get("scope").asText());
      assertEquals("binary", responseNode.get("type").asText());
      assertNotNull(responseNode.get("valueUrl").isNull());
      assertTrue(
          responseNode
              .get("valueUrl")
              .asText()
              .endsWith(
                  RestUrls.createRelativeResourceUrl(
                      RestUrls.URL_TASK_VARIABLE_DATA, task.getId(), "binaryVariable")));

      // Check actual value of variable in engine
      Object variableValue = taskService.getVariableLocal(task.getId(), "binaryVariable");
      assertNotNull(variableValue);
      assertTrue(variableValue instanceof byte[]);
      assertEquals("This is binary content", new String((byte[]) variableValue));
    } finally {
      // Clean adhoc-tasks even if test fails
      List<Task> tasks = taskService.createTaskQuery().list();
      for (Task task : tasks) {
        taskService.deleteTask(task.getId(), true);
      }
    }
  }
예제 #5
0
  public FacebookPhoto getPhotos() {
    ClientResource cr = null;
    FacebookPhoto photos = null;

    try {
      cr = new ClientResource(uriPhoto + "&access_token=" + access_token);
      photos = cr.get(FacebookPhoto.class);
    } catch (ResourceException re) {
      System.err.println("Error when retrieving photos: " + cr.getResponse().getStatus());
      System.err.println(uri + "?access_token" + access_token);
    }

    return photos;
  }
  protected void assertResultsPresentInDataResponse(
      String url,
      ObjectNode body,
      int numberOfResultsExpected,
      String variableName,
      Object variableValue)
      throws JsonProcessingException, IOException {

    // Do the actual call
    ClientResource client = getAuthenticatedClient(url);
    Representation response = client.post(body);

    // Check status and size
    assertEquals(Status.SUCCESS_OK, client.getResponse().getStatus());
    JsonNode dataNode = objectMapper.readTree(response.getStream()).get("data");
    assertEquals(numberOfResultsExpected, dataNode.size());

    // Check presence of ID's
    if (variableName != null) {
      boolean variableFound = false;
      Iterator<JsonNode> it = dataNode.iterator();
      while (it.hasNext()) {
        JsonNode variableNode = it.next();
        String name = variableNode.get("variableName").getTextValue();
        if (variableName.equals(name)) {
          variableFound = true;
          if (variableValue instanceof Boolean) {
            assertTrue(
                "Variable value is not equal",
                variableNode.get("value").asBoolean() == (Boolean) variableValue);
          } else if (variableValue instanceof Integer) {
            assertTrue(
                "Variable value is not equal",
                variableNode.get("value").asInt() == (Integer) variableValue);
          } else {
            assertTrue(
                "Variable value is not equal",
                variableNode.get("value").asText().equals((String) variableValue));
          }
        }
      }
      assertTrue("Variable " + variableName + " is missing", variableFound);
    }

    client.release();
  }
  /**
   * Tries to send a query to the PushEndpoint running on http://localhost:8183/pushendpoint.
   *
   * @throws Exception
   */
  @Test
  public void sendQueryToPushEndpoint() throws Exception {

    // construct workflow
    ClientResource rdfResource = new ClientResource(Resources.MGMT_WORKFLOWS_URL);

    Form form = new Form();
    form.add("workflow", SampleRdfWorkflows.getWorkflowWithPushEndpoint());
    Representation rep = form.getWebRepresentation();
    rep.setMediaType(MediaType.APPLICATION_RDF_XML);
    Representation rdfResponse = rdfResource.post(rep);
    Reference url = rdfResponse.getLocationRef();

    // retrieve endpoint
    ClientResource endpointResource =
        new ClientResource(url + "/endpoint?urn=urn:eu.larkc.endpoint.push.ep1");
    Representation endpointResponse = endpointResource.get();

    Reference pushEndpointUrl = endpointResponse.getLocationRef();
    logger.debug("PushEndpoint URL: {}", pushEndpointUrl);

    // execute query
    ClientResource pushEndpointResource = new ClientResource(pushEndpointUrl);

    Form queryForm = new Form();
    queryForm.add("query", SampleQueries.WHO_KNOWS_FRANK);
    Representation queryRep = queryForm.getWebRepresentation();

    pushEndpointResource.post(queryRep);

    Assert.assertEquals(200, pushEndpointResource.getResponse().getStatus().getCode());

    // delete workflow
    ClientResource workflowResource = new ClientResource(url);
    workflowResource.delete();
  }
예제 #8
0
  /** Test getting a task variable. GET runtime/tasks/{taskId}/variables/{variableName} */
  @Deployment
  public void testGetTaskVariable() throws Exception {
    try {
      // Test variable behaviour on standalone tasks
      Task task = taskService.newTask();
      taskService.saveTask(task);
      taskService.setVariableLocal(task.getId(), "localTaskVariable", "localValue");

      ClientResource client =
          getAuthenticatedClient(
              RestUrls.createRelativeResourceUrl(
                  RestUrls.URL_TASK_VARIABLE, task.getId(), "localTaskVariable"));
      Representation response = client.get();
      assertEquals(Status.SUCCESS_OK, client.getResponse().getStatus());

      JsonNode responseNode = objectMapper.readTree(response.getStream());
      assertNotNull(responseNode);
      assertEquals("local", responseNode.get("scope").asText());
      assertEquals("localValue", responseNode.get("value").asText());
      assertEquals("localTaskVariable", responseNode.get("name").asText());
      assertEquals("string", responseNode.get("type").asText());

      // Test variable behaviour for a process-task
      ProcessInstance processInstance =
          runtimeService.startProcessInstanceByKey(
              "oneTaskProcess",
              Collections.singletonMap("sharedVariable", (Object) "processValue"));
      Task processTask =
          taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();

      taskService.setVariableLocal(processTask.getId(), "sharedVariable", "taskValue");

      // ANY scope, local should get precedence
      client =
          getAuthenticatedClient(
              RestUrls.createRelativeResourceUrl(
                  RestUrls.URL_TASK_VARIABLE, processTask.getId(), "sharedVariable"));
      response = client.get();
      assertEquals(Status.SUCCESS_OK, client.getResponse().getStatus());

      responseNode = objectMapper.readTree(response.getStream());
      assertNotNull(responseNode);
      assertEquals("local", responseNode.get("scope").asText());
      assertEquals("taskValue", responseNode.get("value").asText());
      assertEquals("sharedVariable", responseNode.get("name").asText());
      assertEquals("string", responseNode.get("type").asText());

      // LOCAL scope
      client =
          getAuthenticatedClient(
              RestUrls.createRelativeResourceUrl(
                      RestUrls.URL_TASK_VARIABLE, processTask.getId(), "sharedVariable")
                  + "?scope=local");
      response = client.get();
      assertEquals(Status.SUCCESS_OK, client.getResponse().getStatus());

      responseNode = objectMapper.readTree(response.getStream());
      assertNotNull(responseNode);
      assertEquals("local", responseNode.get("scope").asText());
      assertEquals("taskValue", responseNode.get("value").asText());
      assertEquals("sharedVariable", responseNode.get("name").asText());
      assertEquals("string", responseNode.get("type").asText());

      // GLOBAL scope
      client =
          getAuthenticatedClient(
              RestUrls.createRelativeResourceUrl(
                      RestUrls.URL_TASK_VARIABLE, processTask.getId(), "sharedVariable")
                  + "?scope=global");
      response = client.get();
      assertEquals(Status.SUCCESS_OK, client.getResponse().getStatus());

      responseNode = objectMapper.readTree(response.getStream());
      assertNotNull(responseNode);
      assertEquals("global", responseNode.get("scope").asText());
      assertEquals("processValue", responseNode.get("value").asText());
      assertEquals("sharedVariable", responseNode.get("name").asText());
      assertEquals("string", responseNode.get("type").asText());

      // Illegal scope
      client =
          getAuthenticatedClient(
              RestUrls.createRelativeResourceUrl(
                      RestUrls.URL_TASK_VARIABLE, processTask.getId(), "sharedVariable")
                  + "?scope=illegal");
      try {
        response = client.get();
        fail("Exception expected");
      } catch (ResourceException expected) {
        assertEquals(Status.CLIENT_ERROR_BAD_REQUEST, expected.getStatus());
        assertEquals("Invalid variable scope: 'illegal'", expected.getStatus().getDescription());
      }

      // Unexisting task
      client =
          getAuthenticatedClient(
              RestUrls.createRelativeResourceUrl(
                  RestUrls.URL_TASK_VARIABLE, "unexisting", "sharedVariable"));
      try {
        response = client.get();
        fail("Exception expected");
      } catch (ResourceException expected) {
        assertEquals(Status.CLIENT_ERROR_NOT_FOUND, expected.getStatus());
        assertEquals("task unexisting doesn't exist", expected.getStatus().getDescription());
      }

      // Unexisting variable
      client =
          getAuthenticatedClient(
              RestUrls.createRelativeResourceUrl(
                  RestUrls.URL_TASK_VARIABLE, processTask.getId(), "unexistingVariable"));
      try {
        response = client.get();
        fail("Exception expected");
      } catch (ResourceException expected) {
        assertEquals(Status.CLIENT_ERROR_NOT_FOUND, expected.getStatus());
        assertEquals(
            "Task '"
                + processTask.getId()
                + "' doesn't have a variable with name: 'unexistingVariable'.",
            expected.getStatus().getDescription());
      }

    } finally {
      // Clean adhoc-tasks even if test fails
      List<Task> tasks = taskService.createTaskQuery().list();
      for (Task task : tasks) {
        if (task.getExecutionId() == null) {
          taskService.deleteTask(task.getId(), true);
        }
      }
    }
  }
예제 #9
0
  /**
   * Test updating a single task variable in all scopes, including "not found" check.
   *
   * <p>PUT runtime/tasks/{taskId}/variables/{variableName}
   */
  @Deployment
  public void testUpdateTaskVariable() throws Exception {
    ProcessInstance processInstance =
        runtimeService.startProcessInstanceByKey(
            "oneTaskProcess",
            Collections.singletonMap("overlappingVariable", (Object) "processValue"));
    Task task =
        taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    taskService.setVariableLocal(task.getId(), "overlappingVariable", "taskValue");

    // Update variable without scope, local should be presumed -> local updated and global should be
    // retained
    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("name", "overlappingVariable");
    requestNode.put("value", "updatedLocalValue");
    requestNode.put("type", "string");

    ClientResource client =
        getAuthenticatedClient(
            RestUrls.createRelativeResourceUrl(
                RestUrls.URL_TASK_VARIABLE, task.getId(), "overlappingVariable"));
    Representation response = client.put(requestNode);
    assertEquals(Status.SUCCESS_OK, client.getResponse().getStatus());

    JsonNode responseNode = objectMapper.readTree(response.getStream());
    assertNotNull(responseNode);
    assertEquals("updatedLocalValue", responseNode.get("value").asText());
    assertEquals("local", responseNode.get("scope").asText());
    // Check local value is changed in engine and global one remains unchanged
    assertEquals(
        "updatedLocalValue", taskService.getVariableLocal(task.getId(), "overlappingVariable"));
    assertEquals(
        "processValue", runtimeService.getVariable(task.getExecutionId(), "overlappingVariable"));

    // Update variable in local scope
    response.release();
    requestNode = objectMapper.createObjectNode();
    requestNode.put("name", "overlappingVariable");
    requestNode.put("value", "updatedLocalValueOnceAgain");
    requestNode.put("type", "string");
    requestNode.put("scope", "local");
    response = client.put(requestNode);
    assertEquals(Status.SUCCESS_OK, client.getResponse().getStatus());

    responseNode = objectMapper.readTree(response.getStream());
    assertNotNull(responseNode);
    assertEquals("updatedLocalValueOnceAgain", responseNode.get("value").asText());
    assertEquals("local", responseNode.get("scope").asText());
    // Check local value is changed in engine and global one remains unchanged
    assertEquals(
        "updatedLocalValueOnceAgain",
        taskService.getVariableLocal(task.getId(), "overlappingVariable"));
    assertEquals(
        "processValue", runtimeService.getVariable(task.getExecutionId(), "overlappingVariable"));

    // Update variable in global scope
    response.release();
    requestNode = objectMapper.createObjectNode();
    requestNode.put("name", "overlappingVariable");
    requestNode.put("value", "updatedInGlobalScope");
    requestNode.put("type", "string");
    requestNode.put("scope", "global");
    response = client.put(requestNode);
    assertEquals(Status.SUCCESS_OK, client.getResponse().getStatus());

    responseNode = objectMapper.readTree(response.getStream());
    assertNotNull(responseNode);
    assertEquals("updatedInGlobalScope", responseNode.get("value").asText());
    assertEquals("global", responseNode.get("scope").asText());
    // Check global value is changed in engine and local one remains unchanged
    assertEquals(
        "updatedLocalValueOnceAgain",
        taskService.getVariableLocal(task.getId(), "overlappingVariable"));
    assertEquals(
        "updatedInGlobalScope",
        runtimeService.getVariable(task.getExecutionId(), "overlappingVariable"));

    // Try updating with mismatch between URL and body variableName unexisting property
    try {
      requestNode.put("name", "unexistingVariable");
      client.put(requestNode);
      fail("Exception expected");
    } catch (ResourceException expected) {
      assertEquals(Status.CLIENT_ERROR_BAD_REQUEST, expected.getStatus());
      assertEquals(
          "Variable name in the body should be equal to the name used in the requested URL.",
          expected.getStatus().getDescription());
    }

    // Try updating unexisting property
    try {
      client =
          getAuthenticatedClient(
              RestUrls.createRelativeResourceUrl(
                  RestUrls.URL_TASK_VARIABLE, task.getId(), "unexistingVariable"));
      requestNode.put("name", "unexistingVariable");
      client.put(requestNode);
      fail("Exception expected");
    } catch (ResourceException expected) {
      assertEquals(Status.CLIENT_ERROR_NOT_FOUND, expected.getStatus());
      assertEquals(
          "Task '" + task.getId() + "' doesn't have a variable with name: 'unexistingVariable'.",
          expected.getStatus().getDescription());
    }
  }
예제 #10
0
  /**
   * Test deleting a single task variable in all scopes, including "not found" check.
   *
   * <p>DELETE runtime/tasks/{taskId}/variables/{variableName}
   */
  @Deployment
  public void testDeleteTaskVariable() throws Exception {
    ProcessInstance processInstance =
        runtimeService.startProcessInstanceByKey(
            "oneTaskProcess",
            Collections.singletonMap("overlappingVariable", (Object) "processValue"));
    Task task =
        taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    taskService.setVariableLocal(task.getId(), "overlappingVariable", "taskValue");
    taskService.setVariableLocal(task.getId(), "anotherTaskVariable", "taskValue");

    // Delete variable without scope, local should be presumed -> local removed and global should be
    // retained
    ClientResource client =
        getAuthenticatedClient(
            RestUrls.createRelativeResourceUrl(
                RestUrls.URL_TASK_VARIABLE, task.getId(), "overlappingVariable"));
    Representation response = client.delete();
    assertEquals(Status.SUCCESS_NO_CONTENT, client.getResponse().getStatus());
    assertEquals(0L, response.getSize());
    assertFalse(taskService.hasVariableLocal(task.getId(), "overlappingVariable"));
    assertTrue(taskService.hasVariable(task.getId(), "overlappingVariable"));

    // Delete local scope variable
    client.release();
    client =
        getAuthenticatedClient(
            RestUrls.createRelativeResourceUrl(
                    RestUrls.URL_TASK_VARIABLE, task.getId(), "anotherTaskVariable")
                + "?scope=local");
    response = client.delete();
    assertEquals(Status.SUCCESS_NO_CONTENT, client.getResponse().getStatus());
    assertEquals(0L, response.getSize());
    assertFalse(taskService.hasVariableLocal(task.getId(), "anotherTaskVariable"));

    // Delete global scope variable
    assertTrue(taskService.hasVariable(task.getId(), "overlappingVariable"));
    client.release();
    client =
        getAuthenticatedClient(
            RestUrls.createRelativeResourceUrl(
                    RestUrls.URL_TASK_VARIABLE, task.getId(), "overlappingVariable")
                + "?scope=global");
    response = client.delete();
    assertEquals(Status.SUCCESS_NO_CONTENT, client.getResponse().getStatus());
    assertEquals(0L, response.getSize());
    assertFalse(taskService.hasVariable(task.getId(), "overlappingVariable"));

    // Run the same delete again, variable is not there so 404 should be returned
    client.release();
    try {
      client.delete();
      fail("Exception expected");
    } catch (ResourceException expected) {
      assertEquals(Status.CLIENT_ERROR_NOT_FOUND, expected.getStatus());
      assertEquals(
          "Task '"
              + task.getId()
              + "' doesn't have a variable 'overlappingVariable' in scope global",
          expected.getStatus().getDescription());
    }
  }
예제 #11
0
  @Deployment
  public void testGetFormData() throws Exception {
    Map<String, Object> variableMap = new HashMap<String, Object>();
    variableMap.put("SpeakerName", "John Doe");
    Address address = new Address();
    variableMap.put("address", address);
    ProcessInstance processInstance =
        runtimeService.startProcessInstanceByKey("oneTaskProcess", variableMap);
    Task task =
        taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();

    ClientResource client =
        getAuthenticatedClient(
            RestUrls.createRelativeResourceUrl(RestUrls.URL_FORM_DATA) + "?taskId=" + task.getId());
    Representation response = client.get();
    assertEquals(Status.SUCCESS_OK, client.getResponse().getStatus());

    // Check resulting task
    JsonNode responseNode = objectMapper.readTree(response.getStream());
    assertEquals(7, responseNode.get("formProperties").size());
    Map<String, JsonNode> mappedProperties = new HashMap<String, JsonNode>();
    for (JsonNode propNode : responseNode.get("formProperties")) {
      mappedProperties.put(propNode.get("id").asText(), propNode);
    }
    JsonNode propNode = mappedProperties.get("room");
    assertNotNull(propNode);
    assertEquals("room", propNode.get("id").asText());
    assertTrue(propNode.get("name").isNull());
    assertTrue(propNode.get("type").isNull());
    assertTrue(propNode.get("value").isNull());
    assertTrue(propNode.get("readable").asBoolean());
    assertTrue(propNode.get("writable").asBoolean());
    assertTrue(propNode.get("required").asBoolean() == false);

    propNode = mappedProperties.get("duration");
    assertNotNull(propNode);
    assertEquals("duration", propNode.get("id").asText());
    assertTrue(propNode.get("name").isNull());
    assertEquals("long", propNode.get("type").asText());
    assertTrue(propNode.get("value").isNull());
    assertTrue(propNode.get("readable").asBoolean());
    assertTrue(propNode.get("writable").asBoolean());
    assertTrue(propNode.get("required").asBoolean() == false);

    propNode = mappedProperties.get("speaker");
    assertNotNull(propNode);
    assertEquals("speaker", propNode.get("id").asText());
    assertTrue(propNode.get("name").isNull());
    assertTrue(propNode.get("type").isNull());
    assertEquals("John Doe", propNode.get("value").asText());
    assertTrue(propNode.get("readable").asBoolean());
    assertTrue(propNode.get("writable").asBoolean() == false);
    assertTrue(propNode.get("required").asBoolean() == false);

    propNode = mappedProperties.get("street");
    assertNotNull(propNode);
    assertEquals("street", propNode.get("id").asText());
    assertTrue(propNode.get("name").isNull());
    assertTrue(propNode.get("type").isNull());
    assertTrue(propNode.get("value").isNull());
    assertTrue(propNode.get("readable").asBoolean());
    assertTrue(propNode.get("writable").asBoolean());
    assertTrue(propNode.get("required").asBoolean());

    propNode = mappedProperties.get("start");
    assertNotNull(propNode);
    assertEquals("start", propNode.get("id").asText());
    assertTrue(propNode.get("name").isNull());
    assertEquals("date", propNode.get("type").asText());
    assertTrue(propNode.get("value").isNull());
    assertEquals("dd-MMM-yyyy", propNode.get("datePattern").asText());
    assertTrue(propNode.get("readable").asBoolean());
    assertTrue(propNode.get("writable").asBoolean());
    assertTrue(propNode.get("required").asBoolean() == false);

    propNode = mappedProperties.get("end");
    assertNotNull(propNode);
    assertEquals("end", propNode.get("id").asText());
    assertEquals("End", propNode.get("name").asText());
    assertEquals("date", propNode.get("type").asText());
    assertTrue(propNode.get("value").isNull());
    assertEquals("dd/MM/yyyy", propNode.get("datePattern").asText());
    assertTrue(propNode.get("readable").asBoolean());
    assertTrue(propNode.get("writable").asBoolean());
    assertTrue(propNode.get("required").asBoolean() == false);

    propNode = mappedProperties.get("direction");
    assertNotNull(propNode);
    assertEquals("direction", propNode.get("id").asText());
    assertTrue(propNode.get("name").isNull());
    assertEquals("enum", propNode.get("type").asText());
    assertTrue(propNode.get("value").isNull());
    assertTrue(propNode.get("datePattern").isNull());
    assertTrue(propNode.get("readable").asBoolean());
    assertTrue(propNode.get("writable").asBoolean());
    assertTrue(propNode.get("required").asBoolean() == false);
    JsonNode enumValues = propNode.get("enumValues");
    assertEquals(4, enumValues.size());
    Map<String, String> mappedEnums = new HashMap<String, String>();
    for (JsonNode enumNode : enumValues) {
      mappedEnums.put(enumNode.get("id").asText(), enumNode.get("name").asText());
    }
    assertEquals("Go Left", mappedEnums.get("left"));
    assertEquals("Go Right", mappedEnums.get("right"));
    assertEquals("Go Up", mappedEnums.get("up"));
    assertEquals("Go Down", mappedEnums.get("down"));

    client =
        getAuthenticatedClient(
            RestUrls.createRelativeResourceUrl(RestUrls.URL_FORM_DATA)
                + "?processDefinitionId="
                + processInstance.getProcessDefinitionId());
    response = client.get();
    assertEquals(Status.SUCCESS_OK, client.getResponse().getStatus());

    // Check resulting task
    responseNode = objectMapper.readTree(response.getStream());
    assertEquals(2, responseNode.get("formProperties").size());
    mappedProperties.clear();
    for (JsonNode propertyNode : responseNode.get("formProperties")) {
      mappedProperties.put(propertyNode.get("id").asText(), propertyNode);
    }

    propNode = mappedProperties.get("number");
    assertNotNull(propNode);
    assertEquals("number", propNode.get("id").asText());
    assertEquals("Number", propNode.get("name").asText());
    assertEquals("long", propNode.get("type").asText());
    assertTrue(propNode.get("value").isNull());
    assertTrue(propNode.get("readable").asBoolean());
    assertTrue(propNode.get("writable").asBoolean());
    assertTrue(propNode.get("required").asBoolean() == false);

    propNode = mappedProperties.get("description");
    assertNotNull(propNode);
    assertEquals("description", propNode.get("id").asText());
    assertEquals("Description", propNode.get("name").asText());
    assertTrue(propNode.get("type").isNull());
    assertTrue(propNode.get("value").isNull());
    assertTrue(propNode.get("readable").asBoolean());
    assertTrue(propNode.get("writable").asBoolean());
    assertTrue(propNode.get("required").asBoolean() == false);

    client =
        getAuthenticatedClient(
            RestUrls.createRelativeResourceUrl(RestUrls.URL_FORM_DATA)
                + "?processDefinitionId=123");
    try {
      response = client.get();
      fail();
    } catch (Exception e) {
      // expected
      assertEquals(Status.CLIENT_ERROR_NOT_FOUND, client.getResponse().getStatus());
    }

    client =
        getAuthenticatedClient(
            RestUrls.createRelativeResourceUrl(RestUrls.URL_FORM_DATA)
                + "?processDefinitionId2=123");
    try {
      response = client.get();
      fail();
    } catch (Exception e) {
      // expected
      assertEquals(Status.CLIENT_ERROR_BAD_REQUEST, client.getResponse().getStatus());
    }
  }
예제 #12
0
  @Deployment
  public void testSubmitFormData() throws Exception {
    Map<String, Object> variableMap = new HashMap<String, Object>();
    variableMap.put("SpeakerName", "John Doe");
    Address address = new Address();
    variableMap.put("address", address);
    ProcessInstance processInstance =
        runtimeService.startProcessInstanceByKey("oneTaskProcess", variableMap);
    String processInstanceId = processInstance.getId();
    String processDefinitionId = processInstance.getProcessDefinitionId();
    Task task = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult();

    ClientResource client =
        getAuthenticatedClient(RestUrls.createRelativeResourceUrl(RestUrls.URL_FORM_DATA));
    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("taskId", task.getId());
    ArrayNode propertyArray = objectMapper.createArrayNode();
    requestNode.put("properties", propertyArray);
    ObjectNode propNode = objectMapper.createObjectNode();
    propNode.put("id", "room");
    propNode.put("value", 123l);
    propertyArray.add(propNode);
    try {
      client.post(requestNode);
    } catch (Exception e) {
      // expected
      assertEquals(Status.SERVER_ERROR_INTERNAL, client.getResponse().getStatus());
    }

    propNode = objectMapper.createObjectNode();
    propNode.put("id", "street");
    propNode.put("value", "test");
    propertyArray.add(propNode);
    client.release();
    client.post(requestNode);

    assertEquals(Status.SUCCESS_NO_CONTENT, client.getResponse().getStatus());
    task = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult();
    assertNull(task);
    processInstance =
        runtimeService
            .createProcessInstanceQuery()
            .processInstanceId(processInstanceId)
            .singleResult();
    assertNull(processInstance);
    List<HistoricVariableInstance> variables =
        historyService
            .createHistoricVariableInstanceQuery()
            .processInstanceId(processInstanceId)
            .list();
    Map<String, HistoricVariableInstance> historyMap =
        new HashMap<String, HistoricVariableInstance>();
    for (HistoricVariableInstance historicVariableInstance : variables) {
      historyMap.put(historicVariableInstance.getVariableName(), historicVariableInstance);
    }

    assertEquals("123", historyMap.get("room").getValue());
    assertEquals(processInstanceId, historyMap.get("room").getProcessInstanceId());

    processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", variableMap);
    processInstanceId = processInstance.getId();
    task = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult();

    requestNode.put("taskId", task.getId());
    propNode = objectMapper.createObjectNode();
    propNode.put("id", "direction");
    propNode.put("value", "nowhere");
    propertyArray.add(propNode);
    try {
      client.release();
      client.post(requestNode);
    } catch (Exception e) {
      // expected
      assertEquals(Status.CLIENT_ERROR_BAD_REQUEST, client.getResponse().getStatus());
    }

    propNode.put("value", "up");
    client.release();
    client.post(requestNode);
    assertEquals(Status.SUCCESS_NO_CONTENT, client.getResponse().getStatus());
    task = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult();
    assertNull(task);
    processInstance =
        runtimeService
            .createProcessInstanceQuery()
            .processInstanceId(processInstanceId)
            .singleResult();
    assertNull(processInstance);
    variables =
        historyService
            .createHistoricVariableInstanceQuery()
            .processInstanceId(processInstanceId)
            .list();
    historyMap.clear();
    for (HistoricVariableInstance historicVariableInstance : variables) {
      historyMap.put(historicVariableInstance.getVariableName(), historicVariableInstance);
    }

    assertEquals("123", historyMap.get("room").getValue());
    assertEquals(processInstanceId, historyMap.get("room").getProcessInstanceId());
    assertEquals("up", historyMap.get("direction").getValue());

    requestNode = objectMapper.createObjectNode();
    requestNode.put("processDefinitionId", processDefinitionId);
    propertyArray = objectMapper.createArrayNode();
    requestNode.put("properties", propertyArray);
    propNode = objectMapper.createObjectNode();
    propNode.put("id", "number");
    propNode.put("value", 123);
    propertyArray.add(propNode);
    client.release();
    Representation response = client.post(requestNode);
    assertEquals(Status.SUCCESS_OK, client.getResponse().getStatus());
    JsonNode responseNode = objectMapper.readTree(response.getStream());
    assertNotNull(responseNode.get("id").asText());
    assertEquals(processDefinitionId, responseNode.get("processDefinitionId").asText());
    task =
        taskService
            .createTaskQuery()
            .processInstanceId(responseNode.get("id").asText())
            .singleResult();
    assertNotNull(task);
  }