Search in sources :

Example 86 with MockHttpServletResponse

use of org.springframework.mock.web.test.MockHttpServletResponse in project spring-framework by spring-projects.

the class KotlinScriptTemplateTests method renderViewWithModel.

private MockHttpServletResponse renderViewWithModel(String viewUrl, Map<String, Object> model, Locale locale, Class<?> configuration) throws Exception {
    ScriptTemplateView view = createViewWithUrl(viewUrl, configuration);
    view.setLocale(locale);
    MockHttpServletResponse response = new MockHttpServletResponse();
    MockHttpServletRequest request = new MockHttpServletRequest();
    view.renderMergedOutputModel(model, request, response);
    return response;
}
Also used : MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse)

Example 87 with MockHttpServletResponse

use of org.springframework.mock.web.test.MockHttpServletResponse in project spring-framework by spring-projects.

the class ObjectToStringHttpMessageConverterTests method setUp.

@Before
public void setUp() {
    ConversionService conversionService = new DefaultConversionService();
    this.converter = new ObjectToStringHttpMessageConverter(conversionService);
    this.servletResponse = new MockHttpServletResponse();
    this.response = new ServletServerHttpResponse(this.servletResponse);
}
Also used : ConversionService(org.springframework.core.convert.ConversionService) DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) ServletServerHttpResponse(org.springframework.http.server.ServletServerHttpResponse) DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse) Before(org.junit.Before)

Example 88 with MockHttpServletResponse

use of org.springframework.mock.web.test.MockHttpServletResponse in project spring-framework by spring-projects.

the class ModelFactoryOrderingTests method setup.

@Before
public void setup() {
    this.sessionAttributeStore = new DefaultSessionAttributeStore();
    this.webRequest = new ServletWebRequest(new MockHttpServletRequest(), new MockHttpServletResponse());
    this.mavContainer = new ModelAndViewContainer();
    this.mavContainer.addAttribute("methods", new ArrayList<String>());
}
Also used : ModelAndViewContainer(org.springframework.web.method.support.ModelAndViewContainer) MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) DefaultSessionAttributeStore(org.springframework.web.bind.support.DefaultSessionAttributeStore) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse) Before(org.junit.Before)

Example 89 with MockHttpServletResponse

use of org.springframework.mock.web.test.MockHttpServletResponse in project spring-framework by spring-projects.

the class RequestHeaderMethodArgumentResolverTests method setUp.

@Before
@SuppressWarnings("resource")
public void setUp() throws Exception {
    GenericWebApplicationContext context = new GenericWebApplicationContext();
    context.refresh();
    resolver = new RequestHeaderMethodArgumentResolver(context.getBeanFactory());
    Method method = ReflectionUtils.findMethod(getClass(), "params", (Class<?>[]) null);
    paramNamedDefaultValueStringHeader = new SynthesizingMethodParameter(method, 0);
    paramNamedValueStringArray = new SynthesizingMethodParameter(method, 1);
    paramSystemProperty = new SynthesizingMethodParameter(method, 2);
    paramContextPath = new SynthesizingMethodParameter(method, 3);
    paramResolvedNameWithExpression = new SynthesizingMethodParameter(method, 4);
    paramResolvedNameWithPlaceholder = new SynthesizingMethodParameter(method, 5);
    paramNamedValueMap = new SynthesizingMethodParameter(method, 6);
    paramDate = new SynthesizingMethodParameter(method, 7);
    paramInstant = new SynthesizingMethodParameter(method, 8);
    servletRequest = new MockHttpServletRequest();
    webRequest = new ServletWebRequest(servletRequest, new MockHttpServletResponse());
    // Expose request to the current thread (for SpEL expressions)
    RequestContextHolder.setRequestAttributes(webRequest);
}
Also used : SynthesizingMethodParameter(org.springframework.core.annotation.SynthesizingMethodParameter) MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) Method(java.lang.reflect.Method) GenericWebApplicationContext(org.springframework.web.context.support.GenericWebApplicationContext) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse) Before(org.junit.Before)

Example 90 with MockHttpServletResponse

use of org.springframework.mock.web.test.MockHttpServletResponse in project spring-framework by spring-projects.

the class RequestParamMapMethodArgumentResolverTests method setUp.

@Before
public void setUp() throws Exception {
    resolver = new RequestParamMapMethodArgumentResolver();
    request = new MockHttpServletRequest();
    webRequest = new ServletWebRequest(request, new MockHttpServletResponse());
}
Also used : MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse) Before(org.junit.Before)

Aggregations

MockHttpServletResponse (org.springframework.mock.web.test.MockHttpServletResponse)171 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)162 Test (org.junit.Test)140 GenericWebApplicationContext (org.springframework.web.context.support.GenericWebApplicationContext)33 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)28 Before (org.junit.Before)19 MockServletContext (org.springframework.mock.web.test.MockServletContext)14 HttpServletResponse (javax.servlet.http.HttpServletResponse)13 ModelAndView (org.springframework.web.servlet.ModelAndView)13 HttpServletRequest (javax.servlet.http.HttpServletRequest)10 StaticWebApplicationContext (org.springframework.web.context.support.StaticWebApplicationContext)10 TestBean (org.springframework.tests.sample.beans.TestBean)9 HashMap (java.util.HashMap)8 FilterChain (javax.servlet.FilterChain)8 ServletException (javax.servlet.ServletException)7 HttpSession (javax.servlet.http.HttpSession)7 IOException (java.io.IOException)6 Map (java.util.Map)6 ServletRequest (javax.servlet.ServletRequest)6 ServletResponse (javax.servlet.ServletResponse)6