@Test
public void testUpdateKerberosDescriptorArtifact() throws Exception {

  final String propertyToRemove = "yarn.nodemanager.linux-container-executor.cgroups.mount-path";
  final KerberosDescriptorFactory kerberosDescriptorFactory = new KerberosDescriptorFactory();
  KerberosServiceDescriptor serviceDescriptor;
  URL systemResourceURL = ClassLoader.getSystemResource("kerberos/test_kerberos_descriptor_2_5_infra_solr.json");
  Assert.assertNotNull(systemResourceURL);
  final KerberosDescriptor kerberosDescriptorOrig = kerberosDescriptorFactory.createInstance(new File(systemResourceURL.getFile()));
  serviceDescriptor = kerberosDescriptorOrig.getService("LOGSEARCH");
  Assert.assertNotNull(serviceDescriptor);
  Assert.assertNotNull(serviceDescriptor.getComponent("LOGSEARCH_SERVER"));
  Assert.assertNotNull(serviceDescriptor.getComponent("LOGSEARCH_SERVER").getIdentity("logsearch"));
  Assert.assertNotNull(serviceDescriptor.getComponent("LOGSEARCH_SERVER").getIdentity("/AMBARI_INFRA/INFRA_SOLR/infra-solr"));
  serviceDescriptor = kerberosDescriptorOrig.getService("ATLAS");
  Assert.assertNotNull(serviceDescriptor);
  Assert.assertNotNull(serviceDescriptor.getComponent("ATLAS_SERVER"));
  serviceDescriptor = kerberosDescriptorOrig.getService("RANGER");
  Assert.assertNotNull(serviceDescriptor);
  Assert.assertNotNull(serviceDescriptor.getComponent("RANGER_ADMIN"));
  serviceDescriptor = kerberosDescriptorOrig.getService("STORM");
  Assert.assertNotNull(serviceDescriptor);
  Assert.assertNotNull(serviceDescriptor.getComponent("NIMBUS"));
  UpgradeCatalog250 upgradeMock = createMockBuilder(UpgradeCatalog250.class).withConstructor(injector).createMock();
  ArtifactEntity artifactEntity = createNiceMock(ArtifactEntity.class);
  expect(artifactEntity.getArtifactData())
      .andReturn(kerberosDescriptorOrig.toMap())
      .once();
  Capture<Map<String, Object>> updateData = Capture.newInstance(CaptureType.ALL);
  artifactEntity.setArtifactData(capture(updateData));
  expectLastCall().times(1);
  ArtifactDAO artifactDAO = createNiceMock(ArtifactDAO.class);
  expect(artifactDAO.merge(anyObject(ArtifactEntity.class))).andReturn(artifactEntity).times(1);
  replay(artifactEntity, artifactDAO, upgradeMock);
  upgradeMock.updateKerberosDescriptorArtifact(artifactDAO, artifactEntity);
  verify(artifactEntity, artifactDAO, upgradeMock);
  KerberosDescriptor kerberosDescriptorUpdated = new KerberosDescriptorFactory().createInstance(updateData.getValue());
  getIdentity(kerberosDescriptorUpdated,null, null, "spnego");
  getIdentity(kerberosDescriptorUpdated,"LOGSEARCH", "LOGSEARCH_SERVER", "/AMBARI_INFRA/INFRA_SOLR/infra-solr");
  getIdentity(kerberosDescriptorUpdated,"ATLAS", "ATLAS_SERVER", "/AMBARI_INFRA/INFRA_SOLR/infra-solr");
  getIdentity(kerberosDescriptorUpdated,"RANGER", "RANGER_ADMIN", "/AMBARI_INFRA/INFRA_SOLR/infra-solr");
  getIdentity(kerberosDescriptorUpdated,"STORM", "NIMBUS", "/STORM/storm_components");
  Assert.assertFalse(kerberosDescriptorUpdated.getService("YARN").getConfigurations().get("yarn-site").getProperties().containsKey(propertyToRemove));
  KerberosIdentityDescriptor rangerHbaseAuditIdentityDescriptor = getIdentity(kerberosDescriptorUpdated,"HBASE", "HBASE_MASTER", "ranger_hbase_audit");
  KerberosPrincipalDescriptor rangerHbaseAuditPrincipalDescriptor = rangerHbaseAuditIdentityDescriptor.getPrincipalDescriptor();
  Assert.assertNotNull(rangerHbaseAuditPrincipalDescriptor);
  Assert.assertNull(rangerHbaseAuditPrincipalDescriptor.getValue());
  KerberosKeytabDescriptor rangerHbaseAuditKeytabDescriptor = rangerHbaseAuditIdentityDescriptor.getKeytabDescriptor();
  Assert.assertNotNull(rangerHbaseAuditKeytabDescriptor);
  Assert.assertNull(rangerHbaseAuditKeytabDescriptor.getFile());
}