Ignore:
Timestamp:
11/19/14 17:21:25 (10 years ago)
Author:
olhsha@mpi.nl
Message:

units tests updating and adding (all-access)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/DBDispatcherTest.java

    r5836 r5838  
    197197        textBody.setBody("<html><body>some html 1</body></html>");
    198198        mockAnnotation.setBody(mockBody);
     199        PermissionList permissions = new PermissionList();
     200        permissions.setPublic(Access.WRITE);
     201        mockAnnotation.setPermissions(permissions);
    199202        mockAnnotation.setTargets(null);
    200203
     
    235238        mockeryDao.checking(new Expectations() {
    236239            {
    237                 oneOf(annotationDao).getAnnotationWithoutTargetsAndPemissions(1);
     240                oneOf(annotationDao).getAnnotationWithoutTargetsAndPemissionList(1);
    238241                will(returnValue(mockAnnotation));
    239242
     
    257260                oneOf(annotationDao).getPermissions(1);
    258261                will(returnValue(listMap));
    259 
    260                 oneOf(annotationDao).getPublicAttribute(1);
    261                 will(returnValue(Access.WRITE));
    262262
    263263                oneOf(principalDao).getHrefFromInternalID(2);
     
    12531253                will(returnValue(1));
    12541254
    1255                 ///////////
     1255                ///
    12561256
    12571257                oneOf(annotationDao).updateAnnotationBody(5, testAnnotation.getBody().getTextBody().getBody(), testAnnotation.getBody().getTextBody().getMimeType(), false);
    12581258                will(returnValue(1)); // the DB update will be called at perform anyway, even if the body is not changed (can be optimized)
    12591259
    1260                 oneOf(annotationDao).updatePublicAccess(5, Access.WRITE);
     1260                //////
     1261               
     1262               
     1263                oneOf(principalDao).getInternalIDFromHref("/api/principals/00000000-0000-0000-0000-000000000111");
     1264                will(returnValue(1));
     1265               
     1266                oneOf(annotationDao).addPermission(5, 1, Access.ALL);
    12611267                will(returnValue(1));
    12621268            }
     
    12651271        Number result = dbDispatcher.addPrincipalsAnnotation(3, testAnnotation);
    12661272        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 
    12771273    }
    12781274
     
    19551951                oneOf(annotationDao).updatePublicAccess(5, Access.WRITE);
    19561952                will(returnValue(1));
     1953               
     1954                ////               
     1955                   
     1956                oneOf(principalDao).getInternalIDFromHref("/api/principals/00000000-0000-0000-0000-000000000111");
     1957                will(returnValue(1));
    19571958
    19581959                /////////////////////////
     
    19601961                oneOf(notebookDao).addAnnotationToNotebook(1, 5);
    19611962                will(returnValue(true));
     1963               
     1964                oneOf(annotationDao).addPermission(5, 1, Access.ALL);
     1965                will(returnValue(1));
    19621966            }
    19631967        });
     
    20912095        final Annotation annotation = (new TestInstances("/api")).getAnnotationOne();
    20922096        final NotInDataBaseException e = new NotInDataBaseException("annotation", "external ID", "00000000-0000-0000-0000-000000000031");
    2093         final String mockTempID = "00000000-0000-0000-0000-000000000031";
    20942097        final UUID mockNewID = Helpers.generateUUID();
    20952098        final PermissionList permissions = annotation.getPermissions();
     
    21592162                oneOf(annotationDao).updateAnnotationBody(1, annotation.getBody().getTextBody().getBody(), "text/html", false);
    21602163                will(returnValue(1));
    2161 
    2162                 ///
    2163 
    2164                 oneOf(annotationDao).updatePublicAccess(1, permissions.getPublic());
    2165                 will(returnValue(1));
    2166 
    21672164
    21682165            }
     
    22162213                oneOf(annotationDao).addPermission(1, 4, Access.WRITE);
    22172214                will(returnValue(1));
     2215               
     2216                oneOf(annotationDao).deletePermission(1, 2);
     2217                will(returnValue(1));
    22182218
    22192219            }
     
    22222222        assertEquals(1, dbDispatcher.updatePermission(1, 2, Access.READ));
    22232223        assertEquals(1, dbDispatcher.updatePermission(1, 4, Access.WRITE));
     2224        assertEquals(1, dbDispatcher.updatePermission(1, 2, null));
    22242225    }
    22252226
     
    23072308
    23082309    }
     2310   
     2311    @Test
     2312    public void testCanDo(){
     2313        System.out.println("test canDo");
     2314       
     2315        mockeryDao.checking(new Expectations() {            {
     2316                /////
     2317                oneOf(annotationDao).getOwner(1);
     2318                will(returnValue(1));
     2319                oneOf(principalDao).getTypeOfPrincipalAccount(1);
     2320                will(returnValue("developer"));
     2321            }
     2322        });
     2323        assertTrue(dbDispatcher.canDo(Access.ALL, 1, 1, Resource.ANNOTATION));
     2324       
     2325        mockeryDao.checking(new Expectations() {            {
     2326                /////
     2327                oneOf(annotationDao).getOwner(2);
     2328                will(returnValue(2));
     2329                oneOf(principalDao).getTypeOfPrincipalAccount(2);
     2330                will(returnValue("developer"));
     2331               
     2332                oneOf(annotationDao).getAccess(2, 1);
     2333                will(returnValue(Access.READ));
     2334                oneOf(annotationDao).getPublicAttribute(2);
     2335                will(returnValue(Access.READ));
     2336            }
     2337        });
     2338        assertFalse(dbDispatcher.canDo(Access.WRITE, 1, 2, Resource.ANNOTATION));
     2339       
     2340        mockeryDao.checking(new Expectations() {            {
     2341                /////
     2342                oneOf(annotationDao).getOwner(3);
     2343                will(returnValue(3));
     2344                oneOf(principalDao).getTypeOfPrincipalAccount(1);
     2345                will(returnValue("developer"));
     2346               
     2347                oneOf(annotationDao).getAccess(3, 1);
     2348                will(returnValue(Access.READ));
     2349                oneOf(annotationDao).getPublicAttribute(3);
     2350                will(returnValue(Access.ALL));
     2351            }
     2352        });
     2353        assertTrue(dbDispatcher.canDo(Access.WRITE, 1, 3, Resource.ANNOTATION));
     2354       
     2355        mockeryDao.checking(new Expectations() {            {
     2356                /////
     2357                oneOf(annotationDao).getOwner(4);
     2358                will(returnValue(3));
     2359                oneOf(principalDao).getTypeOfPrincipalAccount(11);
     2360                will(returnValue("user"));
     2361               
     2362                oneOf(annotationDao).getAccess(4, 11);
     2363                will(returnValue(Access.NONE));
     2364                oneOf(annotationDao).getPublicAttribute(4);
     2365                will(returnValue(Access.NONE));
     2366            }
     2367        });
     2368        assertFalse(dbDispatcher.canDo(Access.READ, 11, 4, Resource.ANNOTATION));
     2369    }
    23092370}
Note: See TracChangeset for help on using the changeset viewer.