Codota Logo
MockHttpServletRequestBuilder.requestAttr
Code IndexAdd Codota to your IDE (free)

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

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

  • Common ways to obtain MockHttpServletRequestBuilder
private void myMethod () {
MockHttpServletRequestBuilder m =
  • Codota IconMockMvcRequestBuilders.get("<changeme>")
  • Codota IconString httpMethod;URI url;new MockHttpServletRequestBuilder(httpMethod, url)
  • Smart code suggestions by Codota
}
origin: rest-assured/rest-assured

  @Override
  protected void applyParam(String paramName, String[] paramValues) {
    request.requestAttr(paramName, paramValues[0]);
  }
}.applyParams();
origin: spring-projects/spring-framework

@Test
public void singletonController() throws Exception {
  this.mockMvc.perform(get("/singletonController").requestAttr(FROM_MVC_TEST_MOCK, FROM_MVC_TEST_MOCK));
}
origin: spring-projects/spring-framework

@Test
public void singletonController() throws Exception {
  this.mockMvc.perform(get("/singletonController").requestAttr(FROM_MVC_TEST_MOCK, FROM_MVC_TEST_MOCK));
}
origin: spring-projects/spring-security

@Test
public void loadConfigWhenDefaultConfigThenWebAsyncManagerIntegrationFilterAdded() throws Exception {
  this.spring.register(WebAsyncPopulatedByDefaultConfig.class).autowire();
  WebAsyncManager webAsyncManager = mock(WebAsyncManager.class);
  this.mockMvc.perform(get("/").requestAttr(WebAsyncUtils.WEB_ASYNC_MANAGER_ATTRIBUTE, webAsyncManager));
  ArgumentCaptor<CallableProcessingInterceptor> callableProcessingInterceptorArgCaptor =
    ArgumentCaptor.forClass(CallableProcessingInterceptor.class);
  verify(webAsyncManager, atLeastOnce()).registerCallableInterceptor(any(), callableProcessingInterceptorArgCaptor.capture());
  CallableProcessingInterceptor callableProcessingInterceptor =
    callableProcessingInterceptorArgCaptor.getAllValues().stream()
      .filter(e -> SecurityContextCallableProcessingInterceptor.class.isAssignableFrom(e.getClass()))
      .findFirst()
      .orElse(null);
  assertThat(callableProcessingInterceptor).isNotNull();
}
origin: spring-projects/spring-framework

@Test
public void requestAttribute() {
  this.builder.requestAttr("foo", "bar");
  MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
  assertEquals("bar", request.getAttribute("foo"));
}
origin: spring-projects/spring-framework

@Test
public void requestScopedController() throws Exception {
  assertTrue("request-scoped controller must be a CGLIB proxy", AopUtils.isCglibProxy(this.requestScopedController));
  this.mockMvc.perform(get("/requestScopedController").requestAttr(FROM_MVC_TEST_MOCK, FROM_MVC_TEST_MOCK));
}
origin: spring-projects/spring-framework

@Test
public void requestScopedService() throws Exception {
  assertTrue("request-scoped service must be a CGLIB proxy", AopUtils.isCglibProxy(this.requestScopedService));
  this.mockMvc.perform(get("/requestScopedService").requestAttr(FROM_MVC_TEST_MOCK, FROM_MVC_TEST_MOCK));
}
origin: spring-projects/spring-framework

@Test
public void sessionScopedService() throws Exception {
  assertTrue("session-scoped service must be a CGLIB proxy", AopUtils.isCglibProxy(this.sessionScopedService));
  this.mockMvc.perform(get("/sessionScopedService").requestAttr(FROM_MVC_TEST_MOCK, FROM_MVC_TEST_MOCK));
}
origin: spring-projects/spring-security

@Test
public void csrfToken() throws Exception {
  CsrfToken csrfToken = new DefaultCsrfToken("headerName", "paramName", "token");
  MockHttpServletRequestBuilder request = get("/csrf").requestAttr(
      CsrfToken.class.getName(), csrfToken);
  mockMvc.perform(request).andExpect(assertResult(csrfToken));
}
origin: spring-projects/spring-security

