congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
MockHttpServletRequestBuilder.params
Code IndexAdd Tabnine to your IDE (free)

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

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

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-security

@Test
public void getWhenUsingDefaultsWithBearerTokenInTwoParametersThenInvalidRequest()
    throws Exception {
  this.spring.register(JwkSetUriConfig.class).autowire();
  MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
  params.add("access_token", "token1");
  params.add("access_token", "token2");
  this.mvc.perform(get("/")
      .params(params))
      .andExpect(status().isBadRequest())
      .andExpect(invalidRequestHeader("Found multiple bearer tokens in the request"));
}
origin: entando/entando-core

private void unauthorized(String username, String password, String clientId, String secret) throws Exception {
  MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
  params.add("grant_type", "password");
  params.add("username", username);
  params.add("password", password);
  String hash = new String(Base64.encode((clientId + ":" + secret).getBytes()));
  ResultActions result
      = mockMvc.perform(post("/oauth/token")
          .params(params)
          .header("Authorization", "Basic " + hash)
          .accept("application/json;charset=UTF-8"))
      .andExpect(status().isUnauthorized());
  String resultString = result.andReturn().getResponse().getContentAsString();
  Assert.assertTrue(StringUtils.isBlank(resultString));
  if (!StringUtils.isEmpty(username)) {
    Collection<OAuth2AccessToken> oauthTokens = apiOAuth2TokenManager.findTokensByUserName(username);
    Assert.assertEquals(0, oauthTokens.size());
  }
}
origin: com.gitlab.jhonsapp/bootstrap-test

public String obtainAccessToken(MockMvc mockMvc) throws Exception {
  
  MultiValueMap<String, String> params = createParams();
   ResultActions result = mockMvc.perform(post("/oauth/token")
                .params(params)
                .with(httpBasic(userInformation.getClient(), userInformation.getClientPassword()))
                .accept("application/json;charset=UTF-8"))
                .andExpect(status().isOk())
                .andExpect(content().contentType("application/json;charset=UTF-8"));
   String resultString = result.andReturn().getResponse().getContentAsString();
  
  JacksonJsonParser jsonParser = new JacksonJsonParser();
  return jsonParser.parseMap(resultString).get("access_token").toString();
}

origin: entando/entando-core

private void invalidClient(String username, String password, String clientId, String secret, String grantType) throws Exception {
  MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
  params.add("grant_type", grantType);
  params.add("username", username);
  params.add("password", password);
  String hash = new String(Base64.encode((clientId + ":" + secret).getBytes()));
  ResultActions result
      = mockMvc.perform(post("/oauth/token")
          .params(params)
          .header("Authorization", "Basic " + hash)
          .accept("application/json;charset=UTF-8"))
      .andExpect(status().isUnauthorized())
      .andExpect(content().contentType("application/json;charset=UTF-8"));
  String resultString = result.andReturn().getResponse().getContentAsString();
  Assert.assertTrue(StringUtils.isNotBlank(resultString));
  result.andExpect(jsonPath("$.error", is("invalid_client")));
  String expectedMessage = "Unauthorized grant type: " + grantType;
  result.andExpect(jsonPath("$.error_description", is(expectedMessage)));
  Collection<OAuth2AccessToken> oauthTokens = apiOAuth2TokenManager.findTokensByUserName(username);
  Assert.assertEquals(0, oauthTokens.size());
}
origin: entando/entando-core

private void missingGrant(String username, String password, String clientId, String secret, String grantType) throws Exception {
  MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
  params.add("grant_type", grantType);
  params.add("username", username);
  params.add("password", password);
  String hash = new String(Base64.encode((clientId + ":" + secret).getBytes()));
  ResultActions result
      = mockMvc.perform(post("/oauth/token")
          .params(params)
          .header("Authorization", "Basic " + hash)
          .accept("application/json;charset=UTF-8"))
      .andExpect(status().isBadRequest())
      .andExpect(content().contentType("application/json;charset=UTF-8"));
  String resultString = result.andReturn().getResponse().getContentAsString();
  Assert.assertTrue(StringUtils.isNotBlank(resultString));
  result.andExpect(jsonPath("$.error", is("invalid_request")));
  result.andExpect(jsonPath("$.error_description", is("Missing grant type")));
  Collection<OAuth2AccessToken> oauthTokens = apiOAuth2TokenManager.findTokensByUserName(username);
  Assert.assertEquals(0, oauthTokens.size());
}
origin: entando/entando-core

private void authenticationFailed(String username, String password) throws Exception {
  MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
  params.add("grant_type", "password");
  params.add("username", username);
  params.add("password", password);
  String hash = new String(Base64.encode("test1_consumer:secret".getBytes()));
  ResultActions result
      = mockMvc.perform(post("/oauth/token")
          .params(params)
          .header("Authorization", "Basic " + hash)
          .accept("application/json;charset=UTF-8"))
      .andExpect(status().isUnauthorized())
      .andExpect(content().contentType("application/json;charset=UTF-8"));
  String resultString = result.andReturn().getResponse().getContentAsString();
  Assert.assertTrue(StringUtils.isNotBlank(resultString));
  result.andExpect(jsonPath("$.error", is("unauthorized")));
  result.andExpect(jsonPath("$.error_description", anything()));
  if (!StringUtils.isEmpty(username)) {
    Collection<OAuth2AccessToken> oauthTokens = apiOAuth2TokenManager.findTokensByUserName(username);
    Assert.assertEquals(0, oauthTokens.size());
  }
}
origin: entando/entando-core

ResultActions result
    = mockMvc.perform(post("/oauth/token")
        .params(params)
        .header("Authorization", "Basic " + hash)
        .accept("application/json;charset=UTF-8"))
origin: Caratacus/Crown

requestBuilder = MockMvcRequestBuilders.get(url);
if (Objects.nonNull(params)) {
  requestBuilder.params(params);
requestBuilder = MockMvcRequestBuilders.delete(url);
if (Objects.nonNull(params)) {
  requestBuilder.params(params);
origin: entando/entando-core

ResultActions result
    = mockMvc.perform(post("/oauth/token")
        .params(params)
        .header("Authorization", "Basic " + hash)
        .accept("application/json;charset=UTF-8"))
org.springframework.test.web.servlet.requestMockHttpServletRequestBuilderparams

Javadoc

Add a map of request parameters to the MockHttpServletRequest, for example when testing a form submission.

If called more than once, new values get added to existing ones.

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.
  • 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.
  • flashAttr,
  • headers,
  • session,
  • sessionAttr,
  • cookie,
  • servletPath,
  • <init>,
  • characterEncoding,
  • locale

Popular in Java

  • Parsing JSON documents to java classes using gson
  • setScale (BigDecimal)
  • getSystemService (Context)
  • compareTo (BigDecimal)
  • InputStream (java.io)
    A readable source of bytes.Most clients will use input streams that read data from the file system (
  • Path (java.nio.file)
  • Enumeration (java.util)
    A legacy iteration interface.New code should use Iterator instead. Iterator replaces the enumeration
  • List (java.util)
    An ordered collection (also known as a sequence). The user of this interface has precise control ove
  • CountDownLatch (java.util.concurrent)
    A synchronization aid that allows one or more threads to wait until a set of operations being perfor
  • JarFile (java.util.jar)
    JarFile is used to read jar entries and their associated data from jar files.
  • Top plugins for Android Studio
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