1 | /* |
---|
2 | * Copyright (C) 2013 DASISH |
---|
3 | * |
---|
4 | * This program is free software; you can redistribute it and/or |
---|
5 | * modify it under the terms of the GNU General Public License |
---|
6 | * as published by the Free Software Foundation; either version 2 |
---|
7 | * of the License, or (at your option) any later version. |
---|
8 | * |
---|
9 | * This program is distributed in the hope that it will be useful, |
---|
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | * GNU General Public License for more details. |
---|
13 | * |
---|
14 | * You should have received a copy of the GNU General Public License |
---|
15 | * along with this program; if not, write to the Free Software |
---|
16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
17 | */ |
---|
18 | package eu.dasish.annotation.backend.dao.impl; |
---|
19 | |
---|
20 | import eu.dasish.annotation.backend.Helpers; |
---|
21 | import eu.dasish.annotation.backend.NotInDataBaseException; |
---|
22 | import eu.dasish.annotation.backend.TestInstances; |
---|
23 | import eu.dasish.annotation.schema.Annotation; |
---|
24 | import eu.dasish.annotation.schema.Access; |
---|
25 | import eu.dasish.annotation.schema.AnnotationBody; |
---|
26 | import eu.dasish.annotation.schema.AnnotationBody.XmlBody; |
---|
27 | import eu.dasish.annotation.schema.AnnotationInfo; |
---|
28 | import java.io.IOException; |
---|
29 | import java.sql.SQLException; |
---|
30 | import java.sql.Timestamp; |
---|
31 | import java.util.ArrayList; |
---|
32 | import java.util.HashMap; |
---|
33 | import java.util.List; |
---|
34 | import java.util.Map; |
---|
35 | import java.util.UUID; |
---|
36 | import javax.xml.datatype.DatatypeConfigurationException; |
---|
37 | import javax.xml.datatype.DatatypeFactory; |
---|
38 | import javax.xml.parsers.ParserConfigurationException; |
---|
39 | import static org.junit.Assert.*; |
---|
40 | import org.junit.Test; |
---|
41 | import org.junit.runner.RunWith; |
---|
42 | import org.springframework.beans.factory.annotation.Autowired; |
---|
43 | import org.springframework.test.context.ContextConfiguration; |
---|
44 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
---|
45 | import org.w3c.dom.Element; |
---|
46 | import org.xml.sax.SAXException; |
---|
47 | |
---|
48 | /** |
---|
49 | * |
---|
50 | * @author olhsha |
---|
51 | */ |
---|
52 | @RunWith(SpringJUnit4ClassRunner.class) |
---|
53 | @ContextConfiguration({"/spring-test-config/dataSource.xml", "/spring-config/annotationDao.xml"}) |
---|
54 | public class JdbcAnnotationDaoTest extends JdbcResourceDaoTest { |
---|
55 | |
---|
56 | @Autowired |
---|
57 | JdbcAnnotationDao jdbcAnnotationDao; |
---|
58 | TestInstances testInstances = new TestInstances("/api"); |
---|
59 | |
---|
60 | /** |
---|
61 | * Test of stringURItoExternalID method public String |
---|
62 | * stringURItoExternalID(String uri); |
---|
63 | */ |
---|
64 | @Test |
---|
65 | public void testHrefToExternalID() { |
---|
66 | System.out.println("test stringURItoExternalID"); |
---|
67 | jdbcAnnotationDao.setResourcePath("/api/annotations/"); |
---|
68 | String randomUUID = Helpers.generateUUID().toString(); |
---|
69 | String uri = "/api/annotations/" + randomUUID; |
---|
70 | String uuid = jdbcAnnotationDao.hrefToExternalID(uri); |
---|
71 | assertEquals(randomUUID, uuid); |
---|
72 | } |
---|
73 | |
---|
74 | /** |
---|
75 | * Test of externalIDtoURI method public String externalIDtoURI(String |
---|
76 | * externalID); |
---|
77 | */ |
---|
78 | @Test |
---|
79 | public void testExternalIDtoHref() { |
---|
80 | System.out.println("test externalIDtoHref"); |
---|
81 | jdbcAnnotationDao.setResourcePath("/api/annotations/"); |
---|
82 | String randomUUID = Helpers.generateUUID().toString(); |
---|
83 | String uri = "/api/annotations/" + randomUUID; |
---|
84 | String uriResult = jdbcAnnotationDao.externalIDtoHref(randomUUID); |
---|
85 | assertEquals(uri, uriResult); |
---|
86 | } |
---|
87 | |
---|
88 | /** |
---|
89 | * Test of retrieveTargetIDs method, of class JdbcAnnotationDao. |
---|
90 | */ |
---|
91 | /** |
---|
92 | * Test of getAnnotations method, of class JdbcNotebookDao. |
---|
93 | */ |
---|
94 | @Test |
---|
95 | public void testGetAnnotations() { |
---|
96 | System.out.println("test getAnnotations"); |
---|
97 | List<Number> expResult = new ArrayList<Number>(); |
---|
98 | expResult.add(1); |
---|
99 | expResult.add(2); |
---|
100 | List<Number> result = jdbcAnnotationDao.getAnnotations(1); |
---|
101 | assertEquals(expResult, result); |
---|
102 | } |
---|
103 | |
---|
104 | /////////////////////////////////////////// |
---|
105 | @Test |
---|
106 | public void testDeleteAllAnnotationTarget() { |
---|
107 | System.out.println("test deleteAllAnnotationTargets"); |
---|
108 | assertEquals(2, jdbcAnnotationDao.deleteAllAnnotationTarget(1)); |
---|
109 | assertEquals(0, jdbcAnnotationDao.deleteAllAnnotationTarget(1)); |
---|
110 | } |
---|
111 | |
---|
112 | /////////////////////////////////////////// |
---|
113 | @Test |
---|
114 | public void testDeleteAnnotationPrinciplePermissions() { |
---|
115 | System.out.println("test deleteAllAnnotationTargets"); |
---|
116 | int result = jdbcAnnotationDao.deletePermissions(1); |
---|
117 | assertEquals(3, result); |
---|
118 | assertEquals(0, jdbcAnnotationDao.deletePermissions(1)); |
---|
119 | } |
---|
120 | |
---|
121 | /////////////////////////////////////////// |
---|
122 | @Test |
---|
123 | public void testAddAnnotationPrincipalAccess() { |
---|
124 | System.out.println("test addAnnotationTargets"); |
---|
125 | int result = jdbcAnnotationDao.addPermission(1, 1, Access.READ); |
---|
126 | assertEquals(1, result); |
---|
127 | } |
---|
128 | |
---|
129 | /////////////////////////////////////////// |
---|
130 | @Test |
---|
131 | public void testAddAnnotationTarget() { |
---|
132 | System.out.println("test addAnnotationTargetPair"); |
---|
133 | assertEquals(1, jdbcAnnotationDao.addAnnotationTarget(1, 3)); |
---|
134 | } |
---|
135 | |
---|
136 | /** |
---|
137 | * Test of getAnnotationREFs method, of class JdbcAnnotationDao. |
---|
138 | * List<ReTargetREF> getAnnotationREFs(List<Number> annotationIDs) |
---|
139 | */ |
---|
140 | @Test |
---|
141 | public void testGetAnnotationREFs() { |
---|
142 | System.out.println("getAnnotationREFs"); |
---|
143 | List<Number> annotIds = new ArrayList<Number>(); |
---|
144 | annotIds.add(1); |
---|
145 | annotIds.add(2); |
---|
146 | annotIds.add(3); |
---|
147 | |
---|
148 | jdbcAnnotationDao.setResourcePath("/api/annotations/"); |
---|
149 | final List<String> testList = jdbcAnnotationDao.getAnnotationREFs(annotIds); |
---|
150 | assertEquals(3, testList.size()); |
---|
151 | assertEquals("/api/annotations/00000000-0000-0000-0000-000000000021", testList.get(0)); |
---|
152 | assertEquals("/api/annotations/00000000-0000-0000-0000-000000000022", testList.get(1)); |
---|
153 | assertEquals("/api/annotations/00000000-0000-0000-0000-000000000023", testList.get(2)); |
---|
154 | |
---|
155 | final List<String> testListTwo = jdbcAnnotationDao.getAnnotationREFs(new ArrayList<Number>()); |
---|
156 | assertEquals(0, testListTwo.size()); |
---|
157 | |
---|
158 | } |
---|
159 | |
---|
160 | /** |
---|
161 | * |
---|
162 | * Test of getAnnotationID method, of class JdbcAnnotationDao. Integer |
---|
163 | * getAnnotationID(UUID externalID) |
---|
164 | */ |
---|
165 | @Test |
---|
166 | public void getInternalID() throws NotInDataBaseException { |
---|
167 | System.out.println("test getInternalID"); |
---|
168 | |
---|
169 | final Number annotaionId = jdbcAnnotationDao.getInternalID(UUID.fromString("00000000-0000-0000-0000-000000000021")); |
---|
170 | assertEquals(1, annotaionId.intValue()); |
---|
171 | |
---|
172 | try { |
---|
173 | final Number annotaionIdNE = jdbcAnnotationDao.getInternalID(UUID.fromString("00000000-0000-0000-0000-0000000000cc")); |
---|
174 | } catch (NotInDataBaseException e) { |
---|
175 | System.out.println(e); |
---|
176 | } |
---|
177 | |
---|
178 | |
---|
179 | } |
---|
180 | |
---|
181 | /** |
---|
182 | * Test of getInternalIDFromURI method, public Number |
---|
183 | * getInternalIDFromURI(UUID externalID); |
---|
184 | */ |
---|
185 | @Test |
---|
186 | public void testGetInternalIDFRomHref() throws NotInDataBaseException { |
---|
187 | System.out.println("test getInternalIDFromHref"); |
---|
188 | jdbcAnnotationDao.setResourcePath("/api/annotations/"); |
---|
189 | String uri = "/api/annotations/00000000-0000-0000-0000-000000000021"; |
---|
190 | Number result = jdbcAnnotationDao.getInternalIDFromHref(uri); |
---|
191 | assertEquals(1, result.intValue()); |
---|
192 | assertEquals(1, result); |
---|
193 | } |
---|
194 | |
---|
195 | /** |
---|
196 | * |
---|
197 | * Test of getAnnotationWithoutTargetsAndPemissions method, of class |
---|
198 | * JdbcAnnotationDao. Annotation getAnnotation(Number annotationlID) |
---|
199 | */ |
---|
200 | @Test |
---|
201 | public void getAnnotationWithoutTargetsAndPermisions() throws DatatypeConfigurationException { |
---|
202 | System.out.println("test getAnnotationWithoutTargetsAndPermissions"); |
---|
203 | jdbcAnnotationDao.setResourcePath("/api/annotations/"); |
---|
204 | final Annotation result = jdbcAnnotationDao.getAnnotationWithoutTargetsAndPemissions(1); |
---|
205 | |
---|
206 | assertEquals("Sagrada Famiglia", result.getHeadline()); |
---|
207 | assertEquals("<html><body>some html 1</body></html>", result.getBody().getTextBody().getBody()); |
---|
208 | assertEquals("text/html", result.getBody().getTextBody().getMimeType()); |
---|
209 | assertEquals("00000000-0000-0000-0000-000000000021", result.getId()); |
---|
210 | assertEquals("/api/annotations/00000000-0000-0000-0000-000000000021", result.getHref()); |
---|
211 | assertEquals(DatatypeFactory.newInstance().newXMLGregorianCalendar("2013-08-12T09:25:00.383000Z"), result.getLastModified()); |
---|
212 | } |
---|
213 | |
---|
214 | /** |
---|
215 | * Test of deletAnnotation method, of class JdbcAnnotationDao. |
---|
216 | */ |
---|
217 | /** |
---|
218 | * |
---|
219 | * @param annotationId |
---|
220 | * @return removed annotation rows (should be 1) |
---|
221 | */ |
---|
222 | @Test |
---|
223 | public void testDeleteAnnotation() { |
---|
224 | System.out.println("deleteAnnotation"); |
---|
225 | |
---|
226 | // to provide integrity, first delete rows in the joint tables |
---|
227 | jdbcAnnotationDao.deleteAllAnnotationTarget(4); |
---|
228 | jdbcAnnotationDao.deletePermissions(4); |
---|
229 | |
---|
230 | assertEquals(1, jdbcAnnotationDao.deleteAnnotation(4)); |
---|
231 | assertEquals(0, jdbcAnnotationDao.deleteAnnotation(4)); |
---|
232 | } |
---|
233 | |
---|
234 | /** |
---|
235 | * Test of addAnnotation method, of class JdbcAnnotationDao. |
---|
236 | */ |
---|
237 | @Test |
---|
238 | public void testAddAnnotation() throws SQLException, Exception { |
---|
239 | System.out.println("test_addAnnotation "); |
---|
240 | jdbcAnnotationDao.setResourcePath("/api/annotations/"); |
---|
241 | final Annotation annotationToAdd = testInstances.getAnnotationToAdd();// existing Targets |
---|
242 | |
---|
243 | Number newAnnotationID = jdbcAnnotationDao.addAnnotation(annotationToAdd, 3); |
---|
244 | assertEquals(5, newAnnotationID); |
---|
245 | |
---|
246 | // checking |
---|
247 | Annotation addedAnnotation = jdbcAnnotationDao.getAnnotationWithoutTargetsAndPemissions(5); |
---|
248 | assertEquals(addedAnnotation.getHref(), "/api/annotations/"+addedAnnotation.getId()); |
---|
249 | assertFalse(null == addedAnnotation.getLastModified()); |
---|
250 | assertEquals(annotationToAdd.getBody().getTextBody().getMimeType(), addedAnnotation.getBody().getTextBody().getMimeType()); |
---|
251 | assertEquals(annotationToAdd.getBody().getTextBody().getBody(), addedAnnotation.getBody().getTextBody().getBody()); |
---|
252 | assertEquals(annotationToAdd.getHeadline(), addedAnnotation.getHeadline()); |
---|
253 | System.out.println("creation time " + addedAnnotation.getLastModified()); |
---|
254 | } |
---|
255 | |
---|
256 | |
---|
257 | |
---|
258 | ////////////////////////////////// |
---|
259 | @Test |
---|
260 | public void testGetExternalID() { |
---|
261 | System.out.println("getExternalID"); |
---|
262 | |
---|
263 | final UUID externalId = jdbcAnnotationDao.getExternalID(1); |
---|
264 | assertEquals(UUID.fromString("00000000-0000-0000-0000-000000000021"), externalId); |
---|
265 | |
---|
266 | } |
---|
267 | |
---|
268 | /** |
---|
269 | * test public List<Number> getFilteredAnnotationIDs(String link, String |
---|
270 | * text, String access, String namespace, UUID owner, Timestamp after, |
---|
271 | * Timestamp before) { |
---|
272 | * |
---|
273 | */ |
---|
274 | @Test |
---|
275 | public void testGetFilteredAnnotationIDs() { |
---|
276 | System.out.println(" test getFilteredAnnotationIDs"); |
---|
277 | |
---|
278 | List<Number> result_1 = jdbcAnnotationDao.getFilteredAnnotationIDs(null, "some html", null, null, null); |
---|
279 | assertEquals(3, result_1.size()); |
---|
280 | assertEquals(1, result_1.get(0)); |
---|
281 | assertEquals(2, result_1.get(1)); |
---|
282 | assertEquals(4, result_1.get(2)); |
---|
283 | |
---|
284 | |
---|
285 | final String after = (new Timestamp(0)).toString(); |
---|
286 | final String before = (new Timestamp(System.currentTimeMillis())).toString(); |
---|
287 | |
---|
288 | List<Number> result_2 = jdbcAnnotationDao.getFilteredAnnotationIDs(1, "some html", null, after, before); |
---|
289 | assertEquals(1, result_2.size()); |
---|
290 | assertEquals(1, result_2.get(0)); |
---|
291 | |
---|
292 | final String after_1 = (new Timestamp(System.currentTimeMillis())).toString();// no annotations added after "now" |
---|
293 | List<Number> result_3 = jdbcAnnotationDao.getFilteredAnnotationIDs(4, "some html", null, after_1, null); |
---|
294 | assertEquals(0, result_3.size()); |
---|
295 | |
---|
296 | |
---|
297 | } |
---|
298 | |
---|
299 | ////////////////////////////////// |
---|
300 | @Test |
---|
301 | public void testGetReprmissions() { |
---|
302 | System.out.println("test getPermissions"); |
---|
303 | List<Map<Number, String>> result = jdbcAnnotationDao.getPermissions(1); |
---|
304 | assertEquals(3, result.size()); |
---|
305 | assertEquals("write", result.get(0).get(2)); |
---|
306 | assertEquals("read", result.get(1).get(3)); |
---|
307 | assertEquals("read", result.get(2).get(11)); |
---|
308 | |
---|
309 | } |
---|
310 | |
---|
311 | // getAnnotationIDsForPermission(Number principalID, Access access) |
---|
312 | @Test |
---|
313 | public void testAnnotationIDsForPermission() { |
---|
314 | System.out.println("test getAnnotationIDsForPermission"); |
---|
315 | List<Number> result = jdbcAnnotationDao.getAnnotationIDsPermissionAtLeast(1, Access.READ); |
---|
316 | assertEquals(3, result.size()); |
---|
317 | assertEquals(2, result.get(0)); |
---|
318 | assertEquals(3, result.get(1)); |
---|
319 | assertEquals(4, result.get(2)); |
---|
320 | |
---|
321 | List<Number> resultTwo = jdbcAnnotationDao.getAnnotationIDsPermissionAtLeast(1, Access.WRITE); |
---|
322 | assertEquals(1, resultTwo.size()); |
---|
323 | assertEquals(4, resultTwo.get(0)); |
---|
324 | |
---|
325 | List<Number> resultThree = jdbcAnnotationDao.getAnnotationIDsPermissionAtLeast(1, Access.NONE); |
---|
326 | assertEquals(0, resultThree.size()); |
---|
327 | |
---|
328 | } |
---|
329 | |
---|
330 | // getAnnotationIDsForPublicAccess |
---|
331 | @Test |
---|
332 | public void testAnnotationIDsForPublicAccess() { |
---|
333 | System.out.println("test getAnnotationIDsForPublicAccess"); |
---|
334 | List<Number> result = jdbcAnnotationDao.getAnnotationIDsPublicAtLeast(Access.READ); |
---|
335 | assertEquals(2, result.size()); |
---|
336 | assertTrue(result.contains(1)); |
---|
337 | assertTrue(result.contains(2)); |
---|
338 | |
---|
339 | List<Number> resultTwo = jdbcAnnotationDao.getAnnotationIDsPublicAtLeast(Access.WRITE); |
---|
340 | assertEquals(1, resultTwo.size()); |
---|
341 | assertEquals(1, resultTwo.get(0)); |
---|
342 | |
---|
343 | |
---|
344 | List<Number> resultThree = jdbcAnnotationDao.getAnnotationIDsPublicAtLeast(Access.NONE); |
---|
345 | assertEquals(2, resultThree.size()); |
---|
346 | assertTrue(resultThree.contains(3)); |
---|
347 | assertTrue(resultThree.contains(4)); |
---|
348 | |
---|
349 | } |
---|
350 | |
---|
351 | @Test |
---|
352 | public void testGetPublicAttribute() { |
---|
353 | System.out.println("test getPublicAttribute"); |
---|
354 | assertEquals(Access.WRITE, jdbcAnnotationDao.getPublicAttribute(1)); |
---|
355 | assertEquals(Access.READ, jdbcAnnotationDao.getPublicAttribute(2)); |
---|
356 | assertEquals(Access.NONE, jdbcAnnotationDao.getPublicAttribute(3)); |
---|
357 | } |
---|
358 | |
---|
359 | @Test |
---|
360 | public void testGetAccess() { |
---|
361 | System.out.println("test getAccess"); |
---|
362 | assertEquals(Access.READ, jdbcAnnotationDao.getAccess(1, 3)); |
---|
363 | assertEquals(Access.WRITE, jdbcAnnotationDao.getAccess(2, 3)); |
---|
364 | assertEquals(Access.NONE, jdbcAnnotationDao.getAccess(3, 3)); |
---|
365 | } |
---|
366 | |
---|
367 | @Test |
---|
368 | public void testSublistOrderedAnnotationIDs() { |
---|
369 | System.out.println("test getSublistOrderedAnnotationIDs"); |
---|
370 | |
---|
371 | final List<Number> annotationIDs = new ArrayList<Number>(); |
---|
372 | annotationIDs.add(1); |
---|
373 | annotationIDs.add(2); |
---|
374 | annotationIDs.add(3); |
---|
375 | annotationIDs.add(4); |
---|
376 | |
---|
377 | List<Number> result = jdbcAnnotationDao.sublistOrderedAnnotationIDs(annotationIDs, 1, 3, "last_modified", "DESC"); |
---|
378 | assertEquals(3, result.size()); |
---|
379 | assertEquals(3, result.get(0)); |
---|
380 | assertEquals(2, result.get(1)); |
---|
381 | assertEquals(1, result.get(2)); |
---|
382 | } |
---|
383 | |
---|
384 | @Test |
---|
385 | public void testGetOwner() { |
---|
386 | System.out.println("test getOwner"); |
---|
387 | assertEquals(1, jdbcAnnotationDao.getOwner(1)); |
---|
388 | } |
---|
389 | |
---|
390 | @Test |
---|
391 | public void testGetAnnotationInfoWithoutTargetsAndOwner() throws DatatypeConfigurationException { |
---|
392 | System.out.println("test getAnnotationInfoWithoutTargets"); |
---|
393 | jdbcAnnotationDao.setResourcePath("/api/annotations/"); |
---|
394 | final AnnotationInfo result = jdbcAnnotationDao.getAnnotationInfoWithoutTargetsAndOwner(1); |
---|
395 | |
---|
396 | assertEquals("Sagrada Famiglia", result.getHeadline()); |
---|
397 | assertEquals("/api/annotations/00000000-0000-0000-0000-000000000021", result.getHref()); |
---|
398 | assertEquals(DatatypeFactory.newInstance().newXMLGregorianCalendar("2013-08-12T09:25:00.383000Z"), result.getLastModified()); |
---|
399 | } |
---|
400 | |
---|
401 | @Test |
---|
402 | public void testTargetIsInUse() { |
---|
403 | System.out.println("test targetIsInUse"); |
---|
404 | assertTrue(jdbcAnnotationDao.targetIsInUse(1)); |
---|
405 | assertFalse(jdbcAnnotationDao.targetIsInUse(6)); |
---|
406 | } |
---|
407 | |
---|
408 | @Test |
---|
409 | public void testGetAllAnnotationIDs() { |
---|
410 | System.out.println("test getAllAnnotationIDs"); |
---|
411 | List<Number> result = jdbcAnnotationDao.getAllAnnotationIDs(); |
---|
412 | assertEquals(4, result.size()); |
---|
413 | assertEquals(4, result.get(0)); |
---|
414 | assertEquals(3, result.get(1)); |
---|
415 | assertEquals(2, result.get(2)); |
---|
416 | assertEquals(1, result.get(3)); |
---|
417 | } |
---|
418 | |
---|
419 | @Test |
---|
420 | public void testUpdateAnnotationBody() { |
---|
421 | System.out.println("test updateAnnotationbody "); |
---|
422 | int result = jdbcAnnotationDao.updateAnnotationBody(1, "some html 1 updated", "text/plain", false); |
---|
423 | assertEquals(1, result); |
---|
424 | Annotation check = jdbcAnnotationDao.getAnnotationWithoutTargetsAndPemissions(1); |
---|
425 | assertEquals("some html 1 updated", check.getBody().getTextBody().getBody()); |
---|
426 | assertEquals("text/plain", check.getBody().getTextBody().getMimeType()); |
---|
427 | |
---|
428 | String testXml = "<xhtml:span style=\"background-color:rgb(0,0,153);color:rgb(255,255,255);border: thick solid rgb(0, 0, 153);\">test</xhtml:span>"; |
---|
429 | int result2 = jdbcAnnotationDao.updateAnnotationBody(1, testXml, "application/xml", true); |
---|
430 | assertEquals(1, result2); |
---|
431 | Annotation check2 = jdbcAnnotationDao.getAnnotationWithoutTargetsAndPemissions(1); |
---|
432 | assertEquals("xhtml:span", check2.getBody().getXmlBody().getAny().getNodeName()); |
---|
433 | assertTrue(check2.getBody().getXmlBody().getAny().hasAttribute("style")); |
---|
434 | assertEquals("test", check2.getBody().getXmlBody().getAny().getTextContent()); |
---|
435 | assertEquals("application/xml", check2.getBody().getXmlBody().getMimeType()); |
---|
436 | } |
---|
437 | |
---|
438 | @Test |
---|
439 | public void testUpdateAnnotationHeader() { |
---|
440 | System.out.println("test updateAnnotationHeader "); |
---|
441 | int result = jdbcAnnotationDao.updateAnnotationHeadline(1, "new Header"); |
---|
442 | assertEquals(1, result); |
---|
443 | Annotation check = jdbcAnnotationDao.getAnnotationWithoutTargetsAndPemissions(1); |
---|
444 | assertEquals("new Header", check.getHeadline()); |
---|
445 | } |
---|
446 | |
---|
447 | @Test |
---|
448 | public void testUpdateAnnotationPrincipalAccess() { |
---|
449 | System.out.println("test updateAnntationPrincipalAccess "); |
---|
450 | |
---|
451 | int result = jdbcAnnotationDao.updatePermission(1, 2, Access.NONE); |
---|
452 | assertEquals(1, result); |
---|
453 | assertEquals(Access.NONE, jdbcAnnotationDao.getAccess(1, 2)); |
---|
454 | } |
---|
455 | |
---|
456 | @Test |
---|
457 | public void testUpdatPublicAttribute() { |
---|
458 | System.out.println("test updatePublicAtribute "); |
---|
459 | |
---|
460 | int result = jdbcAnnotationDao.updatePublicAccess(1, Access.NONE); |
---|
461 | assertEquals(1, result); |
---|
462 | assertEquals(Access.NONE, jdbcAnnotationDao.getPublicAttribute(1)); |
---|
463 | } |
---|
464 | |
---|
465 | @Test |
---|
466 | public void testUpdateIdentifier() throws NotInDataBaseException{ |
---|
467 | System.out.println("test updateResourceIdentifier "); |
---|
468 | |
---|
469 | boolean result = jdbcAnnotationDao.updateResourceIdentifier(UUID.fromString("00000000-0000-0000-0000-000000000021"), UUID.fromString("10000000-0000-0000-0000-000000000021")); |
---|
470 | assertEquals(true, result); |
---|
471 | Number id = jdbcAnnotationDao.getInternalID(UUID.fromString("10000000-0000-0000-0000-000000000021")); |
---|
472 | assertEquals(1, id); |
---|
473 | } |
---|
474 | |
---|
475 | @Test |
---|
476 | public void testRetrieveBodyComponents() throws ParserConfigurationException, IOException, SAXException { |
---|
477 | System.out.println("test retrieveBodyComponents 1"); |
---|
478 | |
---|
479 | AnnotationBody ab = testInstances.getAnnotationOne().getBody(); |
---|
480 | |
---|
481 | String[] result = jdbcAnnotationDao.retrieveBodyComponents(ab); |
---|
482 | assertEquals(2, result.length); |
---|
483 | assertEquals("<html><body>some html 1</body></html>", result[0]); |
---|
484 | assertEquals("text/html", result[1]); |
---|
485 | |
---|
486 | |
---|
487 | String testXml = "<xhtml:span style=\"background-color:rgb(0,0,153);color:rgb(255,255,255);border: thick solid rgb(0, 0, 153);\">test</xhtml:span>"; |
---|
488 | AnnotationBody ab2 = new AnnotationBody(); |
---|
489 | XmlBody xb = new XmlBody(); |
---|
490 | Element el = Helpers.stringToElement(testXml); |
---|
491 | String str = Helpers.elementToString(el); |
---|
492 | xb.setAny(el); |
---|
493 | xb.setMimeType("application/xml"); |
---|
494 | ab2.setXmlBody(xb); |
---|
495 | System.out.println("test retrieveBodyComponents 2"); |
---|
496 | String[] result2 = jdbcAnnotationDao.retrieveBodyComponents(ab2); |
---|
497 | assertEquals(2, result2.length); |
---|
498 | assertEquals(str, result2[0]); |
---|
499 | assertEquals("application/xml", result2[1]); |
---|
500 | } |
---|
501 | |
---|
502 | @Test |
---|
503 | public void testUpdateAnnotation() { |
---|
504 | System.out.println("test UpdateAnnotation"); |
---|
505 | jdbcAnnotationDao.setResourcePath("/api/annotations/"); |
---|
506 | |
---|
507 | Annotation annotation = testInstances.getAnnotationOne(); |
---|
508 | annotation.setHeadline("updated headline 1"); |
---|
509 | annotation.getBody().getTextBody().setBody("updated some html 1"); |
---|
510 | annotation.getBody().getTextBody().setMimeType("text/plain"); |
---|
511 | |
---|
512 | |
---|
513 | int result = jdbcAnnotationDao.updateAnnotation(annotation,1, 1); |
---|
514 | assertEquals(1, result); |
---|
515 | System.out.println(" annotation updated"); |
---|
516 | Annotation check = jdbcAnnotationDao.getAnnotationWithoutTargetsAndPemissions(1); |
---|
517 | assertEquals("updated some html 1", check.getBody().getTextBody().getBody()); |
---|
518 | assertEquals("text/plain", check.getBody().getTextBody().getMimeType()); |
---|
519 | assertEquals("updated headline 1", check.getHeadline()); |
---|
520 | assertEquals("/api/annotations/00000000-0000-0000-0000-000000000021", check.getHref()); |
---|
521 | assertEquals("00000000-0000-0000-0000-000000000021", check.getId()); |
---|
522 | } |
---|
523 | |
---|
524 | @Test |
---|
525 | public void helperReplaceString() { |
---|
526 | System.out.println("test Helpers.ReplaceString"); |
---|
527 | StringBuilder source = new StringBuilder("va%?&b;v_wa%?&b;w"); |
---|
528 | String oldFragment = "a%?&b;"; |
---|
529 | String newFragment = ":;:"; |
---|
530 | Helpers.replaceString(source, oldFragment, (Object) newFragment); |
---|
531 | assertEquals(source.toString(), "v:;:v_w:;:w"); |
---|
532 | } |
---|
533 | |
---|
534 | @Test |
---|
535 | public void helperReplace() { |
---|
536 | System.out.println("test Helpers.Replace"); |
---|
537 | String source = "va%?&b;v_xy:_wa%?&b;w"; |
---|
538 | Map<String, String> replacements = new HashMap<String,String>(); |
---|
539 | replacements.put("a%?&b;", ":;:"); |
---|
540 | replacements.put("xy:", ":yx"); |
---|
541 | replacements.put("", ":;:"); |
---|
542 | String sourceUPD = Helpers.replace(source, replacements); |
---|
543 | assertEquals(sourceUPD, "v:;:v_:yx_w:;:w"); |
---|
544 | } |
---|
545 | } |
---|