@Test
  public void testCreateRegenerateKeytabStages() throws Exception {
    Capture<Map<String, String>> requestPropertyMapCapture = EasyMock.newCapture();

    Map<String, Object> requestProps = new HashMap<>();
    requestProps.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "c1");
    requestProps.put(UpgradeResourceProvider.UPGRADE_REPO_VERSION_ID, String.valueOf(repoVersionEntity2200.getId()));
    requestProps.put(UpgradeResourceProvider.UPGRADE_PACK, "upgrade_test_regenerate_keytabs");
    requestProps.put(UpgradeResourceProvider.UPGRADE_SKIP_PREREQUISITE_CHECKS, "true");
    requestProps.put(UpgradeResourceProvider.UPGRADE_DIRECTION, Direction.UPGRADE.name());

    cluster.setSecurityType(SecurityType.KERBEROS);

    RequestStageContainer requestStageContainer = createNiceMock(RequestStageContainer.class);
    expect(requestStageContainer.getStages()).andReturn(Lists.newArrayList()).once();

    expect(kerberosHelperMock.executeCustomOperations(eq(cluster), EasyMock.capture(requestPropertyMapCapture),
        EasyMock.anyObject(RequestStageContainer.class), eq(null))).andReturn(
        requestStageContainer).once();

    replayAll();

    ResourceProvider upgradeResourceProvider = createProvider(amc);
    Request request = PropertyHelper.getCreateRequest(Collections.singleton(requestProps), null);

    try {
      upgradeResourceProvider.createResources(request);
      Assert.fail("The mock request stage container should have caused a problem in JPA");
    } catch (IllegalArgumentException illegalArgumentException) {
      // ignore
    }

    verifyAll();

    Map<String, String> requestPropertyMap = requestPropertyMapCapture.getValue();
    assertEquals("true", requestPropertyMap.get(KerberosHelper.ALLOW_RETRY));
    assertEquals("missing", requestPropertyMap.get(KerberosHelperImpl.SupportedCustomOperation.REGENERATE_KEYTABS.name().toLowerCase()));
    assertEquals(UpdateConfigurationPolicy.NEW_AND_IDENTITIES.name(), requestPropertyMap.get(KerberosHelper.DIRECTIVE_CONFIG_UPDATE_POLICY.toLowerCase()));
  }
Tests that a {@link RegenerateKeytabsTask} causes the upgrade to inject the
correct stages.

@throws Exception
ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java