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 |
|
package info.magnolia.rest.service.property.v1; |
35 |
|
|
36 |
|
import static org.junit.Assert.*; |
37 |
|
|
38 |
|
import info.magnolia.repository.RepositoryConstants; |
39 |
|
import info.magnolia.rest.service.node.v1.RepositoryProperty; |
40 |
|
import info.magnolia.rest.service.property.definition.ConfiguredPropertyEndpointDefinition; |
41 |
|
import info.magnolia.rest.service.property.definition.PropertyEndpointDefinition; |
42 |
|
import info.magnolia.test.MgnlTestCase; |
43 |
|
import info.magnolia.test.mock.MockUtil; |
44 |
|
import info.magnolia.test.mock.jcr.MockSession; |
45 |
|
import info.magnolia.test.mock.jcr.MockValue; |
46 |
|
import info.magnolia.test.mock.jcr.SessionTestUtil; |
47 |
|
|
48 |
|
import java.util.Arrays; |
49 |
|
import java.util.Collections; |
50 |
|
|
51 |
|
import javax.jcr.PropertyType; |
52 |
|
import javax.jcr.RepositoryException; |
53 |
|
import javax.jcr.Value; |
54 |
|
import javax.ws.rs.core.Response; |
55 |
|
|
56 |
|
import org.junit.Before; |
57 |
|
import org.junit.Test; |
58 |
|
|
59 |
|
|
60 |
|
@link |
61 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (94) |
Complexity: 23 |
Complexity Density: 0.32 |
|
62 |
|
public class PropertyEndpointTest extends MgnlTestCase { |
63 |
|
|
64 |
|
private PropertyEndpoint<PropertyEndpointDefinition> endpoint; |
65 |
|
private MockSession session; |
66 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
67 |
22 |
@Before... |
68 |
|
public void setUp() throws Exception { |
69 |
22 |
super.setUp(); |
70 |
22 |
endpoint = new PropertyEndpoint<PropertyEndpointDefinition>(new ConfiguredPropertyEndpointDefinition()); |
71 |
|
|
72 |
22 |
session = SessionTestUtil.createSession(RepositoryConstants.WEBSITE, |
73 |
|
"/start", |
74 |
|
"/start.property=propertyValue"); |
75 |
|
|
76 |
22 |
session.getNode("start").setProperty("multiValueProperty", new Value[]{new MockValue("value1"), new MockValue("value2")}); |
77 |
|
|
78 |
22 |
MockUtil.setSessionAndHierarchyManager(session); |
79 |
|
} |
80 |
|
|
81 |
|
|
82 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
83 |
1 |
@Test... |
84 |
|
public void testGetReturnsPropertyValue() throws RepositoryException { |
85 |
|
|
86 |
|
|
87 |
1 |
Response response = endpoint.readProperty(RepositoryConstants.WEBSITE, "/start/property"); |
88 |
|
|
89 |
|
|
90 |
1 |
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); |
91 |
1 |
RepositoryProperty property = (RepositoryProperty) response.getEntity(); |
92 |
1 |
assertEquals(1, property.getValues().size()); |
93 |
1 |
assertEquals("propertyValue", property.getValues().get(0)); |
94 |
|
} |
95 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
96 |
1 |
@Test... |
97 |
|
public void testGetMultiValuedProperty() throws RepositoryException { |
98 |
|
|
99 |
|
|
100 |
1 |
Response response = endpoint.readProperty(RepositoryConstants.WEBSITE, "/start/multiValueProperty"); |
101 |
|
|
102 |
|
|
103 |
1 |
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); |
104 |
1 |
RepositoryProperty property = (RepositoryProperty) response.getEntity(); |
105 |
1 |
assertEquals(2, property.getValues().size()); |
106 |
1 |
assertEquals("value1", property.getValues().get(0)); |
107 |
1 |
assertEquals("value2", property.getValues().get(1)); |
108 |
|
} |
109 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
110 |
1 |
@Test... |
111 |
|
public void testGetReturnsNotFoundForNonExistingProperty() throws RepositoryException { |
112 |
|
|
113 |
|
|
114 |
1 |
Response response = endpoint.readProperty(RepositoryConstants.WEBSITE, "/start/nonExistingProperty"); |
115 |
|
|
116 |
|
|
117 |
1 |
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus()); |
118 |
|
} |
119 |
|
|
120 |
|
|
121 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
122 |
1 |
@Test... |
123 |
|
public void testCreateProperty() throws RepositoryException { |
124 |
|
|
125 |
|
|
126 |
1 |
Response response = endpoint.createProperty(RepositoryConstants.WEBSITE, "/start", "newProperty", Arrays.asList("newValue"), PropertyType.TYPENAME_STRING, false); |
127 |
|
|
128 |
|
|
129 |
1 |
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); |
130 |
1 |
assertEquals("newValue", session.getProperty("/start/newProperty").getString()); |
131 |
|
} |
132 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
133 |
1 |
@Test... |
134 |
|
public void testCreatePropertyOnRootNode() throws RepositoryException { |
135 |
|
|
136 |
|
|
137 |
1 |
Response response = endpoint.createProperty(RepositoryConstants.WEBSITE, "/", "newProperty", Arrays.asList("newValue"), PropertyType.TYPENAME_STRING, false); |
138 |
|
|
139 |
|
|
140 |
1 |
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); |
141 |
1 |
assertEquals("newValue", session.getProperty("/newProperty").getString()); |
142 |
|
} |
143 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
144 |
1 |
@Test... |
145 |
|
public void testCreatePropertyOnRootNodePassingEmptyStringAsPath() throws RepositoryException { |
146 |
|
|
147 |
|
|
148 |
1 |
Response response = endpoint.createProperty(RepositoryConstants.WEBSITE, "", "newProperty", Arrays.asList("newValue"), PropertyType.TYPENAME_STRING, false); |
149 |
|
|
150 |
|
|
151 |
1 |
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); |
152 |
1 |
assertEquals("newValue", session.getProperty("/newProperty").getString()); |
153 |
|
} |
154 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
155 |
1 |
@Test... |
156 |
|
public void testCreateMultiValueProperty() throws RepositoryException { |
157 |
|
|
158 |
|
|
159 |
1 |
Response response = endpoint.createProperty(RepositoryConstants.WEBSITE, "/start", "newProperty", Arrays.asList("value1", "value2"), PropertyType.TYPENAME_STRING, true); |
160 |
|
|
161 |
|
|
162 |
1 |
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); |
163 |
1 |
assertTrue(session.getProperty("/start/newProperty").isMultiple()); |
164 |
1 |
assertEquals("value1", session.getProperty("/start/newProperty").getValues()[0].getString()); |
165 |
1 |
assertEquals("value2", session.getProperty("/start/newProperty").getValues()[1].getString()); |
166 |
|
} |
167 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
168 |
1 |
@Test... |
169 |
|
public void testCreateReturnsBadRequestIfNoValuesGiven() throws RepositoryException { |
170 |
|
|
171 |
|
|
172 |
1 |
Response response = endpoint.createProperty(RepositoryConstants.WEBSITE, "/start", "newProperty", Collections.<String>emptyList(), PropertyType.TYPENAME_STRING, false); |
173 |
|
|
174 |
|
|
175 |
1 |
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); |
176 |
|
} |
177 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
178 |
1 |
@Test... |
179 |
|
public void testCreateReturnsBadRequestIfMultipleValuesGivenButMultipleFlagIsFalse() throws RepositoryException { |
180 |
|
|
181 |
|
|
182 |
1 |
Response response = endpoint.createProperty(RepositoryConstants.WEBSITE, "/start", "newProperty", Arrays.asList("value1", "value2"), PropertyType.TYPENAME_STRING, false); |
183 |
|
|
184 |
|
|
185 |
1 |
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); |
186 |
|
} |
187 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
188 |
1 |
@Test... |
189 |
|
public void testCreateReturnsBadRequestWhenTypeIsUnknown() throws RepositoryException { |
190 |
|
|
191 |
|
|
192 |
1 |
Response response = endpoint.createProperty(RepositoryConstants.WEBSITE, "/start", "newProperty", Arrays.asList("newValue"), "UnknownType", false); |
193 |
|
|
194 |
|
|
195 |
1 |
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); |
196 |
|
} |
197 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
198 |
1 |
@Test... |
199 |
|
public void testCreateReturnsNotFoundWhenNodeDoesntExist() throws RepositoryException { |
200 |
|
|
201 |
|
|
202 |
1 |
Response response = endpoint.createProperty(RepositoryConstants.WEBSITE, "/nodeThatDoesntExist", "newProperty", Arrays.asList("newValue"), PropertyType.TYPENAME_STRING, false); |
203 |
|
|
204 |
|
|
205 |
1 |
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus()); |
206 |
|
} |
207 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
208 |
1 |
@Test... |
209 |
|
public void testCreateReturnsBadRequestIfPropertyAlreadyExists() throws RepositoryException { |
210 |
|
|
211 |
|
|
212 |
1 |
Response response = endpoint.createProperty(RepositoryConstants.WEBSITE, "/start", "property", Arrays.asList("newValue"), PropertyType.TYPENAME_STRING, false); |
213 |
|
|
214 |
|
|
215 |
1 |
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); |
216 |
|
} |
217 |
|
|
218 |
|
|
219 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
220 |
1 |
@Test... |
221 |
|
public void testUpdateProperty() throws RepositoryException { |
222 |
|
|
223 |
|
|
224 |
1 |
Response response = endpoint.updateProperty(RepositoryConstants.WEBSITE, "/start/property", Arrays.asList("newValue"), PropertyType.TYPENAME_STRING, false); |
225 |
|
|
226 |
|
|
227 |
1 |
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); |
228 |
1 |
assertEquals("newValue", session.getProperty("/start/property").getString()); |
229 |
|
} |
230 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
231 |
1 |
@Test... |
232 |
|
public void testUpdatePropertyOnRootNode() throws RepositoryException { |
233 |
|
|
234 |
1 |
session.getRootNode().setProperty("newProperty", "oldValue"); |
235 |
|
|
236 |
|
|
237 |
1 |
Response response = endpoint.updateProperty(RepositoryConstants.WEBSITE, "/newProperty", Arrays.asList("newValue"), PropertyType.TYPENAME_STRING, false); |
238 |
|
|
239 |
|
|
240 |
1 |
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); |
241 |
1 |
assertEquals("newValue", session.getProperty("/newProperty").getString()); |
242 |
|
} |
243 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
244 |
1 |
@Test... |
245 |
|
public void testUpdateSingleValuePropertyWithMultiValue() throws RepositoryException { |
246 |
|
|
247 |
|
|
248 |
1 |
Response response = endpoint.updateProperty(RepositoryConstants.WEBSITE, "/start/property", Arrays.asList("value1", "value2"), PropertyType.TYPENAME_STRING, true); |
249 |
|
|
250 |
|
|
251 |
1 |
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); |
252 |
1 |
assertTrue(session.getProperty("/start/property").isMultiple()); |
253 |
1 |
assertEquals("value1", session.getProperty("/start/property").getValues()[0].getString()); |
254 |
1 |
assertEquals("value2", session.getProperty("/start/property").getValues()[1].getString()); |
255 |
|
} |
256 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
257 |
1 |
@Test... |
258 |
|
public void testUpdateMultiValuePropertyWithSingleProperty() throws RepositoryException { |
259 |
|
|
260 |
|
|
261 |
1 |
Response response = endpoint.updateProperty(RepositoryConstants.WEBSITE, "/start/multiValueProperty", Arrays.asList("newValue"), PropertyType.TYPENAME_STRING, false); |
262 |
|
|
263 |
|
|
264 |
1 |
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); |
265 |
1 |
assertFalse(session.getProperty("/start/multiValueProperty").isMultiple()); |
266 |
1 |
assertEquals("newValue", session.getProperty("/start/multiValueProperty").getString()); |
267 |
|
} |
268 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
269 |
1 |
@Test... |
270 |
|
public void testUpdateReturnsBadRequestIfNoValuesGiven() throws RepositoryException { |
271 |
|
|
272 |
|
|
273 |
1 |
Response response = endpoint.updateProperty(RepositoryConstants.WEBSITE, "/start/property", Collections.<String>emptyList(), PropertyType.TYPENAME_STRING, false); |
274 |
|
|
275 |
|
|
276 |
1 |
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); |
277 |
|
} |
278 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
279 |
1 |
@Test... |
280 |
|
public void testUpdateReturnsBadRequestIfMultipleValuesGivenButMultipleFlagIsFalse() throws RepositoryException { |
281 |
|
|
282 |
|
|
283 |
1 |
Response response = endpoint.updateProperty(RepositoryConstants.WEBSITE, "/start/property", Arrays.asList("value1", "value2"), PropertyType.TYPENAME_STRING, false); |
284 |
|
|
285 |
|
|
286 |
1 |
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); |
287 |
|
} |
288 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
289 |
1 |
@Test... |
290 |
|
public void testUpdateReturnsBadRequestWhenTypeIsUnknown() throws RepositoryException { |
291 |
|
|
292 |
|
|
293 |
1 |
Response response = endpoint.updateProperty(RepositoryConstants.WEBSITE, "/start/property", Arrays.asList("newValue"), "UnknownType", false); |
294 |
|
|
295 |
|
|
296 |
1 |
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); |
297 |
|
} |
298 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
299 |
1 |
@Test... |
300 |
|
public void testUpdateReturnsNotFoundIfPropertyDoesntExist() throws RepositoryException { |
301 |
|
|
302 |
|
|
303 |
1 |
Response response = endpoint.updateProperty(RepositoryConstants.WEBSITE, "/start/propertyThatDoesntExist", Arrays.asList("newValue"), PropertyType.TYPENAME_STRING, false); |
304 |
|
|
305 |
|
|
306 |
1 |
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus()); |
307 |
|
} |
308 |
|
|
309 |
|
|
310 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
311 |
1 |
@Test... |
312 |
|
public void testDeleteReturnsNotFoundForNonExistingProperty() throws RepositoryException { |
313 |
|
|
314 |
|
|
315 |
1 |
Response response = endpoint.deleteProperty(RepositoryConstants.WEBSITE, "/start/nonExistingProperty"); |
316 |
|
|
317 |
|
|
318 |
1 |
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus()); |
319 |
|
} |
320 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
321 |
1 |
@Test... |
322 |
|
public void testDeleteProperty() throws RepositoryException { |
323 |
|
|
324 |
|
|
325 |
1 |
Response response = endpoint.deleteProperty(RepositoryConstants.WEBSITE, "/start/property"); |
326 |
|
|
327 |
|
|
328 |
1 |
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); |
329 |
1 |
assertFalse(session.propertyExists("/start/property")); |
330 |
|
} |
331 |
|
} |