@Test
public void testFailingOperationWithErrorHandler() throws Exception {

  WorkflowInstance instance = startAndWait(failingDefinitionWithErrorHandler, mediapackage1, WorkflowState.FAILED);
  Assert.assertEquals(WorkflowState.FAILED, service.getWorkflowById(instance.getId()).getState());
  // The second operation should have failed
  Assert.assertEquals(OperationState.FAILED, service.getWorkflowById(instance.getId()).getOperations().get(1)
          .getState());
  // Load a fresh copy
  WorkflowInstance storedInstance = service.getWorkflowById(instance.getId());
  // Make sure the error handler has been added
  Assert.assertEquals(4, storedInstance.getOperations().size());
  Assert.assertEquals("op1", storedInstance.getOperations().get(0).getTemplate());
  Assert.assertEquals("op3", storedInstance.getOperations().get(1).getTemplate());
  Assert.assertEquals("op1", storedInstance.getOperations().get(2).getTemplate());
  Assert.assertEquals("op2", storedInstance.getOperations().get(3).getTemplate());
}