Package org.springframework.mock.web.test

Examples of org.springframework.mock.web.test.MockServletConfig


  private DispatcherServlet complexDispatcherServlet;

  @Override
  protected void setUp() throws ServletException {
    servletConfig = new MockServletConfig(new MockServletContext(), "simple");
    MockServletConfig complexConfig = new MockServletConfig(servletConfig.getServletContext(), "complex");
    complexConfig.addInitParameter("publishContext", "false");
    complexConfig.addInitParameter("class", "notWritable");
    complexConfig.addInitParameter("unknownParam", "someValue");

    simpleDispatcherServlet = new DispatcherServlet();
    simpleDispatcherServlet.setContextClass(SimpleWebApplicationContext.class);
    simpleDispatcherServlet.init(servletConfig);
View Full Code Here


  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);
    assertEquals(HttpServletResponse.SC_NOT_FOUND, response.getStatus());
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();
    complexDispatcherServlet.service(request, response);
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 testThrowExceptionIfNoHandlerFound() throws ServletException, IOException {
    DispatcherServlet complexDispatcherServlet = new DispatcherServlet();
    complexDispatcherServlet.setContextClass(SimpleWebApplicationContext.class);
    complexDispatcherServlet.setNamespace("test");
    complexDispatcherServlet.setThrowExceptionIfNoHandlerFound(true);
    complexDispatcherServlet.init(new MockServletConfig(getServletContext(), "complex"));

    MockHttpServletRequest request = new MockHttpServletRequest(getServletContext(), "GET", "/unknown");
    MockHttpServletResponse response = new MockHttpServletResponse();

    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

TOP

Related Classes of org.springframework.mock.web.test.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.