public void testQuery(){
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
    HistoricProcessInstance processInstance=historyService.createHistoricProcessInstanceQuery().includeProcessVariables().variableValueEquals("anothertest",123).singleResult();
    Map<String,Object> variableMap=processInstance.getProcessVariables();
    assertEquals(1,variableMap.size());
    assertEquals(123,variableMap.get("anothertest"));
    List<HistoricProcessInstance> instanceList=historyService.createHistoricProcessInstanceQuery().includeProcessVariables().list();
    assertEquals(6,instanceList.size());
    instanceList=historyService.createHistoricProcessInstanceQuery().includeProcessVariables().processDefinitionKey(PROCESS_DEFINITION_KEY).list();
    assertEquals(4,instanceList.size());
    processInstance=instanceList.get(0);
    variableMap=processInstance.getProcessVariables();
    assertEquals(2,variableMap.size());
    assertEquals("test",variableMap.get("test"));
    assertEquals("test2",variableMap.get("test2"));
    assertEquals(PROCESS_DEFINITION_KEY,instanceList.get(0).getProcessDefinitionKey());
    processInstance=historyService.createHistoricProcessInstanceQuery().includeProcessVariables().processDefinitionKey(PROCESS_DEFINITION_KEY_2).singleResult();
    variableMap=processInstance.getProcessVariables();
    assertEquals(1,variableMap.size());
    assertEquals(123,variableMap.get("anothertest"));
    processInstance=historyService.createHistoricProcessInstanceQuery().includeProcessVariables().finished().singleResult();
    variableMap=processInstance.getProcessVariables();
    assertEquals(2,variableMap.size());
    assertEquals("test",variableMap.get("test"));
    assertEquals("test2",variableMap.get("test2"));
    instanceList=historyService.createHistoricProcessInstanceQuery().includeProcessVariables().listPage(0,50);
    assertEquals(6,instanceList.size());
    assertEquals(6,historyService.createHistoricProcessInstanceQuery().includeProcessVariables().count());
    instanceList=historyService.createHistoricProcessInstanceQuery().variableValueEquals("test","test").includeProcessVariables().listPage(0,50);
    assertEquals(4,instanceList.size());
    assertEquals(4,historyService.createHistoricProcessInstanceQuery().variableValueEquals("test","test").includeProcessVariables().count());
    instanceList=historyService.createHistoricProcessInstanceQuery().variableValueLike("test","te%").includeProcessVariables().list();
    assertEquals(4,instanceList.size());
    assertEquals(4,historyService.createHistoricProcessInstanceQuery().variableValueLike("test","te%").includeProcessVariables().count());
    instanceList=historyService.createHistoricProcessInstanceQuery().variableValueLike("test2","te%2").includeProcessVariables().list();
    assertEquals(4,instanceList.size());
    assertEquals(4,historyService.createHistoricProcessInstanceQuery().variableValueLike("test2","te%2").includeProcessVariables().count());
    instanceList=historyService.createHistoricProcessInstanceQuery().variableValueLikeIgnoreCase("test","te%").includeProcessVariables().list();
    assertEquals(4,instanceList.size());
    assertEquals(4,historyService.createHistoricProcessInstanceQuery().variableValueLikeIgnoreCase("test","te%").includeProcessVariables().count());
    instanceList=historyService.createHistoricProcessInstanceQuery().variableValueLikeIgnoreCase("test","t3%").includeProcessVariables().list();
    assertEquals(0,instanceList.size());
    assertEquals(0,historyService.createHistoricProcessInstanceQuery().variableValueLikeIgnoreCase("test","t3%").includeProcessVariables().count());
    instanceList=historyService.createHistoricProcessInstanceQuery().includeProcessVariables().listPage(0,50);
    assertEquals(6,instanceList.size());
    assertEquals(6,historyService.createHistoricProcessInstanceQuery().includeProcessVariables().count());
    instanceList=historyService.createHistoricProcessInstanceQuery().variableValueEquals("test","test").includeProcessVariables().listPage(0,1);
    assertEquals(1,instanceList.size());
    processInstance=instanceList.get(0);
    variableMap=processInstance.getProcessVariables();
    assertEquals(2,variableMap.size());
    assertEquals("test",variableMap.get("test"));
    assertEquals("test2",variableMap.get("test2"));
    assertEquals(4,historyService.createHistoricProcessInstanceQuery().variableValueEquals("test","test").includeProcessVariables().count());
    instanceList=historyService.createHistoricProcessInstanceQuery().includeProcessVariables().processDefinitionKey(PROCESS_DEFINITION_KEY).listPage(1,2);
    assertEquals(2,instanceList.size());
    processInstance=instanceList.get(0);
    variableMap=processInstance.getProcessVariables();
    assertEquals(2,variableMap.size());
    assertEquals("test",variableMap.get("test"));
    assertEquals("test2",variableMap.get("test2"));
    instanceList=historyService.createHistoricProcessInstanceQuery().includeProcessVariables().processDefinitionKey(PROCESS_DEFINITION_KEY).listPage(3,4);
    assertEquals(1,instanceList.size());
    processInstance=instanceList.get(0);
    variableMap=processInstance.getProcessVariables();
    assertEquals(2,variableMap.size());
    assertEquals("test",variableMap.get("test"));
    assertEquals("test2",variableMap.get("test2"));
    instanceList=historyService.createHistoricProcessInstanceQuery().includeProcessVariables().processDefinitionKey(PROCESS_DEFINITION_KEY).listPage(4,2);
    assertEquals(0,instanceList.size());
    instanceList=historyService.createHistoricProcessInstanceQuery().variableValueEquals("test","test").includeProcessVariables().orderByProcessInstanceId().asc().listPage(0,50);
    assertEquals(4,instanceList.size());
  }
}
