code: @Test public void testGetServiceComponentsWithFilters() throws AmbariException {
    clusters.addCluster("c1");
    clusters.addCluster("c2");
    Cluster c1=clusters.getCluster("c1");
    Cluster c2=clusters.getCluster("c2");
    c1.setDesiredStackVersion(new StackId("HDP-0.2"));
    c2.setDesiredStackVersion(new StackId("HDP-0.2"));
    Service s1=serviceFactory.createNew(c1,"HDFS");
    Service s2=serviceFactory.createNew(c1,"MAPREDUCE");
    Service s3=serviceFactory.createNew(c1,"HBASE");
    Service s4=serviceFactory.createNew(c2,"HIVE");
    Service s5=serviceFactory.createNew(c2,"ZOOKEEPER");
    c1.addService(s1);
    c1.addService(s2);
    c1.addService(s3);
    c2.addService(s4);
    c2.addService(s5);
    s1.setDesiredState(State.INSTALLED);
    s2.setDesiredState(State.INSTALLED);
    s4.setDesiredState(State.INSTALLED);
    s1.persist();
    s2.persist();
    s3.persist();
    s4.persist();
    s5.persist();
    ServiceComponent sc1=serviceComponentFactory.createNew(s1,"DATANODE");
    ServiceComponent sc2=serviceComponentFactory.createNew(s1,"NAMENODE");
    ServiceComponent sc3=serviceComponentFactory.createNew(s3,"HBASE_REGIONSERVER");
    ServiceComponent sc4=serviceComponentFactory.createNew(s4,"HIVE_SERVER");
    ServiceComponent sc5=serviceComponentFactory.createNew(s4,"HIVE_CLIENT");
    ServiceComponent sc6=serviceComponentFactory.createNew(s4,"MYSQL_SERVER");
    ServiceComponent sc7=serviceComponentFactory.createNew(s5,"ZOOKEEPER_SERVER");
    ServiceComponent sc8=serviceComponentFactory.createNew(s5,"ZOOKEEPER_CLIENT");
    s1.addServiceComponent(sc1);
    s1.addServiceComponent(sc2);
    s3.addServiceComponent(sc3);
    s4.addServiceComponent(sc4);
    s4.addServiceComponent(sc5);
    s4.addServiceComponent(sc6);
    s5.addServiceComponent(sc7);
    s5.addServiceComponent(sc8);
    sc1.setDesiredState(State.UNINSTALLED);
    sc3.setDesiredState(State.UNINSTALLED);
    sc5.setDesiredState(State.UNINSTALLED);
    sc6.setDesiredState(State.UNINSTALLED);
    sc7.setDesiredState(State.UNINSTALLED);
    sc8.setDesiredState(State.UNINSTALLED);
    sc1.persist();
    sc2.persist();
    sc3.persist();
    sc4.persist();
    sc5.persist();
    sc6.persist();
    sc7.persist();
    sc8.persist();
    ServiceComponentRequest r=new ServiceComponentRequest(null,null,null,null,null);
    try {
      controller.getComponents(Collections.singleton(r));
      fail("Expected failure for invalid cluster");
    }
   catch (  Exception e) {
    }
    r=new ServiceComponentRequest(c1.getClusterName(),null,null,null,null);
    Set<ServiceComponentResponse> resps=controller.getComponents(Collections.singleton(r));
    Assert.assertEquals(3,resps.size());
    r=new ServiceComponentRequest(c2.getClusterName(),null,null,null,State.UNINSTALLED.toString());
    resps=controller.getComponents(Collections.singleton(r));
    Assert.assertEquals(4,resps.size());
    r=new ServiceComponentRequest(c2.getClusterName(),s5.getName(),null,null,null);
    resps=controller.getComponents(Collections.singleton(r));
    Assert.assertEquals(2,resps.size());
    r=new ServiceComponentRequest(c2.getClusterName(),s4.getName(),null,null,State.INIT.toString());
    resps=controller.getComponents(Collections.singleton(r));
    Assert.assertEquals(1,resps.size());
    Assert.assertEquals(sc4.getName(),resps.iterator().next().getComponentName());
    r=new ServiceComponentRequest(c2.getClusterName(),null,sc5.getName(),null,State.INIT.toString());
    resps=controller.getComponents(Collections.singleton(r));
    Assert.assertEquals(1,resps.size());
    Assert.assertEquals(sc5.getName(),resps.iterator().next().getComponentName());
    r=new ServiceComponentRequest(c2.getClusterName(),s4.getName(),sc5.getName(),null,State.INIT.toString());
    resps=controller.getComponents(Collections.singleton(r));
    Assert.assertEquals(1,resps.size());
    Assert.assertEquals(sc5.getName(),resps.iterator().next().getComponentName());
    ServiceComponentRequest r1, r2, r3;
    Set<ServiceComponentRequest> reqs=new HashSet<ServiceComponentRequest>();
    r1=new ServiceComponentRequest(c2.getClusterName(),null,null,null,State.UNINSTALLED.toString());
    r2=new ServiceComponentRequest(c1.getClusterName(),null,null,null,null);
    r3=new ServiceComponentRequest(c1.getClusterName(),null,null,null,State.INIT.toString());
    reqs.addAll(Arrays.asList(r1,r2,r3));
    resps=controller.getComponents(reqs);
    Assert.assertEquals(7,resps.size());
  }
  