@Test
public void archiveWorkflowsWithActionsAndStatesWorks() {

  List<Long> workflowIds = new ArrayList<>();
  List<Long> actionIds = new ArrayList<>();
  List<StateKey> stateIds = new ArrayList<>();
  long nonArchivableWorkflow1 = storeActiveWorkflow(archiveTime1);
  storeStateVariables(nonArchivableWorkflow1, storeActions(nonArchivableWorkflow1, 3), 1);
  long nonArchivableWorkflow2 = storeActiveWorkflow(prodTime1);
  storeStateVariables(nonArchivableWorkflow2, storeActions(nonArchivableWorkflow2, 1), 3);
  long nonArchivableWorkflow3 = storePassiveWorkflow(prodTime1);
  storeStateVariables(nonArchivableWorkflow3, storeActions(nonArchivableWorkflow3, 2), 2);
  long archivable1 = storePassiveWorkflow(archiveTime1);
  long archivable2 = storePassiveWorkflow(archiveTime2);
  List<Long> actions1 = storeActions(archivable1, 1);
  List<Long> actions2 = storeActions(archivable2, 2);
  actionIds.addAll(actions1);
  actionIds.addAll(actions2);
  stateIds.addAll(storeStateVariables(archivable1, actions1, 4));
  stateIds.addAll(storeStateVariables(archivable2, actions2, 2));
  workflowIds.addAll(asList(archivable1, archivable2));
  int variablesCountBefore = getActiveStateCount();
  assertEquals(workflowIds.size(), maintenanceDao.archiveWorkflows(workflowIds));
  int variablesCountAfter = getActiveStateCount();
  assertActiveWorkflowsRemoved(workflowIds);
  assertArchiveWorkflowsExist(workflowIds);
  assertActiveActionsRemoved(actionIds);
  assertArchiveActionsExist(actionIds, true);
  assertActiveStateVariablesRemoved(stateIds);
  assertArchiveStateVariablesExist(stateIds, true);
  // each workflow gets automatically stateVariable called "requestData"
  int requestDataVariableCount = workflowIds.size();
  assertEquals(stateIds.size() + requestDataVariableCount, getArchivedStateCount());
  assertEquals(variablesCountAfter, variablesCountBefore - stateIds.size() - requestDataVariableCount);
}