@Test
  public void testAutoSkipFailedSummaryAction__red__service_checks_only() throws Exception {
    AutoSkipFailedSummaryAction action = new AutoSkipFailedSummaryAction();
    m_injector.injectMembers(action);

    ServiceComponentHostEvent event = createNiceMock(ServiceComponentHostEvent.class);

    // Set mock for parent's getHostRoleCommand()
    final HostRoleCommand hostRoleCommand = new HostRoleCommand("host1", Role.AMBARI_SERVER_ACTION,
        event, RoleCommand.EXECUTE, hostDAO, executionCommandDAO, ecwFactory);
    hostRoleCommand.setRequestId(1l);
    hostRoleCommand.setStageId(1l);

    ExecutionCommand executionCommand = new ExecutionCommand();
    executionCommand.setClusterName("cc");
    executionCommand.setRoleCommand(RoleCommand.EXECUTE);
    executionCommand.setRole("AMBARI_SERVER_ACTION");
    executionCommand.setServiceName("");
    executionCommand.setTaskId(1l);
    ExecutionCommandWrapper wrapper = new ExecutionCommandWrapper(executionCommand);
    hostRoleCommand.setExecutionCommandWrapper(wrapper);

    Field f = AbstractServerAction.class.getDeclaredField("hostRoleCommand");
    f.setAccessible(true);
    f.set(action, hostRoleCommand);

    final UpgradeItemEntity upgradeItem1 = new UpgradeItemEntity();
    upgradeItem1.setStageId(5l);
    final UpgradeItemEntity upgradeItem2 = new UpgradeItemEntity();
    upgradeItem2.setStageId(6l);

    UpgradeGroupEntity upgradeGroupEntity = new UpgradeGroupEntity();
    upgradeGroupEntity.setId(11l);
    // List of upgrade items in group
    List<UpgradeItemEntity> groupUpgradeItems = new ArrayList<UpgradeItemEntity>(){{
      add(upgradeItem1);
      add(upgradeItem2);
    }};
    upgradeGroupEntity.setItems(groupUpgradeItems);

    UpgradeItemEntity upgradeItemEntity = new UpgradeItemEntity();
    upgradeItemEntity.setGroupEntity(upgradeGroupEntity);

    expect(upgradeDAOMock.findUpgradeItemByRequestAndStage(anyLong(), anyLong())).andReturn(upgradeItemEntity).anyTimes();
    expect(upgradeDAOMock.findUpgradeGroup(anyLong())).andReturn(upgradeGroupEntity).anyTimes();
    replay(upgradeDAOMock);

    List<HostRoleCommandEntity> skippedTasks = new ArrayList<HostRoleCommandEntity>() {{
      add(createSkippedTask("ZOOKEEPER_QUORUM_SERVICE_CHECK", "ZOOKEEPER_CLIENT", "host2.vm",
        "SERVICE_CHECK ZOOKEEPER", RoleCommand.SERVICE_CHECK, null));
    }};
    expect(hostRoleCommandDAOMock.findByStatusBetweenStages(anyLong(),
      anyObject(HostRoleStatus.class), anyLong(), anyLong())).andReturn(skippedTasks).anyTimes();
    replay(hostRoleCommandDAOMock);

    ConcurrentMap<String, Object> requestSharedDataContext = new ConcurrentHashMap<>();
    CommandReport result = action.execute(requestSharedDataContext);

    assertNotNull(result.getStructuredOut());
    assertEquals(0, result.getExitCode());
    assertEquals(HostRoleStatus.HOLDING.toString(), result.getStatus());
    assertEquals("There were 1 skipped failure(s) that must be addressed " +
        "before you can proceed. Please resolve each failure before continuing with the upgrade.",
      result.getStdOut());
    assertEquals("{\"failures\":{\"service_check\":[\"ZOOKEEPER\"]},\"skipped\":[\"service_check\"]}",
      result.getStructuredOut());
    assertEquals("The following steps failed but were automatically skipped:\n" +
      "ZOOKEEPER_CLIENT on host2.vm: SERVICE_CHECK ZOOKEEPER\n", result.getStdErr());
  }
Tests workflow with failed service check
ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/AutoSkipFailedSummaryActionTest.java