Changeset 5566


Ignore:
Timestamp:
08/18/14 17:33:47 (10 years ago)
Author:
olhsha@mpi.nl
Message:

Unit test for deleting comments from groups.

Location:
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/RestGroupServiceTest.java

    r5565 r5566  
    11501150        assertEquals(0, baseRegistry.getProfileDescriptions().size());
    11511151    }
     1152     
     1153      @Test 
     1154    public void testDeleteCommentFromGroupComponentAndProfile() throws Exception {
     1155
     1156        System.out.println("test deleteCommentFromGroupComponent");
     1157
     1158       
     1159        fillUpGroupA();
     1160        fillUpGroupB();       
     1161        fillUpGroupC();
     1162       
     1163         RegistryTestHelper.addComment(baseRegistry, "COMMENTc1",  ComponentDescription.COMPONENT_PREFIX + "component-1",
     1164                "JUnit@test.com");
     1165        RegistryTestHelper.addComment(baseRegistry, "COMMENTp1",  ProfileDescription.PROFILE_PREFIX + "profile-1",
     1166                "JUnit@test.com");
     1167        RegistryTestHelper.addComment(baseRegistry, "COMMENTBc1",  ComponentDescription.COMPONENT_PREFIX + "Bcomponent-1",
     1168                "anotherPrincipal");
     1169        RegistryTestHelper.addComment(baseRegistry, "COMMENTBp1",  ProfileDescription.PROFILE_PREFIX + "Bprofile-1",
     1170                "anotherPrincipal");
     1171       (new RegistryTestHelper()).addCommentBypassAuthorisation(commentsDao, "COMMENTCc1",  ComponentDescription.COMPONENT_PREFIX + "Ccomponent-1",
     1172                "anotherPrincipal");
     1173       (new RegistryTestHelper()).addCommentBypassAuthorisation(commentsDao, "COMMENTCp1",  ProfileDescription.PROFILE_PREFIX + "Cprofile-1","anotherPrincipal");
     1174         
     1175        ClientResponse response = getAuthenticatedResource(
     1176                "/registry/components/" + ComponentDescription.COMPONENT_PREFIX + "component-1/comments/1").delete(
     1177                ClientResponse.class);
     1178        assertEquals(200, response.getStatus());
     1179        response = getAuthenticatedResource(
     1180                "/registry/components/" + ComponentDescription.COMPONENT_PREFIX + "component-1/comments/1").get(
     1181                ClientResponse.class);
     1182        assertEquals(404, response.getStatus());
     1183       
     1184        response = getAuthenticatedResource(
     1185                "/registry/components/" + ComponentDescription.COMPONENT_PREFIX + "Bcomponent-1/comments/3").delete(
     1186                ClientResponse.class);
     1187        assertEquals(403, response.getStatus());
     1188       
     1189       
     1190        response = getAuthenticatedResource(
     1191                "/registry/components/" + ComponentDescription.COMPONENT_PREFIX + "Ccomponent-1/comments/5").delete(
     1192                ClientResponse.class);
     1193        assertEquals(403, response.getStatus());
     1194
     1195       
     1196       response = getAuthenticatedResource(
     1197                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX + "profile-1/comments/2").delete(
     1198                ClientResponse.class);
     1199        assertEquals(200, response.getStatus());
     1200        response = getAuthenticatedResource(
     1201                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX + "profile-1/comments/2").get(
     1202                ClientResponse.class);
     1203        assertEquals(404, response.getStatus());
     1204       
     1205        response = getAuthenticatedResource(
     1206                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX + "Bprofile-1/comments/4").delete(
     1207                ClientResponse.class);
     1208        assertEquals(403, response.getStatus());
     1209       
     1210       
     1211        response = getAuthenticatedResource(
     1212                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX + "Cprofile-1/comments/6").delete(
     1213                ClientResponse.class);
     1214        assertEquals(403, response.getStatus());
     1215       
     1216    }
    11521217}
  • ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/SanboxTest.java

    r5565 r5566  
    230230 
    231231   
    232     @Test
    233     public void testDeleteProfileAndComponentFromGroup() throws Exception {
    234 
    235         System.out.println("test deleteProfileAndComponentFromGroup");
    236 
     232   
     233   
     234    @Test 
     235    public void testDeleteCommentFromGroupComponentAndProfile() throws Exception {
     236
     237        System.out.println("test deleteCommentFromGroupComponent");
     238
     239       
    237240        fillUpGroupA();
    238241        fillUpGroupB();       
    239242        fillUpGroupC();
    240243       
     244         RegistryTestHelper.addComment(baseRegistry, "COMMENTc1",  ComponentDescription.COMPONENT_PREFIX + "component-1",
     245                "JUnit@test.com");
     246        RegistryTestHelper.addComment(baseRegistry, "COMMENTp1",  ProfileDescription.PROFILE_PREFIX + "profile-1",
     247                "JUnit@test.com");
     248        RegistryTestHelper.addComment(baseRegistry, "COMMENTBc1",  ComponentDescription.COMPONENT_PREFIX + "Bcomponent-1",
     249                "anotherPrincipal");
     250        RegistryTestHelper.addComment(baseRegistry, "COMMENTBp1",  ProfileDescription.PROFILE_PREFIX + "Bprofile-1",
     251                "anotherPrincipal");
     252       (new RegistryTestHelper()).addCommentBypassAuthorisation(commentsDao, "COMMENTCc1",  ComponentDescription.COMPONENT_PREFIX + "Ccomponent-1",
     253                "anotherPrincipal");
     254       (new RegistryTestHelper()).addCommentBypassAuthorisation(commentsDao, "COMMENTCp1",  ProfileDescription.PROFILE_PREFIX + "Cprofile-1","anotherPrincipal");
     255         
    241256        ClientResponse response = getAuthenticatedResource(
    242                 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX
    243                 + "component-1").delete(ClientResponse.class);
     257                "/registry/components/" + ComponentDescription.COMPONENT_PREFIX + "component-1/comments/1").delete(
     258                ClientResponse.class);
    244259        assertEquals(200, response.getStatus());
     260        response = getAuthenticatedResource(
     261                "/registry/components/" + ComponentDescription.COMPONENT_PREFIX + "component-1/comments/1").get(
     262                ClientResponse.class);
     263        assertEquals(404, response.getStatus());
     264       
     265        response = getAuthenticatedResource(
     266                "/registry/components/" + ComponentDescription.COMPONENT_PREFIX + "Bcomponent-1/comments/3").delete(
     267                ClientResponse.class);
     268        assertEquals(403, response.getStatus());
     269       
     270       
     271        response = getAuthenticatedResource(
     272                "/registry/components/" + ComponentDescription.COMPONENT_PREFIX + "Ccomponent-1/comments/5").delete(
     273                ClientResponse.class);
     274        assertEquals(403, response.getStatus());
     275
    245276       
    246         response = getAuthenticatedResource(
    247                 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX
    248                 + "component-1").get(ClientResponse.class);
     277       response = getAuthenticatedResource(
     278                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX + "profile-1/comments/2").delete(
     279                ClientResponse.class);
     280        assertEquals(200, response.getStatus());
     281        response = getAuthenticatedResource(
     282                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX + "profile-1/comments/2").get(
     283                ClientResponse.class);
    249284        assertEquals(404, response.getStatus());
    250285       
    251         // my group, not my component
    252        
    253         response = getAuthenticatedResource(
    254                 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX
    255                 + "Bcomponent-1").delete(ClientResponse.class);
    256         assertEquals(200, response.getStatus());
    257        
    258         response = getAuthenticatedResource(
    259                 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX
    260                 + "Bcomponent-1").get(ClientResponse.class);
    261         assertEquals(404, response.getStatus());
    262        
    263         // not my group
    264         response = getAuthenticatedResource(
    265                 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX
    266                 + "Ccomponent-1").delete(ClientResponse.class);
    267         assertEquals(403, response.getStatus());
    268        
    269         baseRegistry.setRegistrySpace(RegistrySpace.GROUP);
    270         baseRegistry.setGroupId(1);
    271         assertEquals(1, baseRegistry.getComponentDescriptions().size());
    272         baseRegistry.setGroupId(2);
    273         assertEquals(1, baseRegistry.getComponentDescriptions().size());
    274 //        baseRegistry.setGroupId(3);
    275 //        assertEquals(2, baseRegistry.getComponentDescriptions().size());
    276        
    277         baseRegistry.setRegistrySpace(null);
    278         baseRegistry.setGroupId(null);
    279        
    280         // profiles
    281        
    282         response = getAuthenticatedResource(
    283                 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
    284                 + "profile-1").delete(ClientResponse.class);
    285         assertEquals(200, response.getStatus());
    286        
    287         response = getAuthenticatedResource(
    288                 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
    289                 + "profile-1").get(ClientResponse.class);
    290         assertEquals(404, response.getStatus());
    291        
    292         // my group, not my component
    293        
    294         response = getAuthenticatedResource(
    295                 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
    296                 + "Bprofile-1").delete(ClientResponse.class);
    297         assertEquals(200, response.getStatus());
    298        
    299         response = getAuthenticatedResource(
    300                 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
    301                 + "Bprofile-1").get(ClientResponse.class);
    302         assertEquals(404, response.getStatus());
    303        
    304         // not my group
    305         response = getAuthenticatedResource(
    306                 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
    307                 + "Cprofile-1").delete(ClientResponse.class);
    308         assertEquals(403, response.getStatus());
    309        
    310         baseRegistry.setRegistrySpace(RegistrySpace.GROUP);
    311         baseRegistry.setGroupId(1);
    312         assertEquals(0, baseRegistry.getProfileDescriptions().size());
    313         baseRegistry.setGroupId(2);
    314         assertEquals(0, baseRegistry.getProfileDescriptions().size());
     286        response = getAuthenticatedResource(
     287                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX + "Bprofile-1/comments/4").delete(
     288                ClientResponse.class);
     289        assertEquals(403, response.getStatus());
     290       
     291       
     292        response = getAuthenticatedResource(
     293                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX + "Cprofile-1/comments/6").delete(
     294                ClientResponse.class);
     295        assertEquals(403, response.getStatus());
     296       
    315297    }
    316298
Note: See TracChangeset for help on using the changeset viewer.