@Test
public void requestWhenConnectMessageThenUsesCsrfTokenHandshakeInterceptor() throws Exception {
  this.spring.configLocations(xml("SyncConfig")).autowire();
  WebApplicationContext context = (WebApplicationContext) this.spring.getContext();
  MockMvc mvc = MockMvcBuilders.webAppContextSetup(context).build();
  String csrfAttributeName = CsrfToken.class.getName();
  String customAttributeName = this.getClass().getName();
  MvcResult result = mvc.perform(get("/app")
              .requestAttr(csrfAttributeName, this.token)
              .sessionAttr(customAttributeName, "attributeValue"))
            .andReturn();
  CsrfToken handshakeToken = (CsrfToken) this.testHandshakeHandler.attributes.get(csrfAttributeName);
  String handshakeValue = (String) this.testHandshakeHandler.attributes.get(customAttributeName);
  String sessionValue = (String) result.getRequest().getSession().getAttribute(customAttributeName);
  assertThat(handshakeToken).isEqualTo(this.token)
      .withFailMessage("CsrfToken is populated");
  assertThat(handshakeValue).isEqualTo(sessionValue)
      .withFailMessage("Explicitly listed session variables are not overridden");
}
origin: spring-projects/spring-security

@Test
public void requestWhenConnectMessageAndUsingSockJsThenUsesCsrfTokenHandshakeInterceptor() throws Exception {
  this.spring.configLocations(xml("SyncSockJsConfig")).autowire();
  WebApplicationContext context = (WebApplicationContext) this.spring.getContext();
  MockMvc mvc = MockMvcBuilders.webAppContextSetup(context).build();
  String csrfAttributeName = CsrfToken.class.getName();
  String customAttributeName = this.getClass().getName();
  MvcResult result = mvc.perform(get("/app/289/tpyx6mde/websocket")
              .requestAttr(csrfAttributeName, this.token)
              .sessionAttr(customAttributeName, "attributeValue"))
            .andReturn();
  CsrfToken handshakeToken = (CsrfToken) this.testHandshakeHandler.attributes.get(csrfAttributeName);
  String handshakeValue = (String) this.testHandshakeHandler.attributes.get(customAttributeName);
  String sessionValue = (String) result.getRequest().getSession().getAttribute(customAttributeName);
  assertThat(handshakeToken).isEqualTo(this.token)
      .withFailMessage("CsrfToken is populated");
  assertThat(handshakeValue).isEqualTo(sessionValue)
      .withFailMessage("Explicitly listed session variables are not overridden");
}
origin: spring-projects/spring-framework

@Test
public void mergeRequestAttribute() throws Exception {
  String attrName = "PARENT";
  String attrValue = "VALUE";
  MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new HelloController())
      .defaultRequest(get("/").requestAttr(attrName, attrValue))
      .build();
  assertThat(mockMvc.perform(requestBuilder).andReturn().getRequest().getAttribute(attrName), equalTo(attrValue));
}
origin: rest-assured/rest-assured

request.requestAttr(ATTRIBUTE_NAME_URL_TEMPLATE, PathSupport.getPath(uri));
origin: spring-io/initializr

