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

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

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

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
void getPerson99() throws Exception {
  this.mockMvc.perform(get("/person/99").accept(MediaType.APPLICATION_JSON))
    .andExpect(jsonPath("$.name", is("Wally")));
}
origin: spring-projects/spring-framework

@Test
void getPerson42() throws Exception {
  this.mockMvc.perform(get("/person/42").accept(MediaType.APPLICATION_JSON))
    .andExpect(jsonPath("$.name", is("Dilbert")));
}
origin: spring-projects/spring-framework

@Test
public void testContentStringMatcher() throws Exception {
  this.mockMvc.perform(get("/handle").accept(MediaType.TEXT_PLAIN))
    .andExpect(content().string(containsString("world")));
}
origin: spring-projects/spring-framework

@Test
public void callableInterceptor() throws Exception {
  MvcResult mvcResult = this.mockMvc.perform(get("/callable").accept(MediaType.APPLICATION_JSON))
      .andExpect(status().isOk())
      .andExpect(request().asyncStarted())
      .andExpect(request().asyncResult(Collections.singletonMap("key", "value")))
      .andReturn();
  Mockito.verify(this.callableInterceptor).beforeConcurrentHandling(any(), any());
  Mockito.verify(this.callableInterceptor).preProcess(any(), any());
  Mockito.verify(this.callableInterceptor).postProcess(any(), any(), any());
  Mockito.verifyNoMoreInteractions(this.callableInterceptor);
  this.mockMvc.perform(asyncDispatch(mvcResult))
      .andExpect(status().isOk())
      .andExpect(content().string("{\"key\":\"value\"}"));
  Mockito.verify(this.callableInterceptor).afterCompletion(any(), any());
  Mockito.verifyNoMoreInteractions(this.callableInterceptor);
}
origin: spring-projects/spring-framework

@Test
public void testContentAsBytes() throws Exception {
  this.mockMvc.perform(get("/handle").accept(MediaType.TEXT_PLAIN))
    .andExpect(content().bytes("Hello world!".getBytes("ISO-8859-1")));
  this.mockMvc.perform(get("/handleUtf8"))
    .andExpect(content().bytes("\u3053\u3093\u306b\u3061\u306f\u4e16\u754c\uff01".getBytes("UTF-8")));
}
origin: spring-projects/spring-framework

@Test
void springMvcTest(WebApplicationContext wac) throws Exception {
  webAppContextSetup(wac).build()
    .perform(get("/person/42").accept(MediaType.APPLICATION_JSON))
    .andExpect(status().isOk())
    .andExpect(jsonPath("$.name", is("Dilbert")));
}
origin: spring-projects/spring-framework

@Test
public void testContentAsString() throws Exception {
  this.mockMvc.perform(get("/handle").accept(MediaType.TEXT_PLAIN))
    .andExpect(content().string("Hello world!"));
  this.mockMvc.perform(get("/handleUtf8"))
    .andExpect(content().string("\u3053\u3093\u306b\u3061\u306f\u4e16\u754c\uff01"));
  // Hamcrest matchers...
  this.mockMvc.perform(get("/handle").accept(MediaType.TEXT_PLAIN)).andExpect(content().string(equalTo("Hello world!")));
  this.mockMvc.perform(get("/handleUtf8")).andExpect(content().string(equalTo("\u3053\u3093\u306b\u3061\u306f\u4e16\u754c\uff01")));
}
origin: spring-projects/spring-framework

@Test
public void testCharacterEncoding() throws Exception {
  this.mockMvc.perform(get("/handle").accept(MediaType.TEXT_PLAIN))
    .andExpect(content().encoding("ISO-8859-1"))
    .andExpect(content().string(containsString("world")));
  this.mockMvc.perform(get("/handleUtf8"))
    .andExpect(content().encoding("UTF-8"))
    .andExpect(content().bytes("\u3053\u3093\u306b\u3061\u306f\u4e16\u754c\uff01".getBytes("UTF-8")));
}
origin: spring-projects/spring-framework

@Test
public void person() throws Exception {
  this.mockMvc.perform(get("/person/5").accept(MediaType.APPLICATION_JSON))
    .andDo(print())
    .andExpect(status().isOk())
    .andExpect(content().string("{\"name\":\"Joe\",\"someDouble\":0.0,\"someBoolean\":false}"));
}
origin: spring-projects/spring-framework

@Test
public void person() throws Exception {
  this.mockMvc.perform(get("/person/5").accept(MediaType.APPLICATION_JSON))
    .andDo(print())
    .andExpect(status().isOk())
    .andExpect(content().string("{\"name\":\"Joe\",\"someDouble\":0.0,\"someBoolean\":false}"));
}
origin: spring-projects/spring-framework

@Before
public void setup() {
  this.mockMvc = standaloneSetup(new MusicController())
      .defaultRequest(get("/").accept(MediaType.APPLICATION_JSON))
      .alwaysExpect(status().isOk())
      .alwaysExpect(content().contentType("application/json;charset=UTF-8"))
      .build();
}
origin: spring-projects/spring-framework

@Before
public void setup() {
  this.mockMvc = standaloneSetup(new MusicController())
      .defaultRequest(get("/").accept(MediaType.APPLICATION_XML, MediaType.parseMediaType("application/xml;charset=UTF-8")))
      .alwaysExpect(status().isOk())
      .alwaysExpect(content().contentType(MediaType.parseMediaType("application/xml;charset=UTF-8")))
      .build();
}
origin: spring-projects/spring-framework

