// System.out.println("Total tested: "+total);
// System.out.println("Total passed: "+passedCount);
}
public boolean serverTest(PrintStream out, URL url) {
WebMapServer wms = null;
boolean passed = true;
out.println("Beginning tests for server:");
out.println(url);
out.print("Parsing Capabilities...");
try {
wms = new WebMapServer(url);
out.println("passed.");
} catch (ServiceException e) {
out.println("failed.");
passed = false;
while (e != null) {
if (e.getLocator() != null && e.getLocator().length() != 0) {
out.println("ServiceException at "+e.getLocator()+": "+e.getMessage()+"("+e.getCode()+")");
}
out.println("ServiceException: "+e.getMessage()+"("+e.getCode()+")");
e = e.getNext();
}
return passed;
} catch (IOException e) {
out.println("failed.");
passed = false;
out.println("IOException: "+e.getMessage());
e.printStackTrace(out);
return passed;
} catch (SAXException e) {
out.println("failed.");
passed = false;
out.println("SAXException: "+e.getMessage());
e.printStackTrace(out);
return passed;
}
WMSCapabilities caps = wms.getCapabilities();
assertNotNull(caps);
out.println("Validating layer LatLonBoundingBoxes...");
Iterator iter = caps.getLayerList().iterator();
while (iter.hasNext()) {
Layer layer = (Layer) iter.next();
if (layer.getLatLonBoundingBox() == null) {
if (layer.getName() != null) {
out.println("WARNING: Layer '"+layer.getName()+"' contains no LatLonBoundingBox.");
passed = false;
}
}
}
Layer layer = null;
out.print("Looking for a named layer...");
iter = caps.getLayerList().iterator();
while (iter.hasNext()) {
Layer tempLayer = (Layer) iter.next();
if (tempLayer.getName() != null) {
layer = tempLayer;
out.println("found one. Using layer '"+layer.getName()+"'");
break;
}
}
String format = null;
if (layer == null) {
out.println("server contains no named layers. Cannot perform GetMap requests on it");
passed = false;
} else {
out.print("Checking for GetMap operation...");
if (caps.getRequest().getGetMap() == null) {
out.println("NOT FOUND. Will attempt a request using 'image/gif' anyway.");
passed = false;
format = "image/gif";
} else {
out.println("found.");
out.print("Searching for a suitable format...");
List formats = caps.getRequest().getGetMap().getFormats();
if (formats.contains("image/png")) {
format = "image/png";
out.println("using 'image/png'.");
}
if (format == null && formats.contains("image/gif")) {
format = "image/gif";
out.println("using 'image/gif'.");
}
if (format == null && formats.contains("image/jpeg")) {
format = "image/jpeg";
out.println("using 'image/jpeg'.");
}
if (format == null) {
format = (String) formats.get(0);
out.println("server does not support GIF, PNG or JPEG. Using '"+format+"'");
passed = false;
}
}
}
out.print("Performing GetMap operation...");
GetMapRequest request = wms.createGetMapRequest();
request.addLayer(layer);
CRSEnvelope bbox = layer.getLatLonBoundingBox();
request.setBBox(bbox);
request.setFormat(format);
request.setSRS("EPSG:4326");
request.setDimensions("100","100");
try {
GetMapResponse response = wms.issueRequest(request);
out.println("received a response.");
out.print("Checking returned format...");
if (response.getContentType().indexOf(format) == -1) {
out.println("server returned bad format. Expected "+format+", got "+response.getContentType()+".");