if (status.value() >= 400) {
  requestBuilder = request(HttpMethod.GET, "/error")
      .requestAttr(RequestDispatcher.ERROR_STATUS_CODE,
          status.value())
      .requestAttr(RequestDispatcher.ERROR_REQUEST_URI,
          uri.toString());
  if (servletResponse.getErrorMessage() != null) {
    requestBuilder.requestAttr(RequestDispatcher.ERROR_MESSAGE,
        servletResponse.getErrorMessage());
origin: spring-projects/spring-framework

@Before
public void setup() {
  this.mockRequest.setAttribute(FROM_TCF_MOCK, FROM_TCF_MOCK);
  this.mockMvc = webAppContextSetup(this.wac)
      .addFilters(new RequestFilter(), new RequestAttributesFilter(), this.filterWithSessionScopedService)
      .defaultRequest(get("/").requestAttr(FROM_MVC_TEST_DEFAULT, FROM_MVC_TEST_DEFAULT))
      .alwaysExpect(status().isOk())
      .build();
}
origin: spring-projects/spring-restdocs

/**
 * Create a {@link MockHttpServletRequestBuilder} for a DELETE request. The url
 * template will be captured and made available for documentation.
 * @param urlTemplate a URL template; the resulting URL will be encoded
 * @param urlVariables zero or more URL variables
 * @return the builder for the DELETE request
 */
public static MockHttpServletRequestBuilder delete(String urlTemplate,
    Object... urlVariables) {
  return MockMvcRequestBuilders.delete(urlTemplate, urlVariables).requestAttr(
      RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE, urlTemplate);
}
origin: spring-projects/spring-restdocs

/**
 * Create a {@link MockHttpServletRequestBuilder} for a PUT request. The url template
 * will be captured and made available for documentation.
 * @param urlTemplate a URL template; the resulting URL will be encoded
 * @param urlVariables zero or more URL variables
 * @return the builder for the PUT request
 */
public static MockHttpServletRequestBuilder put(String urlTemplate,
    Object... urlVariables) {
  return MockMvcRequestBuilders.put(urlTemplate, urlVariables).requestAttr(
      RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE, urlTemplate);
}
origin: spring-projects/spring-restdocs

/**
 * Create a {@link MockHttpServletRequestBuilder} for an OPTIONS request. The url
 * template will be captured and made available for documentation.
 * @param urlTemplate a URL template; the resulting URL will be encoded
 * @param urlVariables zero or more URL variables
 * @return the builder for the OPTIONS request
 */
public static MockHttpServletRequestBuilder options(String urlTemplate,
    Object... urlVariables) {
  return MockMvcRequestBuilders.options(urlTemplate, urlVariables).requestAttr(
      RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE, urlTemplate);
}
origin: spring-projects/spring-restdocs

/**
 * Create a {@link MockHttpServletRequestBuilder} for a POST request. The url template
 * will be captured and made available for documentation.
 * @param urlTemplate a URL template; the resulting URL will be encoded
 * @param urlVariables zero or more URL variables
 * @return the builder for the POST request
 */
public static MockHttpServletRequestBuilder post(String urlTemplate,
    Object... urlVariables) {
  return MockMvcRequestBuilders.post(urlTemplate, urlVariables).requestAttr(
      RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE, urlTemplate);
}
origin: spring-projects/spring-framework

@Before
public void setUp() {
  ServletContext servletContext = new MockServletContext();
  MockHttpServletRequest mockRequest = new MockHttpServletRequest(servletContext);
  mockRequest.setAttribute(FROM_CUSTOM_MOCK, FROM_CUSTOM_MOCK);
  RequestContextHolder.setRequestAttributes(new ServletWebRequest(mockRequest, new MockHttpServletResponse()));
  this.wac.setServletContext(servletContext);
  new AnnotatedBeanDefinitionReader(this.wac).register(WebConfig.class);
  this.wac.refresh();
  this.mockMvc = webAppContextSetup(this.wac)
      .defaultRequest(get("/").requestAttr(FROM_MVC_TEST_DEFAULT, FROM_MVC_TEST_DEFAULT))
      .alwaysExpect(status().isOk())
      .build();
}
org.springframework.test.web.servlet.requestMockHttpServletRequestBuilderrequestAttr

Javadoc

Set a request attribute.

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
  • 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
  • getSystemService (Context)
  • compareTo (BigDecimal)
  • getContentResolver (Context)
  • BufferedReader (java.io)
    Reads text from a character-input stream, buffering characters so as to provide for the efficient re
  • ServerSocket (java.net)
    This class represents a server-side socket that waits for incoming client connections. A ServerSocke
  • ByteBuffer (java.nio)
    A buffer for bytes. A byte buffer can be created in either one of the following ways: * #allocate(i
  • Format (java.text)
    The base class for all formats. This is an abstract base class which specifies the protocol for clas
  • HashMap (java.util)
    HashMap is an implementation of Map. All optional operations are supported.All elements are permitte
  • SAXParseException (org.xml.sax)
    Encapsulate an XML parse error or warning.This exception may include information for locating the er
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now