ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maha...@apache.org
Subject svn commit: r1431843 [9/10] - in /incubator/ambari/trunk: ./ ambari-agent/ ambari-agent/conf/unix/ ambari-agent/src/main/package/rpm/ ambari-agent/src/main/puppet/modules/configgenerator/manifests/ ambari-agent/src/main/puppet/modules/hdp-ganglia/manif...
Date Fri, 11 Jan 2013 03:02:41 GMT
Added: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java?rev=1431843&view=auto
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java (added)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java Fri Jan 11 03:02:37 2013
@@ -0,0 +1,1463 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.controller;
+
+import com.google.gson.Gson;
+import com.google.inject.Injector;
+import org.apache.ambari.server.*;
+import org.apache.ambari.server.api.services.AmbariMetaInfo;
+import org.apache.ambari.server.state.*;
+import org.easymock.Capture;
+import org.junit.Test;
+
+import java.lang.reflect.Field;
+import java.util.*;
+
+import static org.junit.Assert.*;
+import static org.easymock.EasyMock.*;
+
+/**
+ * AmbariManagementControllerImpl unit tests
+ */
+public class AmbariManagementControllerImplTest {
+
+  @Test
+  public void testGetClusters() throws Exception {
+    // member state mocks
+    Injector injector = createStrictMock(Injector.class);
+    Capture<AmbariManagementController> controllerCapture = new Capture<AmbariManagementController>();
+    Clusters clusters = createNiceMock(Clusters.class);
+
+    ClusterRequest request1 = new ClusterRequest(null, "cluster1", "1", Collections.<String>emptySet());
+    Cluster cluster = createNiceMock(Cluster.class);
+    ClusterResponse response = createNiceMock(ClusterResponse.class);
+
+    Set<ClusterRequest> setRequests = new HashSet<ClusterRequest>();
+    setRequests.add(request1);
+
+    // expectations
+    // constructor init
+    injector.injectMembers(capture(controllerCapture));
+    expect(injector.getInstance(Gson.class)).andReturn(null);
+
+    // getClusters
+    expect(clusters.getCluster("cluster1")).andReturn(cluster);
+    expect(cluster.convertToResponse()).andReturn(response);
+
+    // replay mocks
+    replay(injector, clusters, cluster, response);
+
+    // test
+    AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector);
+    Set<ClusterResponse> setResponses = controller.getClusters(setRequests);
+
+    // assert and verify
+    assertEquals(1, setResponses.size());
+    assertTrue(setResponses.contains(response));
+
+    verify(injector, clusters, cluster, response);
+  }
+
+  /**
+   * Ensure that ClusterNotFoundException is propagated in case where there is a single request.
+   */
+  @Test
+  public void testGetClusters___ClusterNotFoundException() throws Exception {
+    // member state mocks
+    Injector injector = createStrictMock(Injector.class);
+    Capture<AmbariManagementController> controllerCapture = new Capture<AmbariManagementController>();
+    Clusters clusters = createNiceMock(Clusters.class);
+
+    // requests
+    ClusterRequest request1 = new ClusterRequest(null, "cluster1", "1", Collections.<String>emptySet());
+
+    Set<ClusterRequest> setRequests = new HashSet<ClusterRequest>();
+    setRequests.add(request1);
+
+    // expectations
+    // constructor init
+    injector.injectMembers(capture(controllerCapture));
+    expect(injector.getInstance(Gson.class)).andReturn(null);
+
+    // getClusters
+    expect(clusters.getCluster("cluster1")).andThrow(new ClusterNotFoundException("cluster1"));
+
+    // replay mocks
+    replay(injector, clusters);
+
+    //test
+    AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector);
+
+    // assert that exception is thrown in case where there is a single request
+    try {
+      controller.getClusters(setRequests);
+      fail("expected ClusterNotFoundException");
+    } catch (ClusterNotFoundException e) {
+      // expected
+    }
+
+    verify(injector, clusters);
+  }
+
+  /**
+   * Ensure that ClusterNotFoundException is handled where there are multiple requests as would be the
+   * case when an OR predicate is provided in the query.
+   */
+  @Test
+  public void testGetClusters___OR_Predicate_ClusterNotFoundException() throws Exception {
+    // member state mocks
+    Injector injector = createStrictMock(Injector.class);
+    Capture<AmbariManagementController> controllerCapture = new Capture<AmbariManagementController>();
+    Clusters clusters = createNiceMock(Clusters.class);
+
+    Cluster cluster = createNiceMock(Cluster.class);
+    Cluster cluster2 = createNiceMock(Cluster.class);
+    ClusterResponse response = createNiceMock(ClusterResponse.class);
+    ClusterResponse response2 = createNiceMock(ClusterResponse.class);
+
+    // requests
+    ClusterRequest request1 = new ClusterRequest(null, "cluster1", "1", Collections.<String>emptySet());
+    ClusterRequest request2 = new ClusterRequest(null, "cluster2", "1", Collections.<String>emptySet());
+    ClusterRequest request3 = new ClusterRequest(null, "cluster3", "1", Collections.<String>emptySet());
+    ClusterRequest request4 = new ClusterRequest(null, "cluster4", "1", Collections.<String>emptySet());
+
+    Set<ClusterRequest> setRequests = new HashSet<ClusterRequest>();
+    setRequests.add(request1);
+    setRequests.add(request2);
+    setRequests.add(request3);
+    setRequests.add(request4);
+
+    // expectations
+    // constructor init
+    injector.injectMembers(capture(controllerCapture));
+    expect(injector.getInstance(Gson.class)).andReturn(null);
+
+    // getClusters
+    expect(clusters.getCluster("cluster1")).andThrow(new ClusterNotFoundException("cluster1"));
+    expect(clusters.getCluster("cluster2")).andReturn(cluster);
+    expect(clusters.getCluster("cluster3")).andReturn(cluster2);
+    expect(clusters.getCluster("cluster4")).andThrow(new ClusterNotFoundException("cluster4"));
+
+    expect(cluster.convertToResponse()).andReturn(response);
+    expect(cluster2.convertToResponse()).andReturn(response2);
+    // replay mocks
+    replay(injector, clusters, cluster, cluster2, response, response2);
+
+    //test
+    AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector);
+    Set<ClusterResponse> setResponses = controller.getClusters(setRequests);
+
+    // assert and verify
+    assertSame(controller, controllerCapture.getValue());
+    assertEquals(2, setResponses.size());
+    assertTrue(setResponses.contains(response));
+    assertTrue(setResponses.contains(response2));
+
+    verify(injector, clusters, cluster, cluster2, response, response2);
+  }
+
+  @Test
+  public void testGetServices() throws Exception {
+    // member state mocks
+    Injector injector = createStrictMock(Injector.class);
+    Capture<AmbariManagementController> controllerCapture = new Capture<AmbariManagementController>();
+    Clusters clusters = createNiceMock(Clusters.class);
+
+    Cluster cluster = createNiceMock(Cluster.class);
+    Service service = createNiceMock(Service.class);
+    ServiceResponse response = createNiceMock(ServiceResponse.class);
+
+    // requests
+    ServiceRequest request1 = new ServiceRequest("cluster1", "service1", Collections.<String, String>emptyMap(), null);
+
+    Set<ServiceRequest> setRequests = new HashSet<ServiceRequest>();
+    setRequests.add(request1);
+
+    // expectations
+    // constructor init
+    injector.injectMembers(capture(controllerCapture));
+    expect(injector.getInstance(Gson.class)).andReturn(null);
+
+    // getServices
+    expect(clusters.getCluster("cluster1")).andReturn(cluster);
+    expect(cluster.getService("service1")).andReturn(service);
+
+    expect(service.convertToResponse()).andReturn(response);
+    // replay mocks
+    replay(injector, clusters, cluster, service, response);
+
+    //test
+    AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector);
+    Set<ServiceResponse> setResponses = controller.getServices(setRequests);
+
+    // assert and verify
+    assertSame(controller, controllerCapture.getValue());
+    assertEquals(1, setResponses.size());
+    assertTrue(setResponses.contains(response));
+
+    verify(injector, clusters, cluster, service, response);
+  }
+
+  /**
+   * Ensure that ServiceNotFoundException is propagated in case where there is a single request.
+   */
+  @Test
+  public void testGetServices___ServiceNotFoundException() throws Exception {
+    // member state mocks
+    Injector injector = createStrictMock(Injector.class);
+    Capture<AmbariManagementController> controllerCapture = new Capture<AmbariManagementController>();
+    Clusters clusters = createNiceMock(Clusters.class);
+
+    Cluster cluster = createNiceMock(Cluster.class);
+
+    // requests
+    ServiceRequest request1 = new ServiceRequest("cluster1", "service1", Collections.<String, String>emptyMap(), null);
+    Set<ServiceRequest> setRequests = new HashSet<ServiceRequest>();
+    setRequests.add(request1);
+
+    // expectations
+    // constructor init
+    injector.injectMembers(capture(controllerCapture));
+    expect(injector.getInstance(Gson.class)).andReturn(null);
+
+    // getServices
+    expect(clusters.getCluster("cluster1")).andReturn(cluster);
+    expect(cluster.getService("service1")).andThrow(new ServiceNotFoundException("custer1", "service1"));
+
+    // replay mocks
+    replay(injector, clusters, cluster);
+
+    //test
+    AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector);
+
+    // assert that exception is thrown in case where there is a single request
+    try {
+      controller.getServices(setRequests);
+      fail("expected ServiceNotFoundException");
+    } catch (ServiceNotFoundException e) {
+      // expected
+    }
+
+    assertSame(controller, controllerCapture.getValue());
+    verify(injector, clusters, cluster);
+  }
+
+  /**
+   * Ensure that ServiceNotFoundException is handled where there are multiple requests as would be the
+   * case when an OR predicate is provided in the query.
+   */
+  @Test
+  public void testGetServices___OR_Predicate_ServiceNotFoundException() throws Exception {
+    // member state mocks
+    Injector injector = createStrictMock(Injector.class);
+    Capture<AmbariManagementController> controllerCapture = new Capture<AmbariManagementController>();
+    Clusters clusters = createNiceMock(Clusters.class);
+
+    Cluster cluster = createNiceMock(Cluster.class);
+    Service service1 = createNiceMock(Service.class);
+    Service service2 = createNiceMock(Service.class);
+    ServiceResponse response = createNiceMock(ServiceResponse.class);
+    ServiceResponse response2 = createNiceMock(ServiceResponse.class);
+
+    // requests
+    ServiceRequest request1 = new ServiceRequest("cluster1", "service1", Collections.<String, String>emptyMap(), null);
+    ServiceRequest request2 = new ServiceRequest("cluster1", "service2", Collections.<String, String>emptyMap(), null);
+    ServiceRequest request3 = new ServiceRequest("cluster1", "service3", Collections.<String, String>emptyMap(), null);
+    ServiceRequest request4 = new ServiceRequest("cluster1", "service4", Collections.<String, String>emptyMap(), null);
+
+    Set<ServiceRequest> setRequests = new HashSet<ServiceRequest>();
+    setRequests.add(request1);
+    setRequests.add(request2);
+    setRequests.add(request3);
+    setRequests.add(request4);
+
+    // expectations
+    // constructor init
+    injector.injectMembers(capture(controllerCapture));
+    expect(injector.getInstance(Gson.class)).andReturn(null);
+
+    // getServices
+    expect(clusters.getCluster("cluster1")).andReturn(cluster).times(4);
+    expect(cluster.getService("service1")).andReturn(service1);
+    expect(cluster.getService("service2")).andThrow(new ServiceNotFoundException("cluster1", "service2"));
+    expect(cluster.getService("service3")).andThrow(new ServiceNotFoundException("cluster1", "service3"));
+    expect(cluster.getService("service4")).andReturn(service2);
+
+    expect(service1.convertToResponse()).andReturn(response);
+    expect(service2.convertToResponse()).andReturn(response2);
+    // replay mocks
+    replay(injector, clusters, cluster, service1, service2, response, response2);
+
+    //test
+    AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector);
+    Set<ServiceResponse> setResponses = controller.getServices(setRequests);
+
+    // assert and verify
+    assertSame(controller, controllerCapture.getValue());
+    assertEquals(2, setResponses.size());
+    assertTrue(setResponses.contains(response));
+    assertTrue(setResponses.contains(response2));
+
+    verify(injector, clusters, cluster, service1, service2, response, response2);
+  }
+
+  @Test
+  public void testGetComponents() throws Exception {
+    // member state mocks
+    Injector injector = createStrictMock(Injector.class);
+    Capture<AmbariManagementController> controllerCapture = new Capture<AmbariManagementController>();
+    Clusters clusters = createNiceMock(Clusters.class);
+
+    Cluster cluster = createNiceMock(Cluster.class);
+    Service service = createNiceMock(Service.class);
+    ServiceComponent component = createNiceMock(ServiceComponent.class);
+    ServiceComponentResponse response = createNiceMock(ServiceComponentResponse.class);
+
+    // requests
+    ServiceComponentRequest request1 = new ServiceComponentRequest("cluster1", "service1", "component1",
+        Collections.<String, String>emptyMap(), null);
+
+    Set<ServiceComponentRequest> setRequests = new HashSet<ServiceComponentRequest>();
+    setRequests.add(request1);
+
+    // expectations
+    // constructor init
+    injector.injectMembers(capture(controllerCapture));
+    expect(injector.getInstance(Gson.class)).andReturn(null);
+
+    // getComponents
+    expect(clusters.getCluster("cluster1")).andReturn(cluster);
+    expect(cluster.getService("service1")).andReturn(service);
+    expect(service.getServiceComponent("component1")).andReturn(component);
+
+    expect(component.convertToResponse()).andReturn(response);
+    // replay mocks
+    replay(injector, clusters, cluster, service, component, response);
+
+    //test
+    AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector);
+    Set<ServiceComponentResponse> setResponses = controller.getComponents(setRequests);
+
+    // assert and verify
+    assertSame(controller, controllerCapture.getValue());
+    assertEquals(1, setResponses.size());
+    assertTrue(setResponses.contains(response));
+
+    verify(injector, clusters, cluster, service, component, response);
+  }
+
+  /**
+   * Ensure that ServiceComponentNotFoundException is propagated in case where there is a single request.
+   */
+  @Test
+  public void testGetComponents___ServiceComponentNotFoundException() throws Exception {
+    // member state mocks
+    Injector injector = createStrictMock(Injector.class);
+    Capture<AmbariManagementController> controllerCapture = new Capture<AmbariManagementController>();
+    Clusters clusters = createNiceMock(Clusters.class);
+
+    Cluster cluster = createNiceMock(Cluster.class);
+    Service service = createNiceMock(Service.class);
+
+    // requests
+    ServiceComponentRequest request1 = new ServiceComponentRequest("cluster1", "service1", "component1",
+        Collections.<String, String>emptyMap(), null);
+
+    Set<ServiceComponentRequest> setRequests = new HashSet<ServiceComponentRequest>();
+    setRequests.add(request1);
+
+    // expectations
+    // constructor init
+    injector.injectMembers(capture(controllerCapture));
+    expect(injector.getInstance(Gson.class)).andReturn(null);
+
+    // getComponents
+    expect(clusters.getCluster("cluster1")).andReturn(cluster);
+    expect(cluster.getService("service1")).andReturn(service);
+    expect(service.getServiceComponent("component1")).andThrow(
+        new ServiceComponentNotFoundException("cluster1", "service1", "component1"));
+    // replay mocks
+    replay(injector, clusters, cluster, service);
+
+    //test
+    AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector);
+
+    // assert that exception is thrown in case where there is a single request
+    try {
+      controller.getComponents(setRequests);
+      fail("expected ServiceComponentNotFoundException");
+    } catch (ServiceComponentNotFoundException e) {
+      // expected
+    }
+
+    assertSame(controller, controllerCapture.getValue());
+    verify(injector, clusters, cluster, service);
+  }
+
+  /**
+   * Ensure that ServiceComponentNotFoundException is handled where there are multiple requests as would be the
+   * case when an OR predicate is provided in the query.
+   */
+  @Test
+  public void testGetComponents___OR_Predicate_ServiceComponentNotFoundException() throws Exception {
+    // member state mocks
+    Injector injector = createStrictMock(Injector.class);
+    Capture<AmbariManagementController> controllerCapture = new Capture<AmbariManagementController>();
+    Clusters clusters = createNiceMock(Clusters.class);
+
+    Cluster cluster = createNiceMock(Cluster.class);
+    Service service = createNiceMock(Service.class);
+    ServiceComponent component1 = createNiceMock(ServiceComponent.class);
+    ServiceComponent component2 = createNiceMock(ServiceComponent.class);
+    ServiceComponentResponse response1 = createNiceMock(ServiceComponentResponse.class);
+    ServiceComponentResponse response2 = createNiceMock(ServiceComponentResponse.class);
+
+    // requests
+    ServiceComponentRequest request1 = new ServiceComponentRequest("cluster1", "service1", "component1",
+        Collections.<String, String>emptyMap(), null);
+    ServiceComponentRequest request2 = new ServiceComponentRequest("cluster1", "service1", "component2",
+        Collections.<String, String>emptyMap(), null);
+    ServiceComponentRequest request3 = new ServiceComponentRequest("cluster1", "service1", "component3",
+        Collections.<String, String>emptyMap(), null);
+    ServiceComponentRequest request4 = new ServiceComponentRequest("cluster1", "service1", "component4",
+        Collections.<String, String>emptyMap(), null);
+
+    Set<ServiceComponentRequest> setRequests = new HashSet<ServiceComponentRequest>();
+    setRequests.add(request1);
+    setRequests.add(request2);
+    setRequests.add(request3);
+    setRequests.add(request4);
+
+    // expectations
+    // constructor init
+    injector.injectMembers(capture(controllerCapture));
+    expect(injector.getInstance(Gson.class)).andReturn(null);
+
+    // getComponents
+    expect(clusters.getCluster("cluster1")).andReturn(cluster).times(4);
+    expect(cluster.getService("service1")).andReturn(service).times(4);
+
+    expect(service.getServiceComponent("component1")).andThrow(new ServiceComponentNotFoundException("cluster1", "service1", "component1"));
+    expect(service.getServiceComponent("component2")).andThrow(new ServiceComponentNotFoundException("cluster1", "service1", "component2"));
+    expect(service.getServiceComponent("component3")).andReturn(component1);
+    expect(service.getServiceComponent("component4")).andReturn(component2);
+
+    expect(component1.convertToResponse()).andReturn(response1);
+    expect(component2.convertToResponse()).andReturn(response2);
+    // replay mocks
+    replay(injector, clusters, cluster, service, component1,  component2, response1, response2);
+
+    //test
+    AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector);
+    Set<ServiceComponentResponse> setResponses = controller.getComponents(setRequests);
+
+    // assert and verify
+    assertSame(controller, controllerCapture.getValue());
+    assertEquals(2, setResponses.size());
+    assertTrue(setResponses.contains(response1));
+    assertTrue(setResponses.contains(response2));
+
+    verify(injector, clusters, cluster, service, component1,  component2, response1, response2);
+  }
+
+  @Test
+  public void testGetHosts() throws Exception {
+    // member state mocks
+    Injector injector = createStrictMock(Injector.class);
+    Capture<AmbariManagementController> controllerCapture = new Capture<AmbariManagementController>();
+    Clusters clusters = createNiceMock(Clusters.class);
+
+    Cluster cluster = createNiceMock(Cluster.class);
+    Host host = createNiceMock(Host.class);
+    HostResponse response = createNiceMock(HostResponse.class);
+
+    Set<Cluster> setCluster = Collections.singleton(cluster);
+
+    // requests
+    HostRequest request1 = new HostRequest("host1", "cluster1", Collections.<String, String>emptyMap());
+
+    Set<HostRequest> setRequests = new HashSet<HostRequest>();
+    setRequests.add(request1);
+
+    // expectations
+    // constructor init
+    injector.injectMembers(capture(controllerCapture));
+    expect(injector.getInstance(Gson.class)).andReturn(null);
+
+    // getHosts
+    expect(clusters.getCluster("cluster1")).andReturn(cluster);
+    expect(clusters.getHost("host1")).andReturn(host);
+    expect(host.getHostName()).andReturn("host1").anyTimes();
+    expect(clusters.getClustersForHost("host1")).andReturn(setCluster);
+    expect(host.convertToResponse()).andReturn(response);
+    response.setClusterName("cluster1");
+
+    // replay mocks
+    replay(injector, clusters, cluster, host, response);
+
+    //test
+    AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector);
+    Set<HostResponse> setResponses = controller.getHosts(setRequests);
+
+    // assert and verify
+    assertSame(controller, controllerCapture.getValue());
+    assertEquals(1, setResponses.size());
+    assertTrue(setResponses.contains(response));
+
+    verify(injector, clusters, cluster, host, response);
+  }
+
+  /**
+   * Ensure that HostNotFoundException is propagated in case where there is a single request.
+   */
+  @Test
+  public void testGetHosts___HostNotFoundException() throws Exception {
+    // member state mocks
+    Injector injector = createStrictMock(Injector.class);
+    Capture<AmbariManagementController> controllerCapture = new Capture<AmbariManagementController>();
+    Clusters clusters = createNiceMock(Clusters.class);
+
+    Cluster cluster = createNiceMock(Cluster.class);
+
+    // requests
+    HostRequest request1 = new HostRequest("host1", "cluster1", Collections.<String, String>emptyMap());
+    Set<HostRequest> setRequests = Collections.singleton(request1);
+
+    // expectations
+    // constructor init
+    injector.injectMembers(capture(controllerCapture));
+    expect(injector.getInstance(Gson.class)).andReturn(null);
+
+    // getHosts
+    expect(clusters.getCluster("cluster1")).andReturn(cluster);
+    expect(clusters.getHost("host1")).andThrow(new HostNotFoundException("host1"));
+
+    // replay mocks
+    replay(injector, clusters, cluster);
+
+    //test
+    AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector);
+
+    // assert that exception is thrown in case where there is a single request
+    try {
+      controller.getHosts(setRequests);
+      fail("expected HostNotFoundException");
+    } catch (HostNotFoundException e) {
+      // expected
+    }
+    assertSame(controller, controllerCapture.getValue());
+    verify(injector, clusters, cluster);
+  }
+
+  /**
+   * Ensure that HostNotFoundException is propagated in case where there is a single request.
+   */
+  @Test
+  public void testGetHosts___HostNotFoundException_HostNotAssociatedWithCluster() throws Exception {
+    // member state mocks
+    Injector injector = createStrictMock(Injector.class);
+    Capture<AmbariManagementController> controllerCapture = new Capture<AmbariManagementController>();
+    Clusters clusters = createNiceMock(Clusters.class);
+
+    Cluster cluster = createNiceMock(Cluster.class);
+    Host host = createNiceMock(Host.class);
+
+    // requests
+    HostRequest request1 = new HostRequest("host1", "cluster1", Collections.<String, String>emptyMap());
+    Set<HostRequest> setRequests = Collections.singleton(request1);
+
+    // expectations
+    // constructor init
+    injector.injectMembers(capture(controllerCapture));
+    expect(injector.getInstance(Gson.class)).andReturn(null);
+
+    // getHosts
+    expect(clusters.getCluster("cluster1")).andReturn(cluster);
+    expect(clusters.getHost("host1")).andReturn(host);
+    expect(host.getHostName()).andReturn("host1").anyTimes();
+    // because cluster is not in set will result in HostNotFoundException
+    expect(clusters.getClustersForHost("host1")).andReturn(Collections.<Cluster>emptySet());
+
+    // replay mocks
+    replay(injector, clusters, cluster, host);
+
+    //test
+    AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector);
+
+    // assert that exception is thrown in case where there is a single request
+    try {
+      controller.getHosts(setRequests);
+      fail("expected HostNotFoundException");
+    } catch (HostNotFoundException e) {
+      // expected
+    }
+    assertSame(controller, controllerCapture.getValue());
+    verify(injector, clusters, cluster, host);
+  }
+
+
+  /**
+   * Ensure that HostNotFoundException is handled where there are multiple requests as would be the
+   * case when an OR predicate is provided in the query.
+   */
+  @Test
+  public void testGetHosts___OR_Predicate_HostNotFoundException() throws Exception {
+    // member state mocks
+    Injector injector = createStrictMock(Injector.class);
+    Capture<AmbariManagementController> controllerCapture = new Capture<AmbariManagementController>();
+    Clusters clusters = createNiceMock(Clusters.class);
+
+    Cluster cluster = createNiceMock(Cluster.class);
+    Host host1 = createNiceMock(Host.class);
+    Host host2 = createNiceMock(Host.class);
+    HostResponse response = createNiceMock(HostResponse.class);
+    HostResponse response2 = createNiceMock(HostResponse.class);
+
+    // requests
+    HostRequest request1 = new HostRequest("host1", "cluster1", Collections.<String, String>emptyMap());
+    HostRequest request2 = new HostRequest("host2", "cluster1", Collections.<String, String>emptyMap());
+    HostRequest request3 = new HostRequest("host3", "cluster1", Collections.<String, String>emptyMap());
+    HostRequest request4 = new HostRequest("host4", "cluster1", Collections.<String, String>emptyMap());
+
+    Set<HostRequest> setRequests = new HashSet<HostRequest>();
+    setRequests.add(request1);
+    setRequests.add(request2);
+    setRequests.add(request3);
+    setRequests.add(request4);
+
+    // expectations
+    // constructor init
+    injector.injectMembers(capture(controllerCapture));
+    expect(injector.getInstance(Gson.class)).andReturn(null);
+
+    // getHosts
+    expect(clusters.getCluster("cluster1")).andReturn(cluster).times(4);
+
+    expect(clusters.getHost("host1")).andReturn(host1);
+    expect(host1.getHostName()).andReturn("host1").anyTimes();
+    expect(clusters.getClustersForHost("host1")).andReturn(Collections.singleton(cluster));
+    expect(host1.convertToResponse()).andReturn(response);
+    response.setClusterName("cluster1");
+
+    expect(clusters.getHost("host2")).andReturn(host2);
+    expect(host2.getHostName()).andReturn("host2").anyTimes();
+    expect(clusters.getClustersForHost("host2")).andReturn(Collections.singleton(cluster));
+    expect(host2.convertToResponse()).andReturn(response2);
+    response2.setClusterName("cluster1");
+
+    expect(clusters.getHost("host3")).andThrow(new HostNotFoundException("host3"));
+    expect(clusters.getHost("host4")).andThrow(new HostNotFoundException("host4"));
+
+    // replay mocks
+    replay(injector, clusters, cluster, host1, host2, response, response2);
+
+    //test
+    AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector);
+    Set<HostResponse> setResponses = controller.getHosts(setRequests);
+
+    // assert and verify
+    assertSame(controller, controllerCapture.getValue());
+    assertEquals(2, setResponses.size());
+    assertTrue(setResponses.contains(response));
+    assertTrue(setResponses.contains(response2));
+
+    verify(injector, clusters, cluster, host1, host2, response, response2);
+  }
+
+  @Test
+  public void testGetHostComponents() throws Exception {
+    // member state mocks
+    Injector injector = createStrictMock(Injector.class);
+    Capture<AmbariManagementController> controllerCapture = new Capture<AmbariManagementController>();
+    Clusters clusters = createNiceMock(Clusters.class);
+    StackId stack = createNiceMock(StackId.class);
+    AmbariMetaInfo metaInfo = createStrictMock(AmbariMetaInfo.class);
+
+    Cluster cluster = createNiceMock(Cluster.class);
+    Host host = createNiceMock(Host.class);
+    Service service = createNiceMock(Service.class);
+    ServiceComponent component = createNiceMock(ServiceComponent.class);
+    ServiceComponentHost componentHost = createNiceMock(ServiceComponentHost.class);
+    ServiceComponentHostResponse response = createNiceMock(ServiceComponentHostResponse.class);
+
+    // requests
+    ServiceComponentHostRequest request1 = new ServiceComponentHostRequest(
+        "cluster1", null, "component1", "host1", Collections.<String, String>emptyMap(), null);
+
+
+    Set<ServiceComponentHostRequest> setRequests = new HashSet<ServiceComponentHostRequest>();
+    setRequests.add(request1);
+
+    // expectations
+    // constructor init
+    injector.injectMembers(capture(controllerCapture));
+    expect(injector.getInstance(Gson.class)).andReturn(null);
+
+    // getHostComponent
+    expect(clusters.getCluster("cluster1")).andReturn(cluster);
+    expect(clusters.getClustersForHost("host1")).andReturn(Collections.singleton(cluster));
+
+    expect(cluster.getDesiredStackVersion()).andReturn(stack);
+    expect(stack.getStackName()).andReturn("stackName");
+    expect(stack.getStackVersion()).andReturn("stackVersion");
+
+    expect(metaInfo.getComponentToService("stackName", "stackVersion", "component1")).andReturn("service1");
+    expect(cluster.getService("service1")).andReturn(service);
+    expect(service.getServiceComponent("component1")).andReturn(component);
+    expect(component.getName()).andReturn("component1").anyTimes();
+    expect(component.getServiceComponentHost("host1")).andReturn(componentHost);
+    expect(componentHost.convertToResponse()).andReturn(response);
+
+    // replay mocks
+    replay(injector, clusters, cluster, host, response, stack, metaInfo, service, component, componentHost);
+
+    //test
+    AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector);
+    //need to set private field 'ambariMetaInfo' which is injected at runtime
+    Class<?> c = controller.getClass();
+    Field f = c.getDeclaredField("ambariMetaInfo");
+    f.setAccessible(true);
+    f.set(controller, metaInfo);
+
+    Set<ServiceComponentHostResponse> setResponses = controller.getHostComponents(setRequests);
+
+    // assert and verify
+    assertSame(controller, controllerCapture.getValue());
+    assertEquals(1, setResponses.size());
+    assertTrue(setResponses.contains(response));
+
+    verify(injector, clusters, cluster, host, response, stack, metaInfo, service, component, componentHost);
+  }
+
+  @Test
+  public void testGetHostComponents___ServiceComponentHostNotFoundException() throws Exception {
+    // member state mocks
+    Injector injector = createStrictMock(Injector.class);
+    Capture<AmbariManagementController> controllerCapture = new Capture<AmbariManagementController>();
+    Clusters clusters = createNiceMock(Clusters.class);
+    StackId stack = createNiceMock(StackId.class);
+    AmbariMetaInfo metaInfo = createStrictMock(AmbariMetaInfo.class);
+
+    Cluster cluster = createNiceMock(Cluster.class);
+    Host host = createNiceMock(Host.class);
+    Service service = createNiceMock(Service.class);
+    ServiceComponent component = createNiceMock(ServiceComponent.class);
+
+    // requests
+    ServiceComponentHostRequest request1 = new ServiceComponentHostRequest(
+        "cluster1", null, "component1", "host1", Collections.<String, String>emptyMap(), null);
+
+
+    Set<ServiceComponentHostRequest> setRequests = new HashSet<ServiceComponentHostRequest>();
+    setRequests.add(request1);
+
+    // expectations
+    // constructor init
+    injector.injectMembers(capture(controllerCapture));
+    expect(injector.getInstance(Gson.class)).andReturn(null);
+
+    // getHostComponent
+    expect(clusters.getCluster("cluster1")).andReturn(cluster);
+    expect(clusters.getClustersForHost("host1")).andReturn(Collections.singleton(cluster));
+
+    expect(cluster.getDesiredStackVersion()).andReturn(stack);
+    expect(stack.getStackName()).andReturn("stackName");
+    expect(stack.getStackVersion()).andReturn("stackVersion");
+
+    expect(metaInfo.getComponentToService("stackName", "stackVersion", "component1")).andReturn("service1");
+    expect(cluster.getService("service1")).andReturn(service);
+    expect(service.getServiceComponent("component1")).andReturn(component);
+    expect(component.getName()).andReturn("component1").anyTimes();
+    expect(component.getServiceComponentHost("host1")).andThrow(
+        new ServiceComponentHostNotFoundException("cluster1", "service1", "component1", "host1"));
+
+    // replay mocks
+    replay(injector, clusters, cluster, host, stack, metaInfo, service, component);
+
+    //test
+    AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector);
+    //need to set private field 'ambariMetaInfo' which is injected at runtime
+    Class<?> c = controller.getClass();
+    Field f = c.getDeclaredField("ambariMetaInfo");
+    f.setAccessible(true);
+    f.set(controller, metaInfo);
+
+    try {
+      controller.getHostComponents(setRequests);
+      fail("expected ServiceComponentHostNotFoundException");
+    } catch (ServiceComponentHostNotFoundException e) {
+      //expected
+    }
+
+    // assert and verify
+    assertSame(controller, controllerCapture.getValue());
+    verify(injector, clusters, cluster, host, stack, metaInfo, service, component);
+  }
+
+  @Test
+  public void testGetHostComponents___OR_Predicate_ServiceComponentHostNotFoundException() throws Exception {
+    // member state mocks
+    Injector injector = createStrictMock(Injector.class);
+    Capture<AmbariManagementController> controllerCapture = new Capture<AmbariManagementController>();
+    Clusters clusters = createNiceMock(Clusters.class);
+    StackId stack = createNiceMock(StackId.class);
+    AmbariMetaInfo metaInfo = createNiceMock(AmbariMetaInfo.class);
+
+    Cluster cluster = createNiceMock(Cluster.class);
+    Host host = createNiceMock(Host.class);
+    Service service = createNiceMock(Service.class);
+    ServiceComponent component = createNiceMock(ServiceComponent.class);
+    ServiceComponent component2 = createNiceMock(ServiceComponent.class);
+    ServiceComponent component3 = createNiceMock(ServiceComponent.class);
+
+    ServiceComponentHost componentHost1 = createNiceMock(ServiceComponentHost.class);
+    ServiceComponentHost componentHost2 = createNiceMock(ServiceComponentHost.class);
+    ServiceComponentHostResponse response1 = createNiceMock(ServiceComponentHostResponse.class);
+    ServiceComponentHostResponse response2 = createNiceMock(ServiceComponentHostResponse.class);
+
+    // requests
+    ServiceComponentHostRequest request1 = new ServiceComponentHostRequest(
+        "cluster1", null, "component1", "host1", Collections.<String, String>emptyMap(), null);
+
+    ServiceComponentHostRequest request2 = new ServiceComponentHostRequest(
+        "cluster1", null, "component2", "host1", Collections.<String, String>emptyMap(), null);
+
+    ServiceComponentHostRequest request3 = new ServiceComponentHostRequest(
+        "cluster1", null, "component3", "host1", Collections.<String, String>emptyMap(), null);
+
+
+    Set<ServiceComponentHostRequest> setRequests = new HashSet<ServiceComponentHostRequest>();
+    setRequests.add(request1);
+    setRequests.add(request2);
+    setRequests.add(request3);
+
+    // expectations
+    // constructor init
+    injector.injectMembers(capture(controllerCapture));
+    expect(injector.getInstance(Gson.class)).andReturn(null);
+
+    // getHostComponent
+    expect(clusters.getCluster("cluster1")).andReturn(cluster).times(3);
+    expect(clusters.getClustersForHost("host1")).andReturn(Collections.singleton(cluster)).anyTimes();
+    expect(cluster.getService("service1")).andReturn(service).times(3);
+
+    expect(cluster.getDesiredStackVersion()).andReturn(stack).anyTimes();
+    expect(stack.getStackName()).andReturn("stackName").anyTimes();
+    expect(stack.getStackVersion()).andReturn("stackVersion").anyTimes();
+
+
+    expect(metaInfo.getComponentToService("stackName", "stackVersion", "component1")).andReturn("service1");
+    expect(service.getServiceComponent("component1")).andReturn(component);
+    expect(component.getName()).andReturn("component1");
+    expect(component.getServiceComponentHost("host1")).andReturn(componentHost1);
+    expect(componentHost1.convertToResponse()).andReturn(response1);
+
+    expect(metaInfo.getComponentToService("stackName", "stackVersion", "component2")).andReturn("service1");
+    expect(service.getServiceComponent("component2")).andReturn(component2);
+    expect(component2.getName()).andReturn("component2");
+    expect(component2.getServiceComponentHost("host1")).andThrow(
+        new ServiceComponentHostNotFoundException("cluster1", "service1", "component2", "host1"));
+
+
+    expect(metaInfo.getComponentToService("stackName", "stackVersion", "component3")).andReturn("service1");
+    expect(service.getServiceComponent("component3")).andReturn(component3);
+    expect(component3.getName()).andReturn("component3");
+    expect(component3.getServiceComponentHost("host1")).andReturn(componentHost2);
+    expect(componentHost2.convertToResponse()).andReturn(response2);
+
+    // replay mocks
+    replay(injector, clusters, cluster, host, stack, metaInfo, service, component, component2, component3,
+        componentHost1, componentHost2, response1, response2);
+
+    //test
+    AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector);
+    //need to set private field 'ambariMetaInfo' which is injected at runtime
+    Class<?> c = controller.getClass();
+    Field f = c.getDeclaredField("ambariMetaInfo");
+    f.setAccessible(true);
+    f.set(controller, metaInfo);
+
+    Set<ServiceComponentHostResponse> setResponses = controller.getHostComponents(setRequests);
+
+    // assert and verify
+    assertSame(controller, controllerCapture.getValue());
+    assertEquals(2, setResponses.size());
+    assertTrue(setResponses.contains(response1));
+    assertTrue(setResponses.contains(response2));
+
+    verify(injector, clusters, cluster, host, stack, metaInfo, service, component, component2, component3,
+        componentHost1, componentHost2, response1, response2);
+  }
+
+  @Test
+  public void testGetHostComponents___OR_Predicate_ServiceNotFoundException() throws Exception {
+    // member state mocks
+    Injector injector = createStrictMock(Injector.class);
+    Capture<AmbariManagementController> controllerCapture = new Capture<AmbariManagementController>();
+    Clusters clusters = createNiceMock(Clusters.class);
+    StackId stack = createNiceMock(StackId.class);
+    AmbariMetaInfo metaInfo = createNiceMock(AmbariMetaInfo.class);
+
+    Cluster cluster = createNiceMock(Cluster.class);
+    Host host = createNiceMock(Host.class);
+    Service service = createNiceMock(Service.class);
+    ServiceComponent component = createNiceMock(ServiceComponent.class);
+    ServiceComponent component2 = createNiceMock(ServiceComponent.class);
+    ServiceComponent component3 = createNiceMock(ServiceComponent.class);
+
+    ServiceComponentHost componentHost1 = createNiceMock(ServiceComponentHost.class);
+    ServiceComponentHost componentHost2 = createNiceMock(ServiceComponentHost.class);
+    ServiceComponentHostResponse response1 = createNiceMock(ServiceComponentHostResponse.class);
+    ServiceComponentHostResponse response2 = createNiceMock(ServiceComponentHostResponse.class);
+
+    // requests
+    ServiceComponentHostRequest request1 = new ServiceComponentHostRequest(
+        "cluster1", null, "component1", "host1", Collections.<String, String>emptyMap(), null);
+
+    ServiceComponentHostRequest request2 = new ServiceComponentHostRequest(
+        "cluster1", null, "component2", "host1", Collections.<String, String>emptyMap(), null);
+
+    ServiceComponentHostRequest request3 = new ServiceComponentHostRequest(
+        "cluster1", null, "component3", "host1", Collections.<String, String>emptyMap(), null);
+
+
+    Set<ServiceComponentHostRequest> setRequests = new HashSet<ServiceComponentHostRequest>();
+    setRequests.add(request1);
+    setRequests.add(request2);
+    setRequests.add(request3);
+
+    // expectations
+    // constructor init
+    injector.injectMembers(capture(controllerCapture));
+    expect(injector.getInstance(Gson.class)).andReturn(null);
+
+    // getHostComponent
+    expect(clusters.getCluster("cluster1")).andReturn(cluster).times(3);
+    expect(clusters.getClustersForHost("host1")).andReturn(Collections.singleton(cluster)).anyTimes();
+    //expect(cluster.getService("service1")).andReturn(service).times(3);
+
+    expect(cluster.getDesiredStackVersion()).andReturn(stack).anyTimes();
+    expect(stack.getStackName()).andReturn("stackName").anyTimes();
+    expect(stack.getStackVersion()).andReturn("stackVersion").anyTimes();
+
+
+    expect(metaInfo.getComponentToService("stackName", "stackVersion", "component1")).andReturn("service1");
+    expect(cluster.getService("service1")).andReturn(service);
+    expect(service.getServiceComponent("component1")).andReturn(component);
+    expect(component.getName()).andReturn("component1");
+    expect(component.getServiceComponentHost("host1")).andReturn(componentHost1);
+    expect(componentHost1.convertToResponse()).andReturn(response1);
+
+    expect(metaInfo.getComponentToService("stackName", "stackVersion", "component2")).andReturn("service2");
+    expect(cluster.getService("service2")).andThrow(new ServiceNotFoundException("cluster1", "service2"));
+
+    expect(metaInfo.getComponentToService("stackName", "stackVersion", "component3")).andReturn("service1");
+    expect(cluster.getService("service1")).andReturn(service);
+    expect(service.getServiceComponent("component3")).andReturn(component3);
+    expect(component3.getName()).andReturn("component3");
+    expect(component3.getServiceComponentHost("host1")).andReturn(componentHost2);
+    expect(componentHost2.convertToResponse()).andReturn(response2);
+
+    // replay mocks
+    replay(injector, clusters, cluster, host, stack, metaInfo, service, component, component2, component3,
+        componentHost1, componentHost2, response1, response2);
+
+    //test
+    AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector);
+    //need to set private field 'ambariMetaInfo' which is injected at runtime
+    Class<?> c = controller.getClass();
+    Field f = c.getDeclaredField("ambariMetaInfo");
+    f.setAccessible(true);
+    f.set(controller, metaInfo);
+
+    Set<ServiceComponentHostResponse> setResponses = controller.getHostComponents(setRequests);
+
+    // assert and verify
+    assertSame(controller, controllerCapture.getValue());
+    assertEquals(2, setResponses.size());
+    assertTrue(setResponses.contains(response1));
+    assertTrue(setResponses.contains(response2));
+
+    verify(injector, clusters, cluster, host, stack, metaInfo, service, component, component2, component3,
+        componentHost1, componentHost2, response1, response2);
+  }
+
+  @Test
+  public void testGetHostComponents___OR_Predicate_ServiceComponentNotFoundException() throws Exception {
+    // member state mocks
+    Injector injector = createStrictMock(Injector.class);
+    Capture<AmbariManagementController> controllerCapture = new Capture<AmbariManagementController>();
+    Clusters clusters = createNiceMock(Clusters.class);
+    StackId stack = createNiceMock(StackId.class);
+    AmbariMetaInfo metaInfo = createNiceMock(AmbariMetaInfo.class);
+
+    Cluster cluster = createNiceMock(Cluster.class);
+    Host host = createNiceMock(Host.class);
+    Service service = createNiceMock(Service.class);
+    Service service2 = createNiceMock(Service.class);
+    ServiceComponent component = createNiceMock(ServiceComponent.class);
+    ServiceComponent component2 = createNiceMock(ServiceComponent.class);
+    ServiceComponent component3 = createNiceMock(ServiceComponent.class);
+
+    ServiceComponentHost componentHost1 = createNiceMock(ServiceComponentHost.class);
+    ServiceComponentHost componentHost2 = createNiceMock(ServiceComponentHost.class);
+    ServiceComponentHostResponse response1 = createNiceMock(ServiceComponentHostResponse.class);
+    ServiceComponentHostResponse response2 = createNiceMock(ServiceComponentHostResponse.class);
+
+    // requests
+    ServiceComponentHostRequest request1 = new ServiceComponentHostRequest(
+        "cluster1", null, "component1", "host1", Collections.<String, String>emptyMap(), null);
+
+    ServiceComponentHostRequest request2 = new ServiceComponentHostRequest(
+        "cluster1", null, "component2", "host1", Collections.<String, String>emptyMap(), null);
+
+    ServiceComponentHostRequest request3 = new ServiceComponentHostRequest(
+        "cluster1", null, "component3", "host1", Collections.<String, String>emptyMap(), null);
+
+
+    Set<ServiceComponentHostRequest> setRequests = new HashSet<ServiceComponentHostRequest>();
+    setRequests.add(request1);
+    setRequests.add(request2);
+    setRequests.add(request3);
+
+    // expectations
+    // constructor init
+    injector.injectMembers(capture(controllerCapture));
+    expect(injector.getInstance(Gson.class)).andReturn(null);
+
+    // getHostComponent
+    expect(clusters.getCluster("cluster1")).andReturn(cluster).times(3);
+    expect(clusters.getClustersForHost("host1")).andReturn(Collections.singleton(cluster)).anyTimes();
+
+    expect(cluster.getDesiredStackVersion()).andReturn(stack).anyTimes();
+    expect(stack.getStackName()).andReturn("stackName").anyTimes();
+    expect(stack.getStackVersion()).andReturn("stackVersion").anyTimes();
+
+
+    expect(metaInfo.getComponentToService("stackName", "stackVersion", "component1")).andReturn("service1");
+    expect(cluster.getService("service1")).andReturn(service);
+    expect(service.getServiceComponent("component1")).andReturn(component);
+    expect(component.getName()).andReturn("component1");
+    expect(component.getServiceComponentHost("host1")).andReturn(componentHost1);
+    expect(componentHost1.convertToResponse()).andReturn(response1);
+
+    expect(metaInfo.getComponentToService("stackName", "stackVersion", "component2")).andReturn("service2");
+    expect(cluster.getService("service2")).andReturn(service2);
+    expect(service2.getServiceComponent("component2")).
+        andThrow(new ServiceComponentNotFoundException("cluster1", "service2", "component2"));
+
+    expect(metaInfo.getComponentToService("stackName", "stackVersion", "component3")).andReturn("service1");
+    expect(cluster.getService("service1")).andReturn(service);
+    expect(service.getServiceComponent("component3")).andReturn(component3);
+    expect(component3.getName()).andReturn("component3");
+    expect(component3.getServiceComponentHost("host1")).andReturn(componentHost2);
+    expect(componentHost2.convertToResponse()).andReturn(response2);
+
+    // replay mocks
+    replay(injector, clusters, cluster, host, stack, metaInfo, service, service2, component, component2, component3,
+        componentHost1, componentHost2, response1, response2);
+
+    //test
+    AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector);
+    //need to set private field 'ambariMetaInfo' which is injected at runtime
+    Class<?> c = controller.getClass();
+    Field f = c.getDeclaredField("ambariMetaInfo");
+    f.setAccessible(true);
+    f.set(controller, metaInfo);
+
+    Set<ServiceComponentHostResponse> setResponses = controller.getHostComponents(setRequests);
+
+    // assert and verify
+    assertSame(controller, controllerCapture.getValue());
+    assertEquals(2, setResponses.size());
+    assertTrue(setResponses.contains(response1));
+    assertTrue(setResponses.contains(response2));
+
+    verify(injector, clusters, cluster, host, stack, metaInfo, service, service2, component, component2, component3,
+        componentHost1, componentHost2, response1, response2);
+  }
+
+  @Test
+  public void testGetHostComponents___OR_Predicate_HostNotFoundException_hostProvidedInQuery() throws Exception {
+    // member state mocks
+    Injector injector = createStrictMock(Injector.class);
+    Capture<AmbariManagementController> controllerCapture = new Capture<AmbariManagementController>();
+    Clusters clusters = createNiceMock(Clusters.class);
+    StackId stack = createNiceMock(StackId.class);
+    AmbariMetaInfo metaInfo = createNiceMock(AmbariMetaInfo.class);
+
+    Cluster cluster = createNiceMock(Cluster.class);
+    Host host = createNiceMock(Host.class);
+    Service service = createNiceMock(Service.class);
+    Service service2 = createNiceMock(Service.class);
+    ServiceComponent component = createNiceMock(ServiceComponent.class);
+    ServiceComponent component2 = createNiceMock(ServiceComponent.class);
+    ServiceComponent component3 = createNiceMock(ServiceComponent.class);
+
+    ServiceComponentHost componentHost1 = createNiceMock(ServiceComponentHost.class);
+    ServiceComponentHost componentHost2 = createNiceMock(ServiceComponentHost.class);
+    ServiceComponentHostResponse response1 = createNiceMock(ServiceComponentHostResponse.class);
+    ServiceComponentHostResponse response2 = createNiceMock(ServiceComponentHostResponse.class);
+
+    // requests
+    ServiceComponentHostRequest request1 = new ServiceComponentHostRequest(
+        "cluster1", null, "component1", null, Collections.<String, String>emptyMap(), null);
+
+    ServiceComponentHostRequest request2 = new ServiceComponentHostRequest(
+        "cluster1", null, "component2", "host2", Collections.<String, String>emptyMap(), null);
+
+    ServiceComponentHostRequest request3 = new ServiceComponentHostRequest(
+        "cluster1", null, "component3", null, Collections.<String, String>emptyMap(), null);
+
+
+    Set<ServiceComponentHostRequest> setRequests = new HashSet<ServiceComponentHostRequest>();
+    setRequests.add(request1);
+    setRequests.add(request2);
+    setRequests.add(request3);
+
+    // expectations
+    // constructor init
+    injector.injectMembers(capture(controllerCapture));
+    expect(injector.getInstance(Gson.class)).andReturn(null);
+
+    // getHostComponent
+    expect(clusters.getCluster("cluster1")).andReturn(cluster).times(3);
+    //expect(clusters.getClustersForHost("host1")).andReturn(Collections.singleton(cluster)).anyTimes();
+
+    expect(cluster.getDesiredStackVersion()).andReturn(stack).anyTimes();
+    expect(stack.getStackName()).andReturn("stackName").anyTimes();
+    expect(stack.getStackVersion()).andReturn("stackVersion").anyTimes();
+
+    expect(metaInfo.getComponentToService("stackName", "stackVersion", "component1")).andReturn("service1");
+    expect(cluster.getService("service1")).andReturn(service);
+    expect(service.getServiceComponent("component1")).andReturn(component);
+    expect(component.getName()).andReturn("component1");
+    expect(component.getServiceComponentHosts()).andReturn(Collections.singletonMap("foo", componentHost1));
+    expect(componentHost1.convertToResponse()).andReturn(response1);
+
+    expect(clusters.getClustersForHost("host2")).andThrow(new HostNotFoundException("host2"));
+
+    expect(metaInfo.getComponentToService("stackName", "stackVersion", "component3")).andReturn("service1");
+    expect(cluster.getService("service1")).andReturn(service);
+    expect(service.getServiceComponent("component3")).andReturn(component3);
+    expect(component3.getName()).andReturn("component3");
+    expect(component3.getServiceComponentHosts()).andReturn(Collections.singletonMap("foo", componentHost2));
+    expect(componentHost2.convertToResponse()).andReturn(response2);
+
+    // replay mocks
+    replay(injector, clusters, cluster, host, stack, metaInfo, service, service2, component, component2, component3,
+        componentHost1, componentHost2, response1, response2);
+
+    //test
+    AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector);
+    //need to set private field 'ambariMetaInfo' which is injected at runtime
+    Class<?> c = controller.getClass();
+    Field f = c.getDeclaredField("ambariMetaInfo");
+    f.setAccessible(true);
+    f.set(controller, metaInfo);
+
+    Set<ServiceComponentHostResponse> setResponses = controller.getHostComponents(setRequests);
+
+    // assert and verify
+    assertSame(controller, controllerCapture.getValue());
+    assertEquals(2, setResponses.size());
+    assertTrue(setResponses.contains(response1));
+    assertTrue(setResponses.contains(response2));
+
+    verify(injector, clusters, cluster, host, stack, metaInfo, service, service2, component, component2, component3,
+        componentHost1, componentHost2, response1, response2);
+  }
+
+  @Test
+  public void testGetHostComponents___OR_Predicate_HostNotFoundException_hostProvidedInURL() throws Exception {
+    // member state mocks
+    Injector injector = createStrictMock(Injector.class);
+    Capture<AmbariManagementController> controllerCapture = new Capture<AmbariManagementController>();
+    Clusters clusters = createNiceMock(Clusters.class);
+    StackId stack = createNiceMock(StackId.class);
+    AmbariMetaInfo metaInfo = createNiceMock(AmbariMetaInfo.class);
+
+    Cluster cluster = createNiceMock(Cluster.class);
+
+    // requests
+    ServiceComponentHostRequest request1 = new ServiceComponentHostRequest(
+        "cluster1", null, "component1", "host1", Collections.<String, String>emptyMap(), null);
+
+    ServiceComponentHostRequest request2 = new ServiceComponentHostRequest(
+        "cluster1", null, "component2", "host1", Collections.<String, String>emptyMap(), null);
+
+    ServiceComponentHostRequest request3 = new ServiceComponentHostRequest(
+        "cluster1", null, "component3", "host1", Collections.<String, String>emptyMap(), null);
+
+
+    Set<ServiceComponentHostRequest> setRequests = new HashSet<ServiceComponentHostRequest>();
+    setRequests.add(request1);
+    setRequests.add(request2);
+    setRequests.add(request3);
+
+    // expectations
+    // constructor init
+    injector.injectMembers(capture(controllerCapture));
+    expect(injector.getInstance(Gson.class)).andReturn(null);
+
+    // getHostComponent
+    expect(clusters.getCluster("cluster1")).andReturn(cluster);
+    expect(clusters.getClustersForHost("host1")).andThrow(new HostNotFoundException("host1"));
+
+    // replay mocks
+    replay(injector, clusters, cluster, stack, metaInfo);
+
+    //test
+    AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector);
+    //need to set private field 'ambariMetaInfo' which is injected at runtime
+    Class<?> c = controller.getClass();
+    Field f = c.getDeclaredField("ambariMetaInfo");
+    f.setAccessible(true);
+    f.set(controller, metaInfo);
+
+    try {
+      controller.getHostComponents(setRequests);
+      fail("expected exception");
+    } catch (AmbariException e) {
+      // expected
+    }
+
+    // assert and verify
+    assertSame(controller, controllerCapture.getValue());
+
+    verify(injector, clusters, cluster, stack, metaInfo);
+  }
+
+  @Test
+  public void testGetHostComponents___OR_Predicate_ClusterNotFoundException() throws Exception {
+    // member state mocks
+    Injector injector = createStrictMock(Injector.class);
+    Capture<AmbariManagementController> controllerCapture = new Capture<AmbariManagementController>();
+    Clusters clusters = createNiceMock(Clusters.class);
+    StackId stack = createNiceMock(StackId.class);
+    AmbariMetaInfo metaInfo = createNiceMock(AmbariMetaInfo.class);
+
+    // requests
+    ServiceComponentHostRequest request1 = new ServiceComponentHostRequest(
+        "cluster1", null, "component1", "host1", Collections.<String, String>emptyMap(), null);
+
+    ServiceComponentHostRequest request2 = new ServiceComponentHostRequest(
+        "cluster1", null, "component2", "host2", Collections.<String, String>emptyMap(), null);
+
+    ServiceComponentHostRequest request3 = new ServiceComponentHostRequest(
+        "cluster1", null, "component3", "host1", Collections.<String, String>emptyMap(), null);
+
+
+    Set<ServiceComponentHostRequest> setRequests = new HashSet<ServiceComponentHostRequest>();
+    setRequests.add(request1);
+    setRequests.add(request2);
+    setRequests.add(request3);
+
+    // expectations
+    // constructor init
+    injector.injectMembers(capture(controllerCapture));
+    expect(injector.getInstance(Gson.class)).andReturn(null);
+
+    // getHostComponent
+    expect(clusters.getCluster("cluster1")).andThrow(new ClusterNotFoundException("cluster1"));
+
+    // replay mocks
+    replay(injector, clusters, stack, metaInfo);
+
+    //test
+    AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector);
+    //need to set private field 'ambariMetaInfo' which is injected at runtime
+    Class<?> c = controller.getClass();
+    Field f = c.getDeclaredField("ambariMetaInfo");
+    f.setAccessible(true);
+    f.set(controller, metaInfo);
+
+    try {
+      controller.getHostComponents(setRequests);
+      fail("expected exception");
+    } catch (ParentObjectNotFoundException e) {
+      //expected
+    }
+
+    // assert and verify
+    assertSame(controller, controllerCapture.getValue());
+
+    verify(injector, clusters,stack, metaInfo);
+  }
+
+  @Test
+  public void testGetHostComponents___NullHostName() throws Exception {
+    // member state mocks
+    Injector injector = createStrictMock(Injector.class);
+    Capture<AmbariManagementController> controllerCapture = new Capture<AmbariManagementController>();
+    Clusters clusters = createNiceMock(Clusters.class);
+    StackId stack = createNiceMock(StackId.class);
+    AmbariMetaInfo metaInfo = createStrictMock(AmbariMetaInfo.class);
+
+    Cluster cluster = createNiceMock(Cluster.class);
+    Service service = createNiceMock(Service.class);
+    ServiceComponent component = createNiceMock(ServiceComponent.class);
+    ServiceComponentHost componentHost1 = createNiceMock(ServiceComponentHost.class);
+    ServiceComponentHost componentHost2 = createNiceMock(ServiceComponentHost.class);
+    ServiceComponentHostResponse response1 = createNiceMock(ServiceComponentHostResponse.class);
+    ServiceComponentHostResponse response2 = createNiceMock(ServiceComponentHostResponse.class);
+
+    // requests
+    ServiceComponentHostRequest request1 = new ServiceComponentHostRequest(
+        "cluster1", null, "component1", null, Collections.<String, String>emptyMap(), null);
+
+
+    Set<ServiceComponentHostRequest> setRequests = new HashSet<ServiceComponentHostRequest>();
+    setRequests.add(request1);
+
+    Map<String, ServiceComponentHost> mapHostComponents = new HashMap<String, ServiceComponentHost>();
+    mapHostComponents.put("foo", componentHost1);
+    mapHostComponents.put("bar", componentHost2);
+
+
+    // expectations
+    // constructor init
+    injector.injectMembers(capture(controllerCapture));
+    expect(injector.getInstance(Gson.class)).andReturn(null);
+
+    // getHostComponent
+    expect(clusters.getCluster("cluster1")).andReturn(cluster);
+
+    expect(cluster.getDesiredStackVersion()).andReturn(stack);
+    expect(stack.getStackName()).andReturn("stackName");
+    expect(stack.getStackVersion()).andReturn("stackVersion");
+
+    expect(metaInfo.getComponentToService("stackName", "stackVersion", "component1")).andReturn("service1");
+    expect(cluster.getService("service1")).andReturn(service);
+    expect(service.getServiceComponent("component1")).andReturn(component);
+    expect(component.getName()).andReturn("component1").anyTimes();
+
+    expect(component.getServiceComponentHosts()).andReturn(mapHostComponents);
+    expect(componentHost1.convertToResponse()).andReturn(response1);
+    expect(componentHost2.convertToResponse()).andReturn(response2);
+
+    // replay mocks
+    replay(injector, clusters, cluster, response1, response2, stack, metaInfo, service, component, componentHost1, componentHost2);
+
+    //test
+    AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector);
+    //need to set private field 'ambariMetaInfo' which is injected at runtime
+    Class<?> c = controller.getClass();
+    Field f = c.getDeclaredField("ambariMetaInfo");
+    f.setAccessible(true);
+    f.set(controller, metaInfo);
+
+    Set<ServiceComponentHostResponse> setResponses = controller.getHostComponents(setRequests);
+
+    // assert and verify
+    assertSame(controller, controllerCapture.getValue());
+    assertEquals(2, setResponses.size());
+    assertTrue(setResponses.contains(response1));
+    assertTrue(setResponses.contains(response2));
+
+    verify(injector, clusters, cluster, response1, response2, stack, metaInfo, service, component, componentHost1, componentHost2);
+  }
+
+  @Test
+  public void testGetHostComponents___NullHostName_NullComponentName() throws Exception {
+    // member state mocks
+    Injector injector = createStrictMock(Injector.class);
+    Capture<AmbariManagementController> controllerCapture = new Capture<AmbariManagementController>();
+    Clusters clusters = createNiceMock(Clusters.class);
+    StackId stack = createNiceMock(StackId.class);
+    AmbariMetaInfo metaInfo = createStrictMock(AmbariMetaInfo.class);
+
+    Cluster cluster = createNiceMock(Cluster.class);
+    Service service1 = createNiceMock(Service.class);
+    Service service2 = createNiceMock(Service.class);
+    ServiceComponent component1 = createNiceMock(ServiceComponent.class);
+    ServiceComponent component2 = createNiceMock(ServiceComponent.class);
+    ServiceComponentHost componentHost1 = createNiceMock(ServiceComponentHost.class);
+    ServiceComponentHost componentHost2 = createNiceMock(ServiceComponentHost.class);
+    ServiceComponentHost componentHost3 = createNiceMock(ServiceComponentHost.class);
+    ServiceComponentHostResponse response1 = createNiceMock(ServiceComponentHostResponse.class);
+    ServiceComponentHostResponse response2 = createNiceMock(ServiceComponentHostResponse.class);
+    ServiceComponentHostResponse response3 = createNiceMock(ServiceComponentHostResponse.class);
+
+    // requests
+    ServiceComponentHostRequest request1 = new ServiceComponentHostRequest(
+        "cluster1", null, null, null, Collections.<String, String>emptyMap(), null);
+
+
+    Set<ServiceComponentHostRequest> setRequests = new HashSet<ServiceComponentHostRequest>();
+    setRequests.add(request1);
+
+    Map<String, Service> mapServices = new HashMap<String, Service>();
+    mapServices.put("foo", service1);
+    mapServices.put("bar", service2);
+
+    Map<String, ServiceComponentHost> mapHostComponents = new HashMap<String, ServiceComponentHost>();
+    mapHostComponents.put("foo", componentHost1);
+    mapHostComponents.put("bar", componentHost2);
+
+
+    // expectations
+    // constructor init
+    injector.injectMembers(capture(controllerCapture));
+    expect(injector.getInstance(Gson.class)).andReturn(null);
+
+    // getHostComponent
+    expect(clusters.getCluster("cluster1")).andReturn(cluster);
+
+    expect(cluster.getServices()).andReturn(mapServices);
+    expect(service1.getServiceComponents()).andReturn(Collections.singletonMap("foo", component1));
+    expect(service2.getServiceComponents()).andReturn(Collections.singletonMap("bar", component2));
+
+    expect(component1.getName()).andReturn("component1").anyTimes();
+    expect(component2.getName()).andReturn("component2").anyTimes();
+
+    expect(component1.getServiceComponentHosts()).andReturn(mapHostComponents);
+    expect(componentHost1.convertToResponse()).andReturn(response1);
+    expect(componentHost2.convertToResponse()).andReturn(response2);
+
+    expect(component2.getServiceComponentHosts()).andReturn(Collections.singletonMap("foobar", componentHost3));
+    expect(componentHost3.convertToResponse()).andReturn(response3);
+
+    // replay mocks
+    replay(injector, clusters, cluster, response1, response2, response3, stack, metaInfo, service1, service2,
+        component1, component2, componentHost1, componentHost2, componentHost3);
+
+    //test
+    AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector);
+    //need to set private field 'ambariMetaInfo' which is injected at runtime
+    Class<?> c = controller.getClass();
+    Field f = c.getDeclaredField("ambariMetaInfo");
+    f.setAccessible(true);
+    f.set(controller, metaInfo);
+
+    Set<ServiceComponentHostResponse> setResponses = controller.getHostComponents(setRequests);
+
+    // assert and verify
+    assertSame(controller, controllerCapture.getValue());
+    assertEquals(3, setResponses.size());
+    assertTrue(setResponses.contains(response1));
+    assertTrue(setResponses.contains(response2));
+    assertTrue(setResponses.contains(response3));
+
+    verify(injector, clusters, cluster, response1, response2, response3, stack, metaInfo, service1, service2,
+        component1, component2, componentHost1, componentHost2, componentHost3);
+  }
+
+  //todo other resources
+}

