Example usage for org.springframework.mock.web MockHttpServletRequest setServletPath

List of usage examples for org.springframework.mock.web MockHttpServletRequest setServletPath

Introduction

In this page you can find the example usage for org.springframework.mock.web MockHttpServletRequest setServletPath.

Prototype

public void setServletPath(String servletPath) 

Source Link

Usage

From source file:org.eclipse.virgo.snaps.core.SnapHostFilterTests.java

@Test
public void testRouteToSnap() throws ServletException, IOException {
    MockHttpServletResponse response = new MockHttpServletResponse();
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setServletPath("/hotels/booking");

    Snap snap = createMock(Snap.class);
    snap.handleRequest(request, response);
    expectLastCall();// ww w  . j a  va  2 s  . c o m

    this.stubRegistry.snaps.put("/hotels", snap);

    MockServletContext servletContext = new MockServletContext();
    MockFilterConfig config = new MockFilterConfig(servletContext);
    MockFilterChain chain = new MockFilterChain();

    replay(snap);
    TestFilter filter = new TestFilter();
    filter.init(config);
    filter.doFilter(request, response, chain);
    filter.destroy();
    verify(snap);
}

From source file:ar.com.zauber.commons.web.proxy.impl.PathBasedURLRequestMapperTest.java

/** @throws Exception on error */
public final void testResultDelegate() throws Exception {
    final PathBasedURLRequestMapper mapper = new PathBasedURLRequestMapper(
            new InmutableURLRequestMapper(new InmutableURLResult()));
    final MockServletContext ctx = new MockServletContext();

    final String ctxPath = "/nexusaaa-0.0";
    final String servletContext = "/bin";

    final MockHttpServletRequest request = new MockHttpServletRequest(ctx, "GET",
            ctxPath + servletContext + "/");
    request.setContextPath(ctxPath);/* w ww  . ja  va2 s .  com*/
    request.setServletPath(servletContext);

    assertFalse(mapper.getProxiedURLFromRequest(request).hasResult());
}

From source file:ar.com.zauber.commons.web.proxy.impl.PathBasedURLRequestMapperTest.java

/** @throws Exception on error */
public final void testServletContext() throws Exception {
    final String ctxPath = "/nexusaaa-0.0";
    final String servletContext = "/bin";

    final PathBasedURLRequestMapper mapper = new PathBasedURLRequestMapper(
            new InmutableURLRequestMapper(new InmutableURLResult(new URL(base))));
    mapper.setStripContextPath(true);/*from   w  ww .j a v  a 2  s  .c om*/
    mapper.setStripServletPath(true);

    final MockServletContext ctx = new MockServletContext();

    final MockHttpServletRequest request = new MockHttpServletRequest(ctx, "GET",
            ctxPath + servletContext + "/");
    request.setContextPath(ctxPath);
    request.setServletPath(servletContext);
    assertEquals(new URL(base + "/"), mapper.getProxiedURLFromRequest(request).getURL());
}

From source file:ar.com.zauber.commons.web.proxy.impl.PathBasedURLRequestMapperTest.java

/** @throws Exception on error */
public final void testNoServletContext() throws Exception {
    final String ctxPath = "/nexusaaa-0.0";
    final String servletContext = "/bin";

    final PathBasedURLRequestMapper mapper = new PathBasedURLRequestMapper(
            new InmutableURLRequestMapper(new InmutableURLResult(new URL(base))));
    mapper.setStripContextPath(false);//w  w w.j  a v a 2s  . c o m
    mapper.setStripServletPath(false);

    final MockServletContext ctx = new MockServletContext();

    final MockHttpServletRequest request = new MockHttpServletRequest(ctx, "GET",
            ctxPath + servletContext + "/");
    request.setContextPath(ctxPath);
    request.setServletPath(servletContext);
    assertEquals(new URL(base + ctxPath + servletContext + "/"),
            mapper.getProxiedURLFromRequest(request).getURL());
}

From source file:fragment.web.AccessDecisionTest.java

private MockHttpServletRequest createRequest(String uri) {
    MockHttpServletRequest mockRequest = getRequestTemplate(HttpMethod.GET, uri);
    mockRequest.setContextPath("/portal");
    mockRequest.setServletPath(null);
    return mockRequest;
}

From source file:com.xemantic.tadedon.guice.servlet.mock.FakeServletContainer.java

public void service(ServletRequest request, ServletResponse response) throws IOException, ServletException {
    if (request instanceof MockHttpServletRequest) {
        MockHttpServletRequest mockRequest = (MockHttpServletRequest) request;
        mockRequest.setServletPath(mockRequest.getRequestURI());
    }/*  w w  w.ja v a 2s . c o  m*/
    m_filter.doFilter(request, response, new org.springframework.mock.web.MockFilterChain());
}

From source file:com.github.woonsan.katharsis.servlet.KatharsisServletTest.java

