@Test
public void testUpgrade() throws Exception {

  Map<String, String> commandParams = new HashMap<String, String>();
  commandParams.put("clusterName", "c1");
  commandParams.put("upgrade_direction", "UPGRADE");
  commandParams.put("original_stack", "HDP-2.4");
  commandParams.put("target_stack", "HDP-2.5");
  ExecutionCommand executionCommand = new ExecutionCommand();
  executionCommand.setCommandParams(commandParams);
  executionCommand.setClusterName("c1");
  HostRoleCommand hrc = EasyMock.createMock(HostRoleCommand.class);
  expect(hrc.getRequestId()).andReturn(1L).anyTimes();
  expect(hrc.getStageId()).andReturn(2L).anyTimes();
  expect(hrc.getExecutionCommandWrapper()).andReturn(new ExecutionCommandWrapper(executionCommand)).anyTimes();
  replay(hrc);
  UpgradeUserKerberosDescriptor action = new UpgradeUserKerberosDescriptor();
  injectFields(action);
  action.setExecutionCommand(executionCommand);
  action.setHostRoleCommand(hrc);
  ArtifactEntity entity = EasyMock.createNiceMock(ArtifactEntity.class);
  expect(entity.getArtifactData()).andReturn(null).anyTimes();
  expect(entity.getForeignKeys()).andReturn(null).anyTimes();
  expect(artifactDAO.findByNameAndForeignKeys(anyString(), (TreeMap<String, String>) anyObject())).andReturn(entity).atLeastOnce();
  KerberosDescriptor userDescriptor = EasyMock.createMock(KerberosDescriptor.class);
  KerberosDescriptor newDescriptor = EasyMock.createMock(KerberosDescriptor.class);
  KerberosDescriptor previousDescriptor = EasyMock.createMock(KerberosDescriptor.class);
  KerberosDescriptor updatedKerberosDescriptor = EasyMock.createMock(KerberosDescriptor.class);
  PowerMockito.mockStatic(KerberosDescriptorUpdateHelper.class);
  PowerMockito.when(KerberosDescriptorUpdateHelper.updateUserKerberosDescriptor(previousDescriptor, newDescriptor, userDescriptor)).thenReturn(updatedKerberosDescriptor);
  expect(kerberosDescriptorFactory.createInstance((Map)null)).andReturn(userDescriptor).atLeastOnce();
  expect(ambariMetaInfo.getKerberosDescriptor("HDP","2.5")).andReturn(newDescriptor).atLeastOnce();
  expect(ambariMetaInfo.getKerberosDescriptor("HDP","2.4")).andReturn(previousDescriptor).atLeastOnce();
  expect(updatedKerberosDescriptor.toMap()).andReturn(null).once();
  expect(artifactDAO.merge(entity)).andReturn(entity).once();
  Capture<ArtifactEntity> createCapture = Capture.newInstance();
  artifactDAO.create(capture(createCapture));
  EasyMock.expectLastCall().once();
  replay(artifactDAO, entity, ambariMetaInfo, kerberosDescriptorFactory, updatedKerberosDescriptor);
  action.execute(null);
  verify(artifactDAO, updatedKerberosDescriptor);
  assertEquals(createCapture.getValue().getArtifactName(), "kerberos_descriptor_backup");
}