@Test
  public void testExecutionCommandHasVersionInfoWithoutCurrentClusterVersion()
      throws JSONException, AmbariException {
    Cluster cluster = clusters.getCluster(CLUSTER1);

    StackId stackId = cluster.getDesiredStackVersion();

    // set the repo version resolved state to verify that the version is not sent
    RepositoryVersionEntity repositoryVersion = ormTestHelper.getOrCreateRepositoryVersion(stackId, "0.1-0000");
    repositoryVersion.setResolved(false);
    ormTestHelper.repositoryVersionDAO.merge(repositoryVersion);

    Service service = cluster.getService("HDFS");
    service.setDesiredRepositoryVersion(repositoryVersion);

    // first try with an INSTALL command - this should not populate version info
    ExecutionCommand executionCommand = new ExecutionCommand();
    Map<String, String> commandParams = new HashMap<>();

    executionCommand.setClusterName(CLUSTER1);
    executionCommand.setTaskId(1);
    executionCommand.setRequestAndStage(1, 1);
    executionCommand.setHostname(HOST1);
    executionCommand.setRole("NAMENODE");
    executionCommand.setRoleParams(Collections.<String, String>emptyMap());
    executionCommand.setRoleCommand(RoleCommand.INSTALL);
    executionCommand.setServiceName("HDFS");
    executionCommand.setCommandType(AgentCommandType.EXECUTION_COMMAND);
    executionCommand.setCommandParams(commandParams);

    String json = StageUtils.getGson().toJson(executionCommand, ExecutionCommand.class);
    ExecutionCommandWrapper execCommWrap = new ExecutionCommandWrapper(json);
    injector.injectMembers(execCommWrap);

    ExecutionCommand processedExecutionCommand = execCommWrap.getExecutionCommand();
    commandParams = processedExecutionCommand.getCommandParams();
    Assert.assertFalse(commandParams.containsKey(KeyNames.VERSION));

    // now try with a START command, but still unresolved
    executionCommand = new ExecutionCommand();
    commandParams = new HashMap<>();

    executionCommand.setClusterName(CLUSTER1);
    executionCommand.setTaskId(1);
    executionCommand.setRequestAndStage(1, 1);
    executionCommand.setHostname(HOST1);
    executionCommand.setRole("NAMENODE");
    executionCommand.setRoleParams(Collections.<String, String> emptyMap());
    executionCommand.setRoleCommand(RoleCommand.START);
    executionCommand.setServiceName("HDFS");
    executionCommand.setCommandType(AgentCommandType.EXECUTION_COMMAND);
    executionCommand.setCommandParams(commandParams);

    json = StageUtils.getGson().toJson(executionCommand, ExecutionCommand.class);
    execCommWrap = new ExecutionCommandWrapper(json);
    injector.injectMembers(execCommWrap);

    processedExecutionCommand = execCommWrap.getExecutionCommand();
    commandParams = processedExecutionCommand.getCommandParams();
    Assert.assertFalse(commandParams.containsKey(KeyNames.VERSION));

    // now that the repositoryVersion is resolved, it should populate the version even
    // though the state is INSTALLING
    repositoryVersion.setResolved(true);
    ormTestHelper.repositoryVersionDAO.merge(repositoryVersion);
    execCommWrap = new ExecutionCommandWrapper(json);
    injector.injectMembers(execCommWrap);

    processedExecutionCommand = execCommWrap.getExecutionCommand();
    commandParams = processedExecutionCommand.getCommandParams();
    Assert.assertEquals("0.1-0000", commandParams.get(KeyNames.VERSION));
    }
Test that the execution command wrapper properly sets the version
information when the cluster is in the INSTALLING state.

@throws JSONException
@throws AmbariException
ambari-server/src/test/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapperTest.java