@Test public void testIsApplicable() throws Exception{ final String clusterName = "c1"; final Cluster cluster = EasyMock.createMock(Cluster.class); Map<String, Service> services = new HashMap<String, Service>(){{ put("SERVICE1", null); put("SERVICE2", null); put("SERVICE3", null); }}; expect(clusters.getCluster(anyString())).andReturn(cluster).atLeastOnce(); expect(cluster.getServices()).andReturn(services).atLeastOnce(); replay(clusters, cluster); AbstractCheckDescriptor check = new TestCheckImpl(PrereqCheckType.SERVICE); PrereqCheckRequest request = new PrereqCheckRequest(clusterName, UpgradeType.ROLLING); List<String> oneServiceList = new ArrayList<String>() {{ add("SERVICE1"); }}; List<String> atLeastOneServiceList = new ArrayList<String>() {{ add("SERVICE1"); add("NON_EXISTED_SERVICE"); }}; List<String> allServicesList = new ArrayList<String>(){{ add("SERVICE1"); add("SERVICE2"); }}; List<String> nonExistedList = new ArrayList<String>(){{ add("NON_EXISTED_SERVICE"); }}; Assert.assertEquals(true, check.isApplicable(request, oneServiceList, false)); Assert.assertEquals(true, check.isApplicable(request, atLeastOneServiceList, false)); Assert.assertEquals(false, check.isApplicable(request,atLeastOneServiceList, true)); Assert.assertEquals(true, check.isApplicable(request, allServicesList, true)); Assert.assertEquals(false, check.isApplicable(request, new ArrayList<String>(), true)); Assert.assertEquals(false, check.isApplicable(request, new ArrayList<String>(), false)); Assert.assertEquals(false, check.isApplicable(request, nonExistedList, false)); Assert.assertEquals(false, check.isApplicable(request, nonExistedList, true)); }
public boolean isApplicable(PrereqCheckRequest request) throws AmbariException { return true; }
AbstractCheckDescriptor { public boolean isApplicable(PrereqCheckRequest request) throws AmbariException { return true; } }
AbstractCheckDescriptor { public boolean isApplicable(PrereqCheckRequest request) throws AmbariException { return true; } protected  AbstractCheckDescriptor(CheckDescription description); }
AbstractCheckDescriptor { public boolean isApplicable(PrereqCheckRequest request) throws AmbariException { return true; } protected  AbstractCheckDescriptor(CheckDescription description); boolean isApplicable(PrereqCheckRequest request); boolean isApplicable(PrereqCheckRequest request, List<String> requiredServices, boolean requiredAll); abstract void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request); CheckDescription getDescription(); PrereqCheckType getType(); boolean isRequired(UpgradeType upgradeType); boolean isStackUpgradeAllowedToBypassPreChecks(); }
AbstractCheckDescriptor { public boolean isApplicable(PrereqCheckRequest request) throws AmbariException { return true; } protected  AbstractCheckDescriptor(CheckDescription description); boolean isApplicable(PrereqCheckRequest request); boolean isApplicable(PrereqCheckRequest request, List<String> requiredServices, boolean requiredAll); abstract void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request); CheckDescription getDescription(); PrereqCheckType getType(); boolean isRequired(UpgradeType upgradeType); boolean isStackUpgradeAllowedToBypassPreChecks();  }