public void testParseXML() throws Exception { URL url = getClass().getResource("applicationContext.xml"); FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext(url.toString()); Dispatcher dispatcher = (Dispatcher) context.getBean("dispatcher"); String body = "<Hello service=\"hello\" message=\"Hello world!\"/>"; File file = File.createTempFile("geoserver", "req"); try { FileOutputStream output = new FileOutputStream(file); output.write(body.getBytes()); output.flush(); output.close(); BufferedReader input = new BufferedReader(new InputStreamReader(new FileInputStream(file))); input.mark(8192); Request req = new Request(); req.setInput(input); Object object = dispatcher.parseRequestXML(null, input, req); assertEquals(new Message("Hello world!"), object); } finally { file.delete(); } }
@Before public void initCallback() { this.callback = new LocalWorkspaceCallback(getGeoServer()); this.request = new Request(); }
@Test public void testRequest() throws InterruptedException, ExecutionException, SecurityException, NoSuchFieldException { // setup the state final Request request = new Request(); Dispatcher.REQUEST.set(request); // test it's transferred properly using the base class machinery testThreadLocalTransfer( new ThreadLocalTransferCallable( new PublicThreadLocalTransfer(Dispatcher.class, "REQUEST")) { @Override void assertThreadLocalCleaned() { assertNull(Dispatcher.REQUEST.get()); } @Override void assertThreadLocalApplied() { assertSame(request, Dispatcher.REQUEST.get()); } }); } }
@Test public void testThreadLocalTransfer() throws InterruptedException, ExecutionException { final Request request = new Request(); Dispatcher.REQUEST.set(request); final LayerInfo layer = new LayerInfoImpl();
Operation opDescriptor = new Operation("concat", service, method, parameters); Object result = dispatcher.execute(new Request(), opDescriptor); assertEquals("p1p2", result); assertTrue(invokeDirectCalled.get());
public void testParseKVP() throws Exception { URL url = getClass().getResource("applicationContext.xml"); FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext(url.toString()); Dispatcher dispatcher = (Dispatcher) context.getBean("dispatcher"); MockHttpServletRequest request = new MockHttpServletRequest(); request.setContextPath("/geoserver"); request.addParameter("service", "hello"); request.addParameter("request", "Hello"); request.addParameter("message", "Hello world!"); request.setQueryString("service=hello&request=hello&message=Hello World!"); Request req = new Request(); req.setHttpRequest(request); dispatcher.parseKVP(req); Message message = (Message) dispatcher.parseRequestKVP(Message.class, req); assertEquals(new Message("Hello world!"), message); }
Request request = new Request();
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); }
protected void setUp() throws Exception { super.setUp(); HelloWorld helloWorld = new HelloWorld(); Service service = new Service( "hello", helloWorld, new Version("1.0.0"), Collections.singletonList("hello")); request = new MockHttpServletRequest() { public int getServerPort() { return 8080; } }; request.setScheme("http"); request.setServerName("localhost"); request.setContextPath("geoserver"); response = new MockHttpServletResponse(); handler = new DefaultServiceExceptionHandler(); requestInfo = new Request(); requestInfo.setHttpRequest(request); requestInfo.setHttpResponse(response); requestInfo.setService("hello"); requestInfo.setVersion("1.0.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")); }
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 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); }
Request request = new Request(); request.setService("WMS"); request.setRequest("GetCapabilities");
Request request = new Request(); request.setService("WMS"); request.setRequest("GetCapabilities");
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); }
Request request = new Request(); request.setService("WMS"); request.setRequest("GetCapabilities");
protected void setupRequestThreadLocal(String service) { Request request = new Request(); request.setService(service); Dispatcher.REQUEST.set(request); }
Request buildRequest(String gsCookieValue) { Request request = new Request(); MockHttpServletRequest httpRequest = new MockHttpServletRequest(); request.setHttpRequest(httpRequest); request.setHttpResponse(new MockHttpServletResponse()); if(gsCookieValue != null) { httpRequest.addCookie(new Cookie(UserFlowController.COOKIE_NAME, gsCookieValue)); } return request; } }
@Test public void testWFSLockFeature() throws Exception { LockFeatureType lf = WfsFactory.eINSTANCE.createLockFeatureType(); LockType l = WfsFactory.eINSTANCE.createLockType(); l.setTypeName(new QName("http://acme.org", "foo", "acme")); lf.getLock().add(l); Operation op = op("LockFeature", "WFS", "1.0.0", lf); callback.operationDispatched(new Request(), op); assertEquals("acme:foo", data.getResources().get(0)); }
@Test public void testBasic() throws Exception { callback.operationDispatched(new Request(), op("foo", "bar", "1.2.3", null)); assertEquals("BAR", data.getService()); assertEquals("foo", data.getOperation()); assertEquals("1.2.3", data.getOwsVersion()); }