private void performGeneralDoFilterTest(Authentication authentication, Table<String, String, Boolean> urlTests, boolean expectRedirect) throws Exception {
    SecurityContextHolder.getContext().setAuthentication(authentication);
    final FilterConfig filterConfig = createNiceMock(FilterConfig.class);

    final Configuration configuration = EasyMock.createMock(Configuration.class);
    expect(configuration.getDefaultApiAuthenticatedUser()).andReturn(null).anyTimes();

    final AuditLogger auditLogger = EasyMock.createNiceMock(AuditLogger.class);
    expect(auditLogger.isEnabled()).andReturn(false).anyTimes();

    final AmbariAuthorizationFilter filter = createMockBuilder(AmbariAuthorizationFilter.class)
        .addMockedMethod("getSecurityContext")
        .addMockedMethod("getViewRegistry")
        .withConstructor(createNiceMock(AmbariEntryPoint.class),
            configuration,
            createNiceMock(Users.class),
            auditLogger,
            createNiceMock(PermissionHelper.class))
        .createMock();

    final ViewRegistry viewRegistry = createNiceMock(ViewRegistry.class);

    expect(filterConfig.getInitParameter("realm")).andReturn("AuthFilter").anyTimes();

    expect(filter.getSecurityContext()).andReturn(SecurityContextHolder.getContext()).anyTimes();
    expect(filter.getViewRegistry()).andReturn(viewRegistry).anyTimes();
    expect(viewRegistry.checkPermission(EasyMock.eq("DeniedView"), EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.anyBoolean())).andReturn(false).anyTimes();

    replay(filterConfig, filter, viewRegistry, configuration, auditLogger);

    for (final Cell<String, String, Boolean> urlTest: urlTests.cellSet()) {
      final FilterChain chain = EasyMock.createStrictMock(FilterChain.class);
      final HttpServletRequest request = createNiceMock(HttpServletRequest.class);
      final HttpServletResponse response = createNiceMock(HttpServletResponse.class);

      String URI = urlTest.getRowKey();
      String[] URIParts = URI.split("\\?");

      expect(request.getRequestURI()).andReturn(URIParts[0]).anyTimes();
      expect(request.getQueryString()).andReturn(URIParts.length == 2 ? URIParts[1] : null).anyTimes();
      expect(request.getMethod()).andReturn(urlTest.getColumnKey()).anyTimes();

      if (expectRedirect) {
        String redirectURL = AmbariAuthorizationFilter.LOGIN_REDIRECT_BASE + urlTest.getRowKey();
        expect(response.encodeRedirectURL(redirectURL)).andReturn(redirectURL);
        response.sendRedirect(redirectURL);
      }

      if (urlTest.getValue()) {
        chain.doFilter(EasyMock.anyObject(), EasyMock.anyObject());
        EasyMock.expectLastCall().once();
      }

      replay(request, response, chain);

      try {
        filter.doFilter(request, response, chain);
      } catch (AssertionError error) {
        throw new Exception("doFilter() should not be chained on " + urlTest.getColumnKey() + " " + urlTest.getRowKey(), error);
      }

      try {
        verify(chain);

        if (expectRedirect) {
          verify(response);
        }
      } catch (AssertionError error) {
        throw new Exception("verify( failed on " + urlTest.getColumnKey() + " " + urlTest.getRowKey(), error);
      }
    }
  }
Creates mocks with given permissions and performs all given url tests.

@param authentication the authentication to use
@param urlTests map of triples: url - http method - is allowed
@param expectRedirect true if the requests should redirect to login
@throws Exception if an exception occurs
ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariAuthorizationFilterTest.java