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

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

File:
1 edited

Legend:

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

    r5556 r5560  
    1717import clarin.cmdi.componentregistry.model.ProfileDescription;
    1818import clarin.cmdi.componentregistry.model.RegistryUser;
     19import clarin.cmdi.componentregistry.persistence.jpa.CommentsDao;
    1920import clarin.cmdi.componentregistry.persistence.jpa.UserDao;
    2021import com.sun.jersey.api.client.ClientResponse;
     
    2223import java.util.List;
    2324import javax.ws.rs.core.MediaType;
    24 import javax.ws.rs.core.MultivaluedMap;
    2525import javax.xml.bind.JAXBException;
    2626import org.junit.Before;
     
    4646    @Autowired
    4747    private UserDao userDao;
     48    @Autowired
     49    private CommentsDao commentsDao;
    4850   
    4951    private ComponentRegistry baseRegistry;
     
    507509        fillUpGroupC();
    508510
     511        // lists
    509512       
    510513        List<ProfileDescription> response = this.getAuthenticatedResource(getResource()
     
    534537        assertEquals(403, clientResponse.getStatus());
    535538       
     539        // particular components and profiles
    536540       
    537541        CMDComponentSpec component = this.getAuthenticatedResource(getResource()
     
    570574       
    571575    }
     576   
     577   @Test
     578    public void testGetGroupComments() throws Exception {
     579
     580        System.out.println("test getGroupComments");
     581
     582        fillUpGroupA();
     583        fillUpGroupB();       
     584        fillUpGroupC();
     585
     586       
     587        RegistryTestHelper.addComment(baseRegistry, "COMMENTc1",  ComponentDescription.COMPONENT_PREFIX + "component-1",
     588                "JUnit@test.com");
     589        RegistryTestHelper.addComment(baseRegistry, "COMMENTp1",  ProfileDescription.PROFILE_PREFIX + "profile-1",
     590                "JUnit@test.com");
     591        RegistryTestHelper.addComment(baseRegistry, "COMMENTBc1",  ComponentDescription.COMPONENT_PREFIX + "Bcomponent-1",
     592                "anotherPrincipal");
     593        RegistryTestHelper.addComment(baseRegistry, "COMMENTBp1",  ProfileDescription.PROFILE_PREFIX + "Bprofile-1",
     594                "anotherPrincipal");
     595       (new RegistryTestHelper()).addCommentBypassAuthorisation(commentsDao, "COMMENTCc1",  ComponentDescription.COMPONENT_PREFIX + "Ccomponent-1",
     596                "anotherPrincipal");
     597       (new RegistryTestHelper()).addCommentBypassAuthorisation(commentsDao, "COMMENTCp1",  ProfileDescription.PROFILE_PREFIX + "Cprofile-1","anotherPrincipal");
     598         
     599         
     600                // lists
     601       
     602        List<Comment> response = this.getAuthenticatedResource(getResource()
     603                .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX + "component-1" + "/comments/"))
     604                .accept(MediaType.APPLICATION_XML)
     605                .get(COMMENT_LIST_GENERICTYPE);       
     606        assertEquals(1, response.size());
     607       
     608        response = this.getAuthenticatedResource(getResource()
     609                .path("/registry/components/" + ProfileDescription.PROFILE_PREFIX + "profile-1" + "/comments/"))
     610                .accept(MediaType.APPLICATION_XML)
     611                .get(COMMENT_LIST_GENERICTYPE);       
     612        assertEquals(1, response.size());
     613       
     614        response = this.getAuthenticatedResource(getResource()
     615                .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX + "Bcomponent-1" + "/comments/"))
     616                .accept(MediaType.APPLICATION_XML)
     617                .get(COMMENT_LIST_GENERICTYPE);       
     618        assertEquals(1, response.size());
     619       
     620        response = this.getAuthenticatedResource(getResource()
     621                .path("/registry/components/" + ProfileDescription.PROFILE_PREFIX + "Bprofile-1" + "/comments/"))
     622                .accept(MediaType.APPLICATION_XML)
     623                .get(COMMENT_LIST_GENERICTYPE);       
     624        assertEquals(1, response.size());
     625       
     626       
     627   
     628        ClientResponse clientResponse = this.getAuthenticatedResource(getResource()
     629                .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX+"Cprofile-1"))
     630                .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
     631        assertEquals(403, clientResponse.getStatus());
     632       
     633         clientResponse = this.getAuthenticatedResource(getResource()
     634                .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX+"Ccomponent-1"))
     635                .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
     636        assertEquals(403, clientResponse.getStatus());
     637       
     638        // particular comments
     639       
     640       Comment responseComment = this.getAuthenticatedResource(getResource()
     641                .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX + "component-1" + "/comments/1"))
     642                .accept(MediaType.APPLICATION_XML)
     643                .get(Comment.class);       
     644        assertNotNull(responseComment);
     645     
     646        assertEquals(1, Long.parseLong(responseComment.getId()));
     647       
     648        responseComment = this.getAuthenticatedResource(getResource()
     649                .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX + "profile-1" + "/comments/2"))
     650                .accept(MediaType.APPLICATION_XML)
     651                .get(Comment.class);       
     652        assertNotNull(responseComment);
     653       
     654        assertEquals(2, Long.parseLong(responseComment.getId()));
     655       
     656       responseComment = this.getAuthenticatedResource(getResource()
     657                .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX + "Bcomponent-1" + "/comments/3"))
     658                .accept(MediaType.APPLICATION_XML)
     659                .get(Comment.class);       
     660        assertNotNull(responseComment);
     661        assertEquals(3, Long.parseLong(responseComment.getId()));
     662       
     663        responseComment = this.getAuthenticatedResource(getResource()
     664                .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX + "Bprofile-1" + "/comments/4"))
     665                .accept(MediaType.APPLICATION_XML)
     666                .get(Comment.class);       
     667        assertNotNull(responseComment);
     668        assertEquals(4, Long.parseLong(responseComment.getId()));
     669       
     670        clientResponse = this.getAuthenticatedResource(getResource()
     671                .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX+"Cprofile-1/comments/6"))
     672                .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
     673        assertEquals(403, clientResponse.getStatus());
     674       
     675         clientResponse = this.getAuthenticatedResource(getResource()
     676                .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX+"Ccomponent-1/comments/5"))
     677                .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
     678        assertEquals(403, clientResponse.getStatus());
     679       
     680    }
    572681
    573682}
Note: See TracChangeset for help on using the changeset viewer.