@ApiOperation(value = "Query for historic activity instances", tags = {"History", "Query" },
            notes = "All supported JSON parameter fields allowed are exactly the same as the parameters found for getting a collection of historic task instances, but passed in as JSON-body arguments rather than URL-parameters to allow for more advanced querying and preventing errors with request-uri’s that are too long.")
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "Indicates request was successful and the activities are returned"),
            @ApiResponse(code = 400, message = "Indicates an parameter was passed in the wrong format. The status-message contains additional information") })
    @PostMapping(value = "/query/historic-activity-instances", produces = "application/json")
    public DataResponse<HistoricActivityInstanceResponse> queryActivityInstances(@RequestBody HistoricActivityInstanceQueryRequest queryRequest, @ApiParam(hidden = true) @RequestParam Map<String, String> allRequestParams) {

        return getQueryResponse(queryRequest, allRequestParams);
    }
@Test
    @Deployment
    public void testQueryActivityInstances() throws Exception {
        HashMap<String, Object> processVariables = new HashMap<>();
        processVariables.put("stringVar", "Azerty");
        processVariables.put("intVar", 67890);
        processVariables.put("booleanVar", false);

        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", processVariables);
        Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
        taskService.complete(task.getId());

        ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", processVariables);

        String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_ACTIVITY_INSTANCE_QUERY);

        ObjectNode requestNode = objectMapper.createObjectNode();
        requestNode.put("activityId", "processTask");
        assertResultsPresentInDataResponse(url, requestNode, 2, "processTask");

        requestNode = objectMapper.createObjectNode();
        requestNode.put("activityId", "processTask");
        requestNode.put("finished", true);
        assertResultsPresentInDataResponse(url, requestNode, 1, "processTask");

        requestNode = objectMapper.createObjectNode();
        requestNode.put("activityId", "processTask");
        requestNode.put("finished", false);
        assertResultsPresentInDataResponse(url, requestNode, 1, "processTask");

        requestNode = objectMapper.createObjectNode();
        requestNode.put("activityId", "processTask2");
        assertResultsPresentInDataResponse(url, requestNode, 1, "processTask2");

        requestNode = objectMapper.createObjectNode();
        requestNode.put("activityId", "processTask3");
        assertResultsPresentInDataResponse(url, requestNode, 0);

        requestNode = objectMapper.createObjectNode();
        requestNode.put("activityName", "Process task");
        assertResultsPresentInDataResponse(url, requestNode, 2, "processTask");

        requestNode = objectMapper.createObjectNode();
        requestNode.put("activityName", "Process task2");
        assertResultsPresentInDataResponse(url, requestNode, 1, "processTask2");

        requestNode = objectMapper.createObjectNode();
        requestNode.put("activityName", "Process task3");
        assertResultsPresentInDataResponse(url, requestNode, 0);

        requestNode = objectMapper.createObjectNode();
        requestNode.put("activityType", "userTask");
        assertResultsPresentInDataResponse(url, requestNode, 3, "processTask", "processTask2");

        requestNode = objectMapper.createObjectNode();
        requestNode.put("activityType", "startEvent");
        assertResultsPresentInDataResponse(url, requestNode, 2, "theStart");

        requestNode = objectMapper.createObjectNode();
        requestNode.put("activityType", "receiveTask");
        assertResultsPresentInDataResponse(url, requestNode, 0);

        requestNode = objectMapper.createObjectNode();
        requestNode.put("processInstanceId", processInstance.getId());
        assertResultsPresentInDataResponse(url, requestNode, 5, "theStart", "flow1", "processTask", "flow2", "processTask2");

        requestNode = objectMapper.createObjectNode();
        requestNode.put("processInstanceId", processInstance2.getId());
        assertResultsPresentInDataResponse(url, requestNode, 3, "theStart", "flow1", "processTask");

        requestNode = objectMapper.createObjectNode();
        requestNode.put("processDefinitionId", processInstance.getProcessDefinitionId());
        assertResultsPresentInDataResponse(url, requestNode, 8, "theStart", "flow1", "processTask", "flow2", "processTask2");

        requestNode = objectMapper.createObjectNode();
        requestNode.put("taskAssignee", "kermit");
        assertResultsPresentInDataResponse(url, requestNode, 2, "processTask");

        requestNode = objectMapper.createObjectNode();
        requestNode.put("taskAssignee", "fozzie");
        assertResultsPresentInDataResponse(url, requestNode, 1, "processTask2");

        requestNode = objectMapper.createObjectNode();
        requestNode.put("taskAssignee", "fozzie2");
        assertResultsPresentInDataResponse(url, requestNode, 0);
    }