Modified: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java?rev=1431843&r1=1431842&r2=1431843&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java (original)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java Fri Jan 11 03:02:37 2013
@@ -33,11 +33,7 @@ import java.util.Set;
 
 import junit.framework.Assert;
 
-import org.apache.ambari.server.AmbariException;
-import org.apache.ambari.server.ClusterNotFoundException;
-import org.apache.ambari.server.Role;
-import org.apache.ambari.server.RoleCommand;
-import org.apache.ambari.server.ServiceNotFoundException;
+import org.apache.ambari.server.*;
 import org.apache.ambari.server.actionmanager.*;
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
@@ -312,7 +308,7 @@ public class AmbariManagementControllerT
       set1.add(rInvalid);
       controller.createServices(set1);
       fail("Expected failure for invalid cluster");
-    } catch (ClusterNotFoundException e) {
+    } catch (ParentObjectNotFoundException e) {
       // Expected
     }
 
@@ -542,7 +538,7 @@ public class AmbariManagementControllerT
       set1.add(rInvalid);
       controller.createComponents(set1);
       fail("Expected failure for invalid cluster");
-    } catch (ClusterNotFoundException e) {
+    } catch (ParentObjectNotFoundException e) {
       // Expected
     }
 
@@ -557,7 +553,7 @@ public class AmbariManagementControllerT
       set1.add(rInvalid);
       controller.createComponents(set1);
       fail("Expected failure for invalid service");
