@Test
public void deleteExpiredWorkflowHistory() {

  WorkflowInstance parentWorkflow = constructWorkflowInstanceBuilder().build();
  long parentWorkflowId = workflowInstanceDao.insertWorkflowInstance(parentWorkflow);
  long addChildActionId = addWorkflowAction(parentWorkflowId, new WorkflowInstance.Builder(parentWorkflow).build(), now(),
      now());
  WorkflowInstance childWorkflow = constructWorkflowInstanceBuilder().setParentWorkflowId(parentWorkflowId)
      .setParentActionId(addChildActionId).build();
  long childWorkflowId = workflowInstanceDao.insertWorkflowInstance(childWorkflow);
  addWorkflowAction(parentWorkflowId,
      new WorkflowInstance.Builder(parentWorkflow).putStateVariable("variable", "deletedValue").build(), now(),
      now().minusDays(1));
  addWorkflowAction(parentWorkflowId,
      new WorkflowInstance.Builder(parentWorkflow).putStateVariable("variable", "preservedValue").build(), now(), now());
  maintenanceDao.deleteActionAndStateHistory(parentWorkflowId, now());
  parentWorkflow = workflowInstanceDao.getWorkflowInstance(parentWorkflowId, EnumSet.allOf(WorkflowInstanceInclude.class),
      null);
  assertThat(parentWorkflow.getStateVariable("requestData"), equalTo("{ \"parameter\": \"abc\" }"));
  assertThat(parentWorkflow.getStateVariable("variable"), equalTo("preservedValue"));
  assertThat(parentWorkflow.actions.size(), equalTo(2));
  childWorkflow = workflowInstanceDao.getWorkflowInstance(childWorkflowId, emptySet(), null);
  assertThat(childWorkflow.parentWorkflowId, equalTo(parentWorkflowId));
}