Package org.springframework.mock.web.test

Examples of org.springframework.mock.web.test.MockHttpServletResponse$ResponseServletOutputStream


  @Test
  public void multiPaths() throws Exception {
    initServlet(MultiPathController.class);

    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/category/page/5");
    MockHttpServletResponse response = new MockHttpServletResponse();
    servlet.service(request, response);
    assertEquals("handle4-page-5", response.getContentAsString());

    request = new MockHttpServletRequest("GET", "/category/page/5.html");
    response = new MockHttpServletResponse();
    servlet.service(request, response);
    assertEquals("handle4-page-5", response.getContentAsString());
  }
View Full Code Here


      }
    };
    servlet.init(new MockServletConfig());

    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/hotels/hotel.with.dot");
    MockHttpServletResponse response = new MockHttpServletResponse();
    servlet.service(request, response);
    assertEquals("test-hotel.with.dot", response.getContentAsString());
  }
View Full Code Here

  @Test
  public void customRegex() throws Exception {
    initServlet(CustomRegexController.class);

    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/42");
    MockHttpServletResponse response = new MockHttpServletResponse();
    servlet.service(request, response);
    assertEquals("test-42", response.getContentAsString());
  }
View Full Code Here

  @Test
  public void menuTree() throws Exception {
    initServlet(MenuTreeController.class);

    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/book/menu/type/M5");
    MockHttpServletResponse response = new MockHttpServletResponse();
    servlet.service(request, response);
    assertEquals("M5", response.getContentAsString());
  }
View Full Code Here

  @Test
  public void variableNames() throws Exception {
    initServlet(VariableNamesController.class);

    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/test/foo");
    MockHttpServletResponse response = new MockHttpServletResponse();
    servlet.service(request, response);
    assertEquals("foo-foo", response.getContentAsString());

    request = new MockHttpServletRequest("DELETE", "/test/bar");
    response = new MockHttpServletResponse();
    servlet.service(request, response);
    assertEquals("bar-bar", response.getContentAsString());
  }
View Full Code Here

  @Test
  public void crud() throws Exception {
    initServletWithControllers(CrudController.class);

    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/hotels");
    MockHttpServletResponse response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertEquals("list", response.getContentAsString());

    request = new MockHttpServletRequest("GET", "/hotels/");
    response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertEquals("list", response.getContentAsString());

    request = new MockHttpServletRequest("POST", "/hotels");
    response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertEquals("create", response.getContentAsString());

    request = new MockHttpServletRequest("GET", "/hotels/42");
    response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertEquals("show-42", response.getContentAsString());

    request = new MockHttpServletRequest("GET", "/hotels/42/");
    response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertEquals("show-42", response.getContentAsString());

    request = new MockHttpServletRequest("PUT", "/hotels/42");
    response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertEquals("createOrUpdate-42", response.getContentAsString());

    request = new MockHttpServletRequest("DELETE", "/hotels/42");
    response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertEquals("remove-42", response.getContentAsString());
  }
View Full Code Here

    tc.setServletContext(sc);
    tc.afterPropertiesSet();

    BasicTilesContainer container = (BasicTilesContainer) ServletUtil.getContainer(sc);
    TilesRequestContext requestContext = new ServletTilesRequestContext(
        container.getApplicationContext(), new MockHttpServletRequest(), new MockHttpServletResponse());
    assertNotNull(container.getDefinitionsFactory().getDefinition("test", requestContext));

    tc.destroy();
  }
View Full Code Here

  @Test
  public void methodNotSupported() throws Exception {
    initServletWithControllers(MethodNotAllowedController.class);

    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/hotels/1");
    MockHttpServletResponse response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertEquals(200, response.getStatus());

    request = new MockHttpServletRequest("POST", "/hotels/1");
    response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertEquals(405, response.getStatus());

    request = new MockHttpServletRequest("GET", "/hotels");
    response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertEquals(200, response.getStatus());

    request = new MockHttpServletRequest("POST", "/hotels");
    response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertEquals(405, response.getStatus());
  }
View Full Code Here

  @Test
  public void multiPaths() throws Exception {
    initServletWithControllers(MultiPathController.class);

    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/category/page/5");
    MockHttpServletResponse response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertEquals("handle4-page-5", response.getContentAsString());

    request = new MockHttpServletRequest("GET", "/category/page/5.html");
    response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertEquals("handle4-page-5", response.getContentAsString());
  }
View Full Code Here

  @Test
  public void customRegex() throws Exception {
    initServletWithControllers(CustomRegexController.class);

    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/42;q=1;q=2");
    MockHttpServletResponse response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertEquals(200, response.getStatus());
    assertEquals("test-42-;q=1;q=2-[1, 2]", response.getContentAsString());
  }
View Full Code Here

TOP

Related Classes of org.springframework.mock.web.test.MockHttpServletResponse$ResponseServletOutputStream

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.