Creating a test for versioned postgis connector to ensure that we are able to access...
[udig:udig-platform.git] / plugins / net.refractions.udig.catalog.tests.ui / src / net / refractions / udig / catalog / geotools / data / VersionedPostgisUtils.java
1 package net.refractions.udig.catalog.geotools.data;\r
2 \r
3 import java.io.IOException;\r
4 import java.util.Enumeration;\r
5 import java.util.HashMap;\r
6 import java.util.Map;\r
7 import java.util.PropertyResourceBundle;\r
8 \r
9 import org.geotools.data.postgis.VersionedPostgisDataStoreFactory;\r
10     \r
11 public class VersionedPostgisUtils {\r
12 \r
13         public static Fixture newFixture(String props) throws IOException {\r
14             PropertyResourceBundle resource;\r
15             resource = new PropertyResourceBundle(\r
16                 VersionedPostgisUtils.class.getResourceAsStream(props)\r
17             );\r
18 \r
19             Fixture f = new Fixture();\r
20             \r
21             f.namespace = resource.getString("namespace");\r
22             f.host = resource.getString("host");\r
23             f.port = Integer.valueOf(resource.getString("port"));\r
24             f.database = resource.getString("database");\r
25             f.user = resource.getString("user");\r
26             f.password = resource.getString("password");    \r
27             f.schema = resource.getString("schema");\r
28             \r
29             if (f.schema == null || "".equals(f.schema.trim()))\r
30                 f.schema = "public";\r
31             \r
32             f.wkbEnabled = null;\r
33             f.looseBbox = null;\r
34 \r
35             Enumeration keys = resource.getKeys();\r
36             while (keys.hasMoreElements()) {\r
37                 String key = keys.nextElement().toString();\r
38                 if (key.equalsIgnoreCase("wkbEnabled")) {\r
39                     f.wkbEnabled = new Boolean(resource.getString("wkbEnabled"));\r
40                 } else if (key.equalsIgnoreCase("looseBbox")) {\r
41                     f.looseBbox = new Boolean(resource.getString("looseBbox"));\r
42                 }\r
43             }\r
44             \r
45             return f;\r
46         }\r
47         \r
48         public static Fixture newFixture() throws IOException {\r
49             return newFixture("fixture.properties");\r
50         }\r
51         \r
52         public static class Fixture {\r
53             public String namespace;\r
54             public String host;\r
55             public String database;\r
56             public Integer port;\r
57             public String user;\r
58             public String password;\r
59             public String schema;\r
60             public Boolean wkbEnabled;\r
61             public Boolean looseBbox;\r
62         }\r
63         \r
64         public static Map getParams(Fixture f) {\r
65             Map params = new HashMap();\r
66             \r
67             params.put(VersionedPostgisDataStoreFactory.DBTYPE.key, "postgis-versioned");\r
68             params.put(VersionedPostgisDataStoreFactory.HOST.key, f.host);\r
69             params.put(VersionedPostgisDataStoreFactory.PORT.key, f.port);\r
70             params.put(VersionedPostgisDataStoreFactory.DATABASE.key, f.database);\r
71             params.put(VersionedPostgisDataStoreFactory.USER.key, f.user);\r
72             params.put(VersionedPostgisDataStoreFactory.PASSWD.key, f.password);\r
73             params.put(VersionedPostgisDataStoreFactory.SCHEMA.key,f.schema);\r
74             if (f.wkbEnabled != null) {\r
75                 params.put(VersionedPostgisDataStoreFactory.WKBENABLED.key, f.wkbEnabled);\r
76             }\r
77             if (f.looseBbox != null) {\r
78                 params.put(VersionedPostgisDataStoreFactory.LOOSEBBOX.key, f.looseBbox);\r
79             }\r
80 \r
81             return params;\r
82         }\r
83         \r
84         public static Map getParams(String fixtureFile) throws IOException {\r
85             Fixture f = newFixture(fixtureFile);\r
86             return getParams(f);\r
87         }\r
88 \r
89 }\r