當前位置: 首頁>>代碼示例>>Java>>正文


Java MockHttpServletRequest.setQueryString方法代碼示例

本文整理匯總了Java中org.springframework.mock.web.MockHttpServletRequest.setQueryString方法的典型用法代碼示例。如果您正苦於以下問題:Java MockHttpServletRequest.setQueryString方法的具體用法?Java MockHttpServletRequest.setQueryString怎麽用?Java MockHttpServletRequest.setQueryString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.mock.web.MockHttpServletRequest的用法示例。


在下文中一共展示了MockHttpServletRequest.setQueryString方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: 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

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

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

示例5: verifyNoSuchFlowExecutionExeptionWithQueryString

import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void verifyNoSuchFlowExecutionExeptionWithQueryString() {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRequestURI("test");
    request.setQueryString("test=test");
    ModelAndView model = this.resolver.resolveException(request,
            new MockHttpServletResponse(), null,
            new NoSuchFlowExecutionException(new FlowExecutionKey(){

                private static final long serialVersionUID = -4750073902540974152L;

                @Override
                public String toString() {
                    return "test";
                }

                @Override
                public boolean equals(final Object o) {
                    return true;
                }

                @Override
                public int hashCode() {
                    return 0;
                }
            }, new RuntimeException()));

    assertEquals(request.getRequestURI() + "?" + request.getQueryString(), ((RedirectView) model.getView())
            .getUrl());
}
 
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:31,代碼來源:FlowExecutionExceptionResolverTests.java

示例6: extAuthnHandlerBuildsSessionOnGet

import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void extAuthnHandlerBuildsSessionOnGet() throws Exception {
    when(mockAuthenticationHandlerService.buildSession(any()))
            .thenReturn(new TupasIdentification("210281-9988", "TESTAA PORTAALIA", "e1s1"));
    ProfileRequestContext profileRequestContext = new ProfileRequestContext();
    profileRequestContext.addSubcontext(new AuthenticationContext());

    MockHttpServletRequest request = new MockHttpServletRequest();
    Map<String,String> queryParams = getValidTupasResponseParams();
    String queryString = queryParams.entrySet().stream()
            .map(pair -> pair.getKey() + "=" + pair.getValue())
            .collect(Collectors.joining("&", "?", ""));
    request.setQueryString(queryString);
    request.setParameter("token", "NOT_NULL_ILLOGICAL_MOCK");
    MockHttpServletResponse response = new MockHttpServletResponse();

    when(ExternalAuthentication.getProfileRequestContext("e1s1", request)).thenReturn(profileRequestContext);

    extAuthnHandler.doGet(request, response);

    AuthenticationContext authenticationContext = profileRequestContext.getSubcontext(AuthenticationContext.class);
    assertNotNull(authenticationContext);
    TupasContext tupasContext = authenticationContext.getSubcontext(TupasContext.class);
    assertNotNull(tupasContext);
    assertEquals("TESTAA PORTAALIA", tupasContext.getCn());
    assertEquals("210281-9988", tupasContext.getHetu());
}
 
開發者ID:vrk-kpa,項目名稱:e-identification-tupas-idp-public,代碼行數:28,代碼來源:ShibbolethExtAuthnHandlerTest.java

示例7: getQueryParamRequest

import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
private MockHttpServletRequest getQueryParamRequest(Map<String,String> queryParams) {
    MockHttpServletRequest request = new MockHttpServletRequest();
    String queryString = queryParams.entrySet().stream()
            .map(pair -> pair.getKey() + "=" + pair.getValue())
            .collect(Collectors.joining("&", "?", ""));
    request.setQueryString(queryString);
    request.setParameter("token", "NOT_NULL_ILLOGICAL_MOCK");
    return request;
}
 
開發者ID:vrk-kpa,項目名稱:e-identification-tupas-idp-public,代碼行數:10,代碼來源:ShibbolethExtAuthnHandlerTest.java

示例8: testNoSuchFlowExecutionExeptionWithQueryString

import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void testNoSuchFlowExecutionExeptionWithQueryString() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRequestURI("test");
    request.setQueryString("test=test");
    ModelAndView model = this.resolver.resolveException(request,
            new MockHttpServletResponse(), null,
            new NoSuchFlowExecutionException(new FlowExecutionKey(){

                private static final long serialVersionUID = -4750073902540974152L;

                @Override
                public String toString() {
                    return "test";
                }

                @Override
                public boolean equals(final Object o) {
                    return true;
                }

                @Override
                public int hashCode() {
                    return 0;
                }
            }, new RuntimeException()));

    assertEquals(request.getRequestURI() + "?" + request.getQueryString(), ((RedirectView) model.getView())
            .getUrl());
}
 
開發者ID:luotuo,項目名稱:cas4.0.x-server-wechat,代碼行數:31,代碼來源:FlowExecutionExceptionResolverTests.java

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

示例10: onCollectionRequestWithParamsGetShouldReturnCollection

import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void onCollectionRequestWithParamsGetShouldReturnCollection() 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", "*/*");
	request.addParameter("filter[name]", "John");
	request.setQueryString(URLEncoder.encode("filter[name]", StandardCharsets.UTF_8.name()) + "=John");

	MockHttpServletResponse response = new MockHttpServletResponse();

	servlet.service(request, response);

	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,代碼行數:29,代碼來源:CrnkServletTest.java

示例11: 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.setQueryString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。