Tabnine Logo
MockHttpServletRequestBuilder.buildRequest
Code IndexAdd Tabnine 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)

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

  • Reactive rest calls using spring rest template
  • runOnUiThread (Activity)
  • putExtra (Intent)
  • startActivity (Activity)
  • Window (java.awt)
    A Window object is a top-level window with no borders and no menubar. The default layout for a windo
  • System (java.lang)
    Provides access to system-related information and resources including standard input and output. Ena
  • Timestamp (java.sql)
    A Java representation of the SQL TIMESTAMP type. It provides the capability of representing the SQL
  • Semaphore (java.util.concurrent)
    A counting semaphore. Conceptually, a semaphore maintains a set of permits. Each #acquire blocks if
  • BasicDataSource (org.apache.commons.dbcp)
    Basic implementation of javax.sql.DataSource that is configured via JavaBeans properties. This is no
  • Location (org.springframework.beans.factory.parsing)
    Class that models an arbitrary location in a Resource.Typically used to track the location of proble
  • From CI to AI: The AI layer in your organization
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now