@Test
public void testAddInstallCommand() throws Exception {

  InputStream metainfo_1 = new ByteArrayInputStream(metainfo_1_str.getBytes());
  Metainfo metainfo = new MetainfoParser().fromXmlStream(metainfo_1);
  AgentProviderService aps = createAgentProviderService(new Configuration());
  HeartBeatResponse hbr = new HeartBeatResponse();
  StateAccessForProviders access = createNiceMock(StateAccessForProviders.class);
  AgentProviderService mockAps = Mockito.spy(aps);
  doReturn(access).when(mockAps).getAmState();
  AggregateConf aggConf = new AggregateConf();
  ConfTreeOperations treeOps = aggConf.getAppConfOperations();
  treeOps.getGlobalOptions().put(AgentKeys.JAVA_HOME, "java_home");
  treeOps.set(OptionKeys.APPLICATION_NAME, "HBASE");
  treeOps.set("site.fs.defaultFS", "hdfs://HOST1:8020/");
  treeOps.set("internal.data.dir.path", "hdfs://HOST1:8020/database");
  treeOps.set(OptionKeys.ZOOKEEPER_HOSTS, "HOST1");
  expect(access.getAppConfSnapshot()).andReturn(treeOps).anyTimes();
  expect(access.getInternalsSnapshot()).andReturn(treeOps).anyTimes();
  expect(access.isApplicationLive()).andReturn(true).anyTimes();
  doReturn("HOST1").when(mockAps).getClusterInfoPropertyValue(anyString());
  doReturn(metainfo).when(mockAps).getMetaInfo(anyString());
  doReturn(new HashMap<String, DefaultConfig>()).when(mockAps).getDefaultConfigs(anyString());
  Map<String, Map<String, ClusterNode>> roleClusterNodeMap = new HashMap<String, Map<String, ClusterNode>>();
  Map<String, ClusterNode> container = new HashMap<String, ClusterNode>();
  ClusterNode cn1 = new ClusterNode(new MockContainerId(1));
  cn1.host = "HOST1";
  container.put("cid1", cn1);
  roleClusterNodeMap.put("HBASE_MASTER", container);
  doReturn(roleClusterNodeMap).when(mockAps).getRoleClusterNodeMapping();
  replay(access);
  mockAps.addInstallCommand("HBASE_MASTER", "HBASE_MASTER", "cid1", hbr, "", null, 0, null);
  ExecutionCommand cmd = hbr.getExecutionCommands().get(0);
  String pkgs = cmd.getHostLevelParams().get(AgentKeys.PACKAGE_LIST);
  Assert.assertEquals("[{\"type\":\"tarball\",\"name\":\"files/hbase-0.96.1-hadoop2-bin.tar.gz\"}]", pkgs);
  Assert.assertEquals("java_home", cmd.getHostLevelParams().get(AgentKeys.JAVA_HOME));
  Assert.assertEquals("cid1", cmd.getHostLevelParams().get("container_id"));
  Assert.assertEquals(Command.INSTALL.toString(), cmd.getRoleCommand());
  Assert.assertTrue(cmd.getConfigurations().get("global").containsKey("app_log_dir"));
  Assert.assertTrue(cmd.getConfigurations().get("global").containsKey("app_pid_dir"));
  Assert.assertTrue(cmd.getConfigurations().get("global").containsKey("app_install_dir"));
  Assert.assertTrue(cmd.getConfigurations().get("global").containsKey("app_input_conf_dir"));
  Assert.assertTrue(cmd.getConfigurations().get("global").containsKey("app_container_id"));
  Assert.assertTrue(cmd.getConfigurations().get("global").containsKey("pid_file"));
  Assert.assertTrue(cmd.getConfigurations().get("global").containsKey("app_root"));
}