-    } catch (ServiceNotFoundException e) {
+    } catch (ParentObjectNotFoundException e) {
       // Expected
     }
 
@@ -917,7 +913,7 @@ public class AmbariManagementControllerT
       set1.add(rInvalid);
       controller.createHostComponents(set1);
       fail("Expected failure for invalid cluster");
-    } catch (ClusterNotFoundException e) {
+    } catch (ParentObjectNotFoundException e) {
       // Expected
     }
 
@@ -939,7 +935,7 @@ public class AmbariManagementControllerT
       set1.add(rInvalid);
       controller.createHostComponents(set1);
       fail("Expected failure for invalid service");
-    } catch (AmbariException e) {
+    } catch (IllegalArgumentException e) {
       // Expected
     }
 
@@ -1047,7 +1043,7 @@ public class AmbariManagementControllerT
       set1.add(rInvalid2);
       controller.createHostComponents(set1);
       fail("Expected failure for dup requests");
-    } catch (IllegalArgumentException e) {
+    } catch (DuplicateResourceException e) {
       // Expected
     }
 
@@ -1079,7 +1075,7 @@ public class AmbariManagementControllerT
       set1.add(rInvalid2);
       controller.createHostComponents(set1);
       fail("Expected failure for already existing");
-    } catch (IllegalArgumentException e) {
+    } catch (DuplicateResourceException e) {
       // Expected
     }
 
