Esempio n. 1
0
 @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"));
 }
Esempio n. 2
0
  @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);
  }
Esempio n. 3
0
  @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 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());
  }
Esempio n. 5
0
  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");
  }
Esempio n. 6
0
  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");
  }
Esempio n. 7
0
  @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());
  }
Esempio n. 8
0
  @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 testMissingGrandule() throws Exception {
   MockHttpServletResponse response =
       getAsServletResponse(
           "/rest/workspaces/wcs/coveragestores/watertemp/coverages/watertemp/index/granules/notThere.xml");
   assertEquals(404, response.getStatusCode());
 }
Esempio n. 10
0
  @Test
  public void testElevationSecond() throws Exception {
    String request = getWaterTempElevationRequest("100.0");

    MockHttpServletResponse response = postAsServletResponse("wcs", request);
    assertEquals("image/tiff", response.getContentType());

    // save
    File tiffFile = File.createTempFile("wcs", "", new File("target"));
    IOUtils.copy(getBinaryInputStream(response), new FileOutputStream(tiffFile));

    // make sure we can read the coverage back
    GeoTiffReader reader = new GeoTiffReader(tiffFile);
    GridCoverage2D result = reader.read(null);

    /*
     gdallocationinfo NCOM_wattemp_100_20081101T0000000_12.tiff  10 10
     Report:
      Location: (10P,10L)
      Band 1:
      Value: 13.337999683572
    */

    // check a pixel
    double[] pixel = new double[1];
    result.getRenderedImage().getData().getPixel(10, 10, pixel);
    assertEquals(13.337999683572, pixel[0], 1e-6);

    tiffFile.delete();
  }
Esempio n. 11
0
  @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 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);
  }
Esempio n. 13
0
  public void testPlainAddition() throws Exception { // Standard Test A.4.4.3
    String xml =
        "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>\r\n"
            + "<wps:Execute service=\"WPS\" version=\"1.0.0\"\r\n"
            + "        xmlns:wps=\"http://www.opengis.net/wps/1.0.0\" xmlns:ows=\"http://www.opengis.net/ows/1.1\"\r\n"
            + "        xmlns:xlink=\"http://www.w3.org/1999/xlink\">\r\n"
            + "        <ows:Identifier>gt:DoubleAddition</ows:Identifier>\r\n"
            + "        <wps:DataInputs>\r\n"
            + "                <wps:Input>\r\n"
            + "                        <ows:Identifier>input_a</ows:Identifier>\r\n"
            + "                        <wps:Data>\r\n"
            + "                                <wps:LiteralData>7</wps:LiteralData>\r\n"
            + "                        </wps:Data>\r\n"
            + "                </wps:Input>\r\n"
            + "                <wps:Input>\r\n"
            + "                        <ows:Identifier>input_b</ows:Identifier>\r\n"
            + "                        <wps:Data>\r\n"
            + "                                <wps:LiteralData>7</wps:LiteralData>\r\n"
            + "                        </wps:Data>\r\n"
            + "                </wps:Input>\r\n"
            + "        </wps:DataInputs>\r\n"
            + "        <wps:ResponseForm>\r\n"
            + "                <wps:RawDataOutput>\r\n"
            + "                        <ows:Identifier>result</ows:Identifier>\r\n"
            + "                </wps:RawDataOutput>\r\n"
            + "        </wps:ResponseForm>\r\n"
            + "</wps:Execute>";

    MockHttpServletResponse response = postAsServletResponse(root(), xml);
    assertEquals("text/plain", response.getContentType());
    assertEquals("14.0", response.getOutputStreamContent());
  }
