Codota Logo
MockHttpServletRequestBuilder.buildRequest
Code IndexAdd Codota to your IDE (free)

How to use
buildRequest
method
in
org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder

Best Java code snippets using org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder.buildRequest (Showing top 20 results out of 315)

  • Common ways to obtain MockHttpServletRequestBuilder
private void myMethod () {
MockHttpServletRequestBuilder m =
  • Codota IconMockMvcRequestBuilders.get("<changeme>")
  • Codota IconString httpMethod;URI url;new MockHttpServletRequestBuilder(httpMethod, url)
  • Smart code suggestions by Codota
}
origin: spring-projects/spring-framework

@Test
public void sessionAttributes() {
  Map<String, Object> map = new HashMap<>();
  map.put("foo", "bar");
  this.builder.sessionAttrs(map);
  MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
  assertEquals("bar", request.getSession().getAttribute("foo"));
}
origin: spring-projects/spring-framework

@Test  // SPR-13801
public void requestParameterFromMultiValueMap() throws Exception {
  MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
  params.add("foo", "bar");
  params.add("foo", "baz");
  this.builder = new MockHttpServletRequestBuilder(HttpMethod.POST, "/foo");
  this.builder.params(params);
  MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
  assertArrayEquals(new String[] {"bar", "baz"}, request.getParameterMap().get("foo"));
}
origin: spring-projects/spring-framework

@Test  // SPR-13435
public void requestUriWithDoubleSlashes() throws URISyntaxException {
  this.builder = new MockHttpServletRequestBuilder(HttpMethod.GET, new URI("/test//currentlyValid/0"));
  MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
  assertEquals("/test//currentlyValid/0", request.getRequestURI());
}
origin: spring-projects/spring-framework

@Test
public void locale() {
  Locale locale = new Locale("nl", "nl");
  this.builder.locale(locale);
  MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
  assertEquals(locale, request.getLocale());
}
origin: spring-projects/spring-framework

@Test
public void method() {
  MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
  assertEquals("GET", request.getMethod());
}
origin: spring-projects/spring-framework

@Test
public void acceptHeader() {
  this.builder.accept(MediaType.TEXT_HTML, MediaType.APPLICATION_XML);
  MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
  List<String> accept = Collections.list(request.getHeaders("Accept"));
  List<MediaType> result = MediaType.parseMediaTypes(accept.get(0));
  assertEquals(1, accept.size());
  assertEquals("text/html", result.get(0).toString());
  assertEquals("application/xml", result.get(1).toString());
}
origin: spring-projects/spring-framework

@Test
public void contentType() {
  this.builder.contentType(MediaType.TEXT_HTML);
  MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
  String contentType = request.getContentType();
  List<String> contentTypes = Collections.list(request.getHeaders("Content-Type"));
  assertEquals("text/html", contentType);
  assertEquals(1, contentTypes.size());
  assertEquals("text/html", contentTypes.get(0));
}
origin: spring-projects/spring-framework

@Test
public void contentTypeViaString() {
  this.builder.contentType("text/html");
  MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
  String contentType = request.getContentType();
  List<String> contentTypes = Collections.list(request.getHeaders("Content-Type"));
  assertEquals("text/html", contentType);
  assertEquals(1, contentTypes.size());
  assertEquals("text/html", contentTypes.get(0));
}
origin: spring-projects/spring-framework

@Test
public void body() throws IOException {
  byte[] body = "Hello World".getBytes("UTF-8");
  this.builder.content(body);
  MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
  byte[] result = FileCopyUtils.copyToByteArray(request.getInputStream());
  assertArrayEquals(body, result);
}
origin: spring-projects/spring-framework

@Test  // SPR-11308
public void contentTypeViaMultipleHeaderValues() {
  this.builder.header("Content-Type", MediaType.TEXT_HTML_VALUE, MediaType.ALL_VALUE);
  MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
  assertEquals("text/html", request.getContentType());
}
origin: spring-projects/spring-framework

@Test
public void characterEncoding() {
  String encoding = "UTF-8";
  this.builder.characterEncoding(encoding);
  MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
  assertEquals(encoding, request.getCharacterEncoding());
}
origin: spring-projects/spring-framework

@Test  // SPR-11043
public void requestParameterFromQueryNull() {
  this.builder = new MockHttpServletRequestBuilder(HttpMethod.GET, "/?foo");
  MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
  Map<String, String[]> parameterMap = request.getParameterMap();
  assertArrayEquals(new String[] {null}, parameterMap.get("foo"));
  assertEquals("foo", request.getQueryString());
}
origin: spring-projects/spring-framework

@Test  // SPR-13719
public void arbitraryMethod() {
  String httpMethod = "REPort";
  URI url = UriComponentsBuilder.fromPath("/foo/{bar}").buildAndExpand(42).toUri();
  this.builder = new MockHttpServletRequestBuilder(httpMethod, url);
  MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
  assertEquals(httpMethod, request.getMethod());
  assertEquals("/foo/42", request.getPathInfo());
}
origin: spring-projects/spring-framework

