Search in sources :

Example 16 with MockHttpServletResponse

use of com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletResponse in project wcomponents by BorderTech.

the class ServletResponse_Test method testGetOutputStream.

@Test
public void testGetOutputStream() throws IOException {
    MockHttpServletResponse backing = new MockHttpServletResponse();
    ServletResponse response = new ServletResponse(backing);
    Assert.assertSame("Incorrect outputStream", backing.getOutputStream(), response.getOutputStream());
}
Also used : MockHttpServletResponse(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletResponse) MockHttpServletResponse(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletResponse) Test(org.junit.Test)

Example 17 with MockHttpServletResponse

use of com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletResponse in project wcomponents by BorderTech.

the class ThemeServlet_Test method testValidFile.

@Test
public void testValidFile() throws ServletException, IOException {
    MockHttpServletResponse response = requestFile("ThemeServlet_Testfile.xsl", false);
    Assert.assertEquals("Should have returned 200", HttpServletResponse.SC_OK, response.getStatus());
    Assert.assertEquals("Incorrect MIME type", ConfigurationProperties.getFileMimeTypeForExtension("xsl"), response.getContentType());
    response = requestFile("ThemeServlet_Testfile.xsl", true);
    Assert.assertEquals("Should have returned 200", HttpServletResponse.SC_OK, response.getStatus());
    Assert.assertEquals("Incorrect MIME type", ConfigurationProperties.getFileMimeTypeForExtension("xsl"), response.getContentType());
}
Also used : MockHttpServletResponse(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletResponse) Test(org.junit.Test)

Example 18 with MockHttpServletResponse

use of com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletResponse in project wcomponents by BorderTech.

the class ThemeServlet_Test method testInvalidFiles.

@Test
public void testInvalidFiles() throws ServletException, IOException {
    // Test Invalid due to relative path
    MockHttpServletResponse response = requestFile("../wcomponents.properties", false);
    Assert.assertEquals("Should have returned 404", HttpServletResponse.SC_NOT_FOUND, response.getStatus());
    response = requestFile("../wcomponents.properties", true);
    Assert.assertEquals("Should have returned 404", HttpServletResponse.SC_NOT_FOUND, response.getStatus());
    response = requestFile("/wcomponents.properties", false);
    Assert.assertEquals("Should have returned 404", HttpServletResponse.SC_NOT_FOUND, response.getStatus());
    response = requestFile("/wcomponents.properties", true);
    Assert.assertEquals("Should have returned 404", HttpServletResponse.SC_NOT_FOUND, response.getStatus());
    // Invalid due to non-existant resource
    response = requestFile("xslt/ThemeServlet_Test.testInvalidFiles", false);
    Assert.assertEquals("Should have returned 404", HttpServletResponse.SC_NOT_FOUND, response.getStatus());
}
Also used : MockHttpServletResponse(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletResponse) Test(org.junit.Test)

Example 19 with MockHttpServletResponse

use of com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletResponse in project wcomponents by BorderTech.

the class ThemeServlet_Test method requestFile.

/**
 * Requests a file from the servlet.
 *
 * @param path the path to the file
 * @param asParam true to use the ThemeServlet's 'f' parameter or false to place the path in the URL.
 * @return the servlet response
 * @throws ServletException a servlet exception
 * @throws IOException an exception
 */
private MockHttpServletResponse requestFile(final String path, final boolean asParam) throws ServletException, IOException {
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    if (asParam) {
        request.setRequestURI("/theme");
        request.setParameter("f", path);
    } else {
        request.setRequestURI("/theme/" + path);
        request.setPathInfo('/' + path);
    }
    themeServlet.doGet(request, response);
    return response;
}
Also used : MockHttpServletRequest(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest) MockHttpServletResponse(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletResponse)

Example 20 with MockHttpServletResponse

use of com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletResponse in project wcomponents by BorderTech.

the class WServletPerformance_Test method sendOtherServletRequest.

/**
 * Invokes the other servlet request processing.
 *
 * @param servlet the servlet to invoke request processing on.
 * @param session the current session.
 * @param step the step count
 * @throws Exception an exception
 */
private void sendOtherServletRequest(final SimpleServlet servlet, final HttpSession session, final int step) throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest(session);
    MockHttpServletResponse response = new MockHttpServletResponse();
    if (step > 0) {
        request.setMethod("POST");
        request.setRequestURI("http://localhost/app");
        request.setParameter("formBean.property1", "p1_" + step);
        request.setParameter("formBean.property2", "p2_" + step);
        request.setParameter("submit", "Submit");
    } else {
        request.setMethod("GET");
        request.setRequestURI("http://localhost/app");
    }
    servlet.service(request, response);
}
Also used : MockHttpServletRequest(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest) MockHttpServletResponse(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletResponse)

Aggregations

MockHttpServletResponse (com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletResponse)21 Test (org.junit.Test)15 MockHttpServletRequest (com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest)13 MockServletConfig (com.github.bordertech.wcomponents.util.mock.servlet.MockServletConfig)8 MockHttpSession (com.github.bordertech.wcomponents.util.mock.servlet.MockHttpSession)6 WText (com.github.bordertech.wcomponents.WText)5 WServletHelper (com.github.bordertech.wcomponents.servlet.WServlet.WServletHelper)2 UIContext (com.github.bordertech.wcomponents.UIContext)1 ServletException (javax.servlet.ServletException)1