@Test
  public void testDueDateParametersAsPost() {
    String value = "2013-05-18T00:00:00";
    String anotherValue = "2013-05-05T00:00:00";

    Date date = DateTimeUtil.parseDate(value);
    Date anotherDate = DateTimeUtil.parseDate(anotherValue);

    Map<String, Object> conditionJson = new HashMap<String, Object>();
    conditionJson.put("operator", "lt");
    conditionJson.put("value", value);

    Map<String, Object> anotherConditionJson = new HashMap<String, Object>();
    anotherConditionJson.put("operator", "gt");
    anotherConditionJson.put("value", anotherValue);

    List<Map<String, Object>> conditions = new ArrayList<Map<String, Object>>();
    conditions.add(conditionJson);
    conditions.add(anotherConditionJson);

    Map<String, Object> json = new HashMap<String, Object>();
    json.put("dueDates", conditions);

    given()
        .contentType(POST_JSON_CONTENT_TYPE)
        .body(json)
        .then()
        .expect()
        .statusCode(Status.OK.getStatusCode())
        .when()
        .post(JOBS_RESOURCE_URL);

    verify(mockQuery).duedateHigherThan(anotherDate);
    verify(mockQuery).duedateLowerThan(date);
  }
  @Test
  public void testSimpleJobQuery() {
    String jobId = MockProvider.EXAMPLE_JOB_ID;

    Response response =
        given()
            .queryParam("jobId", jobId)
            .then()
            .expect()
            .statusCode(Status.OK.getStatusCode())
            .when()
            .get(JOBS_RESOURCE_URL);

    InOrder inOrder = inOrder(mockQuery);
    inOrder.verify(mockQuery).jobId(jobId);
    inOrder.verify(mockQuery).list();

    String content = response.asString();
    List<String> instances = from(content).getList("");
    Assert.assertEquals("There should be one job returned.", 1, instances.size());
    Assert.assertNotNull("The returned job should not be null.", instances.get(0));

    String returnedJobId = from(content).getString("[0].id");
    String returnedProcessInstanceId = from(content).getString("[0].processInstanceId");
    String returnedProcessDefinitionId = from(content).getString("[0].processDefinitionId");
    String returnedProcessDefinitionKey = from(content).getString("[0].processDefinitionKey");
    String returnedExecutionId = from(content).getString("[0].executionId");
    String returnedExceptionMessage = from(content).getString("[0].exceptionMessage");
    int returnedRetries = from(content).getInt("[0].retries");
    Date returnedDueDate = DateTimeUtil.parseDate(from(content).getString("[0].dueDate"));
    boolean returnedSuspended = from(content).getBoolean("[0].suspended");
    long returnedPriority = from(content).getLong("[0].priority");
    String returnedJobDefinitionId = from(content).getString("[0].jobDefinitionId");
    String returnedTenantId = from(content).getString("[0].tenantId");

    Assert.assertEquals(MockProvider.EXAMPLE_JOB_ID, returnedJobId);
    Assert.assertEquals(MockProvider.EXAMPLE_PROCESS_INSTANCE_ID, returnedProcessInstanceId);
    Assert.assertEquals(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID, returnedProcessDefinitionId);
    Assert.assertEquals(MockProvider.EXAMPLE_PROCESS_DEFINITION_KEY, returnedProcessDefinitionKey);
    Assert.assertEquals(MockProvider.EXAMPLE_EXECUTION_ID, returnedExecutionId);
    Assert.assertEquals(MockProvider.EXAMPLE_JOB_NO_EXCEPTION_MESSAGE, returnedExceptionMessage);
    Assert.assertEquals(MockProvider.EXAMPLE_JOB_RETRIES, returnedRetries);
    Assert.assertEquals(DateTimeUtil.parseDate(MockProvider.EXAMPLE_DUE_DATE), returnedDueDate);
    Assert.assertEquals(MockProvider.EXAMPLE_JOB_IS_SUSPENDED, returnedSuspended);
    Assert.assertEquals(MockProvider.EXAMPLE_JOB_PRIORITY, returnedPriority);
    Assert.assertEquals(MockProvider.EXAMPLE_JOB_DEFINITION_ID, returnedJobDefinitionId);
    Assert.assertEquals(MockProvider.EXAMPLE_TENANT_ID, returnedTenantId);
  }
  @Test
  public void testDueDateParameters() {
    String variableValue = "2013-05-05T00:00:00";
    Date date = DateTimeUtil.parseDate(variableValue);

    String queryValue = "lt_" + variableValue;
    given()
        .queryParam("dueDates", queryValue)
        .then()
        .expect()
        .statusCode(Status.OK.getStatusCode())
        .when()
        .get(JOBS_RESOURCE_URL);

    InOrder inOrder = inOrder(mockQuery);
    inOrder.verify(mockQuery).duedateLowerThan(date);
    inOrder.verify(mockQuery).list();

    queryValue = "gt_" + variableValue;
    given()
        .queryParam("dueDates", queryValue)
        .then()
        .expect()
        .statusCode(Status.OK.getStatusCode())
        .when()
        .get(JOBS_RESOURCE_URL);

    inOrder = inOrder(mockQuery);
    inOrder.verify(mockQuery).duedateHigherThan(date);
    inOrder.verify(mockQuery).list();
  }
  @Test
  public void testMultipleDueDateParameters() {
    String variableValue1 = "2012-05-05T00:00:00";
    String variableParameter1 = "gt_" + variableValue1;

    String variableValue2 = "2013-02-02T00:00:00";
    String variableParameter2 = "lt_" + variableValue2;

    Date date = DateTimeUtil.parseDate(variableValue1);
    Date anotherDate = DateTimeUtil.parseDate(variableValue2);

    String queryValue = variableParameter1 + "," + variableParameter2;

    given()
        .queryParam("dueDates", queryValue)
        .then()
        .expect()
        .statusCode(Status.OK.getStatusCode())
        .when()
        .get(JOBS_RESOURCE_URL);

    verify(mockQuery).duedateHigherThan(date);
    verify(mockQuery).duedateLowerThan(anotherDate);
  }
  @Test
  public void testSimpleHistoricActivityQuery() {
    Response response =
        given()
            .then()
            .expect()
            .statusCode(Status.OK.getStatusCode())
            .when()
            .get(HISTORIC_DETAIL_RESOURCE_URL);

    InOrder inOrder = inOrder(mockedQuery);
    inOrder.verify(mockedQuery).list();

    String content = response.asString();
    List<String> details = from(content).getList("");
    Assert.assertEquals("There should be two activity instance returned.", 2, details.size());
    Assert.assertNotNull("The returned details should not be null.", details.get(0));
    Assert.assertNotNull("The returned details should not be null.", details.get(1));

    String returnedId1 = from(content).getString("[0].id");
    String returnedProcessInstanceId1 = from(content).getString("[0].processInstanceId");
    String returnedActivityInstanceId1 = from(content).getString("[0].activityInstanceId");
    String returnedExecutionId1 = from(content).getString("[0].executionId");
    String returnedTaskId1 = from(content).getString("[0].taskId");
    Date returnedTime1 = DateTimeUtil.parseDateTime(from(content).getString("[0].time")).toDate();
    String returnedVariableName = from(content).getString("[0].variableName");
    String returnedVariableTypeName = from(content).getString("[0].variableTypeName");
    String returnedValue = from(content).getString("[0].value");
    int returnedRevision = from(content).getInt("[0].revision");

    Assert.assertEquals(MockProvider.EXAMPLE_HISTORIC_VAR_UPDATE_ID, returnedId1);
    Assert.assertEquals(
        MockProvider.EXAMPLE_HISTORIC_VAR_UPDATE_PROC_INST_ID, returnedProcessInstanceId1);
    Assert.assertEquals(
        MockProvider.EXAMPLE_HISTORIC_VAR_UPDATE_ACT_INST_ID, returnedActivityInstanceId1);
    Assert.assertEquals(MockProvider.EXAMPLE_HISTORIC_VAR_UPDATE_EXEC_ID, returnedExecutionId1);
    Assert.assertEquals(MockProvider.EXAMPLE_HISTORIC_VAR_UPDATE_TASK_ID, returnedTaskId1);
    Assert.assertEquals(
        DateTimeUtil.parseDateTime(MockProvider.EXAMPLE_HISTORIC_VAR_UPDATE_TIME).toDate(),
        returnedTime1);
    Assert.assertEquals(MockProvider.EXAMPLE_HISTORIC_VAR_UPDATE_NAME, returnedVariableName);
    Assert.assertEquals(
        MockProvider.EXAMPLE_HISTORIC_VAR_UPDATE_TYPE_NAME, returnedVariableTypeName);
    Assert.assertEquals(MockProvider.EXAMPLE_HISTORIC_VAR_UPDATE_VALUE, returnedValue);
    Assert.assertEquals(MockProvider.EXAMPLE_HISTORIC_VAR_UPDATE_REVISION, returnedRevision);

    String returnedId2 = from(content).getString("[1].id");
    String returnedProcessInstanceId2 = from(content).getString("[1].processInstanceId");
    String returnedActivityInstanceId2 = from(content).getString("[1].activityInstanceId");
    String returnedExecutionId2 = from(content).getString("[1].executionId");
    String returnedTaskId2 = from(content).getString("[1].taskId");
    Date returnedTime2 = DateTimeUtil.parseDateTime(from(content).getString("[1].time")).toDate();
    String returnedFieldId = from(content).getString("[1].fieldId");
    String returnedFieldValue = from(content).getString("[1].fieldValue");

    Assert.assertEquals(MockProvider.EXAMPLE_HISTORIC_FORM_FIELD_ID, returnedId2);
    Assert.assertEquals(
        MockProvider.EXAMPLE_HISTORIC_FORM_FIELD_PROC_INST_ID, returnedProcessInstanceId2);
    Assert.assertEquals(
        MockProvider.EXAMPLE_HISTORIC_FORM_FIELD_ACT_INST_ID, returnedActivityInstanceId2);
    Assert.assertEquals(MockProvider.EXAMPLE_HISTORIC_FORM_FIELD_EXEC_ID, returnedExecutionId2);
    Assert.assertEquals(MockProvider.EXAMPLE_HISTORIC_FORM_FIELD_TASK_ID, returnedTaskId2);
    Assert.assertEquals(
        DateTimeUtil.parseDateTime(MockProvider.EXAMPLE_HISTORIC_FORM_FIELD_TIME).toDate(),
        returnedTime2);
    Assert.assertEquals(MockProvider.EXAMPLE_HISTORIC_FORM_FIELD_FIELD_ID, returnedFieldId);
    Assert.assertEquals(MockProvider.EXAMPLE_HISTORIC_FORM_FIELD_VALUE, returnedFieldValue);
  }