/**
   * reads a deegree WCS configuration file and performs a DescribeCoverage request Steps:
   *
   * <ul>
   *   <li>read configuration file
   *   <li>read a DescribeCoverage request object
   *   <li>perform the request
   * </ul>
   */
  public void _testDescribeCoverage() {
    try {
      WCSConfiguration configuration =
          WCSConfiguration.create(Configuration.getWCSConfigurationURL());
      WCService service = new WCService(configuration);

      Map<String, String> map = new HashMap<String, String>();
      map.put("SERVICE", "WCS");
      map.put("REQUEST", "DescribeCoverage");
      map.put("VERSION", "1.0.0");
      map.put("COVERAGE", "europe");

      // StringBuffer sb = new StringBuffer();
      // sb.append(Configuration.PROTOCOL + "://" + Configuration.HOST).append(':').append(
      // Configuration.PORT).append('/').append(Configuration.WCS_WEB_CONTEXT).append(
      // '/').append(Configuration.WCS_SERVLET).append("?service=WCS&").append(
      // "request=DescribeCoverage&version=1.0.0&coverage=europe");

      DescribeCoverage desc = DescribeCoverage.create(map);
      CoverageDescription o = (CoverageDescription) service.doService(desc);
      LOG.logInfo(Arrays.toString(o.getCoverageOfferings()));
    } catch (Exception e) {
      fail(StringTools.stackTraceToString(e));
    }
  }
  /**
   * reads a deegree WCS configuration file and performs a GetCoverage request Steps:
   *
   * <ul>
   *   <li>read configuration file
   *   <li>read a GetCoverage request object
   *   <li>perform the request
   * </ul>
   */
  public void _testGetCoverage1() {
    try {
      WCSConfiguration configuration =
          WCSConfiguration.create(Configuration.getWCSConfigurationURL());
      WCService service = new WCService(configuration);
      StringBuffer sb = new StringBuffer();
      sb.append(Configuration.PROTOCOL + "://" + Configuration.HOST)
          .append(':')
          .append(Configuration.PORT)
          .append(Configuration.WCS_WEB_CONTEXT)
          .append('/')
          .append(Configuration.WCS_SERVLET);

      String req =
          "<?xml version='1.0' encoding='UTF-8'?><GetCoverage "
              + "xmlns='http://www.opengis.net/wcs' xmlns:gml='http://www.opengis.net/gml' "
              + "service='WCS' version='1.0.0'><sourceCoverage>Mapneatline</sourceCoverage>"
              + "<domainSubset><spatialSubset><gml:Envelope srsName='EPSG:4326'>"
              + "<gml:pos dimension='2'>-1,-1</gml:pos><gml:pos dimension='2'>1,1"
              + "</gml:pos></gml:Envelope><gml:Grid dimension='2'><gml:limits>"
              + "<gml:GridEnvelope><gml:low>0 0</gml:low><gml:high>300 300</gml:high>"
              + "</gml:GridEnvelope></gml:limits><gml:axisName>x</gml:axisName>"
              + "<gml:axisName>y</gml:axisName></gml:Grid></spatialSubset></domainSubset>"
              + "<output><crs>EPSG:4326</crs><format>jpeg</format></output></GetCoverage>";
      StringReader reader = new StringReader(req);
      Document doc = XMLTools.parse(reader);

      GetCoverage desc = (GetCoverage) OGCRequestFactory.createFromXML(doc);
      ResultCoverage o = (ResultCoverage) service.doService(desc);
      BufferedImage bi = ((AbstractGridCoverage) o.getCoverage()).getAsImage(500, 500);

      FileOutputStream fos =
          new FileOutputStream(Configuration.getWCSBaseDir().getPath() + "/kannweg1.tif");
      ImageUtils.saveImage(bi, fos, "tif", 1);
      fos.close();
    } catch (Exception e) {
      fail(StringTools.stackTraceToString(e));
    }
  }
  /**
   * reads a deegree WCS configuration file and performs a GetCoverage request Steps:
   *
   * <ul>
   *   <li>read configuration file
   *   <li>read a GetCoverage request object
   *   <li>perform the request
   * </ul>
   */
  public void _testGetCoverage3() {
    try {
      WCSConfiguration configuration =
          WCSConfiguration.create(Configuration.getWCSConfigurationURL());
      WCService service = new WCService(configuration);

      Map<String, String> map = new HashMap<String, String>();
      map.put("SERVICE", "WCS");
      map.put("REQUEST", "GetCoverage");
      map.put("VERSION", "1.0.0");
      map.put("COVERAGE", "europe");
      map.put("CRS", "EPSG:4326");
      map.put("BBOX", "-5,40,20,60");
      map.put("WIDTH", "800");
      map.put("HEIGHT", "800");
      map.put("FORMAT", "jpeg");

      // StringBuffer sb = new StringBuffer();
      // sb.append(Configuration.PROTOCOL + "://" + Configuration.HOST)
      // .append(':').append(Configuration.PORT).append('/')
      // .append(Configuration.WCS_WEB_CONTEXT).append('/')
      // .append(Configuration.WCS_SERVLET).append("?service=WCS&")
      // .append("request=GetCoverage&version=1.0.0&coverage=europe&")
      // .append( "crs=EPSG:4326&BBOX=-5,40,20,60&Width=800&height=800&")
      // .append("format=jpeg");
      GetCoverage desc = GetCoverage.create(map);
      ResultCoverage o = (ResultCoverage) service.doService(desc);
      BufferedImage bi = ((AbstractGridCoverage) o.getCoverage()).getAsImage(800, 800);

      FileOutputStream fos =
          new FileOutputStream(Configuration.getWCSBaseDir().getPath() + "/kannweg3.tif");
      ImageUtils.saveImage(bi, fos, "tif", 1);
      fos.close();
    } catch (Exception e) {
      fail(StringTools.stackTraceToString(e));
    }
  }
  /**
   * reads a deegree WCS configuration file and performs a GetCoverage request. same as
   * testGetCoverage1() but uses nameIndexed data source Steps:
   *
   * <ul>
   *   <li>read configuration file
   *   <li>read a GetCoverage request object
   *   <li>perform the request
   * </ul>
   */
  public void _testGetCoverage2() {
    try {
      WCSConfiguration configuration =
          WCSConfiguration.create(Configuration.getWCSConfigurationURL());
      WCService service = new WCService(configuration);

      Map<String, String> map = new HashMap<String, String>();
      map.put("SERVICE", "WCS");
      map.put("REQUEST", "GetCoverage");
      map.put("VERSION", "1.0.0");
      map.put("COVERAGE", "dem");
      map.put("CRS", "EPSG:4326");
      map.put("BBOX", "-122.6261,37.4531,-122.0777,38.0");
      map.put("WIDTH", "828");
      map.put("HEIGHT", "823");
      map.put("FORMAT", "GeoTiff");

      // StringBuffer sb = new StringBuffer();
      // sb.append(Configuration.PROTOCOL + "://" + Configuration.HOST).append(':').append(
      // Configuration.PORT).append('/').append(Configuration.WCS_WEB_CONTEXT).append(
      // '/').append(Configuration.WCS_SERVLET).append("?service=WCS&").append(
      // "request=GetCoverage&version=1.0.0&coverage=dem&").append(
      // "crs=EPSG:4326&BBOX=-122.6261,37.4531,-122.0777,38.0&Width=828&height=823&")
      // .append("format=GeoTiff");
      GetCoverage desc = GetCoverage.create(map);
      ResultCoverage o = (ResultCoverage) service.doService(desc);
      BufferedImage bi = ((AbstractGridCoverage) o.getCoverage()).getAsImage(828, 823);
      LOG.logInfo(o.toString());
      FileOutputStream fos =
          new FileOutputStream(new URL(Configuration.getWCSBaseDir(), "/kannweg2.tif").getFile());
      ImageUtils.saveImage(bi, fos, "tif", 1);
      fos.close();
    } catch (Exception e) {
      fail(StringTools.stackTraceToString(e));
    }
  }
  /** test transforming all geometries contained within a FeatureCollection */
  public void testTransformFeatureCollection() {
    try {
      URL url = new URL(Configuration.getGMLBaseDir(), Configuration.GML_COMPLEX_EXAMPLE);
      GMLFeatureCollectionDocument doc = new GMLFeatureCollectionDocument();
      doc.load(url);
      FeatureCollection fc = doc.parse();
      CoordinateSystem crs = CRSFactory.create("epsg:31467");
      GeoTransformer gt = new GeoTransformer(crs);
      gt.transform(fc);
      for (int i = 0; i < fc.size(); i++) {
        assertEquals(true, isTargetCRS(fc.getFeature(i), crs));
      }

      // GMLFeatureAdapter ada = new GMLFeatureAdapter();
      // ada.export( fc ).prettyPrint( System.out );

    } catch (Exception e) {
      LOG.logError(e.getLocalizedMessage(), e);
      assertEquals(true, false);
    }
  }
 /**
  * reads a deegree WCS configuration file and performs a GetCapbilities request Steps:
  *
  * <ul>
  *   <li>read configuration file
  *   <li>read a GetCapabilites request object
  *   <li>perform the request
  * </ul>
  */
 public void testGetCapabilities() {
   try {
     WCSConfiguration configuration =
         WCSConfiguration.create(Configuration.getWCSConfigurationURL());
     WCService service = new WCService(configuration);
     // StringBuffer sb = new StringBuffer();
     // sb.append( "http://127.0.0.1/deegreewcs/wcs?service=WCS&" );
     // sb.append( "request=GetCapabilities&version=1.0.0" );
     Map<String, String> map = new HashMap<String, String>();
     map.put("REQUEST", "GetCapabilities");
     map.put("VERSION", "1.0.0");
     map.put("SERVICE", "WCS");
     WCSGetCapabilities getCapa = (WCSGetCapabilities) WCSGetCapabilities.create(map);
     // (WCSGetCapabilities) OGCRequestFactory.createFromKVP(sb.toString());
     Object o = service.doService(getCapa);
     XMLFragment xml = XMLFactory.export((WCSConfiguration) o);
     // xml.write( System.out );
     LOG.logInfo(xml.getAsPrettyString());
   } catch (Exception e) {
     fail(StringTools.stackTraceToString(e));
   }
 }