@Test
public void testRemove() throws Exception {

  WorkflowInstance wi1 = startAndWait(workingDefinition, mediapackage1, WorkflowState.SUCCEEDED);
  WorkflowInstance wi2 = startAndWait(workingDefinition, mediapackage2, WorkflowState.SUCCEEDED);
  WorkflowInstance wi3 = startAndWait(pausingWorkflowDefinition, mediapackage1, WorkflowState.PAUSED);
  // reload instances, because operations have no id before
  wi1 = service.getWorkflowById(wi1.getId());
  wi2 = service.getWorkflowById(wi2.getId());
  service.remove(wi1.getId());
  assertEquals(2, service.getWorkflowInstances(new WorkflowQuery()).size());
  for (WorkflowOperationInstance op : wi1.getOperations()) {
    assertEquals(0, serviceRegistry.getChildJobs(op.getId()).size());
  }
  service.remove(wi2.getId(), false);
  assertEquals(1, service.getWorkflowInstances(new WorkflowQuery()).size());
  try {
    service.remove(wi3.getId(), false);
    Assert.fail("A paused workflow shouldn't be removed without using force");
  } catch (WorkflowStateException e) {
    assertEquals(1, service.getWorkflowInstances(new WorkflowQuery()).size());
  }
  try {
    service.remove(wi3.getId(), true);
    assertEquals(0, service.getWorkflowInstances(new WorkflowQuery()).size());
  } catch (WorkflowStateException e) {
    Assert.fail(e.getMessage());
  }
}