public void testGridOffsets() throws Exception {
    Map<String, Object> raw = baseMap();

    final String layerId = getLayerId(TASMANIA_BM);
    raw.put("identifier", layerId);
    raw.put("format", "image/tiff");
    raw.put("BoundingBox", "-45,146,-42,147");

    raw.put("GridOffsets", "10.5,-30.2");
    raw.put("GridType", GridType.GT2dSimpleGrid.getXmlConstant());
    GetCoverageType getCoverage =
        (GetCoverageType) reader.read(reader.createRequest(), parseKvp(raw), raw);
    Double[] offsets = (Double[]) getCoverage.getOutput().getGridCRS().getGridOffsets();
    assertEquals(2, offsets.length);
    assertEquals(10.5, offsets[0]);
    assertEquals(-30.2, offsets[1]);

    raw.put("GridOffsets", "12");
    try {
      reader.read(reader.createRequest(), parseKvp(raw), raw);
      fail("We should have had a WcsException here?");
    } catch (WcsException e) {
      assertEquals(InvalidParameterValue.name(), e.getCode());
      assertEquals("GridOffsets", e.getLocator());
    }

    raw.put("GridOffsets", "12,a");
    try {
      reader.read(reader.createRequest(), parseKvp(raw), raw);
      fail("We should have had a WcsException here?");
    } catch (WcsException e) {
      assertEquals(InvalidParameterValue.name(), e.getCode());
      assertEquals("GridOffsets", e.getLocator());
    }
  }
  public void testGridCS() throws Exception {
    Map<String, Object> raw = baseMap();
    final String layerId = getLayerId(TASMANIA_BM);
    raw.put("identifier", layerId);
    raw.put("format", "image/tiff");
    raw.put("BoundingBox", "-45,146,-42,147");

    raw.put("GridCS", GridCS.GCSGrid2dSquare.getXmlConstant());
    GetCoverageType getCoverage =
        (GetCoverageType) reader.read(reader.createRequest(), parseKvp(raw), raw);
    assertEquals(
        GridCS.GCSGrid2dSquare.getXmlConstant(), getCoverage.getOutput().getGridCRS().getGridCS());

    raw.put("GridCS", GridCS.GCSGrid2dSquare.getXmlConstant().toUpperCase());
    getCoverage = (GetCoverageType) reader.read(reader.createRequest(), parseKvp(raw), raw);
    assertEquals(
        GridCS.GCSGrid2dSquare.getXmlConstant(), getCoverage.getOutput().getGridCRS().getGridCS());

    raw.put("GridCS", "Hoolabaloola");
    try {
      reader.read(reader.createRequest(), parseKvp(raw), raw);
      fail("We should have had a WcsException here?");
    } catch (WcsException e) {
      assertEquals(InvalidParameterValue.name(), e.getCode());
      assertEquals("GridCS", e.getLocator());
    }
  }
  @Test
  public void testWCS11GetCoverageDifferentCrs() throws Exception {
    net.opengis.wcs11.GetCoverageType gc = Wcs11Factory.eINSTANCE.createGetCoverageType();
    // xMin,yMin 5988504.35,851278.90 : xMax,yMax 7585113.55,1950872.01
    // xMin,yMin -95.1193,42.2802 : xMax,yMax -71.295,53.73

    CoordinateReferenceSystem logCrs = CRS.decode("EPSG:4326", false);
    BoundingBox bbox = new ReferencedEnvelope(42.2802, 53.73, -95.1193, -71.295, logCrs);
    net.opengis.ows11.BoundingBoxType wcsBbox =
        net.opengis.ows11.Ows11Factory.eINSTANCE.createBoundingBoxType();
    wcsBbox.setLowerCorner(Arrays.asList(5988504.35d, 851278.90d));
    wcsBbox.setUpperCorner(Arrays.asList(7585113.55d, 1950872.01d));
    wcsBbox.setCrs("urn:ogc:def:crs:EPSG:3348");
    net.opengis.wcs11.DomainSubsetType domainSubset =
        Wcs11Factory.eINSTANCE.createDomainSubsetType();
    domainSubset.setBoundingBox(wcsBbox);

    gc.setDomainSubset(domainSubset);

    CodeType c = Ows11Factory.eINSTANCE.createCodeType();
    c.setValue("acme:bar");
    gc.setIdentifier(c);

    callback.operationDispatched(new Request(), op("GetCoverage", "WCS", "1.1.0", gc));
    assertEquals("acme:bar", data.getResources().get(0));
    BBoxAsserts.assertEqualsBbox(bbox, data.getBbox(), 0.1);
  }
  @Test
  public void testWCS11GetCoverage() throws Exception {
    net.opengis.wcs11.GetCoverageType gc = Wcs11Factory.eINSTANCE.createGetCoverageType();

    CoordinateReferenceSystem crs = CRS.decode("EPSG:4326");
    GeneralEnvelope env =
        new GeneralEnvelope(new double[] {48.2, -123.4}, new double[] {50.1, -120.9});
    env.setCoordinateReferenceSystem(crs);
    BoundingBox bbox = new ReferencedEnvelope(env);
    net.opengis.ows11.BoundingBoxType wcsBbox =
        net.opengis.ows11.Ows11Factory.eINSTANCE.createBoundingBoxType();
    wcsBbox.setLowerCorner(Arrays.asList(48.2d, -123.4d));
    wcsBbox.setUpperCorner(Arrays.asList(50.1d, -120.9d));
    // wcsBbox.setCrs("urn:ogc:def:crs:OGC:1.3:CRS84");
    wcsBbox.setCrs("urn:ogc:def:crs:EPSG:4326");
    net.opengis.wcs11.DomainSubsetType domainSubset =
        Wcs11Factory.eINSTANCE.createDomainSubsetType();
    domainSubset.setBoundingBox(wcsBbox);

    gc.setDomainSubset(domainSubset);

    CodeType c = Ows11Factory.eINSTANCE.createCodeType();
    c.setValue("acme:bar");
    gc.setIdentifier(c);

    callback.operationDispatched(new Request(), op("GetCoverage", "WCS", "1.1.0", gc));
    assertEquals("acme:bar", data.getResources().get(0));
    BBoxAsserts.assertEqualsBbox(bbox, data.getBbox(), 0.1);
  }
  public void testBasic() throws Exception {
    Map<String, Object> raw = baseMap();
    final String layerId = getLayerId(TASMANIA_BM);
    raw.put("identifier", layerId);
    raw.put("format", "image/tiff");
    raw.put("BoundingBox", "-45,146,-42,147");
    raw.put("store", "false");
    raw.put("GridBaseCRS", "urn:ogc:def:crs:EPSG:6.6:4326");

    GetCoverageType getCoverage =
        (GetCoverageType) reader.read(reader.createRequest(), parseKvp(raw), raw);
    assertEquals(layerId, getCoverage.getIdentifier().getValue());
    assertEquals("image/tiff", getCoverage.getOutput().getFormat());
    assertFalse(getCoverage.getOutput().isStore());
    assertEquals(
        "urn:ogc:def:crs:EPSG:6.6:4326", getCoverage.getOutput().getGridCRS().getGridBaseCRS());
  }
  @Override
  protected void qualifyRequest(
      WorkspaceInfo ws, PublishedInfo l, Operation operation, Request request) {

    GetCapabilitiesType caps = parameter(operation, GetCapabilitiesType.class);
    if (caps != null) {
      return;
    }

    DescribeCoverageType dcov = parameter(operation, DescribeCoverageType.class);
    if (dcov != null) {
      qualifyLayerNames(dcov.getIdentifier(), ws);
      return;
    }

    GetCoverageType gcov = parameter(operation, GetCoverageType.class);
    if (gcov != null) {
      if (gcov.getIdentifier() != null && gcov.getIdentifier().getValue() != null) {
        gcov.getIdentifier().setValue(qualifyName(gcov.getIdentifier().getValue(), ws));
      }
    }
  }
  /**
   * Tests valid range subset expressions, but with a mix of valid and invalid identifiers
   *
   * @throws Exception
   */
  public void testRangeSubset() throws Exception {
    Map<String, Object> raw = baseMap();
    final String layerId = getLayerId(TASMANIA_BM);
    raw.put("identifier", layerId);
    raw.put("format", "image/tiff");
    raw.put("BoundingBox", "-45,146,-42,147");

    // ok, finally something we can parse
    raw.put("rangeSubset", "BlueMarble:nearest[Bands[Red_band]]");
    GetCoverageType getCoverage =
        (GetCoverageType) reader.read(reader.createRequest(), parseKvp(raw), raw);
    RangeSubsetType rs = getCoverage.getRangeSubset();
    assertNotNull(rs);
    assertEquals(1, rs.getFieldSubset().size());
    FieldSubsetType field = (FieldSubsetType) rs.getFieldSubset().get(0);
    assertEquals("BlueMarble", field.getIdentifier().getValue());
    assertEquals(1, field.getAxisSubset().size());
    AxisSubsetType axis = (AxisSubsetType) field.getAxisSubset().get(0);
    assertEquals("Bands", axis.getIdentifier());
    List keys = axis.getKey();
    assertEquals(1, keys.size());
    assertEquals("Red_band", keys.get(0));
  }