Search in sources :

Example 26 with ServletWebRequest

use of org.springframework.web.context.request.ServletWebRequest in project spring-data-commons by spring-projects.

the class SortHandlerMethodArgumentResolverUnitTests method fallbackToGivenDefaultSort.

// DATACMNS-351
@Test
public void fallbackToGivenDefaultSort() throws Exception {
    MethodParameter parameter = TestUtils.getParameterOfMethod(getControllerClass(), "unsupportedMethod", String.class);
    SortHandlerMethodArgumentResolver resolver = new SortHandlerMethodArgumentResolver();
    Sort fallbackSort = Sort.by(Direction.ASC, "ID");
    resolver.setFallbackSort(fallbackSort);
    Sort sort = resolver.resolveArgument(parameter, null, new ServletWebRequest(new MockHttpServletRequest()), null);
    assertThat(sort).isEqualTo(fallbackSort);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Sort(org.springframework.data.domain.Sort) MethodParameter(org.springframework.core.MethodParameter) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest) Test(org.junit.Test)

Example 27 with ServletWebRequest

use of org.springframework.web.context.request.ServletWebRequest in project spring-data-commons by spring-projects.

the class QuerydslPredicateArgumentResolverUnitTests method resolveArgumentShouldResolveTypePropertyFromPageCorrectly.

// DATACMNS-669
@Test
public void resolveArgumentShouldResolveTypePropertyFromPageCorrectly() throws Exception {
    request.addParameter("address.city", "tar valon");
    Predicate predicate = resolver.resolveArgument(getMethodParameterFor("pagedFind", Predicate.class, Pageable.class), null, new ServletWebRequest(request), null);
    assertThat(predicate).isEqualTo((Predicate) QUser.user.address.city.eq("tar valon"));
}
Also used : Pageable(org.springframework.data.domain.Pageable) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest) QuerydslPredicate(org.springframework.data.querydsl.binding.QuerydslPredicate) Predicate(com.querydsl.core.types.Predicate) Test(org.junit.Test)

Example 28 with ServletWebRequest

use of org.springframework.web.context.request.ServletWebRequest in project profile by craftercms.

the class ProviderLoginSupportImpl method completeConnection.

protected Connection<?> completeConnection(ConnectSupport connectSupport, String providerId, HttpServletRequest request) throws OAuth2Exception {
    if (StringUtils.isNotEmpty(request.getParameter(PARAM_OAUTH_TOKEN))) {
        OAuth1ConnectionFactory<?> connectionFactory = (OAuth1ConnectionFactory<?>) getConnectionFactory(providerId);
        ServletWebRequest webRequest = new ServletWebRequest(request);
        return connectSupport.completeConnection(connectionFactory, webRequest);
    } else if (StringUtils.isNotEmpty(request.getParameter(PARAM_CODE))) {
        OAuth2ConnectionFactory<?> connectionFactory = (OAuth2ConnectionFactory<?>) getConnectionFactory(providerId);
        ServletWebRequest webRequest = new ServletWebRequest(request);
        return connectSupport.completeConnection(connectionFactory, webRequest);
    } else if (StringUtils.isNotEmpty(request.getParameter(PARAM_ERROR))) {
        String error = request.getParameter(PARAM_ERROR);
        String errorDescription = request.getParameter(PARAM_ERROR_DESCRIPTION);
        String errorUri = request.getParameter(PARAM_ERROR_URI);
        throw new OAuth2Exception(error, errorDescription, errorUri);
    } else {
        return null;
    }
}
Also used : OAuth1ConnectionFactory(org.springframework.social.connect.support.OAuth1ConnectionFactory) OAuth2ConnectionFactory(org.springframework.social.connect.support.OAuth2ConnectionFactory) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest) OAuth2Exception(org.craftercms.security.exception.OAuth2Exception)

Example 29 with ServletWebRequest

use of org.springframework.web.context.request.ServletWebRequest in project spring-security by spring-projects.

the class OAuth2AuthorizedClientArgumentResolverTests method resolveArgumentWhenRegistrationIdInvalidThenThrowIllegalArgumentException.

@Test
public void resolveArgumentWhenRegistrationIdInvalidThenThrowIllegalArgumentException() {
    MethodParameter methodParameter = this.getMethodParameter("registrationIdInvalid", OAuth2AuthorizedClient.class);
    assertThatIllegalArgumentException().isThrownBy(() -> this.argumentResolver.resolveArgument(methodParameter, null, new ServletWebRequest(this.request, this.response), null)).withMessage("Could not find ClientRegistration with id 'invalid'");
}
Also used : MethodParameter(org.springframework.core.MethodParameter) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest) Test(org.junit.jupiter.api.Test)

Example 30 with ServletWebRequest

use of org.springframework.web.context.request.ServletWebRequest in project spring-security by spring-projects.

the class OAuth2AuthorizedClientArgumentResolverTests method resolveArgumentWhenAuthorizedClientNotFoundForAuthorizationCodeClientThenThrowClientAuthorizationRequiredException.

@Test
public void resolveArgumentWhenAuthorizedClientNotFoundForAuthorizationCodeClientThenThrowClientAuthorizationRequiredException() {
    given(this.authorizedClientRepository.loadAuthorizedClient(anyString(), any(), any(HttpServletRequest.class))).willReturn(null);
    MethodParameter methodParameter = this.getMethodParameter("paramTypeAuthorizedClient", OAuth2AuthorizedClient.class);
    assertThatExceptionOfType(ClientAuthorizationRequiredException.class).isThrownBy(() -> this.argumentResolver.resolveArgument(methodParameter, null, new ServletWebRequest(this.request, this.response), null));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServletRequest(jakarta.servlet.http.HttpServletRequest) ClientAuthorizationRequiredException(org.springframework.security.oauth2.client.ClientAuthorizationRequiredException) MethodParameter(org.springframework.core.MethodParameter) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest) Test(org.junit.jupiter.api.Test)

Aggregations

ServletWebRequest (org.springframework.web.context.request.ServletWebRequest)224 MockHttpServletRequest (org.springframework.web.testfixture.servlet.MockHttpServletRequest)80 Test (org.junit.jupiter.api.Test)79 MethodParameter (org.springframework.core.MethodParameter)50 BeforeEach (org.junit.jupiter.api.BeforeEach)41 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)32 ModelAndViewContainer (org.springframework.web.method.support.ModelAndViewContainer)30 MockHttpServletResponse (org.springframework.web.testfixture.servlet.MockHttpServletResponse)28 Method (java.lang.reflect.Method)21 Test (org.junit.Test)21 MockMultipartHttpServletRequest (org.springframework.web.testfixture.servlet.MockMultipartHttpServletRequest)21 MockMultipartFile (org.springframework.web.testfixture.servlet.MockMultipartFile)18 ITestBean (org.springframework.beans.testfixture.beans.ITestBean)14 TestBean (org.springframework.beans.testfixture.beans.TestBean)14 RequestParam (org.springframework.web.bind.annotation.RequestParam)14 MockPart (org.springframework.web.testfixture.servlet.MockPart)14 HttpServletRequest (javax.servlet.http.HttpServletRequest)13 MultipartFile (org.springframework.web.multipart.MultipartFile)13 SynthesizingMethodParameter (org.springframework.core.annotation.SynthesizingMethodParameter)11 IOException (java.io.IOException)10