Package org.springframework.mock.web.test

Examples of org.springframework.mock.web.test.MockHttpServletResponse


    returnTypeString = new MethodParameter(method, -1);

    mavContainer = new ModelAndViewContainer();

    servletRequest = new MockHttpServletRequest();
    servletResponse = new MockHttpServletResponse();
    webRequest = new ServletWebRequest(servletRequest, servletResponse);

    this.binderFactory = new ValidatingBinderFactory();
  }
View Full Code Here


    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addPreferredLocale(Locale.US);
    request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
    request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver());
    HttpServletResponse response = new MockHttpServletResponse();

    Map model = new HashMap();
    model.put("myattr", "myvalue");
    fv.render(model, request, response);

    assertEquals(AbstractView.DEFAULT_CONTENT_TYPE, response.getContentType());
  }
View Full Code Here

    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addPreferredLocale(Locale.US);
    request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
    request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver());
    HttpServletResponse response = new MockHttpServletResponse();
    response.setContentType("myContentType");

    Map model = new HashMap();
    model.put("myattr", "myvalue");
    fv.render(model, request, response);

    assertEquals("myContentType", response.getContentType());
  }
View Full Code Here

    context.register(WebConfig.class);
    context.refresh();

    this.request = new MockHttpServletRequest("GET", "/");
    this.request.setContextPath("/myapp");
    this.response = new MockHttpServletResponse();

    Object urlProvider = context.getBean(ResourceUrlProvider.class);
    this.request.setAttribute(ResourceUrlProviderExposingInterceptor.RESOURCE_URL_PROVIDER_ATTR, urlProvider);
  }
View Full Code Here

  public void setUp() throws Exception {
    this.returnValueHandlers = new HandlerMethodReturnValueHandlerComposite();
    this.argumentResolvers = new HandlerMethodArgumentResolverComposite();
    this.mavContainer = new ModelAndViewContainer();
    this.request = new MockHttpServletRequest();
    this.response = new MockHttpServletResponse();
    this.webRequest = new ServletWebRequest(this.request, this.response);
  }
View Full Code Here

  @Before
  public void setUp() throws Exception {
    resolver = new ServletResponseMethodArgumentResolver();
    method = getClass().getMethod("supportedParams", ServletResponse.class, OutputStream.class, Writer.class);
    servletResponse = new MockHttpServletResponse();
    mavContainer = new ModelAndViewContainer();
    webRequest = new ServletWebRequest(new MockHttpServletRequest(), servletResponse);
  }
View Full Code Here

  private MockHttpServletResponse response;

  @Before
  public void setUp() throws Exception {
    this.request = new MockHttpServletRequest();
    this.response = new MockHttpServletResponse();
  }
View Full Code Here

  @Test
  public void simple() throws Exception {
    initServlet(SimpleUriTemplateController.class);

    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/42");
    MockHttpServletResponse response = new MockHttpServletResponse();
    servlet.service(request, response);
    assertEquals("test-42", response.getContentAsString());
  }
View Full Code Here

  @Test
  public void multiple() throws Exception {
    initServlet(MultipleUriTemplateController.class);

    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/hotels/42/bookings/21-other");
    MockHttpServletResponse response = new MockHttpServletResponse();
    servlet.service(request, response);
    assertEquals("test-42-21-other", response.getContentAsString());
  }
View Full Code Here

  @Test
  public void binding() throws Exception {
    initServlet(BindingUriTemplateController.class);

    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/hotels/42/dates/2008-11-18");
    MockHttpServletResponse response = new MockHttpServletResponse();
    servlet.service(request, response);
    assertEquals(200, response.getStatus());

    request = new MockHttpServletRequest("GET", "/hotels/42/dates/2008-foo-bar");
    response = new MockHttpServletResponse();
    servlet.service(request, response);
    assertEquals(400, response.getStatus());

    initServlet(NonBindingUriTemplateController.class);
    request = new MockHttpServletRequest("GET", "/hotels/42/dates/2008-foo-bar");
    response = new MockHttpServletResponse();
    servlet.service(request, response);
    assertEquals(500, response.getStatus());
  }
View Full Code Here

TOP

Related Classes of org.springframework.mock.web.test.MockHttpServletResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.