@Test
public void testTransitiveServices() throws AmbariException {

  ClusterImpl cluster = createMock(ClusterImpl.class);
  Service hdfsService = createMock(Service.class);
  ServiceComponent namenode = createMock(ServiceComponent.class);
  expect(namenode.getName()).andReturn("NAMENODE").anyTimes();
  Map<String,ServiceComponent> hdfsComponents = Collections.singletonMap("NAMENODE", namenode);
  expect(hdfsService.getServiceComponents()).andReturn(hdfsComponents).anyTimes();
  Service hbaseService = createMock(Service.class);
  expect(cluster.getService("HBASE")).andReturn(hbaseService).atLeastOnce();
  expect(cluster.getClusterId()).andReturn(1L);
  expect(hbaseService.getCluster()).andReturn(cluster).anyTimes();
  ServiceComponent hbaseMaster = createMock(ServiceComponent.class);
  expect(hbaseMaster.getName()).andReturn("HBASE_MASTER").anyTimes();
  Map<String, ServiceComponent> hbaseComponents = Collections.singletonMap(
      "HBASE_MASTER", hbaseMaster);
  expect(hbaseService.getServiceComponents()).andReturn(hbaseComponents).anyTimes();
  Map<String, Service> installedServices = new HashMap<String, Service>();
  installedServices.put("HDFS", hdfsService);
  installedServices.put("HBASE", hbaseService);
  expect(cluster.getServices()).andReturn(installedServices).atLeastOnce();
  expect(cluster.getService("HDFS")).andReturn(hdfsService).atLeastOnce();
  expect(cluster.getService("GLUSTERFS")).andReturn(null);
  expect(cluster.getService("YARN")).andReturn(null);
  expect(hdfsService.getServiceComponent("JOURNALNODE")).andReturn(null);
  expect(cluster.getCurrentStackVersion()).andReturn(new StackId("HDP", "2.0.5"));
  //replay
  replay(cluster, hdfsService, hbaseService, hbaseMaster, namenode);
  RoleCommandOrder rco = roleCommandOrderProvider.getRoleCommandOrder(cluster);
  Set<Service> transitiveServices = rco.getTransitiveServices(
      cluster.getService("HBASE"), RoleCommand.START);
  // HDFS should be started before HBASE start
  Assert.assertNotNull(transitiveServices);
  Assert.assertFalse(transitiveServices.isEmpty());
  Assert.assertEquals(1, transitiveServices.size());
  Assert.assertTrue(transitiveServices.contains(hdfsService));
}