Changeset 1894


Ignore:
Timestamp:
04/20/12 07:51:13 (12 years ago)
Author:
twagoo
Message:

Fixed manipulate comment methods (for deleting without http DELETE) in rest service. Added tests for all manipulate methods.

Location:
ComponentRegistry/trunk/ComponentRegistry/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestService.java

    r1892 r1894  
    312312    @POST
    313313    @Path("/profiles/{profileId}/comments/{commentId}")
    314     public Response manipulateCommentFromProfile(@PathParam("profileId") String profileId, @PathParam("profileId") String commentId, @FormParam("method") String method,
     314    public Response manipulateCommentFromProfile(@PathParam("profileId") String profileId, @PathParam("commentId") String commentId, @FormParam("method") String method,
    315315            @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
    316316        if ("delete".equalsIgnoreCase(method)) {
     
    323323    @POST
    324324    @Path("/components/{componentId}/comments/{commentId}")
    325     public Response manipulateCommentFromComponent(@PathParam("componentId") String componentId, @PathParam("profileId") String commentId, @FormParam("method") String method,
     325    public Response manipulateCommentFromComponent(@PathParam("componentId") String componentId, @PathParam("commentId") String commentId, @FormParam("method") String method,
    326326            @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
    327327        if ("delete".equalsIgnoreCase(method)) {
  • ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestServiceTest.java

    r1870 r1894  
    1414import com.sun.jersey.api.client.ClientResponse;
    1515import com.sun.jersey.api.client.UniformInterfaceException;
     16import com.sun.jersey.api.representation.Form;
    1617import com.sun.jersey.multipart.FormDataMultiPart;
    1718import java.io.ByteArrayInputStream;
     
    225226
    226227    @Test
     228    public void testManipulateCommentFromComponent() throws Exception {
     229        fillUp();
     230        List<Comment> comments = getResource().path("/registry/components/clarin.eu:cr1:component1/comments").get(COMMENT_LIST_GENERICTYPE);
     231        assertEquals(2, comments.size());
     232        Comment aComment = getResource().path("/registry/components/clarin.eu:cr1:component1/comments/2").get(Comment.class);
     233        assertNotNull(aComment);
     234
     235        Form manipulateForm = new Form();
     236        manipulateForm.add("method", "delete");
     237
     238        // Try to delete from other component
     239        ClientResponse response = getAuthenticatedResource("/registry/components/clarin.eu:cr1:component1/comments/2").post(ClientResponse.class, manipulateForm);
     240        assertEquals(200, response.getStatus());
     241
     242        comments = getResource().path("/registry/components/clarin.eu:cr1:component1/comments/").get(COMMENT_LIST_GENERICTYPE);
     243        assertEquals(1, comments.size());
     244    }
     245
     246    @Test
    227247    public void testDeleteCommentFromProfile() throws Exception {
    228248        fillUp();
     
    247267        comments = getResource().path("/registry/profiles/clarin.eu:cr1:profile1/comments").get(COMMENT_LIST_GENERICTYPE);
    248268        assertEquals(0, comments.size());
     269    }
     270
     271    @Test
     272    public void testManipulateCommentFromProfile() throws Exception {
     273        fillUp();
     274        List<Comment> comments = getResource().path("/registry/profiles/clarin.eu:cr1:profile1/comments").get(COMMENT_LIST_GENERICTYPE);
     275        assertEquals(2, comments.size());
     276        Comment aComment = getResource().path("/registry/profiles/clarin.eu:cr1:profile1/comments/0").get(Comment.class);
     277        assertNotNull(aComment);
     278
     279        Form manipulateForm = new Form();
     280        manipulateForm.add("method", "delete");
     281        // Delete from correct profile
     282        ClientResponse response = getAuthenticatedResource("/registry/profiles/clarin.eu:cr1:profile1/comments/0").post(ClientResponse.class, manipulateForm);
     283        assertEquals(200, response.getStatus());
     284
     285        comments = getResource().path("/registry/profiles/clarin.eu:cr1:profile1/comments/").get(COMMENT_LIST_GENERICTYPE);
     286        assertEquals(1, comments.size());
    249287    }
    250288
     
    329367
    330368    @Test
     369    public void testManipulateRegisteredComponent() throws Exception {
     370        fillUp();
     371        List<ComponentDescription> components = getResource().path("/registry/components").get(COMPONENT_LIST_GENERICTYPE);
     372        assertEquals(2, components.size());
     373        CMDComponentSpec profile = getResource().path("/registry/components/clarin.eu:cr1:component1").get(CMDComponentSpec.class);
     374        assertNotNull(profile);
     375
     376        Form manipulateForm = new Form();
     377        manipulateForm.add("method", "delete");
     378
     379        ClientResponse response = getAuthenticatedResource("/registry/components/clarin.eu:cr1:component1").post(ClientResponse.class, manipulateForm);
     380        assertEquals(200, response.getStatus());
     381
     382        components = getResource().path("/registry/components").get(COMPONENT_LIST_GENERICTYPE);
     383        assertEquals(1, components.size());
     384
     385        response = getAuthenticatedResource("/registry/components/clarin.eu:cr1:component2").post(ClientResponse.class, manipulateForm);
     386        assertEquals(200, response.getStatus());
     387    }
     388
     389    @Test
    331390    public void testGetRegisteredProfile() throws Exception {
    332391        fillUp();
     
    417476
    418477        response = getAuthenticatedResource("/registry/profiles/clarin.eu:cr1:profile1").delete(ClientResponse.class);
     478        assertEquals(200, response.getStatus());
     479    }
     480
     481    @Test
     482    public void testManipulateRegisteredProfile() throws Exception {
     483        fillUp();
     484        List<ProfileDescription> profiles = getResource().path("/registry/profiles").get(PROFILE_LIST_GENERICTYPE);
     485        assertEquals(2, profiles.size());
     486        CMDComponentSpec profile = getResource().path("/registry/profiles/clarin.eu:cr1:profile1").get(CMDComponentSpec.class);
     487        assertNotNull(profile);
     488
     489        Form manipulateForm = new Form();
     490        manipulateForm.add("method", "delete");
     491
     492        ClientResponse response = getAuthenticatedResource("/registry/profiles/clarin.eu:cr1:profile1").post(ClientResponse.class, manipulateForm);
     493        assertEquals(200, response.getStatus());
     494
     495        profiles = getResource().path("/registry/profiles").get(PROFILE_LIST_GENERICTYPE);
     496        assertEquals(1, profiles.size());
     497
     498        response = getAuthenticatedResource("/registry/profiles/clarin.eu:cr1:profile2").post(ClientResponse.class, manipulateForm);
    419499        assertEquals(200, response.getStatus());
    420500    }
Note: See TracChangeset for help on using the changeset viewer.