@Test
public void testGetRootServiceComponents() throws Exception {

  // Request null service name, null component name
  RootServiceComponentRequest request = new RootServiceComponentRequest(null,
      null);
  Set<RootServiceComponentResponse> rootServiceComponents;
  try {
    rootServiceComponents = responseFactory.getRootServiceComponents(request);
  } catch (Exception e) {
    assertTrue(e instanceof ObjectNotFoundException);
  }
  RootServiceResponseFactory.Components ambariServerComponent = RootServiceResponseFactory.Components.AMBARI_SERVER;
  // Request null service name, not-null component name
  request = new RootServiceComponentRequest(null,
      ambariServerComponent.name());
  try {
    rootServiceComponents = responseFactory.getRootServiceComponents(request);
  } catch (Exception e) {
    assertTrue(e instanceof ObjectNotFoundException);
  }
  // Request existent service name, null component name
  request = new RootServiceComponentRequest(
      RootServiceResponseFactory.Services.AMBARI.name(), null);
  rootServiceComponents = responseFactory.getRootServiceComponents(request);
  assertEquals(
      RootServiceResponseFactory.Services.AMBARI.getComponents().length,
      rootServiceComponents.size());
  String ambariVersion = ambariMetaInfo.getServerVersion();
  for (int i = 0; i < RootServiceResponseFactory.Services.AMBARI.getComponents().length; i++) {
    Components component = RootServiceResponseFactory.Services.AMBARI.getComponents()[i];
    if (component.name().equals(ambariServerComponent.name())) {
      for (RootServiceComponentResponse response : rootServiceComponents) {
        if (response.getComponentName().equals(ambariServerComponent.name())) {
          assertEquals(ambariVersion, response.getComponentVersion());
          assertEquals(1, response.getProperties().size(), 1);
          assertTrue(response.getProperties().containsKey("jdk_location"));
        }
      }
    } else {
      assertTrue(rootServiceComponents.contains(new RootServiceComponentResponse(
          component.name(), RootServiceResponseFactory.NOT_APPLICABLE,
          Collections.<String, String> emptyMap())));
    }
  }
  // Request existent service name, existent component name
  request = new RootServiceComponentRequest(
      RootServiceResponseFactory.Services.AMBARI.name(),
      RootServiceResponseFactory.Services.AMBARI.getComponents()[0].name());
  rootServiceComponents = responseFactory.getRootServiceComponents(request);
  assertEquals(1, rootServiceComponents.size());
  for (RootServiceComponentResponse response : rootServiceComponents) {
    if (response.getComponentName().equals(
        RootServiceResponseFactory.Services.AMBARI.getComponents()[0].name())) {
      assertEquals(ambariVersion, response.getComponentVersion());
      assertEquals(2, response.getProperties().size());
      assertTrue(response.getProperties().containsKey("jdk_location"));
      assertTrue(response.getProperties().containsKey("java.version"));
    }
  }
  // Request existent service name, and component, not belongs to requested
  // service
  request = new RootServiceComponentRequest(
      RootServiceResponseFactory.Services.AMBARI.name(), "XXX");
  
  try {
    rootServiceComponents = responseFactory.getRootServiceComponents(request);
  } catch (Exception e) {
    assertTrue(e instanceof ObjectNotFoundException);
  }
}