@Test public void testisOperationAllowed() throws Exception { Injector injector = createStrictMock(Injector.class); Cluster cluster = createMock(Cluster.class); Method isOperationAllowed = MaintenanceStateHelper.class.getDeclaredMethod( "isOperationAllowed", new Class[]{Cluster.class, Type.class, String.class, String.class, String.class}); MaintenanceStateHelper maintenanceStateHelper = createMockBuilder(MaintenanceStateHelper.class) .withConstructor(injector) .addMockedMethod(isOperationAllowed) .createNiceMock(); RequestResourceFilter filter = createMock(RequestResourceFilter.class); RequestOperationLevel level = createMock(RequestOperationLevel.class); expect(level.getLevel()).andReturn(Type.Cluster); expect(maintenanceStateHelper.isOperationAllowed( anyObject(Cluster.class), anyObject(Type.class), anyObject(String.class), anyObject(String.class), anyObject(String.class))).andStubReturn(true); replay(cluster, maintenanceStateHelper, level); maintenanceStateHelper.isOperationAllowed(cluster, level, filter, "service", "component", "hostname"); verify(maintenanceStateHelper, level); maintenanceStateHelper = createMockBuilder(MaintenanceStateHelper.class) .withConstructor(injector) .addMockedMethod(isOperationAllowed) .addMockedMethod("guessOperationLevel") .createNiceMock(); expect(maintenanceStateHelper.guessOperationLevel(anyObject(RequestResourceFilter.class))).andReturn(Type.Cluster); expect(maintenanceStateHelper.isOperationAllowed( anyObject(Cluster.class), anyObject(Type.class), anyObject(String.class), anyObject(String.class), anyObject(String.class))).andStubReturn(true); replay(maintenanceStateHelper); maintenanceStateHelper.isOperationAllowed(cluster, null, filter, "service", "component", "hostname"); verify(maintenanceStateHelper); }
public boolean isOperationAllowed(Cluster cluster, RequestOperationLevel levelObj, RequestResourceFilter reqFilter, String serviceName, String componentName, String hostname) throws AmbariException { Resource.Type level; if (levelObj == null) { level = guessOperationLevel(reqFilter); } else { level = levelObj.getLevel(); } return isOperationAllowed(cluster, level, serviceName, componentName, hostname); }
MaintenanceStateHelper { public boolean isOperationAllowed(Cluster cluster, RequestOperationLevel levelObj, RequestResourceFilter reqFilter, String serviceName, String componentName, String hostname) throws AmbariException { Resource.Type level; if (levelObj == null) { level = guessOperationLevel(reqFilter); } else { level = levelObj.getLevel(); } return isOperationAllowed(cluster, level, serviceName, componentName, hostname); } }
MaintenanceStateHelper { public boolean isOperationAllowed(Cluster cluster, RequestOperationLevel levelObj, RequestResourceFilter reqFilter, String serviceName, String componentName, String hostname) throws AmbariException { Resource.Type level; if (levelObj == null) { level = guessOperationLevel(reqFilter); } else { level = levelObj.getLevel(); } return isOperationAllowed(cluster, level, serviceName, componentName, hostname); } @Inject  MaintenanceStateHelper(Injector injector); }
MaintenanceStateHelper { public boolean isOperationAllowed(Cluster cluster, RequestOperationLevel levelObj, RequestResourceFilter reqFilter, String serviceName, String componentName, String hostname) throws AmbariException { Resource.Type level; if (levelObj == null) { level = guessOperationLevel(reqFilter); } else { level = levelObj.getLevel(); } return isOperationAllowed(cluster, level, serviceName, componentName, hostname); } @Inject  MaintenanceStateHelper(Injector injector); boolean isOperationAllowed(Cluster cluster,
      RequestOperationLevel levelObj, RequestResourceFilter reqFilter,
      String serviceName, String componentName, String hostname); boolean isOperationAllowed(Resource.Type level, Service service); boolean isOperationAllowed(Host host, long clusterId,
      Resource.Type level); MaintenanceState getEffectiveState(ServiceComponentHost sch, Host host); MaintenanceState getEffectiveState(ServiceComponentHost sch); MaintenanceState getEffectiveState(long clusterId, Alert alert); Set<Map<String, String>> getMaintenanceHostComponents(
      Clusters clusters, Cluster cluster); boolean isOperationAllowed(Resource.Type operationLevel,
      ServiceComponentHost sch); Resource.Type guessOperationLevel(RequestResourceFilter filter); Set<String> filterHostsInMaintenanceState(Set<String> candidateHosts,
      HostPredicate condition); }
MaintenanceStateHelper { public boolean isOperationAllowed(Cluster cluster, RequestOperationLevel levelObj, RequestResourceFilter reqFilter, String serviceName, String componentName, String hostname) throws AmbariException { Resource.Type level; if (levelObj == null) { level = guessOperationLevel(reqFilter); } else { level = levelObj.getLevel(); } return isOperationAllowed(cluster, level, serviceName, componentName, hostname); } @Inject  MaintenanceStateHelper(Injector injector); boolean isOperationAllowed(Cluster cluster,
      RequestOperationLevel levelObj, RequestResourceFilter reqFilter,
      String serviceName, String componentName, String hostname); boolean isOperationAllowed(Resource.Type level, Service service); boolean isOperationAllowed(Host host, long clusterId,
      Resource.Type level); MaintenanceState getEffectiveState(ServiceComponentHost sch, Host host); MaintenanceState getEffectiveState(ServiceComponentHost sch); MaintenanceState getEffectiveState(long clusterId, Alert alert); Set<Map<String, String>> getMaintenanceHostComponents(
      Clusters clusters, Cluster cluster); boolean isOperationAllowed(Resource.Type operationLevel,
      ServiceComponentHost sch); Resource.Type guessOperationLevel(RequestResourceFilter filter); Set<String> filterHostsInMaintenanceState(Set<String> candidateHosts,
      HostPredicate condition);  }