@Test
  public void testIsApplicableForPatch() throws Exception {
    final String clusterName = "c1";
    final Cluster cluster = createMock(Cluster.class);

    Map<String, Service> services = new HashMap<String, Service>() {
      {
        put("SERVICE1", null);
        put("SERVICE2", null);
        put("SERVICE3", null);
      }
    };

    Set<String> oneServiceList = Sets.newHashSet("SERVICE1");

    expect(clusters.getCluster(anyString())).andReturn(cluster).atLeastOnce();
    expect(cluster.getServices()).andReturn(services).atLeastOnce();

    RepositoryVersion repositoryVersion = createNiceMock(RepositoryVersion.class);
    expect(repositoryVersion.getId()).andReturn(1L).anyTimes();
    expect(repositoryVersion.getRepositoryType()).andReturn(RepositoryType.STANDARD).anyTimes();

    RepositoryVersionEntity repositoryVersionEntity = createNiceMock(RepositoryVersionEntity.class);
    expect(repositoryVersionEntity.getType()).andReturn(RepositoryType.STANDARD).anyTimes();
    expect(repositoryVersionEntity.getRepositoryXml()).andReturn(m_vdfXml).atLeastOnce();
    expect(m_vdfXml.getClusterSummary(EasyMock.anyObject(Cluster.class), EasyMock.anyObject(AmbariMetaInfo.class))).andReturn(
        m_clusterVersionSummary).atLeastOnce();

    // the cluster summary will only return 1 service for the upgrade, even
    // though this cluster has 2 services installed
    expect(m_clusterVersionSummary.getAvailableServiceNames()).andReturn(
        oneServiceList).atLeastOnce();

    m_mockCheckHelper.m_clusters = clusters;
    Mockito.when(m_mockCheckHelper.m_repositoryVersionDAO.findByPK(Mockito.anyLong())).thenReturn(
        repositoryVersionEntity);

    final AmbariMetaInfo ami = createNiceMock(AmbariMetaInfo.class);

    m_mockCheckHelper.setMetaInfoProvider(new Provider<AmbariMetaInfo>() {
      @Override
      public AmbariMetaInfo get() {
        return ami;
      }
    });

    replayAll();

    TestCheckImpl check = new TestCheckImpl(UpgradeCheckType.SERVICE);
    check.checkHelperProvider = new Provider<CheckHelper>() {
      @Override
      public CheckHelper get() {
        return m_mockCheckHelper;
      }
    };

    ClusterInformation clusterInformation = new ClusterInformation(clusterName, false, null, null, null);
    UpgradeCheckRequest request = new UpgradeCheckRequest(clusterInformation, UpgradeType.ROLLING,
        repositoryVersion, null, null);

    // since the check is for SERVICE2, it should not match even though its
    // installed since the repository is only for SERVICE1
    check.setApplicableServices(Sets.newHashSet("SERVICE2"));
    Assert.assertTrue(m_mockCheckHelper.getApplicableChecks(request, Lists.newArrayList(check)).size() == 0);

    // ok, so now change the check to match against SERVICE1
    check.setApplicableServices(Sets.newHashSet("SERVICE1"));
    Assert.assertTrue(m_mockCheckHelper.getApplicableChecks(request, Lists.newArrayList(check)).size() == 1);
  }
Tests that even though the services are installed, the check doesn't match
since it's for a service not in the PATCH.

@throws Exception
ambari-server/src/test/java/org/apache/ambari/server/checks/ClusterCheckTest.java