예제 #1
0
  public void testReadOpContext() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setContextPath("/geoserver");
    request.setRequestURI("/geoserver/hello");
    request.setMethod("get");

    Dispatcher dispatcher = new Dispatcher();

    Request req = new Request();
    req.httpRequest = request;
    dispatcher.init(req);

    Map map = dispatcher.readOpContext(req);

    assertEquals("hello", map.get("service"));

    request = new MockHttpServletRequest();
    request.setContextPath("/geoserver");
    request.setRequestURI("/geoserver/foobar/hello");
    request.setMethod("get");
    map = dispatcher.readOpContext(req);
    assertEquals("hello", map.get("service"));

    request = new MockHttpServletRequest();
    request.setContextPath("/geoserver");
    request.setRequestURI("/geoserver/foobar/hello/");
    request.setMethod("get");
    map = dispatcher.readOpContext(req);

    assertEquals("hello", map.get("service"));
  }
예제 #2
0
  public void testReadContextAndPath() throws Exception {
    Dispatcher dispatcher = new Dispatcher();

    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setContextPath("/geoserver");
    request.setRequestURI("/geoserver/hello");
    request.setMethod("get");

    Request req = new Request();
    req.httpRequest = request;

    dispatcher.init(req);
    assertNull(req.context);
    assertEquals("hello", req.path);

    request.setRequestURI("/geoserver/foo/hello");
    dispatcher.init(req);
    assertEquals("foo", req.context);
    assertEquals("hello", req.path);

    request.setRequestURI("/geoserver/foo/baz/hello/");
    dispatcher.init(req);
    assertEquals("foo/baz", req.context);
    assertEquals("hello", req.path);
  }
예제 #3
0
  public void testNoErrorOn304ErrorCodeException() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setContextPath("/geoserver");
    request.setRequestURI("/geoserver/hello");
    request.setMethod("get");

    Dispatcher dispatcher = new Dispatcher();

    Request req = new Request();
    req.httpRequest = request;
    dispatcher.init(req);

    MockHttpServletResponse response = new MockHttpServletResponse();
    req.setHttpResponse(response);

    RuntimeException error = new HttpErrorCodeException(304, "Not Modified");
    dispatcher.exception(error, null, req);

    assertNull("Exception erroneously saved", req.error);
  }
예제 #4
0
  public void testErrorSavedOnRequestOnNon304ErrorCodeException() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setContextPath("/geoserver");
    request.setRequestURI("/geoserver/hello");
    request.setMethod("get");

    Dispatcher dispatcher = new Dispatcher();

    Request req = new Request();
    req.httpRequest = request;
    dispatcher.init(req);

    MockHttpServletResponse response = new MockHttpServletResponse();
    req.setHttpResponse(response);

    RuntimeException genericError = new HttpErrorCodeException(500, "Internal Server Error");
    dispatcher.exception(genericError, null, req);

    assertEquals("Exception did not get saved", genericError, req.error);
  }