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:com.google.api.server.spi.auth.EndpointsPeerAuthenticatorTest.java

private static MockHttpServletRequest createRequest(String host, int port, String servletPath,
        String contextPath, String queryString) {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addHeader("Host", host);
    request.setServerName(host);/*from w w  w.  j  a v  a  2s .  com*/
    request.setServerPort(port);
    request.setServletPath(servletPath);
    request.setQueryString(queryString);
    request.setContextPath(contextPath);
    return request;
}

From source file:org.geomajas.gwt.server.mvc.GwtResourceControllerTest.java

@Test
public void testResourceInContext() throws ServletException, IOException {
    // create mock context that loads from the classpath
    MockServletContext context = new MockServletContext();
    MockHttpServletRequest request = new MockHttpServletRequest(context);
    request.setServletPath("/org");
    request.setPathInfo("/org/geomajas/gwt/server/mvc/geomajas_logo.png");
    request.setMethod("GET");
    MockHttpServletResponse response = new MockHttpServletResponse();
    GwtResourceController resourceController = new GwtResourceController();
    resourceController.setServletContext(context);
    resourceController.getResource(request, response);
    Resource resource = new ClassPathResource("/org/geomajas/gwt/server/mvc/geomajas_logo.png");
    Assert.assertArrayEquals(IOUtils.toByteArray(resource.getInputStream()), response.getContentAsByteArray());
}

From source file:ar.com.zauber.commons.web.cache.impl.filter.matchers.AntRequestMatcherTest.java

/**
 * Test method for {@link AntRequestMatcher#matches(HttpServletRequest)}.
 *//*  w  w w.  j ava  2  s .  c om*/
@Test
public final void testMatches() {
    AntRequestMatcher matcher = new AntRequestMatcher("/servlet/path/{variable}");
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/context/servlet/path/pepe");
    request.setServletPath("/servlet");
    request.setContextPath("/context");
    MatchData matches = matcher.matches(request);
    assertThat(matches, notNullValue());
    assertThat((String) matches.get("variable"), equalTo("pepe"));
}

From source file:ar.com.zauber.commons.web.cache.impl.filter.matchers.AntRequestMatcherTest.java

/**
 * Test method for {@link AntRequestMatcher#matches(HttpServletRequest)}.
 *//*from w ww . j a v a  2s .c o  m*/
@Test
public final void testMatchesDecodes() {
    AntRequestMatcher matcher = new AntRequestMatcher("/servlet/path/{variable}");
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/context/servlet/path/pepe%20parada");
    request.setServletPath("/servlet");
    request.setContextPath("/context");
    MatchData matches = matcher.matches(request);
    assertThat(matches, notNullValue());
    assertThat((String) matches.get("variable"), equalTo("pepe parada"));
}

From source file:org.eclipse.virgo.snaps.core.internal.SnapUtilsTests.java

@Test
public void determineSnapContextPathFromDeepPathInfo() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setServletPath("/hotels/booking/index");
    String contextPath = SnapUtils.determineSnapContextPath(request);
    assertEquals("/hotels", contextPath);
}

From source file:org.eclipse.virgo.snaps.core.internal.SnapUtilsTests.java

@Test
public void determineSnapContextPathFromPathInfo() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setServletPath("/hotels/booking");
    String contextPath = SnapUtils.determineSnapContextPath(request);
    assertEquals("/hotels", contextPath);
}

From source file:org.eclipse.virgo.snaps.core.internal.SnapUtilsTests.java

@Test
public void determineSnapContextPathFromStraightPathInfo() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setServletPath("/hotels");
    String contextPath = SnapUtils.determineSnapContextPath(request);
    assertEquals("/hotels", contextPath);
}

From source file:com.google.api.server.spi.handlers.ApiProxyHandlerTest.java

private void testWithServletPath(String servletPath) throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setServerName("localhost");
    request.setServerPort(8080);/*w w w.  j  a va  2 s . c  o  m*/
    request.setServletPath(servletPath);
    MockHttpServletResponse response = new MockHttpServletResponse();
    ApiProxyHandler handler = new ApiProxyHandler();
    EndpointsContext context = new EndpointsContext("GET", "static/proxy.html", request, response);

    handler.handle(context);

    assertThat(response.getContentAsString()).contains(servletPath);
}

From source file:org.springframework.boot.actuate.autoconfigure.security.servlet.ManagementWebSecurityAutoConfigurationTests.java

private int getResponseStatus(AssertableWebApplicationContext context, String path)
        throws IOException, javax.servlet.ServletException {
    FilterChainProxy filterChainProxy = context.getBean(FilterChainProxy.class);
    MockServletContext servletContext = new MockServletContext();
    MockHttpServletResponse response = new MockHttpServletResponse();
    servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, context);
    MockHttpServletRequest request = new MockHttpServletRequest(servletContext);
    request.setServletPath(path);
    request.setMethod("GET");
    filterChainProxy.doFilter(request, response, new MockFilterChain());
    return response.getStatus();
}

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

/** @throws Exception on error */
public final void testAny() throws Exception {
    final URL url = new URL("http://127.0.0.1/foo/bar");
    final URLRequestMapper mapper = new InmutableURLRequestMapper(new InmutableURLResult(url));
    final String ctxPath = "/nexusaaa-0.0";
    final String servletContext = "/bin";

    final MockHttpServletRequest request = new MockHttpServletRequest("GET", ctxPath + servletContext + "/");
    request.setContextPath(ctxPath);//from  ww  w . j a  v a2s .  c  o m
    request.setServletPath(servletContext);

    assertEquals(url, mapper.getProxiedURLFromRequest(request).getURL());
}