/** Tests that symbols relative sizes are proportional. */ @org.junit.Test public void testSimpleLine() throws Exception { GetLegendGraphicRequest req = new GetLegendGraphicRequest(); req.setWidth(20); req.setHeight(20); FeatureTypeInfo ftInfo = getCatalog() .getFeatureTypeByName( MockData.MPOINTS.getNamespaceURI(), MockData.MPOINTS.getLocalPart()); req.setLayer(ftInfo.getFeatureType()); req.setStyle(readSLD("line.sld")); BufferedImage image = this.legendProducer.buildLegendGraphic(req); assertNotBlank("line", image, LegendUtils.DEFAULT_BG_COLOR); // line in the middle, but off the middle, it's white Color colorCenter = getPixelColor(image, 10, 10); assertColorSimilar(Color.BLUE, colorCenter, 20); Color colorOutsideCenter = getPixelColor(image, 6, 6); assertColorSimilar(Color.WHITE, colorOutsideCenter, 20); }
/** Tests that symbols relative sizes are proportional. */ @org.junit.Test public void testProportionalSymbolsLine() throws Exception { GetLegendGraphicRequest req = new GetLegendGraphicRequest(); FeatureTypeInfo ftInfo = getCatalog() .getFeatureTypeByName( MockData.MPOINTS.getNamespaceURI(), MockData.MPOINTS.getLocalPart()); req.setLayer(ftInfo.getFeatureType()); req.setStyle(readSLD("ProportionalSymbolsLine.sld")); BufferedImage image = this.legendProducer.buildLegendGraphic(req); assertNotBlank("ProportionalSymbolsLine", image, LegendUtils.DEFAULT_BG_COLOR); // biggest symbol, thick border assertPixel(image, 1, 1, new Color(255, 255, 255)); // outside assertPixel(image, 5, 5, new Color(0, 0, 0)); // border assertPixel(image, 7, 12, new Color(255, 0, 0)); // inside // second symbol, small, no border assertPixel(image, 1, 21, new Color(255, 255, 255)); // outside assertPixel(image, 5, 25, new Color(255, 255, 255)); // small, still outside assertPixel(image, 10, 30, new Color(255, 0, 0)); // inside }
GetLegendGraphicRequest req = new GetLegendGraphicRequest(); req.setScale(1000); int titleHeight = getTitleHeight(req); getCatalog() .getFeatureTypeByName( MockData.ROAD_SEGMENTS.getNamespaceURI(), getCatalog().getStyleByName(MockData.ROAD_SEGMENTS.getLocalPart()); styles.add(roadStyle.getStyle()); styles.add(readSLD("InvisibleLine.sld")); assertPixel(image, 10, 10 + titleHeight, new Color(192, 160, 0)); assertPixel(image, 10, 30 + titleHeight, new Color(0, 0, 0)); assertPixel(image, 10, 50 + titleHeight, new Color(224, 64, 0));
int titleHeight = getTitleHeight(req); getCatalog() .getFeatureTypeByName( MockData.ROAD_SEGMENTS.getNamespaceURI(), MockData.ROAD_SEGMENTS.getLocalPart()); req.setLayer(ftInfo.getFeatureType()); req.setStyle(getCatalog().getStyleByName(MockData.ROAD_SEGMENTS.getLocalPart()).getStyle()); assertNotBlank("testMultipleLayers", image, LegendUtils.DEFAULT_BG_COLOR); int height = image.getHeight(); getCatalog().getStyleByName(MockData.ROAD_SEGMENTS.getLocalPart()).getStyle()); req.getLegends().add(legend); assertNotBlank("testMultipleLayers", image, LegendUtils.DEFAULT_BG_COLOR); assertPixel(image, 1, titleHeight / 2, new Color(0, 0, 0)); assertPixel(image, 10, 10 + titleHeight, new Color(192, 160, 0)); assertPixel(image, 10, 30 + titleHeight, new Color(0, 0, 0)); assertPixel(image, 10, 50 + titleHeight, new Color(224, 64, 0)); assertPixel(image, 1, 60 + titleHeight + titleHeight / 2, new Color(0, 0, 0)); assertPixel(image, 10, 70 + titleHeight * 2, new Color(192, 160, 0));
getCatalog() .getFeatureTypeByName( MockData.POINTS.getNamespaceURI(), MockData.POINTS.getLocalPart()); req.setLayer(ftInfo.getFeatureType()); Style externalGraphicStyle = readSLD("ExternalGraphicDemo.sld"); req.setStyle(externalGraphicStyle); assertEquals(HEIGHT_HINT * 2, image.getHeight()); for (int x = 21; x <= 29; x++) { assertPixel(image, x, HEIGHT_HINT / 2, new Color(255, 255, 255)); assertEquals(HEIGHT_HINT * 2, image.getHeight()); for (int x = 21; x <= 39; x++) { assertPixel(image, x, HEIGHT_HINT / 2, new Color(255, 255, 255));
GetLegendGraphicRequest req = new GetLegendGraphicRequest(); int titleHeight = getTitleHeight(req); getCatalog() .getFeatureTypeByName( MockData.ROAD_SEGMENTS.getNamespaceURI(), getCatalog().getStyleByName(MockData.ROAD_SEGMENTS.getLocalPart()).getStyle(); styles.add(style1); Style style2 = getCatalog().getStyleByName(MockData.LAKES.getLocalPart()).getStyle(); styles.add(style2); req.setStyles(styles); assertPixel(image, 10, 10 + titleHeight, new Color(192, 160, 0)); assertPixel(image, 10, 30 + titleHeight, new Color(0, 0, 0)); assertPixel(image, 10, 50 + titleHeight, new Color(224, 64, 0)); assertPixel(image, 10, 70 + titleHeight * 2, new Color(64, 64, 192));
Catalog cat = getCatalog(); assertNotBlank("testMultipleLayers", image, LegendUtils.DEFAULT_BG_COLOR); int height = image.getHeight(); assertNotBlank("testForceTitlesOff", image, LegendUtils.DEFAULT_BG_COLOR); assertPixel(image, 10, 10, new Color(192, 160, 0)); assertPixel(image, 10, 30, new Color(0, 0, 0)); assertPixel(image, 10, 50, new Color(224, 64, 0)); assertPixel(image, 10, 70, new Color(192, 160, 0)); assertPixel(image, 10, 90, new Color(0, 0, 0)); assertPixel(image, 10, 110, new Color(224, 64, 0));
req.setStyles(styles); styles.add(readSLD("MixedGeometry.sld")); assertNotBlank("testMixedGeometry", image, LegendUtils.DEFAULT_BG_COLOR); assertPixel(image, 10, 10, new Color(0, 0, 0)); assertPixel(image, 10, 30, new Color(0, 0, 255)); assertPixel(image, 10, 50, new Color(255, 0, 0));
/** * Tests that the legend graphic is still produced when the request's strict parameter is set to * false and a layer is not specified */ @org.junit.Test public void testNoLayerProvidedAndNonStrictRequest() throws Exception { Style style = getCatalog().getStyleByName("rainfall").getStyle(); assertNotNull(style); GetLegendGraphicRequest req = new GetLegendGraphicRequest(); req.setStrict(false); req.setLayer(null); req.setStyle(style); final int HEIGHT_HINT = 30; req.setHeight(HEIGHT_HINT); // use default values for the rest of parameters this.legendProducer.buildLegendGraphic(req); BufferedImage image = this.legendProducer.buildLegendGraphic(req); // was the legend painted? assertNotBlank("testRainfall", image, LegendUtils.DEFAULT_BG_COLOR); // was the legend painted? assertNotBlank("testRainfall", image, LegendUtils.DEFAULT_BG_COLOR); } /** Tests that the legend graphic is produced for multiple layers */
public void testColorMapWithCql() throws Exception { Style style = readSLD("ColorMapWithCql.sld"); assertNotNull(style.featureTypeStyles()); assertEquals(1, style.featureTypeStyles().size()); CoverageInfo cInfo = getCatalog().getCoverageByName("world"); assertNotNull(cInfo); assertNotBlank("testColorMapWithCql", image, LegendUtils.DEFAULT_BG_COLOR); int fixedWidth = image.getWidth(); assertNotBlank("testColorMapWithCql", image, LegendUtils.DEFAULT_BG_COLOR);
/** Tests that minSymbolSize legend option is respected. */ @org.junit.Test public void testInternationalizedLabels() throws Exception { GetLegendGraphicRequest req = new GetLegendGraphicRequest(); Map<String, String> options = new HashMap<String, String>(); options.put("forceLabels", "on"); req.setLegendOptions(options); FeatureTypeInfo ftInfo = getCatalog() .getFeatureTypeByName( MockData.MPOINTS.getNamespaceURI(), MockData.MPOINTS.getLocalPart()); req.setLayer(ftInfo.getFeatureType()); req.setStyle(readSLD("Internationalized.sld")); BufferedImage image = this.legendProducer.buildLegendGraphic(req); int noLocalizedWidth = image.getWidth(); req.setLocale(Locale.ITALIAN); image = this.legendProducer.buildLegendGraphic(req); // test that using localized labels we get a different label than when not using it int itWidth = image.getWidth(); assertTrue(itWidth != noLocalizedWidth); req.setLocale(Locale.ENGLISH); image = this.legendProducer.buildLegendGraphic(req); // test that using localized labels we get a different label than when not using it int enWidth = image.getWidth(); assertTrue(enWidth != noLocalizedWidth); assertTrue(enWidth != itWidth); }
public void testExternalGraphic() throws Exception { Style externalGraphicStyle = readSLD("ExternalGraphicDemo.sld"); CoverageInfo cInfo = getCatalog().getCoverageByName("world"); assertNotNull(cInfo); assertPixel(image, 10, HEIGHT_HINT + HEIGHT_HINT / 2, Color.YELLOW); } finally { RenderedImage ri = coverage.getRenderedImage();
GetLegendGraphicRequest req = new GetLegendGraphicRequest(); int titleHeight = getTitleHeight(req); getCatalog() .getFeatureTypeByName( MockData.ROAD_SEGMENTS.getNamespaceURI(), CoverageInfo cInfo = getCatalog().getCoverageByName("world"); assertNotNull(cInfo); getCatalog().getStyleByName(MockData.ROAD_SEGMENTS.getLocalPart()).getStyle(); styles.add(style1); Style style2 = getCatalog().getStyleByName("rainfall").getStyle(); styles.add(style2); req.setStyles(styles); assertPixel(image, 10, 10 + titleHeight, new Color(192, 160, 0)); assertPixel(image, 10, 30 + titleHeight, new Color(0, 0, 0)); assertPixel(image, 10, 50 + titleHeight, new Color(224, 64, 0)); assertPixel(image, 10, 70 + titleHeight * 2, new Color(115, 38, 0)); } finally { RenderedImage ri = coverage.getRenderedImage();
public void testRainfall() throws Exception { Style multipleRulesStyle = getCatalog().getStyleByName("rainfall").getStyle(); CoverageInfo cInfo = getCatalog().getCoverageByName("world"); assertNotNull(cInfo); assertNotBlank("testRainfall", image, LegendUtils.DEFAULT_BG_COLOR); assertNotBlank("testRainfall", image, LegendUtils.DEFAULT_BG_COLOR); } finally { RenderedImage ri = coverage.getRenderedImage();
Style style = readSLD("ColorMapWithLongLabels.sld"); assertNotNull(style.featureTypeStyles()); assertEquals(1, style.featureTypeStyles().size()); CoverageInfo cInfo = getCatalog().getCoverageByName("world"); assertNotNull(cInfo);
/** Tests that symbols relative sizes are proportional. */ @org.junit.Test public void testProportionalSymbolThickBorder() throws Exception { GetLegendGraphicRequest req = new GetLegendGraphicRequest(); FeatureTypeInfo ftInfo = getCatalog() .getFeatureTypeByName( MockData.MPOINTS.getNamespaceURI(), MockData.MPOINTS.getLocalPart()); req.setLayer(ftInfo.getFeatureType()); req.setStyle(readSLD("ProportionalSymbolsThickBorder.sld")); BufferedImage image = this.legendProducer.buildLegendGraphic(req); assertNotBlank( "testProportionalSymbolSizeThickBorder", image, LegendUtils.DEFAULT_BG_COLOR); // biggest symbol, thick border assertPixel(image, 1, 1, new Color(255, 255, 255)); // outside assertPixel(image, 5, 5, new Color(0, 0, 0)); // border assertPixel(image, 10, 10, new Color(255, 0, 0)); // inside // second symbol, small, no border assertPixel(image, 1, 21, new Color(255, 255, 255)); // outside assertPixel(image, 5, 25, new Color(255, 255, 255)); // small, still outside assertPixel(image, 10, 30, new Color(255, 0, 0)); // inside }
/** Tests that symbols relative sizes are proportional. */ @org.junit.Test public void testLargeCirclePlacement() throws Exception { GetLegendGraphicRequest req = new GetLegendGraphicRequest(); req.setWidth(48); req.setHeight(25); FeatureTypeInfo ftInfo = getCatalog() .getFeatureTypeByName( MockData.MPOINTS.getNamespaceURI(), MockData.MPOINTS.getLocalPart()); req.setLayer(ftInfo.getFeatureType()); req.setStyle(readSLD("largeCircle.sld")); BufferedImage image = this.legendProducer.buildLegendGraphic(req); assertNotBlank("largeCircle", image, LegendUtils.DEFAULT_BG_COLOR); // the border is visible both top middle and bottom middle. Different JDK // build wildly different colors for the border unfortunately, so the test // checks that pixels at top/middle bottom/middle are similar color (they used to be // different, significantly) Color colorTop = getPixelColor(image, 24, 0); Color colorBottom = getPixelColor(image, 24, 24); assertColorSimilar(colorTop, colorBottom, 20); }
GetLegendGraphicRequest req = new GetLegendGraphicRequest(); req.setScale(1000); int titleHeight = getTitleHeight(req); getCatalog() .getFeatureTypeByName( MockData.ROAD_SEGMENTS.getNamespaceURI(), layers.add(ftInfo.getFeatureType()); CoverageInfo cInfo = getCatalog().getCoverageByName("world"); assertNotNull(cInfo); getCatalog().getStyleByName(MockData.ROAD_SEGMENTS.getLocalPart()).getStyle(); styles.add(style1); styles.add(readSLD("InvisibleRaster.sld")); assertPixel(image, 10, 10 + titleHeight, new Color(192, 160, 0)); assertPixel(image, 10, 30 + titleHeight, new Color(0, 0, 0)); assertPixel(image, 10, 50 + titleHeight, new Color(224, 64, 0));
getCatalog().getStyleByName(MockData.ROAD_SEGMENTS.getLocalPart()).getStyle(); assertNotNull(multipleRulesStyle); getCatalog() .getFeatureTypeByName( MockData.ROAD_SEGMENTS.getNamespaceURI(), assertNotBlank("testUserSpecifiedRule", image, LegendUtils.DEFAULT_BG_COLOR);
getCatalog() .getFeatureTypeByName( MockData.MPOINTS.getNamespaceURI(), req.setStyle(readSLD("ProportionalSymbolsUOM.sld")); assertNotBlank("testProportionalSymbolSize", image, LegendUtils.DEFAULT_BG_COLOR); assertPixel(image, 1, 1, new Color(255, 255, 255)); assertPixel(image, 5, 5, new Color(255, 0, 0)); assertPixel(image, 10, 10, new Color(255, 0, 0)); assertPixel(image, 1, 21, new Color(255, 255, 255)); assertPixel(image, 5, 25, new Color(255, 255, 255)); assertPixel(image, 7, 27, new Color(255, 0, 0)); assertPixel(image, 10, 30, new Color(255, 0, 0)); assertPixel(image, 1, 41, new Color(255, 255, 255)); assertPixel(image, 5, 45, new Color(255, 255, 255)); assertPixel(image, 6, 46, new Color(255, 255, 255)); assertPixel(image, 10, 50, new Color(255, 0, 0)); assertPixel(image, 1, 61, new Color(255, 255, 255)); assertPixel(image, 6, 68, new Color(255, 255, 255)); assertPixel(image, 10, 70, new Color(255, 0, 0));