Changeset 5550


Ignore:
Timestamp:
08/12/14 14:59:10 (10 years ago)
Author:
olhsha@mpi.nl
Message:

Fixed exception that have appeared while unit-testing

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

Legend:

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

    r5549 r5550  
    213213     * @throws DeleteFailedException
    214214     */
    215     public void deleteComment(String commentId) throws IOException, ComponentRegistryException, UserUnauthorizedException,
     215    public void deleteComment(String commentId) throws IOException, UserUnauthorizedException,
    216216            DeleteFailedException, ItemNotFoundException;
    217217
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryDbImpl.java

    r5549 r5550  
    284284                    return comment;
    285285                } else {
    286                     // Comment exists in DB, but profile is not in this registry
    287                     throw new ComponentRegistryException("Comment " + commentId + " cannot be found in specified registry");
     286                    throw new ComponentRegistryException("Comment " + commentId  + "for the profile "+profileId);
    288287                }
    289288            } catch (DataAccessException ex) {
     
    323322                    return comment;
    324323                } else {
    325                     // Comment does not exists in DB or component is not in this
    326                     // registry
    327                     throw new ComponentRegistryException("Comment " + commentId
    328                             + " cannot be found in specified registry for specified component");
     324                    throw new ComponentRegistryException("Comment " + commentId  + "for the profile "+componentId);
    329325                }
    330326            } catch (DataAccessException ex) {
     
    809805
    810806    @Override
    811     public void deleteComment(String commentId) throws IOException, ComponentRegistryException,
     807    public void deleteComment(String commentId) throws IOException,
    812808            UserUnauthorizedException, DeleteFailedException, ItemNotFoundException {
    813809        try {
     
    822818            } else {
    823819                // Comment exists in DB, but component is not in this registry
    824                 throw new ComponentRegistryException("Comment " + commentId + " cannot be found in specified registry");
     820                throw new ItemNotFoundException("Comment " + commentId + " cannot be found in specified registry");
    825821            }
    826822        } catch (DataAccessException ex) {
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestService.java

    r5549 r5550  
    2828import clarin.cmdi.componentregistry.rss.RssCreatorDescriptions;
    2929import com.google.common.collect.Lists;
     30import com.sun.jersey.api.client.ClientResponse;
     31import com.sun.jersey.api.client.UniformInterfaceException;
    3032
    3133import com.sun.jersey.api.core.InjectParam;
     
    311313                        }
    312314                    };
     315                    return createDownloadResponse(result, fileName);
    313316                } else if ("xsd".equalsIgnoreCase(rawType)) {
    314317                    result = new StreamingOutput() {
     
    344347                        }
    345348                    };
     349                    return createDownloadResponse(result, fileName);
    346350                } else {
    347                     throw new WebApplicationException(Response
    348                             .serverError()
    349                             .entity("unsupported rawType: " + rawType
    350                             + " (only xml or xsd are supported)").build());
     351                    return Response.status(Status.NOT_FOUND).entity("Usupported raw type "+rawType).build();
    351352                }
    352                 return createDownloadResponse(result, fileName);
     353               
    353354
    354355            } catch (UserUnauthorizedException e2) {
     
    876877                    .build();
    877878        } catch (ItemNotFoundException e) {
    878             LOG.warn("Profile with id " + profileId + " is not found.",
    879                     e);
     879            LOG.warn("Profile with id " + profileId + " is not found.");
    880880            return Response.serverError().status(Status.NOT_FOUND)
    881881                    .build();
     
    931931            return Response.serverError().status(Status.FORBIDDEN)
    932932                    .entity("" + e.getMessage()).build();
    933         } catch (ComponentRegistryException e) {
    934             LOG.info("Could not retrieve component", e);
     933        }
     934        catch (ComponentRegistryException e) {
     935            LOG.info("Could not find comment "+commentId+ " for "+profileId);
    935936            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR)
    936937                    .build();
    937         } catch (IOException e) {
     938        }
     939        catch (IOException e) {
    938940            LOG.error("Comment with id: " + commentId + " deletion failed.", e);
    939941            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR)
     
    983985            return Response.serverError().status(Status.FORBIDDEN)
    984986                    .entity("" + e.getMessage()).build();
    985         } catch (ComponentRegistryException e) {
    986             LOG.info("Could not retrieve component", e);
     987        } catch (ComponentRegistryException e) {           
     988            LOG.info("Could not retrieve component "+componentId+" for the component "+componentId);
    987989            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR)
    988990                    .build();
     
    10121014    public Response getRegisteredProfileRawType(
    10131015            @PathParam("profileId") final String profileId,
    1014             @PathParam("rawType") String rawType) throws ComponentRegistryException {
     1016            @PathParam("rawType") String rawType) throws ComponentRegistryException, IllegalArgumentException {
    10151017
    10161018
     
    10641066                };
    10651067            } else {
    1066                 throw new WebApplicationException(Response
    1067                         .serverError()
    1068                         .entity("unsupported rawType: " + rawType
    1069                         + " (only xml or xsd are supported)").build());
     1068                return Response.status(Status.NOT_FOUND).entity("Unsupported raw type "+rawType).build();
    10701069            }
    10711070            return createDownloadResponse(result, fileName);
  • ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestServiceTest.java

    r5549 r5550  
    2424import java.util.Date;
    2525import java.util.List;
     26import javax.ws.rs.WebApplicationException;
    2627
    2728import javax.ws.rs.core.MediaType;
     
    4041 * Launches a servlet container environment and performs HTTP calls to the
    4142 * {@link ComponentRegistryRestService}
    42  * 
     43 *
    4344 * @author george.georgovassilis@mpi.nl
    44  * 
     45 *
    4546 */
    46 public class ComponentRegistryRestServiceTest extends
    47         ComponentRegistryRestServiceTestCase {
     47public class ComponentRegistryRestServiceTest extends ComponentRegistryRestServiceTestCase {
    4848
    4949    @Autowired
     
    5757    @Before
    5858    public void init() {
    59         ComponentRegistryTestDatabase.resetAndCreateAllTables(jdbcTemplate);
    60         createUserRecord();
    61         baseRegistry = componentRegistryFactory.getBaseRegistry(DummyPrincipal.DUMMY_CREDENTIALS);
     59        ComponentRegistryTestDatabase.resetAndCreateAllTables(jdbcTemplate);
     60        createUserRecord();
     61        baseRegistry = componentRegistryFactory.getBaseRegistry(DummyPrincipal.DUMMY_CREDENTIALS);
    6262    }
    6363
    6464    private String expectedUserId(String principal) {
    65         return getUserDao().getByPrincipalName(principal).getId().toString();
    66     }
    67 
     65        return getUserDao().getByPrincipalName(principal).getId().toString();
     66    }
    6867    private ComponentDescription component1;
    6968    private ComponentDescription component2;
    7069    private ProfileDescription profile1;
    7170    private ProfileDescription profile2;
    72    
    7371    private ComponentDescription component3;
    7472    private ProfileDescription profile3;
    75    
    7673    private Comment profile1Comment1;
    7774    private Comment profile1Comment2;
    7875    private Comment component1Comment3;
    7976    private Comment component1Comment4;
    80    
    8177    private Comment profile3Comment5;
    8278    private Comment component3Comment7;
    8379
    8480    private void fillUpPublicItems() throws Exception {
    85        
    86         profile1 = RegistryTestHelper.addProfile(baseRegistry, "profile2", true);
    87         profile2 = RegistryTestHelper.addProfile(baseRegistry, "profile1", true);
    88         component1 = RegistryTestHelper.addComponent(baseRegistry,
    89                 "component2", true);
    90         component2 = RegistryTestHelper.addComponent(baseRegistry,
    91                 "component1", true);
    92         profile1Comment2 = RegistryTestHelper.addComment(baseRegistry, "comment2",
    93                 ProfileDescription.PROFILE_PREFIX + "profile1",
    94                 "JUnit@test.com");
    95         profile1Comment1 = RegistryTestHelper.addComment(baseRegistry, "comment1",
    96                 ProfileDescription.PROFILE_PREFIX + "profile1",
    97                 "JUnit@test.com");
    98         component1Comment3 = RegistryTestHelper.addComment(baseRegistry, "comment3",
    99                 ComponentDescription.COMPONENT_PREFIX + "component1",
    100                 "JUnit@test.com");
    101         component1Comment4 = RegistryTestHelper.addComment(baseRegistry, "comment4",
    102                 ComponentDescription.COMPONENT_PREFIX + "component1",
    103                 "JUnit@test.com");
    104     }
    105    
     81
     82        profile1 = RegistryTestHelper.addProfile(baseRegistry, "profile2", true);
     83        profile2 = RegistryTestHelper.addProfile(baseRegistry, "profile1", true);
     84        component1 = RegistryTestHelper.addComponent(baseRegistry,
     85                "component2", true);
     86        component2 = RegistryTestHelper.addComponent(baseRegistry,
     87                "component1", true);
     88        profile1Comment2 = RegistryTestHelper.addComment(baseRegistry, "comment2",
     89                ProfileDescription.PROFILE_PREFIX + "profile1",
     90                "JUnit@test.com");
     91        profile1Comment1 = RegistryTestHelper.addComment(baseRegistry, "comment1",
     92                ProfileDescription.PROFILE_PREFIX + "profile1",
     93                "JUnit@test.com");
     94        component1Comment3 = RegistryTestHelper.addComment(baseRegistry, "comment3",
     95                ComponentDescription.COMPONENT_PREFIX + "component1",
     96                "JUnit@test.com");
     97        component1Comment4 = RegistryTestHelper.addComment(baseRegistry, "comment4",
     98                ComponentDescription.COMPONENT_PREFIX + "component1",
     99                "JUnit@test.com");
     100    }
     101
    106102    private void fillUpPrivateItems() throws Exception {
    107         profile3 = RegistryTestHelper.addProfile(baseRegistry, "profile3", false);
    108         component3 = RegistryTestHelper.addComponent(baseRegistry,
    109                 "component3", false);
    110         profile3Comment5 = RegistryTestHelper.addComment(baseRegistry, "comment5",
    111                 ProfileDescription.PROFILE_PREFIX + "profile3",
    112                 "JUnit@test.com");
    113         component3Comment7 = RegistryTestHelper.addComment(baseRegistry, "comment7",
    114                 ComponentDescription.COMPONENT_PREFIX + "component3",
    115                 "JUnit@test.com");
    116     }
    117 
    118     @Test//ok
     103        profile3 = RegistryTestHelper.addProfile(baseRegistry, "profile3", false);
     104        component3 = RegistryTestHelper.addComponent(baseRegistry,
     105                "component3", false);
     106        profile3Comment5 = RegistryTestHelper.addComment(baseRegistry, "comment5",
     107                ProfileDescription.PROFILE_PREFIX + "profile3",
     108                "JUnit@test.com");
     109        component3Comment7 = RegistryTestHelper.addComment(baseRegistry, "comment7",
     110                ComponentDescription.COMPONENT_PREFIX + "component3",
     111                "JUnit@test.com");
     112    }
     113
     114    @Test
    119115    public void testGetPublicProfiles() throws Exception {
    120        
    121         fillUpPublicItems();
    122        
    123         RegistryTestHelper.addProfile(baseRegistry, "PROFILE2", true);
    124         List<ProfileDescription> response = this.getAuthenticatedResource(getResource()
    125                 .path("/registry/profiles")).accept(MediaType.APPLICATION_XML)
    126                 .get(PROFILE_LIST_GENERICTYPE);
    127         assertEquals(3, response.size());
    128         response = this.getAuthenticatedResource(getResource()
    129                 .path("/registry/profiles"))
    130                 .accept(MediaType.APPLICATION_JSON)
    131                 .get(PROFILE_LIST_GENERICTYPE);
    132         assertEquals(3, response.size());
    133         assertEquals("profile1", response.get(0).getName());
    134         assertEquals("PROFILE2", response.get(1).getName());
    135         assertEquals("profile2", response.get(2).getName());
     116
     117        System.out.println("testGetPublicProfiles");
     118
     119        fillUpPublicItems();
     120
     121        RegistryTestHelper.addProfile(baseRegistry, "PROFILE2", true);
     122        List<ProfileDescription> response = this.getAuthenticatedResource(getResource()
     123                .path("/registry/profiles")).accept(MediaType.APPLICATION_XML)
     124                .get(PROFILE_LIST_GENERICTYPE);
     125        assertEquals(3, response.size());
     126        response = this.getAuthenticatedResource(getResource()
     127                .path("/registry/profiles"))
     128                .accept(MediaType.APPLICATION_JSON)
     129                .get(PROFILE_LIST_GENERICTYPE);
     130        assertEquals(3, response.size());
     131        assertEquals("profile1", response.get(0).getName());
     132        assertEquals("PROFILE2", response.get(1).getName());
     133        assertEquals("profile2", response.get(2).getName());
    136134    }
    137135
    138136    @Test //ok
    139137    public void testGetPublicComponents() throws Exception {
    140        
    141         fillUpPublicItems();
    142        
     138
     139        System.out.println("testGetPublicComponents");
     140
     141        fillUpPublicItems();
     142
    143143        RegistryTestHelper.addComponent(baseRegistry, "COMPONENT2", true);
    144         List<ComponentDescription> response = this.getAuthenticatedResource(getResource()
    145                 .path("/registry/components")).accept(MediaType.APPLICATION_XML)
    146                 .get(COMPONENT_LIST_GENERICTYPE);
    147         assertEquals(3, response.size());
    148         response = this.getAuthenticatedResource(getResource()
    149                 .path("/registry/components"))
    150                 .accept(MediaType.APPLICATION_JSON)
    151                 .get(COMPONENT_LIST_GENERICTYPE);
    152         assertEquals(3, response.size());
    153         assertEquals("component1", response.get(0).getName());
    154         assertEquals("COMPONENT2", response.get(1).getName());
    155         assertEquals("component2", response.get(2).getName());
     144        List<ComponentDescription> response = this.getAuthenticatedResource(getResource()
     145                .path("/registry/components")).accept(MediaType.APPLICATION_XML)
     146                .get(COMPONENT_LIST_GENERICTYPE);
     147        assertEquals(3, response.size());
     148        response = this.getAuthenticatedResource(getResource()
     149                .path("/registry/components"))
     150                .accept(MediaType.APPLICATION_JSON)
     151                .get(COMPONENT_LIST_GENERICTYPE);
     152        assertEquals(3, response.size());
     153        assertEquals("component1", response.get(0).getName());
     154        assertEquals("COMPONENT2", response.get(1).getName());
     155        assertEquals("component2", response.get(2).getName());
    156156    }
    157157
    158158    @Test  //ok
    159159    public void testGetUserComponents() throws Exception {
    160        
     160
     161        System.out.println("testGetUserComponents");
     162
    161163        fillUpPrivateItems();
    162        
    163         List<ComponentDescription> response = this.getUserComponents();
    164         assertEquals(1, response.size());
    165        
     164
     165        List<ComponentDescription> response = this.getUserComponents();
     166        assertEquals(1, response.size());
     167
    166168        ////
    167        
    168         fillUpPublicItems();
    169         response = getAuthenticatedResource(getResource().path("/registry/components")).accept(
    170                 MediaType.APPLICATION_JSON).get(COMPONENT_LIST_GENERICTYPE);
    171         assertEquals("Get public components", 2, response.size());
    172        
    173         ClientResponse cResponse = getResource().path("/registry/components")
    174                 .queryParam(REGISTRY_SPACE_PARAM, "private")
    175                 .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
    176         assertEquals("Trying to get userspace without credentials", 401,
    177                 cResponse.getStatus());
     169
     170        fillUpPublicItems();
     171        response = getAuthenticatedResource(getResource().path("/registry/components")).accept(
     172                MediaType.APPLICATION_JSON).get(COMPONENT_LIST_GENERICTYPE);
     173        assertEquals("Get public components", 2, response.size());
     174
     175        ClientResponse cResponse = getResource().path("/registry/components")
     176                .queryParam(REGISTRY_SPACE_PARAM, "private")
     177                .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
     178        assertEquals("Trying to get userspace without credentials", 401,
     179                cResponse.getStatus());
    178180    }
    179181
    180182    @Test //ok
    181183    public void testGetPublicComponent() throws Exception {
    182        
    183         fillUpPublicItems();
    184        
     184
     185        System.out.println("testGetPublicComponents");
     186
     187        fillUpPublicItems();
     188
    185189        String id = ComponentDescription.COMPONENT_PREFIX + "component1";
    186         String id2 = ComponentDescription.COMPONENT_PREFIX + "component2";
    187         CMDComponentSpec component = this.getAuthenticatedResource(getResource()
    188                 .path("/registry/components/" + id))
    189                 .accept(MediaType.APPLICATION_JSON).get(CMDComponentSpec.class);
    190         assertNotNull(component);
    191         assertEquals("Access", component.getCMDComponent().getName());
    192        
    193        
    194         component = this.getAuthenticatedResource(getResource().path("/registry/components/" + id2))
    195                 .accept(MediaType.APPLICATION_XML).get(CMDComponentSpec.class);
    196         assertNotNull(component);
    197         assertEquals("Access", component.getCMDComponent().getName());
    198         assertEquals(id2, component.getHeader().getID());
    199         assertEquals("component2", component.getHeader().getName());
    200         assertEquals("Test Description", component.getHeader().getDescription());
     190        String id2 = ComponentDescription.COMPONENT_PREFIX + "component2";
     191        CMDComponentSpec component = this.getAuthenticatedResource(getResource()
     192                .path("/registry/components/" + id))
     193                .accept(MediaType.APPLICATION_JSON).get(CMDComponentSpec.class);
     194        assertNotNull(component);
     195        assertEquals("Access", component.getCMDComponent().getName());
     196
     197
     198        component = this.getAuthenticatedResource(getResource().path("/registry/components/" + id2))
     199                .accept(MediaType.APPLICATION_XML).get(CMDComponentSpec.class);
     200        assertNotNull(component);
     201        assertEquals("Access", component.getCMDComponent().getName());
     202        assertEquals(id2, component.getHeader().getID());
     203        assertEquals("component2", component.getHeader().getName());
     204        assertEquals("Test Description", component.getHeader().getDescription());
    201205    }
    202206
    203207    @Test   // ok   
    204208    public void testGetCommentsInPublicProfile() throws Exception {
    205        
    206         fillUpPublicItems();
    207        
    208         String id = ProfileDescription.PROFILE_PREFIX + "profile1";
    209         RegistryTestHelper.addComment(baseRegistry, "COMMENT1", id,
    210                 "JUnit@test.com");
    211         List<Comment> response = this.getAuthenticatedResource(getResource()
    212                 .path("/registry/profiles/" + id + "/comments/"))
    213                 .accept(MediaType.APPLICATION_XML)
    214                 .get(COMMENT_LIST_GENERICTYPE);
    215         assertEquals(3, response.size());
    216        
    217         response = this.getAuthenticatedResource(getResource().path("/registry/profiles/" + id + "/comments"))
    218                 .accept(MediaType.APPLICATION_JSON)
    219                 .get(COMMENT_LIST_GENERICTYPE);
    220         assertEquals(3, response.size());
    221         assertEquals("comment2", response.get(0).getComment());
    222         assertEquals("comment1", response.get(1).getComment());
    223         assertEquals("COMMENT1", response.get(2).getComment());
    224 
    225         assertEquals("Database test user", response.get(0).getUserName());
     209
     210        System.out.println("testGetCommentsInPublicPrfile");
     211
     212        fillUpPublicItems();
     213
     214        String id = ProfileDescription.PROFILE_PREFIX + "profile1";
     215        RegistryTestHelper.addComment(baseRegistry, "COMMENT1", id,
     216                "JUnit@test.com");
     217        List<Comment> response = this.getAuthenticatedResource(getResource()
     218                .path("/registry/profiles/" + id + "/comments/"))
     219                .accept(MediaType.APPLICATION_XML)
     220                .get(COMMENT_LIST_GENERICTYPE);
     221        assertEquals(3, response.size());
     222
     223        response = this.getAuthenticatedResource(getResource().path("/registry/profiles/" + id + "/comments"))
     224                .accept(MediaType.APPLICATION_JSON)
     225                .get(COMMENT_LIST_GENERICTYPE);
     226        assertEquals(3, response.size());
     227        assertEquals("comment2", response.get(0).getComment());
     228        assertEquals("comment1", response.get(1).getComment());
     229        assertEquals("COMMENT1", response.get(2).getComment());
     230
     231        assertEquals("Database test user", response.get(0).getUserName());
    226232    }
    227233
    228234    @Test // ok
    229235    public void testGetCommentsInPubliComponent() throws Exception {
    230         fillUpPublicItems();
    231        
    232         String id = ComponentDescription.COMPONENT_PREFIX + "component1";
    233         RegistryTestHelper.addComment(baseRegistry, "COMMENT2", id,
    234                 "JUnit@test.com");
    235         List<Comment> response = this.getAuthenticatedResource(getResource()
    236                 .path("/registry/components/" + id + "/comments/"))
    237                 .accept(MediaType.APPLICATION_XML)
    238                 .get(COMMENT_LIST_GENERICTYPE);
    239         assertEquals(3, response.size());
    240         response = this.getAuthenticatedResource(getResource()
    241                 .path("/registry/components/" + id + "/comments"))
    242                 .accept(MediaType.APPLICATION_JSON)
    243                 .get(COMMENT_LIST_GENERICTYPE);
    244         assertEquals(3, response.size());
    245         assertEquals("comment3", response.get(0).getComment());
    246         assertEquals("comment4", response.get(1).getComment());
    247         assertEquals("COMMENT2", response.get(2).getComment());
    248 
    249         assertEquals("Database test user", response.get(0).getUserName());
     236
     237        System.out.println("testGetCoomentsInPublicComponent");
     238
     239        fillUpPublicItems();
     240
     241        String id = ComponentDescription.COMPONENT_PREFIX + "component1";
     242        RegistryTestHelper.addComment(baseRegistry, "COMMENT2", id,
     243                "JUnit@test.com");
     244        List<Comment> response = this.getAuthenticatedResource(getResource()
     245                .path("/registry/components/" + id + "/comments/"))
     246                .accept(MediaType.APPLICATION_XML)
     247                .get(COMMENT_LIST_GENERICTYPE);
     248        assertEquals(3, response.size());
     249        response = this.getAuthenticatedResource(getResource()
     250                .path("/registry/components/" + id + "/comments"))
     251                .accept(MediaType.APPLICATION_JSON)
     252                .get(COMMENT_LIST_GENERICTYPE);
     253        assertEquals(3, response.size());
     254        assertEquals("comment3", response.get(0).getComment());
     255        assertEquals("comment4", response.get(1).getComment());
     256        assertEquals("COMMENT2", response.get(2).getComment());
     257
     258        assertEquals("Database test user", response.get(0).getUserName());
    250259    }
    251260
    252261    @Test // ok
    253262    public void testGetSpecifiedCommentInPublicComponent() throws Exception {
    254        
    255         fillUpPublicItems();
    256        
    257         String id = ComponentDescription.COMPONENT_PREFIX + "component1";
    258         Comment comment = this.getAuthenticatedResource(getResource()
    259                 .path("/registry/components/" + id + "/comments/"+component1Comment3.getId()))
    260                 .accept(MediaType.APPLICATION_JSON).get(Comment.class);
    261         assertNotNull(comment);
    262         assertEquals("comment3", comment.getComment());
    263         assertEquals(component1Comment3.getId(), comment.getId());
    264         comment = this.getAuthenticatedResource(getResource()
    265                 .path("/registry/components/" + id + "/comments/"+component1Comment4.getId()))
    266                 .accept(MediaType.APPLICATION_JSON).get(Comment.class);
    267         assertNotNull(comment);
    268         assertEquals("comment4", comment.getComment());
    269         assertEquals(component1Comment4.getId(), comment.getId());
    270         assertEquals(id, comment.getComponentId());
     263
     264        System.out.println("testSpecifiedCommentInPublicComponent");
     265
     266        fillUpPublicItems();
     267
     268        String id = ComponentDescription.COMPONENT_PREFIX + "component1";
     269        Comment comment = this.getAuthenticatedResource(getResource()
     270                .path("/registry/components/" + id + "/comments/" + component1Comment3.getId()))
     271                .accept(MediaType.APPLICATION_JSON).get(Comment.class);
     272        assertNotNull(comment);
     273        assertEquals("comment3", comment.getComment());
     274        assertEquals(component1Comment3.getId(), comment.getId());
     275        comment = this.getAuthenticatedResource(getResource()
     276                .path("/registry/components/" + id + "/comments/" + component1Comment4.getId()))
     277                .accept(MediaType.APPLICATION_JSON).get(Comment.class);
     278        assertNotNull(comment);
     279        assertEquals("comment4", comment.getComment());
     280        assertEquals(component1Comment4.getId(), comment.getId());
     281        assertEquals(id, comment.getComponentId());
    271282    }
    272283
    273284    @Test //ok
    274285    public void testGetSpecifiedCommentInPublicProfile() throws Exception {
    275        
    276         fillUpPublicItems();
    277        
    278         String id = ProfileDescription.PROFILE_PREFIX + "profile1";
    279         Comment comment = this.getAuthenticatedResource(getResource()
    280                 .path("/registry/profiles/" + id + "/comments/"+profile1Comment2.getId()))
    281                 .accept(MediaType.APPLICATION_JSON).get(Comment.class);
    282         assertNotNull(comment);
    283         assertEquals("comment2", comment.getComment());
    284         assertEquals(profile1Comment2.getId(), comment.getId());
    285        
    286         comment = this.getAuthenticatedResource(getResource()
    287                 .path("/registry/profiles/" + id + "/comments/"+profile1Comment1.getId()))
     286
     287        System.out.println("testGetSpecifiedCoomentInPublicProfile");
     288
     289        fillUpPublicItems();
     290
     291        String id = ProfileDescription.PROFILE_PREFIX + "profile1";
     292        Comment comment = this.getAuthenticatedResource(getResource()
     293                .path("/registry/profiles/" + id + "/comments/" + profile1Comment2.getId()))
    288294                .accept(MediaType.APPLICATION_JSON).get(Comment.class);
    289         assertNotNull(comment);
    290         assertEquals("comment1", comment.getComment());
    291         assertEquals(profile1Comment1.getId(), comment.getId());
    292         assertEquals(id, comment.getComponentId());
     295        assertNotNull(comment);
     296        assertEquals("comment2", comment.getComment());
     297        assertEquals(profile1Comment2.getId(), comment.getId());
     298
     299        comment = this.getAuthenticatedResource(getResource()
     300                .path("/registry/profiles/" + id + "/comments/" + profile1Comment1.getId()))
     301                .accept(MediaType.APPLICATION_JSON).get(Comment.class);
     302        assertNotNull(comment);
     303        assertEquals("comment1", comment.getComment());
     304        assertEquals(profile1Comment1.getId(), comment.getId());
     305        assertEquals(id, comment.getComponentId());
    293306    }
    294307
    295308    @Test  //ok
    296309    public void testDeleteCommentFromPublicComponent() throws Exception {
    297        
    298         fillUpPublicItems();
    299        
    300         String id = ComponentDescription.COMPONENT_PREFIX + "component1";
    301         String id2 = ComponentDescription.COMPONENT_PREFIX + "component2";
    302         List<Comment> comments = this.getAuthenticatedResource(getResource().path(
    303                 "/registry/components/" + id + "/comments")).get(
    304                 COMMENT_LIST_GENERICTYPE);
    305         assertEquals(2, comments.size());
    306         Comment aComment = this.getAuthenticatedResource(getResource().path(
    307                 "/registry/components/" + id + "/comments/"+component1Comment3.getId()))
    308                 .get(Comment.class);
    309         assertNotNull(aComment);
    310 
    311         // Try to delete from other component
    312         ClientResponse response = getAuthenticatedResource(
    313                 "/registry/components/" + id2 + "/comments/"+component1Comment4.getId()).delete(
    314                 ClientResponse.class);
    315         assertEquals(500, response.getStatus());
    316         // Delete from correct component
    317         response = getAuthenticatedResource(
    318                 "/registry/components/" + id + "/comments/"+component1Comment3.getId()).delete(
    319                 ClientResponse.class);
    320         assertEquals(200, response.getStatus());
    321 
    322         comments = this.getAuthenticatedResource(getResource().path(
    323                 "/registry/components/" + id + "/comments/")).get(
    324                 COMMENT_LIST_GENERICTYPE);
    325         assertEquals(1, comments.size());
    326 
    327         response = getAuthenticatedResource(
    328                 "/registry/components/" + id + "/comments/"+component1Comment4.getId()).delete(
    329                 ClientResponse.class);
    330         assertEquals(200, response.getStatus());
    331 
    332         comments = this.getAuthenticatedResource(getResource().path(
    333                 "/registry/components/" + id + "/comments")).get(
    334                 COMMENT_LIST_GENERICTYPE);
    335         assertEquals(0, comments.size());
     310
     311        System.out.println("testDeleteCommentFromPublicComponent");
     312
     313        fillUpPublicItems();
     314
     315        String id = ComponentDescription.COMPONENT_PREFIX + "component1";
     316        String id2 = ComponentDescription.COMPONENT_PREFIX + "component2";
     317        List<Comment> comments = this.getAuthenticatedResource(getResource().path(
     318                "/registry/components/" + id + "/comments")).get(
     319                COMMENT_LIST_GENERICTYPE);
     320        assertEquals(2, comments.size());
     321        Comment aComment = this.getAuthenticatedResource(getResource().path(
     322                "/registry/components/" + id + "/comments/" + component1Comment3.getId()))
     323                .get(Comment.class);
     324        assertNotNull(aComment);
     325
     326        // Try to delete from other component
     327        ClientResponse response = getAuthenticatedResource(
     328                "/registry/components/" + id2 + "/comments/" + component1Comment4.getId()).delete(
     329                ClientResponse.class);
     330        assertEquals(500, response.getStatus());
     331        // Delete from correct component
     332        response = getAuthenticatedResource(
     333                "/registry/components/" + id + "/comments/" + component1Comment3.getId()).delete(
     334                ClientResponse.class);
     335        assertEquals(200, response.getStatus());
     336
     337        comments = this.getAuthenticatedResource(getResource().path(
     338                "/registry/components/" + id + "/comments/")).get(
     339                COMMENT_LIST_GENERICTYPE);
     340        assertEquals(1, comments.size());
     341
     342        response = getAuthenticatedResource(
     343                "/registry/components/" + id + "/comments/" + component1Comment4.getId()).delete(
     344                ClientResponse.class);
     345        assertEquals(200, response.getStatus());
     346
     347        comments = this.getAuthenticatedResource(getResource().path(
     348                "/registry/components/" + id + "/comments")).get(
     349                COMMENT_LIST_GENERICTYPE);
     350        assertEquals(0, comments.size());
    336351    }
    337352
    338353    @Test
    339354    public void testManipulateCommentFromPublicComponent() throws Exception {
    340        
    341         fillUpPublicItems();
    342        
    343         List<Comment> comments = this.getAuthenticatedResource(getResource().path(
    344                 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX
    345                         + "component1/comments")).get(COMMENT_LIST_GENERICTYPE);
    346         assertEquals(2, comments.size());
    347         Comment aComment = this.getAuthenticatedResource(getResource().path(
    348                 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX
    349                         + "component1/comments/"+component1Comment3.getId())).get(Comment.class);
    350         assertNotNull(aComment);
    351 
    352         Form manipulateForm = new Form();
    353         manipulateForm.add("method", "delete");
    354 
    355         // Try to delete from other component
    356         ClientResponse response = getAuthenticatedResource(
    357                 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX
    358                         + "component1/comments/"+component1Comment3.getId()).post(ClientResponse.class,
    359                 manipulateForm);
    360         assertEquals(200, response.getStatus());
    361 
    362         comments = this.getAuthenticatedResource(getResource().path(
    363                 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX
    364                         + "component1/comments/")).get(COMMENT_LIST_GENERICTYPE);
    365         assertEquals(1, comments.size());
     355
     356        System.out.println("testManipulateCommentFromPublicComponent");
     357
     358        fillUpPublicItems();
     359
     360        List<Comment> comments = this.getAuthenticatedResource(getResource().path(
     361                "/registry/components/" + ComponentDescription.COMPONENT_PREFIX
     362                + "component1/comments")).get(COMMENT_LIST_GENERICTYPE);
     363        assertEquals(2, comments.size());
     364        Comment aComment = this.getAuthenticatedResource(getResource().path(
     365                "/registry/components/" + ComponentDescription.COMPONENT_PREFIX
     366                + "component1/comments/" + component1Comment3.getId())).get(Comment.class);
     367        assertNotNull(aComment);
     368
     369        Form manipulateForm = new Form();
     370        manipulateForm.add("method", "delete");
     371
     372        // Try to delete from other component
     373        ClientResponse response = getAuthenticatedResource(
     374                "/registry/components/" + ComponentDescription.COMPONENT_PREFIX
     375                + "component1/comments/" + component1Comment3.getId()).post(ClientResponse.class,
     376                manipulateForm);
     377        assertEquals(200, response.getStatus());
     378
     379        comments = this.getAuthenticatedResource(getResource().path(
     380                "/registry/components/" + ComponentDescription.COMPONENT_PREFIX
     381                + "component1/comments/")).get(COMMENT_LIST_GENERICTYPE);
     382        assertEquals(1, comments.size());
    366383    }
    367384
    368385    @Test
    369386    public void testDeleteCommentFromPublicProfile() throws Exception {
    370        
    371         fillUpPublicItems();
    372        
    373         List<Comment> comments = this.getAuthenticatedResource(getResource().path(
    374                 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
    375                         + "profile1/comments")).get(COMMENT_LIST_GENERICTYPE);
    376         assertEquals(2, comments.size());
    377         Comment aComment = this.getAuthenticatedResource(getResource().path(
    378                 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
    379                         + "profile1/comments/"+profile1Comment1.getId())).get(Comment.class);
    380         assertNotNull(aComment);
    381 
    382         // Try to delete from other profile
    383         ClientResponse response = getAuthenticatedResource(
    384                 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
    385                         + "profile2/comments/9999").delete(ClientResponse.class);
    386         assertEquals(500, response.getStatus());
    387         // Delete from correct profile
    388         response = getAuthenticatedResource(
    389                 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
    390                         + "profile1/comments/"+profile1Comment1.getId()).delete(ClientResponse.class);
    391         assertEquals(200, response.getStatus());
    392 
    393         comments = this.getAuthenticatedResource(getResource().path(
    394                 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
    395                         + "profile1/comments/")).get(COMMENT_LIST_GENERICTYPE);
    396         assertEquals(1, comments.size());
    397 
    398         response = getAuthenticatedResource(
    399                 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
    400                         + "profile1/comments/"+profile1Comment2.getId()).delete(ClientResponse.class);
    401         assertEquals(200, response.getStatus());
    402 
    403         comments = this.getAuthenticatedResource(getResource().path(
    404                 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
    405                         + "profile1/comments")).get(COMMENT_LIST_GENERICTYPE);
    406         assertEquals(0, comments.size());
     387
     388        System.out.println("testDeleteCommentFromPublicProfile");
     389
     390        fillUpPublicItems();
     391
     392        List<Comment> comments = this.getAuthenticatedResource(getResource().path(
     393                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
     394                + "profile1/comments")).get(COMMENT_LIST_GENERICTYPE);
     395        assertEquals(2, comments.size());
     396        Comment aComment = this.getAuthenticatedResource(getResource().path(
     397                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
     398                + "profile1/comments/" + profile1Comment1.getId())).get(Comment.class);
     399        assertNotNull(aComment);
     400
     401        // Try to delete from other profile
     402        ClientResponse response = getAuthenticatedResource(
     403                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
     404                + "profile2/comments/9999").delete(ClientResponse.class);
     405        assertEquals(500, response.getStatus());
     406        // Delete from correct profile
     407        response = getAuthenticatedResource(
     408                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
     409                + "profile1/comments/" + profile1Comment1.getId()).delete(ClientResponse.class);
     410        assertEquals(200, response.getStatus());
     411
     412        comments = this.getAuthenticatedResource(getResource().path(
     413                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
     414                + "profile1/comments/")).get(COMMENT_LIST_GENERICTYPE);
     415        assertEquals(1, comments.size());
     416
     417        response = getAuthenticatedResource(
     418                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
     419                + "profile1/comments/" + profile1Comment2.getId()).delete(ClientResponse.class);
     420        assertEquals(200, response.getStatus());
     421
     422        comments = this.getAuthenticatedResource(getResource().path(
     423                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
     424                + "profile1/comments")).get(COMMENT_LIST_GENERICTYPE);
     425        assertEquals(0, comments.size());
    407426    }
    408427
    409428    @Test
    410429    public void testManipulateCommentFromPublicProfile() throws Exception {
    411        
    412         fillUpPublicItems();
    413        
    414         List<Comment> comments = this.getAuthenticatedResource(getResource().path(
    415                 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
    416                         + "profile1/comments")).get(COMMENT_LIST_GENERICTYPE);
    417         assertEquals(2, comments.size());
    418         Comment aComment = this.getAuthenticatedResource(getResource().path(
    419                 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
    420                         + "profile1/comments/"+profile1Comment2.getId())).get(Comment.class);
    421         assertNotNull(aComment);
    422 
    423         Form manipulateForm = new Form();
    424         manipulateForm.add("method", "delete");
    425         // Delete from correct profile
    426         ClientResponse response = getAuthenticatedResource(
    427                 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
    428                         + "profile1/comments/"+profile1Comment2.getId()).post(ClientResponse.class,
    429                 manipulateForm);
    430         assertEquals(200, response.getStatus());
    431 
    432         comments = this.getAuthenticatedResource(getResource().path(
    433                 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
    434                         + "profile1/comments/")).get(COMMENT_LIST_GENERICTYPE);
    435         assertEquals(1, comments.size());
     430
     431        System.out.println("testManipulatreCommentFromPublicProfile");
     432
     433        fillUpPublicItems();
     434
     435        List<Comment> comments = this.getAuthenticatedResource(getResource().path(
     436                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
     437                + "profile1/comments")).get(COMMENT_LIST_GENERICTYPE);
     438        assertEquals(2, comments.size());
     439        Comment aComment = this.getAuthenticatedResource(getResource().path(
     440                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
     441                + "profile1/comments/" + profile1Comment2.getId())).get(Comment.class);
     442        assertNotNull(aComment);
     443
     444        Form manipulateForm = new Form();
     445        manipulateForm.add("method", "delete");
     446        // Delete from correct profile
     447        ClientResponse response = getAuthenticatedResource(
     448                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
     449                + "profile1/comments/" + profile1Comment2.getId()).post(ClientResponse.class,
     450                manipulateForm);
     451        assertEquals(200, response.getStatus());
     452
     453        comments = this.getAuthenticatedResource(getResource().path(
     454                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
     455                + "profile1/comments/")).get(COMMENT_LIST_GENERICTYPE);
     456        assertEquals(1, comments.size());
    436457    }
    437458
    438459    @Test
    439460    public void testDeletePublicComponent() throws Exception {
    440        
    441         fillUpPublicItems();
    442        
    443         List<ComponentDescription> components = this.getAuthenticatedResource(getResource().path(
    444                 "/registry/components")).get(COMPONENT_LIST_GENERICTYPE);
    445         assertEquals(2, components.size());
    446         CMDComponentSpec profile = this.getAuthenticatedResource(getResource().path(
    447                 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX
    448                         + "component1")).get(CMDComponentSpec.class);
    449         assertNotNull(profile);
    450         ClientResponse response = getAuthenticatedResource(
    451                 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX
    452                         + "component1").delete(ClientResponse.class);
    453         assertEquals(200, response.getStatus());
    454 
    455         components = this.getAuthenticatedResource(getResource().path("/registry/components")).get(
    456                 COMPONENT_LIST_GENERICTYPE);
    457         assertEquals(1, components.size());
    458 
    459         response = getAuthenticatedResource(
    460                 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX
    461                         + "component2").delete(ClientResponse.class);
    462         assertEquals(200, response.getStatus());
    463 
    464         components = this.getAuthenticatedResource(getResource().path("/registry/components")).get(
    465                 COMPONENT_LIST_GENERICTYPE);
    466         assertEquals(0, components.size());
    467 
    468         response = getAuthenticatedResource(
    469                 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX
    470                         + "component1").delete(ClientResponse.class);
    471         assertEquals(200, response.getStatus());
     461
     462        System.out.println("testDeletePublicComponent");
     463
     464        fillUpPublicItems();
     465
     466        List<ComponentDescription> components = this.getAuthenticatedResource(getResource().path(
     467                "/registry/components")).get(COMPONENT_LIST_GENERICTYPE);
     468        assertEquals(2, components.size());
     469        CMDComponentSpec profile = this.getAuthenticatedResource(getResource().path(
     470                "/registry/components/" + ComponentDescription.COMPONENT_PREFIX
     471                + "component1")).get(CMDComponentSpec.class);
     472        assertNotNull(profile);
     473        ClientResponse response = getAuthenticatedResource(
     474                "/registry/components/" + ComponentDescription.COMPONENT_PREFIX
     475                + "component1").delete(ClientResponse.class);
     476        assertEquals(200, response.getStatus());
     477
     478        components = this.getAuthenticatedResource(getResource().path("/registry/components")).get(
     479                COMPONENT_LIST_GENERICTYPE);
     480        assertEquals(1, components.size());
     481
     482        response = getAuthenticatedResource(
     483                "/registry/components/" + ComponentDescription.COMPONENT_PREFIX
     484                + "component2").delete(ClientResponse.class);
     485        assertEquals(200, response.getStatus());
     486
     487        components = this.getAuthenticatedResource(getResource().path("/registry/components")).get(
     488                COMPONENT_LIST_GENERICTYPE);
     489        assertEquals(0, components.size());
     490
     491        response = getAuthenticatedResource(
     492                "/registry/components/" + ComponentDescription.COMPONENT_PREFIX
     493                + "component1").delete(ClientResponse.class);
     494        assertEquals(200, response.getStatus());
    472495    }
    473496
    474497    @Test
    475498    public void testDeletePublicComponentStillUsed() throws Exception {
    476        
    477         fillUpPublicItems();
    478        
     499
     500        System.out.println("testDeletePublicComponentStillUsed");
     501
     502        fillUpPublicItems();
     503
    479504        String content = "";
    480         content += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
    481         content += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n";
    482         content += "    <Header/>\n";
    483         content += "    <CMD_Component name=\"XXX\" CardinalityMin=\"1\" CardinalityMax=\"10\">\n";
    484         content += "        <CMD_Element name=\"Availability\" ValueScheme=\"string\" />\n";
    485         content += "    </CMD_Component>\n";
    486         content += "</CMD_ComponentSpec>\n";
    487         ComponentDescription compDesc1 = RegistryTestHelper.addComponent(
    488                 baseRegistry, "XXX1", content, true);
    489 
    490         content = "";
    491         content += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
    492         content += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n";
    493         content += "    <Header/>\n";
    494         content += "    <CMD_Component name=\"YYY\" CardinalityMin=\"1\" CardinalityMax=\"unbounded\">\n";
    495         content += "        <CMD_Component ComponentId=\"" + compDesc1.getId()
    496                 + "\" CardinalityMin=\"0\" CardinalityMax=\"99\">\n";
    497         content += "        </CMD_Component>\n";
    498         content += "    </CMD_Component>\n";
    499         content += "</CMD_ComponentSpec>\n";
    500         ComponentDescription compDesc2 = RegistryTestHelper.addComponent(
    501                 baseRegistry, "YYY1", content,true);
    502 
    503         content = "";
    504         content += "<CMD_ComponentSpec isProfile=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
    505         content += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n";
    506         content += "    <Header/>\n";
    507         content += "    <CMD_Component name=\"ZZZ\" CardinalityMin=\"1\" CardinalityMax=\"unbounded\">\n";
    508         content += "        <CMD_Component ComponentId=\"" + compDesc1.getId()
    509                 + "\" CardinalityMin=\"0\" CardinalityMax=\"99\">\n";
    510         content += "        </CMD_Component>\n";
    511         content += "    </CMD_Component>\n";
    512         content += "</CMD_ComponentSpec>\n";
    513         ProfileDescription profile = RegistryTestHelper.addProfile(
    514                 baseRegistry, "TestProfile3", content, true);
    515 
    516         List<ComponentDescription> components = this.getAuthenticatedResource(getResource().path(
    517                 "/registry/components")).get(COMPONENT_LIST_GENERICTYPE);
    518         assertEquals(4, components.size());
    519 
    520         ClientResponse response = getAuthenticatedResource(
    521                 "/registry/components/" + compDesc1.getId()).delete(
    522                 ClientResponse.class);
    523         assertEquals(Status.FORBIDDEN.getStatusCode(), response.getStatus());
    524         assertEquals(
    525                 "Component is still in use by other components or profiles. Request component usage for details.",
    526                 response.getEntity(String.class));
    527 
    528         components = this.getAuthenticatedResource(getResource().path("/registry/components")).get(
    529                 COMPONENT_LIST_GENERICTYPE);
    530         assertEquals(4, components.size());
    531 
    532         response = getAuthenticatedResource(
    533                 "/registry/profiles/" + profile.getId()).delete(
    534                 ClientResponse.class);
    535         assertEquals(200, response.getStatus());
    536         response = getAuthenticatedResource(
    537                 "/registry/components/" + compDesc2.getId()).delete(
    538                 ClientResponse.class);
    539         assertEquals(200, response.getStatus());
    540         response = getAuthenticatedResource(
    541                 "/registry/components/" + compDesc1.getId()).delete(
    542                 ClientResponse.class);
    543         assertEquals(200, response.getStatus());
    544         components = this.getAuthenticatedResource(getResource().path("/registry/components")).get(
    545                 COMPONENT_LIST_GENERICTYPE);
    546         assertEquals(2, components.size());
     505        content += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
     506        content += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n";
     507        content += "    <Header/>\n";
     508        content += "    <CMD_Component name=\"XXX\" CardinalityMin=\"1\" CardinalityMax=\"10\">\n";
     509        content += "        <CMD_Element name=\"Availability\" ValueScheme=\"string\" />\n";
     510        content += "    </CMD_Component>\n";
     511        content += "</CMD_ComponentSpec>\n";
     512        ComponentDescription compDesc1 = RegistryTestHelper.addComponent(
     513                baseRegistry, "XXX1", content, true);
     514
     515        content = "";
     516        content += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
     517        content += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n";
     518        content += "    <Header/>\n";
     519        content += "    <CMD_Component name=\"YYY\" CardinalityMin=\"1\" CardinalityMax=\"unbounded\">\n";
     520        content += "        <CMD_Component ComponentId=\"" + compDesc1.getId()
     521                + "\" CardinalityMin=\"0\" CardinalityMax=\"99\">\n";
     522        content += "        </CMD_Component>\n";
     523        content += "    </CMD_Component>\n";
     524        content += "</CMD_ComponentSpec>\n";
     525        ComponentDescription compDesc2 = RegistryTestHelper.addComponent(
     526                baseRegistry, "YYY1", content, true);
     527
     528        content = "";
     529        content += "<CMD_ComponentSpec isProfile=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
     530        content += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n";
     531        content += "    <Header/>\n";
     532        content += "    <CMD_Component name=\"ZZZ\" CardinalityMin=\"1\" CardinalityMax=\"unbounded\">\n";
     533        content += "        <CMD_Component ComponentId=\"" + compDesc1.getId()
     534                + "\" CardinalityMin=\"0\" CardinalityMax=\"99\">\n";
     535        content += "        </CMD_Component>\n";
     536        content += "    </CMD_Component>\n";
     537        content += "</CMD_ComponentSpec>\n";
     538        ProfileDescription profile = RegistryTestHelper.addProfile(
     539                baseRegistry, "TestProfile3", content, true);
     540
     541        List<ComponentDescription> components = this.getAuthenticatedResource(getResource().path(
     542                "/registry/components")).get(COMPONENT_LIST_GENERICTYPE);
     543        assertEquals(4, components.size());
     544
     545        ClientResponse response = getAuthenticatedResource(
     546                "/registry/components/" + compDesc1.getId()).delete(
     547                ClientResponse.class);
     548        assertEquals(Status.FORBIDDEN.getStatusCode(), response.getStatus());
     549        assertEquals(
     550                "Component is still in use by other components or profiles. Request component usage for details.",
     551                response.getEntity(String.class));
     552
     553        components = this.getAuthenticatedResource(getResource().path("/registry/components")).get(
     554                COMPONENT_LIST_GENERICTYPE);
     555        assertEquals(4, components.size());
     556
     557        response = getAuthenticatedResource(
     558                "/registry/profiles/" + profile.getId()).delete(
     559                ClientResponse.class);
     560        assertEquals(200, response.getStatus());
     561        response = getAuthenticatedResource(
     562                "/registry/components/" + compDesc2.getId()).delete(
     563                ClientResponse.class);
     564        assertEquals(200, response.getStatus());
     565        response = getAuthenticatedResource(
     566                "/registry/components/" + compDesc1.getId()).delete(
     567                ClientResponse.class);
     568        assertEquals(200, response.getStatus());
     569        components = this.getAuthenticatedResource(getResource().path("/registry/components")).get(
     570                COMPONENT_LIST_GENERICTYPE);
     571        assertEquals(2, components.size());
    547572    }
    548573
    549574    @Test
    550575    public void testManipulatePublicComponent() throws Exception {
    551        
    552         fillUpPublicItems();
    553        
    554         List<ComponentDescription> components = this.getAuthenticatedResource(getResource().path(
    555                 "/registry/components")).get(COMPONENT_LIST_GENERICTYPE);
    556         assertEquals(2, components.size());
    557         CMDComponentSpec profile = this.getAuthenticatedResource(getResource().path(
    558                 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX
    559                         + "component1")).get(CMDComponentSpec.class);
    560         assertNotNull(profile);
    561 
    562         Form manipulateForm = new Form();
    563         manipulateForm.add("method", "delete");
    564 
    565         ClientResponse response = getAuthenticatedResource(
    566                 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX
    567                         + "component1").post(ClientResponse.class,
    568                 manipulateForm);
    569         assertEquals(200, response.getStatus());
    570 
    571         components = this.getAuthenticatedResource(getResource().path("/registry/components")).get(
    572                 COMPONENT_LIST_GENERICTYPE);
    573         assertEquals(1, components.size());
    574 
    575         response = getAuthenticatedResource(
    576                 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX
    577                         + "component2").post(ClientResponse.class,
    578                 manipulateForm);
    579         assertEquals(200, response.getStatus());
     576
     577        System.out.println("testManipulatePublicComponent");
     578
     579        fillUpPublicItems();
     580
     581        List<ComponentDescription> components = this.getAuthenticatedResource(getResource().path(
     582                "/registry/components")).get(COMPONENT_LIST_GENERICTYPE);
     583        assertEquals(2, components.size());
     584        CMDComponentSpec profile = this.getAuthenticatedResource(getResource().path(
     585                "/registry/components/" + ComponentDescription.COMPONENT_PREFIX
     586                + "component1")).get(CMDComponentSpec.class);
     587        assertNotNull(profile);
     588
     589        Form manipulateForm = new Form();
     590        manipulateForm.add("method", "delete");
     591
     592        ClientResponse response = getAuthenticatedResource(
     593                "/registry/components/" + ComponentDescription.COMPONENT_PREFIX
     594                + "component1").post(ClientResponse.class,
     595                manipulateForm);
     596        assertEquals(200, response.getStatus());
     597
     598        components = this.getAuthenticatedResource(getResource().path("/registry/components")).get(
     599                COMPONENT_LIST_GENERICTYPE);
     600        assertEquals(1, components.size());
     601
     602        response = getAuthenticatedResource(
     603                "/registry/components/" + ComponentDescription.COMPONENT_PREFIX
     604                + "component2").post(ClientResponse.class,
     605                manipulateForm);
     606        assertEquals(200, response.getStatus());
    580607    }
    581608
    582609    @Test
    583610    public void testGetRegisteredProfile() throws Exception {
    584        
    585         fillUpPublicItems();
    586        
    587         String id = ProfileDescription.PROFILE_PREFIX + "profile1";
    588         String id2 = ProfileDescription.PROFILE_PREFIX + "profile2";
    589         CMDComponentSpec profile = this.getAuthenticatedResource(getResource()
    590                 .path("/registry/profiles/" + id))
    591                 .accept(MediaType.APPLICATION_JSON).get(CMDComponentSpec.class);
    592         assertNotNull(profile);
    593         assertEquals("Actor", profile.getCMDComponent().getName());
    594         profile = this.getAuthenticatedResource(getResource().path("/registry/profiles/" + id2))
    595                 .accept(MediaType.APPLICATION_XML).get(CMDComponentSpec.class);
    596         assertNotNull(profile);
    597         assertEquals("Actor", profile.getCMDComponent().getName());
    598 
    599         assertEquals(id2, profile.getHeader().getID());
    600         assertEquals("profile2", profile.getHeader().getName());
    601         assertEquals("Test Description", profile.getHeader().getDescription());
    602 
    603         try {
    604             profile = this.getAuthenticatedResource(getResource()
    605                     .path("/registry/profiles/"
    606                             + ProfileDescription.PROFILE_PREFIX + "profileXXXX"))
    607                     .accept(MediaType.APPLICATION_XML)
    608                     .get(CMDComponentSpec.class);
    609             fail("Exception should have been thrown resource does not exist, HttpStatusCode 404");
    610         } catch (UniformInterfaceException e) {
    611             assertEquals(404, e.getResponse().getStatus());
    612         }
    613     }
    614 
    615     @Test
    616     public void testGetRegisteredProfileRawData() throws Exception {
    617        
    618         fillUpPublicItems();
    619        
    620         String profile = this.getAuthenticatedResource(getResource()
    621                 .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
    622                         + "profile1/xsd")).accept(MediaType.TEXT_XML)
    623                 .get(String.class).trim();
    624         assertTrue(profile
    625                 .startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?><xs:schema"));
    626         assertTrue(profile.endsWith("</xs:schema>"));
    627 
    628         profile = this.getAuthenticatedResource(getResource()
    629                 .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
    630                         + "profile1/xml")).accept(MediaType.TEXT_XML)
    631                 .get(String.class).trim();
    632         assertTrue(profile
    633                 .startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<CMD_ComponentSpec"));
    634         assertTrue(profile.endsWith("</CMD_ComponentSpec>"));
    635         assertTrue(profile.contains("xsi:schemaLocation"));
    636 
    637         try {
    638             this.getAuthenticatedResource(getResource()
    639                     .path("/registry/components/"
    640                             + ComponentDescription.COMPONENT_PREFIX
    641                             + "component1/xsl")).accept(MediaType.TEXT_XML)
    642                     .get(String.class);
    643             fail("Should have thrown exception, unsupported path parameter");
    644         } catch (UniformInterfaceException e) {// server error
    645         }
     611
     612        System.out.println("testGetRegisteredProfile");
     613
     614        fillUpPublicItems();
     615
     616        String id = ProfileDescription.PROFILE_PREFIX + "profile1";
     617        String id2 = ProfileDescription.PROFILE_PREFIX + "profile2";
     618        CMDComponentSpec profile = this.getAuthenticatedResource(getResource()
     619                .path("/registry/profiles/" + id))
     620                .accept(MediaType.APPLICATION_JSON).get(CMDComponentSpec.class);
     621        assertNotNull(profile);
     622        assertEquals("Actor", profile.getCMDComponent().getName());
     623        profile = this.getAuthenticatedResource(getResource().path("/registry/profiles/" + id2))
     624                .accept(MediaType.APPLICATION_XML).get(CMDComponentSpec.class);
     625        assertNotNull(profile);
     626        assertEquals("Actor", profile.getCMDComponent().getName());
     627
     628        assertEquals(id2, profile.getHeader().getID());
     629        assertEquals("profile2", profile.getHeader().getName());
     630        assertEquals("Test Description", profile.getHeader().getDescription());
     631
     632        try {
     633            profile = this.getAuthenticatedResource(getResource()
     634                    .path("/registry/profiles/"
     635                    + ProfileDescription.PROFILE_PREFIX + "profileXXXX"))
     636                    .accept(MediaType.APPLICATION_XML)
     637                    .get(CMDComponentSpec.class);
     638            fail("Exception should have been thrown resource does not exist, HttpStatusCode 404");
     639        } catch (UniformInterfaceException e) {
     640            assertEquals(404, e.getResponse().getStatus());
     641        }
     642    }
     643
     644    @Test
     645    public void testGetRegisteredProfileRawData() {
     646
     647        System.out.println("testGetRegisteredProfileRawData");
     648
     649        try {
     650            fillUpPublicItems();
     651        } catch (Exception e) {
     652            System.out.println("test fails due to exception: " + e.getMessage());
     653            return;
     654        }
     655
     656        String profile = this.getAuthenticatedResource(getResource()
     657                .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
     658                + "profile1/xsd")).accept(MediaType.TEXT_XML)
     659                .get(String.class).trim();
     660        assertTrue(profile
     661                .startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?><xs:schema"));
     662        assertTrue(profile.endsWith("</xs:schema>"));
     663
     664        profile = this.getAuthenticatedResource(getResource()
     665                .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
     666                + "profile1/xml")).accept(MediaType.TEXT_XML)
     667                .get(String.class).trim();
     668        assertTrue(profile
     669                .startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<CMD_ComponentSpec"));
     670        assertTrue(profile.endsWith("</CMD_ComponentSpec>"));
     671        assertTrue(profile.contains("xsi:schemaLocation"));
     672
     673
     674        ClientResponse respie = this.getAuthenticatedResource(getResource()
     675                .path("/registry/profiles/"
     676                + ProfileDescription.PROFILE_PREFIX
     677                + "profile1/xsl")).accept(MediaType.TEXT_XML).head();
     678        assertEquals(404, respie.getStatus());
    646679    }
    647680
    648681    //
    649682    @Test
    650     public void testPrivateProfileXsd() throws Exception {
    651        
    652         fillUpPublicItems();
    653        
    654         FormDataMultiPart form = createFormData(RegistryTestHelper
    655                 .getTestProfileContent());
    656         RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/profiles").queryParam(
    657                         REGISTRY_SPACE_PARAM, "private")).type(
    658                 MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class,
    659                 form);
    660         assertTrue(response.isProfile());
    661         assertEquals(1, getUserProfiles().size());
    662         BaseDescription desc = response.getDescription();
    663         String profile = this.getAuthenticatedResource(getResource()
    664                 .path("/registry/profiles/" + desc.getId() + "/xsd"))
    665                 .accept(MediaType.TEXT_XML).get(String.class).trim();
    666         assertTrue(profile
    667                 .startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?><xs:schema"));
    668         assertTrue(profile.endsWith("</xs:schema>"));
     683    public void testPrivateProfileXsd() {
     684
     685        System.out.println("testPrivateProfileXsd");
     686
     687        try {
     688            fillUpPublicItems();
     689        } catch (Exception e) {
     690            System.out.println("test fails due to exception: " + e.getMessage());
     691            return;
     692        }
     693
     694        FormDataMultiPart form = createFormData(RegistryTestHelper
     695                .getTestProfileContent());
     696        RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/profiles").queryParam(
     697                REGISTRY_SPACE_PARAM, "private")).type(
     698                MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class,
     699                form);
     700        assertTrue(response.isProfile());
     701        assertEquals(1, getUserProfiles().size());
     702        BaseDescription desc = response.getDescription();
     703        String profile = this.getAuthenticatedResource(getResource()
     704                .path("/registry/profiles/" + desc.getId() + "/xsd"))
     705                .accept(MediaType.TEXT_XML).get(String.class).trim();
     706        assertTrue(profile
     707                .startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?><xs:schema"));
     708        assertTrue(profile.endsWith("</xs:schema>"));
    669709    }
    670710
    671711    @Test
    672712    public void testPrivateComponentXsd() throws Exception {
    673        
    674         fillUpPublicItems();
    675        
    676         FormDataMultiPart form = createFormData(RegistryTestHelper
    677                 .getComponentTestContent());
    678         RegisterResponse response = getAuthenticatedResource(
    679                 getResource().path("/registry/components").queryParam(
    680                         REGISTRY_SPACE_PARAM, "private")).type(
    681                 MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class,
    682                 form);
    683         assertFalse(response.isProfile());
    684         assertEquals(1, getUserComponents().size());
    685         BaseDescription desc = response.getDescription();
    686         String profile = this.getAuthenticatedResource(getResource()
    687                 .path("/registry/components/" + desc.getId() + "/xsd"))
    688                 .accept(MediaType.TEXT_XML).get(String.class).trim();
    689         assertTrue(profile
    690                 .startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?><xs:schema"));
    691         assertTrue(profile.endsWith("</xs:schema>"));
     713
     714        System.out.println("testPrivateComponentXsd");
     715
     716        fillUpPublicItems();
     717
     718        FormDataMultiPart form = createFormData(RegistryTestHelper
     719                .getComponentTestContent());
     720        RegisterResponse response = getAuthenticatedResource(
     721                getResource().path("/registry/components").queryParam(
     722                REGISTRY_SPACE_PARAM, "private")).type(
     723                MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class,
     724                form);
     725        assertFalse(response.isProfile());
     726        assertEquals(1, getUserComponents().size());
     727        BaseDescription desc = response.getDescription();
     728        String profile = this.getAuthenticatedResource(getResource()
     729                .path("/registry/components/" + desc.getId() + "/xsd"))
     730                .accept(MediaType.TEXT_XML).get(String.class).trim();
     731        assertTrue(profile
     732                .startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?><xs:schema"));
     733        assertTrue(profile.endsWith("</xs:schema>"));
    692734    }
    693735
    694736    @Test
    695737    public void testDeleteRegisteredProfile() throws Exception {
    696        
    697         fillUpPublicItems();
    698        
    699         List<ProfileDescription> profiles = this.getAuthenticatedResource(getResource().path(
    700                 "/registry/profiles")).get(PROFILE_LIST_GENERICTYPE);
    701         assertEquals(2, profiles.size());
    702         CMDComponentSpec profile = this.getAuthenticatedResource(getResource().path(
    703                 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
    704                         + "profile1")).get(CMDComponentSpec.class);
    705         assertNotNull(profile);
    706 
    707         ClientResponse response = getAuthenticatedResource(
    708                 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
    709                         + "profile1").delete(ClientResponse.class);
    710         assertEquals(200, response.getStatus());
    711 
    712         profiles = this.getAuthenticatedResource(getResource().path("/registry/profiles")).get(
    713                 PROFILE_LIST_GENERICTYPE);
    714         assertEquals(1, profiles.size());
    715 
    716         response = getAuthenticatedResource(
    717                 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
    718                         + "profile2").delete(ClientResponse.class);
    719         assertEquals(200, response.getStatus());
    720 
    721         profiles = this.getAuthenticatedResource(getResource().path("/registry/profiles")).get(
    722                 PROFILE_LIST_GENERICTYPE);
    723         assertEquals(0, profiles.size());
    724 
    725         response = getAuthenticatedResource(
    726                 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
    727                         + "profile1").delete(ClientResponse.class);
    728         assertEquals(404, response.getStatus());
     738
     739        System.out.println("testDeleteRegistredProfile");
     740
     741        fillUpPublicItems();
     742
     743        List<ProfileDescription> profiles = this.getAuthenticatedResource(getResource().path(
     744                "/registry/profiles")).get(PROFILE_LIST_GENERICTYPE);
     745        assertEquals(2, profiles.size());
     746        CMDComponentSpec profile = this.getAuthenticatedResource(getResource().path(
     747                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
     748                + "profile1")).get(CMDComponentSpec.class);
     749        assertNotNull(profile);
     750
     751        ClientResponse response = getAuthenticatedResource(
     752                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
     753                + "profile1").delete(ClientResponse.class);
     754        assertEquals(200, response.getStatus());
     755
     756        profiles = this.getAuthenticatedResource(getResource().path("/registry/profiles")).get(
     757                PROFILE_LIST_GENERICTYPE);
     758        assertEquals(1, profiles.size());
     759
     760        response = getAuthenticatedResource(
     761                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
     762                + "profile2").delete(ClientResponse.class);
     763        assertEquals(200, response.getStatus());
     764
     765        profiles = this.getAuthenticatedResource(getResource().path("/registry/profiles")).get(
     766                PROFILE_LIST_GENERICTYPE);
     767        assertEquals(0, profiles.size());
     768
     769        response = getAuthenticatedResource(
     770                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
     771                + "profile1").delete(ClientResponse.class);
     772        assertEquals(404, response.getStatus());
    729773    }
    730774
    731775    @Test
    732776    public void testManipulateRegisteredProfile() throws Exception {
    733        
    734         fillUpPublicItems();
    735        
    736         List<ProfileDescription> profiles = this.getAuthenticatedResource(getResource().path(
    737                 "/registry/profiles")).get(PROFILE_LIST_GENERICTYPE);
    738         assertEquals(2, profiles.size());
    739         CMDComponentSpec profile = this.getAuthenticatedResource(getResource().path(
    740                 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
    741                         + "profile1")).get(CMDComponentSpec.class);
    742         assertNotNull(profile);
    743 
    744         Form manipulateForm = new Form();
    745         manipulateForm.add("method", "delete");
    746 
    747         ClientResponse response = getAuthenticatedResource(
    748                 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
    749                         + "profile1")
    750                 .post(ClientResponse.class, manipulateForm);
    751         assertEquals(200, response.getStatus());
    752 
    753         profiles = this.getAuthenticatedResource(getResource().path("/registry/profiles")).get(
    754                 PROFILE_LIST_GENERICTYPE);
    755         assertEquals(1, profiles.size());
    756 
    757         response = getAuthenticatedResource(
    758                 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
    759                         + "profile2")
    760                 .post(ClientResponse.class, manipulateForm);
    761         assertEquals(200, response.getStatus());
     777
     778        System.out.println("testManipulateRegisteredProfile");
     779
     780        fillUpPublicItems();
     781
     782        List<ProfileDescription> profiles = this.getAuthenticatedResource(getResource().path(
     783                "/registry/profiles")).get(PROFILE_LIST_GENERICTYPE);
     784        assertEquals(2, profiles.size());
     785        CMDComponentSpec profile = this.getAuthenticatedResource(getResource().path(
     786                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
     787                + "profile1")).get(CMDComponentSpec.class);
     788        assertNotNull(profile);
     789
     790        Form manipulateForm = new Form();
     791        manipulateForm.add("method", "delete");
     792
     793        ClientResponse response = getAuthenticatedResource(
     794                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
     795                + "profile1")
     796                .post(ClientResponse.class, manipulateForm);
     797        assertEquals(200, response.getStatus());
     798
     799        profiles = this.getAuthenticatedResource(getResource().path("/registry/profiles")).get(
     800                PROFILE_LIST_GENERICTYPE);
     801        assertEquals(1, profiles.size());
     802
     803        response = getAuthenticatedResource(
     804                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
     805                + "profile2")
     806                .post(ClientResponse.class, manipulateForm);
     807        assertEquals(200, response.getStatus());
    762808    }
    763809
    764810    @Test
    765811    public void testGetRegisteredComponentRawData() throws Exception {
    766        
    767         fillUpPublicItems();
    768        
    769         String id = ComponentDescription.COMPONENT_PREFIX + "component1";
    770         String component = this.getAuthenticatedResource(getResource()
    771                 .path("/registry/components/" + id + "/xsd"))
    772                 .accept(MediaType.TEXT_XML).get(String.class).trim();
    773         assertTrue(component
    774                 .startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?><xs:schema"));
    775         assertTrue(component.endsWith("</xs:schema>"));
    776 
    777         component = this.getAuthenticatedResource(getResource().path("/registry/components/" + id + "/xml"))
    778                 .accept(MediaType.TEXT_XML).get(String.class).trim();
    779         assertTrue(component
    780                 .startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<CMD_ComponentSpec"));
    781         assertTrue(component.endsWith("</CMD_ComponentSpec>"));
    782         assertTrue(component.contains("xsi:schemaLocation"));
    783 
    784         try {
    785             this.getAuthenticatedResource(getResource()
    786                     .path("/registry/components/"
    787                             + ComponentDescription.COMPONENT_PREFIX
    788                             + "component1/jpg")).accept(MediaType.TEXT_XML)
    789                     .get(String.class);
    790             fail("Should have thrown exception, unsopported path parameter");
    791         } catch (UniformInterfaceException e) {
    792         }
     812
     813        System.out.println("testGetRegisteredComponentRawData");
     814
     815        fillUpPublicItems();
     816
     817        String id = ComponentDescription.COMPONENT_PREFIX + "component1";
     818        String component = this.getAuthenticatedResource(getResource()
     819                .path("/registry/components/" + id + "/xsd"))
     820                .accept(MediaType.TEXT_XML).get(String.class).trim();
     821        assertTrue(component
     822                .startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?><xs:schema"));
     823        assertTrue(component.endsWith("</xs:schema>"));
     824
     825        component = this.getAuthenticatedResource(getResource().path("/registry/components/" + id + "/xml"))
     826                .accept(MediaType.TEXT_XML).get(String.class).trim();
     827        assertTrue(component
     828                .startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<CMD_ComponentSpec"));
     829        assertTrue(component.endsWith("</CMD_ComponentSpec>"));
     830        assertTrue(component.contains("xsi:schemaLocation"));
     831
     832        ClientResponse respie = this.getAuthenticatedResource(getResource()
     833                    .path("/registry/components/"
     834                    + ComponentDescription.COMPONENT_PREFIX
     835                    + "component1/jpg")).accept(MediaType.TEXT_XML)
     836                    .head();
     837       assertEquals(404, respie.getStatus());
    793838    }
    794839
    795840    @Test
    796841    public void testRegisterProfile() throws Exception {
    797        
    798         fillUpPublicItems();
    799        
    800         FormDataMultiPart form = new FormDataMultiPart();
    801         form.field(IComponentRegistryRestService.DATA_FORM_FIELD,
    802                 RegistryTestHelper.getTestProfileContent(),
    803                 MediaType.APPLICATION_OCTET_STREAM_TYPE);
    804         form.field(IComponentRegistryRestService.NAME_FORM_FIELD,
    805                 "ProfileTest1");
    806         form.field(IComponentRegistryRestService.DOMAIN_FORM_FIELD,
    807                 "TestDomain");
    808         form.field(IComponentRegistryRestService.DESCRIPTION_FORM_FIELD,
    809                 "My Test Profile");
    810         form.field(IComponentRegistryRestService.GROUP_FORM_FIELD,
    811                 "My Test Group");
    812         RegisterResponse response = getAuthenticatedResource(
    813                 "/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post(
    814                 RegisterResponse.class, form);
    815         assertTrue(response.isProfile());
    816         assertTrue(response.isInUserSpace());
    817         ProfileDescription profileDesc = (ProfileDescription) response
    818                 .getDescription();
    819         assertNotNull(profileDesc);
    820         assertEquals("ProfileTest1", profileDesc.getName());
    821         assertEquals("My Test Profile", profileDesc.getDescription());
    822         assertEquals("TestDomain", profileDesc.getDomainName());
    823         assertEquals("My Test Group", profileDesc.getGroupName());
    824         assertEquals(expectedUserId("JUnit@test.com"), profileDesc.getUserId());
    825         assertEquals("Database test user", profileDesc.getCreatorName());
    826         assertTrue(profileDesc.getId().startsWith(
    827                 ComponentRegistry.REGISTRY_ID + "p_"));
    828         assertNotNull(profileDesc.getRegistrationDate());
    829         assertEquals(
    830                 "http://localhost:9998/registry/profiles/"
    831                         + profileDesc.getId(), profileDesc.getHref());
     842
     843        System.out.println("testRegisterProfile");
     844
     845        fillUpPublicItems();
     846
     847        FormDataMultiPart form = new FormDataMultiPart();
     848        form.field(IComponentRegistryRestService.DATA_FORM_FIELD,
     849                RegistryTestHelper.getTestProfileContent(),
     850                MediaType.APPLICATION_OCTET_STREAM_TYPE);
     851        form.field(IComponentRegistryRestService.NAME_FORM_FIELD,
     852                "ProfileTest1");
     853        form.field(IComponentRegistryRestService.DOMAIN_FORM_FIELD,
     854                "TestDomain");
     855        form.field(IComponentRegistryRestService.DESCRIPTION_FORM_FIELD,
     856                "My Test Profile");
     857        form.field(IComponentRegistryRestService.GROUP_FORM_FIELD,
     858                "My Test Group");
     859        RegisterResponse response = getAuthenticatedResource(
     860                "/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post(
     861                RegisterResponse.class, form);
     862        assertTrue(response.isProfile());
     863        assertTrue(response.isInUserSpace());
     864        ProfileDescription profileDesc = (ProfileDescription) response
     865                .getDescription();
     866        assertNotNull(profileDesc);
     867        assertEquals("ProfileTest1", profileDesc.getName());
     868        assertEquals("My Test Profile", profileDesc.getDescription());
     869        assertEquals("TestDomain", profileDesc.getDomainName());
     870        assertEquals("My Test Group", profileDesc.getGroupName());
     871        assertEquals(expectedUserId("JUnit@test.com"), profileDesc.getUserId());
     872        assertEquals("Database test user", profileDesc.getCreatorName());
     873        assertTrue(profileDesc.getId().startsWith(
     874                ComponentRegistry.REGISTRY_ID + "p_"));
     875        assertNotNull(profileDesc.getRegistrationDate());
     876        assertEquals(
     877                "http://localhost:9998/registry/profiles/"
     878                + profileDesc.getId(), profileDesc.getHref());
    832879    }
    833880
    834881    @Test
    835882    public void testPublishProfile() throws Exception {
    836        
     883
     884        System.out.println("testPublishProfile");
     885
    837886        fillUpPrivateItems();
    838887        fillUpPublicItems();
    839        
    840         assertEquals("user registered profiles", 1, getUserProfiles().size());
    841         assertEquals("public registered profiles", 2, getPublicProfiles()
    842                 .size());
    843         FormDataMultiPart form = createFormData(
    844                 RegistryTestHelper.getTestProfileContent(), "Unpublished");
    845         RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/profiles")).type(
    846                 MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class,
    847                 form);
    848         assertTrue(response.isProfile());
    849         BaseDescription desc = response.getDescription();
    850         assertEquals("Unpublished", desc.getDescription());
    851         assertEquals(2, getUserProfiles().size());
    852         assertEquals(2, getPublicProfiles().size());
    853         form = createFormData(
    854                 RegistryTestHelper.getTestProfileContent("publishedName"),
    855                 "Published");
    856         response = getAuthenticatedResource(getResource().path(
    857                         "/registry/profiles/" + desc.getId() + "/publish"))
    858                 .type(MediaType.MULTIPART_FORM_DATA).post(
    859                         RegisterResponse.class, form);
    860 
    861         assertEquals(1, getUserProfiles().size());
    862         List<ProfileDescription> profiles = getPublicProfiles();
    863         assertEquals(3, profiles.size());
    864         ProfileDescription profileDescription = profiles.get(2);
    865         assertNotNull(profileDescription.getId());
    866         assertEquals(desc.getId(), profileDescription.getId());
    867         assertEquals("http://localhost:9998/registry/profiles/" + desc.getId(),
    868                 profileDescription.getHref());
    869         assertEquals("Published", profileDescription.getDescription());
    870         CMDComponentSpec spec = getPublicSpec(profileDescription);
    871         assertEquals("publishedName", spec.getCMDComponent().getName());
     888
     889        assertEquals("user registered profiles", 1, getUserProfiles().size());
     890        assertEquals("public registered profiles", 2, getPublicProfiles()
     891                .size());
     892        FormDataMultiPart form = createFormData(
     893                RegistryTestHelper.getTestProfileContent(), "Unpublished");
     894        RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/profiles")).type(
     895                MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class,
     896                form);
     897        assertTrue(response.isProfile());
     898        BaseDescription desc = response.getDescription();
     899        assertEquals("Unpublished", desc.getDescription());
     900        assertEquals(2, getUserProfiles().size());
     901        assertEquals(2, getPublicProfiles().size());
     902        form = createFormData(
     903                RegistryTestHelper.getTestProfileContent("publishedName"),
     904                "Published");
     905        response = getAuthenticatedResource(getResource().path(
     906                "/registry/profiles/" + desc.getId() + "/publish"))
     907                .type(MediaType.MULTIPART_FORM_DATA).post(
     908                RegisterResponse.class, form);
     909
     910        assertEquals(1, getUserProfiles().size());
     911        List<ProfileDescription> profiles = getPublicProfiles();
     912        assertEquals(3, profiles.size());
     913        ProfileDescription profileDescription = profiles.get(2);
     914        assertNotNull(profileDescription.getId());
     915        assertEquals(desc.getId(), profileDescription.getId());
     916        assertEquals("http://localhost:9998/registry/profiles/" + desc.getId(),
     917                profileDescription.getHref());
     918        assertEquals("Published", profileDescription.getDescription());
     919        CMDComponentSpec spec = getPublicSpec(profileDescription);
     920        assertEquals("publishedName", spec.getCMDComponent().getName());
    872921    }
    873922
    874923    private CMDComponentSpec getPublicSpec(BaseDescription desc) {
    875         if (desc.isProfile()) {
    876             return this.getAuthenticatedResource(getResource().path("/registry/profiles/" + desc.getId()))
    877                     .get(CMDComponentSpec.class);
    878         } else {
    879             return this.getAuthenticatedResource(getResource().path("/registry/components/" + desc.getId()))
    880                     .get(CMDComponentSpec.class);
    881         }
     924        if (desc.isProfile()) {
     925            return this.getAuthenticatedResource(getResource().path("/registry/profiles/" + desc.getId()))
     926                    .get(CMDComponentSpec.class);
     927        } else {
     928            return this.getAuthenticatedResource(getResource().path("/registry/components/" + desc.getId()))
     929                    .get(CMDComponentSpec.class);
     930        }
    882931    }
    883932
    884933    @Test
    885934    public void testPublishRegisteredComponent() throws Exception {
    886        
     935
     936        System.out.println("testPublishRegisteredComponent");
     937
    887938        fillUpPrivateItems();
    888939        fillUpPublicItems();
    889        
    890         assertEquals(1, getUserComponents().size());
    891         assertEquals(2, getPublicComponents().size());
    892        
    893         FormDataMultiPart form = createFormData(
    894                 RegistryTestHelper.getComponentTestContent(), "Unpublished");
    895         RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/components")).type(
    896                 MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class,
    897                 form);
    898         assertFalse(response.isProfile());
    899         BaseDescription desc = response.getDescription();
    900         assertEquals("Unpublished", desc.getDescription());
    901         assertEquals(2, getUserComponents().size());
    902         assertEquals(2, getPublicComponents().size());
    903         form = createFormData(
    904                 RegistryTestHelper.getComponentTestContentAsStream("publishedName"),
    905                 "Published");
    906         response = getAuthenticatedResource(getResource().path(
    907                         "/registry/components/" + desc.getId() + "/publish"))
    908                 .type(MediaType.MULTIPART_FORM_DATA).post(
    909                         RegisterResponse.class, form);
    910 
    911         assertEquals(1, getUserComponents().size());
    912         List<ComponentDescription> components = getPublicComponents();
    913         assertEquals(3, components.size());
    914         ComponentDescription componentDescription = components.get(2);
    915         assertNotNull(componentDescription.getId());
    916         assertEquals(desc.getId(), componentDescription.getId());
    917         assertEquals(
    918                 "http://localhost:9998/registry/components/" + desc.getId(),
    919                 componentDescription.getHref());
    920         assertEquals("Published", componentDescription.getDescription());
    921         CMDComponentSpec spec = getPublicSpec(componentDescription);
    922         assertEquals("publishedName", spec.getCMDComponent().getName());
     940
     941        assertEquals(1, getUserComponents().size());
     942        assertEquals(2, getPublicComponents().size());
     943
     944        FormDataMultiPart form = createFormData(
     945                RegistryTestHelper.getComponentTestContent(), "Unpublished");
     946        RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/components")).type(
     947                MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class,
     948                form);
     949        assertFalse(response.isProfile());
     950        BaseDescription desc = response.getDescription();
     951        assertEquals("Unpublished", desc.getDescription());
     952        assertEquals(2, getUserComponents().size());
     953        assertEquals(2, getPublicComponents().size());
     954        form = createFormData(
     955                RegistryTestHelper.getComponentTestContentAsStream("publishedName"),
     956                "Published");
     957        response = getAuthenticatedResource(getResource().path(
     958                "/registry/components/" + desc.getId() + "/publish"))
     959                .type(MediaType.MULTIPART_FORM_DATA).post(
     960                RegisterResponse.class, form);
     961
     962        assertEquals(1, getUserComponents().size());
     963        List<ComponentDescription> components = getPublicComponents();
     964        assertEquals(3, components.size());
     965        ComponentDescription componentDescription = components.get(2);
     966        assertNotNull(componentDescription.getId());
     967        assertEquals(desc.getId(), componentDescription.getId());
     968        assertEquals(
     969                "http://localhost:9998/registry/components/" + desc.getId(),
     970                componentDescription.getHref());
     971        assertEquals("Published", componentDescription.getDescription());
     972        CMDComponentSpec spec = getPublicSpec(componentDescription);
     973        assertEquals("publishedName", spec.getCMDComponent().getName());
    923974    }
    924975
     
    926977    @Test
    927978    public void testRegisterUserspaceProfile() throws Exception {
    928        
     979
     980        System.out.println("testRegisterUserspacProfile");
     981
    929982        fillUpPrivateItems();
    930983        fillUpPublicItems();
    931        
    932         List<ProfileDescription> profiles = getUserProfiles();
    933         assertEquals("user registered profiles", 1, profiles.size());
    934         assertEquals("public registered profiles", 2, getPublicProfiles()
    935                 .size());
    936         FormDataMultiPart form = createFormData(RegistryTestHelper
    937                 .getTestProfileContent());
    938         RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/profiles")).type(
    939                 MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class,
    940                 form);
    941         assertTrue(response.isProfile());
    942         assertTrue(response.isInUserSpace());
    943         ProfileDescription profileDesc = (ProfileDescription) response
    944                 .getDescription();
    945         assertNotNull(profileDesc);
    946         assertEquals("Test1", profileDesc.getName());
    947         assertEquals("My Test", profileDesc.getDescription());
    948         assertEquals(expectedUserId("JUnit@test.com"), profileDesc.getUserId());
    949         assertEquals("Database test user", profileDesc.getCreatorName());
    950         assertTrue(profileDesc.getId().startsWith(
    951                 ComponentRegistry.REGISTRY_ID + "p_"));
    952         assertNotNull(profileDesc.getRegistrationDate());
    953         assertEquals(
    954                 "http://localhost:9998/registry/profiles/"
    955                         + profileDesc.getId(),
    956                 profileDesc.getHref());
    957 
    958         profiles = getUserProfiles();
    959         assertEquals(2, profiles.size());
    960         assertEquals(2, getPublicProfiles().size());
    961 
    962         // Try to post unauthenticated
    963         ClientResponse cResponse = getResource().path("/registry/profiles")
    964                 .type(MediaType.MULTIPART_FORM_DATA)
    965                 .post(ClientResponse.class, form);
    966         assertEquals(401, cResponse.getStatus());
    967 
    968        
    969        
    970         CMDComponentSpec spec = getAuthenticatedResource(getResource().path("/registry/profiles/" + profileDesc.getId())
    971                         .queryParam(REGISTRY_SPACE_PARAM, "private")).accept(
    972                 MediaType.APPLICATION_XML).get(CMDComponentSpec.class);
    973         assertNotNull(spec);
    974 
    975         cResponse = this.getAuthenticatedResource(getResource()
    976                 .path("/registry/profiles/" + profileDesc.getId() + "/xsd"))
    977                 .accept(MediaType.TEXT_XML).get(ClientResponse.class);
    978         assertEquals(200, cResponse.getStatus());
    979         String profile = cResponse.getEntity(String.class);
    980         assertTrue(profile.length() > 0);
    981 
    982         profile = getAuthenticatedResource(getResource().path(
    983                         "/registry/profiles/" + profileDesc.getId() + "/xml"))
    984                 .accept(MediaType.TEXT_XML).get(String.class);
    985         assertTrue(profile.length() > 0);
    986 
    987         cResponse = getAuthenticatedResource(getResource().path("/registry/profiles/" + profileDesc.getId())
    988                         .queryParam(REGISTRY_SPACE_PARAM, "private")).delete(
    989                 ClientResponse.class);
    990         assertEquals(200, cResponse.getStatus());
    991 
    992         profiles = getUserProfiles();
    993         assertEquals(1, profiles.size());
     984
     985        List<ProfileDescription> profiles = getUserProfiles();
     986        assertEquals("user registered profiles", 1, profiles.size());
     987        assertEquals("public registered profiles", 2, getPublicProfiles()
     988                .size());
     989        FormDataMultiPart form = createFormData(RegistryTestHelper
     990                .getTestProfileContent());
     991        RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/profiles")).type(
     992                MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class,
     993                form);
     994        assertTrue(response.isProfile());
     995        assertTrue(response.isInUserSpace());
     996        ProfileDescription profileDesc = (ProfileDescription) response
     997                .getDescription();
     998        assertNotNull(profileDesc);
     999        assertEquals("Test1", profileDesc.getName());
     1000        assertEquals("My Test", profileDesc.getDescription());
     1001        assertEquals(expectedUserId("JUnit@test.com"), profileDesc.getUserId());
     1002        assertEquals("Database test user", profileDesc.getCreatorName());
     1003        assertTrue(profileDesc.getId().startsWith(
     1004                ComponentRegistry.REGISTRY_ID + "p_"));
     1005        assertNotNull(profileDesc.getRegistrationDate());
     1006        assertEquals(
     1007                "http://localhost:9998/registry/profiles/"
     1008                + profileDesc.getId(),
     1009                profileDesc.getHref());
     1010
     1011        profiles = getUserProfiles();
     1012        assertEquals(2, profiles.size());
     1013        assertEquals(2, getPublicProfiles().size());
     1014
     1015        // Try to post unauthenticated
     1016        ClientResponse cResponse = getResource().path("/registry/profiles")
     1017                .type(MediaType.MULTIPART_FORM_DATA)
     1018                .post(ClientResponse.class, form);
     1019        assertEquals(401, cResponse.getStatus());
     1020
     1021
     1022
     1023        CMDComponentSpec spec = getAuthenticatedResource(getResource().path("/registry/profiles/" + profileDesc.getId())
     1024                .queryParam(REGISTRY_SPACE_PARAM, "private")).accept(
     1025                MediaType.APPLICATION_XML).get(CMDComponentSpec.class);
     1026        assertNotNull(spec);
     1027
     1028        cResponse = this.getAuthenticatedResource(getResource()
     1029                .path("/registry/profiles/" + profileDesc.getId() + "/xsd"))
     1030                .accept(MediaType.TEXT_XML).get(ClientResponse.class);
     1031        assertEquals(200, cResponse.getStatus());
     1032        String profile = cResponse.getEntity(String.class);
     1033        assertTrue(profile.length() > 0);
     1034
     1035        profile = getAuthenticatedResource(getResource().path(
     1036                "/registry/profiles/" + profileDesc.getId() + "/xml"))
     1037                .accept(MediaType.TEXT_XML).get(String.class);
     1038        assertTrue(profile.length() > 0);
     1039
     1040        cResponse = getAuthenticatedResource(getResource().path("/registry/profiles/" + profileDesc.getId())
     1041                .queryParam(REGISTRY_SPACE_PARAM, "private")).delete(
     1042                ClientResponse.class);
     1043        assertEquals(200, cResponse.getStatus());
     1044
     1045        profiles = getUserProfiles();
     1046        assertEquals(1, profiles.size());
    9941047    }
    9951048
    9961049    private List<ProfileDescription> getPublicProfiles() {
    997         return getAuthenticatedResource("/registry/profiles").accept(
    998                 MediaType.APPLICATION_XML).get(PROFILE_LIST_GENERICTYPE);
     1050        return getAuthenticatedResource("/registry/profiles").accept(
     1051                MediaType.APPLICATION_XML).get(PROFILE_LIST_GENERICTYPE);
    9991052    }
    10001053
    10011054    private List<ProfileDescription> getUserProfiles() {
    1002         return getAuthenticatedResource(getResource().path("/registry/profiles").queryParam(
    1003                         REGISTRY_SPACE_PARAM, "private")).accept(
    1004                 MediaType.APPLICATION_XML).get(PROFILE_LIST_GENERICTYPE);
     1055        return getAuthenticatedResource(getResource().path("/registry/profiles").queryParam(
     1056                REGISTRY_SPACE_PARAM, "private")).accept(
     1057                MediaType.APPLICATION_XML).get(PROFILE_LIST_GENERICTYPE);
    10051058    }
    10061059
    10071060    private FormDataMultiPart createFormData(Object content) {
    1008         return createFormData(content, "My Test");
     1061        return createFormData(content, "My Test");
    10091062    }
    10101063
    10111064    private FormDataMultiPart createFormData(Object content, String description) {
    1012         FormDataMultiPart form = new FormDataMultiPart();
    1013         form.field(IComponentRegistryRestService.DATA_FORM_FIELD, content,
    1014                 MediaType.APPLICATION_OCTET_STREAM_TYPE);
    1015         form.field(IComponentRegistryRestService.NAME_FORM_FIELD, "Test1");
    1016         form.field(IComponentRegistryRestService.DESCRIPTION_FORM_FIELD,
    1017                 description);
    1018         form.field(IComponentRegistryRestService.DOMAIN_FORM_FIELD, "My domain");
    1019         form.field(IComponentRegistryRestService.GROUP_FORM_FIELD, "TestGroup");
    1020         return form;
     1065        FormDataMultiPart form = new FormDataMultiPart();
     1066        form.field(IComponentRegistryRestService.DATA_FORM_FIELD, content,
     1067                MediaType.APPLICATION_OCTET_STREAM_TYPE);
     1068        form.field(IComponentRegistryRestService.NAME_FORM_FIELD, "Test1");
     1069        form.field(IComponentRegistryRestService.DESCRIPTION_FORM_FIELD,
     1070                description);
     1071        form.field(IComponentRegistryRestService.DOMAIN_FORM_FIELD, "My domain");
     1072        form.field(IComponentRegistryRestService.GROUP_FORM_FIELD, "TestGroup");
     1073        return form;
    10211074    }
    10221075
    10231076    @Test
    10241077    public void testRegisterWithUserComponents() throws Exception {
     1078
     1079        System.out.println("testRegisterWithUserComponents");
     1080
    10251081        fillUpPrivateItems();
    1026        
     1082
    10271083        // kid component, not public
    1028         String content = "";
    1029         content += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
    1030         content += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n";
    1031         content += "    <Header/>\n";
    1032         content += "    <CMD_Component name=\"XXX\" CardinalityMin=\"1\" CardinalityMax=\"10\">\n";
    1033         content += "        <CMD_Element name=\"Availability\" ValueScheme=\"string\" />\n";
    1034         content += "    </CMD_Component>\n";
    1035         content += "</CMD_ComponentSpec>\n";
    1036         ComponentDescription compDesc1 = RegistryTestHelper.addComponent(
    1037                 baseRegistry, "XXX1", content, false);
     1084        String content = "";
     1085        content += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
     1086        content += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n";
     1087        content += "    <Header/>\n";
     1088        content += "    <CMD_Component name=\"XXX\" CardinalityMin=\"1\" CardinalityMax=\"10\">\n";
     1089        content += "        <CMD_Element name=\"Availability\" ValueScheme=\"string\" />\n";
     1090        content += "    </CMD_Component>\n";
     1091        content += "</CMD_ComponentSpec>\n";
     1092        ComponentDescription compDesc1 = RegistryTestHelper.addComponent(
     1093                baseRegistry, "XXX1", content, false);
    10381094
    10391095        // a containing component, referring to the kid (which is not public, so the containing component cannot be registered
    1040         content = "";
    1041         content += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
    1042         content += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n";
    1043         content += "    <Header/>\n";
    1044         content += "    <CMD_Component name=\"YYY\" CardinalityMin=\"1\" CardinalityMax=\"unbounded\">\n";
    1045         content += "        <CMD_Component ComponentId=\"" + compDesc1.getId()
    1046                 + "\" CardinalityMin=\"0\" CardinalityMax=\"99\">\n";
    1047         content += "        </CMD_Component>\n";
    1048         content += "    </CMD_Component>\n";
    1049         content += "</CMD_ComponentSpec>\n";
    1050         FormDataMultiPart form = createFormData(content);
    1051         RegisterResponse response = getAuthenticatedResource(
    1052                 "/registry/components").type(MediaType.MULTIPART_FORM_DATA)
    1053                 .post(RegisterResponse.class, form);
     1096        content = "";
     1097        content += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
     1098        content += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n";
     1099        content += "    <Header/>\n";
     1100        content += "    <CMD_Component name=\"YYY\" CardinalityMin=\"1\" CardinalityMax=\"unbounded\">\n";
     1101        content += "        <CMD_Component ComponentId=\"" + compDesc1.getId()
     1102                + "\" CardinalityMin=\"0\" CardinalityMax=\"99\">\n";
     1103        content += "        </CMD_Component>\n";
     1104        content += "    </CMD_Component>\n";
     1105        content += "</CMD_ComponentSpec>\n";
     1106        FormDataMultiPart form = createFormData(content);
     1107        RegisterResponse response = getAuthenticatedResource(
     1108                "/registry/components").type(MediaType.MULTIPART_FORM_DATA)
     1109                .post(RegisterResponse.class, form);
    10541110        // we first alway register in a private space, so reference to a private component should work
    1055         assertTrue(response.isRegistered());
     1111        assertTrue(response.isRegistered());
    10561112
    10571113
    10581114        /// profiles ///
    1059         content = "";
    1060         content += "<CMD_ComponentSpec isProfile=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
    1061         content += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n";
    1062         content += "    <Header/>\n";
    1063         content += "    <CMD_Component name=\"ZZZ\" CardinalityMin=\"1\" CardinalityMax=\"unbounded\">\n";
    1064         content += "        <CMD_Component ComponentId=\"" + compDesc1.getId()
    1065                 + "\" CardinalityMin=\"0\" CardinalityMax=\"99\">\n";
    1066         content += "        </CMD_Component>\n";
    1067         content += "    </CMD_Component>\n";
    1068         content += "</CMD_ComponentSpec>\n";
    1069 
    1070         form = createFormData(content);
    1071         response = getAuthenticatedResource("/registry/profiles").type(
    1072                 MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class,
    1073                 form);
    1074         assertTrue(response.isRegistered());
     1115        content = "";
     1116        content += "<CMD_ComponentSpec isProfile=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
     1117        content += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n";
     1118        content += "    <Header/>\n";
     1119        content += "    <CMD_Component name=\"ZZZ\" CardinalityMin=\"1\" CardinalityMax=\"unbounded\">\n";
     1120        content += "        <CMD_Component ComponentId=\"" + compDesc1.getId()
     1121                + "\" CardinalityMin=\"0\" CardinalityMax=\"99\">\n";
     1122        content += "        </CMD_Component>\n";
     1123        content += "    </CMD_Component>\n";
     1124        content += "</CMD_ComponentSpec>\n";
     1125
     1126        form = createFormData(content);
     1127        response = getAuthenticatedResource("/registry/profiles").type(
     1128                MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class,
     1129                form);
     1130        assertTrue(response.isRegistered());
    10751131
    10761132    }
     
    10781134    @Test
    10791135    public void testRegisterUserspaceComponent() throws Exception {
    1080        
     1136
     1137        System.out.println("testREgisterUserspaceComponent");
     1138
    10811139        fillUpPrivateItems();
    1082        
    1083         List<ComponentDescription> components = getUserComponents();
    1084         assertEquals("user registered components", 1, components.size());
    1085         assertEquals("public registered components", 0, getPublicComponents()
    1086                 .size());
    1087         FormDataMultiPart form = createFormData(RegistryTestHelper
    1088                 .getComponentTestContent());
    1089 
    1090         RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/components")).type(
    1091                 MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class,
    1092                 form);
    1093         assertTrue(response.isRegistered());
    1094         assertFalse(response.isProfile());
    1095         assertTrue(response.isInUserSpace());
    1096         ComponentDescription desc = (ComponentDescription) response
    1097                 .getDescription();
    1098         assertNotNull(desc);
    1099         assertEquals("Test1", desc.getName());
    1100         assertEquals("My Test", desc.getDescription());
    1101         assertEquals(expectedUserId("JUnit@test.com"), desc.getUserId());
    1102         assertEquals("Database test user", desc.getCreatorName());
    1103         assertEquals("TestGroup", desc.getGroupName());
    1104         assertTrue(desc.getId()
    1105                 .startsWith(ComponentRegistry.REGISTRY_ID + "c_"));
    1106         assertNotNull(desc.getRegistrationDate());
    1107         String url = getResource().getUriBuilder().build().toString();
    1108         assertEquals(url + "registry/components/" + desc.getId(), desc.getHref());
    1109 
    1110         components = getUserComponents();
    1111         assertEquals(2, components.size());
    1112         assertEquals(0, getPublicComponents().size());
    1113 
    1114         // Try to post unauthenticated
    1115         ClientResponse cResponse = getResource().path("/registry/components")
    1116                 .type(MediaType.MULTIPART_FORM_DATA)
    1117                 .post(ClientResponse.class, form);
    1118         assertEquals(401, cResponse.getStatus());
    1119 
    1120         // Try to get
    1121         cResponse = this.getAuthenticatedResource(getResource().path("/registry/components/" + desc.getId()))
    1122                 .accept(MediaType.APPLICATION_XML).get(ClientResponse.class);
    1123        
    1124         assertEquals(200, cResponse.getStatus());
    1125         CMDComponentSpec spec = getUserComponent(desc);
    1126         assertNotNull(spec);
    1127 
    1128         cResponse = this.getAuthenticatedResource(getResource()
    1129                 .path("/registry/components/" + desc.getId() + "/xsd"))
    1130                 .accept(MediaType.TEXT_XML).get(ClientResponse.class);
    1131         assertEquals(200, cResponse.getStatus());
    1132         String result = cResponse.getEntity(String.class);
    1133         assertTrue(result.length() > 0);
    1134 
    1135         result = getAuthenticatedResource(getResource().path(
    1136                         "/registry/components/" + desc.getId() + "/xml"))
    1137                 .accept(MediaType.TEXT_XML).get(String.class);
    1138         assertTrue(result.length() > 0);
    1139 
    1140         cResponse = getAuthenticatedResource(getResource().path("/registry/components/" + desc.getId())).delete(
    1141                 ClientResponse.class);
    1142         assertEquals(200, cResponse.getStatus());
    1143 
    1144         components = getUserComponents();
    1145         assertEquals(1, components.size());
     1140
     1141        List<ComponentDescription> components = getUserComponents();
     1142        assertEquals("user registered components", 1, components.size());
     1143        assertEquals("public registered components", 0, getPublicComponents()
     1144                .size());
     1145        FormDataMultiPart form = createFormData(RegistryTestHelper
     1146                .getComponentTestContent());
     1147
     1148        RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/components")).type(
     1149                MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class,
     1150                form);
     1151        assertTrue(response.isRegistered());
     1152        assertFalse(response.isProfile());
     1153        assertTrue(response.isInUserSpace());
     1154        ComponentDescription desc = (ComponentDescription) response
     1155                .getDescription();
     1156        assertNotNull(desc);
     1157        assertEquals("Test1", desc.getName());
     1158        assertEquals("My Test", desc.getDescription());
     1159        assertEquals(expectedUserId("JUnit@test.com"), desc.getUserId());
     1160        assertEquals("Database test user", desc.getCreatorName());
     1161        assertEquals("TestGroup", desc.getGroupName());
     1162        assertTrue(desc.getId()
     1163                .startsWith(ComponentRegistry.REGISTRY_ID + "c_"));
     1164        assertNotNull(desc.getRegistrationDate());
     1165        String url = getResource().getUriBuilder().build().toString();
     1166        assertEquals(url + "registry/components/" + desc.getId(), desc.getHref());
     1167
     1168        components = getUserComponents();
     1169        assertEquals(2, components.size());
     1170        assertEquals(0, getPublicComponents().size());
     1171
     1172        // Try to post unauthenticated
     1173        ClientResponse cResponse = getResource().path("/registry/components")
     1174                .type(MediaType.MULTIPART_FORM_DATA)
     1175                .post(ClientResponse.class, form);
     1176        assertEquals(401, cResponse.getStatus());
     1177
     1178        // Try to get
     1179        cResponse = this.getAuthenticatedResource(getResource().path("/registry/components/" + desc.getId()))
     1180                .accept(MediaType.APPLICATION_XML).get(ClientResponse.class);
     1181
     1182        assertEquals(200, cResponse.getStatus());
     1183        CMDComponentSpec spec = getUserComponent(desc);
     1184        assertNotNull(spec);
     1185
     1186        cResponse = this.getAuthenticatedResource(getResource()
     1187                .path("/registry/components/" + desc.getId() + "/xsd"))
     1188                .accept(MediaType.TEXT_XML).get(ClientResponse.class);
     1189        assertEquals(200, cResponse.getStatus());
     1190        String result = cResponse.getEntity(String.class);
     1191        assertTrue(result.length() > 0);
     1192
     1193        result = getAuthenticatedResource(getResource().path(
     1194                "/registry/components/" + desc.getId() + "/xml"))
     1195                .accept(MediaType.TEXT_XML).get(String.class);
     1196        assertTrue(result.length() > 0);
     1197
     1198        cResponse = getAuthenticatedResource(getResource().path("/registry/components/" + desc.getId())).delete(
     1199                ClientResponse.class);
     1200        assertEquals(200, cResponse.getStatus());
     1201
     1202        components = getUserComponents();
     1203        assertEquals(1, components.size());
    11461204    }
    11471205//
     1206
    11481207    @Test
    11491208    public void testCreatePrivateComponentWithRecursion() throws Exception {
    1150        
     1209
     1210        System.out.println("testCreatePrivateComponentWithRecursion");
     1211
    11511212        fillUpPrivateItems();
    1152         // Create new componet
    1153         FormDataMultiPart form = createFormData(RegistryTestHelper
    1154                 .getComponentTestContent());
    1155         ClientResponse cResponse = getAuthenticatedResource(getResource().path("/registry/components")).type(
    1156                 MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form);
    1157         assertEquals(ClientResponse.Status.OK.getStatusCode(),
    1158                 cResponse.getStatus());
    1159         RegisterResponse response = cResponse.getEntity(RegisterResponse.class);
    1160         assertTrue(response.isRegistered());
    1161         ComponentDescription desc = (ComponentDescription) response
    1162                 .getDescription();
    1163 
    1164         // Re-define with self-recursion
    1165         String compContent = "";
    1166         compContent += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
    1167         compContent += "\n";
    1168         compContent += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
    1169         compContent += "    xsi:noNamespaceSchemaLocation=\"../../general-component-schema.xsd\">\n";
    1170         compContent += "    \n";
    1171         compContent += "    <Header/>\n";
    1172         compContent += "    \n";
    1173         compContent += "    <CMD_Component name=\"Nested\" CardinalityMin=\"1\" CardinalityMax=\"1\">\n";
    1174         compContent += "        <CMD_Element name=\"Availability\" ValueScheme=\"string\" />\n";
    1175         compContent += "        <CMD_Component ComponentId=\""
    1176                 + desc.getId()
    1177                 + "\" name=\"Recursive\" CardinalityMin=\"1\" CardinalityMax=\"1\" />\n";
    1178         compContent += "    </CMD_Component>\n";
    1179         compContent += "\n";
    1180         compContent += "</CMD_ComponentSpec>\n";
    1181 
    1182         // Update component
    1183         form = createFormData(
    1184                 RegistryTestHelper.getComponentContentAsStream(compContent),
    1185                 "UPDATE DESCRIPTION!");
    1186         cResponse = getAuthenticatedResource(getResource().path(
    1187                         "/registry/components/" + desc.getId() + "/update")).type(
    1188                 MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form);
    1189         assertEquals(ClientResponse.Status.OK.getStatusCode(),
    1190                 cResponse.getStatus());
    1191         response = cResponse.getEntity(RegisterResponse.class);
    1192         assertFalse("Recursive definition should fail", response.isRegistered());
    1193         assertEquals("There should be an error message for the recursion", 1,
    1194                 response.getErrors().size());
    1195         assertTrue(
    1196                 "There error message should specify the point of recursion",
    1197                 response.getErrors().get(0)
    1198                         .contains("already contains " + desc.getId()));
     1213        // Create new componet
     1214        FormDataMultiPart form = createFormData(RegistryTestHelper
     1215                .getComponentTestContent());
     1216        ClientResponse cResponse = getAuthenticatedResource(getResource().path("/registry/components")).type(
     1217                MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form);
     1218        assertEquals(ClientResponse.Status.OK.getStatusCode(),
     1219                cResponse.getStatus());
     1220        RegisterResponse response = cResponse.getEntity(RegisterResponse.class);
     1221        assertTrue(response.isRegistered());
     1222        ComponentDescription desc = (ComponentDescription) response
     1223                .getDescription();
     1224
     1225        // Re-define with self-recursion
     1226        String compContent = "";
     1227        compContent += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
     1228        compContent += "\n";
     1229        compContent += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
     1230        compContent += "    xsi:noNamespaceSchemaLocation=\"../../general-component-schema.xsd\">\n";
     1231        compContent += "    \n";
     1232        compContent += "    <Header/>\n";
     1233        compContent += "    \n";
     1234        compContent += "    <CMD_Component name=\"Nested\" CardinalityMin=\"1\" CardinalityMax=\"1\">\n";
     1235        compContent += "        <CMD_Element name=\"Availability\" ValueScheme=\"string\" />\n";
     1236        compContent += "        <CMD_Component ComponentId=\""
     1237                + desc.getId()
     1238                + "\" name=\"Recursive\" CardinalityMin=\"1\" CardinalityMax=\"1\" />\n";
     1239        compContent += "    </CMD_Component>\n";
     1240        compContent += "\n";
     1241        compContent += "</CMD_ComponentSpec>\n";
     1242
     1243        // Update component
     1244        form = createFormData(
     1245                RegistryTestHelper.getComponentContentAsStream(compContent),
     1246                "UPDATE DESCRIPTION!");
     1247        cResponse = getAuthenticatedResource(getResource().path(
     1248                "/registry/components/" + desc.getId() + "/update")).type(
     1249                MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form);
     1250        assertEquals(ClientResponse.Status.OK.getStatusCode(),
     1251                cResponse.getStatus());
     1252        response = cResponse.getEntity(RegisterResponse.class);
     1253        assertFalse("Recursive definition should fail", response.isRegistered());
     1254        assertEquals("There should be an error message for the recursion", 1,
     1255                response.getErrors().size());
     1256        assertTrue(
     1257                "There error message should specify the point of recursion",
     1258                response.getErrors().get(0)
     1259                .contains("already contains " + desc.getId()));
    11991260
    12001261    }
     
    12021263    @Test
    12031264    public void testUpdatePrivateComponent() throws Exception {
    1204        
     1265
     1266        System.out.println("testUpdatePrivateComponent");
     1267
    12051268        fillUpPrivateItems();
    1206        
    1207         List<ComponentDescription> components = getUserComponents();
    1208         assertEquals("user registered components", 1, components.size());
    1209         assertEquals("public registered components", 0, getPublicComponents()
    1210                 .size());
    1211        
     1269
     1270        List<ComponentDescription> components = getUserComponents();
     1271        assertEquals("user registered components", 1, components.size());
     1272        assertEquals("public registered components", 0, getPublicComponents()
     1273                .size());
     1274
    12121275        // first, post a component to update
    1213         FormDataMultiPart form = createFormData(RegistryTestHelper
    1214                 .getComponentTestContent());
    1215         ClientResponse cResponse = getAuthenticatedResource(getResource().path("/registry/components")).type(
    1216                 MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form);
    1217         assertEquals(ClientResponse.Status.OK.getStatusCode(),
    1218                 cResponse.getStatus());
    1219         RegisterResponse response = cResponse.getEntity(RegisterResponse.class);
    1220         assertTrue(response.isRegistered());
    1221         assertFalse(response.isProfile());
    1222         assertTrue(response.isInUserSpace());
    1223         ComponentDescription desc = (ComponentDescription) response
    1224                 .getDescription();
    1225         assertNotNull(desc);
    1226         assertEquals("Test1", desc.getName());
    1227         assertEquals("My Test", desc.getDescription());
    1228         Date firstDate = desc.getRegistrationDate();
    1229         CMDComponentSpec spec = getUserComponent(desc);
    1230         assertNotNull(spec);
    1231         assertEquals("Access", spec.getCMDComponent().getName());
    1232         components = getUserComponents();
    1233         assertEquals(2, components.size());
    1234         assertEquals(0, getPublicComponents().size());
    1235 
    1236         // second, now update
    1237         form = createFormData(
    1238                 RegistryTestHelper.getComponentTestContentAsStream("TESTNAME"),
    1239                 "UPDATE DESCRIPTION!");
    1240         cResponse = getAuthenticatedResource(getResource().path(
    1241                         "/registry/components/" + desc.getId() + "/update")
    1242                         .queryParam(REGISTRY_SPACE_PARAM, "private")).type(
    1243                 MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form);
    1244         assertEquals(ClientResponse.Status.OK.getStatusCode(),
    1245                 cResponse.getStatus());
    1246         response = cResponse.getEntity(RegisterResponse.class);
    1247         assertTrue(response.isRegistered());
    1248         assertFalse(response.isProfile());
    1249         assertTrue(response.isInUserSpace());
    1250         desc = (ComponentDescription) response.getDescription();
    1251         assertNotNull(desc);
    1252         assertEquals("Test1", desc.getName());
    1253         assertEquals("UPDATE DESCRIPTION!", desc.getDescription());
    1254         Date secondDate = desc.getRegistrationDate();
    1255         assertTrue(firstDate.before(secondDate) || firstDate.equals(secondDate));
    1256 
    1257         spec = getUserComponent(desc);
    1258         assertNotNull(spec);
    1259         assertEquals("TESTNAME", spec.getCMDComponent().getName());
    1260         components = getUserComponents();
    1261         assertEquals(2, components.size());
    1262         assertEquals(0, getPublicComponents().size());
     1276        FormDataMultiPart form = createFormData(RegistryTestHelper
     1277                .getComponentTestContent());
     1278        ClientResponse cResponse = getAuthenticatedResource(getResource().path("/registry/components")).type(
     1279                MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form);
     1280        assertEquals(ClientResponse.Status.OK.getStatusCode(),
     1281                cResponse.getStatus());
     1282        RegisterResponse response = cResponse.getEntity(RegisterResponse.class);
     1283        assertTrue(response.isRegistered());
     1284        assertFalse(response.isProfile());
     1285        assertTrue(response.isInUserSpace());
     1286        ComponentDescription desc = (ComponentDescription) response
     1287                .getDescription();
     1288        assertNotNull(desc);
     1289        assertEquals("Test1", desc.getName());
     1290        assertEquals("My Test", desc.getDescription());
     1291        Date firstDate = desc.getRegistrationDate();
     1292        CMDComponentSpec spec = getUserComponent(desc);
     1293        assertNotNull(spec);
     1294        assertEquals("Access", spec.getCMDComponent().getName());
     1295        components = getUserComponents();
     1296        assertEquals(2, components.size());
     1297        assertEquals(0, getPublicComponents().size());
     1298
     1299        // second, now update
     1300        form = createFormData(
     1301                RegistryTestHelper.getComponentTestContentAsStream("TESTNAME"),
     1302                "UPDATE DESCRIPTION!");
     1303        cResponse = getAuthenticatedResource(getResource().path(
     1304                "/registry/components/" + desc.getId() + "/update")
     1305                .queryParam(REGISTRY_SPACE_PARAM, "private")).type(
     1306                MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form);
     1307        assertEquals(ClientResponse.Status.OK.getStatusCode(),
     1308                cResponse.getStatus());
     1309        response = cResponse.getEntity(RegisterResponse.class);
     1310        assertTrue(response.isRegistered());
     1311        assertFalse(response.isProfile());
     1312        assertTrue(response.isInUserSpace());
     1313        desc = (ComponentDescription) response.getDescription();
     1314        assertNotNull(desc);
     1315        assertEquals("Test1", desc.getName());
     1316        assertEquals("UPDATE DESCRIPTION!", desc.getDescription());
     1317        Date secondDate = desc.getRegistrationDate();
     1318        assertTrue(firstDate.before(secondDate) || firstDate.equals(secondDate));
     1319
     1320        spec = getUserComponent(desc);
     1321        assertNotNull(spec);
     1322        assertEquals("TESTNAME", spec.getCMDComponent().getName());
     1323        components = getUserComponents();
     1324        assertEquals(2, components.size());
     1325        assertEquals(0, getPublicComponents().size());
    12631326    }
    12641327
    12651328    @Test
    12661329    public void testUpdatePrivateProfile() throws Exception {
    1267        
     1330
     1331        System.out.println("testUpdatePrivateProfile");
     1332
    12681333        fillUpPrivateItems();
    1269        
    1270         List<ProfileDescription> profiles = getUserProfiles();
    1271         assertEquals(1, profiles.size());
    1272         assertEquals(0, getPublicProfiles().size());
    1273 
    1274         FormDataMultiPart form = createFormData(RegistryTestHelper
    1275                 .getTestProfileContent());
    1276         ClientResponse cResponse = getAuthenticatedResource(getResource().path("/registry/profiles")).type(
    1277                 MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form);
    1278         assertEquals(ClientResponse.Status.OK.getStatusCode(),
    1279                 cResponse.getStatus());
    1280         RegisterResponse response = cResponse.getEntity(RegisterResponse.class);
    1281         assertTrue(response.isRegistered());
    1282         assertTrue(response.isProfile());
    1283         assertTrue(response.isInUserSpace());
    1284         ProfileDescription desc = (ProfileDescription) response
    1285                 .getDescription();
    1286         assertNotNull(desc);
    1287         assertEquals("Test1", desc.getName());
    1288         assertEquals("My Test", desc.getDescription());
    1289         assertEquals("TestGroup", desc.getGroupName());
    1290         Date firstDate = desc.getRegistrationDate();
    1291         CMDComponentSpec spec = getUserProfile(desc);
    1292         assertNotNull(spec);
    1293         assertEquals("Actor", spec.getCMDComponent().getName());
    1294         profiles = getUserProfiles();
    1295         assertEquals(2, profiles.size());
    1296         assertEquals(0, getPublicComponents().size());
    1297 
    1298         // Now update
    1299         form = createFormData(
    1300                 RegistryTestHelper.getTestProfileContent("TESTNAME"),
    1301                 "UPDATE DESCRIPTION!");
    1302         cResponse = getAuthenticatedResource(getResource().path(
    1303                         "/registry/profiles/" + desc.getId() + "/update")).type(
    1304                 MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form);
    1305         assertEquals(ClientResponse.Status.OK.getStatusCode(),
    1306                 cResponse.getStatus());
    1307         response = cResponse.getEntity(RegisterResponse.class);
    1308         assertTrue(response.isRegistered());
    1309         assertTrue(response.isProfile());
    1310         assertTrue(response.isInUserSpace());
    1311         desc = (ProfileDescription) response.getDescription();
    1312         assertNotNull(desc);
    1313         assertEquals("Test1", desc.getName());
    1314         assertEquals("UPDATE DESCRIPTION!", desc.getDescription());
    1315         Date secondDate = desc.getRegistrationDate();
    1316         assertTrue(firstDate.before(secondDate) || firstDate.equals(secondDate));
    1317 
    1318         spec = getUserProfile(desc);
    1319         assertNotNull(spec);
    1320         assertEquals("TESTNAME", spec.getCMDComponent().getName());
    1321         profiles = getUserProfiles();
    1322         assertEquals(2, profiles.size());
    1323         assertEquals(0, getPublicComponents().size());
     1334
     1335        List<ProfileDescription> profiles = getUserProfiles();
     1336        assertEquals(1, profiles.size());
     1337        assertEquals(0, getPublicProfiles().size());
     1338
     1339        FormDataMultiPart form = createFormData(RegistryTestHelper
     1340                .getTestProfileContent());
     1341        ClientResponse cResponse = getAuthenticatedResource(getResource().path("/registry/profiles")).type(
     1342                MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form);
     1343        assertEquals(ClientResponse.Status.OK.getStatusCode(),
     1344                cResponse.getStatus());
     1345        RegisterResponse response = cResponse.getEntity(RegisterResponse.class);
     1346        assertTrue(response.isRegistered());
     1347        assertTrue(response.isProfile());
     1348        assertTrue(response.isInUserSpace());
     1349        ProfileDescription desc = (ProfileDescription) response
     1350                .getDescription();
     1351        assertNotNull(desc);
     1352        assertEquals("Test1", desc.getName());
     1353        assertEquals("My Test", desc.getDescription());
     1354        assertEquals("TestGroup", desc.getGroupName());
     1355        Date firstDate = desc.getRegistrationDate();
     1356        CMDComponentSpec spec = getUserProfile(desc);
     1357        assertNotNull(spec);
     1358        assertEquals("Actor", spec.getCMDComponent().getName());
     1359        profiles = getUserProfiles();
     1360        assertEquals(2, profiles.size());
     1361        assertEquals(0, getPublicComponents().size());
     1362
     1363        // Now update
     1364        form = createFormData(
     1365                RegistryTestHelper.getTestProfileContent("TESTNAME"),
     1366                "UPDATE DESCRIPTION!");
     1367        cResponse = getAuthenticatedResource(getResource().path(
     1368                "/registry/profiles/" + desc.getId() + "/update")).type(
     1369                MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form);
     1370        assertEquals(ClientResponse.Status.OK.getStatusCode(),
     1371                cResponse.getStatus());
     1372        response = cResponse.getEntity(RegisterResponse.class);
     1373        assertTrue(response.isRegistered());
     1374        assertTrue(response.isProfile());
     1375        assertTrue(response.isInUserSpace());
     1376        desc = (ProfileDescription) response.getDescription();
     1377        assertNotNull(desc);
     1378        assertEquals("Test1", desc.getName());
     1379        assertEquals("UPDATE DESCRIPTION!", desc.getDescription());
     1380        Date secondDate = desc.getRegistrationDate();
     1381        assertTrue(firstDate.before(secondDate) || firstDate.equals(secondDate));
     1382
     1383        spec = getUserProfile(desc);
     1384        assertNotNull(spec);
     1385        assertEquals("TESTNAME", spec.getCMDComponent().getName());
     1386        profiles = getUserProfiles();
     1387        assertEquals(2, profiles.size());
     1388        assertEquals(0, getPublicComponents().size());
    13241389    }
    13251390
    13261391    private CMDComponentSpec getUserComponent(ComponentDescription desc) {
    1327         return getAuthenticatedResource(getResource().path("/registry/components/" + desc.getId())
    1328                         .queryParam(REGISTRY_SPACE_PARAM, "private")).accept(
    1329                 MediaType.APPLICATION_XML).get(CMDComponentSpec.class);
     1392        return getAuthenticatedResource(getResource().path("/registry/components/" + desc.getId())
     1393                .queryParam(REGISTRY_SPACE_PARAM, "private")).accept(
     1394                MediaType.APPLICATION_XML).get(CMDComponentSpec.class);
    13301395    }
    13311396
    13321397    private CMDComponentSpec getUserProfile(ProfileDescription desc) {
    1333         return getAuthenticatedResource(getResource().path("/registry/profiles/" + desc.getId())
    1334                         .queryParam(REGISTRY_SPACE_PARAM, "private")).accept(
    1335                 MediaType.APPLICATION_XML).get(CMDComponentSpec.class);
     1398        return getAuthenticatedResource(getResource().path("/registry/profiles/" + desc.getId())
     1399                .queryParam(REGISTRY_SPACE_PARAM, "private")).accept(
     1400                MediaType.APPLICATION_XML).get(CMDComponentSpec.class);
    13361401    }
    13371402
    13381403    private List<ComponentDescription> getPublicComponents() {
    1339         return getAuthenticatedResource("/registry/components").accept(
    1340                 MediaType.APPLICATION_XML).get(COMPONENT_LIST_GENERICTYPE);
     1404        return getAuthenticatedResource("/registry/components").accept(
     1405                MediaType.APPLICATION_XML).get(COMPONENT_LIST_GENERICTYPE);
    13411406    }
    13421407
    13431408    private List<ComponentDescription> getUserComponents() {
    1344         return getAuthenticatedResource(getResource().path("/registry/components").queryParam(
    1345                         REGISTRY_SPACE_PARAM, "private")).accept(
    1346                 MediaType.APPLICATION_XML).get(COMPONENT_LIST_GENERICTYPE);
     1409        return getAuthenticatedResource(getResource().path("/registry/components").queryParam(
     1410                REGISTRY_SPACE_PARAM, "private")).accept(
     1411                MediaType.APPLICATION_XML).get(COMPONENT_LIST_GENERICTYPE);
    13471412    }
    13481413
    13491414    @Test
    13501415    public void testRegisterComponent() throws Exception {
    1351        
     1416
     1417        System.out.println("testRegisterComponent");
     1418
    13521419        fillUpPrivateItems();
    1353        
    1354         FormDataMultiPart form = new FormDataMultiPart();
    1355         form.field(IComponentRegistryRestService.DATA_FORM_FIELD,
    1356                 RegistryTestHelper.getComponentTestContent(),
    1357                 MediaType.APPLICATION_OCTET_STREAM_TYPE);
    1358         form.field(IComponentRegistryRestService.NAME_FORM_FIELD,
    1359                 "ComponentTest1");
    1360         form.field(IComponentRegistryRestService.DESCRIPTION_FORM_FIELD,
    1361                 "My Test Component");
    1362         form.field(IComponentRegistryRestService.DOMAIN_FORM_FIELD,
    1363                 "TestDomain");
    1364         form.field(IComponentRegistryRestService.GROUP_FORM_FIELD, "TestGroup");
    1365         RegisterResponse response = getAuthenticatedResource(
    1366                 "/registry/components").type(MediaType.MULTIPART_FORM_DATA)
    1367                 .post(RegisterResponse.class, form);
    1368         assertTrue(response.isRegistered());
    1369         assertFalse(response.isProfile());
    1370         assertTrue(response.isInUserSpace());
    1371         ComponentDescription desc = (ComponentDescription) response
    1372                 .getDescription();
    1373         assertNotNull(desc);
    1374         assertEquals("ComponentTest1", desc.getName());
    1375         assertEquals("My Test Component", desc.getDescription());
    1376         assertEquals(expectedUserId("JUnit@test.com"), desc.getUserId());
    1377         assertEquals("Database test user", desc.getCreatorName());
    1378         assertEquals("TestGroup", desc.getGroupName());
    1379         assertEquals("TestDomain", desc.getDomainName());
    1380         assertTrue(desc.getId()
    1381                 .startsWith(ComponentRegistry.REGISTRY_ID + "c_"));
    1382         assertNotNull(desc.getRegistrationDate());
    1383         String url = getResource().getUriBuilder().build().toString();
    1384         assertEquals(url + "registry/components/" + desc.getId(),
    1385                 desc.getHref());
     1420
     1421        FormDataMultiPart form = new FormDataMultiPart();
     1422        form.field(IComponentRegistryRestService.DATA_FORM_FIELD,
     1423                RegistryTestHelper.getComponentTestContent(),
     1424                MediaType.APPLICATION_OCTET_STREAM_TYPE);
     1425        form.field(IComponentRegistryRestService.NAME_FORM_FIELD,
     1426                "ComponentTest1");
     1427        form.field(IComponentRegistryRestService.DESCRIPTION_FORM_FIELD,
     1428                "My Test Component");
     1429        form.field(IComponentRegistryRestService.DOMAIN_FORM_FIELD,
     1430                "TestDomain");
     1431        form.field(IComponentRegistryRestService.GROUP_FORM_FIELD, "TestGroup");
     1432        RegisterResponse response = getAuthenticatedResource(
     1433                "/registry/components").type(MediaType.MULTIPART_FORM_DATA)
     1434                .post(RegisterResponse.class, form);
     1435        assertTrue(response.isRegistered());
     1436        assertFalse(response.isProfile());
     1437        assertTrue(response.isInUserSpace());
     1438        ComponentDescription desc = (ComponentDescription) response
     1439                .getDescription();
     1440        assertNotNull(desc);
     1441        assertEquals("ComponentTest1", desc.getName());
     1442        assertEquals("My Test Component", desc.getDescription());
     1443        assertEquals(expectedUserId("JUnit@test.com"), desc.getUserId());
     1444        assertEquals("Database test user", desc.getCreatorName());
     1445        assertEquals("TestGroup", desc.getGroupName());
     1446        assertEquals("TestDomain", desc.getDomainName());
     1447        assertTrue(desc.getId()
     1448                .startsWith(ComponentRegistry.REGISTRY_ID + "c_"));
     1449        assertNotNull(desc.getRegistrationDate());
     1450        String url = getResource().getUriBuilder().build().toString();
     1451        assertEquals(url + "registry/components/" + desc.getId(),
     1452                desc.getHref());
    13861453    }
    13871454
    13881455    @Test
    13891456    public void testRegisterComment() throws Exception {
    1390        
    1391         fillUpPublicItems();
    1392        
    1393         FormDataMultiPart form = new FormDataMultiPart();
    1394         form.field(IComponentRegistryRestService.DATA_FORM_FIELD,
    1395                 RegistryTestHelper.getCommentTestContent(),
    1396                 MediaType.APPLICATION_OCTET_STREAM_TYPE);
    1397         String id = ProfileDescription.PROFILE_PREFIX + "profile1";
    1398         CommentResponse response = getAuthenticatedResource(
    1399                 "/registry/profiles/" + id + "/comments").type(
    1400                 MediaType.MULTIPART_FORM_DATA)
    1401                 .post(CommentResponse.class, form);
    1402         assertTrue(response.isRegistered());
    1403         assertFalse(response.isInUserSpace());
    1404         Comment comment = response.getComment();
    1405         assertNotNull(comment);
    1406         assertEquals("Actual", comment.getComment());
    1407         assertEquals("Database test user", comment.getUserName());
    1408         Assert.notNull(comment.getCommentDate());
    1409         Assert.hasText(comment.getId());
    1410 
    1411         // User id should not be serialized!
    1412         assertEquals(0, comment.getUserId());
     1457
     1458        System.out.println("testRegisterComponent");
     1459
     1460        fillUpPublicItems();
     1461
     1462        FormDataMultiPart form = new FormDataMultiPart();
     1463        form.field(IComponentRegistryRestService.DATA_FORM_FIELD,
     1464                RegistryTestHelper.getCommentTestContent(),
     1465                MediaType.APPLICATION_OCTET_STREAM_TYPE);
     1466        String id = ProfileDescription.PROFILE_PREFIX + "profile1";
     1467        CommentResponse response = getAuthenticatedResource(
     1468                "/registry/profiles/" + id + "/comments").type(
     1469                MediaType.MULTIPART_FORM_DATA)
     1470                .post(CommentResponse.class, form);
     1471        assertTrue(response.isRegistered());
     1472        assertFalse(response.isInUserSpace());
     1473        Comment comment = response.getComment();
     1474        assertNotNull(comment);
     1475        assertEquals("Actual", comment.getComment());
     1476        assertEquals("Database test user", comment.getUserName());
     1477        Assert.notNull(comment.getCommentDate());
     1478        Assert.hasText(comment.getId());
     1479
     1480        // User id should not be serialized!
     1481        assertEquals(0, comment.getUserId());
    14131482    }
    14141483
     
    14161485    public void testRegisterCommentToNonExistent() throws Exception {
    14171486        fillUpPublicItems();
    1418        
    1419         FormDataMultiPart form = new FormDataMultiPart();
    1420         form.field(IComponentRegistryRestService.DATA_FORM_FIELD,
    1421                 RegistryTestHelper.getCommentTestContent(),
    1422                 MediaType.APPLICATION_OCTET_STREAM_TYPE);
    1423         ClientResponse cResponse = getAuthenticatedResource(
    1424                 "/registry/profiles/clarin.eu:cr1:profile99/comments").type(
    1425                 MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form);
    1426         assertEquals(404, cResponse.getStatus());
     1487
     1488        FormDataMultiPart form = new FormDataMultiPart();
     1489        form.field(IComponentRegistryRestService.DATA_FORM_FIELD,
     1490                RegistryTestHelper.getCommentTestContent(),
     1491                MediaType.APPLICATION_OCTET_STREAM_TYPE);
     1492        ClientResponse cResponse = getAuthenticatedResource(
     1493                "/registry/profiles/clarin.eu:cr1:profile99/comments").type(
     1494                MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form);
     1495        assertEquals(404, cResponse.getStatus());
    14271496    }
    14281497
    14291498    @Test
    14301499    public void testRegisterCommentUnauthenticated() throws Exception {
    1431         fillUpPublicItems();
    1432        
    1433         FormDataMultiPart form = new FormDataMultiPart();
    1434         form.field(IComponentRegistryRestService.DATA_FORM_FIELD,
    1435                 RegistryTestHelper.getCommentTestContent(),
    1436                 MediaType.APPLICATION_OCTET_STREAM_TYPE);
    1437         ClientResponse cResponse = getResource()
    1438                 .path("/registry/profiles/clarin.eu:cr1:profile1/comments")
    1439                 .type(MediaType.MULTIPART_FORM_DATA)
    1440                 .post(ClientResponse.class, form);
    1441         assertEquals(401, cResponse.getStatus());
     1500
     1501        System.out.println("testREgisterCommentUnauthentified");
     1502
     1503        fillUpPublicItems();
     1504
     1505        FormDataMultiPart form = new FormDataMultiPart();
     1506        form.field(IComponentRegistryRestService.DATA_FORM_FIELD,
     1507                RegistryTestHelper.getCommentTestContent(),
     1508                MediaType.APPLICATION_OCTET_STREAM_TYPE);
     1509        ClientResponse cResponse = getResource()
     1510                .path("/registry/profiles/clarin.eu:cr1:profile1/comments")
     1511                .type(MediaType.MULTIPART_FORM_DATA)
     1512                .post(ClientResponse.class, form);
     1513        assertEquals(401, cResponse.getStatus());
    14421514    }
    14431515
    14441516    @Test
    14451517    public void testRegisterProfileInvalidData() throws Exception {
     1518        System.out.println("testRegisterProfileInvalidData");
    14461519        fillUpPrivateItems();
    1447         FormDataMultiPart form = new FormDataMultiPart();
    1448         String notAValidProfile = "<CMD_ComponentSpec> </CMD_ComponentSpec>";
    1449         form.field(IComponentRegistryRestService.DATA_FORM_FIELD,
    1450                 new ByteArrayInputStream(notAValidProfile.getBytes()),
    1451                 MediaType.APPLICATION_OCTET_STREAM_TYPE);
    1452         form.field(IComponentRegistryRestService.NAME_FORM_FIELD,
    1453                 "ProfileTest1");
    1454         form.field(IComponentRegistryRestService.DOMAIN_FORM_FIELD, "Domain");
    1455         form.field(IComponentRegistryRestService.GROUP_FORM_FIELD, "Group");
    1456         form.field(IComponentRegistryRestService.DESCRIPTION_FORM_FIELD,
    1457                 "My Test Profile");
    1458         RegisterResponse postResponse = getAuthenticatedResource(
    1459                 "/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post(
    1460                 RegisterResponse.class, form);
    1461         assertTrue(postResponse.isProfile());
    1462         assertFalse(postResponse.isRegistered());
    1463         assertEquals(1, postResponse.getErrors().size());
    1464         assertTrue(postResponse.getErrors().get(0).contains("isProfile"));
     1520        FormDataMultiPart form = new FormDataMultiPart();
     1521        String notAValidProfile = "<CMD_ComponentSpec> </CMD_ComponentSpec>";
     1522        form.field(IComponentRegistryRestService.DATA_FORM_FIELD,
     1523                new ByteArrayInputStream(notAValidProfile.getBytes()),
     1524                MediaType.APPLICATION_OCTET_STREAM_TYPE);
     1525        form.field(IComponentRegistryRestService.NAME_FORM_FIELD,
     1526                "ProfileTest1");
     1527        form.field(IComponentRegistryRestService.DOMAIN_FORM_FIELD, "Domain");
     1528        form.field(IComponentRegistryRestService.GROUP_FORM_FIELD, "Group");
     1529        form.field(IComponentRegistryRestService.DESCRIPTION_FORM_FIELD,
     1530                "My Test Profile");
     1531        RegisterResponse postResponse = getAuthenticatedResource(
     1532                "/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post(
     1533                RegisterResponse.class, form);
     1534        assertTrue(postResponse.isProfile());
     1535        assertFalse(postResponse.isRegistered());
     1536        assertEquals(1, postResponse.getErrors().size());
     1537        assertTrue(postResponse.getErrors().get(0).contains("isProfile"));
    14651538    }
    14661539
     
    14681541     * Two elements on the same level with the same name violates schematron
    14691542     * rule, and should fail validation
    1470      * 
     1543     *
    14711544     * @throws Exception
    14721545     */
    14731546    @Test
    14741547    public void testRegisterInvalidProfile() throws Exception {
     1548        System.out.println("testRegisterInvalidProfile");
    14751549        fillUpPrivateItems();
    1476         FormDataMultiPart form = new FormDataMultiPart();
    1477         String profileContent = "";
    1478         profileContent += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
    1479         profileContent += "<CMD_ComponentSpec isProfile=\"true\" xmlns:xml=\"http://www.w3.org/XML/1998/namespace\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
    1480         profileContent += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n";
    1481         profileContent += "    <Header />\n";
    1482         profileContent += "    <CMD_Component name=\"ProfileTest1\" CardinalityMin=\"0\" CardinalityMax=\"unbounded\">\n";
    1483         profileContent += "        <CMD_Element name=\"Age\">\n";
    1484         profileContent += "            <ValueScheme>\n";
    1485         profileContent += "                <pattern>[23][0-9]</pattern>\n";
    1486         profileContent += "            </ValueScheme>\n";
    1487         profileContent += "        </CMD_Element>\n";
    1488         profileContent += "        <CMD_Element name=\"Age\">\n";
    1489         profileContent += "            <ValueScheme>\n";
    1490         profileContent += "                <pattern>[23][0-9]</pattern>\n";
    1491         profileContent += "            </ValueScheme>\n";
    1492         profileContent += "        </CMD_Element>\n";
    1493         profileContent += "    </CMD_Component>\n";
    1494         profileContent += "</CMD_ComponentSpec>\n";
    1495         form.field(IComponentRegistryRestService.DATA_FORM_FIELD,
    1496                 RegistryTestHelper.getComponentContentAsStream(profileContent),
    1497                 MediaType.APPLICATION_OCTET_STREAM_TYPE);
    1498         form.field(IComponentRegistryRestService.NAME_FORM_FIELD,
    1499                 "ProfileTest1");
    1500         form.field(IComponentRegistryRestService.DOMAIN_FORM_FIELD,
    1501                 "TestDomain");
    1502         form.field(IComponentRegistryRestService.DESCRIPTION_FORM_FIELD,
    1503                 "My Test Profile");
    1504         form.field(IComponentRegistryRestService.GROUP_FORM_FIELD,
    1505                 "My Test Group");
    1506         RegisterResponse response = getAuthenticatedResource(
    1507                 "/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post(
    1508                 RegisterResponse.class, form);
    1509         assertFalse(
    1510                 "Subsequent elements should not be allowed to have the same name",
    1511                 response.isRegistered());
    1512         assertTrue(response.getErrors().get(0)
    1513                 .contains(MDValidator.PARSE_ERROR));
     1550        FormDataMultiPart form = new FormDataMultiPart();
     1551        String profileContent = "";
     1552        profileContent += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
     1553        profileContent += "<CMD_ComponentSpec isProfile=\"true\" xmlns:xml=\"http://www.w3.org/XML/1998/namespace\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
     1554        profileContent += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n";
     1555        profileContent += "    <Header />\n";
     1556        profileContent += "    <CMD_Component name=\"ProfileTest1\" CardinalityMin=\"0\" CardinalityMax=\"unbounded\">\n";
     1557        profileContent += "        <CMD_Element name=\"Age\">\n";
     1558        profileContent += "            <ValueScheme>\n";
     1559        profileContent += "                <pattern>[23][0-9]</pattern>\n";
     1560        profileContent += "            </ValueScheme>\n";
     1561        profileContent += "        </CMD_Element>\n";
     1562        profileContent += "        <CMD_Element name=\"Age\">\n";
     1563        profileContent += "            <ValueScheme>\n";
     1564        profileContent += "                <pattern>[23][0-9]</pattern>\n";
     1565        profileContent += "            </ValueScheme>\n";
     1566        profileContent += "        </CMD_Element>\n";
     1567        profileContent += "    </CMD_Component>\n";
     1568        profileContent += "</CMD_ComponentSpec>\n";
     1569        form.field(IComponentRegistryRestService.DATA_FORM_FIELD,
     1570                RegistryTestHelper.getComponentContentAsStream(profileContent),
     1571                MediaType.APPLICATION_OCTET_STREAM_TYPE);
     1572        form.field(IComponentRegistryRestService.NAME_FORM_FIELD,
     1573                "ProfileTest1");
     1574        form.field(IComponentRegistryRestService.DOMAIN_FORM_FIELD,
     1575                "TestDomain");
     1576        form.field(IComponentRegistryRestService.DESCRIPTION_FORM_FIELD,
     1577                "My Test Profile");
     1578        form.field(IComponentRegistryRestService.GROUP_FORM_FIELD,
     1579                "My Test Group");
     1580        RegisterResponse response = getAuthenticatedResource(
     1581                "/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post(
     1582                RegisterResponse.class, form);
     1583        assertFalse(
     1584                "Subsequent elements should not be allowed to have the same name",
     1585                response.isRegistered());
     1586        assertTrue(response.getErrors().get(0)
     1587                .contains(MDValidator.PARSE_ERROR));
    15141588    }
    15151589
    15161590    @Test
    15171591    public void testRegisterProfileInvalidDescriptionAndContent()
    1518             throws Exception {
     1592            throws Exception {
     1593        System.out.println("testRegisterProfileInvalidDescriptionAndContent");
    15191594        fillUpPrivateItems();
    1520         FormDataMultiPart form = new FormDataMultiPart();
    1521         String profileContent = "";
    1522         profileContent += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
    1523         profileContent += "<CMD_ComponentSpec> \n"; // No isProfile attribute
    1524         profileContent += "    <Header />\n";
    1525         profileContent += "    <CMD_Component name=\"Actor\" CardinalityMin=\"0\" CardinalityMax=\"unbounded\">\n";
    1526         profileContent += "        <AttributeList>\n";
    1527         profileContent += "            <Attribute>\n";
    1528         profileContent += "                <Name>Name</Name>\n";
    1529         profileContent += "                <Type>string</Type>\n";
    1530         profileContent += "            </Attribute>\n";
    1531         profileContent += "        </AttributeList>\n";
    1532         profileContent += "    </CMD_Component>\n";
    1533         profileContent += "</CMD_ComponentSpec>\n";
    1534         form.field("data", new ByteArrayInputStream(profileContent.getBytes()),
    1535                 MediaType.APPLICATION_OCTET_STREAM_TYPE);
    1536         form.field("name", "");// Empty name so invalid
    1537         form.field("description", "My Test Profile");
    1538         RegisterResponse response = getAuthenticatedResource(
    1539                 "/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post(
    1540                 RegisterResponse.class, form);
    1541         assertFalse(response.isRegistered());
    1542         assertEquals(2, response.getErrors().size());
    1543         assertNotNull(response.getErrors().get(0));
    1544         assertEquals(MDValidator.PARSE_ERROR, response.getErrors().get(1)
    1545                 .substring(0, MDValidator.PARSE_ERROR.length()));
     1595        FormDataMultiPart form = new FormDataMultiPart();
     1596        String profileContent = "";
     1597        profileContent += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
     1598        profileContent += "<CMD_ComponentSpec> \n"; // No isProfile attribute
     1599        profileContent += "    <Header />\n";
     1600        profileContent += "    <CMD_Component name=\"Actor\" CardinalityMin=\"0\" CardinalityMax=\"unbounded\">\n";
     1601        profileContent += "        <AttributeList>\n";
     1602        profileContent += "            <Attribute>\n";
     1603        profileContent += "                <Name>Name</Name>\n";
     1604        profileContent += "                <Type>string</Type>\n";
     1605        profileContent += "            </Attribute>\n";
     1606        profileContent += "        </AttributeList>\n";
     1607        profileContent += "    </CMD_Component>\n";
     1608        profileContent += "</CMD_ComponentSpec>\n";
     1609        form.field("data", new ByteArrayInputStream(profileContent.getBytes()),
     1610                MediaType.APPLICATION_OCTET_STREAM_TYPE);
     1611        form.field("name", "");// Empty name so invalid
     1612        form.field("description", "My Test Profile");
     1613        RegisterResponse response = getAuthenticatedResource(
     1614                "/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post(
     1615                RegisterResponse.class, form);
     1616        assertFalse(response.isRegistered());
     1617        assertEquals(2, response.getErrors().size());
     1618        assertNotNull(response.getErrors().get(0));
     1619        assertEquals(MDValidator.PARSE_ERROR, response.getErrors().get(1)
     1620                .substring(0, MDValidator.PARSE_ERROR.length()));
    15461621    }
    15471622
    15481623    @Test
    15491624    public void testRegisterLargeProfile() throws Exception {
     1625        System.out.println("testRegisterLargeProfile");
    15501626        //fillUpPrivateItems(); not necessary
    1551         FormDataMultiPart form = new FormDataMultiPart();
    1552         form.field(IComponentRegistryRestService.DATA_FORM_FIELD,
    1553                 RegistryTestHelper.getLargeProfileContent(),
    1554                 MediaType.APPLICATION_OCTET_STREAM_TYPE);
    1555         form.field(IComponentRegistryRestService.NAME_FORM_FIELD,
    1556                 "ProfileTest1");
    1557         form.field(IComponentRegistryRestService.DOMAIN_FORM_FIELD,
    1558                 "TestDomain");
    1559         form.field(IComponentRegistryRestService.DESCRIPTION_FORM_FIELD,
    1560                 "My Test Profile");
    1561         form.field(IComponentRegistryRestService.GROUP_FORM_FIELD,
    1562                 "My Test Group");
    1563         ClientResponse response = getAuthenticatedResource("/registry/profiles")
    1564                 .type(MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class,
    1565                         form);
    1566         assertEquals(200, response.getStatus());
     1627        FormDataMultiPart form = new FormDataMultiPart();
     1628        form.field(IComponentRegistryRestService.DATA_FORM_FIELD,
     1629                RegistryTestHelper.getLargeProfileContent(),
     1630                MediaType.APPLICATION_OCTET_STREAM_TYPE);
     1631        form.field(IComponentRegistryRestService.NAME_FORM_FIELD,
     1632                "ProfileTest1");
     1633        form.field(IComponentRegistryRestService.DOMAIN_FORM_FIELD,
     1634                "TestDomain");
     1635        form.field(IComponentRegistryRestService.DESCRIPTION_FORM_FIELD,
     1636                "My Test Profile");
     1637        form.field(IComponentRegistryRestService.GROUP_FORM_FIELD,
     1638                "My Test Group");
     1639        ClientResponse response = getAuthenticatedResource("/registry/profiles")
     1640                .type(MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class,
     1641                form);
     1642        assertEquals(200, response.getStatus());
    15671643    }
    15681644
    15691645    @Test
    15701646    public void testRegisterComponentAsProfile() throws Exception {
     1647        System.out.println("tesRegisterComponentAsProfile");
    15711648        //fillUpPrivateItems();; not necessary
    1572         FormDataMultiPart form = new FormDataMultiPart();
    1573         form.field(IComponentRegistryRestService.DATA_FORM_FIELD,
    1574                 RegistryTestHelper.getComponentTestContent(),
    1575                 MediaType.APPLICATION_OCTET_STREAM_TYPE);
    1576         form.field(IComponentRegistryRestService.NAME_FORM_FIELD, "t");
    1577         form.field(IComponentRegistryRestService.DOMAIN_FORM_FIELD, "domain");
    1578         form.field(IComponentRegistryRestService.DESCRIPTION_FORM_FIELD,
    1579                 "My Test");
    1580         form.field(IComponentRegistryRestService.GROUP_FORM_FIELD, "My Group");
    1581         RegisterResponse response = getAuthenticatedResource(
    1582                 "/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post(
    1583                 RegisterResponse.class, form);
    1584         assertFalse(response.isRegistered());
    1585         assertTrue(response.isProfile());
    1586         assertEquals(1, response.getErrors().size());
    1587         assertEquals(MDValidator.MISMATCH_ERROR, response.getErrors().get(0));
     1649        FormDataMultiPart form = new FormDataMultiPart();
     1650        form.field(IComponentRegistryRestService.DATA_FORM_FIELD,
     1651                RegistryTestHelper.getComponentTestContent(),
     1652                MediaType.APPLICATION_OCTET_STREAM_TYPE);
     1653        form.field(IComponentRegistryRestService.NAME_FORM_FIELD, "t");
     1654        form.field(IComponentRegistryRestService.DOMAIN_FORM_FIELD, "domain");
     1655        form.field(IComponentRegistryRestService.DESCRIPTION_FORM_FIELD,
     1656                "My Test");
     1657        form.field(IComponentRegistryRestService.GROUP_FORM_FIELD, "My Group");
     1658        RegisterResponse response = getAuthenticatedResource(
     1659                "/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post(
     1660                RegisterResponse.class, form);
     1661        assertFalse(response.isRegistered());
     1662        assertTrue(response.isProfile());
     1663        assertEquals(1, response.getErrors().size());
     1664        assertEquals(MDValidator.MISMATCH_ERROR, response.getErrors().get(0));
    15881665    }
    15891666
     
    15931670     * "nodel-L", "node-R", "leaf-LL", "leaf-LM", "leaf-LR", "leaf-RL",
    15941671     * "leaf-RM", "leaf-RR"
    1595      * 
     1672     *
    15961673     * @throws Exception
    15971674     */
    15981675    @Test
    15991676    public void testSetFilenamesToNull() throws Exception {
    1600 
    1601         // helper assists in generating a test component
    1602         CMDComponentSetFilenamesToNullTestRunner helper = new CMDComponentSetFilenamesToNullTestRunner();
    1603 
    1604         // making an (up to ternary) tree of test components
    1605         // inductive explaination of the variable names, an example: leaf-LM is
    1606         // the middle child of the nodeL
    1607         // the filename is this leaf is "leaf-LM"
    1608 
    1609         // making children of the node L
    1610         CMDComponentType leafLR = helper.makeTestComponent("leaf-LR", null);
    1611         CMDComponentType leafLM = helper.makeTestComponent("leaf-LM", null);
    1612         CMDComponentType leafLL = helper.makeTestComponent("leaf-LL", null);
    1613 
    1614         // making node L
    1615         List<CMDComponentType> nodeLchild = (new ArrayList<CMDComponentType>());
    1616         nodeLchild.add(leafLL);
    1617         nodeLchild.add(leafLM);
    1618         nodeLchild.add(leafLR);
    1619         CMDComponentType nodeL = helper.makeTestComponent("node-L", nodeLchild);
    1620 
    1621         // making children of the node R
    1622         CMDComponentType leafRR = helper.makeTestComponent("leaf-RR", null);
    1623         CMDComponentType leafRM = helper.makeTestComponent("leaf-RM", null);
    1624         CMDComponentType leafRL = helper.makeTestComponent("leaf-RL", null);
    1625 
    1626         // making node R
    1627         List<CMDComponentType> nodeRchild = (new ArrayList<CMDComponentType>());
    1628         nodeRchild.add(leafRL);
    1629         nodeRchild.add(leafRM);
    1630         nodeRchild.add(leafRR);
    1631         CMDComponentType nodeR = helper.makeTestComponent("node-R", nodeRchild);
    1632 
    1633         // making the root, which has children NodeL and nodeR
    1634         List<CMDComponentType> wortelchild = (new ArrayList<CMDComponentType>());
    1635         wortelchild.add(nodeL);
    1636         wortelchild.add(nodeR);
    1637         CMDComponentType root = helper.makeTestComponent("wortel", wortelchild);
    1638 
    1639         // checking if the test compnent has the expected structure and the
    1640         // expected filenames
    1641         // ALSO this checking code below shows the strtucture of the tree
    1642 
    1643         assertEquals(root.getCMDComponent().size(), 2);
    1644         assertEquals(root.getCMDComponent().get(0).getCMDComponent().size(), 3);
    1645         assertEquals(root.getCMDComponent().get(1).getCMDComponent().size(), 3);
    1646 
    1647         assertEquals(root.getFilename(), "wortel");
    1648 
    1649         assertEquals(root.getCMDComponent().get(0).getFilename(), "node-L");
    1650         assertEquals(root.getCMDComponent().get(1).getFilename(), "node-R");
    1651 
    1652         assertEquals(root.getCMDComponent().get(0).getCMDComponent().get(0)
    1653                 .getFilename(), "leaf-LL");
    1654         assertEquals(root.getCMDComponent().get(0).getCMDComponent().get(1)
    1655                 .getFilename(), "leaf-LM");
    1656         assertEquals(root.getCMDComponent().get(0).getCMDComponent().get(2)
    1657                 .getFilename(), "leaf-LR");
    1658 
    1659         assertEquals(root.getCMDComponent().get(1).getCMDComponent().get(0)
    1660                 .getFilename(), "leaf-RL");
    1661         assertEquals(root.getCMDComponent().get(1).getCMDComponent().get(1)
    1662                 .getFilename(), "leaf-RM");
    1663         assertEquals(root.getCMDComponent().get(1).getCMDComponent().get(2)
    1664                 .getFilename(), "leaf-RR");
    1665 
    1666         // the actual job
    1667         // nulling the filenames will be called as a method of testrestservice
    1668         ComponentRegistryRestService restservice = new ComponentRegistryRestService();
    1669         restservice.setFileNamesToNullCurrent(root);
    1670 
    1671         // check if the filenames are nulled
    1672         assertEquals(root.getFilename(), null);
    1673 
    1674         assertEquals(root.getCMDComponent().get(0).getFilename(), null);
    1675         assertEquals(root.getCMDComponent().get(1).getFilename(), null);
    1676 
    1677         assertEquals(root.getCMDComponent().get(0).getCMDComponent().get(0)
    1678                 .getFilename(), null);
    1679         assertEquals(root.getCMDComponent().get(0).getCMDComponent().get(1)
    1680                 .getFilename(), null);
    1681         assertEquals(root.getCMDComponent().get(0).getCMDComponent().get(2)
    1682                 .getFilename(), null);
    1683 
    1684         assertEquals(root.getCMDComponent().get(1).getCMDComponent().get(0)
    1685                 .getFilename(), null);
    1686         assertEquals(root.getCMDComponent().get(1).getCMDComponent().get(1)
    1687                 .getFilename(), null);
    1688         assertEquals(root.getCMDComponent().get(1).getCMDComponent().get(2)
    1689                 .getFilename(), null);
    1690     }
    1691    
    1692     @Test
    1693     public void testGetDescription() throws Exception{
     1677        System.out.println("testSetfilenamesTonull");
     1678        // helper assists in generating a test component
     1679        CMDComponentSetFilenamesToNullTestRunner helper = new CMDComponentSetFilenamesToNullTestRunner();
     1680
     1681        // making an (up to ternary) tree of test components
     1682        // inductive explaination of the variable names, an example: leaf-LM is
     1683        // the middle child of the nodeL
     1684        // the filename is this leaf is "leaf-LM"
     1685
     1686        // making children of the node L
     1687        CMDComponentType leafLR = helper.makeTestComponent("leaf-LR", null);
     1688        CMDComponentType leafLM = helper.makeTestComponent("leaf-LM", null);
     1689        CMDComponentType leafLL = helper.makeTestComponent("leaf-LL", null);
     1690
     1691        // making node L
     1692        List<CMDComponentType> nodeLchild = (new ArrayList<CMDComponentType>());
     1693        nodeLchild.add(leafLL);
     1694        nodeLchild.add(leafLM);
     1695        nodeLchild.add(leafLR);
     1696        CMDComponentType nodeL = helper.makeTestComponent("node-L", nodeLchild);
     1697
     1698        // making children of the node R
     1699        CMDComponentType leafRR = helper.makeTestComponent("leaf-RR", null);
     1700        CMDComponentType leafRM = helper.makeTestComponent("leaf-RM", null);
     1701        CMDComponentType leafRL = helper.makeTestComponent("leaf-RL", null);
     1702
     1703        // making node R
     1704        List<CMDComponentType> nodeRchild = (new ArrayList<CMDComponentType>());
     1705        nodeRchild.add(leafRL);
     1706        nodeRchild.add(leafRM);
     1707        nodeRchild.add(leafRR);
     1708        CMDComponentType nodeR = helper.makeTestComponent("node-R", nodeRchild);
     1709
     1710        // making the root, which has children NodeL and nodeR
     1711        List<CMDComponentType> wortelchild = (new ArrayList<CMDComponentType>());
     1712        wortelchild.add(nodeL);
     1713        wortelchild.add(nodeR);
     1714        CMDComponentType root = helper.makeTestComponent("wortel", wortelchild);
     1715
     1716        // checking if the test compnent has the expected structure and the
     1717        // expected filenames
     1718        // ALSO this checking code below shows the strtucture of the tree
     1719
     1720        assertEquals(root.getCMDComponent().size(), 2);
     1721        assertEquals(root.getCMDComponent().get(0).getCMDComponent().size(), 3);
     1722        assertEquals(root.getCMDComponent().get(1).getCMDComponent().size(), 3);
     1723
     1724        assertEquals(root.getFilename(), "wortel");
     1725
     1726        assertEquals(root.getCMDComponent().get(0).getFilename(), "node-L");
     1727        assertEquals(root.getCMDComponent().get(1).getFilename(), "node-R");
     1728
     1729        assertEquals(root.getCMDComponent().get(0).getCMDComponent().get(0)
     1730                .getFilename(), "leaf-LL");
     1731        assertEquals(root.getCMDComponent().get(0).getCMDComponent().get(1)
     1732                .getFilename(), "leaf-LM");
     1733        assertEquals(root.getCMDComponent().get(0).getCMDComponent().get(2)
     1734                .getFilename(), "leaf-LR");
     1735
     1736        assertEquals(root.getCMDComponent().get(1).getCMDComponent().get(0)
     1737                .getFilename(), "leaf-RL");
     1738        assertEquals(root.getCMDComponent().get(1).getCMDComponent().get(1)
     1739                .getFilename(), "leaf-RM");
     1740        assertEquals(root.getCMDComponent().get(1).getCMDComponent().get(2)
     1741                .getFilename(), "leaf-RR");
     1742
     1743        // the actual job
     1744        // nulling the filenames will be called as a method of testrestservice
     1745        ComponentRegistryRestService restservice = new ComponentRegistryRestService();
     1746        restservice.setFileNamesToNullCurrent(root);
     1747
     1748        // check if the filenames are nulled
     1749        assertEquals(root.getFilename(), null);
     1750
     1751        assertEquals(root.getCMDComponent().get(0).getFilename(), null);
     1752        assertEquals(root.getCMDComponent().get(1).getFilename(), null);
     1753
     1754        assertEquals(root.getCMDComponent().get(0).getCMDComponent().get(0)
     1755                .getFilename(), null);
     1756        assertEquals(root.getCMDComponent().get(0).getCMDComponent().get(1)
     1757                .getFilename(), null);
     1758        assertEquals(root.getCMDComponent().get(0).getCMDComponent().get(2)
     1759                .getFilename(), null);
     1760
     1761        assertEquals(root.getCMDComponent().get(1).getCMDComponent().get(0)
     1762                .getFilename(), null);
     1763        assertEquals(root.getCMDComponent().get(1).getCMDComponent().get(1)
     1764                .getFilename(), null);
     1765        assertEquals(root.getCMDComponent().get(1).getCMDComponent().get(2)
     1766                .getFilename(), null);
     1767    }
     1768
     1769    @Test
     1770    public void testGetDescription() throws Exception {
     1771        System.out.println("testGetDescription");
    16941772        fillUpPublicItems();
    16951773        String id = ComponentDescription.COMPONENT_PREFIX + "component1";
  • ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/SanboxTest.java

    r5549 r5550  
    1212import clarin.cmdi.componentregistry.model.ComponentDescription;
    1313import clarin.cmdi.componentregistry.model.ProfileDescription;
    14 import clarin.cmdi.componentregistry.model.RegisterResponse;
    1514import com.sun.jersey.api.client.ClientResponse;
    1615import com.sun.jersey.multipart.FormDataMultiPart;
     16import java.util.List;
     17import javax.ws.rs.WebApplicationException;
    1718import javax.ws.rs.core.MediaType;
    1819import org.junit.Before;
     
    2122import org.springframework.jdbc.core.JdbcTemplate;
    2223
    23 import org.springframework.util.Assert;
    2424import static org.junit.Assert.*;
     25
    2526/**
    2627 *
    2728 * @author olhsha
    2829 */
    29 public class SanboxTest extends
    30         ComponentRegistryRestServiceTestCase {
     30public class SanboxTest extends ComponentRegistryRestServiceTestCase {
    3131
    3232    @Autowired
     
    4040    @Before
    4141    public void init() {
    42         ComponentRegistryTestDatabase.resetAndCreateAllTables(jdbcTemplate);
    43         createUserRecord();
    44         baseRegistry = componentRegistryFactory.getBaseRegistry(DummyPrincipal.DUMMY_CREDENTIALS);
     42        ComponentRegistryTestDatabase.resetAndCreateAllTables(jdbcTemplate);
     43        createUserRecord();
     44        baseRegistry = componentRegistryFactory.getBaseRegistry(DummyPrincipal.DUMMY_CREDENTIALS);
    4545    }
    4646
    4747    private String expectedUserId(String principal) {
    48         return getUserDao().getByPrincipalName(principal).getId().toString();
     48        return getUserDao().getByPrincipalName(principal).getId().toString();
    4949    }
    50 
    5150    private ComponentDescription component1;
    5251    private ComponentDescription component2;
    5352    private ProfileDescription profile1;
    5453    private ProfileDescription profile2;
    55    
    5654    private ComponentDescription component3;
    5755    private ProfileDescription profile3;
    58    
    5956    private Comment profile1Comment1;
    6057    private Comment profile1Comment2;
    6158    private Comment component1Comment3;
    6259    private Comment component1Comment4;
    63    
    6460    private Comment profile3Comment5;
    6561    private Comment component3Comment7;
    6662
    6763    private void fillUpPublicItems() throws Exception {
    68        
    69         profile1 = RegistryTestHelper.addProfile(baseRegistry, "profile2", true);
    70         profile2 = RegistryTestHelper.addProfile(baseRegistry, "profile1", true);
    71         component1 = RegistryTestHelper.addComponent(baseRegistry,
    72                 "component2", true);
    73         component2 = RegistryTestHelper.addComponent(baseRegistry,
    74                 "component1", true);
    75         profile1Comment2 = RegistryTestHelper.addComment(baseRegistry, "comment2",
    76                 ProfileDescription.PROFILE_PREFIX + "profile1",
    77                 "JUnit@test.com");
    78         profile1Comment1 = RegistryTestHelper.addComment(baseRegistry, "comment1",
    79                 ProfileDescription.PROFILE_PREFIX + "profile1",
    80                 "JUnit@test.com");
    81         component1Comment3 = RegistryTestHelper.addComment(baseRegistry, "comment3",
    82                 ComponentDescription.COMPONENT_PREFIX + "component1",
    83                 "JUnit@test.com");
    84         component1Comment4 = RegistryTestHelper.addComment(baseRegistry, "comment4",
    85                 ComponentDescription.COMPONENT_PREFIX + "component1",
    86                 "JUnit@test.com");
    87     }
    88    
    89     private void fillUpPrivateItems() throws Exception {
    90         profile3 = RegistryTestHelper.addProfile(baseRegistry, "profile3", false);
    91         component3 = RegistryTestHelper.addComponent(baseRegistry,
    92                 "component3", false);
    93         profile3Comment5 = RegistryTestHelper.addComment(baseRegistry, "comment5",
    94                 ProfileDescription.PROFILE_PREFIX + "profile3",
    95                 "JUnit@test.com");
    96         component3Comment7 = RegistryTestHelper.addComment(baseRegistry, "comment7",
    97                 ComponentDescription.COMPONENT_PREFIX + "component3",
    98                 "JUnit@test.com");
    99     }
    100    
    101        @Test
    102     public void testCreatePrivateComponentWithRecursion() throws Exception {
    103        
    104         fillUpPrivateItems();
    105         // Create new componet
    106         FormDataMultiPart form = createFormData(RegistryTestHelper
    107                 .getComponentTestContent());
    108         ClientResponse cResponse = getAuthenticatedResource(getResource().path("/registry/components")).type(
    109                 MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form);
    110         assertEquals(ClientResponse.Status.OK.getStatusCode(),
    111                 cResponse.getStatus());
    112         RegisterResponse response = cResponse.getEntity(RegisterResponse.class);
    113         assertTrue(response.isRegistered());
    114         ComponentDescription desc = (ComponentDescription) response
    115                 .getDescription();
    11664
    117         // Re-define with self-recursion
    118         String compContent = "";
    119         compContent += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
    120         compContent += "\n";
    121         compContent += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
    122         compContent += "    xsi:noNamespaceSchemaLocation=\"../../general-component-schema.xsd\">\n";
    123         compContent += "    \n";
    124         compContent += "    <Header/>\n";
    125         compContent += "    \n";
    126         compContent += "    <CMD_Component name=\"Nested\" CardinalityMin=\"1\" CardinalityMax=\"1\">\n";
    127         compContent += "        <CMD_Element name=\"Availability\" ValueScheme=\"string\" />\n";
    128         compContent += "        <CMD_Component ComponentId=\""
    129                 + desc.getId()
    130                 + "\" name=\"Recursive\" CardinalityMin=\"1\" CardinalityMax=\"1\" />\n";
    131         compContent += "    </CMD_Component>\n";
    132         compContent += "\n";
    133         compContent += "</CMD_ComponentSpec>\n";
    134 
    135         // Update component
    136         form = createFormData(
    137                 RegistryTestHelper.getComponentContentAsStream(compContent),
    138                 "UPDATE DESCRIPTION!");
    139         cResponse = getAuthenticatedResource(getResource().path(
    140                         "/registry/components/" + desc.getId() + "/update")).type(
    141                 MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form);
    142         assertEquals(ClientResponse.Status.OK.getStatusCode(),
    143                 cResponse.getStatus());
    144         response = cResponse.getEntity(RegisterResponse.class);
    145         assertFalse("Recursive definition should fail", response.isRegistered());
    146         assertEquals("There should be an error message for the recursion", 1,
    147                 response.getErrors().size());
    148         assertTrue(
    149                 "There error message should specify the point of recursion",
    150                 response.getErrors().get(0)
    151                         .contains("already contains " + desc.getId()));
    152 
     65        profile1 = RegistryTestHelper.addProfile(baseRegistry, "profile2", true);
     66        profile2 = RegistryTestHelper.addProfile(baseRegistry, "profile1", true);
     67        component1 = RegistryTestHelper.addComponent(baseRegistry,
     68                "component2", true);
     69        component2 = RegistryTestHelper.addComponent(baseRegistry,
     70                "component1", true);
     71        profile1Comment2 = RegistryTestHelper.addComment(baseRegistry, "comment2",
     72                ProfileDescription.PROFILE_PREFIX + "profile1",
     73                "JUnit@test.com");
     74        profile1Comment1 = RegistryTestHelper.addComment(baseRegistry, "comment1",
     75                ProfileDescription.PROFILE_PREFIX + "profile1",
     76                "JUnit@test.com");
     77        component1Comment3 = RegistryTestHelper.addComment(baseRegistry, "comment3",
     78                ComponentDescription.COMPONENT_PREFIX + "component1",
     79                "JUnit@test.com");
     80        component1Comment4 = RegistryTestHelper.addComment(baseRegistry, "comment4",
     81                ComponentDescription.COMPONENT_PREFIX + "component1",
     82                "JUnit@test.com");
    15383    }
    15484
    155      private FormDataMultiPart createFormData(Object content) {
    156         return createFormData(content, "My Test");
     85    private void fillUpPrivateItems() throws Exception {
     86        profile3 = RegistryTestHelper.addProfile(baseRegistry, "profile3", false);
     87        component3 = RegistryTestHelper.addComponent(baseRegistry,
     88                "component3", false);
     89        profile3Comment5 = RegistryTestHelper.addComment(baseRegistry, "comment5",
     90                ProfileDescription.PROFILE_PREFIX + "profile3",
     91                "JUnit@test.com");
     92        component3Comment7 = RegistryTestHelper.addComment(baseRegistry, "comment7",
     93                ComponentDescription.COMPONENT_PREFIX + "component3",
     94                "JUnit@test.com");
     95    }
     96
     97    @Test
     98    public void testDeleteCommentFromPublicProfile() throws Exception {
     99
     100        System.out.println("testDeleteCommentFromPublicProfile");
     101
     102        fillUpPublicItems();
     103
     104        List<Comment> comments = this.getAuthenticatedResource(getResource().path(
     105                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
     106                + "profile1/comments")).get(COMMENT_LIST_GENERICTYPE);
     107        assertEquals(2, comments.size());
     108        Comment aComment = this.getAuthenticatedResource(getResource().path(
     109                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
     110                + "profile1/comments/" + profile1Comment1.getId())).get(Comment.class);
     111        assertNotNull(aComment);
     112
     113        // Try to delete from other profile
     114        ClientResponse response = getAuthenticatedResource(
     115                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
     116                + "profile2/comments/9999").delete(ClientResponse.class);
     117        assertEquals(500, response.getStatus());
     118        // Delete from correct profile
     119        response = getAuthenticatedResource(
     120                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
     121                + "profile1/comments/" + profile1Comment1.getId()).delete(ClientResponse.class);
     122        assertEquals(200, response.getStatus());
     123
     124        comments = this.getAuthenticatedResource(getResource().path(
     125                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
     126                + "profile1/comments/")).get(COMMENT_LIST_GENERICTYPE);
     127        assertEquals(1, comments.size());
     128
     129        response = getAuthenticatedResource(
     130                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
     131                + "profile1/comments/" + profile1Comment2.getId()).delete(ClientResponse.class);
     132        assertEquals(200, response.getStatus());
     133
     134        comments = this.getAuthenticatedResource(getResource().path(
     135                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
     136                + "profile1/comments")).get(COMMENT_LIST_GENERICTYPE);
     137        assertEquals(0, comments.size());
     138    }
     139
     140    private FormDataMultiPart createFormData(Object content) {
     141        return createFormData(content, "My Test");
    157142    }
    158143
    159144    private FormDataMultiPart createFormData(Object content, String description) {
    160         FormDataMultiPart form = new FormDataMultiPart();
    161         form.field(IComponentRegistryRestService.DATA_FORM_FIELD, content,
    162                 MediaType.APPLICATION_OCTET_STREAM_TYPE);
    163         form.field(IComponentRegistryRestService.NAME_FORM_FIELD, "Test1");
    164         form.field(IComponentRegistryRestService.DESCRIPTION_FORM_FIELD,
    165                 description);
    166         form.field(IComponentRegistryRestService.DOMAIN_FORM_FIELD, "My domain");
    167         form.field(IComponentRegistryRestService.GROUP_FORM_FIELD, "TestGroup");
    168         return form;
     145        FormDataMultiPart form = new FormDataMultiPart();
     146        form.field(IComponentRegistryRestService.DATA_FORM_FIELD, content,
     147                MediaType.APPLICATION_OCTET_STREAM_TYPE);
     148        form.field(IComponentRegistryRestService.NAME_FORM_FIELD, "Test1");
     149        form.field(IComponentRegistryRestService.DESCRIPTION_FORM_FIELD,
     150                description);
     151        form.field(IComponentRegistryRestService.DOMAIN_FORM_FIELD, "My domain");
     152        form.field(IComponentRegistryRestService.GROUP_FORM_FIELD, "TestGroup");
     153        return form;
    169154    }
    170155}
Note: See TracChangeset for help on using the changeset viewer.