Tabnine Logo
MockHttpServletRequestBuilder.contentType
Code IndexAdd Tabnine to your IDE (free)

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

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

origin: spring-projects/spring-framework

/**
 * Package-private constructor. Use static factory methods in
 * {@link MockMvcRequestBuilders}.
 * <p>For other ways to initialize a {@code MockMultipartHttpServletRequest},
 * see {@link #with(RequestPostProcessor)} and the
 * {@link RequestPostProcessor} extension point.
 * @param uri the URL
 * @since 4.0.3
 */
MockMultipartHttpServletRequestBuilder(URI uri) {
  super(HttpMethod.POST, uri);
  super.contentType(MediaType.MULTIPART_FORM_DATA);
}
origin: spring-projects/spring-framework

/**
 * Package-private constructor. Use static factory methods in
 * {@link MockMvcRequestBuilders}.
 * <p>For other ways to initialize a {@code MockMultipartHttpServletRequest},
 * see {@link #with(RequestPostProcessor)} and the
 * {@link RequestPostProcessor} extension point.
 * @param urlTemplate a URL template; the resulting URL will be encoded
 * @param uriVariables zero or more URI variables
 */
MockMultipartHttpServletRequestBuilder(String urlTemplate, Object... uriVariables) {
  super(HttpMethod.POST, urlTemplate, uriVariables);
  super.contentType(MediaType.MULTIPART_FORM_DATA);
}
origin: hs-web/hsweb-framework

protected MockHttpServletRequestBuilder initDefaultSetting(MockHttpServletRequestBuilder builder) {
  return builder.session(session).characterEncoding("UTF-8").contentType(MediaType.APPLICATION_JSON);
}
origin: rest-assured/rest-assured

private void setContentTypeToApplicationFormUrlEncoded(MockHttpServletRequestBuilder request) {
  MediaType mediaType = MediaType.parseMediaType(HeaderHelper.buildApplicationFormEncodedContentType(config, APPLICATION_FORM_URLENCODED_VALUE));
  request.contentType(mediaType);
  List<Header> newHeaders = new ArrayList<Header>(headers.asList());
  newHeaders.add(new Header(CONTENT_TYPE, mediaType.toString()));
  headers = new Headers(newHeaders);
}
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 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 requestParameterFromRequestBodyFormData() throws Exception {
  String contentType = "application/x-www-form-urlencoded;charset=UTF-8";
  String body = "name+1=value+1&name+2=value+A&name+2=value+B&name+3";
  MockHttpServletRequest request = new MockHttpServletRequestBuilder(HttpMethod.POST, "/foo")
      .contentType(contentType).content(body.getBytes(StandardCharsets.UTF_8))
      .buildRequest(this.servletContext);
  assertArrayEquals(new String[] {"value 1"}, request.getParameterMap().get("name 1"));
  assertArrayEquals(new String[] {"value A", "value B"}, request.getParameterMap().get("name 2"));
  assertArrayEquals(new String[] {null}, request.getParameterMap().get("name 3"));
}
origin: requery/requery

@Test
public void findUserById() throws Exception {
  String userJson = objectMapper.writeValueAsString(testUser);
  mockMvc.perform(
      post("/user")
          .contentType(MediaType.APPLICATION_JSON_UTF8)
          .content(userJson));
  mockMvc.perform(get("/user" + 1)
      .contentType(MediaType.APPLICATION_JSON_UTF8)
      .content(userJson));
}
origin: cloudfoundry/uaa

  @Test
  public void changeEmail_withIncorrectCode() throws Exception {
    when(expiringCodeStore.retrieveCode("the_secret_code", IdentityZoneHolder.get().getId()))
      .thenReturn(new ExpiringCode("the_secret_code", new Timestamp(System.currentTimeMillis()), "{\"userId\":\"user-id-001\",\"email\":\"new@example.com\",\"client_id\":null}", "incorrect-code"));

    mockMvc.perform(post("/email_changes")
      .contentType(APPLICATION_JSON)
      .content("the_secret_code")
      .accept(APPLICATION_JSON))
      .andExpect(MockMvcResultMatchers.status().isUnprocessableEntity());
  }
}
origin: spring-projects/spring-framework

