001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2005-2006, GeoTools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.data.postgis;
017:
018: import java.io.IOException;
019: import java.util.Enumeration;
020: import java.util.HashMap;
021: import java.util.Map;
022: import java.util.PropertyResourceBundle;
023:
024: /**
025: * Convenience class for postgis testing.
026: *
027: * @author Justin Deoliveira, The Open Planning Project
028: *
029: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/plugin/postgis/src/test/java/org/geotools/data/postgis/PostgisTests.java $
030: * @deprecated please use PostgisOnlineTestCase
031: */
032: public class PostgisTests {
033:
034: public static Fixture newFixture(String props) throws IOException {
035: PropertyResourceBundle resource;
036: resource = new PropertyResourceBundle(PostgisTests.class
037: .getResourceAsStream(props));
038:
039: Fixture f = new Fixture();
040:
041: f.namespace = resource.getString("namespace");
042: f.host = resource.getString("host");
043: f.port = Integer.valueOf(resource.getString("port"));
044: f.database = resource.getString("database");
045: f.user = resource.getString("user");
046: f.password = resource.getString("password");
047: f.schema = resource.getString("schema");
048:
049: if (f.schema == null || "".equals(f.schema.trim()))
050: f.schema = "public";
051:
052: f.wkbEnabled = null;
053: f.looseBbox = null;
054:
055: Enumeration keys = resource.getKeys();
056: while (keys.hasMoreElements()) {
057: String key = keys.nextElement().toString();
058: if (key.equalsIgnoreCase("wkbEnabled")) {
059: f.wkbEnabled = new Boolean(resource
060: .getString("wkbEnabled"));
061: } else if (key.equalsIgnoreCase("looseBbox")) {
062: f.looseBbox = new Boolean(resource
063: .getString("looseBbox"));
064: }
065: }
066:
067: return f;
068: }
069:
070: public static Fixture newFixture() throws IOException {
071: return newFixture("fixture.properties");
072: }
073:
074: public static class Fixture {
075: public String namespace;
076: public String host;
077: public String database;
078: public Integer port;
079: public String user;
080: public String password;
081: public String schema;
082: public Boolean wkbEnabled;
083: public Boolean looseBbox;
084: }
085:
086: public static Map getParams(Fixture f) {
087: Map params = new HashMap();
088:
089: params.put(PostgisDataStoreFactory.DBTYPE.key, "postgis");
090: params.put(PostgisDataStoreFactory.HOST.key, f.host);
091: params.put(PostgisDataStoreFactory.PORT.key, f.port);
092: params.put(PostgisDataStoreFactory.DATABASE.key, f.database);
093: params.put(PostgisDataStoreFactory.USER.key, f.user);
094: params.put(PostgisDataStoreFactory.PASSWD.key, f.password);
095: params.put(PostgisDataStoreFactory.SCHEMA.key, f.schema);
096: if (f.wkbEnabled != null) {
097: params.put(PostgisDataStoreFactory.WKBENABLED.key,
098: f.wkbEnabled);
099: }
100: if (f.looseBbox != null) {
101: params.put(PostgisDataStoreFactory.LOOSEBBOX.key,
102: f.looseBbox);
103: }
104:
105: return params;
106: }
107:
108: public static Map getParams(String fixtureFile) throws IOException {
109: Fixture f = newFixture(fixtureFile);
110: return getParams(f);
111: }
112: }
|