Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

More test coverage for z-ordering

  • Loading branch information...
commit 490b50f03fa9af3784bef175fece552cdec181bd 1 parent 5f6478f
@aaime aaime authored
View
27 modules/library/render/src/main/java/org/geotools/renderer/lite/ZGroupLayer.java
@@ -190,6 +190,8 @@ private SortKey getSmallestKey(List<ZGroupLayerPainter> painters,
}
}
+ validateSortBy(painters);
+
// got to the end cleanly, no need to close the painters accumulated so far
closePainters = false;
} finally {
@@ -205,8 +207,6 @@ private SortKey getSmallestKey(List<ZGroupLayerPainter> painters,
}
}
- validateSortBy(painters);
-
return painters;
}
@@ -219,12 +219,15 @@ private SortKey getSmallestKey(List<ZGroupLayerPainter> painters,
*/
private void validateSortBy(List<ZGroupLayerPainter> painters) {
Class[] referenceClasses = null;
+ SortOrder[] referenceOrders = null;
LiteFeatureTypeStyle reference = null;
for (ZGroupLayerPainter painter : painters) {
for (LiteFeatureTypeStyle style : painter.lfts) {
Class[] styleClasses = getSortByAttributeClasses(style);
+ SortOrder[] styleOrders = getSortOrders(style);
if (referenceClasses == null) {
referenceClasses = styleClasses;
+ referenceOrders = styleOrders;
reference = style;
for (int i = 0; i < referenceClasses.length; i++) {
if (!Comparable.class.isAssignableFrom(referenceClasses[i])) {
@@ -254,6 +257,15 @@ private void validateSortBy(List<ZGroupLayerPainter> painters) {
+ ": " + sortByToString(reference, referenceClasses)
+ " vs " + sortByToString(style, styleClasses));
}
+ SortOrder currOrder = styleOrders[i];
+ SortOrder referenceOrder = referenceOrders[i];
+ if (!currOrder.equals(referenceOrder)) {
+ throw new IllegalArgumentException(
+ "Found two different sort orders at position " + (i + 1)
+ + " of the sortBy clauses in group " + groupId
+ + ": " + sortByToString(reference, referenceClasses)
+ + " vs " + sortByToString(style, styleClasses));
+ }
}
}
}
@@ -285,6 +297,17 @@ private void validateSortBy(List<ZGroupLayerPainter> painters) {
return classes;
}
+ private SortOrder[] getSortOrders(LiteFeatureTypeStyle style) {
+ SortBy[] sb = style.sortBy;
+ FeatureType schema = style.layer.getFeatureSource().getSchema();
+ SortOrder[] orders = new SortOrder[sb.length];
+ for (int i = 0; i < orders.length; i++) {
+ orders[i] = sb[i].getSortOrder();
+ }
+
+ return orders;
+ }
+
private String sortByToString(LiteFeatureTypeStyle style, Class[] classes) {
StringBuilder sb = new StringBuilder("Layer ").append(style.layer.getTitle()).append("[");
SortBy[] sortBy = style.sortBy;
View
4 modules/library/render/src/main/java/org/geotools/renderer/style/SLDStyleFactory.java
@@ -1607,8 +1607,8 @@ public static Composite getComposite(Map<String, String> options, float defaultO
if ("D".equalsIgnoreCase(direction) || "DESC".equalsIgnoreCase(direction)) {
order = SortOrder.DESCENDING;
} else if(!"A".equalsIgnoreCase(direction) || "ASC".equalsIgnoreCase(direction)) {
- throw new IllegalArgumentException("Unknown sort order '" + order
- + "' in: '" + attributeSpec + "'");
+ throw new IllegalArgumentException(
+ "Unknown sort order '" + direction + "' in: '" + attributeSpec + "'");
}
}
SortBy sort = ff.sort(attribute, order);
View
171 modules/library/render/src/test/java/org/geotools/renderer/lite/ZOrderTest.java
@@ -18,12 +18,15 @@
import static java.awt.RenderingHints.KEY_ANTIALIASING;
import static java.awt.RenderingHints.VALUE_ANTIALIAS_ON;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
+import java.util.concurrent.atomic.AtomicInteger;
import org.geotools.data.property.PropertyDataStore;
import org.geotools.data.simple.SimpleFeatureSource;
@@ -201,4 +204,172 @@ private void forceSortByGroup(Style style, String sortByGroup) {
}
}
+ @Test
+ public void testInvalidAttribute() throws Exception {
+ final AtomicInteger failureCount = new AtomicInteger(0);
+ runZRoadsFailureTest("zorder/zpolygon.sld", "not-there", null, new RenderListener() {
+
+ @Override
+ public void featureRenderer(SimpleFeature feature) {
+ // nothing to do
+ }
+
+ @Override
+ public void errorOccurred(Exception e) {
+ failureCount.incrementAndGet();
+ assertTrue(e instanceof IllegalArgumentException);
+ assertTrue(e.getMessage().contains("not-there"));
+
+ }
+ });
+ assertEquals(1, failureCount.get());
+ }
+
+ @Test
+ public void testInvalidSortBySyntax() throws Exception {
+ final AtomicInteger failureCount = new AtomicInteger(0);
+ runZRoadsFailureTest("zorder/zpolygon.sld", "z upsideDown", null, new RenderListener() {
+
+ @Override
+ public void featureRenderer(SimpleFeature feature) {
+ // nothing to do
+ }
+
+ @Override
+ public void errorOccurred(Exception e) {
+ failureCount.incrementAndGet();
+ assertTrue(e instanceof IllegalArgumentException);
+ assertTrue(e.getMessage().contains("z upsideDown"));
+
+ }
+ });
+ assertEquals(1, failureCount.get());
+ }
+
+ @Test
+ public void testNonComparable() throws Exception {
+ final AtomicInteger failureCount = new AtomicInteger(0);
+ runZRoadsFailureTest("zorder/zpolygon.sld", "color", null, new RenderListener() {
+
+ @Override
+ public void featureRenderer(SimpleFeature feature) {
+ // nothing to do
+ }
+
+ @Override
+ public void errorOccurred(Exception e) {
+ failureCount.incrementAndGet();
+ assertTrue(e instanceof IllegalArgumentException);
+ assertTrue(e.getMessage().contains("color"));
+ assertTrue(e.getMessage().contains("sort"));
+
+ }
+ });
+ assertEquals(1, failureCount.get());
+ }
+
+ @Test
+ public void testIncompatibleAttributes() throws Exception {
+ final AtomicInteger failureCount = new AtomicInteger(0);
+ runRoadsBuildFailureTest("zorder/zpolygon.sld", "z", "cat", "theGroup",
+ new RenderListener() {
+
+ @Override
+ public void featureRenderer(SimpleFeature feature) {
+ // nothing to do
+ }
+
+ @Override
+ public void errorOccurred(Exception e) {
+ failureCount.incrementAndGet();
+ assertTrue(e instanceof IllegalArgumentException);
+ assertTrue(e.getMessage().contains("z"));
+ assertTrue(e.getMessage().contains("cat"));
+ assertTrue(e.getMessage().contains("incompatible"));
+ }
+ });
+ assertEquals(1, failureCount.get());
+ }
+
+ @Test
+ public void testIncompatibleDirections() throws Exception {
+ final AtomicInteger failureCount = new AtomicInteger(0);
+ runRoadsBuildFailureTest("zorder/zpolygon.sld", "z A", "z D", "theGroup",
+ new RenderListener() {
+
+ @Override
+ public void featureRenderer(SimpleFeature feature) {
+ // nothing to do
+ }
+
+ @Override
+ public void errorOccurred(Exception e) {
+ failureCount.incrementAndGet();
+ assertTrue(e instanceof IllegalArgumentException);
+ assertTrue(e.getMessage().contains("order"));
+ }
+ });
+ assertEquals(1, failureCount.get());
+ }
+
+ @Test
+ public void testDifferentLenghts() throws Exception {
+ final AtomicInteger failureCount = new AtomicInteger(0);
+ runRoadsBuildFailureTest("zorder/zpolygon.sld", "z, cat", "z", "theGroup",
+ new RenderListener() {
+
+ @Override
+ public void featureRenderer(SimpleFeature feature) {
+ // nothing to do
+ }
+
+ @Override
+ public void errorOccurred(Exception e) {
+ failureCount.incrementAndGet();
+ assertTrue(e instanceof IllegalArgumentException);
+ assertTrue(e.getMessage().contains("number of attributes"));
+ }
+ });
+ assertEquals(1, failureCount.get());
+ }
+
+ private void runZRoadsFailureTest(String styleName, String sortBy, String sortByGroup,
+ RenderListener listener)
+ throws Exception {
+ Style style = RendererBaseTest.loadStyle(this, styleName);
+ forceSortBy(style, sortBy);
+ forceSortByGroup(style, sortByGroup);
+
+ MapContent mc = new MapContent();
+ mc.addLayer(new FeatureLayer(zroads, style));
+
+ runFailureTest(listener, mc);
+ }
+
+ private void runFailureTest(RenderListener listener, MapContent mc) throws Exception {
+ StreamingRenderer renderer = new StreamingRenderer();
+ renderer.setMapContent(mc);
+ renderer.setJava2DHints(new RenderingHints(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON));
+ renderer.addRenderListener(listener);
+ RendererBaseTest.showRender("failures", renderer, TIME, bounds);
+ mc.dispose();
+ }
+
+ private void runRoadsBuildFailureTest(String styleName, String sortByRoads,
+ String sortByBuildings, String sortByGroup, RenderListener listener) throws Exception {
+ Style roadsStyle = RendererBaseTest.loadStyle(this, "zorder/zroads.sld");
+ forceSortBy(roadsStyle, sortByRoads);
+ forceSortByGroup(roadsStyle, sortByGroup);
+
+ Style buildingsStyle = RendererBaseTest.loadStyle(this, "zorder/zbuildings.sld");
+ forceSortBy(buildingsStyle, sortByBuildings);
+ forceSortByGroup(buildingsStyle, sortByGroup);
+
+ MapContent mc = new MapContent();
+ mc.addLayer(new FeatureLayer(zroads, roadsStyle));
+ mc.addLayer(new FeatureLayer(zbuildings, buildingsStyle));
+
+ runFailureTest(listener, mc);
+ }
+
}
View
2  ...render/src/test/resources/org/geotools/renderer/lite/test-data/zorder/zsquares.properties
@@ -1,4 +1,4 @@
-_=geom:Polygon:4326,cat:String,z:int,name:String,color:String
+_=geom:Polygon:4326,cat:String,z:int,name:String,color:java.awt.Color
square.0=POLYGON((2 5, 2 9, 6 9, 6 5, 2 5))|a|3|foo|#FF0000
square.1=POLYGON((3 4, 7 4, 7 8, 3 8, 3 4))|b|2|bar|#00FF00
square.2=POLYGON((4 3, 8 3, 8 7, 4 7, 4 3))|b|1|car|#0000FF
Please sign in to comment.
Something went wrong with that request. Please try again.