public void testReadOpPost() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); request.setContextPath("/geoserver"); request.setRequestURI("/geoserver/hello"); request.setMethod("post"); String body = "<Hello service=\"hello\"/>"; DelegatingServletInputStream input = new DelegatingServletInputStream(new ByteArrayInputStream(body.getBytes())); Dispatcher dispatcher = new Dispatcher(); BufferedReader buffered = new BufferedReader(new InputStreamReader(input)); buffered.mark(2048); Map map = dispatcher.readOpPost(buffered); assertNotNull(map); assertEquals("Hello", map.get("request")); assertEquals("hello", map.get("service")); }
public void testErrorSavedOnRequestOnGenericException() 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 RuntimeException("foo"); dispatcher.exception(genericError, null, req); assertEquals("Exception did not get saved", genericError, req.error); }
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); }
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")); }
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); }
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); }