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

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

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

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: 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
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: spring-projects/spring-framework

private ClientHttpResponse getClientHttpResponse(
    HttpMethod httpMethod, URI uri, HttpHeaders requestHeaders, byte[] requestBody) {
  try {
    MockHttpServletResponse servletResponse = this.mockMvc
        .perform(request(httpMethod, uri).content(requestBody).headers(requestHeaders))
        .andReturn()
        .getResponse();
    HttpStatus status = HttpStatus.valueOf(servletResponse.getStatus());
    byte[] body = servletResponse.getContentAsByteArray();
    MockClientHttpResponse clientResponse = new MockClientHttpResponse(body, status);
    clientResponse.getHeaders().putAll(getResponseHeaders(servletResponse));
    return clientResponse;
  }
  catch (Exception ex) {
    byte[] body = ex.toString().getBytes(StandardCharsets.UTF_8);
    return new MockClientHttpResponse(body, HttpStatus.INTERNAL_SERVER_ERROR);
  }
}
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: spring-projects/spring-framework

@Test
public void testPrint() throws Exception {
  StringWriter writer = new StringWriter();
  standaloneSetup(new SimpleController())
    .build()
    .perform(get("/").content("Hello Request".getBytes()))
    .andDo(log())
    .andDo(print())
    .andDo(print(System.err))
    .andDo(print(writer))
  ;
  System.out.println();
  System.out.println("===============================================================");
  System.out.println(writer.toString());
}
origin: cloudfoundry/uaa

private ResultActions createZoneScope(ScimGroup group) throws Exception {
  MockHttpServletRequestBuilder post = post("/Groups/zones")
    .accept(APPLICATION_JSON)
    .contentType(APPLICATION_JSON)
    .header("Authorization", "Bearer " + identityClientToken)
    .content(JsonUtils.writeValueAsBytes(group));
  return getMockMvc().perform(post);
}
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: cloudfoundry/uaa

private ResultActions updateAccountStatus(ScimUser user, UserAccountStatus alteredAccountStatus) throws Exception {
  String jsonStatus = JsonUtils.writeValueAsString(alteredAccountStatus);
  return mockMvc
      .perform(
          patch("/Users/" + user.getId() + "/status")
              .header("Authorization", "Bearer " + uaaAdminToken)
              .accept(APPLICATION_JSON)
              .contentType(APPLICATION_JSON)
              .content(jsonStatus)
      );
}
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 createScimGroupHelper(ScimGroup scimGroup) throws Exception {
  MockHttpServletRequestBuilder post = post("/Groups")
    .header("Authorization", "Bearer " + scimWriteToken)
    .contentType(APPLICATION_JSON)
    .content(serializeWithoutMeta(scimGroup));
  return mockMvc.perform(post).andExpect(status().isCreated());
}
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 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: 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.requestMockHttpServletRequestBuildercontent

Javadoc

Set the request body as a UTF-8 String.

Popular methods of MockHttpServletRequestBuilder

  • contentType
    Set the 'Content-Type' header of the request.
  • 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

  • Reading from database using SQL prepared statement
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • scheduleAtFixedRate (ScheduledExecutorService)
  • startActivity (Activity)
  • Socket (java.net)
    Provides a client-side TCP socket.
  • TimeZone (java.util)
    TimeZone represents a time zone offset, and also figures out daylight savings. Typically, you get a
  • Vector (java.util)
    Vector is an implementation of List, backed by an array and synchronized. All optional operations in
  • Callable (java.util.concurrent)
    A task that returns a result and may throw an exception. Implementors define a single method with no
  • TimeUnit (java.util.concurrent)
    A TimeUnit represents time durations at a given unit of granularity and provides utility methods to
  • Loader (org.hibernate.loader)
    Abstract superclass of object loading (and querying) strategies. This class implements useful common
  • CodeWhisperer 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