@@ -1109,10 +1105,9 @@ public class AmbariManagementControllerT
 
   @Test
   public void testCreateHostSimple() throws AmbariException {
-    List<String> clusterNames = null;
     Map<String, String> hostAttributes = null;
 
-    HostRequest r1 = new HostRequest("h1", clusterNames, hostAttributes);
+    HostRequest r1 = new HostRequest("h1", null, hostAttributes);
     r1.toString();
 
     Set<HostRequest> requests = new HashSet<HostRequest>();
@@ -1131,14 +1126,7 @@ public class AmbariManagementControllerT
     clusters.getHost("h1").persist();
     clusters.getHost("h2").persist();
 
-    clusterNames = new ArrayList<String>();
-    clusterNames.add("foo1");
-    clusterNames.add("foo2");
-
-    hostAttributes = new HashMap<String, String>();
-    HostRequest r2 = new HostRequest("h2", clusterNames, hostAttributes);
-
-    requests.add(r2);
+    requests.add(new HostRequest("h2", "foo", new HashMap<String, String>()));
 
     try {
       controller.createHosts(requests);
@@ -1147,10 +1135,8 @@ public class AmbariManagementControllerT
       // Expected
     }
 
-    clusters.addCluster("foo1");
-    clusters.addCluster("foo2");
-    clusters.getCluster("foo1").setDesiredStackVersion(new StackId("HDP-0.1"));
-    clusters.getCluster("foo2").setDesiredStackVersion(new StackId("HDP-0.1"));
+    clusters.addCluster("foo");
+    clusters.getCluster("foo").setDesiredStackVersion(new StackId("HDP-0.1"));
 
     controller.createHosts(requests);
 
@@ -1158,7 +1144,7 @@ public class AmbariManagementControllerT
     Assert.assertNotNull(clusters.getHost("h2"));
 
     Assert.assertEquals(0, clusters.getClustersForHost("h1").size());
-    Assert.assertEquals(2, clusters.getClustersForHost("h2").size());
+    Assert.assertEquals(1, clusters.getClustersForHost("h2").size());
 
   }
 
