public RunResponse restart(RunRequest runRequest) {
    RunResponse runResponse = restartRecursively(runRequest);
    if (runResponse.getStatus() == RunResponse.Status.NON_TERMINAL_ERROR) {
      LOG.error(
          "workflow instance {} does not support restart action as it is in a non-terminal status [{}]",
          runRequest.getWorkflowIdentity(),
          runResponse.getTimelineEvent().getMessage());
      throw new MaestroBadRequestException(
          Collections.emptyList(),
          "workflow instance %s does not support restart action as it is in a non-terminal status [%s]",
          runRequest.getWorkflowIdentity(),
          runResponse.getTimelineEvent().getMessage());
    }
    return runResponse;
  }
@Test
  public void testRestart() {
    WorkflowInstance wfInstance = new WorkflowInstance();
    wfInstance.setInitiator(new ManualInitiator());
    wfInstance.setStatus(WorkflowInstance.Status.SUCCEEDED);
    wfInstance.setWorkflowInstanceId(10L);
    wfInstance.setWorkflowRunId(1L);
    wfInstance.setWorkflowId("test-workflow");
    wfInstance.setRuntimeWorkflow(Workflow.builder().build());
    RunRequest request =
        RunRequest.builder()
            .initiator(new ManualInitiator())
            .currentPolicy(RunPolicy.RESTART_FROM_BEGINNING)
            .restartConfig(
                RestartConfig.builder().addRestartNode("test-workflow", 10L, null).build())
            .build();

    when(instanceDao.getWorkflowInstance("test-workflow", 10L, Constants.LATEST_INSTANCE_RUN, true))
        .thenReturn(wfInstance);
    when(runStrategyDao.startWithRunStrategy(any(), any())).thenReturn(1);
    when(instanceDao.getLatestWorkflowInstanceStatus(any(), anyLong()))
        .thenReturn(WorkflowInstance.Status.SUCCEEDED);

    RunResponse response = actionHandler.restart(request);
    assertEquals("test-workflow", response.getWorkflowId());
    assertEquals(10L, response.getWorkflowInstanceId());
    assertEquals(RunResponse.Status.WORKFLOW_RUN_CREATED, response.getStatus());
  }