1
2
3
4
5
6
7 package nl.mineleni.cbsviewer.util;
8
9 import static org.junit.Assert.assertEquals;
10 import static org.junit.Assert.assertFalse;
11 import static org.junit.Assert.assertTrue;
12
13 import java.util.List;
14
15 import nl.mineleni.cbsviewer.util.xml.LayerDescriptor;
16
17 import org.junit.After;
18 import org.junit.Before;
19 import org.junit.Test;
20
21 import flexjson.JSONDeserializer;
22
23
24
25
26
27
28 public class AvailableLayersBeanTest {
29 private static final String ID1 = "vierkanten500m_oad2000";
30 private static final String LAYERS1 = "omgevings_adres_dichtheid_2000";
31 private static final String STYLES1 = "cbsvierkanten500m.oad2000";
32 private static final String NAME1 = "Vierkant 500m - Omgevingsadressendichtheid 2000";
33 private static final String URL1 = "http://geodata.nationaalgeoregister.nl/cbsvierkanten500m/wms";
34
35
36 private AvailableLayersBean bean;
37
38
39
40
41
42
43
44 @Before
45 public void beforeTest() throws Exception {
46 this.bean = new AvailableLayersBean();
47 }
48
49
50
51
52
53 @After
54 public void afterTest() {
55 this.bean = null;
56 }
57
58
59
60
61 @Test
62 public void testAsJSON() {
63 assertTrue(this.bean.asJSON().startsWith(
64 "\n/* <![CDATA[ */ var _layers="));
65 }
66
67
68
69
70 @Test
71 public void testAsJSONBoolean() {
72 assertTrue(this.bean.asJSON(true).startsWith(
73 "\n/* <![CDATA[ */ var _layers="));
74 assertFalse(this.bean.asJSON(false).startsWith(
75 "\n/* <![CDATA[ */ var _layers="));
76 assertTrue(this.bean.asJSON(false).startsWith("["));
77
78 List<LayerDescriptor> layers = new JSONDeserializer<List<LayerDescriptor>>()
79 .use("values", LayerDescriptor.class).deserialize(
80 this.bean.asJSON(false));
81 assertFalse(layers.isEmpty());
82 assertEquals(NAME1, layers.get(0).getName());
83 }
84
85
86
87
88 @Test
89 public void testGetLayerByID() {
90 assertEquals(ID1, this.bean.getLayerByID(ID1).getId());
91 assertEquals(NAME1, this.bean.getLayerByID(ID1).getName());
92 }
93
94
95
96
97
98
99
100 @Test
101 public void testGetLayerByLayersStringString() {
102 assertEquals(ID1, this.bean.getLayerByLayers(LAYERS1, URL1).getId());
103 }
104
105
106
107
108
109 @Test
110 public void testGetLayerByLayersStringStringString() {
111 assertEquals(ID1, this.bean.getLayerByLayers(LAYERS1, URL1, STYLES1)
112 .getId());
113 }
114
115
116
117
118
119
120 @Test
121 public void testGetLayerByName() {
122 assertEquals(ID1, this.bean.getLayerByName(NAME1).getId());
123 assertEquals(NAME1, this.bean.getLayerByName(NAME1).getName());
124 }
125
126
127
128
129
130 @Test
131 public void testGetLayers() {
132 assertEquals(2, this.bean.getLayers().size());
133
134 assertEquals(ID1, this.bean.getLayers().get(0).getId());
135 }
136
137
138
139
140
141 @Test(expected = UnsupportedOperationException.class)
142 public void testGetLayersImmutable() {
143 this.bean.getLayers().add(new LayerDescriptor());
144 }
145 }