Java 类org.springframework.test.web.servlet.request.RequestPostProcessor 实例源码

项目:spring-auto-restdocs    文件:MockMvcBase.java   
protected RequestPostProcessor userToken() {
    return new RequestPostProcessor() {
        @Override
        public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) {
            // If the tests requires setup logic for users, you can place it here.
            // Authorization headers or cookies for users should be added here as well.
            String accessToken;
            try {
                accessToken = getAccessToken("test", "test");
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            request.addHeader("Authorization", "Bearer " + accessToken);
            return documentAuthorization(request, "User access token required.");
        }
    };
}
项目:AlmaPortlet    文件:ServletIntegrationTest.java   
@Test
public void whenUserInfoNotInSessionThenEmptySessionExceptionIsThrown() throws Exception{

    mockMvc.perform(get("/summary")
            .accept(MediaType.APPLICATION_JSON)
            .with(new RequestPostProcessor() {

                @Override
                public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) {

                    request.getSession(true);
                    return request;
                }
            }))
            .andExpect(status().isInternalServerError())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON));
}
项目:AlmaPortlet    文件:ServletIntegrationTest.java   
@Test
public void whenUserInfoHasInvalidBarcodeThenPatronLibraryAccessExceptionIsThrown() throws Exception {

    final UserInfo userInfo = new UserInfo("BadUUN","BadBarcode","BadSurname");

        mockMvc.perform(get("/summary")
            .accept(MediaType.APPLICATION_JSON)
            .with(new RequestPostProcessor() {

                @Override
                public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) {

                    MockHttpSession mockSession = (MockHttpSession) request.getSession(true);
                    mockSession.setAttribute(UserInfo.SESSION_ATTR, userInfo);
                    request.setSession(mockSession);

                    return request;
                }
            }))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON))
            .andExpect(jsonPath("$.*", hasSize(9)))
            .andExpect(jsonPath("$.message", nullValue()))
            .andExpect(jsonPath("$.payload", nullValue()))
            .andReturn();
}
项目:spring4-understanding    文件:AbstractMockMvcBuilder.java   
/**
 * Build a {@link org.springframework.test.web.servlet.MockMvc} instance.
 */
