/*
   * https://osgeo-org.atlassian.net/browse/GEOT-5287
   */
  @Test
  public void testEmptyGeometryRendering() throws Exception {

    MapContent mc = new MapContent();

    /*
     * We simulate reading empty geometries with this properties and mocking the capability to
     * filter, so that no filter layer is installed over our data and the empty geometry reaches
     * rendering code. These geometries are in EPSG:32717 because the 0,0 coordinate is in the
     * pole.
     */
    File dir = new File(TestData.getResource(this, "empty-geom-rendering.properties").toURI());
    PropertyDataStore dataStore =
        new PropertyDataStore(dir.getParentFile()) {
          @Override
          protected ContentFeatureSource createFeatureSource(ContentEntry entry)
              throws IOException {
            return new PropertyFeatureSource(entry, Query.ALL) {
              @Override
              protected boolean canFilter() {
                return true;
              }
            };
          }
        };
    /*
     * Set up the rendering of previous empty geometry
     */
    StyleBuilder sb = new StyleBuilder();
    Style style = sb.createStyle(sb.createPolygonSymbolizer());
    Layer layer = new FeatureLayer(dataStore.getFeatureSource("empty-geom-rendering"), style);
    mc.addLayer(layer);
    StreamingRenderer sr = new StreamingRenderer();
    sr.setMapContent(mc);
    BufferedImage img = new BufferedImage(40, 40, BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphics = img.createGraphics();
    Rectangle paintArea = new Rectangle(40, 40);
    // An EPSG:8357 extent on the EPSG:32717 area of application.
    double minx = -8929252.1;
    double maxx = -8708634.6;
    double miny = -491855.7;
    double maxy = -271204.3;
    ReferencedEnvelope referencedEnvelope =
        new ReferencedEnvelope(
            new Rectangle2D.Double(minx, miny, maxx - minx, maxy - miny), CRS.decode("EPSG:3857"));
    sr.addRenderListener(
        new RenderListener() {
          public void featureRenderer(SimpleFeature feature) {}

          public void errorOccurred(Exception e) {
            errors++;
          }
        });
    errors = 0;

    sr.paint(graphics, paintArea, referencedEnvelope);

    assertTrue(errors == 0);
  }
  @Override
  protected void setUp() throws Exception {
    // setup data
    File property = new File(TestData.getResource(this, "diaglines.properties").toURI());
    PropertyDataStore ds = new PropertyDataStore(property.getParentFile());
    fs = ds.getFeatureSource("diaglines");
    bounds = new ReferencedEnvelope(0, 10, 0, 10, DefaultGeographicCRS.WGS84);

    renderer = new StreamingRenderer();
    Map rendererParams = new HashMap();
    LabelCacheImpl labelCache = new LabelCacheImpl();
    rendererParams.put(StreamingRenderer.LABEL_CACHE_KEY, labelCache);
    renderer.setRendererHints(rendererParams);
    renderer.setJava2DHints(new RenderingHints(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON));

    //        System.setProperty("org.geotools.test.interactive", "true");
  }
  private void testTransformWithQuery(boolean invert)
      throws IOException, URISyntaxException, CQLException, NoSuchAuthorityCodeException,
          FactoryException, Exception {
    // grab the style
    Style style =
        RendererBaseTest.loadStyle(
            this, invert ? "attributeRename.sld" : "attributeRenameNoInvert.sld");
    // grab the data
    File property = new File(TestData.getResource(this, "point.properties").toURI());
    PropertyDataStore ds = new PropertyDataStore(property.getParentFile());
    FeatureSource fs = ds.getFeatureSource("point");

    // prepare a feature layer with a query and the rendering tx
    FeatureLayer layer = new FeatureLayer(fs, style);
    layer.setQuery(new Query(null, CQL.toFilter("id > 5")));

    // render it
    MapContent mc = new MapContent();
    mc.addLayer(layer);
    StreamingRenderer renderer = new StreamingRenderer();
    final AtomicInteger counter = new AtomicInteger();
    renderer.addRenderListener(
        new RenderListener() {

          @Override
          public void featureRenderer(SimpleFeature feature) {
            counter.incrementAndGet();
          }

          @Override
          public void errorOccurred(Exception e) {}
        });
    renderer.setMapContent(mc);
    ReferencedEnvelope re = new ReferencedEnvelope(0, 12, 0, 12, CRS.decode("EPSG:4326"));
    BufferedImage image =
        RendererBaseTest.showRender("Lines with circle stroke", renderer, TIME, re);

    // if everything went fine we'll have a single red dot in the middle, and we rendered
    // just one feature
    assertEquals(1, counter.get());
    assertEquals(Color.RED, getPixelColor(image, image.getWidth() / 2, image.getHeight() / 2));
  }
  @Test
  public void testTransformReproject() throws Exception {
    // grab the style
    Style style = RendererBaseTest.loadStyle(this, "reproject-rt.sld");
    // grab the data
    File property = new File(TestData.getResource(this, "point.properties").toURI());
    PropertyDataStore ds = new PropertyDataStore(property.getParentFile());
    FeatureSource fs = ds.getFeatureSource("point");

    // prepare a feature layer with a query and the rendering tx
    FeatureLayer layer = new FeatureLayer(fs, style);

    // prepare a bbox in UTM-32N
    ReferencedEnvelope reWgs84 = new ReferencedEnvelope(0, 12, 0, 12, CRS.decode("EPSG:4326"));
    ReferencedEnvelope reUTM32N = reWgs84.transform(CRS.decode("EPSG:3857"), true);

    // render it
    MapContent mc = new MapContent();
    mc.addLayer(layer);
    StreamingRenderer renderer = new StreamingRenderer();
    final AtomicInteger counter = new AtomicInteger();
    renderer.addRenderListener(
        new RenderListener() {

          @Override
          public void featureRenderer(SimpleFeature feature) {
            counter.incrementAndGet();
          }

          @Override
          public void errorOccurred(Exception e) {}
        });
    renderer.setMapContent(mc);
    BufferedImage image =
        RendererBaseTest.showRender("Lines with circle stroke", renderer, TIME, reUTM32N);

    // if everything went fine we rendered all the features
    assertEquals(10, counter.get());
    assertEquals(Color.RED, getPixelColor(image, image.getWidth() / 2, image.getHeight() / 2));
  }