@Test
public void testUpdateKerberosDescriptorArtifact() throws Exception {

  final KerberosDescriptorFactory kerberosDescriptorFactory = new KerberosDescriptorFactory();
  KerberosServiceDescriptor serviceDescriptor;
  URL systemResourceURL = ClassLoader.getSystemResource("kerberos/test_kerberos_descriptor_2_1_3.json");
  assertNotNull(systemResourceURL);
  final KerberosDescriptor kerberosDescriptorOrig = kerberosDescriptorFactory.createInstance(new File(systemResourceURL.getFile()));
  assertNotNull(kerberosDescriptorOrig);
  serviceDescriptor = kerberosDescriptorOrig.getService("HDFS");
  assertNotNull(serviceDescriptor);
  assertNotNull(serviceDescriptor.getIdentity("hdfs"));
  serviceDescriptor = kerberosDescriptorOrig.getService("OOZIE");
  assertNotNull(serviceDescriptor);
  assertNotNull(serviceDescriptor.getIdentity("/HDFS/hdfs"));
  UpgradeCatalog220 upgradeMock = createMockBuilder(UpgradeCatalog220.class).createMock();
  Capture<Map<String, Object>> updatedData = EasyMock.newCapture();
  ArtifactEntity artifactEntity = createNiceMock(ArtifactEntity.class);
  expect(artifactEntity.getArtifactData())
      .andReturn(kerberosDescriptorOrig.toMap())
      .once();
  artifactEntity.setArtifactData(capture(updatedData));
  expectLastCall().once();
  replay(artifactEntity, upgradeMock);
  upgradeMock.updateKerberosDescriptorArtifact(createNiceMock(ArtifactDAO.class), artifactEntity);
  verify(artifactEntity, upgradeMock);
  KerberosDescriptor kerberosDescriptorUpdated = new KerberosDescriptorFactory().createInstance(updatedData.getValue());
  assertNotNull(kerberosDescriptorUpdated);
  serviceDescriptor = kerberosDescriptorUpdated.getService("HDFS");
  assertNotNull(serviceDescriptor);
  assertNull(serviceDescriptor.getIdentity("hdfs"));
  KerberosComponentDescriptor namenodeComponent = serviceDescriptor.getComponent("NAMENODE");
  assertNotNull(namenodeComponent.getIdentity("hdfs"));
  serviceDescriptor = kerberosDescriptorUpdated.getService("OOZIE");
  assertNotNull(serviceDescriptor);
  assertNull(serviceDescriptor.getIdentity("/HDFS/hdfs"));
  assertNotNull(serviceDescriptor.getIdentity("/HDFS/NAMENODE/hdfs"));
  // check execution with empty kerberos descriptor
  KerberosDescriptor kerberosDescriptor= new KerberosDescriptorFactory().createInstance(kerberosDescriptorOrig.toMap());
  ArtifactEntity artifactEntityOrig = createNiceMock(ArtifactEntity.class);
  kerberosDescriptor.getService("HDFS").removeIdentity("hdfs");
  expect(artifactEntityOrig.getArtifactData()).andReturn(kerberosDescriptor.toMap()).once();
 //expect(artifactDAO.merge((ArtifactEntity) anyObject())).andReturn(null).atLeastOnce();
  replay(artifactEntityOrig);
  upgradeMock.updateKerberosDescriptorArtifact(createNiceMock(ArtifactDAO.class), artifactEntityOrig);
  verify(artifactEntityOrig);
}