Esempio n. 14
0
  public void testShapeZip() throws Exception {
    String xml =
        "<wps:Execute service='WPS' version='1.0.0' xmlns:xlink=\"http://www.w3.org/1999/xlink\" "
            + "xmlns:wps='http://www.opengis.net/wps/1.0.0' xmlns:wfs='http://www.opengis.net/wfs' "
            + "xmlns:ows='http://www.opengis.net/ows/1.1'>"
            + "<ows:Identifier>gt:BufferFeatureCollection</ows:Identifier>"
            + "<wps:DataInputs>"
            + "    <wps:Input>\n"
            + "<ows:Identifier>features</ows:Identifier>"
            + "<wps:Data>"
            + "<wps:ComplexData>"
            + readFileIntoString("states-FeatureCollection.xml")
            + "</wps:ComplexData>"
            + "</wps:Data>"
            + "</wps:Input>"
            + "<wps:Input>"
            + "<ows:Identifier>buffer</ows:Identifier>"
            + "<wps:Data>"
            + "<wps:LiteralData>10</wps:LiteralData>"
            + "</wps:Data>"
            + "</wps:Input>"
            + "</wps:DataInputs>"
            + "<wps:ResponseForm>"
            + "<wps:RawDataOutput mimeType=\"application/zip\">"
            + "<ows:Identifier>result</ows:Identifier>"
            + "</wps:RawDataOutput>"
            + "</wps:ResponseForm>"
            + "</wps:Execute>";

    MockHttpServletResponse r = postAsServletResponse("wps", xml);
    assertEquals("application/zip", r.getContentType());
    checkShapefileIntegrity(new String[] {"states"}, getBinaryInputStream(r));
  }
Esempio n. 15
0
  public void testInlineGeoJSON() throws Exception {
    String xml =
        "<wps:Execute service='WPS' version='1.0.0' xmlns:wps='http://www.opengis.net/wps/1.0.0' "
            + "xmlns:ows='http://www.opengis.net/ows/1.1'>"
            + "<ows:Identifier>gt:BufferFeatureCollection</ows:Identifier>"
            + "<wps:DataInputs>"
            + "<wps:Input>"
            + "<ows:Identifier>features</ows:Identifier>"
            + "<wps:Data>"
            + "<wps:ComplexData mimeType=\"application/json\"><![CDATA["
            + readFileIntoString("states-FeatureCollection.json")
            + "]]></wps:ComplexData>"
            + "</wps:Data>"
            + "</wps:Input>"
            + "<wps:Input>"
            + "<ows:Identifier>buffer</ows:Identifier>"
            + "<wps:Data>"
            + "<wps:LiteralData>10</wps:LiteralData>"
            + "</wps:Data>"
            + "</wps:Input>"
            + "</wps:DataInputs>"
            + "<wps:ResponseForm>"
            + "<wps:RawDataOutput mimeType=\"application/json\">"
            + "<ows:Identifier>result</ows:Identifier>"
            + "</wps:RawDataOutput>"
            + "</wps:ResponseForm>"
            + "</wps:Execute>";

    MockHttpServletResponse r = postAsServletResponse("wps", xml);
    assertEquals("application/json", r.getContentType());
    // System.out.println(r.getOutputStreamContent());
    FeatureCollection fc = new FeatureJSON().readFeatureCollection(r.getOutputStreamContent());
    assertEquals(2, fc.size());
  }
  @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 the content disposition
  *
  * @throws Exception
  */
 public void testContentDisposition() throws Exception {
   MockHttpServletResponse resp =
       getAsServletResponse("wfs?request=GetFeature&typeName=Points&outputFormat=spatialite");
   String featureName = "Points";
   assertEquals(
       "attachment; filename=" + featureName + ".sqlite", resp.getHeader("Content-Disposition"));
 }
Esempio n. 18
0
 @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());
 }
Esempio n. 19
0
 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());
 }
Esempio n. 20
0
  @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);
  }
Esempio n. 21
0
  @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());
  }
Esempio n. 22
0
  @Test
  public void testElevationFirst() throws Exception {
    String request = getWaterTempElevationRequest("0.0");

    MockHttpServletResponse response = postAsServletResponse("wcs", request);
    assertEquals("image/tiff", response.getContentType());

    // same result as time first
    checkTimeCurrent(response);
  }
  @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);
  }
Esempio n. 24
0
  public void testPlainAdditionKVP() throws Exception { // Standard Test A.4.4.3
    String request =
        "wps?service=WPS&version=1.0.0&request=Execute&Identifier=gt:DoubleAddition"
            + "&DataInputs="
            + urlEncode("input_a=7;input_b=7")
            + "&RawDataOutput=result";

    MockHttpServletResponse response = getAsServletResponse(request);
    assertEquals("text/plain", response.getContentType());
    assertEquals("14.0", response.getOutputStreamContent());
  }
