本文整理匯總了Java中org.springframework.mock.web.MockHttpServletRequest.setMethod方法的典型用法代碼示例。如果您正苦於以下問題:Java MockHttpServletRequest.setMethod方法的具體用法?Java MockHttpServletRequest.setMethod怎麽用?Java MockHttpServletRequest.setMethod使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.mock.web.MockHttpServletRequest
的用法示例。
在下文中一共展示了MockHttpServletRequest.setMethod方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: loginUnsuccessfully
import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Override
protected MockHttpServletResponse loginUnsuccessfully(final String username, final String fromAddress)
throws Exception {
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockHttpServletResponse response = new MockHttpServletResponse();
request.setMethod("POST");
request.setParameter("username", username);
request.setRemoteAddr(fromAddress);
final MockRequestContext context = new MockRequestContext();
context.setCurrentEvent(new Event("", "error"));
request.setAttribute("flowRequestContext", context);
ClientInfoHolder.setClientInfo(new ClientInfo(request));
getThrottle().preHandle(request, response, null);
try {
authenticationManager.authenticate(AuthenticationTransaction.wrap(badCredentials(username)));
} catch (final AuthenticationException e) {
getThrottle().postHandle(request, response, null, null);
return response;
}
fail("Expected AbstractAuthenticationException");
return null;
}
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:25,代碼來源:InspektrThrottledSubmissionByIpAddressAndUsernameHandlerInterceptorAdapterTests.java
示例2: testAcceptJsonApi
import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void testAcceptJsonApi() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest(servletContext);
request.setMethod("GET");
request.setContextPath("");
request.setServletPath("/api");
request.setPathInfo("/tasks/1");
request.setRequestURI("/api/tasks/1");
request.addHeader("Accept", HttpHeaders.JSONAPI_CONTENT_TYPE);
MockHttpServletResponse response = new MockHttpServletResponse();
servlet.service(request, response);
String responseContent = response.getContentAsString();
log.debug("responseContent: {}", responseContent);
assertNotNull(responseContent);
assertJsonPartEquals("tasks", responseContent, "data.type");
assertJsonPartEquals("\"1\"", responseContent, "data.id");
assertJsonPartEquals(SOME_TASK_ATTRIBUTES, responseContent, "data.attributes");
assertJsonPartEquals(FIRST_TASK_LINKS, responseContent, "data.links");
assertJsonPartEquals(PROJECT1_RELATIONSHIP_LINKS, responseContent, "data.relationships.project.links");
}
示例3: testIncludeWithNullIterableRelationshipCall
import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void testIncludeWithNullIterableRelationshipCall() throws Exception {
Node root = new Node(1L, null, null);
// by making the setting children null and requesting them in the
// include statement should cause a serialization error
Node child1 = new Node(2L, root, null);
Node child2 = new Node(3L, root, null);
root.setChildren(new LinkedHashSet<>(Arrays.asList(child1, child2)));
nodeRepository.save(root);
nodeRepository.save(child1);
nodeRepository.save(child2);
MockHttpServletRequest request = new MockHttpServletRequest(servletContext);
request.setMethod("GET");
request.setServletPath("/api");
request.setPathInfo("/nodes");
request.setRequestURI("/api/nodes");
request.setQueryString("include[nodes]=children");
request.setContentType(HttpHeaders.JSONAPI_CONTENT_TYPE);
Map<String, String> params = new HashMap<>();
params.put("include[nodes]", "children");
request.setParameters(params);
request.addHeader("Accept", "*/*");
MockHttpServletResponse response = new MockHttpServletResponse();
servlet.service(request, response);
assertEquals(500, response.getStatus());
}
示例4: testGetUrl
import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void testGetUrl() {
MockHttpServletRequest request = new MockHttpServletRequest(servletContext);
request.setMethod("GET");
request.setContextPath("");
request.setServletPath("/api");
request.setPathInfo("/tasks/");
request.setRequestURI("/api/tasks/");
request.setContentType(HttpHeaders.JSONAPI_CONTENT_TYPE);
request.addHeader("Accept", "*/*");
request.setServerName("test");
request.setServerPort(1234);
ServletRequestContext context = new ServletRequestContext(servletContext, request, response, "/api");
Assert.assertEquals("http://test:1234/api", context.getBaseUrl());
Assert.assertEquals("/tasks/", context.getPath());
}
示例5: loginUnsuccessfully
import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Override
protected MockHttpServletResponse loginUnsuccessfully(final String username, final String fromAddress) throws Exception {
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockHttpServletResponse response = new MockHttpServletResponse();
request.setMethod("POST");
request.setParameter("username", username);
request.setRemoteAddr(fromAddress);
final MockRequestContext context = new MockRequestContext();
context.setCurrentEvent(new Event(StringUtils.EMPTY, "error"));
request.setAttribute("flowRequestContext", context);
ClientInfoHolder.setClientInfo(new ClientInfo(request));
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
throttle.preHandle(request, response, null);
try {
authenticationManager.authenticate(AuthenticationTransaction.wrap(CoreAuthenticationTestUtils.getService(), badCredentials(username)));
} catch (final AuthenticationException e) {
throttle.postHandle(request, response, null, null);
return response;
}
fail("Expected AbstractAuthenticationException");
return null;
}
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:25,代碼來源:InspektrThrottledSubmissionByIpAddressAndUsernameHandlerInterceptorAdapterTests.java
示例6: testInclude
import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void testInclude() throws Exception {
Node root = new Node(1L, null, null);
Node child1 = new Node(2L, root, Collections.<Node>emptySet());
Node child2 = new Node(3L, root, Collections.<Node>emptySet());
root.setChildren(new LinkedHashSet<>(Arrays.asList(child1, child2)));
nodeRepository.save(root);
nodeRepository.save(child1);
nodeRepository.save(child2);
MockHttpServletRequest request = new MockHttpServletRequest(servletContext);
request.setMethod("GET");
request.setServletPath("/api");
request.setPathInfo("/nodes/1");
request.setRequestURI("/api/nodes/1");
request.setQueryString("include[nodes]=parent");
request.setContentType(HttpHeaders.JSONAPI_CONTENT_TYPE);
Map<String, String> params = new HashMap<>();
params.put("include[nodes]", "children");
request.setParameters(params);
request.addHeader("Accept", "*/*");
MockHttpServletResponse response = new MockHttpServletResponse();
servlet.service(request, response);
String responseContent = response.getContentAsString();
assertTopLevelNodesCorrectWithChildren(responseContent);
}
示例7: testUnacceptableRequestContentType
import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void testUnacceptableRequestContentType() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest(servletContext);
request.setMethod("GET");
request.setContextPath("");
request.setServletPath("/api");
request.setPathInfo("/tasks");
request.setRequestURI("/api/tasks");
request.setContentType(HttpHeaders.JSONAPI_CONTENT_TYPE);
request.addHeader("Accept", "application/xml");
request.addParameter("filter[Task][name]", "John");
request.setQueryString(URLEncoder.encode("filter[Task][name]", StandardCharsets.UTF_8.name()) + "=John");
MockHttpServletResponse response = new MockHttpServletResponse();
servlet.service(request, response);
assertEquals(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, response.getStatus());
String responseContent = response.getContentAsString();
assertTrue(responseContent == null || "".equals(responseContent.trim()));
}
示例8: testAcceptPlainJson
import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void testAcceptPlainJson() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest(servletContext);
request.setMethod("GET");
request.setContextPath("");
request.setServletPath("/api");
request.setPathInfo("/tasks/1");
request.setRequestURI("/api/tasks/1");
request.addHeader("Accept", "application/json");
MockHttpServletResponse response = new MockHttpServletResponse();
servlet.service(request, response);
String responseContent = response.getContentAsString();
log.debug("responseContent: {}", responseContent);
assertNotNull(responseContent);
assertJsonPartEquals("tasks", responseContent, "data.type");
assertJsonPartEquals("\"1\"", responseContent, "data.id");
assertJsonPartEquals(SOME_TASK_ATTRIBUTES, responseContent, "data.attributes");
assertJsonPartEquals(FIRST_TASK_LINKS, responseContent, "data.links");
assertJsonPartEquals(PROJECT1_RELATIONSHIP_LINKS, responseContent, "data.relationships.project.links");
}
示例9: setUp
import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@BeforeMethod
protected void setUp() throws Exception {
httpRequest = new MockHttpServletRequest();
httpRequest.setMethod(Method.POST.toString());
decoder = new OIDCClientRegistrationRequestDecoder();
decoder.setHttpServletRequest(httpRequest);
decoder.initialize();
}
開發者ID:CSCfi,項目名稱:shibboleth-idp-oidc-extension,代碼行數:9,代碼來源:OIDCClientRegistrationRequestDecoderTest.java
示例10: buildRequestLog_WithNoBody_ReturnStringRequestWithUriAndEmptyBody
import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void buildRequestLog_WithNoBody_ReturnStringRequestWithUriAndEmptyBody() {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod(HttpMethod.GET.name());
request.setRequestURI("/dummy");
String log = FILTER.buildRequestLog(new ContentCachingRequestWrapper(request));
assertThat(log, is("Server has received a request\n > GET http://localhost/dummy\n[empty]"));
}
示例11: verifyProperMatchCorrectMethodWithParam
import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void verifyProperMatchCorrectMethodWithParam() throws Exception {
final MockHttpServletRequest request = new MockHttpServletRequest();
request.setContextPath("/login");
request.setMethod("POST");
request.setParameter("openid.mode", "check_authentication");
assertNotNull(this.handlerMapping.lookupHandler("/login", request));
}
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:11,代碼來源:OpenIdPostUrlHandlerMappingTests.java
示例12: verifyProperMatchWrongMethod
import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void verifyProperMatchWrongMethod() throws Exception {
final MockHttpServletRequest request = new MockHttpServletRequest();
request.setContextPath("/login");
request.setMethod("GET");
assertNull(this.handlerMapping.lookupHandler("/login", request));
}
示例13: loginUnsuccessfully
import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Override
protected MockHttpServletResponse loginUnsuccessfully(final String username, final String fromAddress) throws Exception {
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockHttpServletResponse response = new MockHttpServletResponse();
request.setMethod("POST");
request.setParameter("username", username);
request.setRemoteAddr(fromAddress);
final MockRequestContext context = new MockRequestContext();
context.setCurrentEvent(new Event("", "error"));
request.setAttribute("flowRequestContext", context);
getThrottle().preHandle(request, response, null);
getThrottle().postHandle(request, response, null, null);
return response;
}
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:15,代碼來源:AbstractInMemoryThrottledSubmissionHandlerInterceptorAdapterTests.java
示例14: testIncludeNestedWithDefault
import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void testIncludeNestedWithDefault() throws Exception {
Node root = new Node(1L, null, null);
Locale engLocale = new Locale(1L, java.util.Locale.ENGLISH);
Node child1 = new Node(2L, root, Collections.<Node>emptySet());
NodeComment child1Comment = new NodeComment(1L, "Child 1", child1, engLocale);
child1.setNodeComments(new LinkedHashSet<>(Collections.singleton(child1Comment)));
Node child2 = new Node(3L, root, Collections.<Node>emptySet(), Collections.<NodeComment>emptySet());
root.setChildren(new LinkedHashSet<>(Arrays.asList(child1, child2)));
nodeRepository.save(root);
nodeRepository.save(child1);
nodeRepository.save(child2);
MockHttpServletRequest request = new MockHttpServletRequest(servletContext);
request.setMethod("GET");
request.setServletPath("/api");
request.setPathInfo("/nodes/1");
request.setRequestURI("/api/nodes/1");
request.setQueryString("include[nodes]=children.nodeComments");
request.setContentType(HttpHeaders.JSONAPI_CONTENT_TYPE);
Map<String, String> params = new HashMap<>();
params.put("include[nodes]", "children.nodeComments.langLocale");
request.setParameters(params);
request.addHeader("Accept", "*/*");
MockHttpServletResponse response = new MockHttpServletResponse();
servlet.service(request, response);
String responseContent = response.getContentAsString();
assertTopLevelNodesCorrectWithChildren(responseContent);
}
示例15: verifyProperMatchCorrectMethodWithParam
import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void verifyProperMatchCorrectMethodWithParam() throws Exception {
final MockHttpServletRequest request = new MockHttpServletRequest();
request.setContextPath(LOGIN_URL_PATH);
request.setMethod("POST");
request.setParameter("openid.mode", "check_authentication");
assertNotNull(this.handlerMapping.lookupHandler(LOGIN_URL_PATH, request));
}