@Test
public void testUnacceptableRequestContentType() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest(servletContext);
    request.setMethod("GET");
    request.setContextPath("");
    request.setServletPath("/api");
    request.setPathInfo("/tasks");
    request.setRequestURI("/api/tasks");
    request.setContentType(JsonApiMediaType.APPLICATION_JSON_API);
    request.addHeader("Accept", "application/xml");
    request.addParameter("filter", "{\"name\":\"John\"}");

    MockHttpServletResponse response = new MockHttpServletResponse();

    katharsisServlet.service(request, response);

    assertEquals(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, response.getStatus());
    String responseContent = response.getContentAsString();
    assertTrue(responseContent == null || "".equals(responseContent.trim()));
}

From source file:com.github.woonsan.katharsis.servlet.KatharsisServletTest.java

@Test
public void onSimpleCollectionGetShouldReturnCollectionOfResources() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest(servletContext);
    request.setMethod("GET");
    request.setContextPath("");
    request.setServletPath("/api");
    request.setPathInfo("/tasks/");
    request.setRequestURI("/api/tasks/");
    request.setContentType(JsonApiMediaType.APPLICATION_JSON_API);
    request.addHeader("Accept", "*/*");

    MockHttpServletResponse response = new MockHttpServletResponse();

    katharsisServlet.service(request, response);

    String responseContent = response.getContentAsString();

    log.debug("responseContent: {}", responseContent);
    assertNotNull(responseContent);//from   w  ww.j  a  v  a2 s  .  c o m

    assertJsonPartEquals("tasks", responseContent, "data[0].type");
    assertJsonPartEquals("\"1\"", responseContent, "data[0].id");
    assertJsonPartEquals(FIRST_TASK_ATTRIBUTES, responseContent, "data[0].attributes");
    assertJsonPartEquals(FIRST_TASK_LINKS, responseContent, "data[0].links");
    assertJsonPartEquals(PROJECT1_RELATIONSHIP_LINKS, responseContent, "data[0].relationships.project.links");
    assertJsonPartEquals("[]", responseContent, "included");
}

From source file:com.github.woonsan.katharsis.servlet.KatharsisServletTest.java

@Test
public void onSimpleResourceGetShouldReturnOneResource() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest(servletContext);
    request.setMethod("GET");
    request.setContextPath("");
    request.setServletPath("/api");
    request.setPathInfo("/tasks/1");
    request.setRequestURI("/api/tasks/1");
    request.setContentType(JsonApiMediaType.APPLICATION_JSON_API);
    request.addHeader("Accept", "*/*");
    request.addParameter("filter", "");

    MockHttpServletResponse response = new MockHttpServletResponse();

    katharsisServlet.service(request, response);

    String responseContent = response.getContentAsString();

    log.debug("responseContent: {}", responseContent);
    assertNotNull(responseContent);//w w  w . j av a 2  s .  c o  m

    assertJsonPartEquals("tasks", responseContent, "data.type");
    assertJsonPartEquals("\"1\"", responseContent, "data.id");
    assertJsonPartEquals(SOME_TASK_ATTRIBUTES, responseContent, "data.attributes");
    assertJsonPartEquals(FIRST_TASK_LINKS, responseContent, "data.links");
    assertJsonPartEquals(PROJECT1_RELATIONSHIP_LINKS, responseContent, "data.relationships.project.links");
    assertJsonPartEquals("[]", responseContent, "included");
}

From source file:com.github.woonsan.katharsis.servlet.KatharsisServletTest.java

@Test
public void onCollectionRequestWithParamsGetShouldReturnCollection() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest(servletContext);
    request.setMethod("GET");
    request.setContextPath("");
    request.setServletPath("/api");
    request.setPathInfo("/tasks");
    request.setRequestURI("/api/tasks");
    request.setContentType(JsonApiMediaType.APPLICATION_JSON_API);
    request.addHeader("Accept", "*/*");
    request.addParameter("filter", "{\"name\":\"John\"}");

    MockHttpServletResponse response = new MockHttpServletResponse();

    katharsisServlet.service(request, response);

    String responseContent = response.getContentAsString();

    log.debug("responseContent: {}", responseContent);
    assertNotNull(responseContent);/* w  w w.j a  v a  2  s .c o  m*/

    assertJsonPartEquals("tasks", responseContent, "data[0].type");
    assertJsonPartEquals("\"1\"", responseContent, "data[0].id");
    assertJsonPartEquals(FIRST_TASK_ATTRIBUTES, responseContent, "data[0].attributes");
    assertJsonPartEquals(FIRST_TASK_LINKS, responseContent, "data[0].links");
    assertJsonPartEquals(PROJECT1_RELATIONSHIP_LINKS, responseContent, "data[0].relationships.project.links");
    assertJsonPartEquals("[]", responseContent, "included");
}