@Test
public void testDeleteService() throws Exception {

  // Given
  String serviceToDelete = "TEZ";
  String clusterName = "TEST_CLUSTER";
  String hostName1 = "HOST1", hostName2 = "HOST2";
  clusters.addCluster(clusterName, new StackId("HDP-2.1.1"));
  Cluster cluster = clusters.getCluster(clusterName);
  clusters.addHost(hostName1);
  clusters.addHost(hostName2);
  Host host1 = clusters.getHost(hostName1);
  host1.setHostAttributes(ImmutableMap.of("os_family", "centos", "os_release_version", "6.0"));
  Host host2 = clusters.getHost(hostName2);
  host2.setHostAttributes(ImmutableMap.of("os_family", "centos", "os_release_version", "6.0"));
  clusters.mapAndPublishHostsToCluster(Sets.newHashSet(hostName1, hostName2), clusterName);
  Service hdfs = cluster.addService("HDFS");
  ServiceComponent nameNode = hdfs.addServiceComponent("NAMENODE");
  nameNode.addServiceComponentHost(hostName1);
  ServiceComponent dataNode = hdfs.addServiceComponent("DATANODE");
  dataNode.addServiceComponentHost(hostName1);
  dataNode.addServiceComponentHost(hostName2);
  ServiceComponent hdfsClient = hdfs.addServiceComponent("HDFS_CLIENT");
  hdfsClient.addServiceComponentHost(hostName1);
  hdfsClient.addServiceComponentHost(hostName2);
  Service tez = cluster.addService(serviceToDelete);
  ServiceComponent tezClient = tez.addServiceComponent("TEZ_CLIENT");
  ServiceComponentHost tezClientHost1 =  tezClient.addServiceComponentHost(hostName1);
  ServiceComponentHost tezClientHost2 = tezClient.addServiceComponentHost(hostName2);
  // When
  cluster.deleteService(serviceToDelete);
  // Then
  assertFalse("Deleted service should be removed from the service collection !", cluster.getServices().containsKey(serviceToDelete));
  assertEquals("All components of the deleted service should be removed from all hosts", 0, cluster.getServiceComponentHosts(serviceToDelete, null).size());
  boolean checkHost1 = !cluster.getServiceComponentHosts(hostName1).contains(tezClientHost1);
  boolean checkHost2 = !cluster.getServiceComponentHosts(hostName2).contains(tezClientHost2);
  assertTrue("All components of the deleted service should be removed from all hosts", checkHost1 && checkHost2);
}