congrats Icon
New! Announcing our next generation AI code completions
Read here
Tabnine Logo
MockHttpServletRequestBuilder.header
Code IndexAdd Tabnine to your IDE (free)

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

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

origin: spring-projects/spring-framework

@Test
public void header() {
  this.builder.header("foo", "bar", "baz");
  MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
  List<String> headers = Collections.list(request.getHeaders("foo"));
  assertEquals(2, headers.size());
  assertEquals("bar", headers.get(0));
  assertEquals("baz", headers.get(1));
}
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  // SPR-11308
public void contentTypeViaHeader() {
  this.builder.header("Content-Type", MediaType.TEXT_HTML_VALUE);
  MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
  String contentType = request.getContentType();
  assertEquals("text/html", contentType);
}
origin: spring-projects/spring-framework

@Test
public void stringWithMatcherAndCorrectResponseHeaderValue() throws Exception {
  this.mockMvc.perform(get("/persons/1").header(IF_MODIFIED_SINCE, minuteAgo))
      .andExpect(header().string(LAST_MODIFIED, equalTo(now)));
}
origin: spring-projects/spring-framework

private void assertIncorrectResponseHeader(ResultMatcher matcher, String expected) throws Exception {
  try {
    this.mockMvc.perform(get("/persons/1")
        .header(IF_MODIFIED_SINCE, minuteAgo))
        .andExpect(matcher);
    fail(ERROR_MESSAGE);
  }
  catch (AssertionError err) {
    if (ERROR_MESSAGE.equals(err.getMessage())) {
      throw err;
    }
    // SPR-10659: ensure header name is in the message
    // Unfortunately, we can't control formatting from JUnit or Hamcrest.
    assertMessageContains(err, "Response header '" + LAST_MODIFIED + "'");
    assertMessageContains(err, expected);
    assertMessageContains(err, this.now);
  }
}
origin: spring-projects/spring-framework

@Test
public void longValueWithMissingResponseHeader() throws Exception {
  try {
    this.mockMvc.perform(get("/persons/1").header(IF_MODIFIED_SINCE, now))
        .andExpect(status().isNotModified())
        .andExpect(header().longValue("X-Custom-Header", 99L));
    fail(ERROR_MESSAGE);
  }
  catch (AssertionError err) {
    if (ERROR_MESSAGE.equals(err.getMessage())) {
      throw err;
    }
    assertEquals("Response does not contain header 'X-Custom-Header'", err.getMessage());
  }
}
origin: spring-projects/spring-framework

@Test
public void stringWithCorrectResponseHeaderValue() throws Exception {
  this.mockMvc.perform(get("/persons/1").header(IF_MODIFIED_SINCE, minuteAgo))
      .andExpect(header().string(LAST_MODIFIED, now));
}
origin: spring-projects/spring-framework

@Test
public void dateValueWithCorrectResponseHeaderValue() throws Exception {
  this.mockMvc.perform(get("/persons/1").header(IF_MODIFIED_SINCE, minuteAgo))
      .andExpect(header().dateValue(LAST_MODIFIED, this.currentTime));
}
origin: spring-projects/spring-framework

@Test
public void stringWithMatcherAndMissingResponseHeader() throws Exception {
  this.mockMvc.perform(get("/persons/1").header(IF_MODIFIED_SINCE, now))
      .andExpect(status().isNotModified())
      .andExpect(header().string("X-Custom-Header", nullValue()));
}
origin: spring-projects/spring-framework

@Test
public void mergeHeader() throws Exception {
  String headerName = "PARENT";
  String headerValue = "VALUE";
  MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new HelloController())
        .defaultRequest(get("/").header(headerName, headerValue))
        .build();
  assertThat(mockMvc.perform(requestBuilder).andReturn().getRequest().getHeader(headerName), equalTo(headerValue));
}
origin: spring-projects/spring-framework

@Test
public void stringWithMissingResponseHeader() throws Exception {
  this.mockMvc.perform(get("/persons/1").header(IF_MODIFIED_SINCE, now))
      .andExpect(status().isNotModified())
      .andExpect(header().stringValues("X-Custom-Header"));
}
origin: spring-projects/spring-security

@Test
public void getWhenAcceptHeaderIsApplicationXhtmlXmlThenRespondsWith302() throws Exception {
  this.spring.register(HttpBasicAndFormLoginEntryPointsConfig.class).autowire();
  this.mvc.perform(get("/")
      .header(HttpHeaders.ACCEPT, MediaType.APPLICATION_XHTML_XML))
      .andExpect(status().isFound());
}
origin: spring-projects/spring-security

