WMTSCapabilitiesParser { public static WMTSCapabilities parseCapabilities(String xml) throws IllegalArgumentException, XMLStreamException { OMElement doc = XmlHelper.parseXML(xml); if (doc == null) { throw new XMLStreamException("Failed to parse XML"); } return parseCapabilities(doc); }  static WMTSCapabilities parseCapabilities(String xml); static WMTSCapabilities parseCapabilities(InputStream in); static WMTSCapabilities parseCapabilities(OMElement doc); static JSONObject asJSON(WMTSCapabilities caps, String url, String currentCrs);  }
@Test public void testASDIParsing() throws Exception { WMTSCapabilities caps = WMTSCapabilitiesParser.parseCapabilities(capabilitiesInput_ASDI); Set<String> crss = new HashSet<>(); crss.add("EPSG:3575"); OskariLayer layer = new OskariLayer(); layer.setId(1); layer.setName("arcticsdi_wmts"); JSONObject options = layer.getOptions(); options.put("format", "REST"); assertTrue(options.has("format")); OskariLayerCapabilitiesHelper.setPropertiesFromCapabilitiesWMTS(caps, layer, crss); assertFalse("'format' value should have been removed since the layer doesn't support RESTful WMTS", options.has("format")); }
@Test public void parsesTileMatrixSetInformationCorrectly() throws IOException, IllegalArgumentException, XMLStreamException { List<TileMatrix> tileMatrices = new ArrayList<>(16); final double[] topLeftCorner = { -548576.0, 8388608.0 }; double scaleDenominator = 29257142.85714285820722579956; for (int i = 0; i <= 15; i++) { int len = 1 << i; tileMatrices.add(new TileMatrix("" + i, scaleDenominator, topLeftCorner, 256, 256, len, len)); scaleDenominator /= 2; } TileMatrixSet expected = new TileMatrixSet("ETRS-TM35FIN", "urn:ogc:def:crs:EPSG:6.3:3067", tileMatrices); WMTSCapabilities wmtsCapabilities; try (InputStream in = new BufferedInputStream( getClass().getClassLoader().getResourceAsStream("WMTSCapabilities.xml"))) { wmtsCapabilities = WMTSCapabilitiesParser.parseCapabilities(in); } Collection<TileMatrixSet> tileMatrixSets = wmtsCapabilities.getTileMatrixSets(); assertEquals(1, tileMatrixSets.size()); TileMatrixSet actual = tileMatrixSets.iterator().next(); assertEquals(expected.getId(), actual.getId()); assertEquals(expected.getCrs(), actual.getCrs()); Map<String, TileMatrix> eTileMatrises = expected.getTileMatrixMap(); Map<String, TileMatrix> aTileMatrises = actual.getTileMatrixMap(); assertEquals(eTileMatrises.size(), aTileMatrises.size()); for (String key : eTileMatrises.keySet()) { assertTrue(aTileMatrises.containsKey(key)); TileMatrix eMatrix = eTileMatrises.get(key); TileMatrix aMatrix = aTileMatrises.get(key); assertEquals(eMatrix.getId(), aMatrix.getId()); assertEquals(eMatrix.getScaleDenominator(), aMatrix.getScaleDenominator(), 0); assertEquals(eMatrix.getMatrixWidth(), aMatrix.getMatrixWidth()); assertEquals(eMatrix.getMatrixHeight(), aMatrix.getMatrixHeight()); assertEquals(eMatrix.getTileWidth(), aMatrix.getTileWidth()); assertEquals(eMatrix.getTileHeight(), aMatrix.getTileHeight()); assertEquals(eMatrix.getId(), aMatrix.getId()); assertArrayEquals(eMatrix.getTopLeftCorner(), aMatrix.getTopLeftCorner(), 0); } }