@@ -1168,9 +1154,7 @@ public class AmbariManagementControllerT
     clusters.addHost("h2");
     clusters.addHost("h3");
     clusters.addCluster("c1");
-    clusters.addCluster("c2");
     clusters.getCluster("c1").setDesiredStackVersion(new StackId("HDP-0.1"));
-    clusters.getCluster("c2").setDesiredStackVersion(new StackId("HDP-0.1"));
     clusters.getHost("h1").setOsType("centos5");
     clusters.getHost("h2").setOsType("centos5");
     clusters.getHost("h3").setOsType("centos5");
@@ -1183,12 +1167,10 @@ public class AmbariManagementControllerT
     hostAttrs.put("attr1", "val1");
     hostAttrs.put("attr2", "val2");
 
-    List<String> clusterNames = new ArrayList<String>();
-    clusterNames.add("c1");
-    clusterNames.add("c2");
+    String clusterName = "c1";
 
-    HostRequest r1 = new HostRequest("h1", clusterNames, null);
-    HostRequest r2 = new HostRequest("h2", clusterNames, hostAttrs);
+    HostRequest r1 = new HostRequest("h1", clusterName, null);
+    HostRequest r2 = new HostRequest("h2", clusterName, hostAttrs);
     HostRequest r3 = new HostRequest("h3", null, hostAttrs);
 
     Set<HostRequest> set1 = new HashSet<HostRequest>();