@Test
public void getWhenAcceptHeaderIsImageJpgThenRespondsWith302() throws Exception {
  this.spring.register(HttpBasicAndFormLoginEntryPointsConfig.class).autowire();
  this.mvc.perform(get("/")
      .header(HttpHeaders.ACCEPT, MediaType.IMAGE_JPEG))
      .andExpect(status().isFound());
}
origin: spring-projects/spring-security

@Test
public void getWhenAcceptIsChromeThenRespondsWith302() throws Exception {
  this.spring.register(DefaultSecurityConfig.class).autowire();
  this.mvc.perform(get("/")
      .header(HttpHeaders.ACCEPT,
          "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"))
      .andExpect(status().isFound());
}
origin: spring-projects/spring-security

@Test
public void getWhenDeclaringHttpBasicBeforeFormLoginThenRespondsWith401() throws Exception {
  this.spring.register(BasicAuthenticationEntryPointBeforeFormLoginConfig.class).autowire();
  this.mvc.perform(get("/")
      .header(HttpHeaders.ACCEPT, "bogus/type"))
      .andExpect(status().isUnauthorized());
}
origin: spring-projects/spring-security

@Test
public void getWhenAcceptHeaderIsImagePngThenRespondsWith302() throws Exception {
  this.spring.register(HttpBasicAndFormLoginEntryPointsConfig.class).autowire();
  this.mvc.perform(get("/")
      .header(HttpHeaders.ACCEPT, MediaType.IMAGE_PNG))
      .andExpect(status().isFound());
}
origin: spring-projects/spring-security

@Test
public void getWhenAcceptHeaderIsApplicationAtomXmlThenRespondsWith401() throws Exception {
  this.spring.register(HttpBasicAndFormLoginEntryPointsConfig.class).autowire();
  this.mvc.perform(get("/")
      .header(HttpHeaders.ACCEPT, MediaType.APPLICATION_ATOM_XML))
      .andExpect(status().isUnauthorized());
}
origin: spring-projects/spring-security

@Test
public void getWhenAcceptHeaderIsApplicationFormUrlEncodedThenRespondsWith401() throws Exception {
  this.spring.register(HttpBasicAndFormLoginEntryPointsConfig.class).autowire();
  this.mvc.perform(get("/")
      .header(HttpHeaders.ACCEPT, MediaType.APPLICATION_FORM_URLENCODED))
      .andExpect(status().isUnauthorized());
}
origin: spring-projects/spring-security

@Test
public void requestTokenWhenUsingPasswordGrantTypeThenOk()
    throws Exception {
  this.mvc.perform(post("/oauth/token")
    .param("grant_type", "password")
    .param("username", "subject")
    .param("password", "password")
    .header("Authorization", "Basic cmVhZGVyOnNlY3JldA=="))
      .andExpect(status().isOk());
}
origin: spring-projects/spring-security

@Test
public void getWhenBookmarkedRequestIsRequestedWithAndroidThenPostAuthenticationRemembers() throws Exception {
  this.spring.register(RequestCacheDefaultsConfig.class, DefaultSecurityConfig.class).autowire();
  MockHttpSession session = (MockHttpSession)
      this.mvc.perform(get("/messages")
          .header("X-Requested-With", "com.android"))
          .andExpect(redirectedUrl("http://localhost/login"))
          .andReturn().getRequest().getSession();
  this.mvc.perform(formLogin(session))
      .andExpect(redirectedUrl("http://localhost/messages"));
}
org.springframework.test.web.servlet.requestMockHttpServletRequestBuilderheader

Javadoc

Add a header to the request. Values are always added.

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).
  • with
    An extension point for further initialization of MockHttpServletRequestin ways not built directly in
  • requestAttr
    Set a request attribute.
  • buildRequest
    Build a MockHttpServletRequest.
  • 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

  • Parsing JSON documents to java classes using gson
  • getResourceAsStream (ClassLoader)
  • requestLocationUpdates (LocationManager)
  • getSupportFragmentManager (FragmentActivity)
  • VirtualMachine (com.sun.tools.attach)
    A Java virtual machine. A VirtualMachine represents a Java virtual machine to which this Java vir
  • BorderLayout (java.awt)
    A border layout lays out a container, arranging and resizing its components to fit in five regions:
  • Proxy (java.net)
    This class represents proxy server settings. A created instance of Proxy stores a type and an addres
  • Socket (java.net)
    Provides a client-side TCP socket.
  • Charset (java.nio.charset)
    A charset is a named mapping between Unicode characters and byte sequences. Every Charset can decode
  • TreeSet (java.util)
    TreeSet is an implementation of SortedSet. All optional operations (adding and removing) are support
  • PhpStorm for WordPress
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

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