当前位置: 首页>>代码示例>>Java>>正文


Java MockHttpServletRequest.setContextPath方法代码示例

本文整理汇总了Java中org.springframework.mock.web.MockHttpServletRequest.setContextPath方法的典型用法代码示例。如果您正苦于以下问题:Java MockHttpServletRequest.setContextPath方法的具体用法?Java MockHttpServletRequest.setContextPath怎么用?Java MockHttpServletRequest.setContextPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.mock.web.MockHttpServletRequest的用法示例。


在下文中一共展示了MockHttpServletRequest.setContextPath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testRejectPlainJson

import org.springframework.mock.web.MockHttpServletRequest; //导入方法依赖的package包/类
/** Option to reject plain JSON GET requests is enabled explicitly. */
@Test
public void testRejectPlainJson() 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/json");
	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()));
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:23,代码来源:CrnkServletRejectJsonTest.java

示例2: verifyResettingContexPath

import org.springframework.mock.web.MockHttpServletRequest; //导入方法依赖的package包/类
@Test
public void verifyResettingContexPath() throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setContextPath(CONST_CONTEXT_PATH);
    final MockRequestContext context = new MockRequestContext();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));

    this.action.doExecute(context);

    assertEquals(CONST_CONTEXT_PATH + "/", this.warnCookieGenerator.getCookiePath());
    assertEquals(CONST_CONTEXT_PATH + "/", this.tgtCookieGenerator.getCookiePath());

    request.setContextPath(CONST_CONTEXT_PATH_2);
    this.action.doExecute(context);

    assertNotSame(CONST_CONTEXT_PATH_2 + "/", this.warnCookieGenerator.getCookiePath());
    assertNotSame(CONST_CONTEXT_PATH_2 + "/", this.tgtCookieGenerator.getCookiePath());
    assertEquals(CONST_CONTEXT_PATH + "/", this.warnCookieGenerator.getCookiePath());
    assertEquals(CONST_CONTEXT_PATH + "/", this.tgtCookieGenerator.getCookiePath());
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:21,代码来源:InitialFlowSetupActionTests.java

示例3: testAcceptWildcard

import org.springframework.mock.web.MockHttpServletRequest; //导入方法依赖的package包/类
@Test
public void testAcceptWildcard() 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", "*/*");

	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");
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:26,代码来源:CrnkServletRejectJsonTest.java

示例4: 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()));
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:22,代码来源:CrnkServletTest.java

示例5: verifyNoMatch

import org.springframework.mock.web.MockHttpServletRequest; //导入方法依赖的package包/类
@Test
public void verifyNoMatch() throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setContextPath("/hello");

    assertNull(this.handlerMapping.lookupHandler("/hello", request));
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:8,代码来源:OpenIdPostUrlHandlerMappingTests.java

示例6: 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));
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:9,代码来源:OpenIdPostUrlHandlerMappingTests.java

示例7: verifyImproperMatch

import org.springframework.mock.web.MockHttpServletRequest; //导入方法依赖的package包/类
@Test
public void verifyImproperMatch() throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setContextPath("/hello");

    assertNull(this.handlerMapping.lookupHandler("/login", request));
}
 
开发者ID:yuweijun,项目名称:cas-server-4.2.1,代码行数:8,代码来源:OpenIdPostUrlHandlerMappingTests.java

示例8: 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

示例9: verifySettingContextPath

import org.springframework.mock.web.MockHttpServletRequest; //导入方法依赖的package包/类
@Test
public void verifySettingContextPath() throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setContextPath(CONST_CONTEXT_PATH);
    final MockRequestContext context = new MockRequestContext();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));

    this.action.doExecute(context);

    assertEquals(CONST_CONTEXT_PATH + '/', this.warnCookieGenerator.getCookiePath());
    assertEquals(CONST_CONTEXT_PATH + '/', this.tgtCookieGenerator.getCookiePath());
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:13,代码来源:InitialFlowSetupActionTests.java

示例10: onSimpleResourceGetShouldReturnOneResource

import org.springframework.mock.web.MockHttpServletRequest; //导入方法依赖的package包/类
@Test
public void onSimpleResourceGetShouldReturnOneResource() throws Exception {
	MockFilterChain filterChain = new MockFilterChain();

	MockHttpServletRequest request = new MockHttpServletRequest(servletContext);
	request.setMethod("GET");
	request.setContextPath("");
	request.setServletPath(null);
	request.setPathInfo(null);
	request.setRequestURI("/api/tasks/1");
	request.setContentType(HttpHeaders.JSONAPI_CONTENT_TYPE);
	request.addHeader("Accept", "*/*");

	MockHttpServletResponse response = new MockHttpServletResponse();

	filter.doFilter(request, response, filterChain);

	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");
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:29,代码来源:CrnkFilterTest.java

