001: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
002: * This code is licensed under the GPL 2.0 license, availible at the root
003: * application directory.
004: */
005: package org.vfny.geoserver.requests.wms;
006:
007: import com.meterware.httpunit.GetMethodWebRequest;
008: import com.meterware.httpunit.PostMethodWebRequest;
009: import com.meterware.httpunit.WebConversation;
010: import com.meterware.httpunit.WebRequest;
011: import com.meterware.httpunit.WebResponse;
012: import org.vfny.geoserver.AbstractGeoserverHttpTest;
013: import java.awt.image.BufferedImage;
014: import java.io.ByteArrayInputStream;
015: import java.io.InputStream;
016: import javax.imageio.ImageIO;
017:
018: public class GetMapTestHttp extends AbstractGeoserverHttpTest {
019: String bbox = "-130,24,-66,50";
020: String styles = "population";
021: String layers = "states";
022:
023: public void testImage() throws Exception {
024: if (isOffline()) {
025: return;
026: }
027:
028: WebConversation conversation = new WebConversation();
029: WebRequest request = new GetMethodWebRequest(getBaseUrl()
030: + "/wms?bbox=" + bbox + "&styles=" + styles
031: + "&layers=" + layers + "&Format=image/png"
032: + "&request=GetMap" + "&width=550" + "&height=250"
033: + "&srs=EPSG:4326");
034:
035: WebResponse response = conversation.getResponse(request);
036: assertEquals("image/png", response.getContentType());
037:
038: try {
039: BufferedImage image = ImageIO.read(response
040: .getInputStream());
041: assertNotNull(image);
042: assertEquals(image.getWidth(), 550);
043: assertEquals(image.getHeight(), 250);
044: } catch (Throwable t) {
045: t.printStackTrace();
046: fail("Could not read image returned from GetMap:"
047: + t.getLocalizedMessage());
048: }
049: }
050:
051: public void testSldBody() throws Exception {
052: if (isOffline()) {
053: return;
054: }
055:
056: WebConversation conversation = new WebConversation();
057: WebRequest request = new GetMethodWebRequest(
058: getBaseUrl()
059: + "/wms?bbox="
060: + bbox
061: + "&styles="
062: + styles
063: + "&layers="
064: + layers
065: + "&Format=image/png"
066: + "&request=GetMap"
067: + "&width=550"
068: + "&height=250"
069: + "&srs=EPSG:4326"
070: + "&SLD_BODY=%3CStyledLayerDescriptor%20version=%221.0.0%22%3E%3CUserLayer%3E%3CName%3Etopp:states%3C/Name%3E%3CUserStyle%3E%3CName%3EUserSelection%3C/Name%3E%3CFeatureTypeStyle%3E%3CRule%3E%3CFilter%20xmlns:gml=%22http://www.opengis.net/gml%22%3E%3CPropertyIsEqualTo%3E%3CPropertyName%3ESTATE_NAME%3C/PropertyName%3E%3CLiteral%3EIllinois%3C/Literal%3E%3C/PropertyIsEqualTo%3E%3C/Filter%3E%3CPolygonSymbolizer%3E%3CFill%3E%3CCssParameter%20name=%22fill%22%3E%23FF0000%3C/CssParameter%3E%3C/Fill%3E%3C/PolygonSymbolizer%3E%3C/Rule%3E%3CRule%3E%3CLineSymbolizer%3E%3CStroke/%3E%3C/LineSymbolizer%3E%3C/Rule%3E%3C/FeatureTypeStyle%3E%3C/UserStyle%3E%3C/UserLayer%3E%3C/StyledLayerDescriptor%3E");
071:
072: WebResponse response = conversation.getResponse(request);
073: assertEquals("image/png", response.getContentType());
074:
075: try {
076: BufferedImage image = ImageIO.read(response
077: .getInputStream());
078: assertNotNull(image);
079: assertEquals(image.getWidth(), 550);
080: assertEquals(image.getHeight(), 250);
081: } catch (Throwable t) {
082: t.printStackTrace();
083: fail("Could not read image returned from GetMap:"
084: + t.getLocalizedMessage());
085: }
086: }
087:
088: public void testSldBodyPost() throws Exception {
089: if (isOffline()) {
090: return;
091: }
092:
093: InputStream in = new ByteArrayInputStream(STATES_SLD.getBytes());
094:
095: WebConversation conversation = new WebConversation();
096: WebRequest request = new PostMethodWebRequest(getBaseUrl()
097: + "/wms?bbox=" + bbox + "&Format=image/png"
098: + "&request=GetMap" + "&width=550" + "&height=250"
099: + "&srs=EPSG:4326", in, "text/xml");
100:
101: WebResponse response = conversation.getResponse(request);
102: assertEquals("image/png", response.getContentType());
103:
104: try {
105: BufferedImage image = ImageIO.read(response
106: .getInputStream());
107: assertNotNull(image);
108: assertEquals(image.getWidth(), 550);
109: assertEquals(image.getHeight(), 250);
110: } catch (Throwable t) {
111: t.printStackTrace();
112: fail("Could not read image returned from GetMap:"
113: + t.getLocalizedMessage());
114: }
115: }
116:
117: public void testXmlPost() throws Exception {
118: if (isOffline()) {
119: return;
120: }
121:
122: InputStream in = new ByteArrayInputStream(STATES_GETMAP
123: .getBytes());
124:
125: WebConversation conversation = new WebConversation();
126: WebRequest request = new PostMethodWebRequest(getBaseUrl()
127: + "/wms", in, "text/xml");
128:
129: WebResponse response = conversation.getResponse(request);
130: assertEquals("image/png", response.getContentType());
131:
132: try {
133: BufferedImage image = ImageIO.read(response
134: .getInputStream());
135: assertNotNull(image);
136: assertEquals(image.getWidth(), 550);
137: assertEquals(image.getHeight(), 250);
138: } catch (Throwable t) {
139: t.printStackTrace();
140: fail("Could not read image returned from GetMap:"
141: + t.getLocalizedMessage());
142: }
143: }
144:
145: public static final String STATES_SLD = "<StyledLayerDescriptor version=\"1.0.0\">"
146: + "<UserLayer>"
147: + "<Name>topp:states</Name>"
148: + "<UserStyle>"
149: + "<Name>UserSelection</Name>"
150: + "<FeatureTypeStyle>"
151: + "<Rule>"
152: + "<Filter xmlns:gml=\"http://www.opengis.net/gml\">"
153: + "<PropertyIsEqualTo>"
154: + "<PropertyName>STATE_NAME</PropertyName>"
155: + "<Literal>Illinois</Literal>"
156: + "</PropertyIsEqualTo>"
157: + "</Filter>"
158: + "<PolygonSymbolizer>"
159: + "<Fill>"
160: + "<CssParameter name=\"fill\">#FF0000</CssParameter>"
161: + "</Fill>"
162: + "</PolygonSymbolizer>"
163: + "</Rule>"
164: + "<Rule>"
165: + "<LineSymbolizer>"
166: + "<Stroke/>"
167: + "</LineSymbolizer>"
168: + "</Rule>"
169: + "</FeatureTypeStyle>"
170: + "</UserStyle>"
171: + "</UserLayer>" + "</StyledLayerDescriptor>";
172: public static final String STATES_GETMAP = //
173: "<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n "
174: + "<ogc:GetMap service=\"WMS\" version=\"1.1.1\" \n "
175: + " xmlns:gml=\"http://www.opengis.net/gml\"\n "
176: + " xmlns:ogc=\"http://www.opengis.net/ows\"\n "
177: + " xmlns:sld=\"http://www.opengis.net/sld\"\n "
178: + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n "
179: + " xsi:schemaLocation=\"http://www.opengis.net/ows GetMap.xsd http://www.opengis.net/gml geometry.xsd http://www.opengis.net/sld StyledLayerDescriptor.xsd \">\n "
180: + " <sld:StyledLayerDescriptor>\n "
181: + " <sld:NamedLayer>\n "
182: + " <sld:Name>topp:states</sld:Name>\n "
183: + " <sld:NamedStyle>\n "
184: + " <sld:Name>population</sld:Name>\n "
185: + " </sld:NamedStyle>\n "
186: + " </sld:NamedLayer>\n "
187: + " </sld:StyledLayerDescriptor>\n "
188: + " <ogc:BoundingBox srsName=\"4326\">\n "
189: + " <gml:coord>\n "
190: + " <gml:X>-130</gml:X>\n "
191: + " <gml:Y>24</gml:Y>\n "
192: + " </gml:coord>\n "
193: + " <gml:coord>\n "
194: + " <gml:X>-66</gml:X>\n "
195: + " <gml:Y>50</gml:Y>\n "
196: + " </gml:coord>\n "
197: + " </ogc:BoundingBox>\n "
198: + " <ogc:Output>\n "
199: + " <ogc:Format>image/png</ogc:Format>\n "
200: + " <ogc:Size>\n "
201: + " <ogc:Width>550</ogc:Width>\n "
202: + " <ogc:Height>250</ogc:Height>\n "
203: + " </ogc:Size>\n "
204: + " </ogc:Output>\n " + "</ogc:GetMap>\n ";
205: }
|