Ignore:
Timestamp:
12/07/11 10:24:43 (12 years ago)
Author:
jeafer
Message:

Jean-Charles branch ComponentRegistry commit4,
Changes regarding comment on the ComponentRegistry.

Modification of classes Comment, CommentsDao?
Improvement of validation process for comments
Improvement of ComponentRegistryRestService?
Functionnal implementation of class test (RegisterHelper? and RestServiceTest?)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestServiceTest.java

    r1635 r1639  
    7676        RegistryTestHelper.addComponent(getTestRegistry(), "component2");
    7777        RegistryTestHelper.addComponent(getTestRegistry(), "component1");
    78         RegistryTestHelper.addComment(getTestRegistry(), "comment2");
    79         RegistryTestHelper.addComment(getTestRegistry(), "comment1");
    80        
     78        RegistryTestHelper.addComment(getTestRegistry(), "comment2", "profile1", "JUnit@test.com");
     79        RegistryTestHelper.addComment(getTestRegistry(), "comment1", "profile1", "JUnit@test.com");
     80        RegistryTestHelper.addComment(getTestRegistry(), "comment3", "component1", "JUnit@test.com");
     81        RegistryTestHelper.addComment(getTestRegistry(), "comment4", "component1", "JUnit@test.com");
     82
    8183    }
    8284
     
    143145    public void testGetRegisteredCommentsInProfile() throws Exception {
    144146        fillUp();
    145         RegistryTestHelper.addComment(getTestRegistry(), "COMMENT1");
    146         List<Comment> response = getResource().path("/registry/profiles/clarin.eu:cr1:profile1/comments").accept(MediaType.APPLICATION_XML).
     147        RegistryTestHelper.addComment(getTestRegistry(), "COMMENT1", "profile1", "JUnit@test.com");
     148        List<Comment> response = getResource().path("/registry/profiles/profile1/comments/").accept(MediaType.APPLICATION_XML).
    147149                get(COMMENT_LIST_GENERICTYPE);
    148         assertEquals(0, response.size());
    149         response = getResource().path("/registry/components/clarin.eu:cr1:profile1/comments").accept(MediaType.APPLICATION_JSON).get(
     150        assertEquals(3, response.size());
     151        response = getResource().path("/registry/profiles/profile1/comments").accept(MediaType.APPLICATION_JSON).get(
    150152                COMMENT_LIST_GENERICTYPE);
    151153        assertEquals(3, response.size());
    152         assertEquals("comment1", response.get(0).getComment());
    153         assertEquals("comment2", response.get(1).getComment());
     154        assertEquals("comment2", response.get(0).getComment());
     155        assertEquals("comment1", response.get(1).getComment());
    154156        assertEquals("COMMENT1", response.get(2).getComment());
     157    }
     158
     159    @Test
     160    public void testGetRegisteredCommentsInComponent() throws Exception {
     161        fillUp();
     162        RegistryTestHelper.addComment(getTestRegistry(), "COMMENT2", "component1", "JUnit@test.com");
     163        List<Comment> response = getResource().path("/registry/components/component1/comments/").accept(MediaType.APPLICATION_XML).
     164                get(COMMENT_LIST_GENERICTYPE);
     165        assertEquals(3, response.size());
     166        response = getResource().path("/registry/components/component1/comments").accept(MediaType.APPLICATION_JSON).get(
     167                COMMENT_LIST_GENERICTYPE);
     168        assertEquals(3, response.size());
     169        assertEquals("comment3", response.get(0).getComment());
     170        assertEquals("comment4", response.get(1).getComment());
     171        assertEquals("COMMENT2", response.get(2).getComment());
     172    }
     173
     174    @Test
     175    public void testGetSpecifiedCommentInComponent() throws Exception {
     176        fillUp();
     177        Comment comment = getResource().path("/registry/components/component1/comments/2").accept(MediaType.APPLICATION_JSON).get(Comment.class);
     178        assertNotNull(comment);
     179        assertEquals("comment3", comment.getComment());
     180        assertEquals("2", comment.getId());
     181        comment = getResource().path("/registry/components/component1/comments/3").accept(MediaType.APPLICATION_JSON).get(Comment.class);
     182        assertNotNull(comment);
     183        assertEquals("comment4", comment.getComment());
     184        assertEquals("3", comment.getId());
     185        assertEquals("component1", comment.getComponentDescriptionId());
     186    }
     187
     188    @Test
     189    public void testGetSpecifiedCommentInProfile() throws Exception {
     190        fillUp();
     191        Comment comment = getResource().path("/registry/profiles/profile1/comments/0").accept(MediaType.APPLICATION_JSON).get(Comment.class);
     192        assertNotNull(comment);
     193        assertEquals("comment2", comment.getComment());
     194        assertEquals("0", comment.getId());
     195        comment = getResource().path("/registry/profiles/profile1/comments/1").accept(MediaType.APPLICATION_JSON).get(Comment.class);
     196        assertNotNull(comment);
     197        assertEquals("comment1", comment.getComment());
     198        assertEquals("1", comment.getId());
     199        assertEquals("profile1", comment.getProfileDescriptionId());
     200    }
     201   
     202    @Test
     203    public void testDeleteCommentFromComponent() throws Exception {
     204        fillUp();
     205        List<Comment> comments = getResource().path("/registry/components/component1/comments").get(COMMENT_LIST_GENERICTYPE);
     206        assertEquals(2, comments.size());
     207        Comment aComment = getResource().path("/registry/components/component1/comments/2").get(Comment.class);
     208        assertNotNull(aComment);
     209        ClientResponse response = getAuthenticatedResource("/registry/components/component1/comments/2").delete(ClientResponse.class);
     210        assertEquals(200, response.getStatus());
     211       
     212        comments = getResource().path("/registry/components/component1/comments/").get(COMMENT_LIST_GENERICTYPE);
     213        assertEquals(1, comments.size());
     214       
     215        response = getAuthenticatedResource("/registry/components/component1/comments/3").delete(ClientResponse.class);
     216        assertEquals(200, response.getStatus());
     217       
     218        comments = getResource().path("/registry/components/component1/comments").get(COMMENT_LIST_GENERICTYPE);
     219        assertEquals(0, comments.size());
     220    }
     221   
     222        @Test
     223    public void testDeleteCommentFromProfile() throws Exception {
     224        fillUp();
     225        List<Comment> comments = getResource().path("/registry/profiles/profile1/comments").get(COMMENT_LIST_GENERICTYPE);
     226        assertEquals(2, comments.size());
     227        Comment aComment = getResource().path("/registry/profiles/profile1/comments/0").get(Comment.class);
     228        assertNotNull(aComment);
     229        ClientResponse response = getAuthenticatedResource("/registry/profiles/profile1/comments/0").delete(ClientResponse.class);
     230        assertEquals(200, response.getStatus());
     231       
     232        comments = getResource().path("/registry/profiles/profile1/comments/").get(COMMENT_LIST_GENERICTYPE);
     233        assertEquals(1, comments.size());
     234       
     235        response = getAuthenticatedResource("/registry/profiles/profile1/comments/1").delete(ClientResponse.class);
     236        assertEquals(200, response.getStatus());
     237       
     238        comments = getResource().path("/registry/profiles/profile1/comments").get(COMMENT_LIST_GENERICTYPE);
     239        assertEquals(0, comments.size());
    155240    }
    156241
     
    769854        RegisterResponse response = getAuthenticatedResource("/registry/profiles/clarin.eu:cr1:profile1/comments").type(MediaType.MULTIPART_FORM_DATA).post(
    770855                RegisterResponse.class, form);
     856        assertTrue(response.isRegistered());
    771857        assertFalse(response.isInUserSpace());
    772         Comment comment = (Comment) response.getComment();
     858        Comment comment = response.getComment();
    773859        assertNotNull(comment);
    774         assertEquals("CommentTest1", comment.getComment());
     860        assertEquals("Actual", comment.getComment());
    775861        assertEquals(expectedUserId("JUnit@test.com"), comment.getUserId());
    776         assertTrue(comment.getId().startsWith(ComponentRegistry.REGISTRY_ID + "p_"));
    777862        assertNotNull(comment.getCommentDate());
    778         String url = getResource().getUriBuilder().build().toString();
    779         assertEquals(url + "registry/profiles/{clarin.eu:cr1:p_1297242111880}/comments/" + comment.getId(), 1);
    780863    }
    781864
Note: See TracChangeset for help on using the changeset viewer.