Changeset 5561


Ignore:
Timestamp:
08/18/14 14:48:56 (10 years ago)
Author:
olhsha@mpi.nl
Message:

Unit test for getting rss of profiles and components from groups, and their comments.

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

    r5560 r5561  
    1919import clarin.cmdi.componentregistry.persistence.jpa.CommentsDao;
    2020import clarin.cmdi.componentregistry.persistence.jpa.UserDao;
     21import clarin.cmdi.componentregistry.rss.Rss;
    2122import com.sun.jersey.api.client.ClientResponse;
    2223import java.text.ParseException;
     
    627628   
    628629        ClientResponse clientResponse = this.getAuthenticatedResource(getResource()
    629                 .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX+"Cprofile-1"))
     630                .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX+"Cprofile-1/comments"))
    630631                .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
    631632        assertEquals(403, clientResponse.getStatus());
    632633       
    633634         clientResponse = this.getAuthenticatedResource(getResource()
    634                 .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX+"Ccomponent-1"))
     635                .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX+"Ccomponent-1/comments"))
    635636                .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
    636637        assertEquals(403, clientResponse.getStatus());
     
    679680       
    680681    }
     682   
     683    @Test
     684    public void testGetGroupRss() throws Exception {
     685
     686        System.out.println("test getGroupRss");
     687
     688        fillUpGroupA();
     689        fillUpGroupB();       
     690        fillUpGroupC();
     691
     692       
     693         // lists of profiles and components
     694       
     695        Rss response = this.getAuthenticatedResource(getResource()
     696                .path("/registry/profiles/rss").queryParam("registrySpace", "group").queryParam("groupid", "1")).accept(MediaType.APPLICATION_XML)
     697                .get(Rss.class);
     698        assertEquals(1, response.getChannel().getItem().size());
     699       
     700         response = this.getAuthenticatedResource(getResource()
     701                .path("/registry/components/rss").queryParam("registrySpace", "group").queryParam("groupid", "1")).accept(MediaType.APPLICATION_XML)
     702                .get(Rss.class);
     703        assertEquals(2, response.getChannel().getItem().size());
     704       
     705        response = this.getAuthenticatedResource(getResource()
     706                .path("/registry/profiles/rss").queryParam("registrySpace", "group").queryParam("groupid", "2")).accept(MediaType.APPLICATION_XML)
     707                .get(Rss.class);
     708        assertEquals(1, response.getChannel().getItem().size());
     709       
     710        response = this.getAuthenticatedResource(getResource()
     711                .path("/registry/components/rss").queryParam("registrySpace", "group").queryParam("groupid", "2")).accept(MediaType.APPLICATION_XML)
     712                .get(Rss.class);
     713        assertEquals(2, response.getChannel().getItem().size());
     714       
     715        ClientResponse clientResponse = this.getAuthenticatedResource(getResource()
     716                .path("/registry/components").queryParam("registrySpace", "group").queryParam("groupid", "3")).accept(MediaType.APPLICATION_XML)
     717                .get(ClientResponse.class);
     718       
     719        assertEquals(403, clientResponse.getStatus());
     720       
     721        RegistryTestHelper.addComment(baseRegistry, "COMMENTc1",  ComponentDescription.COMPONENT_PREFIX + "component-1",
     722                "JUnit@test.com");
     723        RegistryTestHelper.addComment(baseRegistry, "COMMENTp1",  ProfileDescription.PROFILE_PREFIX + "profile-1",
     724                "JUnit@test.com");
     725        RegistryTestHelper.addComment(baseRegistry, "COMMENTBc1",  ComponentDescription.COMPONENT_PREFIX + "Bcomponent-1",
     726                "anotherPrincipal");
     727        RegistryTestHelper.addComment(baseRegistry, "COMMENTBp1",  ProfileDescription.PROFILE_PREFIX + "Bprofile-1",
     728                "anotherPrincipal");
     729       (new RegistryTestHelper()).addCommentBypassAuthorisation(commentsDao, "COMMENTCc1",  ComponentDescription.COMPONENT_PREFIX + "Ccomponent-1",
     730                "anotherPrincipal");
     731       (new RegistryTestHelper()).addCommentBypassAuthorisation(commentsDao, "COMMENTCp1",  ProfileDescription.PROFILE_PREFIX + "Cprofile-1","anotherPrincipal");
     732         
     733         
     734                // lists
     735       
     736        response = this.getAuthenticatedResource(getResource()
     737                .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX + "component-1" + "/comments/rss"))
     738                .accept(MediaType.APPLICATION_XML)
     739                .get(Rss.class);       
     740        assertEquals(1, response.getChannel().getItem().size());
     741       
     742        response = this.getAuthenticatedResource(getResource()
     743                .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX + "profile-1" + "/comments/rss"))
     744                .accept(MediaType.APPLICATION_XML)
     745                .get(Rss.class);       
     746        assertEquals(1, response.getChannel().getItem().size());
     747       
     748        response = this.getAuthenticatedResource(getResource()
     749                .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX + "Bcomponent-1" + "/comments/rss"))
     750                .accept(MediaType.APPLICATION_XML)
     751                .get(Rss.class);       
     752        assertEquals(1, response.getChannel().getItem().size());
     753       
     754        response = this.getAuthenticatedResource(getResource()
     755                .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX + "Bprofile-1" + "/comments/rss"))
     756                .accept(MediaType.APPLICATION_XML)
     757                .get(Rss.class);       
     758        assertEquals(1, response.getChannel().getItem().size());
     759       
     760       
     761   
     762        clientResponse = this.getAuthenticatedResource(getResource()
     763                .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX+"Cprofile-1/comments/rss"))
     764                .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
     765        assertEquals(403, clientResponse.getStatus());
     766       
     767         clientResponse = this.getAuthenticatedResource(getResource()
     768                .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX+"Ccomponent-1/comments/rss"))
     769                .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
     770        assertEquals(403, clientResponse.getStatus());
     771       
     772        // particular comments
     773       
     774       Comment responseComment = this.getAuthenticatedResource(getResource()
     775                .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX + "component-1" + "/comments/1"))
     776                .accept(MediaType.APPLICATION_XML)
     777                .get(Comment.class);       
     778        assertNotNull(responseComment);
     779     
     780        assertEquals(1, Long.parseLong(responseComment.getId()));
     781       
     782        responseComment = this.getAuthenticatedResource(getResource()
     783                .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX + "profile-1" + "/comments/2"))
     784                .accept(MediaType.APPLICATION_XML)
     785                .get(Comment.class);       
     786        assertNotNull(responseComment);
     787       
     788        assertEquals(2, Long.parseLong(responseComment.getId()));
     789       
     790       responseComment = this.getAuthenticatedResource(getResource()
     791                .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX + "Bcomponent-1" + "/comments/3"))
     792                .accept(MediaType.APPLICATION_XML)
     793                .get(Comment.class);       
     794        assertNotNull(responseComment);
     795        assertEquals(3, Long.parseLong(responseComment.getId()));
     796       
     797        responseComment = this.getAuthenticatedResource(getResource()
     798                .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX + "Bprofile-1" + "/comments/4"))
     799                .accept(MediaType.APPLICATION_XML)
     800                .get(Comment.class);       
     801        assertNotNull(responseComment);
     802        assertEquals(4, Long.parseLong(responseComment.getId()));
     803       
     804        clientResponse = this.getAuthenticatedResource(getResource()
     805                .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX+"Cprofile-1/comments/6"))
     806                .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
     807        assertEquals(403, clientResponse.getStatus());
     808       
     809         clientResponse = this.getAuthenticatedResource(getResource()
     810                .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX+"Ccomponent-1/comments/5"))
     811                .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
     812        assertEquals(403, clientResponse.getStatus());
     813       
     814    }
    681815
    682816}
  • ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/SanboxTest.java

    r5560 r5561  
    1717import clarin.cmdi.componentregistry.persistence.jpa.CommentsDao;
    1818import clarin.cmdi.componentregistry.persistence.jpa.UserDao;
     19import clarin.cmdi.componentregistry.rss.Rss;
    1920import com.sun.jersey.api.client.ClientResponse;
    2021import java.text.ParseException;
     
    207208   
    208209    @Test
    209     public void testGetGroupComments() throws Exception {
    210 
    211         System.out.println("test getGroupComments");
     210    public void testGetGroupRss() throws Exception {
     211
     212        System.out.println("test getGroupRss");
    212213
    213214        fillUpGroupA();
     
    215216        fillUpGroupC();
    216217
     218       
     219         // lists of profiles and components
     220       
     221        Rss response = this.getAuthenticatedResource(getResource()
     222                .path("/registry/profiles/rss").queryParam("registrySpace", "group").queryParam("groupid", "1")).accept(MediaType.APPLICATION_XML)
     223                .get(Rss.class);
     224        assertEquals(1, response.getChannel().getItem().size());
     225       
     226         response = this.getAuthenticatedResource(getResource()
     227                .path("/registry/components/rss").queryParam("registrySpace", "group").queryParam("groupid", "1")).accept(MediaType.APPLICATION_XML)
     228                .get(Rss.class);
     229        assertEquals(2, response.getChannel().getItem().size());
     230       
     231        response = this.getAuthenticatedResource(getResource()
     232                .path("/registry/profiles/rss").queryParam("registrySpace", "group").queryParam("groupid", "2")).accept(MediaType.APPLICATION_XML)
     233                .get(Rss.class);
     234        assertEquals(1, response.getChannel().getItem().size());
     235       
     236        response = this.getAuthenticatedResource(getResource()
     237                .path("/registry/components/rss").queryParam("registrySpace", "group").queryParam("groupid", "2")).accept(MediaType.APPLICATION_XML)
     238                .get(Rss.class);
     239        assertEquals(2, response.getChannel().getItem().size());
     240       
     241        ClientResponse clientResponse = this.getAuthenticatedResource(getResource()
     242                .path("/registry/components").queryParam("registrySpace", "group").queryParam("groupid", "3")).accept(MediaType.APPLICATION_XML)
     243                .get(ClientResponse.class);
     244       
     245        assertEquals(403, clientResponse.getStatus());
    217246       
    218247        RegistryTestHelper.addComment(baseRegistry, "COMMENTc1",  ComponentDescription.COMPONENT_PREFIX + "component-1",
     
    231260                // lists
    232261       
    233         List<Comment> response = this.getAuthenticatedResource(getResource()
    234                 .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX + "component-1" + "/comments/"))
    235                 .accept(MediaType.APPLICATION_XML)
    236                 .get(COMMENT_LIST_GENERICTYPE);       
    237         assertEquals(1, response.size());
    238        
    239         response = this.getAuthenticatedResource(getResource()
    240                 .path("/registry/components/" + ProfileDescription.PROFILE_PREFIX + "profile-1" + "/comments/"))
    241                 .accept(MediaType.APPLICATION_XML)
    242                 .get(COMMENT_LIST_GENERICTYPE);       
    243         assertEquals(1, response.size());
    244        
    245         response = this.getAuthenticatedResource(getResource()
    246                 .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX + "Bcomponent-1" + "/comments/"))
    247                 .accept(MediaType.APPLICATION_XML)
    248                 .get(COMMENT_LIST_GENERICTYPE);       
    249         assertEquals(1, response.size());
    250        
    251         response = this.getAuthenticatedResource(getResource()
    252                 .path("/registry/components/" + ProfileDescription.PROFILE_PREFIX + "Bprofile-1" + "/comments/"))
    253                 .accept(MediaType.APPLICATION_XML)
    254                 .get(COMMENT_LIST_GENERICTYPE);       
    255         assertEquals(1, response.size());
    256        
    257        
    258    
    259         ClientResponse clientResponse = this.getAuthenticatedResource(getResource()
    260                 .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX+"Cprofile-1"))
     262        response = this.getAuthenticatedResource(getResource()
     263                .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX + "component-1" + "/comments/rss"))
     264                .accept(MediaType.APPLICATION_XML)
     265                .get(Rss.class);       
     266        assertEquals(1, response.getChannel().getItem().size());
     267       
     268        response = this.getAuthenticatedResource(getResource()
     269                .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX + "profile-1" + "/comments/rss"))
     270                .accept(MediaType.APPLICATION_XML)
     271                .get(Rss.class);       
     272        assertEquals(1, response.getChannel().getItem().size());
     273       
     274        response = this.getAuthenticatedResource(getResource()
     275                .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX + "Bcomponent-1" + "/comments/rss"))
     276                .accept(MediaType.APPLICATION_XML)
     277                .get(Rss.class);       
     278        assertEquals(1, response.getChannel().getItem().size());
     279       
     280        response = this.getAuthenticatedResource(getResource()
     281                .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX + "Bprofile-1" + "/comments/rss"))
     282                .accept(MediaType.APPLICATION_XML)
     283                .get(Rss.class);       
     284        assertEquals(1, response.getChannel().getItem().size());
     285       
     286       
     287   
     288        clientResponse = this.getAuthenticatedResource(getResource()
     289                .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX+"Cprofile-1/comments/rss"))
    261290                .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
    262291        assertEquals(403, clientResponse.getStatus());
    263292       
    264293         clientResponse = this.getAuthenticatedResource(getResource()
    265                 .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX+"Ccomponent-1"))
     294                .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX+"Ccomponent-1/comments/rss"))
    266295                .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
    267296        assertEquals(403, clientResponse.getStatus());
Note: See TracChangeset for help on using the changeset viewer.