@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<>();
    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"));
    expect(hdfsService.getDesiredStackId()).andReturn(new StackId("HDP", "2.0.5"));
    expect(hbaseService.getDesiredStackId()).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));
  }
Tests building dependencies in HA-enabled HDFS cluster. Uses real
dependency mapping file (role_command_order.json)
ambari-server/src/test/java/org/apache/ambari/server/metadata/RoleCommandOrderTest.java