@Test
public void requestParameterFromQueryWithEncoding() {
  this.builder = new MockHttpServletRequestBuilder(HttpMethod.GET, "/?foo={value}", "bar=baz");
  MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
  assertEquals("foo=bar%3Dbaz", request.getQueryString());
  assertEquals("bar=baz", request.getParameter("foo"));
}
origin: spring-projects/spring-framework

@Test
public void flashAttribute() {
  this.builder.flashAttr("foo", "bar");
  MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
  FlashMap flashMap = new SessionFlashMapManager().retrieveAndUpdate(request, null);
  assertNotNull(flashMap);
  assertEquals("bar", flashMap.get("foo"));
}
origin: spring-projects/spring-framework

@Test
public void contextPathEmpty() {
  this.builder = new MockHttpServletRequestBuilder(HttpMethod.GET, "/foo");
  MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
  assertEquals("", request.getContextPath());
  assertEquals("", request.getServletPath());
  assertEquals("/foo", request.getPathInfo());
}
origin: spring-projects/spring-framework

@Test
public void requestParameterFromQueryList() {
  this.builder = new MockHttpServletRequestBuilder(HttpMethod.GET, "/?foo[0]=bar&foo[1]=baz");
  MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
  assertEquals("foo%5B0%5D=bar&foo%5B1%5D=baz", request.getQueryString());
  assertEquals("bar", request.getParameter("foo[0]"));
  assertEquals("baz", request.getParameter("foo[1]"));
}
origin: spring-projects/spring-framework

@Test
public void contextPathServletPathEmpty() {
  this.builder = new MockHttpServletRequestBuilder(HttpMethod.GET, "/travel/hotels/42");
  this.builder.contextPath("/travel");
  MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
  assertEquals("/travel", request.getContextPath());
  assertEquals("", request.getServletPath());
  assertEquals("/hotels/42", request.getPathInfo());
}
origin: spring-projects/spring-framework

@Test
public void contextPathServletPath() {
  this.builder = new MockHttpServletRequestBuilder(HttpMethod.GET, "/travel/main/hotels/42");
  this.builder.contextPath("/travel");
  this.builder.servletPath("/main");
  MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
  assertEquals("/travel", request.getContextPath());
  assertEquals("/main", request.getServletPath());
  assertEquals("/hotels/42", request.getPathInfo());
}
origin: spring-projects/spring-framework

@Test
public void contextPathServletPathInfoEmpty() {
  this.builder = new MockHttpServletRequestBuilder(HttpMethod.GET, "/travel/hotels/42");
  this.builder.contextPath("/travel");
  this.builder.servletPath("/hotels/42");
  MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
  assertEquals("/travel", request.getContextPath());
  assertEquals("/hotels/42", request.getServletPath());
  assertNull(request.getPathInfo());
}
org.springframework.test.web.servlet.requestMockHttpServletRequestBuilderbuildRequest

Javadoc

Build a MockHttpServletRequest.

Popular methods of MockHttpServletRequestBuilder

  • contentType
    Set the 'Content-Type' header of the request.
  • content
    Set the request body.
  • param
    Add a request parameter to the MockHttpServletRequest.If called more than once, new values get added
  • accept
    Set the 'Accept' header to the given media type(s).
  • header
    Add a header to the request. Values are always added.
  • with
    An extension point for further initialization of MockHttpServletRequestin ways not built directly in
  • requestAttr
    Set a request attribute.
  • contextPath
    Specify the portion of the requestURI that represents the context path. The context path, if specifi
  • principal
    Set the principal of the request.
  • flashAttr
    Set an "input" flash attribute.
  • headers
    Add all headers to the request. Values are always added.
  • session
    Set the HTTP session to use, possibly re-used across requests.Individual attributes provided via #se
  • headers,
  • session,
  • sessionAttr,
  • cookie,
  • params,
  • servletPath,
  • <init>,
  • characterEncoding,
  • locale

Popular in Java

  • Finding current android device location
  • getResourceAsStream (ClassLoader)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • startActivity (Activity)
  • HttpServer (com.sun.net.httpserver)
    This class implements a simple HTTP server. A HttpServer is bound to an IP address and port number a
  • Graphics2D (java.awt)
    This Graphics2D class extends the Graphics class to provide more sophisticated control overgraphics
  • SecureRandom (java.security)
    This class generates cryptographically secure pseudo-random numbers. It is best to invoke SecureRand
  • HashMap (java.util)
    HashMap is an implementation of Map. All optional operations are supported.All elements are permitte
  • IsNull (org.hamcrest.core)
    Is the value null?
  • Runner (org.openjdk.jmh.runner)
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now