use of cn.taketoday.web.context.support.StaticWebApplicationContext in project today-infrastructure by TAKETODAY.
the class ResourceHttpRequestHandlerTests method servletContextRootValidation.
@Test
public void servletContextRootValidation() {
StaticWebApplicationContext context = new StaticWebApplicationContext() {
@Override
public Resource getResource(String location) {
return new FileSystemResource("/");
}
};
ResourceHttpRequestHandler handler = new ResourceHttpRequestHandler();
handler.setLocationValues(Collections.singletonList("/"));
handler.setApplicationContext(context);
assertThatIllegalStateException().isThrownBy(handler::afterPropertiesSet).withMessage("The String-based location \"/\" should be relative to the web application root but " + "resolved to a Resource of type: class cn.taketoday.core.io.FileSystemResource. " + "If this is intentional, please pass it as a pre-configured Resource via setLocations.");
}
use of cn.taketoday.web.context.support.StaticWebApplicationContext in project today-infrastructure by TAKETODAY.
the class ControllerTests method parameterizableViewController.
@Test
public void parameterizableViewController() throws Exception {
String viewName = "viewName";
ParameterizableViewController pvc = new ParameterizableViewController();
pvc.setViewName(viewName);
// We don't care about the params.
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.refresh();
ServletRequestContext context = new ServletRequestContext(wac, new MockHttpServletRequest("GET", "foo.html"), new MockHttpServletResponse());
ModelAndView mv = pvc.handleRequest(context);
assertThat(mv.getModel().size() == 0).as("model has no data").isTrue();
assertThat(mv.getViewName().equals(viewName)).as("model has correct viewname").isTrue();
assertThat(pvc.getViewName().equals(viewName)).as("getViewName matches").isTrue();
}
use of cn.taketoday.web.context.support.StaticWebApplicationContext in project today-infrastructure by TAKETODAY.
the class UrlFilenameViewControllerTests method withContextMapping.
@Test
void withContextMapping() throws Exception {
UrlFilenameViewController controller = new UrlFilenameViewController();
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myapp/docs/cvs/commit.html");
request.setContextPath("/myapp");
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.refresh();
ServletRequestContext context = new ServletRequestContext(wac, request, new MockHttpServletResponse());
ModelAndView mv = controller.handleRequest(context);
assertThat(mv.getViewName()).isEqualTo("docs/cvs/commit");
assertThat(mv.getModel().isEmpty()).isTrue();
}
use of cn.taketoday.web.context.support.StaticWebApplicationContext in project today-framework by TAKETODAY.
the class UrlFilenameViewControllerTests method withContextMapping.
@Test
void withContextMapping() throws Exception {
UrlFilenameViewController controller = new UrlFilenameViewController();
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myapp/docs/cvs/commit.html");
request.setContextPath("/myapp");
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.refresh();
ServletRequestContext context = new ServletRequestContext(wac, request, new MockHttpServletResponse());
ModelAndView mv = controller.handleRequest(context);
assertThat(mv.getViewName()).isEqualTo("docs/cvs/commit");
assertThat(mv.getModel().isEmpty()).isTrue();
}
use of cn.taketoday.web.context.support.StaticWebApplicationContext in project today-framework by TAKETODAY.
the class XsltViewTests method getXsltView.
private XsltView getXsltView(String templatePath) {
XsltView view = new XsltView();
view.setUrl(templatePath);
view.setApplicationContext(new StaticWebApplicationContext());
view.initApplicationContext();
return view;
}
Aggregations