@Test
  public void simpleQueryTaskRestCallTest() throws Exception {
    int[] pageInfo = {0, 0};
    Map<String, String[]> queryParams = new HashMap<String, String[]>();

    // simple (everything)
    JaxbQueryTaskResult result =
        queryTaskHelper.queryTaskOrProcInstAndAssociatedVariables(USER_ID, queryParams, pageInfo);
    assertNotNull("null result", result);
    assertFalse("empty result", result.getTaskInfoList().isEmpty());
    assertTrue("empty result", result.getTaskInfoList().size() > 2);
    assertTrue(
        "pagination should not have happened: " + result.getTaskInfoList().size(),
        result.getTaskInfoList().size() >= 20);

    for (JaxbQueryTaskInfo taskInfo : result.getTaskInfoList()) {
      long procInstId = taskInfo.getProcessInstanceId();
      assertEquals(
          procInstId, taskInfo.getTaskSummaries().get(0).getProcessInstanceId().longValue());
    }

    roundTripJson(result);
    roundTripXml(result);

    // complicated
    String varVal = null;
    String varName = null;
    Date varDate = null;
    for (JaxbVariableInfo varInfo : result.getTaskInfoList().get(0).getVariables()) {
      if (varDate == null) {
        varVal = varInfo.getValue().toString();
        varName = varInfo.getName();
        varDate = varInfo.getModificationDate();
      } else if (varInfo.getModificationDate().after(varDate)
          && varInfo.getName().equals(varName)) {
        varVal = varInfo.getValue().toString();
      }
    }
    addParams(queryParams, "var_" + varName, varVal);

    result =
        queryTaskHelper.queryTaskOrProcInstAndAssociatedVariables(USER_ID, queryParams, pageInfo);

    // typo test
    queryParams.clear();
    addParams(queryParams, "potentialowner", "anton");

    result =
        queryTaskHelper.queryTaskOrProcInstAndAssociatedVariables(USER_ID, queryParams, pageInfo);
  }
  @Test
  public void queryTaskRestCallTest() throws Exception {
    int[] pageInfo = {0, 0};
    Map<String, String[]> queryParams = new HashMap<String, String[]>();

    // simple (everything)
    JaxbQueryTaskResult result =
        queryTaskHelper.queryTaskOrProcInstAndAssociatedVariables(USER_ID, queryParams, pageInfo);
    assertNotNull("null result", result);
    assertFalse("empty result", result.getTaskInfoList().isEmpty());
    assertTrue("empty result", result.getTaskInfoList().size() > 2);
    assertTrue(
        "pagination should not have happened: " + result.getTaskInfoList().size(),
        result.getTaskInfoList().size() >= 20);

    for (JaxbQueryTaskInfo taskInfo : result.getTaskInfoList()) {
      long procInstId = taskInfo.getProcessInstanceId();
      assertEquals(
          procInstId, taskInfo.getTaskSummaries().get(0).getProcessInstanceId().longValue());
    }

    roundTripJson(result);
    roundTripXml(result);

    // pagination
    pageInfo[1] = 3; // page size
    result =
        queryTaskHelper.queryTaskOrProcInstAndAssociatedVariables(USER_ID, queryParams, pageInfo);
    assertTrue(
        "Expected a page of size " + pageInfo[1] + ", not " + result.getTaskInfoList().size(),
        result.getTaskInfoList().size() == pageInfo[1]);

    pageInfo[0] = 2; // page number 2
    JaxbQueryTaskResult otherResult =
        queryTaskHelper.queryTaskOrProcInstAndAssociatedVariables(USER_ID, queryParams, pageInfo);
    Set<Long> origResultSet = new HashSet<Long>();
    long lastProcInstId = -1;
    for (JaxbQueryTaskInfo taskInfo : result.getTaskInfoList()) {
      assertTrue(
          "Not in process instance id order:"
              + lastProcInstId
              + " !< "
              + taskInfo.getProcessInstanceId(),
          lastProcInstId < taskInfo.getProcessInstanceId());
      lastProcInstId = taskInfo.getProcessInstanceId();
      origResultSet.add(taskInfo.getProcessInstanceId());
    }
    Set<Long> newResultSet = new HashSet<Long>();
    for (JaxbQueryTaskInfo taskInfo : otherResult.getTaskInfoList()) {
      newResultSet.add(taskInfo.getProcessInstanceId());
    }
    for (JaxbQueryTaskInfo taskInfo : otherResult.getTaskInfoList()) {
      long procInstId = taskInfo.getProcessInstanceId();
      assertFalse(
          "Original results should not be available in new results: " + procInstId,
          origResultSet.contains(procInstId));
    }
    pageInfo[0] = pageInfo[1] = 0; // reset page info for other tests

    // complicated
    long procInstId = result.getTaskInfoList().get(0).getProcessInstanceId();
    long taskId = result.getTaskInfoList().get(0).getTaskSummaries().get(0).getId();

    addParams(queryParams, "processinstanceid", procInstId + "");
    addParams(queryParams, "processid_re", PROCESS_STRING_VAR_ID.substring(0, 10) + "*");
    addParams(queryParams, "taskid_min", taskId + "");
    addParams(queryParams, "taskid_max", taskId + "");
    addParams(queryParams, "taskowner", USER_ID);
    addParams(queryParams, "tst", "Completed");

    Calendar cal = GregorianCalendar.getInstance();
    cal.roll(Calendar.DAY_OF_YEAR, +2);
    String tomorowStr = QUERY_PARAM_DATE_FORMAT.format(cal.getTime()).substring(0, 8);
    addParams(queryParams, "edt_max", tomorowStr);
    String yesterdayStr = "00:00:01";
    addParams(queryParams, "startdate_min", yesterdayStr);
    addParams(queryParams, "var_inputStr", "check-1");
    addParams(queryParams, "vv_re", "check*");

    result =
        queryTaskHelper.queryTaskOrProcInstAndAssociatedVariables(USER_ID, queryParams, pageInfo);
    assertNotNull("null result", result);
    assertFalse("empty result", result.getTaskInfoList().isEmpty());
    assertTrue("more than 1 result", result.getTaskInfoList().size() == 1);
    JaxbQueryTaskInfo taskInfo = result.getTaskInfoList().get(0);
    assertEquals("more than 1 task sum", 1, taskInfo.getTaskSummaries().size());
    assertEquals("more than 1 variable", 1, taskInfo.getVariables().size());
    TaskSummary taskSum = taskInfo.getTaskSummaries().get(0);
    assertNotNull(taskSum);
    assertEquals(taskId, taskSum.getId().longValue());
    JaxbVariableInfo varInfo = taskInfo.getVariables().get(0);
    assertEquals("inputStr", varInfo.getName());

    roundTripJson(result);
    roundTripXml(result);
  }