Skip to content

Commit

Permalink
[GEOS-8391] Layer default style is not published in WMTS capabilities…
Browse files Browse the repository at this point in the history
… document
  • Loading branch information
Nuno Oliveira committed Nov 15, 2017
1 parent 4cc238e commit f9d6800
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,20 @@ public Set<String> getLayerStyles() {
public List<String> getLegalValues() {
checkInitialized();
Set<String> layerStyles = getLayerStyles();
// will contain the layer legal \ allowed styles
List<String> finalStyles = new ArrayList<>();
if (allowedStyles==null) {
// Values is null so allow any of the backing layer's styles
return new ArrayList<String>(layerStyles);
finalStyles.addAll(layerStyles);
} else {
// Values is set so only allow the intersection of the specified styles and those of the backing layer.
return new ArrayList<String>(Sets.intersection(layerStyles, allowedStyles));
finalStyles.addAll(Sets.intersection(layerStyles, allowedStyles));
}
// make sure layer default style is considered a legal style
if (defaultStyle != null && !finalStyles.contains(defaultStyle)) {
finalStyles.add(defaultStyle);
}
return finalStyles;
}

/**
Expand Down
87 changes: 35 additions & 52 deletions src/gwc/src/test/java/org/geoserver/gwc/GWCIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,22 @@
@TestSetup(run=TestSetupFrequency.REPEAT)
public class GWCIntegrationTest extends GeoServerSystemTestSupport {

// WMTS 1.0 namespaces
private static final Map<String, String> WMTS_NAMESPACES_10 = new HashMap<>();

static {
// populate WMTS 1.0 namespaces map
WMTS_NAMESPACES_10.put("xlink", "http://www.w3.org/1999/xlink");
WMTS_NAMESPACES_10.put("xsi", "http://www.w3.org/2001/XMLSchema-instance");
WMTS_NAMESPACES_10.put("ows", "http://www.opengis.net/ows/1.1");
WMTS_NAMESPACES_10.put("wmts", "http://www.opengis.net/wmts/1.0");
// set this as the default namespaces
XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(WMTS_NAMESPACES_10));
}

// WMTS 1.0 XPATH engine
private static final XpathEngine WMTS_XPATH_10 = XMLUnit.newXpathEngine();

static final String SIMPLE_LAYER_GROUP = "SIMPLE_LAYER_GROUP";

static final String FLAT_LAYER_GROUP = "flatLayerGroup";
Expand Down Expand Up @@ -960,58 +976,34 @@ public void testRemoveCachedLayer() throws Exception {

@Test
public void testGetCapabilitiesWithLocalWorkspace() throws Exception {
// initiating the xpath engine
Map<String, String> namespaces = new HashMap<>();
namespaces.put("xlink", "http://www.w3.org/1999/xlink");
namespaces.put("xsi", "http://www.w3.org/2001/XMLSchema-instance");
namespaces.put("ows", "http://www.opengis.net/ows/1.1");
namespaces.put("wmts", "http://www.opengis.net/wmts/1.0");
XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(namespaces));
XpathEngine xpath = XMLUnit.newXpathEngine();
// getting capabilities document for CITE workspace
Document document = getAsDOM(MockData.CITE_PREFIX + "/gwc/service/wmts?request=GetCapabilities");
// checking get capabilities result for CITE workspace
List<LayerInfo> citeLayers = getWorkspaceLayers(MockData.CITE_PREFIX);
assertThat(Integer.parseInt(xpath.evaluate("count(//wmts:Contents/wmts:Layer)", document)), greaterThan(0));
assertThat(Integer.parseInt(xpath.evaluate("count(//wmts:Contents/wmts:Layer)", document)), lessThanOrEqualTo(citeLayers.size()));
assertThat(xpath.evaluate("count(//wmts:Contents/wmts:Layer[ows:Identifier='" +
assertThat(Integer.parseInt(WMTS_XPATH_10.evaluate("count(//wmts:Contents/wmts:Layer)", document)), greaterThan(0));
assertThat(Integer.parseInt(WMTS_XPATH_10.evaluate("count(//wmts:Contents/wmts:Layer)", document)), lessThanOrEqualTo(citeLayers.size()));
assertThat(WMTS_XPATH_10.evaluate("count(//wmts:Contents/wmts:Layer[ows:Identifier='" +
MockData.BUILDINGS.getLocalPart() + "'])", document), is("1"));
}

@Test
public void testGetCapabilitiesWithLocalLayer() throws Exception {
// initiating the xpath engine
Map<String, String> namespaces = new HashMap<>();
namespaces.put("xlink", "http://www.w3.org/1999/xlink");
namespaces.put("xsi", "http://www.w3.org/2001/XMLSchema-instance");
namespaces.put("ows", "http://www.opengis.net/ows/1.1");
namespaces.put("wmts", "http://www.opengis.net/wmts/1.0");
XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(namespaces));
XpathEngine xpath = XMLUnit.newXpathEngine();
// getting capabilities document for CITE workspace
Document document = getAsDOM(MockData.CITE_PREFIX + "/" + MockData.BUILDINGS.getLocalPart() + "/gwc/service/wmts?request=GetCapabilities");
// checking get capabilities result for CITE workspace
List<LayerInfo> citeLayers = getWorkspaceLayers(MockData.CITE_PREFIX);
assertThat(Integer.parseInt(xpath.evaluate("count(//wmts:Contents/wmts:Layer)", document)), equalTo(1));
assertThat(xpath.evaluate("count(//wmts:Contents/wmts:Layer[ows:Identifier='" +
assertThat(Integer.parseInt(WMTS_XPATH_10.evaluate("count(//wmts:Contents/wmts:Layer)", document)), equalTo(1));
assertThat(WMTS_XPATH_10.evaluate("count(//wmts:Contents/wmts:Layer[ows:Identifier='" +
MockData.BUILDINGS.getLocalPart() + "'])", document), is("1"));
}

@Test
public void testGetCapabilitiesWithLocalGroup() throws Exception {
// initiating the xpath engine
Map<String, String> namespaces = new HashMap<>();
namespaces.put("xlink", "http://www.w3.org/1999/xlink");
namespaces.put("xsi", "http://www.w3.org/2001/XMLSchema-instance");
namespaces.put("ows", "http://www.opengis.net/ows/1.1");
namespaces.put("wmts", "http://www.opengis.net/wmts/1.0");
XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(namespaces));
XpathEngine xpath = XMLUnit.newXpathEngine();
// getting capabilities document for CITE workspace
Document document = getAsDOM(SIMPLE_LAYER_GROUP + "/gwc/service/wmts?request=GetCapabilities");
// checking get capabilities result for CITE workspace
assertThat(Integer.parseInt(xpath.evaluate("count(//wmts:Contents/wmts:Layer)", document)), equalTo(1));
assertThat(xpath.evaluate("count(//wmts:Contents/wmts:Layer[ows:Identifier='" +
assertThat(Integer.parseInt(WMTS_XPATH_10.evaluate("count(//wmts:Contents/wmts:Layer)", document)), equalTo(1));
assertThat(WMTS_XPATH_10.evaluate("count(//wmts:Contents/wmts:Layer[ows:Identifier='" +
SIMPLE_LAYER_GROUP + "'])", document), is("1"));
}

Expand Down Expand Up @@ -1072,30 +1064,29 @@ public void testWMTSEnabling() throws Exception {
}

@Test
public void testGetCapabilitiesRequest() throws Exception {
public void testWmtsGetCapabilitiesRequest() throws Exception {
// getting the capabilities document
MockHttpServletResponse response = getAsServletResponse("/gwc/service/wmts?request=GetCapabilities");
// check that the request was successful
assertThat(response.getStatus(), is(200));
// parse XML response content
Document document = dom(response, false);
// check that default styles are advertised
WMTS_XPATH_10.evaluate("count(//wmts:Contents/wmts:Layer/wmts:Style[@isDefault='true']" +
"/ows:Identifier[text()=Default])", document);

}

@Test
public void testGetCapabilitiesRequestRestEndpoints() throws Exception {

int totLayers = getCatalog().getLayers().size();

Map<String, String> namespaces = new HashMap<>();
namespaces.put("xlink", "http://www.w3.org/1999/xlink");
namespaces.put("xsi", "http://www.w3.org/2001/XMLSchema-instance");
namespaces.put("ows", "http://www.opengis.net/ows/1.1");
namespaces.put("wmts", "http://www.opengis.net/wmts/1.0");
XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(namespaces));
XpathEngine xpath = XMLUnit.newXpathEngine();
// getting capabilities document for CITE workspace
Document doc = getAsDOM("/gwc/service/wmts?request=GetCapabilities");
// checking ResourceURL
assertEquals(String.valueOf(totLayers),
xpath.evaluate(
WMTS_XPATH_10.evaluate(
"count(//wmts:Contents/wmts:Layer/wmts:ResourceURL[@resourceType='tile']"
+ "[@format='image/png']"
+ "[contains(@template,'http://localhost:8080/geoserver/gwc"
Expand All @@ -1104,7 +1095,7 @@ public void testGetCapabilitiesRequestRestEndpoints() throws Exception {
doc));

assertEquals(String.valueOf(totLayers),
xpath.evaluate(
WMTS_XPATH_10.evaluate(
"count(//wmts:Contents/wmts:Layer/wmts:ResourceURL[@resourceType='FeatureInfo']"
+ "[@format='text/plain']"
+ "[contains(@template,'http://localhost:8080/geoserver/gwc"
Expand All @@ -1113,12 +1104,12 @@ public void testGetCapabilitiesRequestRestEndpoints() throws Exception {
doc));

// checking the service metadata URL
assertEquals("1", xpath.evaluate(
assertEquals("1", WMTS_XPATH_10.evaluate(
"count(//wmts:ServiceMetadataURL[@xlink:href='http://localhost:8080/geoserver/gwc"
+ WMTSService.SERVICE_PATH + "?REQUEST=getcapabilities&VERSION=1.0.0'])",
doc));
assertEquals("1",
xpath.evaluate(
WMTS_XPATH_10.evaluate(
"count(//wmts:ServiceMetadataURL[@xlink:href='http://localhost:8080/geoserver/gwc"
+ WMTSService.REST_PATH + "/WMTSCapabilities.xml'])",
doc));
Expand Down Expand Up @@ -1214,16 +1205,8 @@ public void testGetCapabilitiesWithRestEndpointsAndDimensions() throws Exception
response.getContentAsString().getBytes());
Document doc = dom(bain, true);

Map<String, String> namespaces = new HashMap<>();
namespaces.put("xlink", "http://www.w3.org/1999/xlink");
namespaces.put("xsi", "http://www.w3.org/2001/XMLSchema-instance");
namespaces.put("ows", "http://www.opengis.net/ows/1.1");
namespaces.put("wmts", "http://www.opengis.net/wmts/1.0");
XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(namespaces));
XpathEngine xpath = XMLUnit.newXpathEngine();

assertEquals("1",
xpath.evaluate(
WMTS_XPATH_10.evaluate(
"count(//wmts:Contents/wmts:Layer/wmts:ResourceURL[@resourceType='tile']"
+ "[@format='image/png']"
+ "[contains(@template,'http://localhost:8080/geoserver/gwc"
Expand Down
5 changes: 5 additions & 0 deletions src/gwc/src/test/java/org/geoserver/gwc/GWCTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1303,6 +1303,11 @@ public void testDispatchGetMapWithMatchingParameterFilters() throws Exception {

for (String style : tileLayer.getInfo().cachedStyles()) {

if (style != null && style.equals("default")) {
// if no styles are provided WMTS assumes a default style named default
continue;
}

String rawKvpParamName = "styles";
String rawKvpParamValue = style;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ public void testGetParameterFilters() {
StyleParameterFilter styleFilter = (StyleParameterFilter) parameterFilters.get(0);
assertEquals("STYLES", styleFilter.getKey());
assertEquals("default_style", styleFilter.getDefaultValue());
assertEquals(new HashSet<String>(Arrays.asList("alternateStyle-1", "alternateStyle-2")),
new HashSet<String>(styleFilter.getLegalValues()));
assertEquals(new HashSet<>(Arrays.asList("default_style", "alternateStyle-1", "alternateStyle-2")),
new HashSet<>(styleFilter.getLegalValues()));

// layerInfoTileLayer.getInfo().getCachedStyles().add("alternateStyle-2");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1465,7 +1465,25 @@ protected Document postAsDOM( String path, String xml, List<Exception> validatio
protected String getAsString(String path) throws Exception {
return string(get(path));
}


/**
* Helper method that extracts the content of HTTP response assuming that the content is XML and parse it.
*
* @param response HTTP response expected to contain XML content
* @param skipSchemaValidation if TRUE XML schema validate wil be performed
*
* @return the parsed response XML content
*/
protected Document dom(MockHttpServletResponse response, boolean skipSchemaValidation) {
try (InputStream input = new ByteArrayInputStream(response.getContentAsString().getBytes())) {
// parse response XMl content
return dom(input, skipSchemaValidation);
} catch (Exception exception) {
// something bad happen, since this is test code we just throw an exception
throw new RuntimeException("Something bad happen when parsing response XML content.", exception);
}
}

/**
* Parses a stream into a dom.
*/
Expand Down

0 comments on commit f9d6800

Please sign in to comment.