@Test
public void testDowngrade() throws Exception {

  Map<String, String> commandParams = new HashMap<String, String>();
  commandParams.put("clusterName", "c1");
  commandParams.put("upgrade_direction", "DOWNGRADE");
  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);
  expect(kerberosDescriptorFactory.createInstance((Map)null)).andReturn(userDescriptor).atLeastOnce();
  Capture<ArtifactEntity> createCapture = Capture.newInstance();
  artifactDAO.create(capture(createCapture));
  EasyMock.expectLastCall().once();
  artifactDAO.remove(entity);
  EasyMock.expectLastCall().atLeastOnce();
  replay(artifactDAO, entity, ambariMetaInfo, kerberosDescriptorFactory);
  action.execute(null);
  verify(artifactDAO);
  assertEquals(createCapture.getValue().getArtifactName(), "kerberos_descriptor");
}