@Test
  public void processInstanceWithVariablesTest() throws Exception {
    KieSession ksession = createKnowledgeSession("BPMN2-StringStructureRef.bpmn2");
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);

    Map<String, Object> params = new HashMap<String, Object>();
    String val = "initial-val";
    params.put("test", val);
    ProcessInstance processInstance = ksession.startProcess("StructureRef");
    assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);

    Map<String, Object> res = new HashMap<String, Object>();
    res.put("testHT", "test value");
    ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItem().getId(), res);

    Map<String, String> map = new HashMap<String, String>();
    map.put("test", "initial-val");

    JaxbProcessInstanceWithVariablesResponse jpiwvr =
        new JaxbProcessInstanceWithVariablesResponse(processInstance, map);
    testRoundtrip(jpiwvr);

    JaxbProcessInstanceListResponse jpilp = new JaxbProcessInstanceListResponse();
    List<ProcessInstance> procInstList = new ArrayList<ProcessInstance>();
    procInstList.add(new JaxbProcessInstanceResponse(processInstance));
    jpilp.setResult(procInstList);
    testRoundtrip(jpilp);
  }
  private JaxbProcessInstanceListResponse getProcessInstanceListResponse(
      List<VariableInstanceLog> varLogList, int[] pageInfo) {
    JaxbProcessInstanceListResponse response = new JaxbProcessInstanceListResponse();
    response.setCommandName(FindProcessInstanceCommand.class.getSimpleName());

    int numVarLogs = varLogList.size();
    int numResults = pageInfo[PAGE_NUM] * pageInfo[PAGE_SIZE];
    int numProcInsts = 0;

    for (int i = 0; i < numVarLogs && numProcInsts < numResults; ++i) {
      long procInstId = varLogList.get(i).getProcessInstanceId();
      Object procInstResult = getProcessInstance(procInstId);
      if (procInstResult != null) {
        response.getResult().add(new JaxbProcessInstanceResponse((ProcessInstance) procInstResult));
        ++numProcInsts;
      }
    }
    return response;
  }
  @Test
  public void processInstanceWithVariablesTest() throws Exception {

    this.setupDataSource = true;
    this.sessionPersistence = true;
    super.setUp();

    RuntimeEngine runtimeEngine =
        createRuntimeManager("BPMN2-StringStructureRef.bpmn2").getRuntimeEngine(null);
    KieSession ksession = runtimeEngine.getKieSession();

    Map<String, Object> params = new HashMap<String, Object>();
    String val = "initial-val";
    params.put("test", val);
    ProcessInstance processInstance = ksession.startProcess("StructureRef");
    assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);

    Map<String, Object> res = new HashMap<String, Object>();
    res.put("testHT", "test value");
    // ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItem().getId(),
    // res);

    Map<String, String> map = new HashMap<String, String>();
    map.put("test", "initial-val");

    JaxbProcessInstanceWithVariablesResponse jpiwvr =
        new JaxbProcessInstanceWithVariablesResponse(processInstance, map);
    testRoundTrip(jpiwvr);

    JaxbProcessInstanceListResponse jpilp = new JaxbProcessInstanceListResponse();
    List<ProcessInstance> procInstList = new ArrayList<ProcessInstance>();
    procInstList.add(new JaxbProcessInstanceResponse(processInstance));
    jpilp.setResult(procInstList);
    testRoundTrip(jpilp);

    super.tearDown();
    this.setupDataSource = false;
    this.sessionPersistence = false;
  }