RootServiceResponseFactory extends
    AbstractRootServiceResponseFactory { @Override public Set<RootServiceComponentResponse> getRootServiceComponents( RootServiceComponentRequest request) throws ObjectNotFoundException { Set<RootServiceComponentResponse> response = new HashSet<RootServiceComponentResponse>(); String serviceName = request.getServiceName(); String componentName = request.getComponentName(); Services service; try { service = Services.valueOf(serviceName); } catch (IllegalArgumentException ex) { throw new ObjectNotFoundException("Root service name: " + serviceName); } catch (NullPointerException np) { throw new ObjectNotFoundException("Root service name: null"); } if (componentName != null) { Components component; try { component = Components.valueOf(componentName); if (!ArrayUtils.contains(service.getComponents(), component)) throw new ObjectNotFoundException("No component name: " + componentName + "in service: " + serviceName); } catch (IllegalArgumentException ex) { throw new ObjectNotFoundException("Component name: " + componentName); } response = Collections.singleton(new RootServiceComponentResponse(component.toString(), getComponentVersion(componentName, null), getComponentProperties(componentName))); } else { for (Components component: service.getComponents()) response.add(new RootServiceComponentResponse(component.toString(), getComponentVersion(component.name(), null), getComponentProperties(component.name()))); } return response; }  @Override Set<RootServiceResponse> getRootServices(RootServiceRequest request); @Override Set<RootServiceComponentResponse> getRootServiceComponents(
      RootServiceComponentRequest request); @Override Set<RootServiceHostComponentResponse> getRootServiceHostComponent(RootServiceHostComponentRequest request, Set<HostResponse> hosts); static final String NOT_APPLICABLE; }
@Test public void testGetRootServiceComponents() throws Exception { 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 = new RootServiceComponentRequest(null, ambariServerComponent.name()); try { rootServiceComponents = responseFactory.getRootServiceComponents(request); } catch (Exception e) { assertTrue(e instanceof ObjectNotFoundException); } 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 = 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 = new RootServiceComponentRequest( RootServiceResponseFactory.Services.AMBARI.name(), "XXX"); try { rootServiceComponents = responseFactory.getRootServiceComponents(request); } catch (Exception e) { assertTrue(e instanceof ObjectNotFoundException); } }