Changeset 4521
- Timestamp:
- 02/14/14 12:54:43 (10 years ago)
- Location:
- DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/DBIntegrityServiceImlp.java
r4495 r4521 499 499 500 500 int offset = (startAnnotation > 0) ? startAnnotation - 1 : 0; 501 String direction = desc ? " DESC " : " ASC";501 String direction = desc ? "DESC" : "ASC"; 502 502 List<Number> selectedAnnotIDs = annotationDao.sublistOrderedAnnotationIDs(annotationIDs, offset, maximumAnnotations, orderedBy, direction); 503 503 List<UUID> annotationUUIDs = new ArrayList<UUID>(); … … 641 641 return annotationDao.addAnnotationPrincipalPermission(annotationID, userID, permission); 642 642 } 643 643 644 644 //////////// notebooks ////// 645 646 645 @Override 647 646 public Number createNotebook(Notebook notebook, Number ownerID) { … … 719 718 return result; 720 719 } 721 720 722 721 @Override 723 722 public boolean deleteNotebook(Number notebookID) { 724 boolean deletePermissions = notebookDao.deleteAllPermissionsForNotebook(notebookID); 725 boolean deleteAnnotations = notebookDao.deleteAllAnnotationsFromNotebook(notebookID); 726 return notebookDao.deleteNotebook(notebookID); 727 } 728 729 ////////////// HELPERS //////////////////// 730 private Target createFreshTarget(TargetInfo targetInfo) { 723 if (notebookDao.deleteAllPermissionsForNotebook(notebookID) || notebookDao.deleteAllAnnotationsFromNotebook(notebookID)) { 724 return notebookDao.deleteNotebook(notebookID); 725 } else { 726 return false; 727 } 728 } 729 730 ////////////// HELPERS //////////////////// 731 private Target createFreshTarget(TargetInfo targetInfo) { 731 732 Target target = new Target(); 732 733 target.setLink(targetInfo.getLink()); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java
r4506 r4521 221 221 StringBuilder query = new StringBuilder("SELECT DISTINCT "); 222 222 query.append(annotation_id).append(" FROM ").append(annotationsTargetsTableName).append(" WHERE ").append(annotation_id).append(" IN "); 223 query.append(values).append(" ORDER BY ").append(orderedBy) ;223 query.append(values).append(" ORDER BY ").append(orderedBy).append(" ").append(direction).append(" "); 224 224 225 225 if (limit > -1) { -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/DBIntegrityServiceTest.java
r4495 r4521 31 31 import eu.dasish.annotation.schema.AnnotationInfoList; 32 32 import eu.dasish.annotation.schema.CachedRepresentationInfo; 33 import eu.dasish.annotation.schema.Notebook; 34 import eu.dasish.annotation.schema.NotebookInfo; 35 import eu.dasish.annotation.schema.NotebookInfoList; 33 36 import eu.dasish.annotation.schema.Permission; 34 37 import eu.dasish.annotation.schema.ReferenceList; … … 36 39 import eu.dasish.annotation.schema.TargetInfo; 37 40 import eu.dasish.annotation.schema.User; 41 import eu.dasish.annotation.schema.UserWithPermission; 42 import eu.dasish.annotation.schema.UserWithPermissionList; 38 43 import java.io.ByteArrayInputStream; 39 44 import java.sql.SQLException; … … 62 67 @RunWith(SpringJUnit4ClassRunner.class) 63 68 @ContextConfiguration({"/spring-test-config/dataSource.xml", "/spring-test-config/mockeryDao.xml", "/spring-test-config/mockAnnotationDao.xml", 64 "/spring-test-config/mockUserDao.xml", "/spring-test-config/mockTargetDao.xml", "/spring-test-config/mockCachedRepresentationDao.xml", 69 "/spring-test-config/mockUserDao.xml", "/spring-test-config/mockTargetDao.xml", "/spring-test-config/mockCachedRepresentationDao.xml", 65 70 "/spring-test-config/mockNotebookDao.xml", 66 71 "/spring-config/dbIntegrityService.xml"}) … … 74 79 private UserDao userDao; 75 80 @Autowired 76 private CachedRepresentationDao cachedRepresentationDao; 81 private CachedRepresentationDao cachedRepresentationDao; 77 82 @Autowired 78 83 private TargetDao targetDao; … … 81 86 @Autowired 82 87 private NotebookDao notebookDao; 83 84 88 TestInstances testInstances = new TestInstances(TestBackendConstants._TEST_SERVLET_URI); 85 89 … … 93 97 */ 94 98 @Test 95 96 99 public void testGetAnnotationInternalIdentifier() { 97 100 System.out.println("getAnnotationInternalIdentifier"); … … 112 115 */ 113 116 @Test 114 115 117 public void testGetAnnotationExternalIdentifier() { 116 118 System.out.println("getAnnotationExternalIdentifier"); … … 131 133 */ 132 134 @Test 133 134 135 public void testGetUserInternalIdentifier() { 135 136 System.out.println("getUserInternalIdentifier"); … … 151 152 */ 152 153 @Test 153 154 154 public void testGetUserExternalIdentifier() { 155 155 System.out.println("getUserExternalIdentifier"); … … 168 168 * Test of getAnnotation method, of class DBIntegrityServiceImlp. 169 169 */ 170 @Test 170 @Test 171 171 public void testGetAnnotation() throws Exception { 172 172 System.out.println("test getAnnotation"); 173 173 174 174 final Annotation mockAnnotation = new Annotation();// corresponds to the annotation # 1 175 mockAnnotation.setURI(TestBackendConstants._TEST_SERVLET_URI_annotations + "00000000-0000-0000-0000-000000000021");175 mockAnnotation.setURI(TestBackendConstants._TEST_SERVLET_URI_annotations + "00000000-0000-0000-0000-000000000021"); 176 176 mockAnnotation.setHeadline("Sagrada Famiglia"); 177 177 XMLGregorianCalendar mockTimeStamp = DatatypeFactory.newInstance().newXMLGregorianCalendar("2013-08-12T09:25:00.383000Z"); 178 178 mockAnnotation.setLastModified(mockTimeStamp); 179 mockAnnotation.setOwnerRef(TestBackendConstants._TEST_SERVLET_URI_annotations + "00000000-0000-0000-0000-000000000111");179 mockAnnotation.setOwnerRef(TestBackendConstants._TEST_SERVLET_URI_annotations + "00000000-0000-0000-0000-000000000111"); 180 180 181 181 AnnotationBody mockBody = new AnnotationBody(); … … 194 194 final Target mockTargetOne = new Target(); 195 195 mockTargetOne.setLink("http://nl.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia"); 196 mockTargetOne.setURI(TestBackendConstants._TEST_SERVLET_URI_Targets + "00000000-0000-0000-0000-000000000031");196 mockTargetOne.setURI(TestBackendConstants._TEST_SERVLET_URI_Targets + "00000000-0000-0000-0000-000000000031"); 197 197 mockTargetOne.setVersion("version 1.0"); 198 198 199 199 final Target mockTargetTwo = new Target(); 200 200 mockTargetTwo.setLink("http://nl.wikipedia.org/wiki/Antoni_Gaud%C3%AD"); 201 mockTargetTwo.setURI(TestBackendConstants._TEST_SERVLET_URI_Targets + "00000000-0000-0000-0000-000000000032");201 mockTargetTwo.setURI(TestBackendConstants._TEST_SERVLET_URI_Targets + "00000000-0000-0000-0000-000000000032"); 202 202 mockTargetTwo.setVersion("version 1.1"); 203 203 … … 210 210 listMap.add(map3); 211 211 212 final String uri1 = TestBackendConstants._TEST_SERVLET_URI_users + "00000000-0000-0000-0000-000000000111";213 final String uri2 = TestBackendConstants._TEST_SERVLET_URI_users + "00000000-0000-0000-0000-000000000112";214 final String uri3 = TestBackendConstants._TEST_SERVLET_URI_users + "00000000-0000-0000-0000-000000000113";215 216 212 final String uri1 = TestBackendConstants._TEST_SERVLET_URI_users + "00000000-0000-0000-0000-000000000111"; 213 final String uri2 = TestBackendConstants._TEST_SERVLET_URI_users + "00000000-0000-0000-0000-000000000112"; 214 final String uri3 = TestBackendConstants._TEST_SERVLET_URI_users + "00000000-0000-0000-0000-000000000113"; 215 216 217 217 mockeryDao.checking(new Expectations() { 218 218 { 219 219 oneOf(annotationDao).getAnnotationWithoutTargetsAndPermissions(1); 220 220 will(returnValue(mockAnnotation)); 221 221 222 222 oneOf(annotationDao).getOwner(1); 223 223 will(returnValue(1)); … … 225 225 oneOf(userDao).getURIFromInternalID(1); 226 226 will(returnValue(uri1)); 227 227 228 228 oneOf(annotationDao).retrieveTargetIDs(1); 229 229 will(returnValue(mockTargetIDs)); … … 249 249 250 250 Annotation result = dbIntegrityService.getAnnotation(1); 251 assertEquals(TestBackendConstants._TEST_SERVLET_URI_annotations +"00000000-0000-0000-0000-000000000021", result.getURI());251 assertEquals(TestBackendConstants._TEST_SERVLET_URI_annotations + "00000000-0000-0000-0000-000000000021", result.getURI()); 252 252 assertEquals("text/plain", result.getBody().getTextBody().getMimeType()); 253 253 assertEquals("<html><body>some html 1</body></html>", result.getBody().getTextBody().getBody()); 254 254 assertEquals("Sagrada Famiglia", result.getHeadline()); 255 255 assertEquals("2013-08-12T09:25:00.383000Z", result.getLastModified().toString()); 256 assertEquals(TestBackendConstants._TEST_SERVLET_URI_users +"00000000-0000-0000-0000-000000000111", result.getOwnerRef());256 assertEquals(TestBackendConstants._TEST_SERVLET_URI_users + "00000000-0000-0000-0000-000000000111", result.getOwnerRef()); 257 257 258 258 assertEquals(mockTargetOne.getLink(), result.getTargets().getTargetInfo().get(0).getLink()); … … 273 273 * Test of getFilteredAnnotationIDs method, of class DBIntegrityServiceImlp. 274 274 */ 275 @Test 275 @Test 276 276 public void testGetFilteredAnnotationIDs() { 277 277 System.out.println("test getFilteredAnnotationIDs"); … … 283 283 final List<Number> mockAnnotationIDs1 = new ArrayList<Number>(); 284 284 mockAnnotationIDs1.add(1); 285 285 286 286 final List<Number> mockAnnotationIDs2 = new ArrayList<Number>(); 287 287 mockAnnotationIDs2.add(1); 288 288 mockAnnotationIDs2.add(2); 289 289 290 290 final String after = (new Timestamp(0)).toString(); 291 291 final String before = (new Timestamp(System.currentTimeMillis())).toString(); … … 293 293 final List<Number> mockRetval = new ArrayList<Number>(); 294 294 mockRetval.add(1); 295 296 295 296 297 297 mockeryDao.checking(new Expectations() { 298 298 { 299 299 oneOf(targetDao).getTargetsReferringTo("nl.wikipedia.org"); 300 300 will(returnValue(mockTargetIDs)); 301 301 302 302 oneOf(annotationDao).getAnnotationIDsForTargets(mockTargetIDs); 303 will(returnValue(mockAnnotationIDs2)); 304 303 will(returnValue(mockAnnotationIDs2)); 304 305 305 oneOf(annotationDao).getFilteredAnnotationIDs(null, "some html 1", null, after, before); 306 306 will(returnValue(mockAnnotationIDs1)); … … 309 309 will(returnValue(mockAnnotationIDs1)); 310 310 311 311 312 312 313 313 } … … 321 321 322 322 @Test 323 324 public void testGetAnnotationTargets() throws SQLException{ 323 public void testGetAnnotationTargets() throws SQLException { 325 324 System.out.println("test getAnnotationTargets"); 326 325 final List<Number> TargetIDs = new ArrayList<Number>(); … … 333 332 334 333 oneOf(targetDao).getURIFromInternalID(1); 335 will(returnValue(TestBackendConstants._TEST_SERVLET_URI_Targets +"00000000-0000-0000-0000-000000000031"));334 will(returnValue(TestBackendConstants._TEST_SERVLET_URI_Targets + "00000000-0000-0000-0000-000000000031")); 336 335 337 336 oneOf(targetDao).getURIFromInternalID(2); 338 will(returnValue(TestBackendConstants._TEST_SERVLET_URI_Targets +"00000000-0000-0000-0000-000000000032"));339 340 } 341 }); 342 337 will(returnValue(TestBackendConstants._TEST_SERVLET_URI_Targets + "00000000-0000-0000-0000-000000000032")); 338 339 } 340 }); 341 343 342 ReferenceList result = dbIntegrityService.getAnnotationTargets(1); 344 343 assertEquals(2, result.getRef().size()); 345 assertEquals(TestBackendConstants._TEST_SERVLET_URI_Targets+"00000000-0000-0000-0000-000000000031", result.getRef().get(0)); 346 assertEquals(TestBackendConstants._TEST_SERVLET_URI_Targets+"00000000-0000-0000-0000-000000000032", result.getRef().get(1)); 347 348 } 349 350 344 assertEquals(TestBackendConstants._TEST_SERVLET_URI_Targets + "00000000-0000-0000-0000-000000000031", result.getRef().get(0)); 345 assertEquals(TestBackendConstants._TEST_SERVLET_URI_Targets + "00000000-0000-0000-0000-000000000032", result.getRef().get(1)); 346 347 } 348 351 349 // @Override 352 350 // public AnnotationInfoList getFilteredAnnotationInfos(String link, String text, String access, String namespace, UUID … … 354 352 // List<Number> annotationIDs = getFilteredAnnotationIDs(link, text, access, namespace, owner, after, before); 355 353 // List<AnnotationInfo> listAnnotationInfo = annotationDao.getAnnotationInfos(annotationIDs); 356 // AnnotationInfoList result = new AnnotationInfoList();357 // result.getAnnotation().addAll(listAnnotationInfo);358 // return result;354 // AnnotationInfoList result = new AnnotationInfoList(); 355 // result.getAnnotation().addAll(listAnnotationInfo); 356 // return result; 359 357 // } 360 361 @Test 362 public void testGetFilteredAnnotationInfos() throws SQLException{ 358 @Test 359 public void testGetFilteredAnnotationInfos() throws SQLException { 363 360 System.out.println("test getetFilteredAnnotationInfos"); 364 361 365 362 final List<Number> mockTargetIDs = new ArrayList<Number>(); 366 363 mockTargetIDs.add(1); … … 369 366 final List<Number> mockAnnotationIDs1 = new ArrayList<Number>(); 370 367 mockAnnotationIDs1.add(1); 371 368 372 369 final List<Number> mockAnnotationIDs2 = new ArrayList<Number>(); 373 370 mockAnnotationIDs2.add(1); … … 380 377 final List<Number> mockAnnotIDs = new ArrayList<Number>(); 381 378 mockAnnotIDs.add(1); 382 379 383 380 final AnnotationInfo mockAnnotInfo = new AnnotationInfo(); 384 385 mockAnnotInfo.setHeadline("Sagrada Famiglia"); 381 382 mockAnnotInfo.setHeadline("Sagrada Famiglia"); 386 383 mockAnnotInfo.setRef(TestBackendConstants._TEST_SERVLET_URI_annotations + "00000000-0000-0000-0000-000000000021"); 387 mockAnnotInfo.setOwnerRef(TestBackendConstants._TEST_SERVLET_URI_users + "00000000-0000-0000-0000-000000000111");388 384 mockAnnotInfo.setOwnerRef(TestBackendConstants._TEST_SERVLET_URI_users + "00000000-0000-0000-0000-000000000111"); 385 389 386 final List<Number> targetIDs = new ArrayList<Number>(); 390 387 targetIDs.add(1); 391 388 targetIDs.add(2); 392 393 394 395 mockeryDao.checking(new Expectations() { 396 { 397 oneOf(userDao).getInternalID(ownerUUID); 398 will(returnValue(1)); 399 389 390 391 392 mockeryDao.checking(new Expectations() { 393 { 394 oneOf(userDao).getInternalID(ownerUUID); 395 will(returnValue(1)); 396 400 397 oneOf(targetDao).getTargetsReferringTo("nl.wikipedia.org"); 401 398 will(returnValue(mockTargetIDs)); 402 399 403 400 oneOf(annotationDao).getAnnotationIDsForTargets(mockTargetIDs); 404 will(returnValue(mockAnnotationIDs2)); 405 401 will(returnValue(mockAnnotationIDs2)); 402 406 403 oneOf(annotationDao).getFilteredAnnotationIDs(1, "some html 1", null, after, before); 407 404 will(returnValue(mockAnnotationIDs1)); … … 410 407 will(returnValue(mockAnnotationIDs1)); 411 408 412 409 413 410 // /////////////////////////////////// 414 411 // 415 412 oneOf(annotationDao).getAnnotationInfoWithoutTargets(1); 416 413 will(returnValue(mockAnnotInfo)); 417 414 418 415 oneOf(annotationDao).getOwner(1); 419 416 will(returnValue(1)); 420 417 421 418 oneOf(userDao).getURIFromInternalID(1); 422 will(returnValue(TestBackendConstants._TEST_SERVLET_URI_users +"00000000-0000-0000-0000-000000000111"));423 419 will(returnValue(TestBackendConstants._TEST_SERVLET_URI_users + "00000000-0000-0000-0000-000000000111")); 420 424 421 //// 425 422 oneOf(annotationDao).retrieveTargetIDs(1); 426 423 will(returnValue(targetIDs)); 427 424 428 425 oneOf(targetDao).getURIFromInternalID(1); 429 will(returnValue(TestBackendConstants._TEST_SERVLET_URI_Targets + "00000000-0000-0000-0000-000000000031"));430 431 426 will(returnValue(TestBackendConstants._TEST_SERVLET_URI_Targets + "00000000-0000-0000-0000-000000000031")); 427 428 432 429 oneOf(targetDao).getURIFromInternalID(2); 433 will(returnValue(TestBackendConstants._TEST_SERVLET_URI_Targets + "00000000-0000-0000-0000-000000000032"));434 435 436 } 437 }); 438 439 430 will(returnValue(TestBackendConstants._TEST_SERVLET_URI_Targets + "00000000-0000-0000-0000-000000000032")); 431 432 433 } 434 }); 435 436 440 437 AnnotationInfoList result = dbIntegrityService.getFilteredAnnotationInfos(ownerUUID, "nl.wikipedia.org", "some html 1", 3, "reader", null, after, before); 441 assertEquals(1, result.getAnnotationInfo().size()); 438 assertEquals(1, result.getAnnotationInfo().size()); 442 439 AnnotationInfo resultAnnotInfo = result.getAnnotationInfo().get(0); 443 440 assertEquals(mockAnnotInfo.getHeadline(), resultAnnotInfo.getHeadline()); 444 441 assertEquals(mockAnnotInfo.getRef(), resultAnnotInfo.getRef()); 445 442 assertEquals(mockAnnotInfo.getOwnerRef(), resultAnnotInfo.getOwnerRef()); 446 assertEquals(mockAnnotInfo.getRef(), result.getAnnotationInfo().get(0).getRef());447 assertEquals(TestBackendConstants._TEST_SERVLET_URI_Targets + "00000000-0000-0000-0000-000000000031", resultAnnotInfo.getTargets().getRef().get(0));448 assertEquals(TestBackendConstants._TEST_SERVLET_URI_Targets + "00000000-0000-0000-0000-000000000032", resultAnnotInfo.getTargets().getRef().get(1));449 450 } 451 452 @Test 453 public void testGetTargetsWithNoCachedRepresentation() {443 assertEquals(mockAnnotInfo.getRef(), result.getAnnotationInfo().get(0).getRef()); 444 assertEquals(TestBackendConstants._TEST_SERVLET_URI_Targets + "00000000-0000-0000-0000-000000000031", resultAnnotInfo.getTargets().getRef().get(0)); 445 assertEquals(TestBackendConstants._TEST_SERVLET_URI_Targets + "00000000-0000-0000-0000-000000000032", resultAnnotInfo.getTargets().getRef().get(1)); 446 447 } 448 449 @Test 450 public void testGetTargetsWithNoCachedRepresentation() { 454 451 System.out.println("test getTargetsWithNoCachedRepresentation"); 455 452 final List<Number> targetIDs = new ArrayList<Number>(); 456 453 targetIDs.add(5); 457 454 targetIDs.add(7); 458 455 459 456 final List<Number> cachedIDs5 = new ArrayList<Number>(); 460 457 cachedIDs5.add(7); 461 458 final List<Number> cachedIDs7 = new ArrayList<Number>(); 462 463 464 459 460 461 465 462 mockeryDao.checking(new Expectations() { 466 463 { … … 470 467 oneOf(targetDao).getCachedRepresentations(5); 471 468 will(returnValue(cachedIDs5)); 472 469 473 470 oneOf(targetDao).getCachedRepresentations(7); 474 471 will(returnValue(cachedIDs7)); 475 472 476 473 oneOf(targetDao).getURIFromInternalID(7); 477 474 will(returnValue("00000000-0000-0000-0000-000000000037")); 478 479 } 480 }); 481 475 476 } 477 }); 478 482 479 List<String> result = dbIntegrityService.getTargetsWithNoCachedRepresentation(3); 483 480 assertEquals(1, result.size()); 484 481 assertEquals("00000000-0000-0000-0000-000000000037", result.get(0)); // Target number 7 has no cached 485 482 } 486 487 483 488 484 ////////////// ADDERS ///////////////////////// 489 485 /** 490 486 * Test of addCachedForVersion method, of class DBIntegrityServiceImlp. 491 487 */ 492 @Test 488 @Test 493 489 public void testAddCached() throws SerialException, SQLException { 494 490 System.out.println("addCached"); … … 506 502 byte[] blobBytes = blobString.getBytes(); 507 503 final ByteArrayInputStream newCachedBlob = new ByteArrayInputStream(blobBytes); 508 504 509 505 mockeryDao.checking(new Expectations() { 510 506 { … … 532 528 * Test of updateSiblingTargetClassForTarget method, of class 533 529 * DBIntegrityServiceImlp. 534 * 535 **/ 536 537 530 * 531 * 532 */ 538 533 /** 539 534 * Test of addTargetsForAnnotation method, of class DBIntegrityServiceImlp. 540 535 */ 541 536 @Test 542 543 537 public void testAddTargetsForAnnotation() throws Exception { 544 538 System.out.println("test addTargetsForAnnotation"); … … 564 558 Map<String, String> result = dbIntegrityService.addTargetsForAnnotation(4, mockTargetListOne); 565 559 assertEquals(0, result.size()); 566 560 567 561 // test 2: adding a new Target 568 562 TargetInfo testTargetTwo = new TargetInfo(); … … 606 600 */ 607 601 @Test 608 609 602 public void testAddUsersAnnotation() throws Exception { 610 603 System.out.println("test addUsersAnnotation"); … … 630 623 will(returnValue(1)); // the DB update will be called at perform anyway, even if the body is not changed (can be optimized) 631 624 632 625 633 626 } 634 627 }); … … 639 632 640 633 @Test 641 642 634 public void testAddUser() { 643 635 System.out.println("test addUser"); … … 675 667 //////////////////// DELETERS //////////////// 676 668 @Test 677 678 669 public void testDeleteUser() { 679 670 System.out.println("test deleteUser"); … … 702 693 */ 703 694 @Test 704 705 public void testDeleteCachedRepresentationForTarget() throws SQLException{ 695 public void testDeleteCachedRepresentationForTarget() throws SQLException { 706 696 System.out.println("test deleteCachedRepresentationForTarget"); 707 697 mockeryDao.checking(new Expectations() { … … 724 714 ///////////////////////////////////////////// 725 715 @Test 726 727 public void testDeleteAllCachedRepresentationsOfTarget() throws SQLException{ 716 public void testDeleteAllCachedRepresentationsOfTarget() throws SQLException { 728 717 System.out.println("test deleteAllCachedRepresentationsOfTarget"); 729 718 final List<Number> cachedList = new ArrayList<Number>(); 730 719 cachedList.add(1); 731 720 cachedList.add(2); 732 721 733 722 mockeryDao.checking(new Expectations() { 734 723 { 735 724 oneOf(targetDao).getCachedRepresentations(1); 736 725 will(returnValue(cachedList)); 737 726 738 727 oneOf(targetDao).deleteTargetCachedRepresentation(1, 1); 739 728 will(returnValue(1)); 740 729 741 730 oneOf(cachedRepresentationDao).deleteCachedRepresentation(1); 742 731 will(returnValue(1)); 743 732 744 733 oneOf(targetDao).deleteTargetCachedRepresentation(1, 2); 745 734 will(returnValue(1)); 746 747 748 735 736 oneOf(cachedRepresentationDao).deleteCachedRepresentation(2); 737 will(returnValue(1)); 749 738 750 739 } … … 756 745 } 757 746 758 759 760 747 /** 761 748 * Test of deleteAnnotationWithTargets method, of class … … 763 750 */ 764 751 @Test 765 766 752 public void testDeleteAnnotation() throws Exception { 767 753 System.out.println("deleteAnnotation "); … … 770 756 final List<Number> mockTargetIDs = new ArrayList<Number>(); 771 757 mockTargetIDs.add(2); 772 758 773 759 final List<Number> mockCachedIDs = new ArrayList<Number>(); 774 760 mockCachedIDs.add(3); … … 780 766 781 767 oneOf(annotationDao).retrieveTargetIDs(2); 782 will(returnValue(mockTargetIDs)); 783 768 will(returnValue(mockTargetIDs)); 769 784 770 oneOf(annotationDao).deleteAllAnnotationTarget(2); 785 771 will(returnValue(1)); … … 787 773 oneOf(annotationDao).deleteAnnotation(2); 788 774 will(returnValue(1)); 789 775 790 776 oneOf(targetDao).getCachedRepresentations(2); 791 777 will(returnValue(mockCachedIDs)); 792 778 793 779 oneOf(targetDao).deleteTargetCachedRepresentation(2, 3); 794 780 will(returnValue(1)); 795 781 796 782 oneOf(cachedRepresentationDao).deleteCachedRepresentation(3); 797 783 will(returnValue(1)); 798 784 799 785 oneOf(targetDao).deleteTarget(2); 800 786 will(returnValue(1)); 801 787 802 788 803 789 } 804 790 }); … … 832 818 // 833 819 // } 820 821 /** 822 * NOTEBOOKS 823 */ 824 /** 825 * Getters 826 */ 827 /// notebooks /// 828 //public NotebookInfoList getNotebooks(Number prinipalID, Permission permission); 829 // NotebookInfoList result = new NotebookInfoList(); 830 // List<Number> notebookIDs = notebookDao.getNotebookIDs(prinipalID, permission); 831 // for (Number notebookID : notebookIDs) { 832 // NotebookInfo notebookInfo = notebookDao.getNotebookInfoWithoutOwner(notebookID); 833 // Number ownerID = notebookDao.getOwner(notebookID); 834 // notebookInfo.setOwnerRef(userDao.getURIFromInternalID(ownerID)); 835 // result.getNotebookInfo().add(notebookInfo); 836 // } 837 // 838 // return result; 839 @Test 840 public void testGetNotebooks() { 841 842 final List<Number> mockNotebookIDs = new ArrayList<Number>(); 843 mockNotebookIDs.add(1); 844 845 final NotebookInfo mockNotebookInfo = new NotebookInfo(); 846 mockNotebookInfo.setRef("00000000-0000-0000-0000-000000000011"); 847 mockNotebookInfo.setTitle("Notebook 1"); 848 849 mockeryDao.checking(new Expectations() { 850 { 851 oneOf(notebookDao).getNotebookIDs(3, Permission.READER); 852 will(returnValue(mockNotebookIDs)); 853 854 oneOf(notebookDao).getNotebookInfoWithoutOwner(1); 855 will(returnValue(mockNotebookInfo)); 856 857 oneOf(notebookDao).getOwner(1); 858 will(returnValue(1)); 859 860 oneOf(userDao).getURIFromInternalID(1); 861 will(returnValue("00000000-0000-0000-0000-000000000111")); 862 863 } 864 }); 865 866 NotebookInfoList result = dbIntegrityService.getNotebooks(3, Permission.READER); 867 assertEquals("00000000-0000-0000-0000-000000000011", result.getNotebookInfo().get(0).getRef()); 868 assertEquals("00000000-0000-0000-0000-000000000111", result.getNotebookInfo().get(0).getOwnerRef()); 869 assertEquals("Notebook 1", result.getNotebookInfo().get(0).getTitle()); 870 871 } 872 873 ; 874 875 876 /*public NotebookInfoList getNotebooksOwnedBy(Number principalID){ 877 NotebookInfoList result = new NotebookInfoList(); 878 List<Number> notebookIDs = notebookDao.getNotebookIDsOwnedBy(principalID); 879 String ownerRef = userDao.getURIFromInternalID(principalID); 880 for (Number notebookID : notebookIDs) { 881 NotebookInfo notebookInfo = notebookDao.getNotebookInfoWithoutOwner(notebookID); 882 notebookInfo.setOwnerRef(ownerRef); 883 result.getNotebookInfo().add(notebookInfo); 884 } 885 886 return result; 887 }*/ 888 889 @Test 890 public void testGetNotebooksOwnedBy() { 891 892 final List<Number> mockNotebookIDs = new ArrayList<Number>(); 893 mockNotebookIDs.add(3); 894 mockNotebookIDs.add(4); 895 896 final NotebookInfo mockNotebookInfo1 = new NotebookInfo(); 897 mockNotebookInfo1.setRef("00000000-0000-0000-0000-000000000013"); 898 mockNotebookInfo1.setTitle("Notebook 3"); 899 900 final NotebookInfo mockNotebookInfo2 = new NotebookInfo(); 901 mockNotebookInfo2.setRef("00000000-0000-0000-0000-000000000014"); 902 mockNotebookInfo2.setTitle("Notebook 4"); 903 904 mockeryDao.checking(new Expectations() { 905 { 906 oneOf(notebookDao).getNotebookIDsOwnedBy(3); 907 will(returnValue(mockNotebookIDs)); 908 909 oneOf(userDao).getURIFromInternalID(3); 910 will(returnValue("00000000-0000-0000-0000-000000000113")); 911 912 oneOf(notebookDao).getNotebookInfoWithoutOwner(3); 913 will(returnValue(mockNotebookInfo1)); 914 915 oneOf(notebookDao).getNotebookInfoWithoutOwner(4); 916 will(returnValue(mockNotebookInfo2)); 917 918 } 919 }); 920 921 NotebookInfoList result = dbIntegrityService.getNotebooksOwnedBy(3); 922 assertEquals("00000000-0000-0000-0000-000000000013", result.getNotebookInfo().get(0).getRef()); 923 assertEquals("00000000-0000-0000-0000-000000000113", result.getNotebookInfo().get(0).getOwnerRef()); 924 assertEquals("Notebook 3", result.getNotebookInfo().get(0).getTitle()); 925 assertEquals("00000000-0000-0000-0000-000000000014", result.getNotebookInfo().get(1).getRef()); 926 assertEquals("00000000-0000-0000-0000-000000000113", result.getNotebookInfo().get(1).getOwnerRef()); 927 assertEquals("Notebook 4", result.getNotebookInfo().get(1).getTitle()); 928 929 } 930 931 ; 932 933 934 /* 935 public List<UUID> getPrincipals(Number notebookID, Permission permission) { 936 List<UUID> result = new ArrayList<UUID>(); 937 List<Number> principalIDs = notebookDao.getPrincipalIDsWithPermission(notebookID, permission); 938 for (Number principalID : principalIDs) { 939 UUID uuid = userDao.getExternalID(principalID); 940 result.add(uuid); 941 } 942 return result; 943 }*/ 944 945 @Test 946 public void testGetPrincipals() { 947 final List<Number> mockPrincipalIDs = new ArrayList<Number>(); 948 mockPrincipalIDs.add(2); 949 mockPrincipalIDs.add(4); 950 951 final NotebookInfo mockNotebookInfo = new NotebookInfo(); 952 mockNotebookInfo.setRef("00000000-0000-0000-0000-000000000011"); 953 mockNotebookInfo.setTitle("Notebook 1"); 954 955 mockeryDao.checking(new Expectations() { 956 { 957 oneOf(notebookDao).getPrincipalIDsWithPermission(1, Permission.WRITER); 958 will(returnValue(mockPrincipalIDs)); 959 960 oneOf(userDao).getExternalID(2); 961 will(returnValue(UUID.fromString("00000000-0000-0000-0000-000000000112"))); 962 963 oneOf(userDao).getExternalID(4); 964 will(returnValue(UUID.fromString("00000000-0000-0000-0000-000000000114"))); 965 966 967 } 968 }); 969 970 List<UUID> result = dbIntegrityService.getPrincipals(1, Permission.WRITER); 971 assertEquals("00000000-0000-0000-0000-000000000112", result.get(0).toString()); 972 assertEquals("00000000-0000-0000-0000-000000000114", result.get(1).toString()); 973 974 } 975 976 977 // public NotebookInfo getNotebookInfo(Number notebookID) { 978 // NotebookInfo result = notebookDao.getNotebookInfoWithoutOwner(notebookID); 979 // result.setOwnerRef(userDao.getURIFromInternalID(notebookDao.getOwner(notebookID))); 980 // return result; 981 // } 982 983 984 @Test 985 public void testGetNotebookInfo() { 986 987 final NotebookInfo mockNotebookInfo = new NotebookInfo(); 988 mockNotebookInfo.setRef("00000000-0000-0000-0000-000000000011"); 989 mockNotebookInfo.setTitle("Notebook 1"); 990 991 mockeryDao.checking(new Expectations() { 992 { 993 oneOf(notebookDao).getNotebookInfoWithoutOwner(1); 994 will(returnValue(mockNotebookInfo)); 995 996 oneOf(notebookDao).getOwner(1); 997 will(returnValue(1)); 998 999 oneOf(userDao).getURIFromInternalID(1); 1000 will(returnValue("00000000-0000-0000-0000-000000000111")); 1001 1002 1003 } 1004 }); 1005 1006 NotebookInfo result = dbIntegrityService.getNotebookInfo(1); 1007 assertEquals("00000000-0000-0000-0000-000000000011", result.getRef()); 1008 assertEquals("00000000-0000-0000-0000-000000000111", result.getOwnerRef()); 1009 assertEquals("Notebook 1", result.getTitle()); 1010 1011 } 1012 1013 1014 // public List<UUID> getAnnotationsForNotebook(Number notebookID, int startAnnotation, int maximumAnnotations, String orderedBy, boolean desc) { 1015 // List<Number> annotationIDs = notebookDao.getAnnotations(notebookID); 1016 // 1017 // if (startAnnotation < -1) { 1018 // logger.info("Variable's startAnnotation value " + startAnnotation + " is invalid. I will return null."); 1019 // return null; 1020 // } 1021 // 1022 // if (maximumAnnotations < -1) { 1023 // logger.info("Variable's maximumAnnotations value " + maximumAnnotations + " is invalid. I will return null."); 1024 // return null; 1025 // } 1026 // 1027 // int offset = (startAnnotation > 0) ? startAnnotation - 1 : 0; 1028 // String direction = desc ? " DESC " : " ASC "; 1029 // List<Number> selectedAnnotIDs = annotationDao.sublistOrderedAnnotationIDs(annotationIDs, offset, maximumAnnotations, orderedBy, direction); 1030 // List<UUID> annotationUUIDs = new ArrayList<UUID>(); 1031 // for (Number annotationID : selectedAnnotIDs) { 1032 // annotationUUIDs.add(annotationDao.getExternalID(annotationID)); 1033 // } 1034 // return annotationUUIDs; 1035 // } 1036 1037 1038 @Test 1039 public void testAnnotationsForNotebook() { 1040 final List<Number> mockAnnotationIDs = new ArrayList<Number>(); 1041 mockAnnotationIDs.add(1); 1042 mockAnnotationIDs.add(2); 1043 1044 mockeryDao.checking(new Expectations() { 1045 { 1046 oneOf(notebookDao).getAnnotations(1); 1047 will(returnValue(mockAnnotationIDs)); 1048 1049 oneOf(annotationDao).sublistOrderedAnnotationIDs(mockAnnotationIDs, 0, 3, "last_modified", "DESC"); 1050 will(returnValue(mockAnnotationIDs)); 1051 1052 oneOf(annotationDao).getExternalID(1); 1053 will(returnValue(UUID.fromString("00000000-0000-0000-0000-000000000021"))); 1054 1055 oneOf(annotationDao).getExternalID(2); 1056 will(returnValue(UUID.fromString("00000000-0000-0000-0000-000000000022"))); 1057 1058 1059 } 1060 }); 1061 1062 List<UUID> result = dbIntegrityService.getAnnotationsForNotebook(1, -1, 3, "last_modified", true); 1063 assertEquals("00000000-0000-0000-0000-000000000021", result.get(0).toString()); 1064 assertEquals("00000000-0000-0000-0000-000000000022", result.get(1).toString()); 1065 1066 } 1067 1068 1069 /** 1070 * Updaters 1071 */ 1072 1073 // public boolean updateNotebookMetadata(Number notebookID, NotebookInfo upToDateNotebookInfo) { 1074 // Number ownerID = userDao.getInternalIDFromURI(upToDateNotebookInfo.getOwnerRef()); 1075 // return notebookDao.updateNotebookMetadata(notebookID, upToDateNotebookInfo.getTitle(), ownerID); 1076 // } 1077 1078 1079 @Test 1080 public void testUpdateNotebookMetadata() { 1081 1082 final NotebookInfo mockNotebookInfo= new NotebookInfo(); 1083 mockNotebookInfo.setOwnerRef(TestBackendConstants._TEST_SERVLET_URI_users+"00000000-0000-0000-0000-000000000113"); 1084 mockNotebookInfo.setTitle("New Title"); 1085 1086 mockeryDao.checking(new Expectations() { 1087 { 1088 oneOf(userDao).getInternalIDFromURI(TestBackendConstants._TEST_SERVLET_URI_users+"00000000-0000-0000-0000-000000000113"); 1089 will(returnValue(3)); 1090 1091 oneOf(notebookDao).updateNotebookMetadata(1, "New Title", 3); 1092 will(returnValue(true)); 1093 } 1094 }); 1095 1096 boolean result = dbIntegrityService.updateNotebookMetadata(1, mockNotebookInfo); 1097 assertTrue(result); 1098 } 1099 1100 1101 // 1102 // public boolean addAnnotationToNotebook(Number notebookID, Number annotationID) { 1103 // return notebookDao.addAnnotationToNotebook(notebookID, annotationID); 1104 // } 1105 1106 @Test 1107 public void testAddAnnotationToNotebook() { 1108 1109 mockeryDao.checking(new Expectations() { 1110 { 1111 1112 oneOf(notebookDao).addAnnotationToNotebook(1, 3); 1113 will(returnValue(true)); 1114 } 1115 }); 1116 1117 assertTrue(dbIntegrityService.addAnnotationToNotebook(1,3)); 1118 } 1119 1120 1121 /** 1122 * Adders 1123 */ 1124 1125 // public Number createNotebook(Notebook notebook, Number ownerID) { 1126 // Number notebookID = notebookDao.createNotebookWithoutPermissionsAndAnnotations(notebook, ownerID); 1127 // boolean updateOwner = notebookDao.setOwner(notebookID, ownerID); 1128 // List<UserWithPermission> permissions = notebook.getPermissions().getUserWithPermission(); 1129 // for (UserWithPermission principalPermission : permissions) { 1130 // Number principalID = userDao.getInternalIDFromURI(principalPermission.getRef()); 1131 // Permission permission = principalPermission.getPermission(); 1132 // boolean updatePermissions = notebookDao.addPermissionToNotebook(notebookID, principalID, permission); 1133 // } 1134 // return notebookID; 1135 // } 1136 1137 1138 @Test 1139 public void testCreateNotebook() { 1140 1141 final Notebook notebook = new Notebook(); 1142 notebook.setOwnerRef("tmpXXX"); 1143 notebook.setTitle("(Almost) Copy of Notebook 1"); 1144 notebook.setURI("tmpYYY"); 1145 1146 UserWithPermissionList permissions = new UserWithPermissionList(); 1147 UserWithPermission p1 = new UserWithPermission(); 1148 p1.setPermission(Permission.WRITER); 1149 p1.setRef(TestBackendConstants._TEST_SERVLET_URI_users + "00000000-0000-0000-0000-000000000112"); 1150 permissions.getUserWithPermission().add(p1); 1151 UserWithPermission p2 = new UserWithPermission(); 1152 p2.setPermission(Permission.READER); 1153 p2.setRef(TestBackendConstants._TEST_SERVLET_URI_users + "00000000-0000-0000-0000-000000000113"); 1154 permissions.getUserWithPermission().add(p2); 1155 notebook.setPermissions(permissions); 1156 1157 mockeryDao.checking(new Expectations() { 1158 { 1159 oneOf(notebookDao).createNotebookWithoutPermissionsAndAnnotations(notebook, 1); 1160 will(returnValue(5)); 1161 1162 oneOf(notebookDao).setOwner(5, 1); 1163 will(returnValue(true)); 1164 1165 oneOf(userDao).getInternalIDFromURI(TestBackendConstants._TEST_SERVLET_URI_users + "00000000-0000-0000-0000-000000000112"); 1166 will(returnValue(2)); 1167 1168 oneOf(userDao).getInternalIDFromURI(TestBackendConstants._TEST_SERVLET_URI_users + "00000000-0000-0000-0000-000000000113"); 1169 will(returnValue(3)); 1170 1171 oneOf(notebookDao).addPermissionToNotebook(5, 2, Permission.WRITER); 1172 will(returnValue(true)); 1173 1174 oneOf(notebookDao).addPermissionToNotebook(5, 3, Permission.READER); 1175 will(returnValue(true)); 1176 1177 } 1178 }); 1179 1180 Number result = dbIntegrityService.createNotebook(notebook, 1); 1181 assertEquals(5, result); 1182 1183 } 1184 1185 1186 1187 1188 // public boolean createAnnotationInNotebook(Number notebookID, Annotation annotation, Number ownerID) { 1189 // Number newAnnotationID = this.addUsersAnnotation(ownerID, annotation); 1190 // return notebookDao.addAnnotationToNotebook(notebookID, newAnnotationID); 1191 // } 1192 1193 @Test 1194 public void testCreateAnnotationInNotebook() { 1195 1196 final Annotation testAnnotation = testInstances.getAnnotationToAdd(); 1197 1198 mockeryDao.checking(new Expectations() { 1199 { 1200 oneOf(annotationDao).addAnnotation(testAnnotation, 3); 1201 will(returnValue(5)); // the next free number is 5 1202 1203 // expectations for addTargetsForannotation 1204 oneOf(targetDao).getInternalIDFromURI(TestBackendConstants._TEST_SERVLET_URI_Targets + "00000000-0000-0000-0000-000000000031"); 1205 will(returnValue(1)); 1206 1207 oneOf(annotationDao).addAnnotationTarget(5, 1); 1208 will(returnValue(1)); 1209 1210 oneOf(annotationDao).updateAnnotationBody(5, testAnnotation.getBody().getTextBody().getBody(), testAnnotation.getBody().getTextBody().getMimeType(), false); 1211 will(returnValue(1)); // the DB update will be called at perform anyway, even if the body is not changed (can be optimized) 1212 1213 ///////////////////////// 1214 1215 oneOf(notebookDao).addAnnotationToNotebook(1, 5); 1216 will(returnValue(true)); 1217 } 1218 }); 1219 1220 assertTrue(dbIntegrityService.createAnnotationInNotebook(1, testAnnotation, 3)); 1221 1222 } 1223 1224 /** 1225 * Deleters 1226 */ 1227 1228 // public boolean deleteNotebook(Number notebookID) { 1229 // if (notebookDao.deleteAllPermissionsForNotebook(notebookID) || notebookDao.deleteAllAnnotationsFromNotebook(notebookID)) { 1230 // return notebookDao.deleteNotebook(notebookID); 1231 // } else { 1232 // return false; 1233 // } 1234 // 1235 // } 1236 1237 @Test 1238 public void testDeleteNotebook() { 1239 1240 mockeryDao.checking(new Expectations() { 1241 { 1242 1243 oneOf(notebookDao).deleteAllPermissionsForNotebook(1); 1244 will(returnValue(true)); 1245 1246 oneOf(notebookDao).deleteAllAnnotationsFromNotebook(1); 1247 will(returnValue(true)); 1248 1249 oneOf(notebookDao).deleteNotebook(1); 1250 will(returnValue(true)); 1251 } 1252 }); 1253 1254 assertTrue(dbIntegrityService.deleteNotebook(1)); 1255 } 1256 834 1257 }
Note: See TracChangeset
for help on using the changeset viewer.