diff --git a/src/extension/mapml/src/test/java/org/geoserver/mapml/MapMLBaseProxyTest.java b/src/extension/mapml/src/test/java/org/geoserver/mapml/MapMLBaseProxyTest.java index 4d84bb11989..f1fc438767d 100644 --- a/src/extension/mapml/src/test/java/org/geoserver/mapml/MapMLBaseProxyTest.java +++ b/src/extension/mapml/src/test/java/org/geoserver/mapml/MapMLBaseProxyTest.java @@ -13,9 +13,14 @@ import com.github.tomakehurst.wiremock.client.WireMock; import com.github.tomakehurst.wiremock.core.WireMockConfiguration; import java.io.ByteArrayInputStream; +import java.net.URL; import java.util.Map; import org.custommonkey.xmlunit.XMLUnit; import org.custommonkey.xmlunit.XpathEngine; +import org.geotools.ows.wms.WMSCapabilities; +import org.geotools.ows.wms.WebMapServer; +import org.geotools.ows.wmts.WebMapTileServer; +import org.geotools.ows.wmts.model.WMTSCapabilities; import org.junit.AfterClass; import org.junit.Before; import org.springframework.http.MediaType; @@ -105,11 +110,32 @@ protected void checkCascading( } } - protected void assertCascading(boolean shouldCascade, String url) { + protected void assertCascading(boolean shouldCascade, String url) throws Exception { + if (shouldCascade) { - assertTrue( - url.startsWith( - "http://localhost:" + mockService.port() + MOCK_SERVER + CONTEXT)); + URL getResourceURL = null; + boolean cascadingWMS = getCapabilitiesURL().matches(".*SERVICE=WMS.*"); + if (cascadingWMS) { + WebMapServer wms = new WebMapServer(new URL(getCapabilitiesURL())); + WMSCapabilities capabilities = wms.getCapabilities(); + getResourceURL = capabilities.getRequest().getGetMap().getGet(); + } else { + WebMapTileServer wmts = new WebMapTileServer(new URL(getCapabilitiesURL())); + WMTSCapabilities capabilities = wmts.getCapabilities(); + getResourceURL = capabilities.getRequest().getGetTile().getGet(); + } + URL base = + new URL( + getResourceURL.getProtocol() + + "://" + + getResourceURL.getHost() + + (getResourceURL.getPort() == -1 + ? "" + : ":" + getResourceURL.getPort()) + + "/"); + String path = getResourceURL.getPath(); + + assertTrue(url.startsWith((new URL(base, path)).toString())); assertTrue(url.contains("layers=topp:states")); } else { assertTrue(url.startsWith("http://localhost:8080/geoserver" + CONTEXT));