use of org.springframework.mock.web.test.MockServletConfig in project spring-framework by spring-projects.
the class DispatcherServletTests method notDetectAllViewResolvers.
@Test
public void notDetectAllViewResolvers() throws ServletException, IOException {
DispatcherServlet complexDispatcherServlet = new DispatcherServlet();
complexDispatcherServlet.setContextClass(ComplexWebApplicationContext.class);
complexDispatcherServlet.setNamespace("test");
complexDispatcherServlet.setDetectAllViewResolvers(false);
complexDispatcherServlet.init(new MockServletConfig(getServletContext(), "complex"));
MockHttpServletRequest request = new MockHttpServletRequest(getServletContext(), "GET", "/unknown.do");
MockHttpServletResponse response = new MockHttpServletResponse();
try {
complexDispatcherServlet.service(request, response);
fail("Should have thrown ServletException");
} catch (ServletException ex) {
// expected
assertTrue(ex.getMessage().indexOf("failed0") != -1);
}
}
use of org.springframework.mock.web.test.MockServletConfig in project spring-framework by spring-projects.
the class DispatcherServletTests method notDetectAllHandlerExceptionResolvers.
@Test
public void notDetectAllHandlerExceptionResolvers() throws ServletException, IOException {
DispatcherServlet complexDispatcherServlet = new DispatcherServlet();
complexDispatcherServlet.setContextClass(ComplexWebApplicationContext.class);
complexDispatcherServlet.setNamespace("test");
complexDispatcherServlet.setDetectAllHandlerExceptionResolvers(false);
complexDispatcherServlet.init(new MockServletConfig(getServletContext(), "complex"));
MockHttpServletRequest request = new MockHttpServletRequest(getServletContext(), "GET", "/unknown.do");
MockHttpServletResponse response = new MockHttpServletResponse();
try {
complexDispatcherServlet.service(request, response);
fail("Should have thrown ServletException");
} catch (ServletException ex) {
// expected
assertTrue(ex.getMessage().indexOf("No adapter for handler") != -1);
}
}
use of org.springframework.mock.web.test.MockServletConfig in project spring-framework by spring-projects.
the class ContextLoaderTests method testFrameworkServletWithDefaultLocation.
@Test
public void testFrameworkServletWithDefaultLocation() throws Exception {
DispatcherServlet servlet = new DispatcherServlet();
servlet.setContextClass(XmlWebApplicationContext.class);
try {
servlet.init(new MockServletConfig(new MockServletContext(""), "test"));
fail("Should have thrown BeanDefinitionStoreException");
} catch (BeanDefinitionStoreException ex) {
// expected
assertTrue(ex.getCause() instanceof IOException);
assertTrue(ex.getCause().getMessage().contains("/WEB-INF/test-servlet.xml"));
}
}
use of org.springframework.mock.web.test.MockServletConfig in project spring-framework by spring-projects.
the class AnnotationConfigDispatcherServletInitializerTests method rootContextOnly.
// SPR-11357
@Test
public void rootContextOnly() throws ServletException {
initializer = new MyAnnotationConfigDispatcherServletInitializer() {
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class<?>[] { MyConfiguration.class };
}
@Override
protected Class<?>[] getServletConfigClasses() {
return null;
}
};
initializer.onStartup(servletContext);
DispatcherServlet servlet = (DispatcherServlet) servlets.get(SERVLET_NAME);
servlet.init(new MockServletConfig(this.servletContext));
WebApplicationContext wac = servlet.getWebApplicationContext();
((AnnotationConfigWebApplicationContext) wac).refresh();
assertTrue(wac.containsBean("bean"));
assertTrue(wac.getBean("bean") instanceof MyBean);
}
Aggregations