01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2004-2006, Geotools Project Managment Committee (PMC)
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2.1 of the License, or (at your option) any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: */
16: package org.geotools.data.ows.test;
17:
18: import java.io.File;
19: import java.net.URL;
20: import java.util.HashMap;
21: import java.util.Map;
22: import java.util.logging.Level;
23:
24: import junit.framework.TestCase;
25:
26: import org.geotools.data.ows.Layer;
27: import org.geotools.data.ows.StyleImpl;
28: import org.geotools.data.ows.WMSCapabilities;
29: import org.geotools.data.wms.xml.WMSSchema;
30: import org.geotools.test.TestData;
31: import org.geotools.xml.DocumentFactory;
32: import org.geotools.xml.SchemaFactory;
33: import org.geotools.xml.handlers.DocumentHandler;
34: import org.geotools.xml.schema.Schema;
35:
36: public class LayerInheritanceTest extends TestCase {
37:
38: public void testInheritCapabilities() throws Exception {
39:
40: File getCaps = TestData.file(this , "inheritCap.xml");
41: URL getCapsURL = getCaps.toURL();
42:
43: Map hints = new HashMap();
44: hints.put(DocumentHandler.DEFAULT_NAMESPACE_HINT_KEY, WMSSchema
45: .getInstance());
46: Object object = DocumentFactory.getInstance(getCapsURL
47: .openStream(), hints, Level.WARNING);
48:
49: Schema schema = WMSSchema.getInstance();
50: SchemaFactory.getInstance(WMSSchema.NAMESPACE);
51:
52: assertTrue("Capabilities failed to parse",
53: object instanceof WMSCapabilities);
54:
55: WMSCapabilities capabilities = (WMSCapabilities) object;
56:
57: // Get first test layer, it's nested 3 deep
58: Layer layer = (Layer) capabilities.getLayerList().get(2);
59: assertNotNull(layer);
60: assertNotNull(layer.getParent());
61:
62: // Should be false by default since not specified in layer or ancestors
63: assertFalse(layer.isQueryable());
64: assertEquals(layer.getTitle(), "Coastlines");
65:
66: // Should be 5 total after accumulating all ancestors
67: assertEquals(layer.getSrs().size(), 5);
68: assertTrue(layer.getSrs().contains("EPSG:26906"));
69: assertTrue(layer.getSrs().contains("EPSG:26905"));
70: assertTrue(layer.getSrs().contains("EPSG:4326"));
71: assertTrue(layer.getSrs().contains("AUTO:42003"));
72: assertTrue(layer.getSrs().contains("AUTO:42005"));
73:
74: // 2 total, this layer plus top most layer
75: assertEquals(layer.getStyles().size(), 2);
76: assertTrue(layer.getStyles().contains(
77: new StyleImpl("TestStyle")));
78: assertTrue(layer.getStyles().contains(new StyleImpl("default")));
79:
80: // Next test layer, nested 3 deep but different path
81: layer = (Layer) capabilities.getLayerList().get(4);
82: assertNotNull(layer);
83: assertNotNull(layer.getParent());
84:
85: // Should be true by default since inherited from parent
86: assertEquals(layer.getName(), "RTOPO");
87: assertTrue(layer.isQueryable());
88: }
89: }
|