Statistics
| Revision:

root / branches / v10 / extensions / extPublishGeoserver / src-test / org / gvsig / publish / geoserver / config / Test_WriteConf.java @ 19431

History | View | Annotate | Download (8.58 KB)

1
/* gvSIG. Sistema de Información Geográfica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004-2006 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *   Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ibañez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *   +34 963862235
28
 *   gvsig@gva.es
29
 *   www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package org.gvsig.publish.geoserver.config;
42

    
43
import java.awt.geom.Rectangle2D;
44
import java.io.File;
45
import java.net.MalformedURLException;
46
import java.net.URI;
47
import java.net.URISyntaxException;
48
import java.net.URL;
49

    
50
import junit.framework.TestCase;
51

    
52
import org.gvsig.publish.geoserver.conf.GSConfiguration;
53
import org.gvsig.publish.geoserver.conf.GSDatastore;
54
import org.gvsig.publish.geoserver.conf.GSFeature;
55
import org.gvsig.publish.geoserver.conf.GSNamespace;
56
import org.gvsig.publish.geoserver.conf.GSServer;
57
import org.gvsig.publish.geoserver.conf.GSStyle;
58
import org.gvsig.publish.geoserver.conf.GSWFS;
59
import org.gvsig.publish.geoserver.conf.GSWMS;
60

    
61
public class Test_WriteConf extends TestCase {
62
        
63
        private File conf_dir;
64
        private File resources_dir;
65
        /**
66
         * Creates the Geoserver DATA_DIR
67
         * 
68
         */
69
        protected void setUp() throws Exception {
70
                //creates conf directory
71
                conf_dir = new File ("test"); 
72
                conf_dir.mkdirs();                
73
                System.out.println("GEOSERVER_DATA_DIR: " + conf_dir.getAbsolutePath());
74
                //init resources dir
75
                resources_dir = new File("resources");
76
                System.out.println("RESOURCES_DIR: " + resources_dir.getAbsolutePath());
77
        }
78

    
79
        protected void tearDown() throws Exception {
80
        }
81

    
82

    
83
        public GSConfiguration createConfiguration(){
84
                //create configuration
85
                GSConfiguration conf = new GSConfiguration();
86
                conf.setUser("admin");
87
                conf.setPassword("geoserver");
88
                
89
                //configure services.global
90
                GSServer srvs = conf.getServices();
91
                srvs.setMaxFeatures(1000);
92
                srvs.setLoginLevel(GSServer.LOG_SEVERE);
93
                srvs.setAdminPassword("geoserver");
94
                srvs.setAdminUser("admin");
95
                srvs.setCharset("UTF-8");
96
                srvs.setImageIOCache(false);
97
                srvs.setJaiJPEGNative(true);
98
                srvs.setJaiMemoryCapacity(0.5);
99
                srvs.setJaiMemoryThreshold(0.75);
100
                srvs.setJaiPNGNative(true);
101
                srvs.setJaiRecycling(true);
102
                srvs.setJaiTilePriority(5);
103
                srvs.setJaiTileThreads(7);
104
                srvs.setLoginToFile(false);
105
                srvs.setNumDecimals(8);
106
                srvs.setVerbose(false);
107
                srvs.setVerboseExceptions(false);
108
                return conf;
109
        }
110
        
111
        public GSWFS configure_wfs(GSConfiguration conf){
112
                //configure services.wfs
113
                GSWFS wfs = conf.getServices().getWFS();                
114
                wfs.setName("WGS:WFS");
115
                wfs.setTitle("Geoserver WFS");
116
                wfs.setAbstract("Geoserver OGC-WFS test service");
117
                wfs.addKeyword("wfs");
118
                wfs.addKeyword("Geoserver");
119
                wfs.setEnabled(true);
120
                try {
121
                        wfs.setOnlineResource(new URL("http://localhost:8080/geoserver/wfs"));
122
                } catch (MalformedURLException e) {
123
                        // TODO Auto-generated catch block
124
                        e.printStackTrace();
125
                }
126
                return wfs;                
127
        }
128
        public GSWMS configure_wms(GSConfiguration conf){
129
                //configure services.wms
130
                GSWMS wms = conf.getServices().getWMS();                
131
                wms.setName("WGS:WMS");
132
                wms.setTitle("Geoserver WMS");
133
                wms.setAbstract("Geoserver OGC-WMS test service");
134
                wms.addKeyword("wms");
135
                wms.addKeyword("Geoserver");
136
                wms.setEnabled(true);
137
                try {
138
                        wms.setOnlineResource(new URL("http://localhost:8080/geoserver/wms"));
139
                } catch (MalformedURLException e) {
140
                        // TODO Auto-generated catch block
141
                        e.printStackTrace();
142
                }
143
                return wms;
144
                
145
        }
146

    
147
        public GSNamespace create_namespace(){
148
                GSNamespace ns = new GSNamespace();
149
                ns.setPrefix("ns_prefix");
150
                try {
151
                        ns.setURI(new URI("http://localhost/geoserver"));
152
                } catch (URISyntaxException e1) {                        
153
                        e1.printStackTrace();
154
                }
155
                return ns;
156
        }
157
        public GSDatastore create_datastore_roads(GSNamespace ns){
158
                GSDatastore ds = new GSDatastore();
159
                ds.setId("sfRoads");
160
                        //ds.setEnabled(true);
161
                ds.setCharset("ISO-8859-1");
162
                ds.setNamespace(ns);
163
                try {
164
                        String f = resources_dir.getAbsolutePath() + File.separator + "shp" + File.separator + "roads.shp";
165
                        ds.setURL(new URL("file:" + f));
166
                } catch (MalformedURLException e) {
167
                        e.printStackTrace();
168
                }                
169
                return ds;
170

    
171
        }
172
        /**
173
         * Testing postgis datastores. 
174
         * Content example in the catalog.xml
175
         *         
176
                <datastore namespace = "default" enabled = "true" id = "postgis_id" >
177
            <abstract>descripcion datastore</abstract>
178
            <connectionParams >
179
              <parameter value = "default" name = "namespace" />
180
              <parameter value = "true" name = "loose bbox" />
181
              <parameter value = "postgres" name = "user" />
182
              <parameter value = "postgres" name = "passwd" />
183
              <parameter value = "false" name = "estimated extent" />
184
              <parameter value = "true" name = "wkb enabled" />
185
              <parameter value = "localhost" name = "host" />
186
              <parameter value = "public" name = "schema" />
187
              <parameter value = "5432" name = "port" />
188
              <parameter value = "publish" name = "database" />
189
              <parameter value = "postgis" name = "dbtype" />
190
            </connectionParams>
191
          </datastore>
192
        */
193

    
194
        private GSDatastore create_datastore_postgis(GSNamespace ns) {
195
                GSDatastore ds = new GSDatastore();
196
                ds.setNamespace(ns);
197
                ds.setId("test_postgis");
198
                        //ds.setEnabled(true);
199
                        //ds.setCharset("ISO-8859-1");
200
                ds.setAbstract("descripcion del datastore postgis");
201
                ds.setLooseBbox(true);
202
                ds.setUser("postgres");
203
                ds.setPassword("postgres");
204
                ds.setEstimatedExtent(false);
205
                ds.setHost("localhost");
206
                ds.setSchema("public");
207
                ds.setPort(5432);
208
                ds.setDatabase("publish");
209
                ds.setDbType("postgis");
210
                return ds;
211
        }
212
        
213
        public GSStyle create_style_roads(){
214
                //create style
215
                GSStyle st = new GSStyle();
216
                st.setId("simple_roads");
217
                File f = new File (resources_dir.getAbsoluteFile() + File.separator + "sld" + File.separator + "simpleRoads.sld");
218
                st.setSLDString(f.toString());
219
                return st;
220
        }
221
        
222
        public void writeConf(GSConfiguration conf){                
223
                //write configuration
224
                conf.toXML(conf_dir);                
225
                //reload conf
226
                conf.reload();
227
        }
228
        
229
        /**
230
         * Creates a configuration for a shapefile 
231
         */
232
        public void test_feature_shape(){
233
                //create conf
234
                GSConfiguration conf = createConfiguration();
235
                //configure wfs
236
                configure_wfs(conf);
237
                //configure wms
238
                configure_wms(conf);
239
                //create namespace
240
                GSNamespace ns = create_namespace();
241
                //create datastore
242
                GSDatastore ds = create_datastore_roads(ns);
243
                //create style 
244
                GSStyle st = create_style_roads();
245
                //create feature
246
                GSFeature ft = new GSFeature();
247
                ft.setDatastore(ds);
248
                ft.setNamespace(ns);
249
                ft.setStyle(st);
250
                ft.setName("roads");
251
                ft.setTitle("roads_Type");
252
                ft.setAbstract("Generated from sfRoads");
253
                ft.addKeyword("sfRoads");
254
                ft.addKeyword("roads");
255
                ft.setSRID(26713);
256
                ft.setLatLonBBox(new Rectangle2D.Double(-7.555555229087563, 35.94874548545378, -1.6313474381419066, 38.614699115836444));
257
                ft.setNativeBBox(new Rectangle2D.Double(102912.609375, 3987436.25, 619271.8125, 4274256.0));
258
                //adds feature
259
                conf.addFeatureType(ft);
260
                //write conf
261
                writeConf(conf);
262
        }
263

    
264
        public void test_feature_postgis(){
265
                //create conf
266
                GSConfiguration conf = createConfiguration();
267
                //configure wfs
268
                configure_wfs(conf);
269
                //configure wms
270
                configure_wms(conf);
271
                //create namespace
272
                GSNamespace ns = create_namespace();
273
                //create datastore
274
                GSDatastore ds = create_datastore_postgis(ns);
275
                //create style 
276
                GSStyle st = create_style_roads();
277
                //create feature
278
                GSFeature ft = new GSFeature();
279
                ft.setDatastore(ds);
280
                ft.setNamespace(ns);
281
                ft.setStyle(st);
282
                ft.setName("roads");
283
                ft.setTitle("test_postgis");
284
                ft.setAbstract("Testing postgis datasource");
285
                ft.addKeyword("test");
286
                ft.addKeyword("postgis");
287
                ft.setSRID(23030);
288
                ft.setLatLonBBox(new Rectangle2D.Double(-103.87741691493184,44.37087275281798,609527.2102150217,4928063.398014731));
289
                ft.setNativeBBox(new Rectangle2D.Double(589434.8564686741,4914006.337837095,609527.2102150217,4928063.398014731));
290
                //adds feature
291
                conf.addFeatureType(ft);
292
                //write conf
293
                writeConf(conf);
294
        }
295
        
296

    
297
}