use of cn.taketoday.web.mock.MockHttpServletResponse in project today-infrastructure by TAKETODAY.
the class ContentNegotiatingViewResolverTests method createViewResolver.
@BeforeEach
public void createViewResolver() {
wac.setServletContext(new MockServletContext());
wac.refresh();
viewResolver = new ContentNegotiatingViewResolver();
viewResolver.setApplicationContext(wac);
request = new MockHttpServletRequest("GET", "/test");
MockHttpServletResponse response = new MockHttpServletResponse();
this.requestContext = new MockServletRequestContext(wac, request, response);
RequestContextHolder.set(requestContext);
}
use of cn.taketoday.web.mock.MockHttpServletResponse in project today-infrastructure by TAKETODAY.
the class NashornScriptTemplateTests method renderTemplateWithUrl.
// SPR-13453
@Test
public void renderTemplateWithUrl() throws Exception {
String url = "cn/taketoday/web/servlet/view/script/nashorn/template.html";
MockHttpServletResponse response = render(url, null, ScriptTemplatingWithUrlConfiguration.class);
assertThat(response.getContentAsString()).isEqualTo(("<html><head><title>Check url parameter</title></head><body><p>" + url + "</p></body></html>"));
}
use of cn.taketoday.web.mock.MockHttpServletResponse in project today-infrastructure by TAKETODAY.
the class ScriptTemplateViewTests method resourceLoaderPath.
// SPR-14210
@Test
public void resourceLoaderPath() throws Exception {
MockServletContext servletContext = new MockServletContext();
this.wac.setServletContext(servletContext);
this.wac.refresh();
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
Map<String, Object> model = new HashMap<>();
InvocableScriptEngine engine = mock(InvocableScriptEngine.class);
given(engine.invokeFunction(any(), any(), any(), any())).willReturn("foo");
this.view.setEngine(engine);
this.view.setRenderFunction("render");
this.view.setApplicationContext(this.wac);
this.view.setUrl("cn/taketoday/web/servlet/view/script/empty.txt");
this.view.render(model, new ServletRequestContext(wac, request, response));
assertThat(response.getContentAsString()).isEqualTo("foo");
response = new MockHttpServletResponse();
this.view.setResourceLoaderPath("classpath:cn/taketoday/web/servlet/view/script/");
this.view.setUrl("empty.txt");
this.view.render(model, new ServletRequestContext(wac, request, response));
assertThat(response.getContentAsString()).isEqualTo("foo");
response = new MockHttpServletResponse();
this.view.setResourceLoaderPath("classpath:cn/taketoday/web/servlet/view/script");
this.view.setUrl("empty.txt");
this.view.render(model, new ServletRequestContext(wac, request, response));
assertThat(response.getContentAsString()).isEqualTo("foo");
}
use of cn.taketoday.web.mock.MockHttpServletResponse in project today-infrastructure by TAKETODAY.
the class RedirectViewTests method contextRelativeWithValidatedContextPath.
// SPR-16752
@Test
public void contextRelativeWithValidatedContextPath() throws Exception {
String url = "/myUrl";
this.request.setContextPath("//context");
this.response = new MockHttpServletResponse();
this.context = null;
doTest(new HashMap<>(), url, true, "/context" + url);
this.request.setContextPath("///context");
this.response = new MockHttpServletResponse();
this.context = null;
doTest(new HashMap<>(), url, true, "/context" + url);
}
use of cn.taketoday.web.mock.MockHttpServletResponse in project today-infrastructure by TAKETODAY.
the class WebUtilsTests method checkSameOrigin.
private boolean checkSameOrigin(String scheme, String serverName, int port, String originHeader) {
MockHttpServletRequest servletRequest = new MockHttpServletRequest();
servletRequest.setScheme(scheme);
servletRequest.setServerName(serverName);
if (port != -1) {
servletRequest.setServerPort(port);
}
servletRequest.addHeader(HttpHeaders.ORIGIN, originHeader);
ServletRequestContext context = new ServletRequestContext(null, servletRequest, new MockHttpServletResponse());
return WebUtils.isSameOrigin(context);
}
Aggregations