@Test // SPR-15753
public void formContentIsNotDuplicated() throws Exception {
  MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new Spr15753Controller())
      .addFilter(new FormContentFilter())
      .build();
  mockMvc.perform(put("/").content("d1=a&d2=s").contentType(MediaType.APPLICATION_FORM_URLENCODED))
      .andExpect(content().string("d1:a, d2:s."));
}
origin: cloudfoundry/uaa

private ClientDetails createClientAdminsClient(String token) throws Exception {
  List<String> scopes = Arrays.asList("oauth.approvals", "clients.admin");
  BaseClientDetails client = createBaseClient(null, SECRET, Arrays.asList("password", "client_credentials"), scopes, scopes);
  MockHttpServletRequestBuilder createClientPost = post("/oauth/clients")
      .header("Authorization", "Bearer " + token)
      .accept(APPLICATION_JSON)
      .contentType(APPLICATION_JSON)
      .content(JsonUtils.writeValueAsString(client));
  mockMvc.perform(createClientPost).andExpect(status().isCreated());
  return getClient(client.getClientId());
}
origin: cloudfoundry/uaa

private ClientDetails createReadWriteClient(String token) throws Exception {
  List<String> scopes = Arrays.asList("oauth.approvals", "clients.read", "clients.write");
  BaseClientDetails client = createBaseClient(null, SECRET, Arrays.asList("password", "client_credentials"), scopes, scopes);
  MockHttpServletRequestBuilder createClientPost = post("/oauth/clients")
      .header("Authorization", "Bearer " + token)
      .accept(APPLICATION_JSON)
      .contentType(APPLICATION_JSON)
      .content(JsonUtils.writeValueAsString(client));
  mockMvc.perform(createClientPost).andExpect(status().isCreated());
  return getClient(client.getClientId());
}
origin: cloudfoundry/uaa

private ClientDetails createAdminClient(String token) throws Exception {
  List<String> scopes = Arrays.asList("uaa.admin", "oauth.approvals", "clients.read", "clients.write");
  BaseClientDetails client = createBaseClient(null, SECRET, Arrays.asList("password", "client_credentials"), scopes, scopes);
  MockHttpServletRequestBuilder createClientPost = post("/oauth/clients")
      .header("Authorization", "Bearer " + token)
      .accept(APPLICATION_JSON)
      .contentType(APPLICATION_JSON)
      .content(JsonUtils.writeValueAsString(client));
  mockMvc.perform(createClientPost).andExpect(status().isCreated());
  return getClient(client.getClientId());
}
origin: cloudfoundry/uaa

private ClientDetails createApprovalsLoginClient(String token) throws Exception {
  List<String> scopes = Arrays.asList("uaa.admin", "oauth.approvals", "oauth.login");
  BaseClientDetails client = createBaseClient(null, SECRET, Arrays.asList("password", "client_credentials"), scopes, scopes);
  MockHttpServletRequestBuilder createClientPost = post("/oauth/clients")
      .header("Authorization", "Bearer " + token)
      .accept(APPLICATION_JSON)
      .contentType(APPLICATION_JSON)
      .content(JsonUtils.writeValueAsString(client));
  mockMvc.perform(createClientPost).andExpect(status().isCreated());
  return getClient(client.getClientId());
}
origin: requery/requery

  private void postUserAndExpectSame(String userJson) throws Exception {
    mockMvc.perform(
        post("/user")
            .contentType(MediaType.APPLICATION_JSON_UTF8)
            .content(userJson)
    ).andExpect(status().isCreated()).andExpect(content().json(userJson));
  }
}
origin: cloudfoundry/uaa

