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.gce.test;
017:
018: import java.net.URL;
019: import java.util.HashMap;
020: import java.util.Iterator;
021: import java.util.List;
022: import java.util.Map;
023: import java.util.Set;
024:
025: import junit.framework.TestCase;
026:
027: import org.geotools.data.ows.WMSCapabilities;
028: import org.geotools.data.wms.gce.WMSFormat;
029: import org.geotools.data.wms.gce.WMSGridCoverageExchange;
030: import org.geotools.data.wms.gce.WMSReader;
031: import org.geotools.data.wms.test.ServerTestCase;
032: import org.geotools.parameter.Parameter;
033: import org.geotools.parameter.DefaultParameterDescriptorGroup;
034: import org.geotools.parameter.ParameterGroup;
035: import org.geotools.referencing.AbstractIdentifiedObject;
036: import org.opengis.coverage.grid.GridCoverage;
037: import org.opengis.parameter.GeneralParameterDescriptor;
038: import org.opengis.parameter.GeneralParameterValue;
039: import org.opengis.parameter.ParameterDescriptor;
040: import org.opengis.parameter.ParameterValueGroup;
041:
042: /**
043: * DOCUMENT ME!
044: *
045: * @author rgould
046: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/plugin/wms/src/test/java/org/geotools/data/wms/gce/test/WMSReaderOnlineTest.java $
047: */
048: public class WMSReaderOnlineTest extends ServerTestCase {
049: WMSCapabilities capabilities;
050: WMSReader reader;
051: URL server;
052: WMSFormat format;
053:
054: public WMSReaderOnlineTest(String arg0) {
055: super (arg0);
056: }
057:
058: protected void setUp() throws Exception {
059: super .setUp();
060: server = new URL(
061: "http://terraservice.net/ogccapabilities.ashx?version=1.1.1&request=GetCapabilties");
062:
063: WMSGridCoverageExchange exchange = new WMSGridCoverageExchange(
064: server);
065:
066: reader = (WMSReader) exchange.getReader(server);
067: format = (WMSFormat) reader.getFormat();
068: }
069:
070: public void testGetFormat() {
071: assertEquals(new WMSFormat(null).getClass(), reader.getFormat()
072: .getClass());
073: }
074:
075: public void testHasMoreGridCoverages() {
076: }
077:
078: public void testRead() throws Exception {
079: ParameterValueGroup valueGroup = reader.getFormat()
080: .getReadParameters();
081:
082: DefaultParameterDescriptorGroup descriptorGroup = (DefaultParameterDescriptorGroup) valueGroup
083: .getDescriptor();
084:
085: List paramDescriptors = descriptorGroup.descriptors();
086: GeneralParameterValue[] generalParameterValues = new GeneralParameterValue[paramDescriptors
087: .size()];
088:
089: for (int i = 0; i < paramDescriptors.size(); i++) {
090: GeneralParameterDescriptor paramDescriptor = (GeneralParameterDescriptor) paramDescriptors
091: .get(i);
092: GeneralParameterValue generalParameterValue = paramDescriptor
093: .createValue();
094: generalParameterValues[i] = generalParameterValue;
095:
096: String parameterName = paramDescriptor.getName().getCode();
097:
098: if (parameterName.equals("LAYERS")) {
099: ParameterGroup groupValue = (ParameterGroup) generalParameterValue;
100: DefaultParameterDescriptorGroup groupDesc = (DefaultParameterDescriptorGroup) generalParameterValue
101: .getDescriptor();
102:
103: DefaultParameterDescriptorGroup layerGroup = (DefaultParameterDescriptorGroup) paramDescriptor;
104:
105: List layerDescriptors = layerGroup.descriptors();
106: GeneralParameterValue[] layerParameterValues = new GeneralParameterValue[layerDescriptors
107: .size()];
108:
109: for (int j = 0; j < layerDescriptors.size(); j++) {
110: GeneralParameterDescriptor layerDescriptor = (GeneralParameterDescriptor) layerDescriptors
111: .get(j);
112: Parameter layerValue = (Parameter) layerDescriptor
113: .createValue();
114: layerParameterValues[j] = layerValue;
115:
116: ParameterDescriptor layerDesc = (ParameterDescriptor) layerValue
117: .getDescriptor();
118: Set styles = layerDesc.getValidValues();
119: layerValue.setValue(styles.iterator().next());
120:
121: groupValue.values().add(layerValue);
122: }
123:
124: continue;
125: }
126:
127: Parameter value = (Parameter) generalParameterValue;
128: ParameterDescriptor desc = (ParameterDescriptor) generalParameterValue
129: .getDescriptor();
130:
131: if (parameterName.equals("FORMAT")) {
132: Iterator iter = desc.getValidValues().iterator();
133:
134: if (iter.hasNext()) {
135: String format = (String) iter.next();
136: value.setValue(format);
137: }
138:
139: continue;
140: }
141:
142: if (parameterName.equals("WIDTH")
143: || parameterName.equals("HEIGHT")) {
144: value.setValue(400);
145:
146: continue;
147: }
148:
149: if (parameterName.equals("SRS")) {
150: value.setValue("EPSG:4326");
151:
152: continue;
153: }
154:
155: if (parameterName.equals("BBOX_MINX")) {
156: value.setValue(-168.67);
157:
158: continue;
159: }
160:
161: if (parameterName.equals("BBOX_MINY")) {
162: value.setValue(17.84);
163:
164: continue;
165: }
166:
167: if (parameterName.equals("BBOX_MAXX")) {
168: value.setValue(-65.15);
169:
170: continue;
171: }
172:
173: if (parameterName.equals("BBOX_MAXY")) {
174: value.setValue(71.55);
175:
176: continue;
177: }
178:
179: if (parameterName.equals("VERSION")) {
180: value.setValue("1.1.1");
181:
182: continue;
183: }
184: }
185: //
186: // Map properties = new HashMap();
187: // properties.put(AbstractIdentifiedObject.NAME_KEY, "WMS");
188:
189: GridCoverage coverage = reader.read(generalParameterValues);
190: }
191: }
|