Commit 6ee2f3a4 authored by Andrea Aime's avatar Andrea Aime
Browse files

Merge pull request #1187 from aaime/ext_prov_exit_fix

[GEOS-7158] WMS extended capabilities not populated if the first provider return a null root
parents 4f9dae62 f8c6dde9
......@@ -595,12 +595,16 @@ public class GetCapabilitiesTransformer extends TransformerBase {
* need to output the VendorSpecificCapabilities element. Moreover, the document will
* not validate if it's there but not declared in the internal DTD
*/
int numberRoots = 0;
for (ExtendedCapabilitiesProvider cp : extCapsProviders) {
List<String> roots = cp.getVendorSpecificCapabilitiesRoots(request);
if (roots == null || roots.size() == 0) {
return;
if (roots != null) {
numberRoots += roots.size();
}
}
if (numberRoots == 0) {
return;
}
start("VendorSpecificCapabilities");
for (ExtendedCapabilitiesProvider cp : extCapsProviders) {
......
......@@ -5,11 +5,12 @@
*/
package org.geoserver.wms.capabilities;
import static junit.framework.Assert.assertEquals;
import static org.custommonkey.xmlunit.XMLAssert.assertXpathEvaluatesTo;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import java.io.StringWriter;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
......@@ -19,6 +20,7 @@ import java.util.Set;
import org.custommonkey.xmlunit.SimpleNamespaceContext;
import org.custommonkey.xmlunit.XMLUnit;
import org.custommonkey.xmlunit.XpathEngine;
import org.custommonkey.xmlunit.exceptions.XpathException;
import org.geoserver.catalog.Catalog;
import org.geoserver.catalog.Keyword;
import org.geoserver.catalog.LayerInfo;
......@@ -52,6 +54,89 @@ import org.xml.sax.helpers.NamespaceSupport;
*/
public class GetCapabilitiesTransformerTest {
private static final class EmptyExtendedCapabilitiesProvider
implements ExtendedCapabilitiesProvider {
public String[] getSchemaLocations(String schemaBaseURL) {
throw new UnsupportedOperationException();
}
public void registerNamespaces(NamespaceSupport namespaces) {
throw new UnsupportedOperationException();
}
public List<String> getVendorSpecificCapabilitiesRoots(GetCapabilitiesRequest request) {
return null;
}
/**
*
* @see org.geoserver.wms.ExtendedCapabilitiesProvider#getVendorSpecificCapabilitiesChildDecls()
*/
public List<String> getVendorSpecificCapabilitiesChildDecls(
GetCapabilitiesRequest request) {
return null;
}
public void encode(Translator tx, WMSInfo wms, GetCapabilitiesRequest request)
throws IOException {
}
@Override
public void customizeRootCrsList(Set<String> srs) {
}
@Override
public NumberRange<Double> overrideScaleDenominators(LayerInfo layer,
NumberRange<Double> scaleDenominators) {
return null;
}
}
private static final class TestExtendedCapabilitiesProvider
implements ExtendedCapabilitiesProvider {
public String[] getSchemaLocations(String schemaBaseURL) {
throw new UnsupportedOperationException();
}
public void registerNamespaces(NamespaceSupport namespaces) {
throw new UnsupportedOperationException();
}
public List<String> getVendorSpecificCapabilitiesRoots(GetCapabilitiesRequest request) {
return Collections.singletonList("TestElement?");
}
/**
*
* @see org.geoserver.wms.ExtendedCapabilitiesProvider#getVendorSpecificCapabilitiesChildDecls()
*/
public List<String> getVendorSpecificCapabilitiesChildDecls(
GetCapabilitiesRequest request) {
return Collections.singletonList("<!ELEMENT TestSubElement (#PCDATA) >");
}
public void encode(Translator tx, WMSInfo wms, GetCapabilitiesRequest request)
throws IOException {
tx.start("TestElement");
tx.start("TestSubElement");
tx.end("TestSubElement");
tx.end("TestElement");
}
@Override
public void customizeRootCrsList(Set<String> srs) {
srs.clear();
srs.add("EPSG:4326");
}
@Override
public NumberRange<Double> overrideScaleDenominators(LayerInfo layer,
NumberRange<Double> scaleDenominators) {
return new NumberRange<Double>(Double.class, 0d, 1000d);
}
}
private XpathEngine XPATH;
/** default base url to feed a GetCapabilitiesTransformer with for it to append the DTD location */
......@@ -253,55 +338,29 @@ public class GetCapabilitiesTransformerTest {
@Test
public void testVendorSpecificCapabilities() throws Exception {
ExtendedCapabilitiesProvider vendorCapsProvider = new ExtendedCapabilitiesProvider() {
public String[] getSchemaLocations(String schemaBaseURL) {
throw new UnsupportedOperationException();
}
public void registerNamespaces(NamespaceSupport namespaces) {
throw new UnsupportedOperationException();
}
public List<String> getVendorSpecificCapabilitiesRoots(GetCapabilitiesRequest request) {
return Collections.singletonList("TestElement?");
}
/**
*
* @see org.geoserver.wms.ExtendedCapabilitiesProvider#getVendorSpecificCapabilitiesChildDecls()
*/
public List<String> getVendorSpecificCapabilitiesChildDecls(
GetCapabilitiesRequest request) {
return Collections.singletonList("<!ELEMENT TestSubElement (#PCDATA) >");
}
public void encode(Translator tx, WMSInfo wms, GetCapabilitiesRequest request)
throws IOException {
tx.start("TestElement");
tx.start("TestSubElement");
tx.end("TestSubElement");
tx.end("TestElement");
}
@Override
public void customizeRootCrsList(Set<String> srs) {
srs.clear();
srs.add("EPSG:4326");
}
@Override
public NumberRange<Double> overrideScaleDenominators(LayerInfo layer,
NumberRange<Double> scaleDenominators) {
return new NumberRange<Double>(Double.class, 0d, 1000d);
}
};
ExtendedCapabilitiesProvider vendorCapsProvider = new TestExtendedCapabilitiesProvider();
GetCapabilitiesTransformer tr;
tr = new GetCapabilitiesTransformer(wmsConfig, baseUrl, mapFormats, legendFormats,
Collections.singletonList(vendorCapsProvider));
tr.setIndentation(2);
checkVendorSpecificCapsProviders(tr);
}
@Test
public void testVendorSpecificCapabilitiesWithEmptyProvider() throws Exception {
ExtendedCapabilitiesProvider emptyCapsProvider = new EmptyExtendedCapabilitiesProvider();
ExtendedCapabilitiesProvider vendorCapsProvider = new TestExtendedCapabilitiesProvider();
GetCapabilitiesTransformer tr;
tr = new GetCapabilitiesTransformer(wmsConfig, baseUrl, mapFormats, legendFormats,
Arrays.asList(emptyCapsProvider, vendorCapsProvider));
tr.setIndentation(2);
checkVendorSpecificCapsProviders(tr);
}
private void checkVendorSpecificCapsProviders(GetCapabilitiesTransformer tr)
throws Exception, XpathException {
Document dom = WMSTestSupport.transform(req, tr);
assertXpathEvaluatesTo("1", "count(/WMT_MS_Capabilities/Capability/Layer/SRS)", dom);
assertXpathEvaluatesTo("1", "count(/WMT_MS_Capabilities/Capability/Layer[SRS='EPSG:4326'])", dom);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment