@Test public void testPostXSLT() throws Exception { String xslt = FileUtils.readFileToString( new File("src/test/resources/org/geoserver/wfs/xslt/general2.xslt")); // test for missing params MockHttpServletResponse response = postAsServletResponse( "rest/services/wfs/transforms?name=general2", xslt, "application/xslt+xml"); assertEquals(400, response.getStatusCode()); // now pass all response = postAsServletResponse( "rest/services/wfs/transforms?name=general2&sourceFormat=gml&outputFormat=HTML&outputMimeType=text/html", xslt, "application/xslt+xml"); assertEquals(201, response.getStatusCode()); assertNotNull(response.getHeader("Location")); assertTrue(response.getHeader("Location").endsWith("/rest/services/wfs/transforms/general2")); TransformInfo info = repository.getTransformInfo("general2"); assertNotNull(info); assertEquals("gml", info.getSourceFormat()); assertEquals("HTML", info.getOutputFormat()); assertEquals("text/html", info.getOutputMimeType()); }
@Test public void testGetWrongGranule() throws Exception { // Parameters for the request String ws = "wcs"; String cs = "watertemp"; String g = "notThere.html"; // Request path String requestPath = "/rest/workspaces/" + ws + "/coveragestores/" + cs + "/coverages/" + cs + "/index/granules/" + g; // Exception path String exception = "Could not find a granule with id " + g + " in coveage " + ws + ":" + cs; // First request should thrown an exception MockHttpServletResponse response = getAsServletResponse(requestPath); assertEquals(404, response.getStatusCode()); assertTrue(response.getOutputStreamContent().contains(exception)); // Same request with ?quietOnNotFound should not throw an exception response = getAsServletResponse(requestPath + "?quietOnNotFound=true"); assertEquals(404, response.getStatusCode()); assertFalse(response.getOutputStreamContent().contains(exception)); // No exception thrown assertTrue(response.getOutputStreamContent().isEmpty()); }
@Test public void testCreateAsJSON() throws Exception { GeoServer geoServer = getGeoServer(); geoServer.remove(geoServer.getSettings(geoServer.getCatalog().getWorkspaceByName("sf"))); String json = "{'settings':{'workspace':{'name':'sf'}," + "'contact':{'addressCity':'Alexandria','addressCountry':'Egypt','addressType':'Work'," + "'contactEmail':'*****@*****.**','contactOrganization':'The ancient geographes INC'," + "'contactPerson':'Claudius Ptolomaeus','contactPosition':'Chief geographer'}," + "'charset':'UTF-8','numDecimals':10,'onlineResource':'http://geoserver.org'," + "'proxyBaseUrl':'http://proxy.url','verbose':false,'verboseExceptions':'true'}}"; MockHttpServletResponse response = putAsServletResponse("/rest/workspaces/sf/settings", json, "text/json"); assertEquals(200, response.getStatusCode()); JSON jsonMod = getAsJSON("/rest/workspaces/sf/settings.json"); JSONObject jsonObject = (JSONObject) jsonMod; assertNotNull(jsonObject); JSONObject settings = jsonObject.getJSONObject("settings"); assertNotNull(settings); JSONObject workspace = settings.getJSONObject("workspace"); assertNotNull(workspace); assertEquals("sf", workspace.get("name")); assertEquals("10", settings.get("numDecimals").toString().trim()); assertEquals("http://geoserver.org", settings.get("onlineResource")); assertEquals("http://proxy.url", settings.get("proxyBaseUrl")); JSONObject contact = settings.getJSONObject("contact"); assertEquals("Claudius Ptolomaeus", contact.get("contactPerson")); assertEquals("The ancient geographes INC", contact.get("contactOrganization")); assertEquals("Work", contact.get("addressType")); assertEquals("*****@*****.**", contact.get("contactEmail")); }
@Test public void testPostXML() throws Exception { String xml = "<transform>\n" + " <name>buildings</name>\n" + // " <sourceFormat>text/xml; subtype=gml/2.1.2</sourceFormat>\n" + // " <outputFormat>text/html</outputFormat>\n" + // " <fileExtension>html</fileExtension>\n" + // " <xslt>buildings.xslt</xslt>\n" + // " <featureType>\n" + // " <name>cite:Buildings</name>\n" + // " </featureType>\n" + "</transform>\n"; MockHttpServletResponse response = postAsServletResponse("rest/services/wfs/transforms", xml); assertEquals(201, response.getStatusCode()); assertNotNull(response.getHeader("Location")); assertTrue(response.getHeader("Location").endsWith("/rest/services/wfs/transforms/buildings")); TransformInfo info = repository.getTransformInfo("buildings"); assertNotNull(info); }
int postNewTaskAsMultiPartForm(int imp, String data) throws Exception { File dir = unpack(data); List<Part> parts = new ArrayList<Part>(); for (File f : dir.listFiles()) { parts.add(new FilePart(f.getName(), f)); } MultipartRequestEntity multipart = new MultipartRequestEntity( parts.toArray(new Part[parts.size()]), new PostMethod().getParams()); ByteArrayOutputStream bout = new ByteArrayOutputStream(); multipart.writeRequest(bout); MockHttpServletRequest req = createRequest("/rest/imports/" + imp + "/tasks"); req.setContentType(multipart.getContentType()); req.addHeader("Content-Type", multipart.getContentType()); req.setMethod("POST"); req.setBodyContent(bout.toByteArray()); MockHttpServletResponse resp = dispatch(req); assertEquals(201, resp.getStatusCode()); assertNotNull(resp.getHeader("Location")); assertTrue(resp.getHeader("Location").matches(".*/imports/" + imp + "/tasks/\\d")); assertEquals("application/json", resp.getContentType()); JSONObject json = (JSONObject) json(resp); JSONObject task = json.getJSONObject("task"); return task.getInt("id"); }
@Override public void executeCurrentTestLogic() throws Exception { servletTestModule.doGet(); MockHttpServletResponse response = webMockObjectFactory.getMockResponse(); int expectedStatusCode = this.getExpectedStatus(NO_STATUS_CODE); int actualStatusCode = response.getStatusCode(); if (expectedStatusCode != NO_STATUS_CODE) { Assert.assertEquals(expectedStatusCode, actualStatusCode); } Map<String, String> expectedHeaders = this.getExpectedHeaders(); for (String name : expectedHeaders.keySet()) { String value = expectedHeaders.get(name); Assert.assertEquals(value, response.getHeader(name)); } if (actualStatusCode != HttpServletResponse.SC_NOT_MODIFIED) { Assert.assertTrue(this.hasCorrectDateHeaders()); String actualOutput = servletTestModule.getOutput(); // !TODO for now hash is ignored bcoz it will differ based last modification time of the // resource // !TODO need to consider and test actual generated hash actualOutput = actualOutput.replaceAll("_wu_[0-9a-f]{32}\\.", "_wu_<ignore_hash>."); Assert.assertNotNull(actualOutput); String expectedOutput = this.getExpectedOutput(); Assert.assertEquals(expectedOutput.trim(), actualOutput.trim()); } }
@Test public void testPostAsXML() throws Exception { if (!RemoteOWSTestSupport.isRemoteWMSStatesAvailable(LOGGER)) { LOGGER.warning("Skipping layer posting test as remote server is not available"); return; } assertNull(catalog.getResourceByName("sf", "bugsites", WMSLayerInfo.class)); String xml = "<wmsLayer>" + "<name>bugsites</name>" + "<nativeName>og:bugsites</nativeName>" + "<srs>EPSG:4326</srs>" + "<nativeCRS>EPSG:4326</nativeCRS>" + "<store>demo</store>" + "</wmsLayer>"; MockHttpServletResponse response = postAsServletResponse("/rest/workspaces/sf/wmsstores/demo/wmslayers/", xml, "text/xml"); assertEquals(201, response.getStatusCode()); assertNotNull(response.getHeader("Location")); assertTrue( response .getHeader("Location") .endsWith("/workspaces/sf/wmsstores/demo/wmslayers/bugsites")); WMSLayerInfo layer = catalog.getResourceByName("sf", "bugsites", WMSLayerInfo.class); assertNotNull(layer.getNativeBoundingBox()); }
@Test public void testMissingGrandule() throws Exception { MockHttpServletResponse response = getAsServletResponse( "/rest/workspaces/wcs/coveragestores/watertemp/coverages/watertemp/index/granules/notThere.xml"); assertEquals(404, response.getStatusCode()); }
@Test public void testDeleteByFilter() throws Exception { Document dom = getAsDOM( "/rest/workspaces/wcs/coveragestores/watertemp/coverages/watertemp/index/granules.xml"); assertXpathEvaluatesTo("2", "count(//gf:watertemp)", dom); // print(dom); MockHttpServletResponse response = deleteAsServletResponse( "/rest/workspaces/wcs/coveragestores/watertemp/coverages" + "/watertemp/index/granules?filter=ingestion=2008-11-01T00:00:00Z"); assertEquals(200, response.getStatusCode()); // check it's gone from the index dom = getAsDOM( "/rest/workspaces/wcs/coveragestores/watertemp/coverages/watertemp/index/granules.xml"); // print(dom); assertXpathEvaluatesTo("1", "count(//gf:watertemp)", dom); assertXpathEvaluatesTo( "2008-10-31T00:00:00Z", "//gf:watertemp[gf:location = 'NCOM_wattemp_000_20081031T0000000_12.tiff']/gf:ingestion", dom); assertXpathEvaluatesTo( "0", "//gf:watertemp[gf:location = 'NCOM_wattemp_000_20081031T0000000_12.tiff']/gf:elevation", dom); }
@Test public void testPutAsJSON() throws Exception { String inputJson = "{'settings':{'workspace':{'name':'sf'}," + "'contact':{'addressCity':'Cairo','addressCountry':'Egypt','addressType':'Work'," + "'contactEmail':'*****@*****.**','contactOrganization':'The ancient geographes INC'," + "'contactPerson':'Claudius Ptolomaeus','contactPosition':'Chief geographer'}," + "'charset':'UTF-8','numDecimals':8,'onlineResource':'http://geoserver2.org'," + "'proxyBaseUrl':'http://proxy2.url','verbose':true,'verboseExceptions':'true'}}"; MockHttpServletResponse response = putAsServletResponse("/rest/workspaces/sf/settings", inputJson, "text/json"); assertEquals(200, response.getStatusCode()); JSON jsonMod = getAsJSON("/rest/workspaces/sf/settings.json"); JSONObject jsonObject = (JSONObject) jsonMod; assertNotNull(jsonObject); JSONObject settings = jsonObject.getJSONObject("settings"); assertNotNull(settings); JSONObject workspace = settings.getJSONObject("workspace"); assertNotNull(workspace); assertEquals("sf", workspace.get("name")); assertEquals("8", settings.get("numDecimals").toString().trim()); assertEquals("http://geoserver2.org", settings.get("onlineResource")); assertEquals("http://proxy2.url", settings.get("proxyBaseUrl")); assertEquals("true", settings.get("verbose").toString().trim()); assertEquals("true", settings.get("verboseExceptions").toString().trim()); JSONObject contact = settings.getJSONObject("contact"); assertNotNull(contact); assertEquals("Claudius Ptolomaeus", contact.get("contactPerson")); assertEquals("Cairo", contact.get("addressCity")); }
@Test public void testPostAsJSON() throws Exception { if (!RemoteOWSTestSupport.isRemoteWMSStatesAvailable(LOGGER)) { LOGGER.warning("Skipping layer posting test as remote server is not available"); return; } assertNull(catalog.getResourceByName("sf", "bugsites", WMSLayerInfo.class)); String json = "{" + "'wmsLayer':{" + "'name':'bugsites'," + "'nativeName':'og:bugsites'," + "'srs':'EPSG:4326'," + "'nativeCRS':'EPSG:4326'," + "'store':'demo'" + "}" + "}"; MockHttpServletResponse response = postAsServletResponse("/rest/workspaces/sf/wmsstores/demo/wmslayers/", json, "text/json"); assertEquals(201, response.getStatusCode()); assertNotNull(response.getHeader("Location")); assertTrue( response .getHeader("Location") .endsWith("/workspaces/sf/wmsstores/demo/wmslayers/bugsites")); WMSLayerInfo layer = catalog.getResourceByName("sf", "bugsites", WMSLayerInfo.class); assertNotNull(layer.getNativeBoundingBox()); }
@Test public void testUploadImageMosaic() throws Exception { URL zip = MockData.class.getResource("watertemp.zip"); InputStream is = null; byte[] bytes; try { is = zip.openStream(); bytes = IOUtils.toByteArray(is); } finally { IOUtils.closeQuietly(is); } MockHttpServletResponse response = putAsServletResponse( "/rest/workspaces/gs/coveragestores/watertemp/file.imagemosaic", bytes, "application/zip"); assertEquals(201, response.getStatusCode()); // check the response contents String content = response.getOutputStreamContent(); Document d = dom(new ByteArrayInputStream(content.getBytes())); XMLAssert.assertXpathEvaluatesTo("watertemp", "//coverageStore/name", d); XMLAssert.assertXpathEvaluatesTo("ImageMosaic", "//coverageStore/type", d); // check the coverage is actually there CoverageStoreInfo storeInfo = getCatalog().getCoverageStoreByName("watertemp"); assertNotNull(storeInfo); CoverageInfo ci = getCatalog().getCoverageByName("watertemp"); assertNotNull(ci); assertEquals(storeInfo, ci.getStore()); }
int putNewTask(int imp, String data) throws Exception { File zip = getTestDataFile(data); byte[] payload = new byte[(int) zip.length()]; FileInputStream fis = new FileInputStream(zip); fis.read(payload); fis.close(); MockHttpServletRequest req = createRequest("/rest/imports/" + imp + "/tasks/" + new File(data).getName()); req.setHeader("Content-Type", MediaType.APPLICATION_ZIP.toString()); req.setMethod("PUT"); req.setBodyContent(payload); MockHttpServletResponse resp = dispatch(req); assertEquals(201, resp.getStatusCode()); assertNotNull(resp.getHeader("Location")); assertTrue(resp.getHeader("Location").matches(".*/imports/" + imp + "/tasks/\\d")); assertEquals("application/json", resp.getContentType()); JSONObject json = (JSONObject) json(resp); JSONObject task = json.getJSONObject("task"); return task.getInt("id"); }
@Test public void testPutNonExistant() throws Exception { String xml = "<wmsLayer>" + "<title>new title</title>" + "</wmsLayer>"; MockHttpServletResponse response = putAsServletResponse( "/rest/workspaces/sf/wmsstores/demo/wmslayers/bugsites", xml, "text/xml"); assertEquals(404, response.getStatusCode()); }
void putItem(int imp, int task, int item, String json) throws Exception { MockHttpServletResponse resp = putAsServletResponse( String.format("/rest/imports/%d/tasks/%d/items/%d", imp, task, item), json, "application/json"); assertEquals(200, resp.getStatusCode()); }
@Test public void testPostToResource() throws Exception { String xml = "<wmsLayer>" + "<name>og:restricted</name>" + "</wmsLayer>"; MockHttpServletResponse response = postAsServletResponse( "/rest/workspaces/sf/wmsstores/demo/wmslayers/states", xml, "text/xml"); assertEquals(405, response.getStatusCode()); }
@Test public void testDelete() throws Exception { MockHttpServletResponse response = deleteAsServletResponse("rest/services/wfs/transforms/general"); assertEquals(200, response.getStatusCode()); TransformInfo info = repository.getTransformInfo("general"); assertNull(info); }
@Test public void testHarvestMulti() throws Exception { for (File file : movedFiles) { File target = new File(mosaic, file.getName()); assertTrue(file.renameTo(target)); } // re-harvest the entire mosaic (two files refreshed, two files added) URL url = DataUtilities.fileToURL(mosaic.getCanonicalFile()); String body = url.toExternalForm(); MockHttpServletResponse response = postAsServletResponse( "/rest/workspaces/wcs/coveragestores/watertemp/external.imagemosaic", body, "text/plain"); assertEquals(202, response.getStatusCode()); Document dom = getAsDOM( "/rest/workspaces/wcs/coveragestores/watertemp/coverages/watertemp/index/granules.xml"); // print(dom); assertXpathEvaluatesTo("4", "count(//gf:watertemp)", dom); assertXpathEvaluatesTo( "2008-10-31T00:00:00Z", "//gf:watertemp[gf:location = 'NCOM_wattemp_000_20081031T0000000_12.tiff']/gf:ingestion", dom); assertXpathEvaluatesTo( "0", "//gf:watertemp[gf:location = 'NCOM_wattemp_000_20081031T0000000_12.tiff']/gf:elevation", dom); assertXpathEvaluatesTo( "2008-11-01T00:00:00Z", "//gf:watertemp[gf:location = 'NCOM_wattemp_000_20081101T0000000_12.tiff']/gf:ingestion", dom); assertXpathEvaluatesTo( "0", "//gf:watertemp[gf:location = 'NCOM_wattemp_000_20081101T0000000_12.tiff']/gf:elevation", dom); assertXpathEvaluatesTo( "2008-10-31T00:00:00Z", "//gf:watertemp[gf:location = 'NCOM_wattemp_100_20081031T0000000_12.tiff']/gf:ingestion", dom); assertXpathEvaluatesTo( "100", "//gf:watertemp[gf:location = 'NCOM_wattemp_100_20081031T0000000_12.tiff']/gf:elevation", dom); assertXpathEvaluatesTo( "2008-11-01T00:00:00Z", "//gf:watertemp[gf:location = 'NCOM_wattemp_100_20081101T0000000_12.tiff']/gf:ingestion", dom); assertXpathEvaluatesTo( "100", "//gf:watertemp[gf:location = 'NCOM_wattemp_100_20081101T0000000_12.tiff']/gf:elevation", dom); }
@Test public void testGetWrongWMSLayer() throws Exception { // Parameters for the request String ws = "sf"; String wms = "demo"; String wl = "statessssss"; // Request path String requestPath = "/rest/workspaces/" + ws + "/wmslayers/" + wl + ".html"; String requestPath2 = "/rest/workspaces/" + ws + "/wmsstores/" + wms + "/wmslayers/" + wl + ".html"; // Exception path String exception = "No such cascaded wms: " + ws + "," + wl; String exception2 = "No such cascaded wms layer: " + ws + "," + wms + "," + wl; // CASE 1: No wmsstore set // First request should thrown an exception MockHttpServletResponse response = getAsServletResponse(requestPath); assertEquals(404, response.getStatusCode()); assertTrue(response.getOutputStreamContent().contains(exception)); // Same request with ?quietOnNotFound should not throw an exception response = getAsServletResponse(requestPath + "?quietOnNotFound=true"); assertEquals(404, response.getStatusCode()); assertFalse(response.getOutputStreamContent().contains(exception)); // No exception thrown assertTrue(response.getOutputStreamContent().isEmpty()); // CASE 2: wmsstore set // First request should thrown an exception response = getAsServletResponse(requestPath2); assertEquals(404, response.getStatusCode()); assertTrue(response.getOutputStreamContent().contains(exception2)); // Same request with ?quietOnNotFound should not throw an exception response = getAsServletResponse(requestPath2 + "?quietOnNotFound=true"); assertEquals(404, response.getStatusCode()); assertFalse(response.getOutputStreamContent().contains(exception2)); // No exception thrown assertTrue(response.getOutputStreamContent().isEmpty()); }
int postNewImport() throws Exception { MockHttpServletResponse resp = postAsServletResponse("/rest/imports", ""); assertEquals(201, resp.getStatusCode()); assertNotNull(resp.getHeader("Location")); assertTrue(resp.getHeader("Location").matches(".*/imports/\\d")); assertEquals("application/json", resp.getContentType()); JSONObject json = (JSONObject) json(resp); JSONObject imprt = json.getJSONObject("import"); return imprt.getInt("id"); }
@Test public void testPut() throws Exception { String xml = "<wmsLayer>" + "<title>Lots of states here</title>" + "</wmsLayer>"; MockHttpServletResponse response = putAsServletResponse( "/rest/workspaces/sf/wmsstores/demo/wmslayers/states", xml, "text/xml"); assertEquals(200, response.getStatusCode()); Document dom = getAsDOM("/rest/workspaces/sf/wmsstores/demo/wmslayers/states.xml"); assertXpathEvaluatesTo("Lots of states here", "/wmsLayer/title", dom); WMSLayerInfo wli = catalog.getResourceByName("sf", "states", WMSLayerInfo.class); assertEquals("Lots of states here", wli.getTitle()); }
@Test public void testPutXML() throws Exception { // let's change the output format String xml = "<transform>\n" + " <sourceFormat>text/xml; subtype=gml/2.1.2</sourceFormat>\n" + " <outputFormat>text/html</outputFormat>\n" + " <fileExtension>html</fileExtension>\n" + " <xslt>general.xslt</xslt>\n" + "</transform>"; MockHttpServletResponse response = putAsServletResponse("rest/services/wfs/transforms/general", xml, "text/xml"); assertEquals(200, response.getStatusCode()); TransformInfo info = repository.getTransformInfo("general"); assertEquals("text/html", info.getOutputFormat()); }
@Test public void testDeleteAllGranules() throws Exception { Document dom = getAsDOM( "/rest/workspaces/wcs/coveragestores/watertemp/coverages/watertemp/index/granules.xml"); assertXpathEvaluatesTo("2", "count(//gf:watertemp)", dom); // print(dom); MockHttpServletResponse response = deleteAsServletResponse( "/rest/workspaces/wcs/coveragestores/watertemp/coverages/watertemp/index/granules"); assertEquals(200, response.getStatusCode()); // check it's gone from the index dom = getAsDOM( "/rest/workspaces/wcs/coveragestores/watertemp/coverages/watertemp/index/granules.xml"); assertXpathEvaluatesTo("0", "count(//gf:watertemp)", dom); }
@Test public void testWorldImageUploadZipped() throws Exception { URL zip = getClass().getResource("test-data/usa.zip"); byte[] bytes = FileUtils.readFileToByteArray(DataUtilities.urlToFile(zip)); MockHttpServletResponse response = putAsServletResponse( "/rest/workspaces/sf/coveragestores/usa/file.worldimage", bytes, "application/zip"); assertEquals(201, response.getStatusCode()); String content = response.getOutputStreamContent(); Document d = dom(new ByteArrayInputStream(content.getBytes())); assertEquals("coverageStore", d.getDocumentElement().getNodeName()); CoverageStoreInfo cs = getCatalog().getCoverageStoreByName("sf", "usa"); assertNotNull(cs); CoverageInfo ci = getCatalog().getCoverageByName("sf", "usa"); assertNotNull(ci); }
@Test public void testCreateAsXML() throws Exception { GeoServer geoServer = getGeoServer(); geoServer.remove(geoServer.getSettings(geoServer.getCatalog().getWorkspaceByName("sf"))); String xml = "<settings>" + "<workspace><name>sf</name></workspace>" + "<contact>" + "<addressCity>Alexandria</addressCity>" + "<addressCountry>Egypt</addressCountry>" + "<addressType>Work</addressType>" + "<contactEmail>[email protected]</contactEmail>" + "<contactOrganization>The ancient geographes INC</contactOrganization>" + "<contactPerson>Claudius Ptolomaeus</contactPerson>" + "<contactPosition>Chief geographer</contactPosition>" + "</contact>" + "<charset>UTF-8</charset>" + "<numDecimals>8</numDecimals>" + "<onlineResource>http://geoserver.org</onlineResource>" + "<proxyBaseUrl>http://proxy.url</proxyBaseUrl>" + "<verbose>false</verbose>" + "<verboseExceptions>false</verboseExceptions>" + "</settings>"; MockHttpServletResponse response = putAsServletResponse("/rest/workspaces/sf/settings", xml, "text/xml"); assertEquals(200, response.getStatusCode()); Document dom = getAsDOM("/rest/workspaces/sf/settings.xml"); assertEquals("settings", dom.getDocumentElement().getLocalName()); assertXpathEvaluatesTo("sf", "/settings/workspace/name", dom); assertXpathEvaluatesTo("false", "/settings/verbose", dom); assertXpathEvaluatesTo("false", "/settings/verboseExceptions", dom); assertXpathEvaluatesTo("http://geoserver.org", "/settings/onlineResource", dom); assertXpathEvaluatesTo("http://proxy.url", "/settings/proxyBaseUrl", dom); assertXpathEvaluatesTo("Claudius Ptolomaeus", "/settings/contact/contactPerson", dom); assertXpathEvaluatesTo("*****@*****.**", "/settings/contact/contactEmail", dom); assertXpathEvaluatesTo("Chief geographer", "/settings/contact/contactPosition", dom); assertXpathEvaluatesTo( "The ancient geographes INC", "/settings/contact/contactOrganization", dom); assertXpathEvaluatesTo("Egypt", "/settings/contact/addressCountry", dom); }
@Test public void testPutXSLT() throws Exception { String xslt = FileUtils.readFileToString( new File("src/test/resources/org/geoserver/wfs/xslt/general2.xslt")); MockHttpServletResponse response = putAsServletResponse("rest/services/wfs/transforms/general", xslt, "application/xslt+xml"); assertEquals(200, response.getStatusCode()); TransformInfo info = repository.getTransformInfo("general"); InputStream is = null; String actual = null; try { is = repository.getTransformSheet(info); actual = IOUtils.toString(is); } finally { IOUtils.closeQuietly(is); } assertEquals(xslt, actual); }
@Test public void testDeleteSingleGranule() throws Exception { Document dom = getAsDOM( "/rest/workspaces/wcs/coveragestores/watertemp/coverages/watertemp/index/granules.xml"); // print(dom); // get the granule ids String octoberId = xpath.evaluate( "//gf:watertemp[gf:location = 'NCOM_wattemp_000_20081031T0000000_12.tiff']/@fid", dom); assertNotNull(octoberId); // delete it MockHttpServletResponse response = deleteAsServletResponse( "/rest/workspaces/wcs/coveragestores/watertemp/coverages/watertemp/index/granules/" + octoberId); assertEquals(200, response.getStatusCode()); // check it's gone from the index dom = getAsDOM( "/rest/workspaces/wcs/coveragestores/watertemp/coverages/watertemp/index/granules.xml"); assertXpathEvaluatesTo("1", "count(//gf:watertemp)", dom); assertXpathEvaluatesTo( "0", "count(//gf:watertemp[gf:location = 'NCOM_wattemp_000_20081031T0000000_12.tiff'])", dom); assertXpathEvaluatesTo( "2008-11-01T00:00:00Z", "//gf:watertemp[gf:location = 'NCOM_wattemp_000_20081101T0000000_12.tiff']/gf:ingestion", dom); assertXpathEvaluatesTo( "0", "//gf:watertemp[gf:location = 'NCOM_wattemp_000_20081101T0000000_12.tiff']/gf:elevation", dom); }
@Test public void testHarvestSingle() throws Exception { File file = movedFiles.get(0); File target = new File(mosaic, file.getName()); assertTrue(file.renameTo(target)); URL url = DataUtilities.fileToURL(target.getCanonicalFile()); String body = url.toExternalForm(); MockHttpServletResponse response = postAsServletResponse( "/rest/workspaces/wcs/coveragestores/watertemp/external.imagemosaic", body, "text/plain"); assertEquals(202, response.getStatusCode()); Document dom = getAsDOM( "/rest/workspaces/wcs/coveragestores/watertemp/coverages/watertemp/index/granules.xml"); // print(dom); assertXpathEvaluatesTo("3", "count(//gf:watertemp)", dom); assertXpathEvaluatesTo( "1", "count(//gf:watertemp[gf:location = '" + file.getName() + "'])", dom); }
void postImport(int imp) throws Exception { MockHttpServletResponse resp = postAsServletResponse("/rest/imports/" + imp, ""); assertEquals(204, resp.getStatusCode()); }
@Test public void testHarvestImageMosaicWithDirectory() throws Exception { // Upload of the Mosaic via REST URL zip = MockData.class.getResource("watertemp.zip"); InputStream is = null; byte[] bytes; try { is = zip.openStream(); bytes = IOUtils.toByteArray(is); } finally { IOUtils.closeQuietly(is); } MockHttpServletResponse response = putAsServletResponse( "/rest/workspaces/gs/coveragestores/watertemp3/file.imagemosaic", bytes, "application/zip"); assertEquals(201, response.getStatusCode()); // check the response contents String content = response.getOutputStreamContent(); Document d = dom(new ByteArrayInputStream(content.getBytes())); XMLAssert.assertXpathEvaluatesTo("watertemp3", "//coverageStore/name", d); XMLAssert.assertXpathEvaluatesTo("ImageMosaic", "//coverageStore/type", d); // check the coverage is actually there CoverageStoreInfo storeInfo = getCatalog().getCoverageStoreByName("watertemp3"); assertNotNull(storeInfo); CoverageInfo ci = getCatalog().getCoverageByName("watertemp3"); assertNotNull(ci); assertEquals(storeInfo, ci.getStore()); // Harvesting of the Mosaic URL zipHarvest = getClass().getResource("test-data/harvesting.zip"); File zipFile = DataUtilities.urlToFile(zipHarvest); // Creation of another zip file which is a copy of the one before File newZip = new File(zipFile.getParentFile(), "harvesting2.zip"); // Copy the content of the first zip to the second FileUtils.copyFile(zipFile, newZip); File outputDirectory = new File(zipFile.getParentFile(), "harvesting"); outputDirectory.mkdir(); RESTUtils.unzipFile(newZip, outputDirectory); // Create the POST request MockHttpServletRequest request = createRequest("/rest/workspaces/gs/coveragestores/watertemp3/external.imagemosaic"); request.setMethod("POST"); request.setContentType("text/plain"); request.setBodyContent("file:///" + outputDirectory.getAbsolutePath()); request.setHeader("Content-type", "text/plain"); // Get The response response = dispatch(request); // Get the Mosaic Reader GridCoverageReader reader = storeInfo.getGridCoverageReader(null, GeoTools.getDefaultHints()); // Test if all the TIME DOMAINS are present String[] metadataNames = reader.getMetadataNames(); assertNotNull(metadataNames); assertEquals("true", reader.getMetadataValue("HAS_TIME_DOMAIN")); assertEquals( "2008-10-31T00:00:00.000Z,2008-11-01T00:00:00.000Z,2008-11-02T00:00:00.000Z", reader.getMetadataValue(metadataNames[0])); // Removal of the temporary directory FileUtils.deleteDirectory(outputDirectory); }