@Override
@SuppressWarnings("rawtypes")
public final MockMvc build() {

    WebApplicationContext wac = initWebAppContext();

    ServletContext servletContext = wac.getServletContext();
    MockServletConfig mockServletConfig = new MockServletConfig(servletContext);

    for (MockMvcConfigurer configurer : this.configurers) {
        RequestPostProcessor processor = configurer.beforeMockMvcCreated(this, wac);
        if (processor != null) {
            if (this.defaultRequestBuilder == null) {
                this.defaultRequestBuilder = MockMvcRequestBuilders.get("/");
            }
            if (this.defaultRequestBuilder instanceof ConfigurableSmartRequestBuilder) {
                ((ConfigurableSmartRequestBuilder) this.defaultRequestBuilder).with(processor);
            }
        }
    }

    Filter[] filterArray = this.filters.toArray(new Filter[this.filters.size()]);

    return super.createMockMvc(filterArray, mockServletConfig, wac, this.defaultRequestBuilder,
            this.globalResultMatchers, this.globalResultHandlers, this.dispatchOptions);
}
项目:spring4-understanding    文件:FrameworkExtensionTests.java   
@Override
public RequestPostProcessor beforeMockMvcCreated(ConfigurableMockMvcBuilder<?> builder,
        WebApplicationContext context) {
    return request -> {
        request.setUserPrincipal(mock(Principal.class));
        return request;
    };
}
项目:angularjs-springboot-bookstore    文件:AccountResourceTest.java   
@Test
public void testAuthenticatedUser() throws Exception {
    restUserMockMvc.perform(get("/api/authenticate")
            .with(new RequestPostProcessor() {
                public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) {
                    request.setRemoteUser("test");
                    return request;
                }
            })
            .accept(MediaType.APPLICATION_JSON))
            .andExpect(status().isOk())
            .andExpect(content().string("test"));
}
项目:resource-server-testing    文件:OAuthHelper.java   
public RequestPostProcessor bearerToken(final String clientid, final String username) {
    return mockRequest -> {
        OAuth2Authentication auth = oAuth2Authentication(clientid, username);
        OAuth2AccessToken token = tokenservice.createAccessToken(auth);
        mockRequest.addHeader("Authorization", "Bearer " + token.getValue());
        return mockRequest;
    };
}
项目:OrcidHub    文件:AccountResourceTest.java   
@Test
public void testAuthenticatedUser() throws Exception {
    restUserMockMvc.perform(get("/api/authenticate")
            .with(new RequestPostProcessor() {
                public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) {
                    request.setRemoteUser("test");
                    return request;
                }
            })
            .accept(MediaType.APPLICATION_JSON))
            .andExpect(status().isOk())
            .andExpect(content().string("test"));
}
项目:ithings-demo    文件:AccountResourceTest.java   
@Test
public void testAuthenticatedUser() throws Exception {
    restUserMockMvc.perform(get("/app/rest/authenticate")
            .with(new RequestPostProcessor() {
                public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) {
                    request.setRemoteUser("test");
                    return request;
                }
            })
            .accept(MediaType.APPLICATION_JSON))
            .andExpect(status().isOk())
            .andExpect(content().string("test"));
}
项目:JQuaternion    文件:AccountResourceTest.java   
@Test
public void testAuthenticatedUser() throws Exception {
    restUserMockMvc.perform(get("/app/rest/authenticate")
            .with(new RequestPostProcessor() {
                public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) {
                    request.setRemoteUser("test");
                    return request;
                }
            })
            .accept(MediaType.APPLICATION_JSON))
            .andExpect(status().isOk())
            .andExpect(content().string("test"));
}
项目:lightadmin-jhipster    文件:AccountResourceTest.java   
@Test
public void testAuthenticatedUser() throws Exception {
    restUserMockMvc.perform(get("/app/rest/authenticate")
            .with(new RequestPostProcessor() {
                public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) {
                    request.setRemoteUser("test");
                    return request;
                }
            })
            .accept(MediaType.APPLICATION_JSON))
            .andExpect(status().isOk())
            .andExpect(content().string("test"));
}
项目:MLDS    文件:AccountResourceTest.java   
@Test
public void testAuthenticatedUser() throws Exception {
    restUserMockMvc.perform(get("/api/authenticate")
            .with(new RequestPostProcessor() {
                public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) {
                    request.setRemoteUser("test");
                    return request;
                }
            })
            .accept(MediaType.APPLICATION_JSON_UTF8))
            .andExpect(status().isOk())
            .andExpect(content().string("test"));
}
项目:cevent-app    文件:AccountResourceTest.java   
@Test
public void testAuthenticatedUser() throws Exception {
    restUserMockMvc.perform(get("/app/rest/authenticate")
            .with(new RequestPostProcessor() {
                public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) {
                    request.setRemoteUser("test");
                    return request;
                }
            })
            .accept(MediaType.APPLICATION_JSON))
            .andExpect(status().isOk())
            .andExpect(content().string("test"));
}
项目:parkingfriends    文件:AccountResourceTest.java   
@Test
public void testAuthenticatedUser() throws Exception {
    restUserMockMvc.perform(get("/app/rest/authenticate")
            .with(new RequestPostProcessor() {
                public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) {
                    request.setRemoteUser("test");
                    return request;
                }
            })
            .accept(MediaType.APPLICATION_JSON))
            .andExpect(status().isOk())
            .andExpect(content().string("test"));
}
项目:xm-uaa    文件:OAuth2TokenMockUtil.java   
public RequestPostProcessor oauth2Authentication(String username, Set<String> scopes) {
    return oauth2Authentication(username, scopes, Collections.emptySet());
}
项目:xm-uaa    文件:OAuth2TokenMockUtil.java   
public RequestPostProcessor oauth2Authentication(String username) {
    return oauth2Authentication(username, Collections.emptySet());
}
项目:spring-security-oauth2-boot    文件:SampleSecureOAuth2ActuatorApplicationTests.java   
private RequestPostProcessor userCredentials() {
    return httpBasic("user", "password");
}
项目:amv-access-api-poc    文件:DeviceCertificateCtrlExampleRequests.java   
private RequestPostProcessor setupRequest() {
    return request -> {
        request.setRemoteAddr("127.0.0.1");
        return request;
    };
}
项目:xm-ms-balance    文件:OAuth2TokenMockUtil.java   
public RequestPostProcessor oauth2Authentication(String username, Set<String> scopes) {
    return oauth2Authentication(username, scopes, Collections.emptySet());
}
项目:xm-ms-balance    文件:OAuth2TokenMockUtil.java   
public RequestPostProcessor oauth2Authentication(String username) {
    return oauth2Authentication(username, Collections.emptySet());
}
项目:xm-ms-dashboard    文件:OAuth2TokenMockUtil.java   
public RequestPostProcessor oauth2Authentication(String username, Set<String> scopes) {
    return oauth2Authentication(username, scopes, Collections.emptySet());
}
项目:xm-ms-dashboard    文件:OAuth2TokenMockUtil.java   
public RequestPostProcessor oauth2Authentication(String username) {
    return oauth2Authentication(username, Collections.emptySet());
}
项目:xm-gate    文件:OAuth2TokenMockUtil.java   
public RequestPostProcessor oauth2Authentication(String username, Set<String> scopes) {
    return oauth2Authentication(username, scopes, Collections.emptySet());
}
项目:xm-gate    文件:OAuth2TokenMockUtil.java   
public RequestPostProcessor oauth2Authentication(String username) {
    return oauth2Authentication(username, Collections.emptySet());
}
项目:xm-ms-entity    文件:OAuth2TokenMockUtil.java   
public RequestPostProcessor oauth2Authentication(String username, Set<String> scopes) {
    return oauth2Authentication(username, scopes, Collections.emptySet());
}
项目:xm-ms-entity    文件:OAuth2TokenMockUtil.java   
public RequestPostProcessor oauth2Authentication(String username) {
    return oauth2Authentication(username, Collections.emptySet());
}
项目:xm-ms-timeline    文件:OAuth2TokenMockUtil.java   
public RequestPostProcessor oauth2Authentication(String username, Set<String> scopes) {
    return oauth2Authentication(username, scopes, Collections.emptySet());
}
项目:xm-ms-timeline    文件:OAuth2TokenMockUtil.java   
public RequestPostProcessor oauth2Authentication(String username) {
    return oauth2Authentication(username, Collections.emptySet());
}
项目:xm-ms-config    文件:OAuth2TokenMockUtil.java   
public RequestPostProcessor oauth2Authentication(String username, Set<String> scopes) {
    return oauth2Authentication(username, scopes, Collections.emptySet());
}
项目:xm-ms-config    文件:OAuth2TokenMockUtil.java   
public RequestPostProcessor oauth2Authentication(String username) {
    return oauth2Authentication(username, Collections.emptySet());
}
项目:judge    文件:BBSControllerTest.java   
private ResultActions testPostpage0(RequestPostProcessor postProcessor) throws Exception {
    log.info("postpage");
    Long problem_id = null;
    return mvc.perform(get("/postpage").with(postProcessor)
            .param("problem_id", Objects.toString(problem_id, "")));
}
项目:spring4-understanding    文件:MockMvcConfigurerAdapter.java   
@Override
public RequestPostProcessor beforeMockMvcCreated(ConfigurableMockMvcBuilder<?> builder, WebApplicationContext cxt) {
    return null;
}
项目:spring4-understanding    文件:HtmlUnitRequestBuilder.java   
public void setForwardPostProcessor(RequestPostProcessor forwardPostProcessor) {
    this.forwardPostProcessor = forwardPostProcessor;
}
项目:JavaSpringMvcBlog    文件:SecurityUtils.java   
public static RequestPostProcessor userAlice() {
    return user("Alice").roles("USER");
}
项目:JavaSpringMvcBlog    文件:SecurityUtils.java   
public static RequestPostProcessor userBob() {
    return user("Bob").roles("USER");
}
项目:JavaSpringMvcBlog    文件:SecurityUtils.java   
public static RequestPostProcessor userAdmin() {
    return user("admin").roles("USER", "ADMIN");
}
项目:atsy    文件:AbstractControllerTest.java   
@Override
public RequestPostProcessor beforeMockMvcCreated(ConfigurableMockMvcBuilder<?> builder, WebApplicationContext context) {
  AbstractControllerTest.this.lazySpringConstraintValidatorFactory.setDelegate(new SpringConstraintValidatorFactory(context.getAutowireCapableBeanFactory()));
  AbstractControllerTest.this.lazySpringConstraintValidatorFactory.setBeanFactory(context.getAutowireCapableBeanFactory());
  return null;
}
项目:resource-server-testing    文件:MyControllerTest.java   
@Test
public void testHelloUserWithRole() throws Exception {
    RequestPostProcessor bearerToken = helper.bearerToken("myclientwith", "user");
    mvc.perform(get("/hello").with(bearerToken)).andExpect(status().isOk()).andExpect(content().string("Hello user"));
}
项目:resource-server-testing    文件:MyControllerTest.java   
@Test
public void testHelloAliceWithRole() throws Exception {
    RequestPostProcessor bearerToken = helper.bearerToken("myclientwith", "alice");
    mvc.perform(get("/hello").with(bearerToken)).andExpect(status().isOk()).andExpect(content().string("Hello alice"));
}
项目:resource-server-testing    文件:MyControllerTest.java   
@Test
public void testHelloWithoutRole() throws Exception {
    RequestPostProcessor bearerToken = helper.bearerToken("myclientwithout", "user");
    mvc.perform(get("/hello").with(bearerToken)).andExpect(status().isForbidden());
}