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.geoserver.wms;
006:
007: import com.vividsolutions.jts.geom.Envelope;
008: import org.geoserver.test.GeoServerTestSupport;
009: import org.geotools.data.DataStore;
010: import org.geotools.data.wfs.WFSDataStoreFactory;
011: import org.geotools.map.DefaultMapLayer;
012: import org.geotools.map.MapLayer;
013: import org.geotools.referencing.crs.DefaultGeographicCRS;
014: import org.geotools.styling.Style;
015: import org.vfny.geoserver.global.ConfigurationException;
016: import org.vfny.geoserver.global.FeatureTypeInfo;
017: import org.vfny.geoserver.global.MapLayerInfo;
018: import org.vfny.geoserver.global.WMS;
019: import org.vfny.geoserver.global.dto.CoverageInfoDTO;
020: import org.vfny.geoserver.global.dto.FeatureTypeInfoDTO;
021: import org.vfny.geoserver.wms.requests.GetMapRequest;
022: import org.vfny.geoserver.wms.servlets.GetMap;
023: import java.io.IOException;
024: import java.lang.reflect.Array;
025: import java.net.MalformedURLException;
026: import java.net.URL;
027: import java.util.ArrayList;
028: import java.util.HashMap;
029: import java.util.List;
030: import java.util.Map;
031: import java.util.logging.Level;
032:
033: import javax.xml.namespace.QName;
034:
035: /**
036: * Base support class for wms tests.
037: * <p>
038: * Deriving from this test class provides the test case with preconfigured
039: * geoserver and wms objects.
040: * </p>
041: * @author Justin Deoliveira, The Open Planning Project, jdeolive@openplans.org
042: *
043: */
044: public class WMSTestSupport extends GeoServerTestSupport {
045: /**
046: * @return The global wms singleton from the application context.
047: */
048: protected WMS getWMS() {
049: return (WMS) applicationContext.getBean("wms");
050: }
051:
052: /**
053: * Convenience method for subclasses to create a map layer from a layer name.
054: * <p>
055: * The map layer is created with the default style for the layer.
056: * </p>
057: * @param layerName The name of the layer.
058: *
059: * @return A new map layer.
060: */
061: protected MapLayer createMapLayer(QName layerName)
062: throws IOException {
063: //TODO: support coverages
064: FeatureTypeInfo info = getCatalog().getFeatureTypeInfo(
065: layerName);
066: Style style = info.getDefaultStyle();
067:
068: DefaultMapLayer layer = new DefaultMapLayer(info
069: .getFeatureSource(), style);
070: layer.setTitle(info.getTypeName());
071:
072: return layer;
073: }
074:
075: /**
076: * Calls through to {@link #createGetMapRequest(QName[])}.
077: *
078: */
079: protected GetMapRequest createGetMapRequest(QName layerName) {
080: return createGetMapRequest(new QName[] { layerName });
081: }
082:
083: /**
084: * Convenience method for subclasses to create a new GetMapRequest object.
085: * <p>
086: * The returned object has the following properties:
087: * <ul>
088: * <li>styles set to default styles for layers specified
089: * <li>bbox set to (-180,-90,180,180 )
090: * <li>crs set to epsg:4326
091: * </ul>
092: * Caller must set additional parameters of request as need be.
093: * </p>
094: *
095: * @param The layer names of the request.
096: *
097: * @return A new GetMapRequest object.
098: */
099: protected GetMapRequest createGetMapRequest(QName[] layerNames) {
100: GetMapRequest request = new GetMapRequest(new GetMap(getWMS()));
101: request.setHttpServletRequest(createRequest("wms"));
102:
103: MapLayerInfo[] layers = new MapLayerInfo[layerNames.length];
104: List styles = new ArrayList();
105:
106: for (int i = 0; i < layerNames.length; i++) {
107: FeatureTypeInfo ftInfo = getCatalog().getFeatureTypeInfo(
108: layerNames[i]);
109: styles.add(ftInfo.getDefaultStyle());
110:
111: layers[i] = new MapLayerInfo(ftInfo);
112: }
113:
114: request.setLayers(layers);
115: request.setStyles(styles);
116: request.setBbox(new Envelope(-180, -90, 180, 90));
117: request.setCrs(DefaultGeographicCRS.WGS84);
118: request.setSRS("EPSG:4326");
119: request.setRawKvp(new HashMap());
120: return request;
121: }
122:
123: }
|