Package org.springframework.mock.web

Examples of org.springframework.mock.web.MockServletConfig


  public void testNotDetectAllHandlerMappings() 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);
View Full Code Here


  public void testHandlerNotMappedWithAutodetect() 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);
View Full Code Here

    DispatcherServlet complexDispatcherServlet = new DispatcherServlet();
    // will have parent
    complexDispatcherServlet.setContextClass(ComplexWebApplicationContext.class);
    complexDispatcherServlet.setNamespace("test");
   
    ServletConfig config = new MockServletConfig(getServletContext(), "complex");
    config.getServletContext().setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, parent);
    complexDispatcherServlet.init(config);

    MockHttpServletRequest request = new MockHttpServletRequest(getServletContext(), "GET",
        URL_KNOWN_ONLY_PARENT);
    MockHttpServletResponse response = new MockHttpServletResponse();
View Full Code Here

  public void testDetectAllHandlerAdapters() throws ServletException, IOException {
    DispatcherServlet complexDispatcherServlet = new DispatcherServlet();
    complexDispatcherServlet.setContextClass(ComplexWebApplicationContext.class);
    complexDispatcherServlet.setNamespace("test");
    complexDispatcherServlet.init(new MockServletConfig(getServletContext(), "complex"));

    MockHttpServletRequest request = new MockHttpServletRequest(getServletContext(), "GET", "/servlet.do");
    MockHttpServletResponse response = new MockHttpServletResponse();
    complexDispatcherServlet.service(request, response);
    assertEquals("body", response.getContentAsString());
View Full Code Here

  public void testNotDetectAllHandlerAdapters() throws ServletException, IOException {
    DispatcherServlet complexDispatcherServlet = new DispatcherServlet();
    complexDispatcherServlet.setContextClass(ComplexWebApplicationContext.class);
    complexDispatcherServlet.setNamespace("test");
    complexDispatcherServlet.setDetectAllHandlerAdapters(false);
    complexDispatcherServlet.init(new MockServletConfig(getServletContext(), "complex"));

    // only ServletHandlerAdapter with bean name "handlerAdapter" detected
    MockHttpServletRequest request = new MockHttpServletRequest(getServletContext(), "GET", "/servlet.do");
    MockHttpServletResponse response = new MockHttpServletResponse();
    complexDispatcherServlet.service(request, response);
View Full Code Here

  public void testNotDetectAllHandlerExceptionResolvers() 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);
View Full Code Here

  public void testNotDetectAllViewResolvers() 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);
View Full Code Here

  public void testDispatcherServletRefresh() throws ServletException {
    MockServletContext servletContext = new MockServletContext("org/springframework/web/context");
    DispatcherServlet servlet = new DispatcherServlet();

    servlet.init(new MockServletConfig(servletContext, "empty"));
    ServletContextAwareBean contextBean = (ServletContextAwareBean)
        servlet.getWebApplicationContext().getBean("servletContextAwareBean");
    ServletConfigAwareBean configBean = (ServletConfigAwareBean)
        servlet.getWebApplicationContext().getBean("servletConfigAwareBean");
    assertSame(servletContext, contextBean.getServletContext());
View Full Code Here

  public void testDispatcherServletContextRefresh() throws ServletException {
    MockServletContext servletContext = new MockServletContext("org/springframework/web/context");
    DispatcherServlet servlet = new DispatcherServlet();

    servlet.init(new MockServletConfig(servletContext, "empty"));
    ServletContextAwareBean contextBean = (ServletContextAwareBean)
        servlet.getWebApplicationContext().getBean("servletContextAwareBean");
    ServletConfigAwareBean configBean = (ServletConfigAwareBean)
        servlet.getWebApplicationContext().getBean("servletConfigAwareBean");
    assertSame(servletContext, contextBean.getServletContext());
View Full Code Here

    wac.setServletContext(servletContext);
    wac.refresh();
    servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);

    Servlet servlet = new HttpRequestHandlerServlet();
    servlet.init(new MockServletConfig(servletContext, "myHandler"));

    servlet.service(request, response);
    assertEquals("myResponse", response.getContentAsString());

    try {
View Full Code Here

TOP

Related Classes of org.springframework.mock.web.MockServletConfig

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.