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.

File:
1 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}
Note: See TracChangeset for help on using the changeset viewer.