示例11: verifyImproperMatch

import org.springframework.mock.web.MockHttpServletRequest; //导入方法依赖的package包/类
@Test
public void verifyImproperMatch() throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setContextPath("/hello");

    assertNull(this.handlerMapping.lookupHandler(LOGIN_URL_PATH, request));
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:8,代码来源: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_URL_PATH);
    request.setMethod("GET");

    assertNull(this.handlerMapping.lookupHandler(LOGIN_URL_PATH, request));
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:9,代码来源:OpenIdPostUrlHandlerMappingTests.java

示例13: 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));
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:11,代码来源:OpenIdPostUrlHandlerMappingTests.java

示例14: testSettingContextPath

import org.springframework.mock.web.MockHttpServletRequest; //导入方法依赖的package包/类
@Test
public void testSettingContextPath() throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final String CONST_CONTEXT_PATH = "/test";
    request.setContextPath(CONST_CONTEXT_PATH);
    final MockRequestContext context = new MockRequestContext();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));

    this.action.doExecute(context);

    assertEquals(CONST_CONTEXT_PATH + "/", this.warnCookieGenerator.getCookiePath());
    assertEquals(CONST_CONTEXT_PATH + "/", this.tgtCookieGenerator.getCookiePath());
}
 
开发者ID:luotuo,项目名称:cas4.0.x-server-wechat,代码行数:14,代码来源:InitialFlowSetupActionTests.java

示例15: onCollectionRequestWithParamsGetShouldReturnCollection

import org.springframework.mock.web.MockHttpServletRequest; //导入方法依赖的package包/类
@Test
public void onCollectionRequestWithParamsGetShouldReturnCollection() throws Exception {
	MockFilterChain filterChain = new MockFilterChain();

	MockHttpServletRequest request = new MockHttpServletRequest(servletContext);
	request.setMethod("GET");
	request.setContextPath("");
	request.setServletPath(null);
	request.setPathInfo(null);
	request.setRequestURI("/api/tasks");
	request.setContentType(HttpHeaders.JSONAPI_CONTENT_TYPE);
	request.addHeader("Accept", "*/*");
	request.addParameter("filter[name]", "John");
	request.setQueryString(URLEncoder.encode("filter[name]", StandardCharsets.UTF_8.name()) + "=John");

	MockHttpServletResponse response = new MockHttpServletResponse();

	filter.doFilter(request, response, filterChain);

	String responseContent = response.getContentAsString();

	log.debug("responseContent: {}", responseContent);
	assertNotNull(responseContent);

	assertJsonPartEquals("tasks", responseContent, "data[0].type");
	assertJsonPartEquals("\"1\"", responseContent, "data[0].id");
	assertJsonPartEquals(FIRST_TASK_ATTRIBUTES, responseContent, "data[0].attributes");
	assertJsonPartEquals(FIRST_TASK_LINKS, responseContent, "data[0].links");
	assertJsonPartEquals(PROJECT1_RELATIONSHIP_LINKS, responseContent, "data[0].relationships.project.links");
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:31,代码来源:CrnkFilterTest.java


注:本文中的org.springframework.mock.web.MockHttpServletRequest.setContextPath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。