@Before
public void setup() throws Exception {
  this.mockMvc = standaloneSetup(new MusicController())
      .defaultRequest(get("/").accept(MediaType.APPLICATION_XML, MediaType.parseMediaType("application/xml;charset=UTF-8")))
      .alwaysExpect(status().isOk())
      .alwaysExpect(content().contentType(MediaType.parseMediaType("application/xml;charset=UTF-8")))
      .build();
}
origin: spring-projects/spring-framework

@Test
public void queryParameter() throws Exception {
  standaloneSetup(new PersonController()).build()
    .perform(get("/search?name=George").accept(MediaType.APPLICATION_JSON))
      .andExpect(status().isOk())
      .andExpect(content().contentType("application/json;charset=UTF-8"))
      .andExpect(jsonPath("$.name").value("George"));
}
origin: spring-projects/spring-framework

@Test
public void json() throws Exception {
  standaloneSetup(new PersonController()).build()
      .perform(get("/person/Lee").accept(MediaType.APPLICATION_JSON))
      .andExpect(status().isOk())
      .andExpect(content().contentType("application/json;charset=UTF-8"))
      .andExpect(jsonPath("$.name").value("Lee"));
}
origin: spring-projects/spring-framework

  @Test
  public void testFeedWithLinefeedChars() throws Exception {

//        Map<String, String> namespace = Collections.singletonMap("ns", "");

    standaloneSetup(new BlogFeedController()).build()
      .perform(get("/blog.atom").accept(MediaType.APPLICATION_ATOM_XML))
        .andExpect(status().isOk())
        .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_ATOM_XML))
        .andExpect(xpath("//feed/title").string("Test Feed"))
        .andExpect(xpath("//feed/icon").string("http://www.example.com/favicon.ico"));
  }

origin: spring-projects/spring-framework

  .andExpect(forwardedUrl("person/show"));
mockMvc.perform(get("/person/Corea").accept(MediaType.APPLICATION_JSON))
  .andExpect(status().isOk())
  .andExpect(content().contentType(MediaType.APPLICATION_JSON))
  .andExpect(jsonPath("$.person.name").value("Corea"));
mockMvc.perform(get("/person/Corea").accept(MediaType.APPLICATION_XML))
  .andExpect(status().isOk())
  .andExpect(content().contentType(MediaType.APPLICATION_XML))
origin: spring-projects/spring-framework

@Test
public void testContentType() throws Exception {
  this.mockMvc.perform(get("/handle").accept(MediaType.TEXT_PLAIN))
    .andExpect(content().contentType(MediaType.valueOf("text/plain;charset=ISO-8859-1")))
    .andExpect(content().contentType("text/plain;charset=ISO-8859-1"))
    .andExpect(content().contentTypeCompatibleWith("text/plain"))
    .andExpect(content().contentTypeCompatibleWith(MediaType.TEXT_PLAIN));
  this.mockMvc.perform(get("/handleUtf8"))
    .andExpect(content().contentType(MediaType.valueOf("text/plain;charset=UTF-8")))
    .andExpect(content().contentType("text/plain;charset=UTF-8"))
    .andExpect(content().contentTypeCompatibleWith("text/plain"))
    .andExpect(content().contentTypeCompatibleWith(MediaType.TEXT_PLAIN));
}
origin: spring-projects/spring-framework

@Test // SPR-16067, SPR-16695
public void filterWrapsRequestResponseAndPerformsAsyncDispatch() throws Exception {
  MockMvc mockMvc = standaloneSetup(new PersonController())
      .addFilters(new WrappingRequestResponseFilter(), new ShallowEtagHeaderFilter())
      .build();
  MvcResult mvcResult = mockMvc.perform(get("/persons/1").accept(MediaType.APPLICATION_JSON))
      .andExpect(request().asyncStarted())
      .andExpect(request().asyncResult(new Person("Lukas")))
      .andReturn();
  mockMvc.perform(asyncDispatch(mvcResult))
      .andExpect(status().isOk())
      .andExpect(header().longValue("Content-Length", 53))
      .andExpect(header().string("ETag", "\"0e37becb4f0c90709cb2e1efcc61eaa00\""))
      .andExpect(content().string("{\"name\":\"Lukas\",\"someDouble\":0.0,\"someBoolean\":false}"));
}
org.springframework.test.web.servlet.requestMockHttpServletRequestBuilderaccept

Javadoc

Set the 'Accept' header to the given media type(s).

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
  • 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.
  • 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

  • Finding current android device location
  • getApplicationContext (Context)
  • setRequestProperty (URLConnection)
  • startActivity (Activity)
  • Container (java.awt)
    A generic Abstract Window Toolkit(AWT) container object is a component that can contain other AWT co
  • PrintWriter (java.io)
    Wraps either an existing OutputStream or an existing Writerand provides convenience methods for prin
  • Deque (java.util)
    A linear collection that supports element insertion and removal at both ends. The name deque is shor
  • Properties (java.util)
    A Properties object is a Hashtable where the keys and values must be Strings. Each property can have
  • JLabel (javax.swing)
  • Reflections (org.reflections)
    Reflections one-stop-shop objectReflections scans your classpath, indexes the metadata, allows you t
  • Sublime Text for Python
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