01: package org.geotools.data.wms;
02:
03: import java.util.ArrayList;
04: import java.util.List;
05: import java.util.Set;
06: import java.util.TreeSet;
07:
08: import junit.framework.TestCase;
09:
10: import org.geotools.data.ows.Layer;
11: import org.geotools.referencing.CRS;
12: import org.opengis.referencing.crs.CoordinateReferenceSystem;
13:
14: public class WMSUtilsTest extends TestCase {
15:
16: public void testFindCommonEPSGs() {
17: List layers = new ArrayList();
18:
19: Layer layer1 = new Layer();
20: TreeSet set1 = new TreeSet();
21: set1.add("EPSG:4326");
22: set1.add("EPSG:3005");
23: set1.add("EPSG:42101");
24: layer1.setSrs(set1);
25:
26: Layer layer2 = new Layer();
27: TreeSet set2 = new TreeSet();
28: set2.add("EPSG:3005");
29: set2.add("EPSG:42101");
30: layer2.setSrs(set2);
31:
32: Layer layer3 = new Layer();
33: TreeSet set3 = new TreeSet();
34: set3.add("EPSG:42111");
35: layer3.setSrs(set3);
36:
37: layers.add(layer1);
38: layers.add(layer2);
39:
40: Set results1 = WMSUtils.findCommonEPSGs(layers);
41:
42: assertNotNull(results1);
43: assertEquals(2, results1.size());
44: assertTrue(results1.contains("EPSG:3005"));
45: assertTrue(results1.contains("EPSG:42101"));
46: assertFalse(results1.contains("EPSG:4326"));
47:
48: layers.clear();
49:
50: layers.add(layer1);
51: layers.add(layer3);
52:
53: Set results2 = WMSUtils.findCommonEPSGs(layers);
54:
55: assertNotNull(results2);
56: assertEquals(0, results2.size());
57: assertTrue(results2.isEmpty());
58: }
59:
60: public void testMatchEPSG() throws Exception {
61: CoordinateReferenceSystem crs4326 = CRS.decode("EPSG:4326");
62: CoordinateReferenceSystem crs3005 = CRS.decode("EPSG:3005");
63: CoordinateReferenceSystem crs42101 = CRS.decode("EPSG:42101");
64:
65: Set codes = new TreeSet();
66: codes.add("EPSG:4326");
67: codes.add("EPSG:42102");
68: codes.add("EPSG:bork"); //invalid CRSs allowed
69:
70: String result1 = WMSUtils.matchEPSG(crs4326, codes);
71:
72: assertNotNull(result1);
73: assertEquals("EPSG:4326", result1);
74:
75: //3005 == 42102
76: String result2 = WMSUtils.matchEPSG(crs3005, codes);
77:
78: assertNotNull(result2);
79: assertEquals("EPSG:42102", result2);
80:
81: String result3 = WMSUtils.matchEPSG(crs42101, codes);
82: assertNull(result3);
83: }
84:
85: }
|