Пример #1
0
  private BoundWcsRequest negotiateResponseCRS(BoundWcsRequest request) throws IOException {

    Set<String> crss = request.getSupportedResponseCRSs();
    // Hack. It will work so long as backing servers
    // are GeoServers
    if (crss.isEmpty() && request.getNativeCRSs().isEmpty()) return request;
    if (!crss.contains(request.getResponseEpsgCode())) {
      String newCrs = "EPSG:4326";
      if (request.getNativeCRSs().isEmpty()) {
        Iterator<String> crsIter = crss.iterator();
        if (!crss.contains(newCrs) && crsIter.hasNext()) {
          newCrs = crsIter.next();
        } else {

        }
      } else {
        newCrs = request.getNativeCRSs().iterator().next();
      }
      return request.withCRS(newCrs);
    }
    return request;
  }
  @Test
  public void BoundWcsRequestTest() throws Throwable {
    WcsReaderRequest rq =
        new WcsReaderRequestFactory()
            .create(
                "1.0",
                "myCov",
                0,
                0,
                1,
                1,
                CRS.decode("EPSG:4326"),
                CRS.decode("EPSG:2154"),
                1,
                "GeoTiff",
                true,
                true,
                true,
                "scott",
                "tiger");

    BoundWcsRequest bwr = new BoundWcsRequest(new URL("http://localhost/"), rq);

    HttpClient mockClient = getMockHttpClient();
    bwr.setHttpClient(mockClient);

    // DescribeCoverage related tests
    setOutputDocument(describeCoverageSample);
    bwr.getCoverage();

    // supported formats
    Set<String> fmts = bwr.getSupportedFormats();
    String[] expectedFmts = {"jpg", "geotiff", "tif", "jpeg", "png", "gif", "tiff"};
    assertArrayEquals(expectedFmts, fmts.toArray());

    // supported response CRS
    Set<String> supportedResponseCrs = bwr.getSupportedResponseCRSs();
    String[] expectedResponseCrs = {"EPSG:4326"};
    assertArrayEquals(expectedResponseCrs, supportedResponseCrs.toArray());

    // num bands
    int numBands = bwr.numBands();
    assertEquals(numBands, 1);

    // supported request CRS
    Set<String> supportedRequestCrs = bwr.getSupportedRequestCRSs();
    String[] expectedRequestCrs = {"EPSG:4326"};
    assertArrayEquals(expectedRequestCrs, supportedRequestCrs.toArray());

    // Native CRS
    Set<String> nativeCRSs = bwr.getNativeCRSs();
    String[] expectedNativeCRSs = {"EPSG:4326"};
    assertArrayEquals(expectedNativeCRSs, nativeCRSs.toArray());

    // just to recall getDescribeCoverage(), should be defined as for now
    assertTrue(bwr.getDescribeCoverage() instanceof String);

    // Same
    assertTrue(bwr.getSupportedFormats() instanceof Set<?>);
    assertTrue(bwr.getSupportedResponseCRSs() instanceof Set<?>);
    assertTrue(bwr.numBands() == 1);
    assertTrue(bwr.getSupportedRequestCRSs() instanceof Set<?>);
    assertTrue(bwr.getNativeCRSs() instanceof Set<?>);

    // GetCapabilities related tests
    setOutputDocument(getCapabilitiesSample);

    String getCap = bwr.getCapabilities();
    assertTrue(getCap instanceof String);
    // another time
    assertTrue(bwr.getCapabilities() instanceof String);
  }