private ResultActions performUpdate(ClientMetadata updatedClientMetadata) throws Exception {
  MockHttpServletRequestBuilder updateClientPut = put("/oauth/clients/" + updatedClientMetadata.getClientId() + "/meta")
      .header("Authorization", "Bearer " + adminClientTokenWithClientsWrite)
      .header("If-Match", "0")
      .accept(APPLICATION_JSON)
      .contentType(APPLICATION_JSON)
      .content(JsonUtils.writeValueAsString(updatedClientMetadata));
  return mockMvc.perform(updateClientPut);
}
origin: cloudfoundry/uaa

  private ResultActions performUpdate(ClientMetadata updatedClientMetadata) throws Exception {
  MockHttpServletRequestBuilder updateClientPut = put("/oauth/clients/" + updatedClientMetadata.getClientId() + "/meta")
   .header("Authorization", "Bearer " + adminClientTokenWithClientsWrite)
   .header("If-Match", "0")
   .accept(APPLICATION_JSON)
   .contentType(APPLICATION_JSON)
   .content(JsonUtils.writeValueAsString(updatedClientMetadata));
  return mockMvc.perform(updateClientPut);
 }
}
origin: cloudfoundry/uaa

@Test
public void testUpdateForbiddenNonAdmin() throws Exception {
  mockMvc.perform(put("/mfa-providers/invalid")
      .header("Authorization", "bearer " + nonAdminToken)
      .contentType(APPLICATION_JSON)
      .content(JsonUtils.writeValueAsString(new MfaProvider<>())))
      .andExpect(status().isForbidden());
}
origin: cloudfoundry/uaa

protected ClientDetails createClient(String token, String id, String clientSecret, Collection<String> grantTypes) throws Exception {
  BaseClientDetails client = createBaseClient(id, clientSecret, grantTypes);
  MockHttpServletRequestBuilder createClientPost = post("/oauth/clients")
    .header("Authorization", "Bearer " + token)
    .accept(APPLICATION_JSON)
    .contentType(APPLICATION_JSON)
    .content(toString(client));
  mockMvc.perform(createClientPost).andExpect(status().isCreated());
  return getClient(client.getClientId());
}
origin: cloudfoundry/uaa

@Test
public void testLimitedScopesWithoutMember() throws Exception {
  IdentityZone zone = MockMvcUtils.createZoneUsingWebRequest(getMockMvc(), identityClientToken);
  ScimGroup group = new ScimGroup("zones." + zone.getId() + ".admin");
  MockHttpServletRequestBuilder post = post("/Groups/zones")
    .accept(APPLICATION_JSON)
    .contentType(APPLICATION_JSON)
    .header("Authorization", "Bearer " + identityClientToken)
    .content(JsonUtils.writeValueAsBytes(group));
  getMockMvc().perform(post)
    .andExpect(status().isBadRequest());
}
org.springframework.test.web.servlet.requestMockHttpServletRequestBuildercontentType

Javadoc

Set the 'Content-Type' header of the request.

Popular methods of MockHttpServletRequestBuilder

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

  • Making http requests using okhttp
  • putExtra (Intent)
  • startActivity (Activity)
  • onRequestPermissionsResult (Fragment)
  • Charset (java.nio.charset)
    A charset is a named mapping between Unicode characters and byte sequences. Every Charset can decode
  • SimpleDateFormat (java.text)
    Formats and parses dates in a locale-sensitive manner. Formatting turns a Date into a String, and pa
  • Arrays (java.util)
    This class contains various methods for manipulating arrays (such as sorting and searching). This cl
  • BlockingQueue (java.util.concurrent)
    A java.util.Queue that additionally supports operations that wait for the queue to become non-empty
  • JarFile (java.util.jar)
    JarFile is used to read jar entries and their associated data from jar files.
  • Table (org.hibernate.mapping)
    A relational table
  • Github Copilot alternatives
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