Ejemplo n.º 1
0
  private BoundWcsRequest negotiateFormat(BoundWcsRequest request) throws IOException {
    final Set<String> formats = request.getSupportedFormats();
    if (formats.isEmpty()) return request;
    if (!formats.contains(request.format)) {
      for (String format : Formats.preferredFormats) {
        if (formats.contains(format)) return request.withFormat(format);
      }

      // Note: If none of the preferred formats are offered by server
      // then we download a format and see if we can convert it to the
      // desired format
      return request.withFormat(formats.iterator().next());
    }
    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);
  }