@Test
  public void testResetOriginalValues() throws Exception {
    KaleoTaskInstanceToken newKaleoTaskInstanceToken = addKaleoTaskInstanceToken();

    _persistence.clearCache();

    KaleoTaskInstanceToken existingKaleoTaskInstanceToken =
        _persistence.findByPrimaryKey(newKaleoTaskInstanceToken.getPrimaryKey());

    Assert.assertEquals(
        Long.valueOf(existingKaleoTaskInstanceToken.getKaleoInstanceId()),
        ReflectionTestUtil.<Long>invoke(
            existingKaleoTaskInstanceToken, "getOriginalKaleoInstanceId", new Class<?>[0]));
    Assert.assertEquals(
        Long.valueOf(existingKaleoTaskInstanceToken.getKaleoTaskId()),
        ReflectionTestUtil.<Long>invoke(
            existingKaleoTaskInstanceToken, "getOriginalKaleoTaskId", new Class<?>[0]));
  }
  protected List<KaleoTaskAssignment> getCalculatedKaleoTaskAssignments(
      KaleoTaskInstanceToken kaleoTaskInstanceToken) throws PortalException {

    List<KaleoTaskAssignment> calculatedKaleoTaskAssignments = new ArrayList<>();

    KaleoInstanceToken kaleoInstanceToken = kaleoTaskInstanceToken.getKaleoInstanceToken();

    Map<String, Serializable> workflowContext =
        WorkflowContextUtil.convert(kaleoTaskInstanceToken.getWorkflowContext());

    ServiceContext workflowContextServiceContext =
        (ServiceContext) workflowContext.get(WorkflowConstants.CONTEXT_SERVICE_CONTEXT);

    ExecutionContext executionContext =
        new ExecutionContext(kaleoInstanceToken, workflowContext, workflowContextServiceContext);

    List<KaleoTaskAssignment> configuredKaleoTaskAssignments =
        KaleoTaskAssignmentLocalServiceUtil.getKaleoTaskAssignments(
            kaleoTaskInstanceToken.getKaleoTaskId());

    for (KaleoTaskAssignment configuredKaleoTaskAssignment : configuredKaleoTaskAssignments) {

      String[] assigneeScriptRequiredContexts =
          StringUtil.split(configuredKaleoTaskAssignment.getAssigneeScriptRequiredContexts());

      ClassLoader[] classLoaders = ClassLoaderUtil.getClassLoaders(assigneeScriptRequiredContexts);

      Collection<KaleoTaskAssignment> kaleoTaskAssignments =
          _taskAssignmentSelector.calculateTaskAssignments(
              configuredKaleoTaskAssignment, executionContext, classLoaders);

      calculatedKaleoTaskAssignments.addAll(kaleoTaskAssignments);
    }

    return calculatedKaleoTaskAssignments;
  }
  @Test
  public void testUpdateExisting() throws Exception {
    long pk = RandomTestUtil.nextLong();

    KaleoTaskInstanceToken newKaleoTaskInstanceToken = _persistence.create(pk);

    newKaleoTaskInstanceToken.setGroupId(RandomTestUtil.nextLong());

    newKaleoTaskInstanceToken.setCompanyId(RandomTestUtil.nextLong());

    newKaleoTaskInstanceToken.setUserId(RandomTestUtil.nextLong());

    newKaleoTaskInstanceToken.setUserName(RandomTestUtil.randomString());

    newKaleoTaskInstanceToken.setCreateDate(RandomTestUtil.nextDate());

    newKaleoTaskInstanceToken.setModifiedDate(RandomTestUtil.nextDate());

    newKaleoTaskInstanceToken.setKaleoDefinitionId(RandomTestUtil.nextLong());

    newKaleoTaskInstanceToken.setKaleoInstanceId(RandomTestUtil.nextLong());

    newKaleoTaskInstanceToken.setKaleoInstanceTokenId(RandomTestUtil.nextLong());

    newKaleoTaskInstanceToken.setKaleoTaskId(RandomTestUtil.nextLong());

    newKaleoTaskInstanceToken.setKaleoTaskName(RandomTestUtil.randomString());

    newKaleoTaskInstanceToken.setClassName(RandomTestUtil.randomString());

    newKaleoTaskInstanceToken.setClassPK(RandomTestUtil.nextLong());

    newKaleoTaskInstanceToken.setCompletionUserId(RandomTestUtil.nextLong());

    newKaleoTaskInstanceToken.setCompleted(RandomTestUtil.randomBoolean());

    newKaleoTaskInstanceToken.setCompletionDate(RandomTestUtil.nextDate());

    newKaleoTaskInstanceToken.setDueDate(RandomTestUtil.nextDate());

    newKaleoTaskInstanceToken.setWorkflowContext(RandomTestUtil.randomString());

    _kaleoTaskInstanceTokens.add(_persistence.update(newKaleoTaskInstanceToken));

    KaleoTaskInstanceToken existingKaleoTaskInstanceToken =
        _persistence.findByPrimaryKey(newKaleoTaskInstanceToken.getPrimaryKey());

    Assert.assertEquals(
        existingKaleoTaskInstanceToken.getKaleoTaskInstanceTokenId(),
        newKaleoTaskInstanceToken.getKaleoTaskInstanceTokenId());
    Assert.assertEquals(
        existingKaleoTaskInstanceToken.getGroupId(), newKaleoTaskInstanceToken.getGroupId());
    Assert.assertEquals(
        existingKaleoTaskInstanceToken.getCompanyId(), newKaleoTaskInstanceToken.getCompanyId());
    Assert.assertEquals(
        existingKaleoTaskInstanceToken.getUserId(), newKaleoTaskInstanceToken.getUserId());
    Assert.assertEquals(
        existingKaleoTaskInstanceToken.getUserName(), newKaleoTaskInstanceToken.getUserName());
    Assert.assertEquals(
        Time.getShortTimestamp(existingKaleoTaskInstanceToken.getCreateDate()),
        Time.getShortTimestamp(newKaleoTaskInstanceToken.getCreateDate()));
    Assert.assertEquals(
        Time.getShortTimestamp(existingKaleoTaskInstanceToken.getModifiedDate()),
        Time.getShortTimestamp(newKaleoTaskInstanceToken.getModifiedDate()));
    Assert.assertEquals(
        existingKaleoTaskInstanceToken.getKaleoDefinitionId(),
        newKaleoTaskInstanceToken.getKaleoDefinitionId());
    Assert.assertEquals(
        existingKaleoTaskInstanceToken.getKaleoInstanceId(),
        newKaleoTaskInstanceToken.getKaleoInstanceId());
    Assert.assertEquals(
        existingKaleoTaskInstanceToken.getKaleoInstanceTokenId(),
        newKaleoTaskInstanceToken.getKaleoInstanceTokenId());
    Assert.assertEquals(
        existingKaleoTaskInstanceToken.getKaleoTaskId(),
        newKaleoTaskInstanceToken.getKaleoTaskId());
    Assert.assertEquals(
        existingKaleoTaskInstanceToken.getKaleoTaskName(),
        newKaleoTaskInstanceToken.getKaleoTaskName());
    Assert.assertEquals(
        existingKaleoTaskInstanceToken.getClassName(), newKaleoTaskInstanceToken.getClassName());
    Assert.assertEquals(
        existingKaleoTaskInstanceToken.getClassPK(), newKaleoTaskInstanceToken.getClassPK());
    Assert.assertEquals(
        existingKaleoTaskInstanceToken.getCompletionUserId(),
        newKaleoTaskInstanceToken.getCompletionUserId());
    Assert.assertEquals(
        existingKaleoTaskInstanceToken.getCompleted(), newKaleoTaskInstanceToken.getCompleted());
    Assert.assertEquals(
        Time.getShortTimestamp(existingKaleoTaskInstanceToken.getCompletionDate()),
        Time.getShortTimestamp(newKaleoTaskInstanceToken.getCompletionDate()));
    Assert.assertEquals(
        Time.getShortTimestamp(existingKaleoTaskInstanceToken.getDueDate()),
        Time.getShortTimestamp(newKaleoTaskInstanceToken.getDueDate()));
    Assert.assertEquals(
        existingKaleoTaskInstanceToken.getWorkflowContext(),
        newKaleoTaskInstanceToken.getWorkflowContext());
  }