Spring Framework MockFilterChain - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Spring Framework MockFilterChain class.

This code example shows how to use the following methods:getRequest
 
        HeaderWriterFilter filter = new HeaderWriterFilter(headerWriters); 
 
        MockHttpServletRequest request = new MockHttpServletRequest(); 
        MockHttpServletResponse response = new MockHttpServletResponse(); 
        MockFilterChain filterChain = new MockFilterChain(); 
 
        filter.doFilter(request, response, filterChain); 
 
        verify(writer1).writeHeaders(request, response); 
        verify(writer2).writeHeaders(request, response); 
        assertThat(filterChain.getRequest()).isEqualTo(request); // verify the filterChain continued 
    } 
} 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
This code example shows how to use the following methods:
This code example shows how to use the following methods:getRequest, getResponse
    MockHttpServletRequest request = this.getDefaultRequest(); 
    request.setRequestURI("/certs/"); 
    request.setScheme("http"); 
    MockHttpServletResponse response = new MockHttpServletResponse(); 
    request.setLocalPort(8440); 
    MockFilterChain chain = new MockFilterChain(); 
    filter.doFilter(request, response, chain); 
    assertNull(chain.getRequest()); 
    assertNull(chain.getResponse()); 
  } 
 
  @Test 
  public void mustAllowSecurePortRequests() throws Exception { 
    SecurityFilter filter = new SecurityFilter(); 
    MockHttpServletResponse response = new MockHttpServletResponse(); 
    MockHttpServletRequest request = this.getDefaultRequest(); 
    request.setServerPort(8441); 
    request.setLocalPort(8441); 
    request.setRequestURI("/certs/"); 
    MockFilterChain chain = new MockFilterChain(); 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
        SecurityContextRepository repo = mock(SecurityContextRepository.class);
        SessionManagementFilter filter = new SessionManagementFilter(repo);
        HttpServletRequest request = new MockHttpServletRequest();
        String sessionId = request.getSession().getId();
 
        filter.doFilter(request, new MockHttpServletResponse(), new MockFilterChain());
 
        assertEquals(sessionId, request.getSession().getId());
    } 
 
    @Test
    public void strategyIsNotInvokedIfSecurityContextAlreadyExistsForRequest() throws Exception {
        SecurityContextRepository repo = mock(SecurityContextRepository.class);
        SessionAuthenticationStrategy strategy = mock(SessionAuthenticationStrategy.class);
        // mock that repo contains a security context 
        when(repo.containsContext(any(HttpServletRequest.class))).thenReturn(true);
        SessionManagementFilter filter = new SessionManagementFilter(repo);
        filter.setSessionAuthenticationStrategy(strategy);
        HttpServletRequest request = new MockHttpServletRequest();
        authenticateUser(); 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
            "GET", 
            "http://localhost:9080/pentaho-di/kettle/executeTrans/?rep=dev&userid=admin&password=Encrypted%202be98afc86aa7f2e4bb18bd63c99dbdde&trans=/home/admin/Trans1" ); 
    request.addParameter( "userid", "admin" );
    request.addParameter( "password", "Encrypted 2be98afc86aa7f2e4bb18bd63c99dbdde" );
 
    filter.doFilter( request, new MockHttpServletResponse(), new MockFilterChain() );
    UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken( "admin", "password" );
    authRequest.setDetails( new WebAuthenticationDetails( request ) );
    verify( authManagerMock ).authenticate( Mockito.eq( authRequest ) );
 
  } 
 
  @Test
  public void userNamePasswordUnencrypted() throws IOException, ServletException {
    final MockHttpServletRequest request =
        new MockHttpServletRequest( "GET",
            "http://localhost:9080/pentaho-di/kettle/executeTrans/?rep=dev&userid=admin&password=password&trans=/home/admin/Trans1" ); 
    request.addParameter( "userid", "admin" );
    request.addParameter( "password", "password" );
 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getRequest
		MockHttpServletRequest request = new MockHttpServletRequest(); 
		request.setMethod("GET"); 
		request.setServletPath(servletPath); 
		request.addParameter("reconnect", "true"); 
		MockHttpServletResponse response = new MockHttpServletResponse(); 
		MockFilterChain chain = new MockFilterChain(); 
		filter.doFilter(request, response, chain); 
		HttpServletRequest redirectRequest = (HttpServletRequest) chain.getRequest(); 
		assertEquals("POST", redirectRequest.getMethod()); 
		assertEquals(servletPath, redirectRequest.getServletPath()); 
		 
		verify(connRepo).removeConnections(providerId); 
	} 
	 
} 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getRequest
 
	@Test 
	public void testDoFilterWithNoChanges() throws Exception { 
		MockHttpServletRequest request = new MockHttpServletRequest(); 
		request.addParameter("foo_bar", ""); 
		MockFilterChain filterChain = new MockFilterChain(); 
		filter.doFilter(request, new MockHttpServletResponse(), filterChain); 
		assertEquals(request, filterChain.getRequest()); 
	} 
 
	@Test 
	public void testDoFilterWithRedirect() throws Exception { 
		MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo;jsessionid=1234"); 
		request.addParameter("foo", "bar"); 
		MockFilterChain filterChain = new MockFilterChain(); 
		MockHttpServletResponse response = new MockHttpServletResponse(); 
		filter.doFilter(request, response, filterChain); 
		assertNull(filterChain.getResponse()); 
		String url = response.getRedirectedUrl(); 
		assertFalse("Wrong: "+url, url.contains(";")); 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
    @Test 
    public void userShouldBeRegisteredAndUnregisteredWhenChainEnded() throws Exception { 
        MockHttpServletRequest request = new MockHttpServletRequest(); 
        MockHttpServletResponse response = new MockHttpServletResponse(); 
 
        MockFilterChain filterChain = new MockFilterChain(); 
        String userName = "Shogun"; 
        when(securityService.getCurrentUserUsername()).thenReturn(userName); 
 
        loggingConfigurationFilter.doFilter(request, response, filterChain); 
 
        verify(loggerMdc).registerUser(userName); 
        verify(loggerMdc).unregisterUser(); 
    } 
 
    @Test 
    public void anonymousUserRegisteredAndUnregistered() throws Exception { 
        MockHttpServletRequest request = new MockHttpServletRequest(); 
        MockHttpServletResponse response = new MockHttpServletResponse(); 
        MockHttpSession httpSession = spy(new MockHttpSession()); 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
	@Before 
	public void setup() { 
		request = new MockHttpServletRequest(); 
		request.setContextPath("/context"); 
		response = new MockHttpServletResponse(); 
		filterChain = new MockFilterChain(); 
		delegate = new MockFilter(); 
	} 
 
	@Test 
	public void init() throws Exception { 
		FilterConfig config = new MockFilterConfig(); 
		filter = new PatternMappingFilterProxy(delegate, "/"); 
		filter.init(config); 
		assertThat(delegate.filterConfig, is(config)); 
	} 
 
	@Test 
	public void destroy() throws Exception { 
		filter = new PatternMappingFilterProxy(delegate, "/"); 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
See Code Examples for Spring Framework MockFilterChain Methods: