Permalink
Browse files

updated the way the http response object was being handled, added tes…

…ts to the isStable(Tile) method
  • Loading branch information...
1 parent 9779e66 commit e0c2786d4e109869568ae8234e5eb680cc75bf90 John Hudson committed Jan 24, 2012
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,162 @@
+/* uDig - User Friendly Desktop Internet GIS client
+ * http://udig.refractions.net
+ * (C) 2012, Refractions Research Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ */
+package net.refractions.udig.catalog.wmsc.server;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Set;
+
+import net.refractions.udig.catalog.tests.wmsc.Activator;
+
+import org.geotools.data.ResourceInfo;
+import org.geotools.data.ServiceInfo;
+import org.geotools.data.ows.AbstractOpenWebService;
+import org.geotools.data.ows.Specification;
+import org.geotools.data.wms.WMS1_1_1;
+import org.geotools.ows.ServiceException;
+import org.junit.Test;
+
+public class TileImageReadWriterTest {
+
+ static String serverURL = "http://localhost:8080/geoserver/ows?service=wms&version=1.3.0&request=GetCapabilities"; //$NON-NLS-1$
+
+ @Test
+ public void testIsStale() throws Exception {
+ Activator instance = Activator.getDefault();
+ assertNotNull("Run as a JUnit Plug-in Test", instance); //$NON-NLS-1$
+
+ MockTiledWebMapServer service = new MockTiledWebMapServer(new URL(serverURL));
+
+ TileImageReadWriter tileReadWriter = new TileImageReadWriter(service, "resources"); //$NON-NLS-1$
+
+ WMSTileSet tileSet = new WMSTileSet();
+ tileSet.setLayers("tasmania"); //$NON-NLS-1$
+ tileSet.setCoorindateReferenceSystem("WGS84(DD)"); //$NON-NLS-1$
+ tileSet.setFormat("image/png"); //$NON-NLS-1$
+
+ WMSTile tile = new WMSTile(service, tileSet, null, 0.009332133792713271);
+ tile.setPosition("0_0"); //$NON-NLS-1$
+
+ Boolean state = tileReadWriter.isTileStale(tile, "png"); //$NON-NLS-1$
+
+ assertTrue(state);
+ }
+
+ @Test
+ public void testIsNotStale() throws Exception {
+ Activator instance = Activator.getDefault();
+ assertNotNull("Run as a JUnit Plug-in Test", instance); //$NON-NLS-1$
+
+ MockTiledWebMapServer service = new MockTiledWebMapServer(new URL(serverURL));
+
+ TileImageReadWriter tileReadWriter = new TileImageReadWriter(service, "resources"); //$NON-NLS-1$
+
+ WMSTileSet tileSet = new WMSTileSet();
+ tileSet.setLayers("tasmania"); //$NON-NLS-1$
+ tileSet.setCoorindateReferenceSystem("WGS84(DD)"); //$NON-NLS-1$
+ tileSet.setFormat("image/png"); //$NON-NLS-1$
+
+ WMSTile tile = new WMSTile(service, tileSet, null, 0.009332133792713271);
+ tile.setPosition("1_0"); //$NON-NLS-1$
+
+ Boolean state = tileReadWriter.isTileStale(tile, "png"); //$NON-NLS-1$
+
+ assertFalse(state);
+ }
+
+ class MockTiledWebMapServer extends AbstractOpenWebService<WMSCCapabilities, TileSet> {
+
+ public MockTiledWebMapServer( URL serverURL ) throws IOException, ServiceException {
+ super(serverURL);
+ // TODO Auto-generated constructor stub
+ }
+
+ @Override
+ public WMSCCapabilities getCapabilities() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ protected ServiceInfo createInfo() {
+ return new MockWMSCInfo();
+ }
+
+ @Override
+ protected ResourceInfo createInfo( TileSet resource ) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ protected void setupSpecifications() {
+ specs = new Specification[1];
+ specs[0] = new WMS1_1_1();
+ }
+
+ }
+
+ protected class MockWMSCInfo implements ServiceInfo {
+
+ @Override
+ public String getDescription() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Set<String> getKeywords() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public URI getPublisher() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public URI getSchema() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public URI getSource() {
+ try {
+ return new URI(serverURL);
+ } catch (URISyntaxException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ @Override
+ public String getTitle() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+
+ }
+}
@@ -179,11 +179,15 @@ public Object adapt( IResolve resolve, Class< ? extends Object> adapter,
Layer layer = resolve.resolve(Layer.class, monitor);
StringBuilder sb = new StringBuilder(""); //$NON-NLS-1$
for( StyleImpl layerStyle : layer.getStyles() ) {
- sb.append(layerStyle.getName()+",");
+ sb.append(layerStyle.getName()+","); //$NON-NLS-1$
}
style = sb.toString();
}
- tileset.setStyles(style.substring(0, style.length()-1));
+ if (style.length()>0){
+ tileset.setStyles(style.substring(0, style.length()-1));
+ } else {
+ tileset.setStyles(style);
+ }
/*
* The server is where tiles can be retrieved
@@ -35,7 +35,6 @@
import org.geotools.data.ows.AbstractRequest;
import org.geotools.data.ows.HTTPClient;
import org.geotools.data.ows.HTTPResponse;
-import org.geotools.data.ows.Request;
import org.geotools.data.ows.Response;
import org.geotools.ows.ServiceException;
@@ -274,10 +273,10 @@ public boolean loadTile( IProgressMonitor monitor ) {
}
InputStream inputStream = null;
try {
- Response response = issueRequest(request);
+ HTTPResponse response = issueRequest(request);
String cacheControl = extractHeaderCacheControl(response);
setMaxCacheAge(cacheControl);
- inputStream = response.getInputStream();
+ inputStream = response.getResponseStream();
// simulate latency if testing
if (testing) {
Random rand = new Random();
@@ -337,8 +336,8 @@ public boolean loadTile( IProgressMonitor monitor ) {
* @return
*/
@SuppressWarnings("nls")
- private String extractHeaderCacheControl( Response response ) {
- String cacheControl = response.getHeader("Cache-Control");
+ private String extractHeaderCacheControl( HTTPResponse response ) {
+ String cacheControl = response.getResponseHeader("Cache-Control");
if (cacheControl != null && !"".equals(cacheControl)) {
String[] split = cacheControl.split(",");
String maxAge = split[0];
@@ -349,7 +348,7 @@ private String extractHeaderCacheControl( Response response ) {
return null;
}
- public Response issueRequest( Request request ) throws IOException, ServiceException {
+ public HTTPResponse issueRequest( GetMapRequest request ) throws IOException, ServiceException {
URL finalURL = request.getFinalURL();
if (finalURL.getHost() == null) {
// System.out.prinln("Poor WMS-C configuration - no host provided by "+ finalURL );
@@ -376,9 +375,7 @@ public Response issueRequest( Request request ) throws IOException, ServiceExcep
httpResponse = httpClient.get(finalURL);
}
- final Response response = request.createResponse(httpResponse);
-
- return response;
+ return httpResponse;
}
private BufferedImage createErrorImage() {

0 comments on commit e0c2786

Please sign in to comment.