use of org.springframework.mock.web.test.MockServletConfig in project spring-framework by spring-projects.
the class DispatcherServletTests method notDetectAllHandlerMappings.
@Test
public void notDetectAllHandlerMappings() throws ServletException, IOException {
DispatcherServlet complexDispatcherServlet = new DispatcherServlet();
complexDispatcherServlet.setContextClass(ComplexWebApplicationContext.class);
complexDispatcherServlet.setNamespace("test");
complexDispatcherServlet.setDetectAllHandlerMappings(false);
complexDispatcherServlet.init(new MockServletConfig(getServletContext(), "complex"));
MockHttpServletRequest request = new MockHttpServletRequest(getServletContext(), "GET", "/unknown.do");
MockHttpServletResponse response = new MockHttpServletResponse();
complexDispatcherServlet.service(request, response);
assertTrue(response.getStatus() == HttpServletResponse.SC_NOT_FOUND);
}
use of org.springframework.mock.web.test.MockServletConfig in project spring-framework by spring-projects.
the class DispatcherServletTests method handlerNotMappedWithAutodetect.
@Test
public void handlerNotMappedWithAutodetect() throws ServletException, IOException {
DispatcherServlet complexDispatcherServlet = new DispatcherServlet();
// no parent
complexDispatcherServlet.setContextClass(ComplexWebApplicationContext.class);
complexDispatcherServlet.setNamespace("test");
complexDispatcherServlet.init(new MockServletConfig(getServletContext(), "complex"));
MockHttpServletRequest request = new MockHttpServletRequest(getServletContext(), "GET", URL_KNOWN_ONLY_PARENT);
MockHttpServletResponse response = new MockHttpServletResponse();
complexDispatcherServlet.service(request, response);
assertEquals(HttpServletResponse.SC_NOT_FOUND, response.getStatus());
}
use of org.springframework.mock.web.test.MockServletConfig in project spring-framework by spring-projects.
the class ServletContextAwareProcessorTests method servletContextAwareWithServletConfig.
@Test
public void servletContextAwareWithServletConfig() {
ServletContext servletContext = new MockServletContext();
ServletConfig servletConfig = new MockServletConfig(servletContext);
ServletContextAwareProcessor processor = new ServletContextAwareProcessor(servletConfig);
ServletContextAwareBean bean = new ServletContextAwareBean();
assertNull(bean.getServletContext());
processor.postProcessBeforeInitialization(bean, "testBean");
assertNotNull("ServletContext should have been set", bean.getServletContext());
assertEquals(servletContext, bean.getServletContext());
}
use of org.springframework.mock.web.test.MockServletConfig in project spring-framework by spring-projects.
the class ServletContextAwareProcessorTests method servletContextAwareWithNullServletContextAndNonNullServletConfig.
@Test
public void servletContextAwareWithNullServletContextAndNonNullServletConfig() {
ServletContext servletContext = new MockServletContext();
ServletConfig servletConfig = new MockServletConfig(servletContext);
ServletContextAwareProcessor processor = new ServletContextAwareProcessor(null, servletConfig);
ServletContextAwareBean bean = new ServletContextAwareBean();
assertNull(bean.getServletContext());
processor.postProcessBeforeInitialization(bean, "testBean");
assertNotNull("ServletContext should have been set", bean.getServletContext());
assertEquals(servletContext, bean.getServletContext());
}
use of org.springframework.mock.web.test.MockServletConfig in project spring-framework by spring-projects.
the class ServletContextAwareProcessorTests method servletConfigAwareWithServletContextAndServletConfig.
@Test
public void servletConfigAwareWithServletContextAndServletConfig() {
ServletContext servletContext = new MockServletContext();
ServletConfig servletConfig = new MockServletConfig(servletContext);
ServletContextAwareProcessor processor = new ServletContextAwareProcessor(servletContext, servletConfig);
ServletConfigAwareBean bean = new ServletConfigAwareBean();
assertNull(bean.getServletConfig());
processor.postProcessBeforeInitialization(bean, "testBean");
assertNotNull("ServletConfig should have been set", bean.getServletConfig());
assertEquals(servletConfig, bean.getServletConfig());
}
Aggregations