@Test(expected = HostNotFoundException.class)
  public void testGetHosts___HostNotFoundException_HostNotAssociatedWithCluster() throws Exception {
    // member state mocks
    Injector injector = createInjector();

    AmbariManagementController managementController = injector.getInstance(AmbariManagementController.class);
    Clusters clusters = injector.getInstance(Clusters.class);
    Cluster cluster = createMock(Cluster.class);
    Host host = createNiceMock(Host.class);

    // requests
    HostRequest request1 = new HostRequest("host1", "cluster1");
    Set<HostRequest> setRequests = Collections.singleton(request1);

    // expectations
    expect(managementController.getClusters()).andReturn(clusters).anyTimes();
    expect(clusters.getCluster("cluster1")).andReturn(cluster);
    expect(clusters.getHost("host1")).andReturn(host);
    expect(cluster.getDesiredConfigs()).andReturn(new HashMap<>()).anyTimes();
    expect(host.getHostName()).andReturn("host1").anyTimes();
    // because cluster is not in set will result in HostNotFoundException
    expect(clusters.getClustersForHost("host1")).andReturn(Collections.emptySet());

    // replay mocks
    replayAll();

    SecurityContextHolder.getContext().setAuthentication(TestAuthenticationFactory.createAdministrator());
    getHosts(managementController, setRequests);

    verifyAll();
  }
Ensure that HostNotFoundException is propagated in case where there is a single request.
ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostResourceProviderTest.java