Skip to content

Commit

Permalink
[GEOS-7929] WMS 1.3.0 GetCapabilities response doesn't validate again…
Browse files Browse the repository at this point in the history
…st the schema when using LayerGroups
  • Loading branch information
aaime committed Jan 13, 2017
1 parent 2e38f7b commit 5f440bb
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
6 changes: 6 additions & 0 deletions src/wms/pom.xml
Expand Up @@ -129,6 +129,12 @@
<artifactId>xmlunit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.geotools.xsd</groupId>
<artifactId>gt-xsd-wms</artifactId>
<version>${gt.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-process-raster</artifactId>
Expand Down
Expand Up @@ -1215,6 +1215,11 @@ protected void handleLayerGroup(LayerGroupInfo layerGroup, Set<LayerInfo> layers
}
handleMetadataList(metadataLinks);

// the layer style is not provided since the group does just have
// one possibility, the lack of styles that will make it use
// the default ones for each layer
handleScaleDenominator(layerGroup);

// handle children layers and groups
if(LayerGroupInfo.Mode.OPAQUE_CONTAINER.equals(layerGroup.getMode())) {
// just hide the layers in the group
Expand All @@ -1233,12 +1238,6 @@ protected void handleLayerGroup(LayerGroupInfo layerGroup, Set<LayerInfo> layers
}
}

// the layer style is not provided since the group does just have
// one possibility, the lack of styles that will make it use
// the default ones for each layer

handleScaleDenominator(layerGroup);

end("Layer");
}

Expand Down
30 changes: 29 additions & 1 deletion src/wms/src/test/java/org/geoserver/wms/WMSTestSupport.java
Expand Up @@ -5,6 +5,7 @@
*/
package org.geoserver.wms;

import static junit.framework.TestCase.fail;
import static org.junit.Assert.*;

import java.awt.Color;
Expand All @@ -22,6 +23,7 @@
import java.io.StringReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
Expand All @@ -30,6 +32,7 @@
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.dom.DOMSource;

import org.custommonkey.xmlunit.SimpleNamespaceContext;
import org.custommonkey.xmlunit.XMLUnit;
Expand All @@ -54,12 +57,15 @@
import org.geotools.map.Layer;
import org.geotools.referencing.crs.DefaultGeographicCRS;
import org.geotools.styling.Style;
import org.geotools.wms.v1_3.WMSConfiguration;
import org.geotools.xlink.XLINKConfiguration;
import org.geotools.xml.Parser;
import org.geotools.xml.transform.TransformerBase;
import org.opengis.feature.Feature;
import org.opengis.feature.type.FeatureType;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;

import org.xml.sax.SAXParseException;
import org.springframework.mock.web.MockHttpServletResponse;
import com.vividsolutions.jts.geom.Envelope;

Expand Down Expand Up @@ -619,5 +625,27 @@ protected int getRawTopLayerCount() {
int expectedLayerCount = layers.size() + groups.size() - 1 /* nested layer group */ - opaqueDelta;
return expectedLayerCount;
}

/**
* Validates a document against the
*
* @param dom
* @param configuration
*/
@SuppressWarnings("rawtypes")
protected void checkWms13ValidationErrors(Document dom) throws Exception {
Parser p = new Parser(new WMSConfiguration());
p.setValidating(true);
p.parse(new DOMSource(dom));

if (!p.getValidationErrors().isEmpty()) {
for (Iterator e = p.getValidationErrors().iterator(); e.hasNext();) {
SAXParseException ex = (SAXParseException) e.next();
System.out.println(ex.getLineNumber() + "," + ex.getColumnNumber() + " -"
+ ex.toString());
}
fail("Document did not validate.");
}
}

}
Expand Up @@ -23,6 +23,7 @@
import org.geoserver.catalog.LayerInfo;
import org.geoserver.catalog.MetadataMap;
import org.geoserver.catalog.StyleInfo;
import org.geoserver.catalog.LayerGroupInfo.Mode;
import org.geoserver.data.test.MockData;
import org.geoserver.data.test.SystemTestData;
import org.geoserver.wms.ExtendedCapabilitiesProvider;
Expand Down Expand Up @@ -117,6 +118,7 @@ void addLayerGroups(SystemTestData testData) throws Exception {
LayerGroupInfo layerGroup1 = catalog.getFactory().createLayerGroup();
layerGroup1.setName("testLayerGroup1");
layerGroup1.setBounds(nativeBounds);
layerGroup1.setMode(Mode.NAMED);

LayerGroupInfo layerGroup2 = catalog.getFactory().createLayerGroup();
layerGroup2.setName("testLayerGroup2");
Expand Down Expand Up @@ -149,7 +151,8 @@ public void testLayerGroups()throws Exception{

Document dom = findCapabilities(false);

print(dom);
// print(dom);
checkWms13ValidationErrors(dom);

Element layerElement= searchLayerElement("testLayerGroup1", dom);

Expand Down

0 comments on commit 5f440bb

Please sign in to comment.