@@ -1197,8 +1179,8 @@ public class AmbariManagementControllerT
     set1.add(r3);
     controller.createHosts(set1);
 
-    Assert.assertEquals(2, clusters.getClustersForHost("h1").size());
-    Assert.assertEquals(2, clusters.getClustersForHost("h2").size());
+    Assert.assertEquals(1, clusters.getClustersForHost("h1").size());
+    Assert.assertEquals(1, clusters.getClustersForHost("h2").size());
     Assert.assertEquals(0, clusters.getClustersForHost("h3").size());
 
     Assert.assertEquals(2, clusters.getHost("h2").getHostAttributes().size());
@@ -1230,13 +1212,12 @@ public class AmbariManagementControllerT
 
     clusters.addHost("h1");
 
-    List<String> clusterNames = new ArrayList<String>();
-    clusterNames.add("c1");
+    String clusterName = "c1";
 
     try {
       set1.clear();
       HostRequest rInvalid =
-          new HostRequest("h1", clusterNames, null);
+          new HostRequest("h1", clusterName, null);
       set1.add(rInvalid);
       controller.createHosts(set1);
       fail("Expected failure for invalid cluster");
@@ -1249,9 +1230,9 @@ public class AmbariManagementControllerT
     try {
       set1.clear();
       HostRequest rInvalid1 =
-          new HostRequest("h1", clusterNames, null);
+          new HostRequest("h1", clusterName, null);
       HostRequest rInvalid2 =
-          new HostRequest("h1", clusterNames, null);
+          new HostRequest("h1", clusterName, null);
       set1.add(rInvalid1);
       set1.add(rInvalid2);
       controller.createHosts(set1);
@@ -2101,9 +2082,8 @@ public class AmbariManagementControllerT
     clusters.getHost("h3").persist();
     clusters.getHost("h4").persist();
     clusters.mapHostToCluster("h1", "c1");
-    clusters.mapHostToCluster("h1", "c2");
     clusters.mapHostToCluster("h2", "c1");
-    clusters.mapHostToCluster("h3", "c1");
+    clusters.mapHostToCluster("h3", "c2");
 
     Map<String, String> attrs = new HashMap<String, String>();
     attrs.put("a1", "b1");
@@ -2122,16 +2102,17 @@ public class AmbariManagementControllerT
     for (HostResponse resp : resps) {
       foundHosts.add(resp.getHostname());
       if (resp.getHostname().equals("h1")) {
-        Assert.assertEquals(2, resp.getClusterNames().size());
+        Assert.assertEquals("c1", resp.getClusterName());
         Assert.assertEquals(0, resp.getHostAttributes().size());
       } else if (resp.getHostname().equals("h2")) {
-        Assert.assertEquals(1, resp.getClusterNames().size());
+        Assert.assertEquals("c1", resp.getClusterName());
         Assert.assertEquals(0, resp.getHostAttributes().size());
       } else if (resp.getHostname().equals("h3")) {
-        Assert.assertEquals(1, resp.getClusterNames().size());
+        Assert.assertEquals("c2", resp.getClusterName());
         Assert.assertEquals(1, resp.getHostAttributes().size());
       } else if (resp.getHostname().equals("h4")) {
-        Assert.assertEquals(0, resp.getClusterNames().size());
+        //todo: why wouldn't this be null?
+        Assert.assertEquals("", resp.getClusterName());
         Assert.assertEquals(2, resp.getHostAttributes().size());
       } else {
         fail("Found invalid host");
@@ -2145,7 +2126,7 @@ public class AmbariManagementControllerT
     Assert.assertEquals(1, resps.size());
     HostResponse resp = resps.iterator().next();
     Assert.assertEquals("h1", resp.getHostname());
-    Assert.assertEquals(2, resp.getClusterNames().size());
+    Assert.assertEquals("c1", resp.getClusterName());
     Assert.assertEquals(0, resp.getHostAttributes().size());
 
   }

Modified: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/ClusterResponseTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/ClusterResponseTest.java?rev=1431843&r1=1431842&r2=1431843&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/ClusterResponseTest.java (original)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/ClusterResponseTest.java Fri Jan 11 03:02:37 2013
@@ -1,5 +1,23 @@
 package org.apache.ambari.server.controller;
 
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 import java.util.HashSet;
 import java.util.Set;
 



Mime
View raw message