@Test
  public void testUpdateKerberosDescriptorArtifact() throws Exception {

    Injector injector = getInjector();

    URL systemResourceURL = ClassLoader.getSystemResource("kerberos/test_kerberos_descriptor_ranger_kms.json");
    Assert.assertNotNull(systemResourceURL);

    final KerberosDescriptor kerberosDescriptor = new KerberosDescriptorFactory().createInstance(new File(systemResourceURL.getFile()));
    Assert.assertNotNull(kerberosDescriptor);

    KerberosServiceDescriptor serviceDescriptor;
    serviceDescriptor = kerberosDescriptor.getService("RANGER_KMS");
    Assert.assertNotNull(serviceDescriptor);
    Assert.assertNotNull(serviceDescriptor.getIdentity("/smokeuser"));
    Assert.assertNotNull(serviceDescriptor.getIdentity("/spnego"));

    KerberosComponentDescriptor componentDescriptor;
    componentDescriptor = serviceDescriptor.getComponent("RANGER_KMS_SERVER");
    Assert.assertNotNull(componentDescriptor);
    Assert.assertNotNull(componentDescriptor.getIdentity("/smokeuser"));
    Assert.assertNotNull(componentDescriptor.getIdentity("/spnego"));
    Assert.assertNotNull(componentDescriptor.getIdentity("/spnego").getPrincipalDescriptor());
    Assert.assertEquals("invalid_name@${realm}", componentDescriptor.getIdentity("/spnego").getPrincipalDescriptor().getValue());

    ArtifactEntity artifactEntity = createMock(ArtifactEntity.class);

    expect(artifactEntity.getArtifactData()).andReturn(kerberosDescriptor.toMap()).once();

    Capture<Map<String, Object>> captureMap = newCapture();
    expect(artifactEntity.getForeignKeys()).andReturn(Collections.singletonMap("cluster", "2")).times(2);
    artifactEntity.setArtifactData(capture(captureMap));
    expectLastCall().once();

    ConfigHelper configHelper = injector.getInstance(ConfigHelper.class);

    configHelper.updateAgentConfigs(anyObject(Set.class));
    expectLastCall().once();

    ArtifactDAO artifactDAO = createMock(ArtifactDAO.class);
    expect(artifactDAO.merge(artifactEntity)).andReturn(artifactEntity).atLeastOnce();

    Map<String, String> properties = new HashMap<>();
    properties.put("ranger.ks.kerberos.principal", "correct_value@EXAMPLE.COM");
    properties.put("xasecure.audit.jaas.Client.option.principal", "wrong_value@EXAMPLE.COM");

    Config config = createMock(Config.class);
    expect(config.getProperties()).andReturn(properties).anyTimes();
    expect(config.getPropertiesAttributes()).andReturn(Collections.<String, Map<String, String>>emptyMap()).anyTimes();
    expect(config.getTag()).andReturn("version1").anyTimes();
    expect(config.getType()).andReturn("ranger-kms-audit").anyTimes();

    Map<String, String> hsiProperties = new HashMap<>();
    hsiProperties.put("hive.llap.daemon.keytab.file", "/etc/security/keytabs/hive.service.keytab");
    hsiProperties.put("hive.llap.zk.sm.keytab.file", "/etc/security/keytabs/hive.llap.zk.sm.keytab");

    Config hsiConfig = createMock(Config.class);
    expect(hsiConfig.getProperties()).andReturn(hsiProperties).anyTimes();
    expect(hsiConfig.getPropertiesAttributes()).andReturn(Collections.<String, Map<String, String>>emptyMap()).anyTimes();
    expect(hsiConfig.getTag()).andReturn("version1").anyTimes();
    expect(hsiConfig.getType()).andReturn("hive-interactive-site").anyTimes();

    Config newConfig = createMock(Config.class);
    expect(newConfig.getTag()).andReturn("version2").anyTimes();
    expect(newConfig.getType()).andReturn("ranger-kms-audit").anyTimes();

    Config newHsiConfig = createMock(Config.class);
    expect(newHsiConfig.getTag()).andReturn("version2").anyTimes();
    expect(newHsiConfig.getType()).andReturn("hive-interactive-site").anyTimes();

    ServiceConfigVersionResponse response = createMock(ServiceConfigVersionResponse.class);
    ServiceConfigVersionResponse response1 = createMock(ServiceConfigVersionResponse.class);

    StackId stackId = createMock(StackId.class);

    Cluster cluster = createMock(Cluster.class);
    expect(cluster.getDesiredStackVersion()).andReturn(stackId).anyTimes();
    expect(cluster.getDesiredConfigByType("dbks-site")).andReturn(config).anyTimes();
    expect(cluster.getDesiredConfigByType("ranger-kms-audit")).andReturn(config).anyTimes();
    expect(cluster.getConfigsByType("ranger-kms-audit")).andReturn(Collections.singletonMap("version1", config)).anyTimes();
    expect(cluster.getServiceByConfigType("ranger-kms-audit")).andReturn("RANGER").anyTimes();
    expect(cluster.getClusterName()).andReturn("cl1").anyTimes();
    expect(cluster.getConfig(eq("ranger-kms-audit"), anyString())).andReturn(newConfig).once();
    expect(cluster.addDesiredConfig("ambari-upgrade", Collections.singleton(newConfig), "Updated ranger-kms-audit during Ambari Upgrade from 2.5.2 to 2.6.0.")).andReturn(response).once();

    //HIVE
    expect(cluster.getDesiredConfigByType("hive-site")).andReturn(hsiConfig).anyTimes();
    expect(cluster.getDesiredConfigByType("hive-interactive-site")).andReturn(hsiConfig).anyTimes();
    expect(cluster.getConfigsByType("hive-interactive-site")).andReturn(Collections.singletonMap("version1", hsiConfig)).anyTimes();
    expect(cluster.getServiceByConfigType("hive-interactive-site")).andReturn("HIVE").anyTimes();
    expect(cluster.getConfig(eq("hive-interactive-site"), anyString())).andReturn(newHsiConfig).anyTimes();


    final Clusters clusters = injector.getInstance(Clusters.class);
    expect(clusters.getCluster(2L)).andReturn(cluster).anyTimes();

    Capture<? extends Map<String, String>> captureProperties = newCapture();

    AmbariManagementController controller = injector.getInstance(AmbariManagementController.class);
    expect(controller.createConfig(eq(cluster), eq(stackId), eq("ranger-kms-audit"), capture(captureProperties), anyString(), anyObject(Map.class)))
        .andReturn(null)
        .once();

    Capture<? extends Map<String, String>> captureHsiProperties = newCapture();

    expect(controller.createConfig(eq(cluster), eq(stackId), eq("hive-interactive-site"), capture(captureHsiProperties), anyString(), anyObject(Map.class)))
            .andReturn(null)
            .anyTimes();

    replay(artifactDAO, artifactEntity, cluster, clusters, config, newConfig, hsiConfig, newHsiConfig, response, response1, controller, stackId, configHelper);

    UpgradeCatalog260 upgradeCatalog260 = injector.getInstance(UpgradeCatalog260.class);
    upgradeCatalog260.updateKerberosDescriptorArtifact(artifactDAO, artifactEntity);
    verify(artifactDAO, artifactEntity, cluster, clusters, config, newConfig, response, controller, stackId, configHelper);
    KerberosDescriptor kerberosDescriptorUpdated = new KerberosDescriptorFactory().createInstance(captureMap.getValue());
    Assert.assertNotNull(kerberosDescriptorUpdated);

    Assert.assertNull(kerberosDescriptorUpdated.getService("RANGER_KMS").getIdentity("/smokeuser"));
    Assert.assertNull(kerberosDescriptorUpdated.getService("RANGER_KMS").getComponent("RANGER_KMS_SERVER").getIdentity("/smokeuser"));

    KerberosIdentityDescriptor identity;

    Assert.assertNull(kerberosDescriptorUpdated.getService("RANGER_KMS").getIdentity("/spnego"));
    identity = kerberosDescriptorUpdated.getService("RANGER_KMS").getIdentity("ranger_kms_spnego");
    Assert.assertNotNull(identity);
    Assert.assertEquals("/spnego", identity.getReference());

    Assert.assertNull(kerberosDescriptorUpdated.getService("RANGER_KMS").getComponent("RANGER_KMS_SERVER").getIdentity("/spnego"));
    identity = kerberosDescriptorUpdated.getService("RANGER_KMS").getComponent("RANGER_KMS_SERVER").getIdentity("ranger_kms_ranger_kms_server_spnego");
    Assert.assertNotNull(identity);
    Assert.assertEquals("/spnego", identity.getReference());
    Assert.assertNotNull(identity.getPrincipalDescriptor());
    Assert.assertNull(identity.getPrincipalDescriptor().getValue());

    Assert.assertTrue(captureProperties.hasCaptured());
    Map<String, String> newProperties = captureProperties.getValue();
    Assert.assertEquals("correct_value@EXAMPLE.COM", newProperties.get("xasecure.audit.jaas.Client.option.principal"));

    // YARN's NodeManager identities (1). 'llap_zk_hive' and (2). 'llap_task_hive' checks after modifications.
    Map<String, List<String>> identitiesMap = new HashMap<>();
    identitiesMap.put("llap_zk_hive", new ArrayList<String>() {{
      add("hive-interactive-site/hive.llap.zk.sm.keytab.file");
      add("hive-interactive-site/hive.llap.zk.sm.principal");
    }});
    identitiesMap.put("llap_task_hive", new ArrayList<String>() {{
      add("hive-interactive-site/hive.llap.task.keytab.file");
      add("hive-interactive-site/hive.llap.task.principal");
    }});
    for (String llapIdentity : identitiesMap.keySet()) {
      KerberosIdentityDescriptor yarnKerberosIdentityDescriptor = kerberosDescriptorUpdated.getService("YARN").getComponent("NODEMANAGER").getIdentity(llapIdentity);
      Assert.assertNotNull(yarnKerberosIdentityDescriptor);
      Assert.assertEquals("/HIVE/HIVE_SERVER/hive_server_hive", yarnKerberosIdentityDescriptor.getReference());

      KerberosKeytabDescriptor yarnKerberosKeytabDescriptor = yarnKerberosIdentityDescriptor.getKeytabDescriptor();
      Assert.assertNotNull(yarnKerberosKeytabDescriptor);

      Assert.assertEquals(null, yarnKerberosKeytabDescriptor.getGroupAccess());
      Assert.assertEquals(null, yarnKerberosKeytabDescriptor.getGroupName());
      Assert.assertEquals(null, yarnKerberosKeytabDescriptor.getOwnerAccess());
      Assert.assertEquals(null, yarnKerberosKeytabDescriptor.getOwnerName());
      Assert.assertEquals(null, yarnKerberosKeytabDescriptor.getFile());
      Assert.assertEquals(identitiesMap.get(llapIdentity).get(0), yarnKerberosKeytabDescriptor.getConfiguration());

      KerberosPrincipalDescriptor yarnKerberosPrincipalDescriptor = yarnKerberosIdentityDescriptor.getPrincipalDescriptor();
      Assert.assertNotNull(yarnKerberosPrincipalDescriptor);
      Assert.assertEquals(null, yarnKerberosPrincipalDescriptor.getName());
      Assert.assertEquals(KerberosPrincipalType.SERVICE, yarnKerberosPrincipalDescriptor.getType());
      Assert.assertEquals(null, yarnKerberosPrincipalDescriptor.getValue());
      Assert.assertEquals(identitiesMap.get(llapIdentity).get(1), yarnKerberosPrincipalDescriptor.getConfiguration());
    }
  }
Sets expectations for DDL work on the
{@link UpgradeCatalog260#REPO_VERSION_TABLE}.

@param hiddenColumnCapture
@throws SQLException
ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog260Test.java