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.MatchMode; |
---|
22 | import eu.dasish.annotation.backend.NotInDataBaseException; |
---|
23 | import eu.dasish.annotation.backend.PrincipalCannotBeDeleted; |
---|
24 | import eu.dasish.annotation.backend.PrincipalExists; |
---|
25 | import eu.dasish.annotation.backend.Resource; |
---|
26 | import eu.dasish.annotation.backend.TestInstances; |
---|
27 | import eu.dasish.annotation.backend.dao.AnnotationDao; |
---|
28 | import eu.dasish.annotation.backend.dao.CachedRepresentationDao; |
---|
29 | import eu.dasish.annotation.backend.dao.NotebookDao; |
---|
30 | import eu.dasish.annotation.backend.dao.TargetDao; |
---|
31 | import eu.dasish.annotation.backend.dao.PrincipalDao; |
---|
32 | import eu.dasish.annotation.schema.Annotation; |
---|
33 | import eu.dasish.annotation.schema.AnnotationBody; |
---|
34 | import eu.dasish.annotation.schema.AnnotationBody.TextBody; |
---|
35 | import eu.dasish.annotation.schema.AnnotationInfo; |
---|
36 | import eu.dasish.annotation.schema.AnnotationInfoList; |
---|
37 | import eu.dasish.annotation.schema.CachedRepresentationInfo; |
---|
38 | import eu.dasish.annotation.schema.Notebook; |
---|
39 | import eu.dasish.annotation.schema.NotebookInfo; |
---|
40 | import eu.dasish.annotation.schema.NotebookInfoList; |
---|
41 | import eu.dasish.annotation.schema.Access; |
---|
42 | import eu.dasish.annotation.schema.ReferenceList; |
---|
43 | import eu.dasish.annotation.schema.Target; |
---|
44 | import eu.dasish.annotation.schema.TargetInfo; |
---|
45 | import eu.dasish.annotation.schema.Principal; |
---|
46 | import eu.dasish.annotation.schema.Permission; |
---|
47 | import eu.dasish.annotation.schema.PermissionList; |
---|
48 | import java.io.ByteArrayInputStream; |
---|
49 | import java.io.IOException; |
---|
50 | import java.sql.SQLException; |
---|
51 | import java.sql.Timestamp; |
---|
52 | import java.util.ArrayList; |
---|
53 | import java.util.HashMap; |
---|
54 | import java.util.List; |
---|
55 | import java.util.Map; |
---|
56 | import java.util.UUID; |
---|
57 | import javax.sql.rowset.serial.SerialException; |
---|
58 | import javax.xml.datatype.DatatypeConfigurationException; |
---|
59 | import javax.xml.datatype.DatatypeFactory; |
---|
60 | import javax.xml.datatype.XMLGregorianCalendar; |
---|
61 | import org.jmock.Expectations; |
---|
62 | import org.jmock.Mockery; |
---|
63 | import org.junit.Test; |
---|
64 | import static org.junit.Assert.*; |
---|
65 | import org.junit.Ignore; |
---|
66 | import org.junit.runner.RunWith; |
---|
67 | import org.springframework.beans.factory.annotation.Autowired; |
---|
68 | import org.springframework.test.context.ContextConfiguration; |
---|
69 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
---|
70 | |
---|
71 | /** |
---|
72 | * |
---|
73 | * @author olhsha |
---|
74 | */ |
---|
75 | @RunWith(SpringJUnit4ClassRunner.class) |
---|
76 | @ContextConfiguration({"/spring-test-config/dataSource.xml", "/spring-test-config/mockeryDao.xml", "/spring-test-config/mockAnnotationDao.xml", |
---|
77 | "/spring-test-config/mockPrincipalDao.xml", "/spring-test-config/mockTargetDao.xml", "/spring-test-config/mockCachedRepresentationDao.xml", |
---|
78 | "/spring-test-config/mockNotebookDao.xml", |
---|
79 | "/spring-config/dbDispatcher.xml"}) |
---|
80 | public class DBDispatcherTest { |
---|
81 | |
---|
82 | @Autowired |
---|
83 | private DBDispatcherImlp dbDispatcher; |
---|
84 | @Autowired |
---|
85 | private Mockery mockeryDao; |
---|
86 | @Autowired |
---|
87 | private PrincipalDao principalDao; |
---|
88 | @Autowired |
---|
89 | private CachedRepresentationDao cachedRepresentationDao; |
---|
90 | @Autowired |
---|
91 | private TargetDao targetDao; |
---|
92 | @Autowired |
---|
93 | private AnnotationDao annotationDao; |
---|
94 | @Autowired |
---|
95 | private NotebookDao notebookDao; |
---|
96 | TestInstances testInstances = new TestInstances("/api"); |
---|
97 | |
---|
98 | public DBDispatcherTest() { |
---|
99 | } |
---|
100 | |
---|
101 | |
---|
102 | |
---|
103 | ///////// GETTERS ///////////// |
---|
104 | /** |
---|
105 | * Test of getAnnotationInternalIdentifier method, of class |
---|
106 | * DBIntegrityServiceImlp. |
---|
107 | */ |
---|
108 | |
---|
109 | @Test |
---|
110 | public void testGetAnnotationInternalIdentifier() throws NotInDataBaseException { |
---|
111 | System.out.println("getAnnotationInternalIdentifier"); |
---|
112 | |
---|
113 | final UUID externalID = UUID.fromString("00000000-0000-0000-0000-000000000021"); |
---|
114 | mockeryDao.checking(new Expectations() { |
---|
115 | { |
---|
116 | oneOf(annotationDao).getInternalID(externalID); |
---|
117 | will(returnValue(1)); |
---|
118 | } |
---|
119 | }); |
---|
120 | assertEquals(1, dbDispatcher.getResourceInternalIdentifier(externalID, Resource.ANNOTATION)); |
---|
121 | } |
---|
122 | |
---|
123 | /** |
---|
124 | * Test of getAnnotationExternalIdentifier method, of class |
---|
125 | * DBIntegrityServiceImlp. |
---|
126 | */ |
---|
127 | @Test |
---|
128 | public void testGetAnnotationExternalIdentifier() { |
---|
129 | System.out.println("getAnnotationExternalIdentifier"); |
---|
130 | final UUID externalID = UUID.fromString("00000000-0000-0000-0000-000000000021"); |
---|
131 | |
---|
132 | mockeryDao.checking(new Expectations() { |
---|
133 | { |
---|
134 | oneOf(annotationDao).getExternalID(1); |
---|
135 | will(returnValue(externalID)); |
---|
136 | } |
---|
137 | }); |
---|
138 | assertEquals("00000000-0000-0000-0000-000000000021", dbDispatcher.getResourceExternalIdentifier(1, Resource.ANNOTATION).toString()); |
---|
139 | } |
---|
140 | |
---|
141 | /** |
---|
142 | * Test of getPrincipalInternalIdentifier method, of class |
---|
143 | * DBIntegrityServiceImlp. |
---|
144 | */ |
---|
145 | @Test |
---|
146 | public void testGetPrincipalInternalIdentifier() throws NotInDataBaseException { |
---|
147 | System.out.println("getPrincipalInternalIdentifier"); |
---|
148 | |
---|
149 | final UUID externalID = UUID.fromString("00000000-0000-0000-0000-000000000111"); |
---|
150 | |
---|
151 | mockeryDao.checking(new Expectations() { |
---|
152 | { |
---|
153 | oneOf(principalDao).getInternalID(externalID); |
---|
154 | will(returnValue(1)); |
---|
155 | } |
---|
156 | }); |
---|
157 | assertEquals(1, dbDispatcher.getResourceInternalIdentifier(externalID, Resource.PRINCIPAL)); |
---|
158 | } |
---|
159 | |
---|
160 | /** |
---|
161 | * Test of getPrincipalExternalIdentifier method, of class |
---|
162 | * DBIntegrityServiceImlp. |
---|
163 | */ |
---|
164 | @Test |
---|
165 | public void testGetPrincipalExternalIdentifier() { |
---|
166 | System.out.println("getPrincipalExternalIdentifier"); |
---|
167 | final UUID externalID = UUID.fromString("00000000-0000-0000-0000-000000000111"); |
---|
168 | |
---|
169 | mockeryDao.checking(new Expectations() { |
---|
170 | { |
---|
171 | oneOf(principalDao).getExternalID(1); |
---|
172 | will(returnValue(externalID)); |
---|
173 | } |
---|
174 | }); |
---|
175 | assertEquals("00000000-0000-0000-0000-000000000111", dbDispatcher.getResourceExternalIdentifier(1, Resource.PRINCIPAL).toString()); |
---|
176 | } |
---|
177 | |
---|
178 | /** |
---|
179 | * Test of getAnnotation method, of class DBIntegrityServiceImlp. |
---|
180 | */ |
---|
181 | @Test |
---|
182 | public void testGetAnnotation() throws Exception { |
---|
183 | System.out.println("test getAnnotation"); |
---|
184 | |
---|
185 | final Annotation mockAnnotation = new Annotation();// corresponds to the annotation # 1 |
---|
186 | mockAnnotation.setHref("/api/annotations/00000000-0000-0000-0000-000000000021"); |
---|
187 | mockAnnotation.setId("00000000-0000-0000-0000-000000000021"); |
---|
188 | mockAnnotation.setHeadline("Sagrada Famiglia"); |
---|
189 | XMLGregorianCalendar mockTimeStamp = DatatypeFactory.newInstance().newXMLGregorianCalendar("2013-08-12T09:25:00.383000Z"); |
---|
190 | mockAnnotation.setLastModified(mockTimeStamp); |
---|
191 | mockAnnotation.setOwnerHref("/api/principals/00000000-0000-0000-0000-000000000111"); |
---|
192 | |
---|
193 | AnnotationBody mockBody = new AnnotationBody(); |
---|
194 | TextBody textBody = new AnnotationBody.TextBody(); |
---|
195 | mockBody.setTextBody(textBody); |
---|
196 | textBody.setMimeType("text/plain"); |
---|
197 | textBody.setBody("<html><body>some html 1</body></html>"); |
---|
198 | mockAnnotation.setBody(mockBody); |
---|
199 | mockAnnotation.setTargets(null); |
---|
200 | |
---|
201 | |
---|
202 | final List<Number> mockTargetIDs = new ArrayList<Number>(); |
---|
203 | mockTargetIDs.add(1); |
---|
204 | mockTargetIDs.add(2); |
---|
205 | |
---|
206 | final Target mockTargetOne = new Target(); |
---|
207 | mockTargetOne.setLink("http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia"); |
---|
208 | mockTargetOne.setId("00000000-0000-0000-0000-000000000031"); |
---|
209 | mockTargetOne.setHref("/api/targets/00000000-0000-0000-0000-000000000031"); |
---|
210 | mockTargetOne.setVersion("version 1.0"); |
---|
211 | |
---|
212 | final Target mockTargetTwo = new Target(); |
---|
213 | mockTargetTwo.setLink("http://nl.wikipedia.org/wiki/Antoni_Gaud%C3%AD"); |
---|
214 | mockTargetTwo.setId("00000000-0000-0000-0000-000000000032"); |
---|
215 | mockTargetTwo.setHref("/api/targets/00000000-0000-0000-0000-000000000032"); |
---|
216 | mockTargetTwo.setVersion("version 1.1"); |
---|
217 | |
---|
218 | final List<Map<Number, String>> listMap = new ArrayList<Map<Number, String>>(); |
---|
219 | Map<Number, String> map2 = new HashMap<Number, String>(); |
---|
220 | map2.put(2, "write"); |
---|
221 | listMap.add(map2); |
---|
222 | Map<Number, String> map3 = new HashMap<Number, String>(); |
---|
223 | map3.put(3, "read"); |
---|
224 | listMap.add(map3); |
---|
225 | Map<Number, String> map4 = new HashMap<Number, String>(); |
---|
226 | map4.put(11, "read"); |
---|
227 | listMap.add(map4); |
---|
228 | |
---|
229 | final String uri1 = "/api/principals/00000000-0000-0000-0000-000000000111"; |
---|
230 | final String uri2 = "/api/principals/00000000-0000-0000-0000-000000000112"; |
---|
231 | final String uri3 = "/api/principals/00000000-0000-0000-0000-000000000113"; |
---|
232 | final String uri4 = "/api/principals/00000000-0000-0000-0000-000000000221"; |
---|
233 | |
---|
234 | |
---|
235 | mockeryDao.checking(new Expectations() { |
---|
236 | { |
---|
237 | oneOf(annotationDao).getAnnotationWithoutTargetsAndPemissions(1); |
---|
238 | will(returnValue(mockAnnotation)); |
---|
239 | |
---|
240 | oneOf(annotationDao).getOwner(1); |
---|
241 | will(returnValue(1)); |
---|
242 | |
---|
243 | oneOf(principalDao).getHrefFromInternalID(1); |
---|
244 | will(returnValue(uri1)); |
---|
245 | |
---|
246 | oneOf(targetDao).getTargetIDs(1); |
---|
247 | will(returnValue(mockTargetIDs)); |
---|
248 | |
---|
249 | oneOf(targetDao).getTarget(1); |
---|
250 | will(returnValue(mockTargetOne)); |
---|
251 | |
---|
252 | oneOf(targetDao).getTarget(2); |
---|
253 | will(returnValue(mockTargetTwo)); |
---|
254 | |
---|
255 | /// getPermissionsForAnnotation |
---|
256 | |
---|
257 | oneOf(annotationDao).getPermissions(1); |
---|
258 | will(returnValue(listMap)); |
---|
259 | |
---|
260 | oneOf(annotationDao).getPublicAttribute(1); |
---|
261 | will(returnValue(Access.WRITE)); |
---|
262 | |
---|
263 | oneOf(principalDao).getHrefFromInternalID(2); |
---|
264 | will(returnValue(uri2)); |
---|
265 | |
---|
266 | oneOf(principalDao).getHrefFromInternalID(3); |
---|
267 | will(returnValue(uri3)); |
---|
268 | |
---|
269 | oneOf(principalDao).getHrefFromInternalID(11); |
---|
270 | will(returnValue(uri4)); |
---|
271 | } |
---|
272 | }); |
---|
273 | |
---|
274 | Annotation result = dbDispatcher.getAnnotation(1); |
---|
275 | assertEquals("00000000-0000-0000-0000-000000000021", result.getId()); |
---|
276 | assertEquals("/api/annotations/00000000-0000-0000-0000-000000000021", result.getHref()); |
---|
277 | assertEquals("text/plain", result.getBody().getTextBody().getMimeType()); |
---|
278 | assertEquals("<html><body>some html 1</body></html>", result.getBody().getTextBody().getBody()); |
---|
279 | assertEquals("Sagrada Famiglia", result.getHeadline()); |
---|
280 | assertEquals("2013-08-12T09:25:00.383000Z", result.getLastModified().toString()); |
---|
281 | assertEquals("/api/principals/00000000-0000-0000-0000-000000000111", result.getOwnerHref()); |
---|
282 | |
---|
283 | assertEquals(mockTargetOne.getLink(), result.getTargets().getTargetInfo().get(0).getLink()); |
---|
284 | assertEquals(mockTargetOne.getHref(), result.getTargets().getTargetInfo().get(0).getHref()); |
---|
285 | assertEquals(mockTargetOne.getVersion(), result.getTargets().getTargetInfo().get(0).getVersion()); |
---|
286 | assertEquals(mockTargetTwo.getLink(), result.getTargets().getTargetInfo().get(1).getLink()); |
---|
287 | assertEquals(mockTargetTwo.getHref(), result.getTargets().getTargetInfo().get(1).getHref()); |
---|
288 | assertEquals(mockTargetTwo.getVersion(), result.getTargets().getTargetInfo().get(1).getVersion()); |
---|
289 | |
---|
290 | assertEquals(3, result.getPermissions().getPermission().size()); |
---|
291 | |
---|
292 | assertEquals(Access.WRITE, result.getPermissions().getPermission().get(0).getLevel()); |
---|
293 | assertEquals(uri2, result.getPermissions().getPermission().get(0).getPrincipalHref()); |
---|
294 | |
---|
295 | assertEquals(Access.READ, result.getPermissions().getPermission().get(1).getLevel()); |
---|
296 | assertEquals(uri3, result.getPermissions().getPermission().get(1).getPrincipalHref()); |
---|
297 | |
---|
298 | assertEquals(Access.READ, result.getPermissions().getPermission().get(2).getLevel()); |
---|
299 | assertEquals(uri4, result.getPermissions().getPermission().get(2).getPrincipalHref()); |
---|
300 | |
---|
301 | assertEquals(Access.WRITE, result.getPermissions().getPublic()); |
---|
302 | } |
---|
303 | |
---|
304 | /** |
---|
305 | * Test of getFilteredAnnotationIDs method, of class DBIntegrityServiceImlp. |
---|
306 | */ |
---|
307 | @Test |
---|
308 | public void testGetFilteredAnnotationIDsContains() throws NotInDataBaseException { |
---|
309 | System.out.println("test getFilteredAnnotationIDs"); |
---|
310 | |
---|
311 | final List<Number> mockAnnotationIDs1 = new ArrayList<Number>(); |
---|
312 | mockAnnotationIDs1.add(1); |
---|
313 | |
---|
314 | final List<Number> mockAnnotationIDsOwned = new ArrayList<Number>(); |
---|
315 | //mockAnnotationIDsOwned.add(3); |
---|
316 | |
---|
317 | final List<Number> mockAnnotationIDsRead = new ArrayList<Number>(); |
---|
318 | mockAnnotationIDsRead.add(1); |
---|
319 | mockAnnotationIDsRead.add(2); |
---|
320 | |
---|
321 | |
---|
322 | final List<Number> mockAnnotationIDsPublicRead = new ArrayList<Number>(); |
---|
323 | mockAnnotationIDsPublicRead.add(1); |
---|
324 | mockAnnotationIDsPublicRead.add(2); |
---|
325 | |
---|
326 | final List<Number> mockTargets1 = new ArrayList<Number>(); |
---|
327 | mockTargets1.add(1); |
---|
328 | mockTargets1.add(2); |
---|
329 | |
---|
330 | |
---|
331 | final String link1 = "http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia"; |
---|
332 | final String link2 = "http://nl.wikipedia.org/wiki/Antoni_Gaud%C3%AD"; |
---|
333 | |
---|
334 | final String after = (new Timestamp(0)).toString(); |
---|
335 | final String before = (new Timestamp(System.currentTimeMillis())).toString(); |
---|
336 | |
---|
337 | final Number loggedIn = 3; |
---|
338 | |
---|
339 | mockeryDao.checking(new Expectations() { |
---|
340 | { |
---|
341 | |
---|
342 | |
---|
343 | oneOf(annotationDao).getFilteredAnnotationIDs(null, "some html 1", null, after, before); |
---|
344 | will(returnValue(mockAnnotationIDs1)); |
---|
345 | |
---|
346 | oneOf(annotationDao).getAnnotationIDsForPermission(loggedIn, Access.READ); |
---|
347 | will(returnValue(mockAnnotationIDsRead)); |
---|
348 | |
---|
349 | oneOf(annotationDao).getAnnotationIDsForPublicAccess(Access.READ); |
---|
350 | will(returnValue(mockAnnotationIDsPublicRead)); |
---|
351 | |
---|
352 | oneOf(annotationDao).getFilteredAnnotationIDs(loggedIn, "some html 1", null, after, before); |
---|
353 | will(returnValue(mockAnnotationIDsOwned)); |
---|
354 | |
---|
355 | oneOf(targetDao).getTargetIDs(1); |
---|
356 | will(returnValue(mockTargets1)); |
---|
357 | |
---|
358 | oneOf(targetDao).getLink(1); |
---|
359 | will(returnValue(link1)); |
---|
360 | |
---|
361 | oneOf(targetDao).getLink(2); |
---|
362 | will(returnValue(link2)); |
---|
363 | |
---|
364 | |
---|
365 | } |
---|
366 | }); |
---|
367 | |
---|
368 | |
---|
369 | List resultContains = dbDispatcher.getFilteredAnnotationIDs(null, "Sagrada_", MatchMode.CONTAINS, "some html 1", 3, "read", null, after, before); |
---|
370 | assertEquals(1, resultContains.size()); |
---|
371 | assertEquals(1, resultContains.get(0)); |
---|
372 | |
---|
373 | |
---|
374 | |
---|
375 | } |
---|
376 | |
---|
377 | |
---|
378 | /** |
---|
379 | * Test of getFilteredAnnotationIDs method, of class DBIntegrityServiceImlp. |
---|
380 | */ |
---|
381 | @Test |
---|
382 | public void testGetFilteredAnnotationIDsExact() throws NotInDataBaseException { |
---|
383 | System.out.println("test getFilteredAnnotationIDs"); |
---|
384 | |
---|
385 | final List<Number> mockAnnotationIDs1 = new ArrayList<Number>(); |
---|
386 | mockAnnotationIDs1.add(1); |
---|
387 | |
---|
388 | final List<Number> mockAnnotationIDsOwned = new ArrayList<Number>(); |
---|
389 | //mockAnnotationIDsOwned.add(3); |
---|
390 | |
---|
391 | final List<Number> mockAnnotationIDsRead = new ArrayList<Number>(); |
---|
392 | mockAnnotationIDsRead.add(1); |
---|
393 | mockAnnotationIDsRead.add(2); |
---|
394 | |
---|
395 | |
---|
396 | final List<Number> mockAnnotationIDsPublicRead = new ArrayList<Number>(); |
---|
397 | mockAnnotationIDsPublicRead.add(1); |
---|
398 | mockAnnotationIDsPublicRead.add(2); |
---|
399 | |
---|
400 | final List<Number> mockTargets1 = new ArrayList<Number>(); |
---|
401 | mockTargets1.add(1); |
---|
402 | mockTargets1.add(2); |
---|
403 | |
---|
404 | |
---|
405 | final String link1 = "http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia"; |
---|
406 | final String link2 = "http://nl.wikipedia.org/wiki/Antoni_Gaud%C3%AD"; |
---|
407 | |
---|
408 | final String after = (new Timestamp(0)).toString(); |
---|
409 | final String before = (new Timestamp(System.currentTimeMillis())).toString(); |
---|
410 | |
---|
411 | final Number loggedIn = 3; |
---|
412 | |
---|
413 | mockeryDao.checking(new Expectations() { |
---|
414 | { |
---|
415 | |
---|
416 | |
---|
417 | oneOf(annotationDao).getFilteredAnnotationIDs(null, "some html 1", null, after, before); |
---|
418 | will(returnValue(mockAnnotationIDs1)); |
---|
419 | |
---|
420 | oneOf(annotationDao).getAnnotationIDsForPermission(loggedIn, Access.READ); |
---|
421 | will(returnValue(mockAnnotationIDsRead)); |
---|
422 | |
---|
423 | oneOf(annotationDao).getAnnotationIDsForPublicAccess(Access.READ); |
---|
424 | will(returnValue(mockAnnotationIDsPublicRead)); |
---|
425 | |
---|
426 | oneOf(annotationDao).getFilteredAnnotationIDs(loggedIn, "some html 1", null, after, before); |
---|
427 | will(returnValue(mockAnnotationIDsOwned)); |
---|
428 | |
---|
429 | oneOf(targetDao).getTargetIDs(1); |
---|
430 | will(returnValue(mockTargets1)); |
---|
431 | |
---|
432 | oneOf(targetDao).getLink(1); |
---|
433 | will(returnValue(link1)); |
---|
434 | |
---|
435 | oneOf(targetDao).getLink(2); |
---|
436 | will(returnValue(link2)); |
---|
437 | |
---|
438 | |
---|
439 | } |
---|
440 | }); |
---|
441 | |
---|
442 | |
---|
443 | |
---|
444 | List resultExact = dbDispatcher.getFilteredAnnotationIDs(null, "http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia", MatchMode.EXACT, "some html 1", 3, "read", null, after, before); |
---|
445 | assertEquals(1, resultExact.size()); |
---|
446 | assertEquals(1, resultExact.get(0)); |
---|
447 | |
---|
448 | |
---|
449 | } |
---|
450 | |
---|
451 | /** |
---|
452 | * Test of getFilteredAnnotationIDs method, of class DBIntegrityServiceImlp. |
---|
453 | */ |
---|
454 | @Test |
---|
455 | public void testGetFilteredAnnotationIDsStartsWith() throws NotInDataBaseException { |
---|
456 | System.out.println("test getFilteredAnnotationIDs"); |
---|
457 | |
---|
458 | final List<Number> mockAnnotationIDs1 = new ArrayList<Number>(); |
---|
459 | mockAnnotationIDs1.add(1); |
---|
460 | |
---|
461 | final List<Number> mockAnnotationIDsOwned = new ArrayList<Number>(); |
---|
462 | //mockAnnotationIDsOwned.add(3); |
---|
463 | |
---|
464 | final List<Number> mockAnnotationIDsRead = new ArrayList<Number>(); |
---|
465 | mockAnnotationIDsRead.add(1); |
---|
466 | mockAnnotationIDsRead.add(2); |
---|
467 | |
---|
468 | |
---|
469 | final List<Number> mockAnnotationIDsPublicRead = new ArrayList<Number>(); |
---|
470 | mockAnnotationIDsPublicRead.add(1); |
---|
471 | mockAnnotationIDsPublicRead.add(2); |
---|
472 | |
---|
473 | final List<Number> mockTargets1 = new ArrayList<Number>(); |
---|
474 | mockTargets1.add(1); |
---|
475 | mockTargets1.add(2); |
---|
476 | |
---|
477 | |
---|
478 | final String link1 = "http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia"; |
---|
479 | final String link2 = "http://nl.wikipedia.org/wiki/Antoni_Gaud%C3%AD"; |
---|
480 | |
---|
481 | final String after = (new Timestamp(0)).toString(); |
---|
482 | final String before = (new Timestamp(System.currentTimeMillis())).toString(); |
---|
483 | |
---|
484 | final Number loggedIn = 3; |
---|
485 | |
---|
486 | mockeryDao.checking(new Expectations() { |
---|
487 | { |
---|
488 | |
---|
489 | |
---|
490 | oneOf(annotationDao).getFilteredAnnotationIDs(null, "some html 1", null, after, before); |
---|
491 | will(returnValue(mockAnnotationIDs1)); |
---|
492 | |
---|
493 | oneOf(annotationDao).getAnnotationIDsForPermission(loggedIn, Access.READ); |
---|
494 | will(returnValue(mockAnnotationIDsRead)); |
---|
495 | |
---|
496 | oneOf(annotationDao).getAnnotationIDsForPublicAccess(Access.READ); |
---|
497 | will(returnValue(mockAnnotationIDsPublicRead)); |
---|
498 | |
---|
499 | oneOf(annotationDao).getFilteredAnnotationIDs(loggedIn, "some html 1", null, after, before); |
---|
500 | will(returnValue(mockAnnotationIDsOwned)); |
---|
501 | |
---|
502 | oneOf(targetDao).getTargetIDs(1); |
---|
503 | will(returnValue(mockTargets1)); |
---|
504 | |
---|
505 | oneOf(targetDao).getLink(1); |
---|
506 | will(returnValue(link1)); |
---|
507 | |
---|
508 | oneOf(targetDao).getLink(2); |
---|
509 | will(returnValue(link2)); |
---|
510 | |
---|
511 | |
---|
512 | } |
---|
513 | }); |
---|
514 | |
---|
515 | |
---|
516 | |
---|
517 | List resultStartsWith = dbDispatcher.getFilteredAnnotationIDs(null, "http://nl.wikipedia.org/wiki/Sagrada_", MatchMode.STARTS_WITH, "some html 1", 3, "read", null, after, before); |
---|
518 | assertEquals(1, resultStartsWith.size()); |
---|
519 | assertEquals(1, resultStartsWith.get(0)); |
---|
520 | |
---|
521 | |
---|
522 | |
---|
523 | } |
---|
524 | |
---|
525 | /** |
---|
526 | * Test of getFilteredAnnotationIDs method, of class DBIntegrityServiceImlp. |
---|
527 | */ |
---|
528 | @Test |
---|
529 | public void testGetFilteredAnnotationIDsEndsWith() throws NotInDataBaseException { |
---|
530 | System.out.println("test getFilteredAnnotationIDs"); |
---|
531 | |
---|
532 | final List<Number> mockAnnotationIDs1 = new ArrayList<Number>(); |
---|
533 | mockAnnotationIDs1.add(1); |
---|
534 | |
---|
535 | final List<Number> mockAnnotationIDsOwned = new ArrayList<Number>(); |
---|
536 | //mockAnnotationIDsOwned.add(3); |
---|
537 | |
---|
538 | final List<Number> mockAnnotationIDsRead = new ArrayList<Number>(); |
---|
539 | mockAnnotationIDsRead.add(1); |
---|
540 | mockAnnotationIDsRead.add(2); |
---|
541 | |
---|
542 | |
---|
543 | final List<Number> mockAnnotationIDsPublicRead = new ArrayList<Number>(); |
---|
544 | mockAnnotationIDsPublicRead.add(1); |
---|
545 | mockAnnotationIDsPublicRead.add(2); |
---|
546 | |
---|
547 | final List<Number> mockTargets1 = new ArrayList<Number>(); |
---|
548 | mockTargets1.add(1); |
---|
549 | mockTargets1.add(2); |
---|
550 | |
---|
551 | |
---|
552 | final String link1 = "http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia"; |
---|
553 | final String link2 = "http://nl.wikipedia.org/wiki/Antoni_Gaud%C3%AD"; |
---|
554 | |
---|
555 | final String after = (new Timestamp(0)).toString(); |
---|
556 | final String before = (new Timestamp(System.currentTimeMillis())).toString(); |
---|
557 | |
---|
558 | final Number loggedIn = 3; |
---|
559 | |
---|
560 | mockeryDao.checking(new Expectations() { |
---|
561 | { |
---|
562 | |
---|
563 | |
---|
564 | oneOf(annotationDao).getFilteredAnnotationIDs(null, "some html 1", null, after, before); |
---|
565 | will(returnValue(mockAnnotationIDs1)); |
---|
566 | |
---|
567 | oneOf(annotationDao).getAnnotationIDsForPermission(loggedIn, Access.READ); |
---|
568 | will(returnValue(mockAnnotationIDsRead)); |
---|
569 | |
---|
570 | oneOf(annotationDao).getAnnotationIDsForPublicAccess(Access.READ); |
---|
571 | will(returnValue(mockAnnotationIDsPublicRead)); |
---|
572 | |
---|
573 | oneOf(annotationDao).getFilteredAnnotationIDs(loggedIn, "some html 1", null, after, before); |
---|
574 | will(returnValue(mockAnnotationIDsOwned)); |
---|
575 | |
---|
576 | oneOf(targetDao).getTargetIDs(1); |
---|
577 | will(returnValue(mockTargets1)); |
---|
578 | |
---|
579 | oneOf(targetDao).getLink(1); |
---|
580 | will(returnValue(link1)); |
---|
581 | |
---|
582 | oneOf(targetDao).getLink(2); |
---|
583 | will(returnValue(link2)); |
---|
584 | |
---|
585 | |
---|
586 | } |
---|
587 | }); |
---|
588 | |
---|
589 | |
---|
590 | List resultEndsWith = dbDispatcher.getFilteredAnnotationIDs(null, "Fam%C3%ADlia", MatchMode.ENDS_WITH, "some html 1", 3, "read", null, after, before); |
---|
591 | assertEquals(1, resultEndsWith.size()); |
---|
592 | assertEquals(1, resultEndsWith.get(0)); |
---|
593 | |
---|
594 | } |
---|
595 | |
---|
596 | |
---|
597 | @Test |
---|
598 | public void testGetFilteredAnnotationIDs2Contains() throws NotInDataBaseException { |
---|
599 | System.out.println("test getFilteredAnnotationIDs"); |
---|
600 | |
---|
601 | final List<Number> mockAnnotationIDs1 = new ArrayList<Number>(); |
---|
602 | mockAnnotationIDs1.add(1); |
---|
603 | |
---|
604 | |
---|
605 | final List<Number> mockAnnotationIDsOwned = new ArrayList<Number>(); |
---|
606 | //mockAnnotationIDsOwned.add(3); |
---|
607 | |
---|
608 | final List<Number> mockAnnotationIDsWrite = new ArrayList<Number>(); |
---|
609 | mockAnnotationIDsWrite.add(2); |
---|
610 | |
---|
611 | |
---|
612 | final List<Number> mockAnnotationIDsPublicWrite = new ArrayList<Number>(); |
---|
613 | mockAnnotationIDsPublicWrite.add(1); |
---|
614 | |
---|
615 | final List<Number> mockTargets1 = new ArrayList<Number>(); |
---|
616 | mockTargets1.add(1); |
---|
617 | mockTargets1.add(2); |
---|
618 | |
---|
619 | |
---|
620 | final String link1 = "http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia"; |
---|
621 | final String link2 = "http://nl.wikipedia.org/wiki/Antoni_Gaud%C3%AD"; |
---|
622 | |
---|
623 | final String after = (new Timestamp(0)).toString(); |
---|
624 | final String before = (new Timestamp(System.currentTimeMillis())).toString(); |
---|
625 | |
---|
626 | final Number loggedIn = 3; |
---|
627 | |
---|
628 | mockeryDao.checking(new Expectations() { |
---|
629 | { |
---|
630 | oneOf(annotationDao).getFilteredAnnotationIDs(null, "some html 1", null, after, before); |
---|
631 | will(returnValue(mockAnnotationIDs1)); |
---|
632 | |
---|
633 | oneOf(annotationDao).getAnnotationIDsForPermission(loggedIn, Access.WRITE); |
---|
634 | will(returnValue(mockAnnotationIDsWrite)); |
---|
635 | |
---|
636 | oneOf(annotationDao).getAnnotationIDsForPublicAccess(Access.WRITE); |
---|
637 | will(returnValue(mockAnnotationIDsPublicWrite)); |
---|
638 | |
---|
639 | oneOf(annotationDao).getFilteredAnnotationIDs(loggedIn, "some html 1", null, after, before); |
---|
640 | will(returnValue(mockAnnotationIDsOwned)); |
---|
641 | |
---|
642 | oneOf(targetDao).getTargetIDs(1); |
---|
643 | will(returnValue(mockTargets1)); |
---|
644 | |
---|
645 | oneOf(targetDao).getLink(1); |
---|
646 | will(returnValue(link1)); |
---|
647 | |
---|
648 | oneOf(targetDao).getLink(2); |
---|
649 | will(returnValue(link2)); |
---|
650 | |
---|
651 | } |
---|
652 | }); |
---|
653 | |
---|
654 | |
---|
655 | |
---|
656 | List resultContains = dbDispatcher.getFilteredAnnotationIDs(null, "Sagrada_", MatchMode.CONTAINS, "some html 1", 3, "write", null, after, before); |
---|
657 | assertEquals(1, resultContains.size()); |
---|
658 | assertEquals(1, resultContains.get(0)); |
---|
659 | } |
---|
660 | |
---|
661 | @Test |
---|
662 | public void testGetFilteredAnnotationIDs2Exact() throws NotInDataBaseException { |
---|
663 | System.out.println("test getFilteredAnnotationIDs"); |
---|
664 | |
---|
665 | final List<Number> mockAnnotationIDs1 = new ArrayList<Number>(); |
---|
666 | mockAnnotationIDs1.add(1); |
---|
667 | |
---|
668 | |
---|
669 | final List<Number> mockAnnotationIDsOwned = new ArrayList<Number>(); |
---|
670 | //mockAnnotationIDsOwned.add(3); |
---|
671 | |
---|
672 | final List<Number> mockAnnotationIDsWrite = new ArrayList<Number>(); |
---|
673 | mockAnnotationIDsWrite.add(2); |
---|
674 | |
---|
675 | |
---|
676 | final List<Number> mockAnnotationIDsPublicWrite = new ArrayList<Number>(); |
---|
677 | mockAnnotationIDsPublicWrite.add(1); |
---|
678 | |
---|
679 | final List<Number> mockTargets1 = new ArrayList<Number>(); |
---|
680 | mockTargets1.add(1); |
---|
681 | mockTargets1.add(2); |
---|
682 | |
---|
683 | |
---|
684 | final String link1 = "http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia"; |
---|
685 | final String link2 = "http://nl.wikipedia.org/wiki/Antoni_Gaud%C3%AD"; |
---|
686 | |
---|
687 | final String after = (new Timestamp(0)).toString(); |
---|
688 | final String before = (new Timestamp(System.currentTimeMillis())).toString(); |
---|
689 | |
---|
690 | final Number loggedIn = 3; |
---|
691 | |
---|
692 | mockeryDao.checking(new Expectations() { |
---|
693 | { |
---|
694 | oneOf(annotationDao).getFilteredAnnotationIDs(null, "some html 1", null, after, before); |
---|
695 | will(returnValue(mockAnnotationIDs1)); |
---|
696 | |
---|
697 | oneOf(annotationDao).getAnnotationIDsForPermission(loggedIn, Access.WRITE); |
---|
698 | will(returnValue(mockAnnotationIDsWrite)); |
---|
699 | |
---|
700 | oneOf(annotationDao).getAnnotationIDsForPublicAccess(Access.WRITE); |
---|
701 | will(returnValue(mockAnnotationIDsPublicWrite)); |
---|
702 | |
---|
703 | oneOf(annotationDao).getFilteredAnnotationIDs(loggedIn, "some html 1", null, after, before); |
---|
704 | will(returnValue(mockAnnotationIDsOwned)); |
---|
705 | |
---|
706 | oneOf(targetDao).getTargetIDs(1); |
---|
707 | will(returnValue(mockTargets1)); |
---|
708 | |
---|
709 | oneOf(targetDao).getLink(1); |
---|
710 | will(returnValue(link1)); |
---|
711 | |
---|
712 | oneOf(targetDao).getLink(2); |
---|
713 | will(returnValue(link2)); |
---|
714 | |
---|
715 | } |
---|
716 | }); |
---|
717 | |
---|
718 | |
---|
719 | |
---|
720 | List resultExact = dbDispatcher.getFilteredAnnotationIDs(null, "http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia", MatchMode.EXACT, "some html 1", 3, "write", null, after, before); |
---|
721 | assertEquals(1, resultExact.size()); |
---|
722 | assertEquals(1, resultExact.get(0)); |
---|
723 | |
---|
724 | |
---|
725 | } |
---|
726 | |
---|
727 | @Test |
---|
728 | public void testGetFilteredAnnotationIDs2StartsWith() throws NotInDataBaseException { |
---|
729 | System.out.println("test getFilteredAnnotationIDs"); |
---|
730 | |
---|
731 | final List<Number> mockAnnotationIDs1 = new ArrayList<Number>(); |
---|
732 | mockAnnotationIDs1.add(1); |
---|
733 | |
---|
734 | |
---|
735 | final List<Number> mockAnnotationIDsOwned = new ArrayList<Number>(); |
---|
736 | //mockAnnotationIDsOwned.add(3); |
---|
737 | |
---|
738 | final List<Number> mockAnnotationIDsWrite = new ArrayList<Number>(); |
---|
739 | mockAnnotationIDsWrite.add(2); |
---|
740 | |
---|
741 | |
---|
742 | final List<Number> mockAnnotationIDsPublicWrite = new ArrayList<Number>(); |
---|
743 | mockAnnotationIDsPublicWrite.add(1); |
---|
744 | |
---|
745 | final List<Number> mockTargets1 = new ArrayList<Number>(); |
---|
746 | mockTargets1.add(1); |
---|
747 | mockTargets1.add(2); |
---|
748 | |
---|
749 | |
---|
750 | final String link1 = "http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia"; |
---|
751 | final String link2 = "http://nl.wikipedia.org/wiki/Antoni_Gaud%C3%AD"; |
---|
752 | |
---|
753 | final String after = (new Timestamp(0)).toString(); |
---|
754 | final String before = (new Timestamp(System.currentTimeMillis())).toString(); |
---|
755 | |
---|
756 | final Number loggedIn = 3; |
---|
757 | |
---|
758 | mockeryDao.checking(new Expectations() { |
---|
759 | { |
---|
760 | oneOf(annotationDao).getFilteredAnnotationIDs(null, "some html 1", null, after, before); |
---|
761 | will(returnValue(mockAnnotationIDs1)); |
---|
762 | |
---|
763 | oneOf(annotationDao).getAnnotationIDsForPermission(loggedIn, Access.WRITE); |
---|
764 | will(returnValue(mockAnnotationIDsWrite)); |
---|
765 | |
---|
766 | oneOf(annotationDao).getAnnotationIDsForPublicAccess(Access.WRITE); |
---|
767 | will(returnValue(mockAnnotationIDsPublicWrite)); |
---|
768 | |
---|
769 | oneOf(annotationDao).getFilteredAnnotationIDs(loggedIn, "some html 1", null, after, before); |
---|
770 | will(returnValue(mockAnnotationIDsOwned)); |
---|
771 | |
---|
772 | oneOf(targetDao).getTargetIDs(1); |
---|
773 | will(returnValue(mockTargets1)); |
---|
774 | |
---|
775 | oneOf(targetDao).getLink(1); |
---|
776 | will(returnValue(link1)); |
---|
777 | |
---|
778 | oneOf(targetDao).getLink(2); |
---|
779 | will(returnValue(link2)); |
---|
780 | |
---|
781 | } |
---|
782 | }); |
---|
783 | |
---|
784 | |
---|
785 | List resultStartsWith = dbDispatcher.getFilteredAnnotationIDs(null, "http://nl.wikipedia.org/wiki/Sagrada_", MatchMode.STARTS_WITH, "some html 1", 3, "write", null, after, before); |
---|
786 | assertEquals(1, resultStartsWith.size()); |
---|
787 | assertEquals(1, resultStartsWith.get(0)); |
---|
788 | |
---|
789 | |
---|
790 | } |
---|
791 | |
---|
792 | @Test |
---|
793 | public void testGetFilteredAnnotationIDs2EndsWith() throws NotInDataBaseException { |
---|
794 | System.out.println("test getFilteredAnnotationIDs"); |
---|
795 | |
---|
796 | final List<Number> mockAnnotationIDs1 = new ArrayList<Number>(); |
---|
797 | mockAnnotationIDs1.add(1); |
---|
798 | |
---|
799 | |
---|
800 | final List<Number> mockAnnotationIDsOwned = new ArrayList<Number>(); |
---|
801 | //mockAnnotationIDsOwned.add(3); |
---|
802 | |
---|
803 | final List<Number> mockAnnotationIDsWrite = new ArrayList<Number>(); |
---|
804 | mockAnnotationIDsWrite.add(2); |
---|
805 | |
---|
806 | |
---|
807 | final List<Number> mockAnnotationIDsPublicWrite = new ArrayList<Number>(); |
---|
808 | mockAnnotationIDsPublicWrite.add(1); |
---|
809 | |
---|
810 | final List<Number> mockTargets1 = new ArrayList<Number>(); |
---|
811 | mockTargets1.add(1); |
---|
812 | mockTargets1.add(2); |
---|
813 | |
---|
814 | |
---|
815 | final String link1 = "http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia"; |
---|
816 | final String link2 = "http://nl.wikipedia.org/wiki/Antoni_Gaud%C3%AD"; |
---|
817 | |
---|
818 | final String after = (new Timestamp(0)).toString(); |
---|
819 | final String before = (new Timestamp(System.currentTimeMillis())).toString(); |
---|
820 | |
---|
821 | final Number loggedIn = 3; |
---|
822 | |
---|
823 | mockeryDao.checking(new Expectations() { |
---|
824 | { |
---|
825 | oneOf(annotationDao).getFilteredAnnotationIDs(null, "some html 1", null, after, before); |
---|
826 | will(returnValue(mockAnnotationIDs1)); |
---|
827 | |
---|
828 | oneOf(annotationDao).getAnnotationIDsForPermission(loggedIn, Access.WRITE); |
---|
829 | will(returnValue(mockAnnotationIDsWrite)); |
---|
830 | |
---|
831 | oneOf(annotationDao).getAnnotationIDsForPublicAccess(Access.WRITE); |
---|
832 | will(returnValue(mockAnnotationIDsPublicWrite)); |
---|
833 | |
---|
834 | oneOf(annotationDao).getFilteredAnnotationIDs(loggedIn, "some html 1", null, after, before); |
---|
835 | will(returnValue(mockAnnotationIDsOwned)); |
---|
836 | |
---|
837 | oneOf(targetDao).getTargetIDs(1); |
---|
838 | will(returnValue(mockTargets1)); |
---|
839 | |
---|
840 | oneOf(targetDao).getLink(1); |
---|
841 | will(returnValue(link1)); |
---|
842 | |
---|
843 | oneOf(targetDao).getLink(2); |
---|
844 | will(returnValue(link2)); |
---|
845 | |
---|
846 | } |
---|
847 | }); |
---|
848 | |
---|
849 | |
---|
850 | |
---|
851 | List resultEndsWith = dbDispatcher.getFilteredAnnotationIDs(null, "Fam%C3%ADlia", MatchMode.ENDS_WITH, "some html 1", 3, "write", null, after, before); |
---|
852 | assertEquals(1, resultEndsWith.size()); |
---|
853 | assertEquals(1, resultEndsWith.get(0)); |
---|
854 | |
---|
855 | } |
---|
856 | |
---|
857 | @Test |
---|
858 | public void testGetFilteredAnnotationIDs3() throws NotInDataBaseException { |
---|
859 | System.out.println("test getFilteredAnnotationIDs"); |
---|
860 | |
---|
861 | final List<Number> mockAnnotationIDs1 = new ArrayList<Number>(); |
---|
862 | |
---|
863 | final String after = (new Timestamp(0)).toString(); |
---|
864 | final String before = (new Timestamp(System.currentTimeMillis())).toString(); |
---|
865 | |
---|
866 | |
---|
867 | mockeryDao.checking(new Expectations() { |
---|
868 | { |
---|
869 | |
---|
870 | oneOf(annotationDao).getFilteredAnnotationIDs(3, "some html 1", null, after, before); |
---|
871 | will(returnValue(mockAnnotationIDs1)); |
---|
872 | |
---|
873 | oneOf(annotationDao).getFilteredAnnotationIDs(3, "some html 1", null, after, before); |
---|
874 | will(returnValue(mockAnnotationIDs1)); |
---|
875 | |
---|
876 | oneOf(annotationDao).getFilteredAnnotationIDs(3, "some html 1", null, after, before); |
---|
877 | will(returnValue(mockAnnotationIDs1)); |
---|
878 | |
---|
879 | oneOf(annotationDao).getFilteredAnnotationIDs(3, "some html 1", null, after, before); |
---|
880 | will(returnValue(mockAnnotationIDs1)); |
---|
881 | |
---|
882 | } |
---|
883 | }); |
---|
884 | |
---|
885 | |
---|
886 | List resultContains = dbDispatcher.getFilteredAnnotationIDs(null, "Sagrada_", MatchMode.CONTAINS, "some html 1", 3, "owner", null, after, before); |
---|
887 | assertEquals(0, resultContains.size()); |
---|
888 | |
---|
889 | List resultExact = dbDispatcher.getFilteredAnnotationIDs(null, "http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia", MatchMode.EXACT, "some html 1", 3, "owner", null, after, before); |
---|
890 | assertEquals(0, resultExact.size()); |
---|
891 | |
---|
892 | List resultStartsWith = dbDispatcher.getFilteredAnnotationIDs(null, "http://nl.wikipedia.org/wiki/Sagrada_", MatchMode.STARTS_WITH, "some html 1", 3, "owner", null, after, before); |
---|
893 | assertEquals(0, resultStartsWith.size()); |
---|
894 | |
---|
895 | List resultEndsWith = dbDispatcher.getFilteredAnnotationIDs(null, "Fam%C3%ADlia", MatchMode.ENDS_WITH, "some html 1", 3, "owner", null, after, before); |
---|
896 | assertEquals(0, resultEndsWith.size()); |
---|
897 | } |
---|
898 | |
---|
899 | |
---|
900 | @Test |
---|
901 | public void testGetFilteredAnnotationIDs4() throws NotInDataBaseException { |
---|
902 | System.out.println("test getFilteredAnnotationIDs"); |
---|
903 | |
---|
904 | final String after = (new Timestamp(0)).toString(); |
---|
905 | final String before = (new Timestamp(System.currentTimeMillis())).toString(); |
---|
906 | |
---|
907 | // final List<Number> mockRetval = new ArrayList<Number>(); |
---|
908 | // mockRetval.add(1); |
---|
909 | |
---|
910 | final Number loggedIn = 3; |
---|
911 | |
---|
912 | mockeryDao.checking(new Expectations() { |
---|
913 | { |
---|
914 | |
---|
915 | oneOf(principalDao).getExternalID(loggedIn); |
---|
916 | will(returnValue(UUID.fromString("00000000-0000-0000-0000-000000000113"))); |
---|
917 | |
---|
918 | |
---|
919 | } |
---|
920 | }); |
---|
921 | |
---|
922 | |
---|
923 | List result = dbDispatcher.getFilteredAnnotationIDs(UUID.fromString("00000000-0000-0000-0000-000000000111"), "nl.wikipedia.org", MatchMode.CONTAINS, "some html 1", 3, "owner", null, after, before); |
---|
924 | assertEquals(0, result.size()); |
---|
925 | } |
---|
926 | |
---|
927 | @Test |
---|
928 | public void testGetAnnotationTargets() throws SQLException { |
---|
929 | System.out.println("test getAnnotationTargets"); |
---|
930 | |
---|
931 | final List<Number> targetIDs = new ArrayList<Number>(); |
---|
932 | targetIDs.add(1); |
---|
933 | targetIDs.add(2); |
---|
934 | mockeryDao.checking(new Expectations() { |
---|
935 | { |
---|
936 | oneOf(targetDao).getTargetIDs(1); |
---|
937 | will(returnValue(targetIDs)); |
---|
938 | |
---|
939 | oneOf(targetDao).getHrefFromInternalID(1); |
---|
940 | will(returnValue("/api/targets/00000000-0000-0000-0000-000000000031")); |
---|
941 | |
---|
942 | oneOf(targetDao).getHrefFromInternalID(2); |
---|
943 | will(returnValue("/api/targets/00000000-0000-0000-0000-000000000032")); |
---|
944 | |
---|
945 | } |
---|
946 | }); |
---|
947 | |
---|
948 | ReferenceList result = dbDispatcher.getAnnotationTargets(1); |
---|
949 | assertEquals(2, result.getHref().size()); |
---|
950 | assertEquals("/api/targets/00000000-0000-0000-0000-000000000031", result.getHref().get(0)); |
---|
951 | assertEquals("/api/targets/00000000-0000-0000-0000-000000000032", result.getHref().get(1)); |
---|
952 | |
---|
953 | } |
---|
954 | |
---|
955 | // @Override |
---|
956 | // public AnnotationInfoList getFilteredAnnotationInfos(String link, String text, String access, String namespace, UUID |
---|
957 | // owner, Timestamp after, Timestamp before){ |
---|
958 | // List<Number> annotationIDs = getFilteredAnnotationIDs(link, text, access, namespace, owner, after, before); |
---|
959 | // List<AnnotationInfo> listAnnotationInfo = annotationDao.getAnnotationInfos(annotationIDs); |
---|
960 | // AnnotationInfoList result = new AnnotationInfoList(); |
---|
961 | // result.getAnnotation().addAll(listAnnotationInfo); |
---|
962 | // return result; |
---|
963 | // } |
---|
964 | @Test |
---|
965 | public void testGetFilteredAnnotationInfos() throws NotInDataBaseException { |
---|
966 | System.out.println("test getetFilteredAnnotationInfos"); |
---|
967 | |
---|
968 | final List<Number> mockAnnotationIDs1 = new ArrayList<Number>(); |
---|
969 | mockAnnotationIDs1.add(1); |
---|
970 | |
---|
971 | |
---|
972 | |
---|
973 | final UUID ownerUUID = UUID.fromString("00000000-0000-0000-0000-000000000111"); |
---|
974 | final String after = (new Timestamp(0)).toString(); |
---|
975 | final String before = (new Timestamp(System.currentTimeMillis())).toString(); |
---|
976 | |
---|
977 | |
---|
978 | |
---|
979 | final List<Number> mockAnnotationIDsOwned = new ArrayList<Number>(); |
---|
980 | //mockAnnotationIDsOwned.add(3); |
---|
981 | |
---|
982 | final List<Number> mockAnnotationIDsRead = new ArrayList<Number>(); |
---|
983 | mockAnnotationIDsRead.add(1); |
---|
984 | mockAnnotationIDsRead.add(2); |
---|
985 | |
---|
986 | final List<Number> mockAnnotationIDsPublicRead = new ArrayList<Number>(); |
---|
987 | mockAnnotationIDsPublicRead.add(1); |
---|
988 | mockAnnotationIDsPublicRead.add(2); |
---|
989 | |
---|
990 | |
---|
991 | |
---|
992 | |
---|
993 | final List<Number> mockTargets1 = new ArrayList<Number>(); |
---|
994 | mockTargets1.add(1); |
---|
995 | mockTargets1.add(2); |
---|
996 | |
---|
997 | |
---|
998 | final String link1 = "http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia"; |
---|
999 | final String link2 = "http://nl.wikipedia.org/wiki/Antoni_Gaud%C3%AD"; |
---|
1000 | |
---|
1001 | |
---|
1002 | final AnnotationInfo mockAnnotInfo = new AnnotationInfo(); |
---|
1003 | |
---|
1004 | mockAnnotInfo.setHeadline("Sagrada Famiglia"); |
---|
1005 | mockAnnotInfo.setHref("/api/annotations/00000000-0000-0000-0000-000000000021"); |
---|
1006 | mockAnnotInfo.setOwnerHref("/api/principals/00000000-0000-0000-0000-000000000111"); |
---|
1007 | |
---|
1008 | final List<Number> targetIDs = new ArrayList<Number>(); |
---|
1009 | targetIDs.add(1); |
---|
1010 | targetIDs.add(2); |
---|
1011 | |
---|
1012 | final Number loggedIn = 3; |
---|
1013 | |
---|
1014 | mockeryDao.checking(new Expectations() { |
---|
1015 | { |
---|
1016 | oneOf(principalDao).getInternalID(ownerUUID); |
---|
1017 | will(returnValue(1)); |
---|
1018 | |
---|
1019 | |
---|
1020 | oneOf(annotationDao).getFilteredAnnotationIDs(1, "some html 1", null, after, before); |
---|
1021 | will(returnValue(mockAnnotationIDs1)); |
---|
1022 | |
---|
1023 | oneOf(annotationDao).getAnnotationIDsForPermission(loggedIn, Access.READ); |
---|
1024 | will(returnValue(mockAnnotationIDsRead)); |
---|
1025 | |
---|
1026 | oneOf(annotationDao).getAnnotationIDsForPublicAccess(Access.READ); |
---|
1027 | will(returnValue(mockAnnotationIDsPublicRead)); |
---|
1028 | |
---|
1029 | |
---|
1030 | oneOf(annotationDao).getFilteredAnnotationIDs(3, "some html 1", null, after, before); |
---|
1031 | will(returnValue(mockAnnotationIDsOwned)); |
---|
1032 | |
---|
1033 | oneOf(targetDao).getTargetIDs(1); |
---|
1034 | will(returnValue(mockTargets1)); |
---|
1035 | |
---|
1036 | oneOf(targetDao).getLink(1); |
---|
1037 | will(returnValue(link1)); |
---|
1038 | |
---|
1039 | oneOf(targetDao).getLink(2); |
---|
1040 | will(returnValue(link2)); |
---|
1041 | |
---|
1042 | // /////////////////////////////////// |
---|
1043 | // |
---|
1044 | oneOf(annotationDao).getAnnotationInfoWithoutTargetsAndOwner(1); |
---|
1045 | will(returnValue(mockAnnotInfo)); |
---|
1046 | |
---|
1047 | oneOf(annotationDao).getOwner(1); |
---|
1048 | will(returnValue(1)); |
---|
1049 | |
---|
1050 | oneOf(principalDao).getHrefFromInternalID(1); |
---|
1051 | will(returnValue("/api/principals/00000000-0000-0000-0000-000000000111")); |
---|
1052 | |
---|
1053 | //// |
---|
1054 | oneOf(targetDao).getTargetIDs(1); |
---|
1055 | will(returnValue(targetIDs)); |
---|
1056 | |
---|
1057 | oneOf(targetDao).getHrefFromInternalID(1); |
---|
1058 | will(returnValue("/api/targets/00000000-0000-0000-0000-000000000031")); |
---|
1059 | |
---|
1060 | |
---|
1061 | oneOf(targetDao).getHrefFromInternalID(2); |
---|
1062 | will(returnValue("/api/targets/00000000-0000-0000-0000-000000000032")); |
---|
1063 | |
---|
1064 | |
---|
1065 | } |
---|
1066 | }); |
---|
1067 | |
---|
1068 | |
---|
1069 | AnnotationInfoList result = dbDispatcher.getFilteredAnnotationInfos(ownerUUID, "http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia", MatchMode.EXACT, "some html 1", 3, "read", null, after, before); |
---|
1070 | assertEquals(1, result.getAnnotationInfo().size()); |
---|
1071 | AnnotationInfo resultAnnotInfo = result.getAnnotationInfo().get(0); |
---|
1072 | assertEquals("Sagrada Famiglia", resultAnnotInfo.getHeadline()); |
---|
1073 | assertEquals("/api/principals/00000000-0000-0000-0000-000000000111", resultAnnotInfo.getOwnerHref()); |
---|
1074 | assertEquals("/api/annotations/00000000-0000-0000-0000-000000000021", result.getAnnotationInfo().get(0).getHref()); |
---|
1075 | assertEquals("/api/targets/00000000-0000-0000-0000-000000000031", resultAnnotInfo.getTargets().getHref().get(0)); |
---|
1076 | assertEquals("/api/targets/00000000-0000-0000-0000-000000000032", resultAnnotInfo.getTargets().getHref().get(1)); |
---|
1077 | |
---|
1078 | } |
---|
1079 | |
---|
1080 | @Test |
---|
1081 | public void testGetTargetsWithNoCachedRepresentation() { |
---|
1082 | System.out.println("test getTargetsWithNoCachedRepresentation"); |
---|
1083 | |
---|
1084 | final List<Number> targetIDs = new ArrayList<Number>(); |
---|
1085 | targetIDs.add(5); |
---|
1086 | targetIDs.add(7); |
---|
1087 | |
---|
1088 | final List<Number> cachedIDs5 = new ArrayList<Number>(); |
---|
1089 | cachedIDs5.add(7); |
---|
1090 | final List<Number> cachedIDs7 = new ArrayList<Number>(); |
---|
1091 | |
---|
1092 | |
---|
1093 | |
---|
1094 | mockeryDao.checking(new Expectations() { |
---|
1095 | { |
---|
1096 | oneOf(targetDao).getTargetIDs(3); |
---|
1097 | will(returnValue(targetIDs)); |
---|
1098 | |
---|
1099 | oneOf(cachedRepresentationDao).getCachedRepresentationsForTarget(5); |
---|
1100 | will(returnValue(cachedIDs5)); |
---|
1101 | |
---|
1102 | oneOf(cachedRepresentationDao).getCachedRepresentationsForTarget(7); |
---|
1103 | will(returnValue(cachedIDs7)); |
---|
1104 | |
---|
1105 | oneOf(targetDao).getHrefFromInternalID(7); |
---|
1106 | will(returnValue("/api/targets/00000000-0000-0000-0000-000000000037")); |
---|
1107 | |
---|
1108 | } |
---|
1109 | }); |
---|
1110 | |
---|
1111 | List<String> result = dbDispatcher.getTargetsWithNoCachedRepresentation(3); |
---|
1112 | assertEquals(1, result.size()); |
---|
1113 | assertEquals("/api/targets/00000000-0000-0000-0000-000000000037", result.get(0)); // Target number 7 has no cached |
---|
1114 | } |
---|
1115 | |
---|
1116 | ////////////// ADDERS ///////////////////////// |
---|
1117 | /** |
---|
1118 | * Test of addCachedForVersion method, of class DBIntegrityServiceImlp. |
---|
1119 | */ |
---|
1120 | @Test |
---|
1121 | public void testAddCached() throws SerialException, IOException, NotInDataBaseException { |
---|
1122 | System.out.println("test addCached"); |
---|
1123 | |
---|
1124 | String mime = "text/html"; |
---|
1125 | String type = "text"; |
---|
1126 | String tool = "latex"; |
---|
1127 | String externalID = Helpers.generateUUID().toString(); |
---|
1128 | final CachedRepresentationInfo newCachedInfo = new CachedRepresentationInfo(); |
---|
1129 | newCachedInfo.setMimeType(mime); |
---|
1130 | newCachedInfo.setType(type); |
---|
1131 | newCachedInfo.setTool(tool); |
---|
1132 | newCachedInfo.setHref("/api/cached/" + externalID); |
---|
1133 | newCachedInfo.setId(externalID); |
---|
1134 | |
---|
1135 | String blobString = "aaa"; |
---|
1136 | byte[] blobBytes = blobString.getBytes(); |
---|
1137 | final ByteArrayInputStream newCachedBlob = new ByteArrayInputStream(blobBytes); |
---|
1138 | |
---|
1139 | mockeryDao.checking(new Expectations() { |
---|
1140 | { |
---|
1141 | |
---|
1142 | oneOf(cachedRepresentationDao).addCachedRepresentation(newCachedInfo, newCachedBlob); |
---|
1143 | will(returnValue(8)); |
---|
1144 | |
---|
1145 | one(targetDao).addTargetCachedRepresentation(1, 8, "#(1,2)"); |
---|
1146 | will(returnValue(1)); |
---|
1147 | |
---|
1148 | } |
---|
1149 | }); |
---|
1150 | |
---|
1151 | |
---|
1152 | Number[] result = dbDispatcher.addCachedForTarget(1, "#(1,2)", newCachedInfo, newCachedBlob); |
---|
1153 | assertEquals(2, result.length); |
---|
1154 | assertEquals(1, result[0]); |
---|
1155 | assertEquals(8, result[1]); |
---|
1156 | } |
---|
1157 | |
---|
1158 | /** |
---|
1159 | * Test of updateSiblingTargetClassForTarget method, of class |
---|
1160 | * DBIntegrityServiceImlp. |
---|
1161 | * |
---|
1162 | * |
---|
1163 | */ |
---|
1164 | /** |
---|
1165 | * Test of addTargetsForAnnotation method, of class DBIntegrityServiceImlp. |
---|
1166 | */ |
---|
1167 | @Test |
---|
1168 | public void testAddTargetsForAnnotation() throws Exception { |
---|
1169 | System.out.println("test addTargetsForAnnotation"); |
---|
1170 | |
---|
1171 | // test 1: adding an existing target |
---|
1172 | TargetInfo testTargetOne = new TargetInfo(); |
---|
1173 | testTargetOne.setLink("http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia"); |
---|
1174 | testTargetOne.setHref("/api/targets/00000000-0000-0000-0000-000000000031"); |
---|
1175 | testTargetOne.setVersion("version 1.0"); |
---|
1176 | final List<TargetInfo> mockTargetListOne = new ArrayList<TargetInfo>(); |
---|
1177 | mockTargetListOne.add(testTargetOne); |
---|
1178 | |
---|
1179 | mockeryDao.checking(new Expectations() { |
---|
1180 | { |
---|
1181 | oneOf(targetDao).getInternalIDFromHref(mockTargetListOne.get(0).getHref()); |
---|
1182 | will(returnValue(1)); |
---|
1183 | |
---|
1184 | oneOf(annotationDao).addAnnotationTarget(4, 1); |
---|
1185 | will(returnValue(1)); |
---|
1186 | } |
---|
1187 | }); |
---|
1188 | |
---|
1189 | Map<String, String> result = dbDispatcher.addTargetsForAnnotation(4, mockTargetListOne); |
---|
1190 | assertEquals(0, result.size()); |
---|
1191 | |
---|
1192 | // test 2: adding a new Target |
---|
1193 | TargetInfo testTargetTwo = new TargetInfo(); |
---|
1194 | final String tempTargetID = "/api/targets/"+Helpers.generateUUID().toString(); |
---|
1195 | testTargetTwo.setHref(tempTargetID); |
---|
1196 | testTargetTwo.setLink("http://www.sagradafamilia.cat/docs_instit/historia.php"); |
---|
1197 | testTargetTwo.setVersion("version 1.0"); |
---|
1198 | final List<TargetInfo> mockTargetListTwo = new ArrayList<TargetInfo>(); |
---|
1199 | mockTargetListTwo.add(testTargetTwo); |
---|
1200 | |
---|
1201 | final UUID mockNewTargetUUID = Helpers.generateUUID(); |
---|
1202 | final NotInDataBaseException e = new NotInDataBaseException("target", "external ID", tempTargetID); |
---|
1203 | |
---|
1204 | // Target newTarget = this.createFreshTarget(targetInfo); |
---|
1205 | // Number targetID = targetDao.addTarget(newTarget); |
---|
1206 | // String targetTemporaryId = targetInfo.getHref(); |
---|
1207 | // result.put(targetTemporaryId, targetDao.getExternalID(targetID).toString()); |
---|
1208 | // int affectedRows = annotationDao.addAnnotationTarget(annotationID, targetID); |
---|
1209 | // |
---|
1210 | mockeryDao.checking(new Expectations() { |
---|
1211 | { |
---|
1212 | oneOf(targetDao).getInternalIDFromHref(mockTargetListTwo.get(0).getHref()); |
---|
1213 | will(throwException(e)); |
---|
1214 | |
---|
1215 | oneOf(targetDao).addTarget(with(aNonNull(Target.class))); |
---|
1216 | will(returnValue(8)); //# the next new number is 8, we have already 7 Targets |
---|
1217 | |
---|
1218 | oneOf(targetDao).getHrefFromInternalID(8); |
---|
1219 | will(returnValue("/api/targets/"+mockNewTargetUUID.toString())); |
---|
1220 | |
---|
1221 | oneOf(annotationDao).addAnnotationTarget(1, 8); |
---|
1222 | will(returnValue(1)); |
---|
1223 | |
---|
1224 | } |
---|
1225 | }); |
---|
1226 | |
---|
1227 | Map<String, String> resultTwo = dbDispatcher.addTargetsForAnnotation(1, mockTargetListTwo); |
---|
1228 | assertEquals(1, resultTwo.size()); |
---|
1229 | assertEquals("/api/targets/"+mockNewTargetUUID.toString(), resultTwo.get(tempTargetID)); |
---|
1230 | |
---|
1231 | } |
---|
1232 | |
---|
1233 | /** |
---|
1234 | * Test of addPrincipalsAnnotation method, of class DBIntegrityServiceImlp. |
---|
1235 | */ |
---|
1236 | @Test |
---|
1237 | public void testAddPrincipalsAnnotation() throws Exception { |
---|
1238 | System.out.println("test addPrincipalsAnnotation"); |
---|
1239 | |
---|
1240 | // expectations for addPrincipalsannotation itself |
---|
1241 | final Annotation testAnnotation = testInstances.getAnnotationToAdd(); |
---|
1242 | |
---|
1243 | mockeryDao.checking(new Expectations() { |
---|
1244 | { |
---|
1245 | oneOf(annotationDao).addAnnotation(testAnnotation, 3); |
---|
1246 | will(returnValue(5)); // the next free number is 5 |
---|
1247 | |
---|
1248 | // expectations for addTargetsForannotation |
---|
1249 | oneOf(targetDao).getInternalIDFromHref("/api/targets/00000000-0000-0000-0000-000000000031"); |
---|
1250 | will(returnValue(1)); |
---|
1251 | |
---|
1252 | oneOf(annotationDao).addAnnotationTarget(5, 1); |
---|
1253 | will(returnValue(1)); |
---|
1254 | |
---|
1255 | /////////// |
---|
1256 | |
---|
1257 | oneOf(annotationDao).updateAnnotationBody(5, testAnnotation.getBody().getTextBody().getBody(), testAnnotation.getBody().getTextBody().getMimeType(), false); |
---|
1258 | will(returnValue(1)); // the DB update will be called at perform anyway, even if the body is not changed (can be optimized) |
---|
1259 | |
---|
1260 | oneOf(annotationDao).updatePublicAttribute(5, Access.WRITE); |
---|
1261 | will(returnValue(1)); |
---|
1262 | } |
---|
1263 | }); |
---|
1264 | |
---|
1265 | Number result = dbDispatcher.addPrincipalsAnnotation(3, testAnnotation); |
---|
1266 | assertEquals(5, result); |
---|
1267 | |
---|
1268 | // Annotation newAnnotation = dbDispatcher.getAnnotation(5); |
---|
1269 | // assertEquals("/api/principals/00000000-0000-0000-0000-000000000113", newAnnotation.getOwnerHref()); |
---|
1270 | // assertEquals(testAnnotation.getHeadline(), newAnnotation.getHeadline()); |
---|
1271 | // assertEquals(testAnnotation.getBody().getTextBody().getBody(), newAnnotation.getBody().getTextBody().getBody()); |
---|
1272 | // assertEquals(testAnnotation.getBody().getTextBody().getMimeType(), newAnnotation.getBody().getTextBody().getMimeType()); |
---|
1273 | // assertEquals(testAnnotation.getPermissions().getPermission().size(), newAnnotation.getPermissions().getPermission().size()); |
---|
1274 | // assertEquals(Access.WRITE, newAnnotation.getPermissions().getPublic()); |
---|
1275 | // assertEquals(testAnnotation.getTargets().getTargetInfo().size(), newAnnotation.getTargets().getTargetInfo().size()); |
---|
1276 | |
---|
1277 | } |
---|
1278 | |
---|
1279 | @Test |
---|
1280 | public void testAddPrincipal() throws NotInDataBaseException, PrincipalExists { |
---|
1281 | System.out.println("test addPrincipal"); |
---|
1282 | final Principal freshPrincipal = new Principal(); |
---|
1283 | freshPrincipal.setDisplayName("Guilherme"); |
---|
1284 | freshPrincipal.setEMail("Guilherme.Silva@mpi.nl"); |
---|
1285 | mockeryDao.checking(new Expectations() { |
---|
1286 | { |
---|
1287 | oneOf(principalDao).principalExists("guisil@mpi.nl"); |
---|
1288 | will(returnValue(false)); |
---|
1289 | |
---|
1290 | oneOf(principalDao).addPrincipal(freshPrincipal, "guisil@mpi.nl"); |
---|
1291 | will(returnValue(11)); |
---|
1292 | } |
---|
1293 | }); |
---|
1294 | |
---|
1295 | |
---|
1296 | assertEquals(11, dbDispatcher.addPrincipal(freshPrincipal, "guisil@mpi.nl").intValue()); |
---|
1297 | |
---|
1298 | /// principal already exists |
---|
1299 | final Principal principal = new Principal(); |
---|
1300 | freshPrincipal.setDisplayName("Olha"); |
---|
1301 | freshPrincipal.setEMail("Olha.Shakaravska@mpi.nl"); |
---|
1302 | mockeryDao.checking(new Expectations() { |
---|
1303 | { |
---|
1304 | oneOf(principalDao).principalExists("olhsha@mpi.nl"); |
---|
1305 | will(returnValue(true)); |
---|
1306 | |
---|
1307 | } |
---|
1308 | }); |
---|
1309 | |
---|
1310 | PrincipalExists ex = null; |
---|
1311 | try { |
---|
1312 | dbDispatcher.addPrincipal(principal, "olhsha@mpi.nl"); |
---|
1313 | } catch (PrincipalExists e) { |
---|
1314 | ex = e; |
---|
1315 | } |
---|
1316 | assertFalse(ex == null); |
---|
1317 | } |
---|
1318 | |
---|
1319 | //////////////////// DELETERS //////////////// |
---|
1320 | @Test |
---|
1321 | public void testDeletePrincipal() throws PrincipalCannotBeDeleted{ |
---|
1322 | System.out.println("test deletePrincipal"); |
---|
1323 | |
---|
1324 | mockeryDao.checking(new Expectations() { |
---|
1325 | { |
---|
1326 | oneOf(principalDao).deletePrincipal(1); |
---|
1327 | will(returnValue(0)); |
---|
1328 | |
---|
1329 | oneOf(principalDao).deletePrincipal(3); |
---|
1330 | will(returnValue(0)); |
---|
1331 | |
---|
1332 | oneOf(principalDao).deletePrincipal(10); |
---|
1333 | will(returnValue(1)); |
---|
1334 | |
---|
1335 | } |
---|
1336 | }); |
---|
1337 | |
---|
1338 | assertEquals(0, dbDispatcher.deletePrincipal(1)); |
---|
1339 | assertEquals(0, dbDispatcher.deletePrincipal(3)); |
---|
1340 | assertEquals(1, dbDispatcher.deletePrincipal(10)); |
---|
1341 | } |
---|
1342 | |
---|
1343 | /** |
---|
1344 | * Test of deleteCachedForVersion method, of class DBIntegrityServiceImlp. |
---|
1345 | */ |
---|
1346 | @Test |
---|
1347 | public void testDeleteCachedRepresentationForTarget() throws SQLException { |
---|
1348 | System.out.println("test deleteCachedRepresentationForTarget"); |
---|
1349 | mockeryDao.checking(new Expectations() { |
---|
1350 | { |
---|
1351 | oneOf(targetDao).deleteTargetCachedRepresentation(5, 7); |
---|
1352 | will(returnValue(1)); |
---|
1353 | |
---|
1354 | oneOf(cachedRepresentationDao).deleteCachedRepresentation(7); |
---|
1355 | will(returnValue(1)); // cached is used by another version |
---|
1356 | |
---|
1357 | } |
---|
1358 | }); |
---|
1359 | |
---|
1360 | int[] result = dbDispatcher.deleteCachedRepresentationOfTarget(5, 7); |
---|
1361 | assertEquals(2, result.length); |
---|
1362 | assertEquals(1, result[0]); |
---|
1363 | assertEquals(1, result[1]); |
---|
1364 | } |
---|
1365 | |
---|
1366 | ///////////////////////////////////////////// |
---|
1367 | @Test |
---|
1368 | public void testDeleteAllCachedRepresentationsOfTarget() throws SQLException { |
---|
1369 | System.out.println("test deleteAllCachedRepresentationsOfTarget"); |
---|
1370 | final List<Number> cachedList = new ArrayList<Number>(); |
---|
1371 | cachedList.add(1); |
---|
1372 | cachedList.add(2); |
---|
1373 | |
---|
1374 | mockeryDao.checking(new Expectations() { |
---|
1375 | { |
---|
1376 | oneOf(cachedRepresentationDao).getCachedRepresentationsForTarget(1); |
---|
1377 | will(returnValue(cachedList)); |
---|
1378 | |
---|
1379 | oneOf(targetDao).deleteTargetCachedRepresentation(1, 1); |
---|
1380 | will(returnValue(1)); |
---|
1381 | |
---|
1382 | oneOf(cachedRepresentationDao).deleteCachedRepresentation(1); |
---|
1383 | will(returnValue(1)); |
---|
1384 | |
---|
1385 | oneOf(targetDao).deleteTargetCachedRepresentation(1, 2); |
---|
1386 | will(returnValue(1)); |
---|
1387 | |
---|
1388 | oneOf(cachedRepresentationDao).deleteCachedRepresentation(2); |
---|
1389 | will(returnValue(1)); |
---|
1390 | |
---|
1391 | } |
---|
1392 | }); |
---|
1393 | |
---|
1394 | int[] result = dbDispatcher.deleteAllCachedRepresentationsOfTarget(1); |
---|
1395 | assertEquals(2, result[0]); // # affected rows in Targets_cacheds |
---|
1396 | assertEquals(2, result[1]); // # affected rows in cacheds |
---|
1397 | } |
---|
1398 | |
---|
1399 | /** |
---|
1400 | * Test of deleteAnnotationWithTargets method, of class |
---|
1401 | * DBIntegrityServiceImlp. |
---|
1402 | */ |
---|
1403 | @Test |
---|
1404 | public void testDeleteAnnotation() throws Exception { |
---|
1405 | System.out.println("deleteAnnotation "); |
---|
1406 | |
---|
1407 | // deleting annotation 3, which has its target Target 2 (used by annotation # 1) |
---|
1408 | final List<Number> mockTargetIDs = new ArrayList<Number>(); |
---|
1409 | mockTargetIDs.add(2); |
---|
1410 | |
---|
1411 | final List<Number> mockCachedIDs = new ArrayList<Number>(); |
---|
1412 | mockCachedIDs.add(3); |
---|
1413 | |
---|
1414 | mockeryDao.checking(new Expectations() { |
---|
1415 | { |
---|
1416 | oneOf(annotationDao).deleteAnnotationPermissions(2); |
---|
1417 | will(returnValue(2)); |
---|
1418 | |
---|
1419 | oneOf(targetDao).getTargetIDs(2); |
---|
1420 | will(returnValue(mockTargetIDs)); |
---|
1421 | |
---|
1422 | oneOf(annotationDao).deleteAllAnnotationTarget(2); |
---|
1423 | will(returnValue(1)); |
---|
1424 | |
---|
1425 | oneOf(annotationDao).deleteAnnotation(2); |
---|
1426 | will(returnValue(1)); |
---|
1427 | |
---|
1428 | oneOf(cachedRepresentationDao).getCachedRepresentationsForTarget(2); |
---|
1429 | will(returnValue(mockCachedIDs)); |
---|
1430 | |
---|
1431 | oneOf(targetDao).deleteTargetCachedRepresentation(2, 3); |
---|
1432 | will(returnValue(1)); |
---|
1433 | |
---|
1434 | oneOf(cachedRepresentationDao).deleteCachedRepresentation(3); |
---|
1435 | will(returnValue(1)); |
---|
1436 | |
---|
1437 | oneOf(annotationDao).targetIsInUse(2); |
---|
1438 | will(returnValue(true)); |
---|
1439 | |
---|
1440 | oneOf(targetDao).deleteTarget(2); |
---|
1441 | will(returnValue(0)); |
---|
1442 | |
---|
1443 | oneOf(annotationDao).deleteAnnotationFromAllNotebooks(2); |
---|
1444 | will(returnValue(1)); |
---|
1445 | |
---|
1446 | |
---|
1447 | } |
---|
1448 | }); |
---|
1449 | int[] result = dbDispatcher.deleteAnnotation(2);// the Target will be deleted because it is not referred by any annotation |
---|
1450 | assertEquals(5, result.length); |
---|
1451 | assertEquals(1, result[0]); // annotation 3 is deleted |
---|
1452 | assertEquals(2, result[1]); // 2 rows in "annotation principal accesss are deleted" |
---|
1453 | assertEquals(1, result[2]); // row (3,2) in "annotations_Targets" is deleted |
---|
1454 | assertEquals(0, result[3]); // target 2 is not deleted deleted since it is used by annotation 1 |
---|
1455 | assertEquals(1, result[4]); // deleted from 1 notebook |
---|
1456 | } |
---|
1457 | |
---|
1458 | /** |
---|
1459 | * NOTEBOOKS |
---|
1460 | */ |
---|
1461 | /** |
---|
1462 | * Getters |
---|
1463 | */ |
---|
1464 | // public Number getNotebookInternalIdentifier(UUID externalIdentifier){ |
---|
1465 | // return notebookDao.getInternalID(externalIdentifier); |
---|
1466 | // } |
---|
1467 | @Test |
---|
1468 | public void testGetNotebookInternalIdentifier() throws NotInDataBaseException { |
---|
1469 | |
---|
1470 | final UUID mockUUID = UUID.fromString("00000000-0000-0000-0000-000000000021"); |
---|
1471 | |
---|
1472 | mockeryDao.checking(new Expectations() { |
---|
1473 | { |
---|
1474 | oneOf(notebookDao).getInternalID(mockUUID); |
---|
1475 | will(returnValue(1)); |
---|
1476 | } |
---|
1477 | }); |
---|
1478 | |
---|
1479 | assertEquals(1, dbDispatcher.getResourceInternalIdentifier(mockUUID, Resource.NOTEBOOK)); |
---|
1480 | |
---|
1481 | } |
---|
1482 | |
---|
1483 | // public NotebookInfoList getNotebooks(Number principalID, String access) { |
---|
1484 | // NotebookInfoList result = new NotebookInfoList(); |
---|
1485 | // if (access.equalsIgnoreCase("read") || access.equalsIgnoreCase("write")) { |
---|
1486 | // List<Number> notebookIDs = notebookDao.getNotebookIDs(principalID, Access.fromValue(access)); |
---|
1487 | // for (Number notebookID : notebookIDs) { |
---|
1488 | // NotebookInfo notebookInfo = notebookDao.getNotebookInfoWithoutOwner(notebookID); |
---|
1489 | // Number ownerID = notebookDao.getOwner(notebookID); |
---|
1490 | // notebookInfo.setOwnerRef(principalDao.getURIFromInternalID(ownerID)); |
---|
1491 | // result.getNotebookInfo().add(notebookInfo); |
---|
1492 | // } |
---|
1493 | // } else { |
---|
1494 | // if (access.equalsIgnoreCase("owner")) { |
---|
1495 | // List<Number> notebookIDs = notebookDao.getNotebookIDsOwnedBy(principalID); |
---|
1496 | // String ownerRef = principalDao.getURIFromInternalID(principalID); |
---|
1497 | // for (Number notebookID : notebookIDs) { |
---|
1498 | // NotebookInfo notebookInfo = notebookDao.getNotebookInfoWithoutOwner(notebookID); |
---|
1499 | // notebookInfo.setOwnerRef(ownerRef); |
---|
1500 | // result.getNotebookInfo().add(notebookInfo); |
---|
1501 | // } |
---|
1502 | // } else { |
---|
1503 | // return null; |
---|
1504 | // } |
---|
1505 | // } |
---|
1506 | // return result; |
---|
1507 | // } |
---|
1508 | @Test |
---|
1509 | public void testGetNotebooksREADBranch() { |
---|
1510 | |
---|
1511 | final List<Number> mockNotebookIDs = new ArrayList<Number>(); |
---|
1512 | mockNotebookIDs.add(1); |
---|
1513 | |
---|
1514 | final NotebookInfo mockNotebookInfo = new NotebookInfo(); |
---|
1515 | mockNotebookInfo.setHref("/api/notebooks/00000000-0000-0000-0000-000000000011"); |
---|
1516 | mockNotebookInfo.setTitle("Notebook 1"); |
---|
1517 | |
---|
1518 | mockeryDao.checking(new Expectations() { |
---|
1519 | { |
---|
1520 | oneOf(notebookDao).getNotebookIDs(3, Access.READ); |
---|
1521 | will(returnValue(mockNotebookIDs)); |
---|
1522 | |
---|
1523 | oneOf(notebookDao).getNotebookInfoWithoutOwner(1); |
---|
1524 | will(returnValue(mockNotebookInfo)); |
---|
1525 | |
---|
1526 | oneOf(notebookDao).getOwner(1); |
---|
1527 | will(returnValue(1)); |
---|
1528 | |
---|
1529 | oneOf(principalDao).getHrefFromInternalID(1); |
---|
1530 | will(returnValue("/api/principals/00000000-0000-0000-0000-000000000111")); |
---|
1531 | |
---|
1532 | } |
---|
1533 | }); |
---|
1534 | |
---|
1535 | NotebookInfoList result = dbDispatcher.getNotebooks(3, Access.READ); |
---|
1536 | assertEquals("/api/notebooks/00000000-0000-0000-0000-000000000011", result.getNotebookInfo().get(0).getHref()); |
---|
1537 | assertEquals("/api/principals/00000000-0000-0000-0000-000000000111", result.getNotebookInfo().get(0).getOwnerHref()); |
---|
1538 | assertEquals("Notebook 1", result.getNotebookInfo().get(0).getTitle()); |
---|
1539 | |
---|
1540 | } |
---|
1541 | |
---|
1542 | @Test |
---|
1543 | @Ignore |
---|
1544 | public void testGetNotebooksOwnerBranch() { |
---|
1545 | |
---|
1546 | final List<Number> mockNotebookIDs = new ArrayList<Number>(); |
---|
1547 | mockNotebookIDs.add(3); |
---|
1548 | mockNotebookIDs.add(4); |
---|
1549 | |
---|
1550 | final NotebookInfo mockNotebookInfo1 = new NotebookInfo(); |
---|
1551 | mockNotebookInfo1.setHref("/api/notebooks/00000000-0000-0000-0000-000000000013"); |
---|
1552 | mockNotebookInfo1.setTitle("Notebook 3"); |
---|
1553 | |
---|
1554 | final NotebookInfo mockNotebookInfo2 = new NotebookInfo(); |
---|
1555 | mockNotebookInfo2.setHref("/api/notebooks/00000000-0000-0000-0000-000000000014"); |
---|
1556 | mockNotebookInfo2.setTitle("Notebook 4"); |
---|
1557 | |
---|
1558 | mockeryDao.checking(new Expectations() { |
---|
1559 | { |
---|
1560 | oneOf(notebookDao).getNotebookIDsOwnedBy(3); |
---|
1561 | will(returnValue(mockNotebookIDs)); |
---|
1562 | |
---|
1563 | oneOf(principalDao).getHrefFromInternalID(3); |
---|
1564 | will(returnValue("/api/principals/00000000-0000-0000-0000-000000000113")); |
---|
1565 | |
---|
1566 | oneOf(notebookDao).getNotebookInfoWithoutOwner(3); |
---|
1567 | will(returnValue(mockNotebookInfo1)); |
---|
1568 | |
---|
1569 | oneOf(notebookDao).getNotebookInfoWithoutOwner(4); |
---|
1570 | will(returnValue(mockNotebookInfo2)); |
---|
1571 | |
---|
1572 | } |
---|
1573 | }); |
---|
1574 | |
---|
1575 | //?? |
---|
1576 | // NotebookInfoList result = dbDispatcher.getNotebooks(3, "owner"); |
---|
1577 | // assertEquals("00000000-0000-0000-0000-000000000013", result.getNotebookInfo().get(0).getRef());// assertEquals("00000000-0000-0000-0000-000000000113", result.getNotebookInfo().get(0).getOwnerRef()); |
---|
1578 | // assertEquals("Notebook 3", result.getNotebookInfo().get(0).getTitle()); |
---|
1579 | // assertEquals("00000000-0000-0000-0000-000000000014", result.getNotebookInfo().get(1).getRef()); |
---|
1580 | // assertEquals("00000000-0000-0000-0000-000000000113", result.getNotebookInfo().get(1).getOwnerRef()); |
---|
1581 | // assertEquals("Notebook 4", result.getNotebookInfo().get(1).getTitle()); |
---|
1582 | |
---|
1583 | } |
---|
1584 | |
---|
1585 | // public ReferenceList getNotebooksOwnedBy(Number principalID) { |
---|
1586 | // ReferenceList result = new ReferenceList(); |
---|
1587 | // List<Number> notebookIDs = notebookDao.getNotebookIDsOwnedBy(principalID); |
---|
1588 | // for (Number notebookID : notebookIDs) { |
---|
1589 | // String reference = notebookDao.getURIFromInternalID(notebookID); |
---|
1590 | // result.getRef().add(reference); |
---|
1591 | // } |
---|
1592 | // return result; |
---|
1593 | // } |
---|
1594 | @Test |
---|
1595 | public void testGetNotebooksOwnedBy() { |
---|
1596 | |
---|
1597 | final List<Number> mockNotebookIDs = new ArrayList<Number>(); |
---|
1598 | mockNotebookIDs.add(3); |
---|
1599 | mockNotebookIDs.add(4); |
---|
1600 | |
---|
1601 | mockeryDao.checking(new Expectations() { |
---|
1602 | { |
---|
1603 | oneOf(notebookDao).getNotebookIDsOwnedBy(3); |
---|
1604 | will(returnValue(mockNotebookIDs)); |
---|
1605 | |
---|
1606 | oneOf(notebookDao).getHrefFromInternalID(3); |
---|
1607 | will(returnValue("/api/notebooks/00000000-0000-0000-0000-000000000013")); |
---|
1608 | |
---|
1609 | oneOf(notebookDao).getHrefFromInternalID(4); |
---|
1610 | will(returnValue("/api/notebooks/00000000-0000-0000-0000-000000000014")); |
---|
1611 | |
---|
1612 | } |
---|
1613 | }); |
---|
1614 | |
---|
1615 | ReferenceList result = dbDispatcher.getNotebooksOwnedBy(3); |
---|
1616 | assertEquals(2, result.getHref().size()); |
---|
1617 | assertEquals("/api/notebooks/00000000-0000-0000-0000-000000000013", result.getHref().get(0)); |
---|
1618 | assertEquals("/api/notebooks/00000000-0000-0000-0000-000000000014", result.getHref().get(1)); |
---|
1619 | } |
---|
1620 | |
---|
1621 | /* public boolean hasAccess(Number notebookID, Number principalID, Access access){ |
---|
1622 | List<Number> notebookIDs = notebookDao.getNotebookIDs(principalID, access); |
---|
1623 | if (notebookIDs == null) { |
---|
1624 | return false; |
---|
1625 | } |
---|
1626 | return notebookIDs.contains(notebookID); |
---|
1627 | } */ |
---|
1628 | @Test |
---|
1629 | public void testHasAccess() { |
---|
1630 | |
---|
1631 | |
---|
1632 | final Access write = Access.fromValue("write"); |
---|
1633 | final List<Number> mockNotebookIDwrite = new ArrayList<Number>(); |
---|
1634 | mockNotebookIDwrite.add(1); |
---|
1635 | mockNotebookIDwrite.add(4); |
---|
1636 | |
---|
1637 | mockeryDao.checking(new Expectations() { |
---|
1638 | { |
---|
1639 | oneOf(notebookDao).getNotebookIDs(2, write); |
---|
1640 | will(returnValue(mockNotebookIDwrite)); |
---|
1641 | |
---|
1642 | oneOf(notebookDao).getNotebookIDs(2, write); |
---|
1643 | will(returnValue(mockNotebookIDwrite)); |
---|
1644 | |
---|
1645 | } |
---|
1646 | }); |
---|
1647 | |
---|
1648 | assertTrue(dbDispatcher.hasAccess(4, 2, write)); |
---|
1649 | assertFalse(dbDispatcher.hasAccess(5, 2, write)); |
---|
1650 | } |
---|
1651 | |
---|
1652 | /* |
---|
1653 | public ReferenceList getPrincipals(Number notebookID, String access) { |
---|
1654 | ReferenceList result = new ReferenceList(); |
---|
1655 | List<Number> principalIDs = notebookDao.getPrincipalIDsWithAccess(notebookID, Access.fromValue(access)); |
---|
1656 | for (Number principalID : principalIDs) { |
---|
1657 | String reference = principalDao.getURIFromInternalID(principalID); |
---|
1658 | result.getRef().add(reference); |
---|
1659 | } |
---|
1660 | return result; |
---|
1661 | } |
---|
1662 | }*/ |
---|
1663 | @Test |
---|
1664 | public void testGetPrincipals() { |
---|
1665 | final List<Number> mockPrincipalIDs = new ArrayList<Number>(); |
---|
1666 | mockPrincipalIDs.add(2); |
---|
1667 | mockPrincipalIDs.add(4); |
---|
1668 | |
---|
1669 | mockeryDao.checking(new Expectations() { |
---|
1670 | { |
---|
1671 | oneOf(principalDao).getPrincipalIDsWithAccessForNotebook(1, Access.WRITE); |
---|
1672 | will(returnValue(mockPrincipalIDs)); |
---|
1673 | |
---|
1674 | oneOf(principalDao).getHrefFromInternalID(2); |
---|
1675 | will(returnValue("/api/principals/00000000-0000-0000-0000-000000000112")); |
---|
1676 | |
---|
1677 | oneOf(principalDao).getHrefFromInternalID(4); |
---|
1678 | will(returnValue("/api/principals/00000000-0000-0000-0000-000000000114")); |
---|
1679 | |
---|
1680 | |
---|
1681 | } |
---|
1682 | }); |
---|
1683 | |
---|
1684 | ReferenceList result = dbDispatcher.getPrincipals(1, "write"); |
---|
1685 | assertEquals("/api/principals/00000000-0000-0000-0000-000000000112", result.getHref().get(0).toString()); |
---|
1686 | assertEquals("/api/principals/00000000-0000-0000-0000-000000000114", result.getHref().get(1).toString()); |
---|
1687 | |
---|
1688 | } |
---|
1689 | |
---|
1690 | // @Override |
---|
1691 | // public Notebook getNotebook(Number notebookID) { |
---|
1692 | // Notebook result = notebookDao.getNotebookWithoutAnnotationsAndAccesssAndOwner(notebookID); |
---|
1693 | // |
---|
1694 | // result.setOwnerRef(principalDao.getURIFromInternalID(notebookDao.getOwner(notebookID))); |
---|
1695 | // |
---|
1696 | // ReferenceList annotations = new ReferenceList(); |
---|
1697 | // List<Number> annotationIDs = notebookDao.getAnnotations(notebookID); |
---|
1698 | // for (Number annotationID : annotationIDs) { |
---|
1699 | // annotations.getRef().add(annotationDao.getURIFromInternalID(annotationID)); |
---|
1700 | // } |
---|
1701 | // result.setAnnotations(annotations); |
---|
1702 | // |
---|
1703 | // PermissionList ups = new PermissionList(); |
---|
1704 | // List<Access> accesss = new ArrayList<Access>(); |
---|
1705 | // accesss.add(Access.READ); |
---|
1706 | // accesss.add(Access.WRITE); |
---|
1707 | // for (Access access : accesss) { |
---|
1708 | // List<Number> principals = notebookDao.getPrincipalIDsWithAccess(notebookID, access); |
---|
1709 | // if (principals != null) { |
---|
1710 | // for (Number principal : principals) { |
---|
1711 | // Permission up = new Permission(); |
---|
1712 | // up.setRef(principalDao.getURIFromInternalID(principal)); |
---|
1713 | // up.setAccess(access); |
---|
1714 | // ups.getPermission().add(up); |
---|
1715 | // } |
---|
1716 | // } |
---|
1717 | // } |
---|
1718 | // |
---|
1719 | // result.setAccesss(ups); |
---|
1720 | // return result; |
---|
1721 | // } |
---|
1722 | @Test |
---|
1723 | public void testGetNotebook() throws DatatypeConfigurationException { |
---|
1724 | |
---|
1725 | final Notebook mockNotebook = new Notebook(); |
---|
1726 | mockNotebook.setHref("/api/notebooks/00000000-0000-0000-0000-000000000012"); |
---|
1727 | mockNotebook.setId("00000000-0000-0000-0000-000000000012"); |
---|
1728 | mockNotebook.setTitle("Notebook 2"); |
---|
1729 | mockNotebook.setLastModified(DatatypeFactory.newInstance().newXMLGregorianCalendar("2014-02-12T09:25:00.383000Z")); |
---|
1730 | |
---|
1731 | final List<Number> mockAnnotations = new ArrayList<Number>(); |
---|
1732 | mockAnnotations.add(3); |
---|
1733 | |
---|
1734 | final List<Number> mockREADs = new ArrayList<Number>(); |
---|
1735 | mockREADs.add(1); |
---|
1736 | |
---|
1737 | final List<Number> mockWRITEs = new ArrayList<Number>(); |
---|
1738 | mockWRITEs.add(3); |
---|
1739 | |
---|
1740 | mockeryDao.checking(new Expectations() { |
---|
1741 | { |
---|
1742 | oneOf(notebookDao).getNotebookWithoutAnnotationsAndAccesssAndOwner(2); |
---|
1743 | will(returnValue(mockNotebook)); |
---|
1744 | |
---|
1745 | oneOf(notebookDao).getOwner(2); |
---|
1746 | will(returnValue(2)); |
---|
1747 | |
---|
1748 | oneOf(principalDao).getHrefFromInternalID(2); |
---|
1749 | will(returnValue("/api/principals/00000000-0000-0000-0000-000000000112")); |
---|
1750 | |
---|
1751 | oneOf(annotationDao).getAnnotations(2); |
---|
1752 | will(returnValue(mockAnnotations)); |
---|
1753 | |
---|
1754 | oneOf(annotationDao).getHrefFromInternalID(3); |
---|
1755 | will(returnValue("/api/annotations/00000000-0000-0000-0000-000000000023")); |
---|
1756 | |
---|
1757 | oneOf(principalDao).getPrincipalIDsWithAccessForNotebook(2, Access.READ); |
---|
1758 | will(returnValue(mockREADs)); |
---|
1759 | |
---|
1760 | oneOf(principalDao).getHrefFromInternalID(1); |
---|
1761 | will(returnValue("/api/principals/00000000-0000-0000-0000-000000000111")); |
---|
1762 | |
---|
1763 | oneOf(principalDao).getPrincipalIDsWithAccessForNotebook(2, Access.WRITE); |
---|
1764 | will(returnValue(mockWRITEs)); |
---|
1765 | |
---|
1766 | oneOf(principalDao).getHrefFromInternalID(3); |
---|
1767 | will(returnValue("/api/principals/00000000-0000-0000-0000-000000000113")); |
---|
1768 | |
---|
1769 | |
---|
1770 | |
---|
1771 | } |
---|
1772 | }); |
---|
1773 | |
---|
1774 | Notebook result = dbDispatcher.getNotebook(2); |
---|
1775 | assertEquals("/api/notebooks/00000000-0000-0000-0000-000000000012", result.getHref()); |
---|
1776 | assertEquals("00000000-0000-0000-0000-000000000012", result.getId()); |
---|
1777 | assertEquals("/api/principals/00000000-0000-0000-0000-000000000112", result.getOwnerRef()); |
---|
1778 | assertEquals("2014-02-12T09:25:00.383000Z", result.getLastModified().toString()); |
---|
1779 | assertEquals("Notebook 2", result.getTitle()); |
---|
1780 | assertEquals(1, result.getAnnotations().getHref().size()); |
---|
1781 | assertEquals("/api/annotations/00000000-0000-0000-0000-000000000023", result.getAnnotations().getHref().get(0)); |
---|
1782 | assertEquals(2, result.getPermissions().getPermission().size()); |
---|
1783 | assertEquals("/api/principals/00000000-0000-0000-0000-000000000111", result.getPermissions().getPermission().get(0).getPrincipalHref()); |
---|
1784 | assertEquals("read", result.getPermissions().getPermission().get(0).getLevel().value()); |
---|
1785 | assertEquals("/api/principals/00000000-0000-0000-0000-000000000113", result.getPermissions().getPermission().get(1).getPrincipalHref()); |
---|
1786 | assertEquals("write", result.getPermissions().getPermission().get(1).getLevel().value()); |
---|
1787 | |
---|
1788 | } |
---|
1789 | |
---|
1790 | @Test |
---|
1791 | public void testAnnotationsForNotebook() { |
---|
1792 | final List<Number> mockAnnotationIDs = new ArrayList<Number>(); |
---|
1793 | mockAnnotationIDs.add(1); |
---|
1794 | mockAnnotationIDs.add(2); |
---|
1795 | |
---|
1796 | mockeryDao.checking(new Expectations() { |
---|
1797 | { |
---|
1798 | oneOf(annotationDao).getAnnotations(1); |
---|
1799 | will(returnValue(mockAnnotationIDs)); |
---|
1800 | |
---|
1801 | oneOf(annotationDao).sublistOrderedAnnotationIDs(mockAnnotationIDs, 0, 3, "last_modified", "DESC"); |
---|
1802 | will(returnValue(mockAnnotationIDs)); |
---|
1803 | |
---|
1804 | oneOf(annotationDao).getHrefFromInternalID(1); |
---|
1805 | will(returnValue("/api/annotations/00000000-0000-0000-0000-000000000021")); |
---|
1806 | |
---|
1807 | oneOf(annotationDao).getHrefFromInternalID(2); |
---|
1808 | will(returnValue("/api/annotations/00000000-0000-0000-0000-000000000022")); |
---|
1809 | |
---|
1810 | |
---|
1811 | |
---|
1812 | } |
---|
1813 | }); |
---|
1814 | |
---|
1815 | ReferenceList result = dbDispatcher.getAnnotationsForNotebook(1, -1, 3, "last_modified", true); |
---|
1816 | assertEquals(2, result.getHref().size()); |
---|
1817 | assertEquals("/api/annotations/00000000-0000-0000-0000-000000000021", result.getHref().get(0).toString()); |
---|
1818 | assertEquals("/api/annotations/00000000-0000-0000-0000-000000000022", result.getHref().get(1).toString()); |
---|
1819 | |
---|
1820 | } |
---|
1821 | |
---|
1822 | /** |
---|
1823 | * Updaters |
---|
1824 | */ |
---|
1825 | // public boolean updateNotebookMetadata(Number notebookID, NotebookInfo upToDateNotebookInfo) { |
---|
1826 | // Number ownerID = principalDao.getInternalIDFromURI(upToDateNotebookInfo.getOwnerRef()); |
---|
1827 | // return notebookDao.updateNotebookMetadata(notebookID, upToDateNotebookInfo.getTitle(), ownerID); |
---|
1828 | // } |
---|
1829 | @Test |
---|
1830 | public void testUpdateNotebookMetadata() throws NotInDataBaseException { |
---|
1831 | |
---|
1832 | final NotebookInfo mockNotebookInfo = new NotebookInfo(); |
---|
1833 | mockNotebookInfo.setOwnerHref("/api/principals/00000000-0000-0000-0000-000000000113"); |
---|
1834 | mockNotebookInfo.setTitle("New Title"); |
---|
1835 | |
---|
1836 | mockeryDao.checking(new Expectations() { |
---|
1837 | { |
---|
1838 | oneOf(principalDao).getInternalIDFromHref("/api/principals/00000000-0000-0000-0000-000000000113"); |
---|
1839 | will(returnValue(3)); |
---|
1840 | |
---|
1841 | oneOf(notebookDao).updateNotebookMetadata(1, "New Title", 3); |
---|
1842 | will(returnValue(true)); |
---|
1843 | } |
---|
1844 | }); |
---|
1845 | |
---|
1846 | boolean result = dbDispatcher.updateNotebookMetadata(1, mockNotebookInfo); |
---|
1847 | assertTrue(result); |
---|
1848 | } |
---|
1849 | |
---|
1850 | // |
---|
1851 | // public boolean addAnnotationToNotebook(Number notebookID, Number annotationID) { |
---|
1852 | // return notebookDao.addAnnotationToNotebook(notebookID, annotationID); |
---|
1853 | // } |
---|
1854 | @Test |
---|
1855 | public void testAddAnnotationToNotebook() { |
---|
1856 | |
---|
1857 | mockeryDao.checking(new Expectations() { |
---|
1858 | { |
---|
1859 | |
---|
1860 | oneOf(notebookDao).addAnnotationToNotebook(1, 3); |
---|
1861 | will(returnValue(true)); |
---|
1862 | } |
---|
1863 | }); |
---|
1864 | |
---|
1865 | assertTrue(dbDispatcher.addAnnotationToNotebook(1, 3)); |
---|
1866 | } |
---|
1867 | |
---|
1868 | /** |
---|
1869 | * Adders |
---|
1870 | */ |
---|
1871 | // public Number createNotebook(Notebook notebook, Number ownerID) { |
---|
1872 | // Number notebookID = notebookDao.createNotebookWithoutAccesssAndAnnotations(notebook, ownerID); |
---|
1873 | // boolean updateOwner = notebookDao.setOwner(notebookID, ownerID); |
---|
1874 | // List<Permission> accesss = notebook.getPermissions().getPermission(); |
---|
1875 | // for (Permission principalAccess : accesss) { |
---|
1876 | // Number principalID = principalDao.getInternalIDFromURI(principalAccess.getRef()); |
---|
1877 | // Access access = principalAccess.getAccess(); |
---|
1878 | // boolean updateAccesss = notebookDao.addAccessToNotebook(notebookID, principalID, access); |
---|
1879 | // } |
---|
1880 | // return notebookID; |
---|
1881 | // } |
---|
1882 | @Test |
---|
1883 | public void testCreateNotebook() throws NotInDataBaseException { |
---|
1884 | |
---|
1885 | final Notebook notebook = new Notebook(); |
---|
1886 | notebook.setOwnerRef("tmpXXX"); |
---|
1887 | notebook.setTitle("(Almost) Copy of Notebook 1"); |
---|
1888 | notebook.setId("tmpYYY"); |
---|
1889 | notebook.setHref("whatever"); |
---|
1890 | |
---|
1891 | PermissionList accesss = new PermissionList(); |
---|
1892 | Permission p1 = new Permission(); |
---|
1893 | p1.setLevel(Access.WRITE); |
---|
1894 | p1.setPrincipalHref("/api/principals/00000000-0000-0000-0000-000000000112"); |
---|
1895 | accesss.getPermission().add(p1); |
---|
1896 | Permission p2 = new Permission(); |
---|
1897 | p2.setLevel(Access.READ); |
---|
1898 | p2.setPrincipalHref("/api/principals/00000000-0000-0000-0000-000000000113"); |
---|
1899 | accesss.getPermission().add(p2); |
---|
1900 | notebook.setPermissions(accesss); |
---|
1901 | |
---|
1902 | mockeryDao.checking(new Expectations() { |
---|
1903 | { |
---|
1904 | oneOf(notebookDao).createNotebookWithoutAccesssAndAnnotations(notebook, 1); |
---|
1905 | will(returnValue(5)); |
---|
1906 | |
---|
1907 | oneOf(notebookDao).setOwner(5, 1); |
---|
1908 | will(returnValue(true)); |
---|
1909 | |
---|
1910 | oneOf(principalDao).getInternalIDFromHref("/api/principals/00000000-0000-0000-0000-000000000112"); |
---|
1911 | will(returnValue(2)); |
---|
1912 | |
---|
1913 | oneOf(principalDao).getInternalIDFromHref("/api/principals/00000000-0000-0000-0000-000000000113"); |
---|
1914 | will(returnValue(3)); |
---|
1915 | |
---|
1916 | oneOf(notebookDao).addAccessToNotebook(5, 2, Access.WRITE); |
---|
1917 | will(returnValue(true)); |
---|
1918 | |
---|
1919 | oneOf(notebookDao).addAccessToNotebook(5, 3, Access.READ); |
---|
1920 | will(returnValue(true)); |
---|
1921 | |
---|
1922 | } |
---|
1923 | }); |
---|
1924 | |
---|
1925 | Number result = dbDispatcher.createNotebook(notebook, 1); |
---|
1926 | assertEquals(5, result); |
---|
1927 | |
---|
1928 | } |
---|
1929 | |
---|
1930 | // public boolean createAnnotationInNotebook(Number notebookID, Annotation annotation, Number ownerID) { |
---|
1931 | // Number newAnnotationID = this.addPrincipalsAnnotation(ownerID, annotation); |
---|
1932 | // return notebookDao.addAnnotationToNotebook(notebookID, newAnnotationID); |
---|
1933 | // } |
---|
1934 | @Test |
---|
1935 | public void testCreateAnnotationInNotebook() throws NotInDataBaseException { |
---|
1936 | |
---|
1937 | final Annotation testAnnotation = testInstances.getAnnotationToAdd(); |
---|
1938 | |
---|
1939 | mockeryDao.checking(new Expectations() { |
---|
1940 | { |
---|
1941 | oneOf(annotationDao).addAnnotation(testAnnotation, 3); |
---|
1942 | will(returnValue(5)); // the next free number is 5 |
---|
1943 | |
---|
1944 | // expectations for addTargetsForannotation |
---|
1945 | oneOf(targetDao).getInternalIDFromHref("/api/targets/00000000-0000-0000-0000-000000000031"); |
---|
1946 | will(returnValue(1)); |
---|
1947 | |
---|
1948 | oneOf(annotationDao).addAnnotationTarget(5, 1); |
---|
1949 | will(returnValue(1)); |
---|
1950 | |
---|
1951 | oneOf(annotationDao).updateAnnotationBody(5, testAnnotation.getBody().getTextBody().getBody(), testAnnotation.getBody().getTextBody().getMimeType(), false); |
---|
1952 | will(returnValue(1)); // the DB update will be called at perform anyway, even if the body is not changed (can be optimized) |
---|
1953 | |
---|
1954 | oneOf(annotationDao).updatePublicAttribute(5, Access.WRITE); |
---|
1955 | will(returnValue(1)); |
---|
1956 | |
---|
1957 | ///////////////////////// |
---|
1958 | |
---|
1959 | oneOf(notebookDao).addAnnotationToNotebook(1, 5); |
---|
1960 | will(returnValue(true)); |
---|
1961 | } |
---|
1962 | }); |
---|
1963 | |
---|
1964 | assertTrue(dbDispatcher.createAnnotationInNotebook(1, testAnnotation, 3)); |
---|
1965 | |
---|
1966 | } |
---|
1967 | |
---|
1968 | /** |
---|
1969 | * Deleters |
---|
1970 | */ |
---|
1971 | // public boolean deleteNotebook(Number notebookID) { |
---|
1972 | // if (notebookDao.deleteAllAccesssForNotebook(notebookID) || notebookDao.deleteAllAnnotationsFromNotebook(notebookID)) { |
---|
1973 | // return notebookDao.deleteNotebook(notebookID); |
---|
1974 | // } else { |
---|
1975 | // return false; |
---|
1976 | // } |
---|
1977 | // |
---|
1978 | // } |
---|
1979 | @Test |
---|
1980 | public void testDeleteNotebook() { |
---|
1981 | |
---|
1982 | mockeryDao.checking(new Expectations() { |
---|
1983 | { |
---|
1984 | |
---|
1985 | oneOf(notebookDao).deleteAllAccesssForNotebook(1); |
---|
1986 | will(returnValue(true)); |
---|
1987 | |
---|
1988 | oneOf(notebookDao).deleteAllAnnotationsFromNotebook(1); |
---|
1989 | will(returnValue(true)); |
---|
1990 | |
---|
1991 | oneOf(notebookDao).deleteNotebook(1); |
---|
1992 | will(returnValue(true)); |
---|
1993 | } |
---|
1994 | }); |
---|
1995 | |
---|
1996 | assertTrue(dbDispatcher.deleteNotebook(1)); |
---|
1997 | } |
---|
1998 | |
---|
1999 | @Test |
---|
2000 | public void testGetAccess() { |
---|
2001 | System.out.println("test getAccess"); |
---|
2002 | |
---|
2003 | mockeryDao.checking(new Expectations() { |
---|
2004 | { |
---|
2005 | |
---|
2006 | oneOf(annotationDao).getAccess(1, 3); |
---|
2007 | will(returnValue(Access.READ)); |
---|
2008 | |
---|
2009 | oneOf(annotationDao).getPublicAttribute(1); |
---|
2010 | will(returnValue(Access.WRITE)); |
---|
2011 | |
---|
2012 | } |
---|
2013 | }); |
---|
2014 | |
---|
2015 | assertEquals(Access.WRITE, dbDispatcher.getAccess(1, 3)); |
---|
2016 | |
---|
2017 | ////// |
---|
2018 | |
---|
2019 | mockeryDao.checking(new Expectations() { |
---|
2020 | { |
---|
2021 | oneOf(annotationDao).getAccess(2, 3); |
---|
2022 | will(returnValue(Access.READ)); |
---|
2023 | |
---|
2024 | oneOf(annotationDao).getPublicAttribute(2); |
---|
2025 | will(returnValue(Access.READ)); |
---|
2026 | |
---|
2027 | } |
---|
2028 | }); |
---|
2029 | assertEquals(Access.READ, dbDispatcher.getAccess(2, 3)); |
---|
2030 | |
---|
2031 | ////// |
---|
2032 | |
---|
2033 | mockeryDao.checking(new Expectations() { |
---|
2034 | { |
---|
2035 | oneOf(annotationDao).getAccess(3, 3); |
---|
2036 | will(returnValue(Access.NONE)); |
---|
2037 | |
---|
2038 | oneOf(annotationDao).getPublicAttribute(3); |
---|
2039 | will(returnValue(Access.NONE)); |
---|
2040 | |
---|
2041 | } |
---|
2042 | }); |
---|
2043 | assertEquals(Access.NONE, dbDispatcher.getAccess(3, 3)); |
---|
2044 | |
---|
2045 | ////// |
---|
2046 | } |
---|
2047 | |
---|
2048 | @Test |
---|
2049 | public void testPublicAttribute() { |
---|
2050 | |
---|
2051 | System.out.println("test getPublicAttribute"); |
---|
2052 | mockeryDao.checking(new Expectations() { |
---|
2053 | { |
---|
2054 | oneOf(annotationDao).getPublicAttribute(2); |
---|
2055 | will(returnValue(Access.READ)); |
---|
2056 | |
---|
2057 | } |
---|
2058 | }); |
---|
2059 | assertEquals(Access.READ, dbDispatcher.getPublicAttribute(2)); |
---|
2060 | } |
---|
2061 | |
---|
2062 | // @Override |
---|
2063 | // public int updateAnnotation(Annotation annotation) throws NotInDataBaseException { |
---|
2064 | // Number annotationID = annotationDao.getInternalIDFromURI(annotation.getURI()); |
---|
2065 | // int updatedAnnotations = annotationDao.updateAnnotation(annotation, annotationID, principalDao.getInternalIDFromURI(annotation.getOwnerRef())); |
---|
2066 | // int deletedTargets = annotationDao.deleteAllAnnotationTarget(annotationID); |
---|
2067 | // int deletedPrinsipalsAccesss = annotationDao.deleteAnnotationPermissions(annotationID); |
---|
2068 | // int addedTargets = addTargets(annotation, annotationID); |
---|
2069 | // int addedPrincipalsAccesss = addPermissions(annotation.getPermissions().getPermission(), annotationID); |
---|
2070 | // int updatedPublicAttribute = annotationDao.updatePublicAttribute(annotationID, annotation.getPermissions().getPublic()); |
---|
2071 | // return updatedAnnotations; |
---|
2072 | // } |
---|
2073 | // for (TargetInfo targetInfo : targets) { |
---|
2074 | // try { |
---|
2075 | // Number targetIDRunner = targetDao.getInternalIDFromURI(targetInfo.getRef()); |
---|
2076 | // int affectedRows = annotationDao.addAnnotationTarget(annotationID, targetIDRunner); |
---|
2077 | // } catch (NotInDataBaseException e) { |
---|
2078 | // Target newTarget = this.createFreshTarget(targetInfo); |
---|
2079 | // Number targetID = targetDao.addTarget(newTarget); |
---|
2080 | // String targetTemporaryID = targetDao.stringURItoExternalID(targetInfo.getRef()); |
---|
2081 | // result.put(targetTemporaryID, targetDao.getExternalID(targetID).toString()); |
---|
2082 | // int affectedRows = annotationDao.addAnnotationTarget(annotationID, targetID); |
---|
2083 | // } |
---|
2084 | // } |
---|
2085 | @Test |
---|
2086 | public void testUpdateAnnotation() throws NotInDataBaseException { |
---|
2087 | |
---|
2088 | System.out.println("test updateAnnotation"); |
---|
2089 | |
---|
2090 | final Annotation annotation = (new TestInstances("/api")).getAnnotationOne(); |
---|
2091 | final NotInDataBaseException e = new NotInDataBaseException("annotation", "external ID", "00000000-0000-0000-0000-000000000031"); |
---|
2092 | final String mockTempID = "00000000-0000-0000-0000-000000000031"; |
---|
2093 | final UUID mockNewID = Helpers.generateUUID(); |
---|
2094 | final PermissionList permissions = annotation.getPermissions(); |
---|
2095 | |
---|
2096 | |
---|
2097 | System.out.println("test updateAnnotation"); |
---|
2098 | mockeryDao.checking(new Expectations() { |
---|
2099 | { |
---|
2100 | oneOf(annotationDao).getInternalID(UUID.fromString(annotation.getId())); |
---|
2101 | will(returnValue(1)); |
---|
2102 | |
---|
2103 | oneOf(principalDao).getInternalIDFromHref(annotation.getOwnerHref()); |
---|
2104 | will(returnValue(1)); |
---|
2105 | |
---|
2106 | oneOf(annotationDao).updateAnnotation(annotation, 1, 1); |
---|
2107 | will(returnValue(1)); |
---|
2108 | |
---|
2109 | oneOf(annotationDao).deleteAllAnnotationTarget(1); |
---|
2110 | will(returnValue(1)); |
---|
2111 | |
---|
2112 | oneOf(annotationDao).deleteAnnotationPermissions(1); |
---|
2113 | will(returnValue(3)); |
---|
2114 | |
---|
2115 | |
---|
2116 | /// adding the first target, not found in the DB |
---|
2117 | |
---|
2118 | oneOf(targetDao).getInternalIDFromHref(annotation.getTargets().getTargetInfo().get(0).getHref()); |
---|
2119 | will(throwException(e)); |
---|
2120 | |
---|
2121 | oneOf(targetDao).addTarget(with(aNonNull(Target.class))); |
---|
2122 | will(returnValue(8)); |
---|
2123 | |
---|
2124 | oneOf(targetDao).getHrefFromInternalID(8); |
---|
2125 | will(returnValue("/api/targets/"+mockNewID.toString())); |
---|
2126 | |
---|
2127 | oneOf(annotationDao).addAnnotationTarget(1, 8); |
---|
2128 | will(returnValue(1)); |
---|
2129 | |
---|
2130 | ///////// |
---|
2131 | oneOf(targetDao).getInternalIDFromHref(annotation.getTargets().getTargetInfo().get(1).getHref()); |
---|
2132 | will(returnValue(2)); |
---|
2133 | |
---|
2134 | oneOf(annotationDao).addAnnotationTarget(1, 2); |
---|
2135 | will(returnValue(1)); |
---|
2136 | |
---|
2137 | ///// |
---|
2138 | |
---|
2139 | oneOf(principalDao).getPrincipalInternalIDFromRemoteID("userello"); |
---|
2140 | will(returnValue(1)); |
---|
2141 | |
---|
2142 | ///// |
---|
2143 | oneOf(principalDao).getInternalIDFromHref(permissions.getPermission().get(0).getPrincipalHref()); |
---|
2144 | will(returnValue(2)); |
---|
2145 | |
---|
2146 | oneOf(annotationDao).addAnnotationPrincipalAccess(1, 2, Access.WRITE); |
---|
2147 | will(returnValue(1)); |
---|
2148 | |
---|
2149 | oneOf(principalDao).getInternalIDFromHref(permissions.getPermission().get(1).getPrincipalHref()); |
---|
2150 | will(returnValue(3)); |
---|
2151 | |
---|
2152 | oneOf(annotationDao).addAnnotationPrincipalAccess(1, 3, Access.READ); |
---|
2153 | will(returnValue(1)); |
---|
2154 | |
---|
2155 | |
---|
2156 | //// |
---|
2157 | |
---|
2158 | oneOf(annotationDao).updateAnnotationBody(1, annotation.getBody().getTextBody().getBody(), "text/html", false); |
---|
2159 | will(returnValue(1)); |
---|
2160 | |
---|
2161 | /// |
---|
2162 | |
---|
2163 | oneOf(annotationDao).updatePublicAttribute(1, permissions.getPublic()); |
---|
2164 | will(returnValue(1)); |
---|
2165 | |
---|
2166 | |
---|
2167 | } |
---|
2168 | }); |
---|
2169 | assertEquals(1, dbDispatcher.updateAnnotation(annotation, "userello")); |
---|
2170 | } |
---|
2171 | |
---|
2172 | @Test |
---|
2173 | public void testUpdateHeadline() throws NotInDataBaseException { |
---|
2174 | |
---|
2175 | System.out.println("test updateAnnotationHeadline "); |
---|
2176 | mockeryDao.checking(new Expectations() { |
---|
2177 | { oneOf(annotationDao).updateAnnotationHeadline(1, "new Headline"); |
---|
2178 | will(returnValue(1)); |
---|
2179 | |
---|
2180 | |
---|
2181 | } |
---|
2182 | }); |
---|
2183 | assertEquals(1, dbDispatcher.updateAnnotationHeadline(1, "new Headline")); |
---|
2184 | } |
---|
2185 | |
---|
2186 | // public int updateAnnotationPrincipalAccess(Number annotationID, Number principalID, Access access) { |
---|
2187 | // int result; |
---|
2188 | // Access currentAccess = annotationDao.getAccess(annotationID, principalID); |
---|
2189 | // if (currentAccess != Access.NONE) { |
---|
2190 | // result = annotationDao.updateAnnotationPrincipalAccess(annotationID, principalID, access); |
---|
2191 | // } else { |
---|
2192 | // if (!access.equals(Access.NONE)) { |
---|
2193 | // result = annotationDao.deleteAnnotationPrincipalAccess(annotationID, principalID); |
---|
2194 | // result = annotationDao.addAnnotationPrincipalAccess(annotationID, principalID, access); |
---|
2195 | // } else { |
---|
2196 | // result = 0; |
---|
2197 | // } |
---|
2198 | // } |
---|
2199 | // return result; |
---|
2200 | // } |
---|
2201 | @Test |
---|
2202 | public void testUpdateAnnotationPrinciaplAccess() { |
---|
2203 | System.out.println("test updateAnnotationPrincipalAccess"); |
---|
2204 | mockeryDao.checking(new Expectations() { |
---|
2205 | { |
---|
2206 | oneOf(annotationDao).getAccess(1, 2); |
---|
2207 | will(returnValue(Access.WRITE)); |
---|
2208 | |
---|
2209 | oneOf(annotationDao).updateAnnotationPrincipalAccess(1, 2, Access.READ); |
---|
2210 | will(returnValue(1)); |
---|
2211 | |
---|
2212 | oneOf(annotationDao).getAccess(1, 4); |
---|
2213 | will(returnValue(null)); |
---|
2214 | |
---|
2215 | oneOf(annotationDao).addAnnotationPrincipalAccess(1, 4, Access.WRITE); |
---|
2216 | will(returnValue(1)); |
---|
2217 | |
---|
2218 | } |
---|
2219 | }); |
---|
2220 | |
---|
2221 | assertEquals(1, dbDispatcher.updateAnnotationPrincipalAccess(1, 2, Access.READ)); |
---|
2222 | assertEquals(1, dbDispatcher.updateAnnotationPrincipalAccess(1, 4, Access.WRITE)); |
---|
2223 | } |
---|
2224 | |
---|
2225 | @Test |
---|
2226 | public void testUpdatePermissions() throws NotInDataBaseException { |
---|
2227 | System.out.println("test updatePermissions"); |
---|
2228 | |
---|
2229 | final PermissionList permissions = new PermissionList(); |
---|
2230 | |
---|
2231 | Permission permission2 = new Permission(); |
---|
2232 | permission2.setPrincipalHref("/api/principals/ref2"); |
---|
2233 | permission2.setLevel(Access.WRITE); |
---|
2234 | |
---|
2235 | Permission permission3 = new Permission(); |
---|
2236 | permission3.setPrincipalHref("/api/principals/ref3"); |
---|
2237 | permission3.setLevel(Access.READ); |
---|
2238 | |
---|
2239 | Permission permission4 = new Permission(); |
---|
2240 | permission4.setLevel(Access.READ); |
---|
2241 | permission4.setPrincipalHref("/api/principals/ref4"); |
---|
2242 | |
---|
2243 | permissions.getPermission().add(permission2); |
---|
2244 | permissions.getPermission().add(permission3); |
---|
2245 | permissions.getPermission().add(permission4); |
---|
2246 | permissions.setPublic(Access.WRITE); |
---|
2247 | |
---|
2248 | mockeryDao.checking(new Expectations() { |
---|
2249 | { |
---|
2250 | ///// |
---|
2251 | oneOf(annotationDao).updatePublicAttribute(1, permissions.getPublic()); |
---|
2252 | will(returnValue(1)); |
---|
2253 | |
---|
2254 | oneOf(principalDao).getInternalIDFromHref(permissions.getPermission().get(0).getPrincipalHref()); |
---|
2255 | will(returnValue(2)); |
---|
2256 | |
---|
2257 | oneOf(annotationDao).getAccess(1, 2); |
---|
2258 | will(returnValue(Access.WRITE)); |
---|
2259 | |
---|
2260 | oneOf(principalDao).getInternalIDFromHref(permissions.getPermission().get(1).getPrincipalHref()); |
---|
2261 | will(returnValue(3)); |
---|
2262 | |
---|
2263 | oneOf(annotationDao).getAccess(1, 3); |
---|
2264 | will(returnValue(Access.WRITE)); |
---|
2265 | |
---|
2266 | oneOf(principalDao).getInternalIDFromHref(permissions.getPermission().get(2).getPrincipalHref()); |
---|
2267 | will(returnValue(4)); |
---|
2268 | |
---|
2269 | oneOf(annotationDao).getAccess(1, 4); |
---|
2270 | will(returnValue(null)); |
---|
2271 | |
---|
2272 | oneOf(annotationDao).updateAnnotationPrincipalAccess(1, 3, Access.READ); |
---|
2273 | will(returnValue(1)); |
---|
2274 | |
---|
2275 | oneOf(annotationDao).addAnnotationPrincipalAccess(1, 4, Access.READ); |
---|
2276 | will(returnValue(1)); |
---|
2277 | |
---|
2278 | } |
---|
2279 | }); |
---|
2280 | |
---|
2281 | assertEquals(2, dbDispatcher.updatePermissions(1, permissions)); |
---|
2282 | |
---|
2283 | } |
---|
2284 | |
---|
2285 | |
---|
2286 | |
---|
2287 | @Test |
---|
2288 | public void testUpdatePublicAttribute(){ |
---|
2289 | System.out.println("test updatePublicAttribute"); |
---|
2290 | |
---|
2291 | |
---|
2292 | mockeryDao.checking(new Expectations() { |
---|
2293 | { |
---|
2294 | ///// |
---|
2295 | oneOf(annotationDao).updatePublicAttribute(1, Access.NONE); |
---|
2296 | will(returnValue(1)); |
---|
2297 | |
---|
2298 | |
---|
2299 | } |
---|
2300 | }); |
---|
2301 | |
---|
2302 | assertEquals(1, dbDispatcher.updatePublicAttribute(1, Access.NONE)); |
---|
2303 | |
---|
2304 | } |
---|
2305 | } |
---|