Changeset 4521


Ignore:
Timestamp:
02/14/14 12:54:43 (10 years ago)
Author:
olhsha
Message:

Integrity-Service tests are done (mocking NotebookDao?).

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  
    499499
    500500        int offset = (startAnnotation > 0) ? startAnnotation - 1 : 0;
    501         String direction = desc ? " DESC " : " ASC ";
     501        String direction = desc ? "DESC" : "ASC";
    502502        List<Number> selectedAnnotIDs = annotationDao.sublistOrderedAnnotationIDs(annotationIDs, offset, maximumAnnotations, orderedBy, direction);
    503503        List<UUID> annotationUUIDs = new ArrayList<UUID>();
     
    641641        return annotationDao.addAnnotationPrincipalPermission(annotationID, userID, permission);
    642642    }
    643    
     643
    644644    //////////// notebooks //////
    645 
    646645    @Override
    647646    public Number createNotebook(Notebook notebook, Number ownerID) {
     
    719718        return result;
    720719    }
    721    
     720
    722721    @Override
    723722    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 ////////////////////
     731private Target createFreshTarget(TargetInfo targetInfo) {
    731732        Target target = new Target();
    732733        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  
    221221        StringBuilder query = new StringBuilder("SELECT DISTINCT ");
    222222        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(" ");
    224224
    225225        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  
    3131import eu.dasish.annotation.schema.AnnotationInfoList;
    3232import eu.dasish.annotation.schema.CachedRepresentationInfo;
     33import eu.dasish.annotation.schema.Notebook;
     34import eu.dasish.annotation.schema.NotebookInfo;
     35import eu.dasish.annotation.schema.NotebookInfoList;
    3336import eu.dasish.annotation.schema.Permission;
    3437import eu.dasish.annotation.schema.ReferenceList;
     
    3639import eu.dasish.annotation.schema.TargetInfo;
    3740import eu.dasish.annotation.schema.User;
     41import eu.dasish.annotation.schema.UserWithPermission;
     42import eu.dasish.annotation.schema.UserWithPermissionList;
    3843import java.io.ByteArrayInputStream;
    3944import java.sql.SQLException;
     
    6267@RunWith(SpringJUnit4ClassRunner.class)
    6368@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",
    6570    "/spring-test-config/mockNotebookDao.xml",
    6671    "/spring-config/dbIntegrityService.xml"})
     
    7479    private UserDao userDao;
    7580    @Autowired
    76     private CachedRepresentationDao cachedRepresentationDao;   
     81    private CachedRepresentationDao cachedRepresentationDao;
    7782    @Autowired
    7883    private TargetDao targetDao;
     
    8186    @Autowired
    8287    private NotebookDao notebookDao;
    83    
    8488    TestInstances testInstances = new TestInstances(TestBackendConstants._TEST_SERVLET_URI);
    8589
     
    9397     */
    9498    @Test
    95    
    9699    public void testGetAnnotationInternalIdentifier() {
    97100        System.out.println("getAnnotationInternalIdentifier");
     
    112115     */
    113116    @Test
    114    
    115117    public void testGetAnnotationExternalIdentifier() {
    116118        System.out.println("getAnnotationExternalIdentifier");
     
    131133     */
    132134    @Test
    133    
    134135    public void testGetUserInternalIdentifier() {
    135136        System.out.println("getUserInternalIdentifier");
     
    151152     */
    152153    @Test
    153    
    154154    public void testGetUserExternalIdentifier() {
    155155        System.out.println("getUserExternalIdentifier");
     
    168168     * Test of getAnnotation method, of class DBIntegrityServiceImlp.
    169169     */
    170     @Test   
     170    @Test
    171171    public void testGetAnnotation() throws Exception {
    172172        System.out.println("test getAnnotation");
    173173
    174174        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");
    176176        mockAnnotation.setHeadline("Sagrada Famiglia");
    177177        XMLGregorianCalendar mockTimeStamp = DatatypeFactory.newInstance().newXMLGregorianCalendar("2013-08-12T09:25:00.383000Z");
    178178        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");
    180180
    181181        AnnotationBody mockBody = new AnnotationBody();
     
    194194        final Target mockTargetOne = new Target();
    195195        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");
    197197        mockTargetOne.setVersion("version 1.0");
    198198
    199199        final Target mockTargetTwo = new Target();
    200200        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");
    202202        mockTargetTwo.setVersion("version 1.1");
    203203
     
    210210        listMap.add(map3);
    211211
    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
    217217        mockeryDao.checking(new Expectations() {
    218218            {
    219219                oneOf(annotationDao).getAnnotationWithoutTargetsAndPermissions(1);
    220220                will(returnValue(mockAnnotation));
    221                
     221
    222222                oneOf(annotationDao).getOwner(1);
    223223                will(returnValue(1));
     
    225225                oneOf(userDao).getURIFromInternalID(1);
    226226                will(returnValue(uri1));
    227                
     227
    228228                oneOf(annotationDao).retrieveTargetIDs(1);
    229229                will(returnValue(mockTargetIDs));
     
    249249
    250250        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());
    252252        assertEquals("text/plain", result.getBody().getTextBody().getMimeType());
    253253        assertEquals("<html><body>some html 1</body></html>", result.getBody().getTextBody().getBody());
    254254        assertEquals("Sagrada Famiglia", result.getHeadline());
    255255        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());
    257257
    258258        assertEquals(mockTargetOne.getLink(), result.getTargets().getTargetInfo().get(0).getLink());
     
    273273     * Test of getFilteredAnnotationIDs method, of class DBIntegrityServiceImlp.
    274274     */
    275     @Test   
     275    @Test
    276276    public void testGetFilteredAnnotationIDs() {
    277277        System.out.println("test getFilteredAnnotationIDs");
     
    283283        final List<Number> mockAnnotationIDs1 = new ArrayList<Number>();
    284284        mockAnnotationIDs1.add(1);
    285        
     285
    286286        final List<Number> mockAnnotationIDs2 = new ArrayList<Number>();
    287287        mockAnnotationIDs2.add(1);
    288288        mockAnnotationIDs2.add(2);
    289        
     289
    290290        final String after = (new Timestamp(0)).toString();
    291291        final String before = (new Timestamp(System.currentTimeMillis())).toString();
     
    293293        final List<Number> mockRetval = new ArrayList<Number>();
    294294        mockRetval.add(1);
    295        
    296        
     295
     296
    297297        mockeryDao.checking(new Expectations() {
    298298            {
    299299                oneOf(targetDao).getTargetsReferringTo("nl.wikipedia.org");
    300300                will(returnValue(mockTargetIDs));
    301                
     301
    302302                oneOf(annotationDao).getAnnotationIDsForTargets(mockTargetIDs);
    303                 will(returnValue(mockAnnotationIDs2));               
    304                
     303                will(returnValue(mockAnnotationIDs2));
     304
    305305                oneOf(annotationDao).getFilteredAnnotationIDs(null, "some html 1", null, after, before);
    306306                will(returnValue(mockAnnotationIDs1));
     
    309309                will(returnValue(mockAnnotationIDs1));
    310310
    311                
     311
    312312
    313313            }
     
    321321
    322322    @Test
    323    
    324     public void testGetAnnotationTargets() throws SQLException{
     323    public void testGetAnnotationTargets() throws SQLException {
    325324        System.out.println("test getAnnotationTargets");
    326325        final List<Number> TargetIDs = new ArrayList<Number>();
     
    333332
    334333                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"));
    336335
    337336                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
    343342        ReferenceList result = dbIntegrityService.getAnnotationTargets(1);
    344343        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
    351349//     @Override
    352350//    public AnnotationInfoList getFilteredAnnotationInfos(String link, String text, String access, String namespace, UUID
     
    354352//        List<Number> annotationIDs = getFilteredAnnotationIDs(link, text, access, namespace, owner, after, before);
    355353//        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;
    359357//    }
    360    
    361     @Test
    362     public void testGetFilteredAnnotationInfos() throws SQLException{
     358    @Test
     359    public void testGetFilteredAnnotationInfos() throws SQLException {
    363360        System.out.println("test getetFilteredAnnotationInfos");
    364        
     361
    365362        final List<Number> mockTargetIDs = new ArrayList<Number>();
    366363        mockTargetIDs.add(1);
     
    369366        final List<Number> mockAnnotationIDs1 = new ArrayList<Number>();
    370367        mockAnnotationIDs1.add(1);
    371        
     368
    372369        final List<Number> mockAnnotationIDs2 = new ArrayList<Number>();
    373370        mockAnnotationIDs2.add(1);
     
    380377        final List<Number> mockAnnotIDs = new ArrayList<Number>();
    381378        mockAnnotIDs.add(1);
    382        
     379
    383380        final AnnotationInfo mockAnnotInfo = new AnnotationInfo();
    384        
    385         mockAnnotInfo.setHeadline("Sagrada Famiglia");       
     381
     382        mockAnnotInfo.setHeadline("Sagrada Famiglia");
    386383        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
    389386        final List<Number> targetIDs = new ArrayList<Number>();
    390387        targetIDs.add(1);
    391388        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
    400397                oneOf(targetDao).getTargetsReferringTo("nl.wikipedia.org");
    401398                will(returnValue(mockTargetIDs));
    402                
     399
    403400                oneOf(annotationDao).getAnnotationIDsForTargets(mockTargetIDs);
    404                 will(returnValue(mockAnnotationIDs2));               
    405                
     401                will(returnValue(mockAnnotationIDs2));
     402
    406403                oneOf(annotationDao).getFilteredAnnotationIDs(1, "some html 1", null, after, before);
    407404                will(returnValue(mockAnnotationIDs1));
     
    410407                will(returnValue(mockAnnotationIDs1));
    411408
    412                
     409
    413410//                ///////////////////////////////////
    414411//               
    415412                oneOf(annotationDao).getAnnotationInfoWithoutTargets(1);
    416413                will(returnValue(mockAnnotInfo));
    417                
     414
    418415                oneOf(annotationDao).getOwner(1);
    419416                will(returnValue(1));
    420                
     417
    421418                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
    424421                ////
    425422                oneOf(annotationDao).retrieveTargetIDs(1);
    426423                will(returnValue(targetIDs));
    427                
     424
    428425                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
    432429                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
    440437        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());
    442439        AnnotationInfo resultAnnotInfo = result.getAnnotationInfo().get(0);
    443440        assertEquals(mockAnnotInfo.getHeadline(), resultAnnotInfo.getHeadline());
    444441        assertEquals(mockAnnotInfo.getRef(), resultAnnotInfo.getRef());
    445442        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() {
    454451        System.out.println("test getTargetsWithNoCachedRepresentation");
    455452        final List<Number> targetIDs = new ArrayList<Number>();
    456453        targetIDs.add(5);
    457454        targetIDs.add(7);
    458        
     455
    459456        final List<Number> cachedIDs5 = new ArrayList<Number>();
    460457        cachedIDs5.add(7);
    461458        final List<Number> cachedIDs7 = new ArrayList<Number>();
    462        
    463        
    464        
     459
     460
     461
    465462        mockeryDao.checking(new Expectations() {
    466463            {
     
    470467                oneOf(targetDao).getCachedRepresentations(5);
    471468                will(returnValue(cachedIDs5));
    472                
     469
    473470                oneOf(targetDao).getCachedRepresentations(7);
    474471                will(returnValue(cachedIDs7));
    475                
     472
    476473                oneOf(targetDao).getURIFromInternalID(7);
    477474                will(returnValue("00000000-0000-0000-0000-000000000037"));
    478                
    479             }
    480         });
    481        
     475
     476            }
     477        });
     478
    482479        List<String> result = dbIntegrityService.getTargetsWithNoCachedRepresentation(3);
    483480        assertEquals(1, result.size());
    484481        assertEquals("00000000-0000-0000-0000-000000000037", result.get(0)); // Target number 7 has no cached
    485482    }
    486    
    487    
     483
    488484    ////////////// ADDERS /////////////////////////
    489485    /**
    490486     * Test of addCachedForVersion method, of class DBIntegrityServiceImlp.
    491487     */
    492     @Test   
     488    @Test
    493489    public void testAddCached() throws SerialException, SQLException {
    494490        System.out.println("addCached");
     
    506502        byte[] blobBytes = blobString.getBytes();
    507503        final ByteArrayInputStream newCachedBlob = new ByteArrayInputStream(blobBytes);
    508        
     504
    509505        mockeryDao.checking(new Expectations() {
    510506            {
     
    532528     * Test of updateSiblingTargetClassForTarget method, of class
    533529     * DBIntegrityServiceImlp.
    534      *
    535   **/
    536    
    537 
     530     *
     531     *
     532     */
    538533    /**
    539534     * Test of addTargetsForAnnotation method, of class DBIntegrityServiceImlp.
    540535     */
    541536    @Test
    542    
    543537    public void testAddTargetsForAnnotation() throws Exception {
    544538        System.out.println("test addTargetsForAnnotation");
     
    564558        Map<String, String> result = dbIntegrityService.addTargetsForAnnotation(4, mockTargetListOne);
    565559        assertEquals(0, result.size());
    566        
     560
    567561        // test 2: adding a new Target
    568562        TargetInfo testTargetTwo = new TargetInfo();
     
    606600     */
    607601    @Test
    608    
    609602    public void testAddUsersAnnotation() throws Exception {
    610603        System.out.println("test addUsersAnnotation");
     
    630623                will(returnValue(1)); // the DB update will be called at perform anyway, even if the body is not changed (can be optimized)
    631624
    632                
     625
    633626            }
    634627        });
     
    639632
    640633    @Test
    641    
    642634    public void testAddUser() {
    643635        System.out.println("test addUser");
     
    675667    //////////////////// DELETERS ////////////////
    676668    @Test
    677    
    678669    public void testDeleteUser() {
    679670        System.out.println("test deleteUser");
     
    702693     */
    703694    @Test
    704    
    705     public void testDeleteCachedRepresentationForTarget() throws SQLException{
     695    public void testDeleteCachedRepresentationForTarget() throws SQLException {
    706696        System.out.println("test deleteCachedRepresentationForTarget");
    707697        mockeryDao.checking(new Expectations() {
     
    724714    /////////////////////////////////////////////
    725715    @Test
    726    
    727     public void testDeleteAllCachedRepresentationsOfTarget() throws SQLException{
     716    public void testDeleteAllCachedRepresentationsOfTarget() throws SQLException {
    728717        System.out.println("test deleteAllCachedRepresentationsOfTarget");
    729718        final List<Number> cachedList = new ArrayList<Number>();
    730719        cachedList.add(1);
    731720        cachedList.add(2);
    732        
     721
    733722        mockeryDao.checking(new Expectations() {
    734723            {
    735724                oneOf(targetDao).getCachedRepresentations(1);
    736725                will(returnValue(cachedList));
    737                
     726
    738727                oneOf(targetDao).deleteTargetCachedRepresentation(1, 1);
    739728                will(returnValue(1));
    740                
     729
    741730                oneOf(cachedRepresentationDao).deleteCachedRepresentation(1);
    742731                will(returnValue(1));
    743                
     732
    744733                oneOf(targetDao).deleteTargetCachedRepresentation(1, 2);
    745734                will(returnValue(1));
    746                
    747                  oneOf(cachedRepresentationDao).deleteCachedRepresentation(2);
    748                  will(returnValue(1));
     735
     736                oneOf(cachedRepresentationDao).deleteCachedRepresentation(2);
     737                will(returnValue(1));
    749738
    750739            }
     
    756745    }
    757746
    758    
    759 
    760747    /**
    761748     * Test of deleteAnnotationWithTargets method, of class
     
    763750     */
    764751    @Test
    765    
    766752    public void testDeleteAnnotation() throws Exception {
    767753        System.out.println("deleteAnnotation ");
     
    770756        final List<Number> mockTargetIDs = new ArrayList<Number>();
    771757        mockTargetIDs.add(2);
    772        
     758
    773759        final List<Number> mockCachedIDs = new ArrayList<Number>();
    774760        mockCachedIDs.add(3);
     
    780766
    781767                oneOf(annotationDao).retrieveTargetIDs(2);
    782                 will(returnValue(mockTargetIDs));               
    783              
     768                will(returnValue(mockTargetIDs));
     769
    784770                oneOf(annotationDao).deleteAllAnnotationTarget(2);
    785771                will(returnValue(1));
     
    787773                oneOf(annotationDao).deleteAnnotation(2);
    788774                will(returnValue(1));
    789                
     775
    790776                oneOf(targetDao).getCachedRepresentations(2);
    791777                will(returnValue(mockCachedIDs));
    792                
     778
    793779                oneOf(targetDao).deleteTargetCachedRepresentation(2, 3);
    794780                will(returnValue(1));
    795                
     781
    796782                oneOf(cachedRepresentationDao).deleteCachedRepresentation(3);
    797783                will(returnValue(1));
    798                
     784
    799785                oneOf(targetDao).deleteTarget(2);
    800786                will(returnValue(1));
    801787
    802                
     788
    803789            }
    804790        });
     
    832818//       
    833819//    }
     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   
    8341257}
Note: See TracChangeset for help on using the changeset viewer.