Search in sources :

Example 6 with NameValuePair

use of com.gargoylesoftware.htmlunit.util.NameValuePair in project spring-framework by spring-projects.

the class HtmlUnitRequestBuilderTests method buildRequestParameterMapViaWebRequestDotSetRequestParametersWithSingleRequestParamWithValueSetToSpace.

@Test
public void buildRequestParameterMapViaWebRequestDotSetRequestParametersWithSingleRequestParamWithValueSetToSpace() {
    webRequest.setRequestParameters(asList(new NameValuePair("name", " ")));
    MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
    assertThat(actualRequest.getParameterMap().size(), equalTo(1));
    assertThat(actualRequest.getParameter("name"), equalTo(" "));
}
Also used : NameValuePair(com.gargoylesoftware.htmlunit.util.NameValuePair) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.Test)

Example 7 with NameValuePair

use of com.gargoylesoftware.htmlunit.util.NameValuePair in project blueocean-plugin by jenkinsci.

the class GitSampleRepoRule method notifyCommit.

public void notifyCommit(JenkinsRule r) throws Exception {
    synchronousPolling(r);
    WebResponse webResponse = r.createWebClient().goTo("git/notifyCommit?url=" + bareUrl(), "text/plain").getWebResponse();
    System.out.println(webResponse.getContentAsString());
    for (NameValuePair pair : webResponse.getResponseHeaders()) {
        if (pair.getName().equals("Triggered")) {
            System.out.println("Triggered: " + pair.getValue());
        }
    }
    r.waitUntilNoActivity();
}
Also used : NameValuePair(com.gargoylesoftware.htmlunit.util.NameValuePair) WebResponse(com.gargoylesoftware.htmlunit.WebResponse)

Example 8 with NameValuePair

use of com.gargoylesoftware.htmlunit.util.NameValuePair in project spring-framework by spring-projects.

the class HtmlUnitRequestBuilder method params.

private void params(MockHttpServletRequest request, UriComponents uriComponents) {
    for (Entry<String, List<String>> entry : uriComponents.getQueryParams().entrySet()) {
        String name = entry.getKey();
        String urlDecodedName = urlDecode(name);
        for (String value : entry.getValue()) {
            value = (value != null ? urlDecode(value) : "");
            request.addParameter(urlDecodedName, value);
        }
    }
    for (NameValuePair param : this.webRequest.getRequestParameters()) {
        request.addParameter(param.getName(), param.getValue());
    }
}
Also used : NameValuePair(com.gargoylesoftware.htmlunit.util.NameValuePair) ArrayList(java.util.ArrayList) List(java.util.List)

Example 9 with NameValuePair

use of com.gargoylesoftware.htmlunit.util.NameValuePair in project spring-framework by spring-projects.

the class MockWebResponseBuilder method responseHeaders.

private List<NameValuePair> responseHeaders() {
    Collection<String> headerNames = this.response.getHeaderNames();
    List<NameValuePair> responseHeaders = new ArrayList<>(headerNames.size());
    for (String headerName : headerNames) {
        List<Object> headerValues = this.response.getHeaderValues(headerName);
        for (Object value : headerValues) {
            responseHeaders.add(new NameValuePair(headerName, String.valueOf(value)));
        }
    }
    String location = this.response.getRedirectedUrl();
    if (location != null) {
        responseHeaders.add(new NameValuePair("Location", location));
    }
    for (Cookie cookie : this.response.getCookies()) {
        responseHeaders.add(new NameValuePair("Set-Cookie", valueOfCookie(cookie)));
    }
    return responseHeaders;
}
Also used : BasicClientCookie(org.apache.http.impl.cookie.BasicClientCookie) Cookie(javax.servlet.http.Cookie) NameValuePair(com.gargoylesoftware.htmlunit.util.NameValuePair) ArrayList(java.util.ArrayList)

Example 10 with NameValuePair

use of com.gargoylesoftware.htmlunit.util.NameValuePair in project spring-framework by spring-projects.

the class HtmlUnitRequestBuilderTests method buildRequestParameterMapViaWebRequestDotSetRequestParametersWithMultipleRequestParams.

@Test
public void buildRequestParameterMapViaWebRequestDotSetRequestParametersWithMultipleRequestParams() {
    webRequest.setRequestParameters(asList(new NameValuePair("name1", "value1"), new NameValuePair("name2", "value2")));
    MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
    assertThat(actualRequest.getParameterMap().size(), equalTo(2));
    assertThat(actualRequest.getParameter("name1"), equalTo("value1"));
    assertThat(actualRequest.getParameter("name2"), equalTo("value2"));
}
Also used : NameValuePair(com.gargoylesoftware.htmlunit.util.NameValuePair) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.Test)

Aggregations

NameValuePair (com.gargoylesoftware.htmlunit.util.NameValuePair)12 Test (org.junit.Test)7 WebResponse (com.gargoylesoftware.htmlunit.WebResponse)5 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)5 Cookie (javax.servlet.http.Cookie)3 ArrayList (java.util.ArrayList)2 List (java.util.List)1 BasicClientCookie (org.apache.http.impl.cookie.BasicClientCookie)1