001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2004-2006, Geotools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.data.wms.xml.test;
017:
018: import java.io.File;
019: import java.net.URI;
020: import java.net.URISyntaxException;
021: import java.net.URL;
022: import java.util.logging.Level;
023:
024: import junit.framework.TestCase;
025:
026: import org.geotools.data.ows.CRSEnvelope;
027: import org.geotools.data.ows.Layer;
028: import org.geotools.data.ows.WMSCapabilities;
029: import org.geotools.data.wms.xml.WMSSchema;
030: import org.geotools.test.TestData;
031: import org.geotools.wms.v1_1_1.bindings.WMSV1_1_1Configuration;
032: import org.geotools.xml.DocumentFactory;
033: import org.geotools.xml.Parser;
034: import org.geotools.xml.SchemaFactory;
035: import org.geotools.xml.schema.Schema;
036:
037: public class WMSSchemaTest extends TestCase {
038:
039: public void testSchema() throws URISyntaxException {
040: Schema v1 = SchemaFactory.getInstance(new URI(
041: "http://www.opengis.net/wms"));
042: assertNotNull(v1);
043: Schema v2 = WMSSchema.getInstance();
044: assertNotNull(v2);
045: assertEquals(v1, v2);
046: }
047:
048: public void testGetCapabilities() throws Exception {
049:
050: File getCaps = TestData.file(this , "1.3.0Capabilities.xml");
051: URL getCapsURL = getCaps.toURL();
052:
053: Object object = DocumentFactory.getInstance(getCapsURL
054: .openStream(), null, Level.WARNING);
055: //Object object = new Parser(new WMSV1_1_1Configuration()).parse(getCapsURL.openStream());
056:
057: Schema schema = WMSSchema.getInstance();
058: SchemaFactory.getInstance(WMSSchema.NAMESPACE);
059:
060: assertTrue("Capabilities failed to parse",
061: object instanceof WMSCapabilities);
062:
063: WMSCapabilities capabilities = (WMSCapabilities) object;
064:
065: assertEquals(capabilities.getVersion(), "1.3.0");
066: assertEquals(capabilities.getService().getName(), "WMS");
067: assertEquals(capabilities.getService().getTitle(), "World Map");
068: assertEquals(capabilities.getService().get_abstract(), "None");
069: assertEquals(capabilities.getService().getOnlineResource(),
070: new URL("http://www2.demis.nl"));
071:
072: assertEquals(capabilities.getService().getLayerLimit(), 40);
073: assertEquals(capabilities.getService().getMaxWidth(), 2000);
074: assertEquals(capabilities.getService().getMaxHeight(), 2000);
075:
076: assertEquals(capabilities.getRequest().getGetCapabilities()
077: .getFormats().get(0), "text/xml");
078: assertEquals(capabilities.getRequest().getGetCapabilities()
079: .getGet(), new URL(
080: "http://www2.demis.nl/wms/wms.asp?wms=WorldMap&"));
081: assertEquals(capabilities.getRequest().getGetCapabilities()
082: .getPost(), new URL(
083: "http://www2.demis.nl/wms/wms.asp?wms=WorldMap&"));
084:
085: assertEquals(capabilities.getRequest().getGetMap().getFormats()
086: .size(), 5);
087: assertEquals(capabilities.getRequest().getGetMap().getFormats()
088: .get(0), "image/gif");
089: assertEquals(capabilities.getRequest().getGetMap().getFormats()
090: .get(1), "image/png");
091: assertEquals(capabilities.getRequest().getGetMap().getFormats()
092: .get(2), "image/jpeg");
093: assertEquals(capabilities.getRequest().getGetMap().getFormats()
094: .get(3), "image/bmp");
095: assertEquals(capabilities.getRequest().getGetMap().getFormats()
096: .get(4), "image/swf");
097: assertEquals(
098: capabilities.getRequest().getGetMap().getGet(),
099: new URL(
100: "http://www2.demis.nl/wms/wms.asp?wms=WorldMap&"));
101:
102: assertEquals(capabilities.getRequest().getGetFeatureInfo()
103: .getFormats().size(), 4);
104: assertEquals(capabilities.getRequest().getGetFeatureInfo()
105: .getFormats().get(0), "text/xml");
106: assertEquals(capabilities.getRequest().getGetFeatureInfo()
107: .getFormats().get(1), "text/plain");
108: assertEquals(capabilities.getRequest().getGetFeatureInfo()
109: .getFormats().get(2), "text/html");
110: assertEquals(capabilities.getRequest().getGetFeatureInfo()
111: .getFormats().get(3), "text/swf");
112: assertEquals(capabilities.getRequest().getGetFeatureInfo()
113: .getGet(), new URL(
114: "http://www2.demis.nl/wms/wms.asp?wms=WorldMap&"));
115:
116: Layer topLayer = (Layer) capabilities.getLayerList().get(0);
117: assertNotNull(topLayer);
118: assertNull(topLayer.getParent());
119: assertFalse(topLayer.isQueryable());
120: assertEquals(topLayer.getTitle(), "World Map");
121: assertEquals(topLayer.getSrs().size(), 1);
122: assertTrue(topLayer.getSrs().contains("CRS:84"));
123:
124: CRSEnvelope llbbox = topLayer.getLatLonBoundingBox();
125: assertNotNull(llbbox);
126: assertEquals(llbbox.getMinX(), -180, 0.0);
127: assertEquals(llbbox.getMaxX(), 180, 0.0);
128: assertEquals(llbbox.getMinY(), -90, 0.0);
129: assertEquals(llbbox.getMaxY(), 90, 0.0);
130:
131: assertEquals(topLayer.getBoundingBoxes().size(), 1);
132:
133: CRSEnvelope bbox = (CRSEnvelope) topLayer.getBoundingBoxes()
134: .get("CRS:84");
135: assertNotNull(bbox);
136: assertEquals(bbox.getEPSGCode(), "CRS:84");
137: assertEquals(bbox.getMinX(), -184, 0.0);
138: assertEquals(bbox.getMaxX(), 180, 0.0);
139: assertEquals(bbox.getMinY(), -90.0000000017335, 0.0);
140: assertEquals(bbox.getMaxY(), 90, 0.0);
141:
142: Layer layer = (Layer) capabilities.getLayerList().get(1);
143: assertEquals(layer.getParent(), topLayer);
144: assertTrue(layer.isQueryable());
145: assertEquals(layer.getName(), "Bathymetry");
146: assertEquals(layer.getTitle(), "Bathymetry");
147:
148: // Added test to verify inheritance, should be same as previous llbbox
149: llbbox = layer.getLatLonBoundingBox();
150: assertNotNull(llbbox);
151: assertEquals(llbbox.getMinX(), -180, 0.0);
152: assertEquals(llbbox.getMaxX(), 180, 0.0);
153: assertEquals(llbbox.getMinY(), -90, 0.0);
154: assertEquals(llbbox.getMaxY(), 90, 0.0);
155:
156: bbox = (CRSEnvelope) layer.getBoundingBoxes().get("CRS:84");
157: assertNotNull(bbox);
158: assertEquals(bbox.getEPSGCode(), "CRS:84");
159: assertEquals(bbox.getMinX(), -180, 0.0);
160: assertEquals(bbox.getMaxX(), 180, 0.0);
161: assertEquals(bbox.getMinY(), -90, 0.0);
162: assertEquals(bbox.getMaxY(), 90, 0.0);
163:
164: assertEquals(capabilities.getLayerList().size(), 21);
165:
166: layer = (Layer) capabilities.getLayerList().get(20);
167: assertEquals(layer.getParent(), topLayer);
168: assertTrue(layer.isQueryable());
169: assertEquals(layer.getName(), "Ocean features");
170: assertEquals(layer.getTitle(), "Ocean features");
171:
172: // Added test to verify inheritance, should be same as previous llbbox
173: llbbox = layer.getLatLonBoundingBox();
174: assertNotNull(llbbox);
175: assertEquals(llbbox.getMinX(), -180, 0.0);
176: assertEquals(llbbox.getMaxX(), 180, 0.0);
177: assertEquals(llbbox.getMinY(), -90, 0.0);
178: assertEquals(llbbox.getMaxY(), 90, 0.0);
179:
180: bbox = (CRSEnvelope) layer.getBoundingBoxes().get("CRS:84");
181: assertNotNull(bbox);
182: assertEquals(bbox.getEPSGCode(), "CRS:84");
183: assertEquals(bbox.getMinX(), -180, 0.0);
184: assertEquals(bbox.getMaxX(), 179.999420166016, 0.0);
185: assertEquals(bbox.getMinY(), -62.9231796264648, 0.0);
186: assertEquals(bbox.getMaxY(), 68.6906585693359, 0.0);
187:
188: }
189: }
|