本文整理汇总了Java中org.springframework.test.web.servlet.request.RequestPostProcessor类的典型用法代码示例。如果您正苦于以下问题:Java RequestPostProcessor类的具体用法?Java RequestPostProcessor怎么用?Java RequestPostProcessor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RequestPostProcessor类属于org.springframework.test.web.servlet.request包,在下文中一共展示了RequestPostProcessor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: userToken
import org.springframework.test.web.servlet.request.RequestPostProcessor; //导入依赖的package包/类
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.");
}
};
}
示例2: whenUserInfoNotInSessionThenEmptySessionExceptionIsThrown
import org.springframework.test.web.servlet.request.RequestPostProcessor; //导入依赖的package包/类
@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));
}
示例3: whenUserInfoHasInvalidBarcodeThenPatronLibraryAccessExceptionIsThrown
import org.springframework.test.web.servlet.request.RequestPostProcessor; //导入依赖的package包/类
@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();
}
示例4: build
import org.springframework.test.web.servlet.request.RequestPostProcessor; //导入依赖的package包/类
/**
* 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);
}
示例5: beforeMockMvcCreated
import org.springframework.test.web.servlet.request.RequestPostProcessor; //导入依赖的package包/类
@Override
public RequestPostProcessor beforeMockMvcCreated(ConfigurableMockMvcBuilder<?> builder,
WebApplicationContext context) {
return request -> {
request.setUserPrincipal(mock(Principal.class));
return request;
};
}
示例6: testAuthenticatedUser
import org.springframework.test.web.servlet.request.RequestPostProcessor; //导入依赖的package包/类
@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"));
}
示例7: bearerToken
import org.springframework.test.web.servlet.request.RequestPostProcessor; //导入依赖的package包/类
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;
};
}
示例8: testAuthenticatedUser
import org.springframework.test.web.servlet.request.RequestPostProcessor; //导入依赖的package包/类
@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"));
}
示例9: testAuthenticatedUser
import org.springframework.test.web.servlet.request.RequestPostProcessor; //导入依赖的package包/类
@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"));
}
示例10: oauth2Authentication
import org.springframework.test.web.servlet.request.RequestPostProcessor; //导入依赖的package包/类
public RequestPostProcessor oauth2Authentication(String username, Set<String> scopes) {
return oauth2Authentication(username, scopes, Collections.emptySet());
}
示例11: userCredentials
import org.springframework.test.web.servlet.request.RequestPostProcessor; //导入依赖的package包/类
private RequestPostProcessor userCredentials() {
return httpBasic("user", "password");
}
开发者ID:spring-projects,项目名称:spring-security-oauth2-boot,代码行数:4,代码来源:SampleSecureOAuth2ActuatorApplicationTests.java
示例12: setupRequest
import org.springframework.test.web.servlet.request.RequestPostProcessor; //导入依赖的package包/类
private RequestPostProcessor setupRequest() {
return request -> {
request.setRemoteAddr("127.0.0.1");
return request;
};
}
示例13: testPostpage0
import org.springframework.test.web.servlet.request.RequestPostProcessor; //导入依赖的package包/类
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, "")));
}
示例14: beforeMockMvcCreated
import org.springframework.test.web.servlet.request.RequestPostProcessor; //导入依赖的package包/类
@Override
public RequestPostProcessor beforeMockMvcCreated(ConfigurableMockMvcBuilder<?> builder, WebApplicationContext cxt) {
return null;
}
示例15: setForwardPostProcessor
import org.springframework.test.web.servlet.request.RequestPostProcessor; //导入依赖的package包/类
public void setForwardPostProcessor(RequestPostProcessor forwardPostProcessor) {
this.forwardPostProcessor = forwardPostProcessor;
}