Esempio n. 25
0
  /**
   * Tests mixed get/post situations for cases in which there is no kvp parser
   *
   * @throws Exception
   */
  public void testHelloOperationMixed() throws Exception {
    URL url = getClass().getResource("applicationContextOnlyXml.xml");

    FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext(url.toString());

    Dispatcher dispatcher = (Dispatcher) context.getBean("dispatcher");

    final String body = "<Hello service=\"hello\" message=\"Hello world!\" version=\"1.0.0\" />";

    MockHttpServletRequest request =
        new MockHttpServletRequest() {
          String encoding;

          public int getServerPort() {
            return 8080;
          }

          public String getCharacterEncoding() {
            return encoding;
          }

          public void setCharacterEncoding(String encoding) {
            this.encoding = encoding;
          }

          public ServletInputStream getInputStream() throws IOException {
            final ServletInputStream stream = super.getInputStream();
            return new ServletInputStream() {
              public int read() throws IOException {
                return stream.read();
              }

              public int available() {
                return body.length();
              }
            };
          }
        };

    request.setScheme("http");
    request.setServerName("localhost");
    request.setContextPath("/geoserver");
    request.setMethod("POST");
    request.setRequestURI("http://localhost/geoserver/ows");
    request.setContentType("application/xml");
    request.setBodyContent(body);

    MockHttpServletResponse response = new MockHttpServletResponse();

    request.setupAddParameter("strict", "true");

    dispatcher.handleRequest(request, response);
    assertEquals("Hello world!", response.getOutputStreamContent());
  }
Esempio n. 26
0
  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 basic extension functionality: mime/type, headers, not empty output generation.
  *
  * @param resp
  * @param featureName
  * @return sResponse
  * @throws Exception
  */
 public ByteArrayInputStream testBasicResult(MockHttpServletResponse resp, String featureName)
     throws Exception {
   // check mime type
   assertEquals("application/x-sqlite3", resp.getContentType());
   // check the content disposition
   assertEquals(
       "attachment; filename=" + featureName + ".sqlite", resp.getHeader("Content-Disposition"));
   ByteArrayInputStream sResponse = getBinaryInputStream(resp);
   // check for content (without checking in detail)
   assertNotNull(sResponse);
   return sResponse;
 }
Esempio n. 28
0
  /**
   * Checks the bounds process returned the expected envelope
   *
   * @param request
   * @param id
   * @throws Exception
   */
  void executeState1BoundsTest(String request, String id) throws Exception {
    if (!RemoteOWSTestSupport.isRemoteWMSStatesAvailable(LOGGER)) {
      LOGGER.warning("Remote OWS tests disabled, skipping test with " + id + " reference source");
      return;
    }

    MockHttpServletResponse resp = postAsServletResponse(root(), request);
    ReferencedEnvelope re = toEnvelope(resp.getOutputStreamContent());
    assertEquals(-91.516129, re.getMinX(), 0.001);
    assertEquals(36.986771, re.getMinY(), 0.001);
    assertEquals(-87.507889, re.getMaxX(), 0.001);
    assertEquals(42.509361, re.getMaxY(), 0.001);
  }
Esempio n. 29
0
  @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());
  }
Esempio n. 30
0
 public void testWKTInlineKVPRawOutput() throws Exception {
   String request =
       "wps?service=WPS&version=1.0.0&request=Execute&Identifier=gt:buffer"
           + "&DataInputs="
           + urlEncode(
               "geom1=POLYGON((1 1, 2 1, 2 2, 1 2, 1 1))@mimetype=application/wkt;buffer=1")
           + "&RawDataOutput="
           + urlEncode("result=@mimetype=application/wkt");
   MockHttpServletResponse response = getAsServletResponse(request);
   // System.out.println(response.getOutputStreamContent());
   assertEquals("application/wkt", response.getContentType());
   Geometry g = new WKTReader().read(response.getOutputStreamContent());
   assertTrue(g instanceof Polygon);
 }