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


Java MockHttpServletRequest.setParameters方法代码示例

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


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

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

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

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


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