Spring Framework MockHttpServletRequest - 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 MockHttpServletRequest class.

This code example shows how to use the following methods:
 * 
 */ 
public class WhitelabelErrorEndpointTests { 
	 
	private WhitelabelErrorEndpoint endpoint = new WhitelabelErrorEndpoint(); 
	private MockHttpServletRequest request = new MockHttpServletRequest(); 
	private MockHttpServletResponse response = new MockHttpServletResponse(); 
 
	@Test 
	public void testErrorPage() throws Exception { 
		request.setContextPath("/foo"); 
		request.setAttribute("error", new InvalidClientException("FOO")); 
		ModelAndView result = endpoint.handleError(request); 
		result.getView().render(result.getModel(), request , response); 
		String content = response.getContentAsString(); 
		assertTrue("Wrong content: " + content, content.contains("OAuth Error")); 
		assertTrue("Wrong content: " + content, content.contains("invalid_client")); 
	} 
 
} 
9
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:addHeader
		assertThat(Servlets.checkIfModifiedSince(request, response, (new Date().getTime() + 2000))).isTrue();
	} 
 
	@Test
	public void checkIfNoneMatch() { 
		MockHttpServletRequest request = new MockHttpServletRequest();
		MockHttpServletResponse response = new MockHttpServletResponse();
		// 未设Header,返回true,需要传输内容 
		assertThat(Servlets.checkIfNoneMatchEtag(request, response, "V1.0")).isTrue();
 
		// 设置If-None-Match Header 
		request.addHeader("If-None-Match", "V1.0,V1.1");
		// 存在Etag 
		assertThat(Servlets.checkIfNoneMatchEtag(request, response, "V1.0")).isFalse();
		// 不存在Etag 
		assertThat(Servlets.checkIfNoneMatchEtag(request, response, "V2.0")).isTrue();
	} 
 
	@Test
	public void getParametersStartingWith() { 
		MockHttpServletRequest request = new MockHttpServletRequest();
9
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
 */ 
public class OAuth2AccessDeniedHandlerTests { 
 
	private OAuth2AccessDeniedHandler handler = new OAuth2AccessDeniedHandler();
 
	private MockHttpServletRequest request = new MockHttpServletRequest();
 
	private MockHttpServletResponse response = new MockHttpServletResponse();
 
	@Test
	public void testHandleWithJson() throws Exception {
		request.addHeader("Accept", MediaType.APPLICATION_JSON_VALUE);
		handler.handle(request, response, new AccessDeniedException("Bad"));
		assertEquals(HttpServletResponse.SC_FORBIDDEN, response.getStatus());
		assertEquals(MediaType.APPLICATION_JSON_VALUE, response.getContentType());
		assertEquals(null, response.getErrorMessage());
	} 
 
} 
9
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
 
    private XContentTypeOptionsHeaderWriter writer;
 
    @Before 
    public void setup() { 
        request = new MockHttpServletRequest();
        response = new MockHttpServletResponse();
        writer = new XContentTypeOptionsHeaderWriter();
    } 
 
    @Test
    public void writeHeaders() { 
        writer.writeHeaders(request, response);
 
        assertThat(response.getHeaderNames().size()).isEqualTo(1);
        assertThat(response.getHeaderValues("X-Content-Type-Options")).isEqualTo(Arrays.asList("nosniff"));
    } 
} 
9
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
 
    private CacheControlHeadersWriter writer;
 
    @Before 
    public void setup() { 
        request = new MockHttpServletRequest();
        response = new MockHttpServletResponse();
        writer = new CacheControlHeadersWriter();
    } 
 
    @Test
    public void writeHeaders() { 
        writer.writeHeaders(request, response);
 
        assertThat(response.getHeaderNames().size()).isEqualTo(3);
        assertThat(response.getHeaderValues("Cache-Control")).isEqualTo(Arrays.asList("no-cache, no-store, max-age=0, must-revalidate"));
        assertThat(response.getHeaderValues("Pragma")).isEqualTo(Arrays.asList("no-cache"));
        assertThat(response.getHeaderValues("Expires")).isEqualTo(Arrays.asList("0"));
    } 
} 
9
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
 
    private MockHttpServletRequest request;
 
    @Before 
    public void setup() { 
        request = new MockHttpServletRequest();
    } 
 
    @Test
    public void x509SingleCertificate() { 
        MockHttpServletRequest postProcessedRequest = x509(certificate).postProcessRequest(request);
 
        X509Certificate[] certificates = (X509Certificate[]) postProcessedRequest.getAttribute("javax.servlet.request.X509Certificate");
 
        assertThat(certificates).containsOnly(certificate);
    } 
 
    @Test
    public void x509ResourceName() throws Exception {
        MockHttpServletRequest postProcessedRequest = x509("rod.cer").postProcessRequest(request);
9
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
 
    private CsrfLogoutHandler handler; 
 
    @Before 
    public void setup() { 
        request = new MockHttpServletRequest(); 
        response = new MockHttpServletResponse(); 
        handler = new CsrfLogoutHandler(csrfTokenRepository); 
    } 
 
    @Test(expected = IllegalArgumentException.class) 
    public void constructorNullCsrfTokenRepository() { 
        new CsrfLogoutHandler(null); 
    } 
 
    @Test 
    public void logoutRemovesCsrfToken() { 
        handler.logout(request, response, new TestingAuthenticationToken("user", "password", "ROLE_USER")); 
 
        verify(csrfTokenRepository).saveToken(null, request, response); 
9
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
 */ 
public abstract class AbstractHttpInboundTests { 
 
	@Before 
	public void setupHttpInbound() { 
		RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(new MockHttpServletRequest())); 
	} 
 
	@After 
	public void tearDownHttpInbound() { 
		RequestContextHolder.resetRequestAttributes(); 
	} 
 
} 
9
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
 
    @Before 
    public void setup() { 
        authenticationStrategy = new RegisterSessionAuthenticationStrategy(registry); 
        authentication = new TestingAuthenticationToken("user", "password","ROLE_USER"); 
        request = new MockHttpServletRequest(); 
        response = new MockHttpServletResponse(); 
    } 
 
    @Test(expected = IllegalArgumentException.class) 
    public void constructorNullRegistry() { 
        new RegisterSessionAuthenticationStrategy(null); 
    } 
 
    @Test 
    public void onAuthenticationRegistersSession() { 
        authenticationStrategy.onAuthentication(authentication, request, response); 
 
        verify(registry).registerNewSession(request.getSession().getId(), authentication.getPrincipal()); 
    } 
9
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
 */ 
public class WhitelabelApprovalEndpointTests { 
	 
	private WhitelabelApprovalEndpoint endpoint = new WhitelabelApprovalEndpoint(); 
	private Map<String, String> parameters = new HashMap<String, String>(); 
	private MockHttpServletRequest request = new MockHttpServletRequest(); 
	private MockHttpServletResponse response = new MockHttpServletResponse(); 
 
	private AuthorizationRequest createFromParameters(Map<String, String> authorizationParameters) { 
		AuthorizationRequest request = new AuthorizationRequest(authorizationParameters, Collections.<String, String> emptyMap(),  
				authorizationParameters.get(OAuth2Utils.CLIENT_ID),  
				OAuth2Utils.parseParameterList(authorizationParameters.get(OAuth2Utils.SCOPE)), null, 
				null, false, authorizationParameters.get(OAuth2Utils.STATE),  
				authorizationParameters.get(OAuth2Utils.REDIRECT_URI),  
				OAuth2Utils.parseParameterList(authorizationParameters.get(OAuth2Utils.RESPONSE_TYPE))); 
		return request; 
	} 
	 
	@Test 
	public void testApprovalPage() throws Exception { 
9
CodeRank
Experience pair programming with AI  Get Codota for Java
See Code Examples for Spring Framework MockHttpServletRequest Methods: