-
Notifications
You must be signed in to change notification settings - Fork 414
/
WmsUtilitiesTest.java
134 lines (124 loc) · 7.38 KB
/
WmsUtilitiesTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package org.mapfish.print.map.image.wms;
import com.google.common.collect.Multimap;
import org.geotools.geometry.jts.ReferencedEnvelope;
import org.geotools.referencing.CRS;
import org.json.JSONObject;
import org.junit.Test;
import org.mapfish.print.TestHttpClientFactory;
import org.mapfish.print.URIUtils;
import org.mapfish.print.map.image.wms.WmsLayerParam.ServerType;
import org.mapfish.print.wrapper.json.PJsonObject;
import java.awt.Dimension;
import java.net.URI;
import java.util.Collection;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertFalse;
public class WmsUtilitiesTest {
@Test
public void testMakeWmsGetLayerRequest() throws Exception {
WmsLayerParam wmsLayerParams = new WmsLayerParam();
wmsLayerParams.layers = new String[] {"layer1", "layer2", "layer3", "layer4", "layer5"};
wmsLayerParams.imageFormat = "image/png";
wmsLayerParams.customParams = new PJsonObject(new JSONObject("{\"map_resolution\":254}"), "customParams");
wmsLayerParams.version = "1.1.1";
URI commonURI = new URI("http://test.xyz/geoserver/wms?SERVICE=WMS");
Dimension imageSize = new Dimension(200,300);
ReferencedEnvelope env = new ReferencedEnvelope(0,10, 40, 50, CRS.decode("EPSG:4326"));
final URI wmsURI = WmsUtilities.makeWmsGetLayerRequest(new TestHttpClientFactory(), wmsLayerParams, commonURI, imageSize,
72.0, env);
final Multimap<String, String> finalParams = URIUtils.getParameters(wmsURI);
final Collection<String> layersParam = finalParams.get("LAYERS");
assertNotNull(layersParam);
assertEquals(1, layersParam.size());
String[] resultlayers = layersParam.iterator().next().split(",");
assertArrayEquals(wmsLayerParams.layers, resultlayers);
}
@Test
public void testMakeWmsGetLayerRequestDpiMapServer() throws Exception {
WmsLayerParam wmsLayerParams = new WmsLayerParam();
wmsLayerParams.layers = new String[] {"layer1", "layer2", "layer3", "layer4", "layer5"};
wmsLayerParams.imageFormat = "image/png";
wmsLayerParams.version = "1.1.1";
wmsLayerParams.serverType = ServerType.MAPSERVER;
URI commonURI = new URI("http://test.xyz/geoserver/wms?SERVICE=WMS");
Dimension imageSize = new Dimension(200,300);
ReferencedEnvelope env = new ReferencedEnvelope(0,10, 40, 50, CRS.decode("EPSG:4326"));
final URI wmsURI = WmsUtilities.makeWmsGetLayerRequest(new TestHttpClientFactory(), wmsLayerParams, commonURI, imageSize,
300.0, env);
final Multimap<String, String> finalParams = URIUtils.getParameters(wmsURI);
final String mapResolution = finalParams.get("MAP_RESOLUTION").iterator().next();
assertEquals("300", mapResolution);
}
@Test
public void testMakeWmsGetLayerRequestDpiMapServerSet() throws Exception {
WmsLayerParam wmsLayerParams = new WmsLayerParam();
wmsLayerParams.layers = new String[] {"layer1", "layer2", "layer3", "layer4", "layer5"};
wmsLayerParams.imageFormat = "image/png";
wmsLayerParams.version = "1.1.1";
wmsLayerParams.serverType = ServerType.MAPSERVER;
wmsLayerParams.customParams = new PJsonObject(new JSONObject("{\"map_resolution\":254}"), "customParams");
URI commonURI = new URI("http://test.xyz/geoserver/wms?SERVICE=WMS");
Dimension imageSize = new Dimension(200,300);
ReferencedEnvelope env = new ReferencedEnvelope(0,10, 40, 50, CRS.decode("EPSG:4326"));
final URI wmsURI = WmsUtilities.makeWmsGetLayerRequest(new TestHttpClientFactory(), wmsLayerParams, commonURI, imageSize,
300.0, env);
final Multimap<String, String> finalParams = URIUtils.getParameters(wmsURI);
assertFalse(finalParams.containsKey("MAP_RESOLUTION"));
final String mapResolution = finalParams.get("map_resolution").iterator().next();
assertEquals("254", mapResolution);
}
@Test
public void testMakeWmsGetLayerRequestDpiGeoServer() throws Exception {
WmsLayerParam wmsLayerParams = new WmsLayerParam();
wmsLayerParams.layers = new String[] {"layer1", "layer2", "layer3", "layer4", "layer5"};
wmsLayerParams.imageFormat = "image/png";
wmsLayerParams.version = "1.1.1";
wmsLayerParams.serverType = ServerType.GEOSERVER;
URI commonURI = new URI("http://test.xyz/geoserver/wms?SERVICE=WMS");
Dimension imageSize = new Dimension(200,300);
ReferencedEnvelope env = new ReferencedEnvelope(0,10, 40, 50, CRS.decode("EPSG:4326"));
final URI wmsURI = WmsUtilities.makeWmsGetLayerRequest(new TestHttpClientFactory(), wmsLayerParams, commonURI, imageSize,
300.0, env);
final Multimap<String, String> finalParams = URIUtils.getParameters(wmsURI);
final String mapResolution = finalParams.get("FORMAT_OPTIONS").iterator().next();
assertEquals("dpi:300", mapResolution);
}
@Test
public void testMakeWmsGetLayerRequestDpiGeoServerSet() throws Exception {
WmsLayerParam wmsLayerParams = new WmsLayerParam();
wmsLayerParams.layers = new String[] {"layer1", "layer2", "layer3", "layer4", "layer5"};
wmsLayerParams.customParams = new PJsonObject(new JSONObject("{\"format_options\":\"dpi:254\"}"), "customParams");
wmsLayerParams.imageFormat = "image/png";
wmsLayerParams.version = "1.1.1";
wmsLayerParams.serverType = ServerType.GEOSERVER;
URI commonURI = new URI("http://test.xyz/geoserver/wms?SERVICE=WMS");
Dimension imageSize = new Dimension(200,300);
ReferencedEnvelope env = new ReferencedEnvelope(0,10, 40, 50, CRS.decode("EPSG:4326"));
final URI wmsURI = WmsUtilities.makeWmsGetLayerRequest(new TestHttpClientFactory(), wmsLayerParams, commonURI, imageSize,
300.0, env);
final Multimap<String, String> finalParams = URIUtils.getParameters(wmsURI);
assertFalse(finalParams.containsKey("FORMAT_OPTIONS"));
final String mapResolution = finalParams.get("format_options").iterator().next();
assertEquals("dpi:254", mapResolution);
}
@Test
public void testMakeWmsGetLayerRequestDpiGeoServerAdd() throws Exception {
WmsLayerParam wmsLayerParams = new WmsLayerParam();
wmsLayerParams.layers = new String[] {"layer1", "layer2", "layer3", "layer4", "layer5"};
wmsLayerParams.customParams = new PJsonObject(new JSONObject("{\"format_options\":\"antialiasing:on\"}"), "customParams");
wmsLayerParams.imageFormat = "image/png";
wmsLayerParams.version = "1.1.1";
wmsLayerParams.serverType = ServerType.GEOSERVER;
URI commonURI = new URI("http://test.xyz/geoserver/wms?SERVICE=WMS");
Dimension imageSize = new Dimension(200,300);
ReferencedEnvelope env = new ReferencedEnvelope(0,10, 40, 50, CRS.decode("EPSG:4326"));
final URI wmsURI = WmsUtilities.makeWmsGetLayerRequest(new TestHttpClientFactory(), wmsLayerParams, commonURI, imageSize,
300.0, env);
final Multimap<String, String> finalParams = URIUtils.getParameters(wmsURI);
assertFalse(finalParams.containsKey("FORMAT_OPTIONS"));
final String mapResolution = finalParams.get("format_options").iterator().next();
assertEquals("antialiasing:on;dpi:300", mapResolution);
}
}