01: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
02: * This code is licensed under the GPL 2.0 license, availible at the root
03: * application directory.
04: */
05: package org.vfny.geoserver;
06:
07: import com.meterware.httpunit.GetMethodWebRequest;
08: import com.meterware.httpunit.WebConversation;
09: import com.meterware.httpunit.WebRequest;
10: import com.meterware.httpunit.WebResponse;
11: import junit.framework.TestCase;
12: import java.io.FileInputStream;
13: import java.util.PropertyResourceBundle;
14:
15: public abstract class AbstractGeoserverHttpTest extends TestCase {
16: /** test fixture properties **/
17: PropertyResourceBundle properties;
18:
19: protected void setUp() throws Exception {
20: properties = new PropertyResourceBundle(new FileInputStream(
21: "httptest.properties"));
22: }
23:
24: public String getProtocol() {
25: return (properties.getString("protocol") != null) ? properties
26: .getString("protocol") : "http";
27: }
28:
29: public String getServer() {
30: return (properties.getString("server") != null) ? properties
31: .getString("server") : "localhost";
32: }
33:
34: public String getPort() {
35: return (properties.getString("port") != null) ? properties
36: .getString("port") : "8080";
37: }
38:
39: public String getContext() {
40: return (properties.getString("context") != null) ? properties
41: .getString("context") : "geoserver";
42: }
43:
44: public String getBaseUrl() {
45: return getProtocol() + "://" + getServer() + ":" + getPort()
46: + "/" + getContext();
47: }
48:
49: protected boolean isOffline() {
50: try {
51: WebConversation conversation = new WebConversation();
52: WebRequest request = new GetMethodWebRequest(getBaseUrl()
53: + "/wfs?request=getCapabilities");
54:
55: WebResponse response = conversation.getResponse(request);
56: } catch (Exception e) {
57: return true;
58: }
59:
60: return false;
61: }
62: }
|