Ignore:
Timestamp:
08/11/14 16:07:55 (10 years ago)
Author:
olhsha@mpi.nl
Message:

Added group service. Tested via the tomcat on loclahots (test URI and postman), old unit tests are adjusted and work well. Todo: retest on localhost tomcat, look at run-time exceptions, add new unit tests, adjust front-end

File:
1 edited

Legend:

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

    r4550 r5549  
    33import clarin.cmdi.componentregistry.ComponentRegistry;
    44import clarin.cmdi.componentregistry.ComponentRegistryFactory;
    5 import clarin.cmdi.componentregistry.ComponentStatus;
    65import clarin.cmdi.componentregistry.components.CMDComponentSpec;
    76import clarin.cmdi.componentregistry.components.CMDComponentType;
     
    1413import clarin.cmdi.componentregistry.model.ProfileDescription;
    1514import clarin.cmdi.componentregistry.model.RegisterResponse;
    16 import static clarin.cmdi.componentregistry.rest.ComponentRegistryRestService.USERSPACE_PARAM;
     15import static clarin.cmdi.componentregistry.rest.ComponentRegistryRestService.REGISTRY_SPACE_PARAM;
    1716
    1817import com.sun.jersey.api.client.ClientResponse;
     
    3231
    3332import org.junit.Before;
     33import org.junit.Ignore;
    3434import org.junit.Test;
    3535import org.springframework.beans.factory.annotation.Autowired;
     
    5353    @Autowired
    5454    private JdbcTemplate jdbcTemplate;
    55     private ComponentRegistry testRegistry;
     55    private ComponentRegistry baseRegistry;
    5656
    5757    @Before
     
    5959        ComponentRegistryTestDatabase.resetAndCreateAllTables(jdbcTemplate);
    6060        createUserRecord();
    61         // Get public component registry
    62         testRegistry = componentRegistryBeanFactory.getNewComponentRegistry();
    63     }
    64 
    65     private ComponentRegistry getTestRegistry() {
    66         return testRegistry;
     61        baseRegistry = componentRegistryFactory.getBaseRegistry(DummyPrincipal.DUMMY_CREDENTIALS);
    6762    }
    6863
     
    7671    private ProfileDescription profile2;
    7772   
     73    private ComponentDescription component3;
     74    private ProfileDescription profile3;
     75   
    7876    private Comment profile1Comment1;
    7977    private Comment profile1Comment2;
    8078    private Comment component1Comment3;
    8179    private Comment component1Comment4;
    82 
    83     private void fillUp() throws Exception {
    84         profile1 = RegistryTestHelper.addProfile(getTestRegistry(), "profile2");
    85         profile2 = RegistryTestHelper.addProfile(getTestRegistry(), "profile1");
    86         component1 = RegistryTestHelper.addComponent(getTestRegistry(),
    87                 "component2");
    88         component2 = RegistryTestHelper.addComponent(getTestRegistry(),
    89                 "component1");
    90         profile1Comment2 = RegistryTestHelper.addComment(getTestRegistry(), "comment2",
     80   
     81    private Comment profile3Comment5;
     82    private Comment component3Comment7;
     83
     84    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",
    9193                ProfileDescription.PROFILE_PREFIX + "profile1",
    9294                "JUnit@test.com");
    93         profile1Comment1 = RegistryTestHelper.addComment(getTestRegistry(), "comment1",
     95        profile1Comment1 = RegistryTestHelper.addComment(baseRegistry, "comment1",
    9496                ProfileDescription.PROFILE_PREFIX + "profile1",
    9597                "JUnit@test.com");
    96         component1Comment3 = RegistryTestHelper.addComment(getTestRegistry(), "comment3",
     98        component1Comment3 = RegistryTestHelper.addComment(baseRegistry, "comment3",
    9799                ComponentDescription.COMPONENT_PREFIX + "component1",
    98100                "JUnit@test.com");
    99         component1Comment4 = RegistryTestHelper.addComment(getTestRegistry(), "comment4",
     101        component1Comment4 = RegistryTestHelper.addComment(baseRegistry, "comment4",
    100102                ComponentDescription.COMPONENT_PREFIX + "component1",
    101103                "JUnit@test.com");
    102104    }
    103 
    104     @Test
    105     public void testGetRegisteredProfiles() throws Exception {
    106         fillUp();
    107         RegistryTestHelper.addProfile(getTestRegistry(), "PROFILE2");
    108         List<ProfileDescription> response = getResource()
    109                 .path("/registry/profiles").accept(MediaType.APPLICATION_XML)
     105   
     106    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
     119    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)
    110126                .get(PROFILE_LIST_GENERICTYPE);
    111127        assertEquals(3, response.size());
    112         response = getResource().path("/registry/profiles")
     128        response = this.getAuthenticatedResource(getResource()
     129                .path("/registry/profiles"))
    113130                .accept(MediaType.APPLICATION_JSON)
    114131                .get(PROFILE_LIST_GENERICTYPE);
     
    119136    }
    120137
    121     @Test
    122     public void testGetRegisteredComponents() throws Exception {
    123         fillUp();
    124         RegistryTestHelper.addComponent(getTestRegistry(), "COMPONENT2");
    125         List<ComponentDescription> response = getResource()
    126                 .path("/registry/components").accept(MediaType.APPLICATION_XML)
     138    @Test //ok
     139    public void testGetPublicComponents() throws Exception {
     140       
     141        fillUpPublicItems();
     142       
     143        RegistryTestHelper.addComponent(baseRegistry, "COMPONENT2", true);
     144        List<ComponentDescription> response = this.getAuthenticatedResource(getResource()
     145                .path("/registry/components")).accept(MediaType.APPLICATION_XML)
    127146                .get(COMPONENT_LIST_GENERICTYPE);
    128147        assertEquals(3, response.size());
    129         response = getResource().path("/registry/components")
     148        response = this.getAuthenticatedResource(getResource()
     149                .path("/registry/components"))
    130150                .accept(MediaType.APPLICATION_JSON)
    131151                .get(COMPONENT_LIST_GENERICTYPE);
     
    136156    }
    137157
    138     @Test
     158    @Test  //ok
    139159    public void testGetUserComponents() throws Exception {
    140         fillUp();
    141         List<ComponentDescription> response = getUserComponents();
    142         assertEquals(0, response.size());
    143         response = getAuthenticatedResource(
    144                 getResource().path("/registry/components")).accept(
     160       
     161        fillUpPrivateItems();
     162       
     163        List<ComponentDescription> response = this.getUserComponents();
     164        assertEquals(1, response.size());
     165       
     166        ////
     167       
     168        fillUpPublicItems();
     169        response = getAuthenticatedResource(getResource().path("/registry/components")).accept(
    145170                MediaType.APPLICATION_JSON).get(COMPONENT_LIST_GENERICTYPE);
    146171        assertEquals("Get public components", 2, response.size());
     172       
    147173        ClientResponse cResponse = getResource().path("/registry/components")
    148                 .queryParam(USERSPACE_PARAM, "true")
     174                .queryParam(REGISTRY_SPACE_PARAM, "private")
    149175                .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
    150176        assertEquals("Trying to get userspace without credentials", 401,
     
    152178    }
    153179
    154     @Test
    155     public void testGetRegisteredComponent() throws Exception {
    156         fillUp();
    157         String id = ComponentDescription.COMPONENT_PREFIX + "component1";
     180    @Test //ok
     181    public void testGetPublicComponent() throws Exception {
     182       
     183        fillUpPublicItems();
     184       
     185        String id = ComponentDescription.COMPONENT_PREFIX + "component1";
    158186        String id2 = ComponentDescription.COMPONENT_PREFIX + "component2";
    159         CMDComponentSpec component = getResource()
    160                 .path("/registry/components/" + id)
     187        CMDComponentSpec component = this.getAuthenticatedResource(getResource()
     188                .path("/registry/components/" + id))
    161189                .accept(MediaType.APPLICATION_JSON).get(CMDComponentSpec.class);
    162190        assertNotNull(component);
    163191        assertEquals("Access", component.getCMDComponent().getName());
    164         component = getResource().path("/registry/components/" + id2)
     192       
     193       
     194        component = this.getAuthenticatedResource(getResource().path("/registry/components/" + id2))
    165195                .accept(MediaType.APPLICATION_XML).get(CMDComponentSpec.class);
    166196        assertNotNull(component);
    167197        assertEquals("Access", component.getCMDComponent().getName());
    168 
    169198        assertEquals(id2, component.getHeader().getID());
    170199        assertEquals("component2", component.getHeader().getName());
     
    172201    }
    173202
    174     @Test
    175     public void testGetRegisteredCommentsInProfile() throws Exception {
    176         fillUp();
     203    @Test   // ok   
     204    public void testGetCommentsInPublicProfile() throws Exception {
     205       
     206        fillUpPublicItems();
     207       
    177208        String id = ProfileDescription.PROFILE_PREFIX + "profile1";
    178         RegistryTestHelper.addComment(getTestRegistry(), "COMMENT1", id,
     209        RegistryTestHelper.addComment(baseRegistry, "COMMENT1", id,
    179210                "JUnit@test.com");
    180         List<Comment> response = getResource()
    181                 .path("/registry/profiles/" + id + "/comments/")
     211        List<Comment> response = this.getAuthenticatedResource(getResource()
     212                .path("/registry/profiles/" + id + "/comments/"))
    182213                .accept(MediaType.APPLICATION_XML)
    183214                .get(COMMENT_LIST_GENERICTYPE);
    184215        assertEquals(3, response.size());
    185         response = getResource().path("/registry/profiles/" + id + "/comments")
     216       
     217        response = this.getAuthenticatedResource(getResource().path("/registry/profiles/" + id + "/comments"))
    186218                .accept(MediaType.APPLICATION_JSON)
    187219                .get(COMMENT_LIST_GENERICTYPE);
     
    194226    }
    195227
    196     @Test
    197     public void testGetRegisteredCommentsInComponent() throws Exception {
    198         fillUp();
     228    @Test // ok
     229    public void testGetCommentsInPubliComponent() throws Exception {
     230        fillUpPublicItems();
     231       
    199232        String id = ComponentDescription.COMPONENT_PREFIX + "component1";
    200         RegistryTestHelper.addComment(getTestRegistry(), "COMMENT2", id,
     233        RegistryTestHelper.addComment(baseRegistry, "COMMENT2", id,
    201234                "JUnit@test.com");
    202         List<Comment> response = getResource()
    203                 .path("/registry/components/" + id + "/comments/")
     235        List<Comment> response = this.getAuthenticatedResource(getResource()
     236                .path("/registry/components/" + id + "/comments/"))
    204237                .accept(MediaType.APPLICATION_XML)
    205238                .get(COMMENT_LIST_GENERICTYPE);
    206239        assertEquals(3, response.size());
    207         response = getResource()
    208                 .path("/registry/components/" + id + "/comments")
     240        response = this.getAuthenticatedResource(getResource()
     241                .path("/registry/components/" + id + "/comments"))
    209242                .accept(MediaType.APPLICATION_JSON)
    210243                .get(COMMENT_LIST_GENERICTYPE);
     
    217250    }
    218251
    219     @Test
    220     public void testGetSpecifiedCommentInComponent() throws Exception {
    221         fillUp();
     252    @Test // ok
     253    public void testGetSpecifiedCommentInPublicComponent() throws Exception {
     254       
     255        fillUpPublicItems();
     256       
    222257        String id = ComponentDescription.COMPONENT_PREFIX + "component1";
    223         Comment comment = getResource()
    224                 .path("/registry/components/" + id + "/comments/"+component1Comment3.getId())
     258        Comment comment = this.getAuthenticatedResource(getResource()
     259                .path("/registry/components/" + id + "/comments/"+component1Comment3.getId()))
    225260                .accept(MediaType.APPLICATION_JSON).get(Comment.class);
    226261        assertNotNull(comment);
    227262        assertEquals("comment3", comment.getComment());
    228263        assertEquals(component1Comment3.getId(), comment.getId());
    229         comment = getResource()
    230                 .path("/registry/components/" + id + "/comments/"+component1Comment4.getId())
     264        comment = this.getAuthenticatedResource(getResource()
     265                .path("/registry/components/" + id + "/comments/"+component1Comment4.getId()))
    231266                .accept(MediaType.APPLICATION_JSON).get(Comment.class);
    232267        assertNotNull(comment);
     
    236271    }
    237272
    238     @Test
    239     public void testGetSpecifiedCommentInProfile() throws Exception {
    240         fillUp();
     273    @Test //ok
     274    public void testGetSpecifiedCommentInPublicProfile() throws Exception {
     275       
     276        fillUpPublicItems();
     277       
    241278        String id = ProfileDescription.PROFILE_PREFIX + "profile1";
    242         Comment comment = getResource()
    243                 .path("/registry/profiles/" + id + "/comments/"+profile1Comment2.getId())
     279        Comment comment = this.getAuthenticatedResource(getResource()
     280                .path("/registry/profiles/" + id + "/comments/"+profile1Comment2.getId()))
    244281                .accept(MediaType.APPLICATION_JSON).get(Comment.class);
    245282        assertNotNull(comment);
    246283        assertEquals("comment2", comment.getComment());
    247284        assertEquals(profile1Comment2.getId(), comment.getId());
    248         comment = getResource()
    249                 .path("/registry/profiles/" + id + "/comments/"+profile1Comment1.getId())
    250                 .accept(MediaType.APPLICATION_JSON).get(Comment.class);
     285       
     286        comment = this.getAuthenticatedResource(getResource()
     287                .path("/registry/profiles/" + id + "/comments/"+profile1Comment1.getId()))
     288                .accept(MediaType.APPLICATION_JSON).get(Comment.class);
    251289        assertNotNull(comment);
    252290        assertEquals("comment1", comment.getComment());
     
    255293    }
    256294
    257     @Test
    258     public void testDeleteCommentFromComponent() throws Exception {
    259         fillUp();
     295    @Test  //ok
     296    public void testDeleteCommentFromPublicComponent() throws Exception {
     297       
     298        fillUpPublicItems();
     299       
    260300        String id = ComponentDescription.COMPONENT_PREFIX + "component1";
    261301        String id2 = ComponentDescription.COMPONENT_PREFIX + "component2";
    262         List<Comment> comments = getResource().path(
    263                 "/registry/components/" + id + "/comments").get(
     302        List<Comment> comments = this.getAuthenticatedResource(getResource().path(
     303                "/registry/components/" + id + "/comments")).get(
    264304                COMMENT_LIST_GENERICTYPE);
    265305        assertEquals(2, comments.size());
    266         Comment aComment = getResource().path(
    267                 "/registry/components/" + id + "/comments/"+component1Comment3.getId())
     306        Comment aComment = this.getAuthenticatedResource(getResource().path(
     307                "/registry/components/" + id + "/comments/"+component1Comment3.getId()))
    268308                .get(Comment.class);
    269309        assertNotNull(aComment);
     
    280320        assertEquals(200, response.getStatus());
    281321
    282         comments = getResource().path(
    283                 "/registry/components/" + id + "/comments/").get(
     322        comments = this.getAuthenticatedResource(getResource().path(
     323                "/registry/components/" + id + "/comments/")).get(
    284324                COMMENT_LIST_GENERICTYPE);
    285325        assertEquals(1, comments.size());
     
    290330        assertEquals(200, response.getStatus());
    291331
    292         comments = getResource().path(
    293                 "/registry/components/" + id + "/comments").get(
     332        comments = this.getAuthenticatedResource(getResource().path(
     333                "/registry/components/" + id + "/comments")).get(
    294334                COMMENT_LIST_GENERICTYPE);
    295335        assertEquals(0, comments.size());
     
    297337
    298338    @Test
    299     public void testManipulateCommentFromComponent() throws Exception {
    300         fillUp();
    301         List<Comment> comments = getResource().path(
     339    public void testManipulateCommentFromPublicComponent() throws Exception {
     340       
     341        fillUpPublicItems();
     342       
     343        List<Comment> comments = this.getAuthenticatedResource(getResource().path(
    302344                "/registry/components/" + ComponentDescription.COMPONENT_PREFIX
    303                         + "component1/comments").get(COMMENT_LIST_GENERICTYPE);
     345                        + "component1/comments")).get(COMMENT_LIST_GENERICTYPE);
    304346        assertEquals(2, comments.size());
    305         Comment aComment = getResource().path(
     347        Comment aComment = this.getAuthenticatedResource(getResource().path(
    306348                "/registry/components/" + ComponentDescription.COMPONENT_PREFIX
    307                         + "component1/comments/"+component1Comment3.getId()).get(Comment.class);
     349                        + "component1/comments/"+component1Comment3.getId())).get(Comment.class);
    308350        assertNotNull(aComment);
    309351
     
    318360        assertEquals(200, response.getStatus());
    319361
    320         comments = getResource().path(
     362        comments = this.getAuthenticatedResource(getResource().path(
    321363                "/registry/components/" + ComponentDescription.COMPONENT_PREFIX
    322                         + "component1/comments/").get(COMMENT_LIST_GENERICTYPE);
     364                        + "component1/comments/")).get(COMMENT_LIST_GENERICTYPE);
    323365        assertEquals(1, comments.size());
    324366    }
    325367
    326368    @Test
    327     public void testDeleteCommentFromProfile() throws Exception {
    328         fillUp();
    329         List<Comment> comments = getResource().path(
     369    public void testDeleteCommentFromPublicProfile() throws Exception {
     370       
     371        fillUpPublicItems();
     372       
     373        List<Comment> comments = this.getAuthenticatedResource(getResource().path(
    330374                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
    331                         + "profile1/comments").get(COMMENT_LIST_GENERICTYPE);
     375                        + "profile1/comments")).get(COMMENT_LIST_GENERICTYPE);
    332376        assertEquals(2, comments.size());
    333         Comment aComment = getResource().path(
     377        Comment aComment = this.getAuthenticatedResource(getResource().path(
    334378                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
    335                         + "profile1/comments/"+profile1Comment1.getId()).get(Comment.class);
     379                        + "profile1/comments/"+profile1Comment1.getId())).get(Comment.class);
    336380        assertNotNull(aComment);
    337381
     
    347391        assertEquals(200, response.getStatus());
    348392
    349         comments = getResource().path(
     393        comments = this.getAuthenticatedResource(getResource().path(
    350394                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
    351                         + "profile1/comments/").get(COMMENT_LIST_GENERICTYPE);
     395                        + "profile1/comments/")).get(COMMENT_LIST_GENERICTYPE);
    352396        assertEquals(1, comments.size());
    353397
     
    357401        assertEquals(200, response.getStatus());
    358402
    359         comments = getResource().path(
     403        comments = this.getAuthenticatedResource(getResource().path(
    360404                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
    361                         + "profile1/comments").get(COMMENT_LIST_GENERICTYPE);
     405                        + "profile1/comments")).get(COMMENT_LIST_GENERICTYPE);
    362406        assertEquals(0, comments.size());
    363407    }
    364408
    365409    @Test
    366     public void testManipulateCommentFromProfile() throws Exception {
    367         fillUp();
    368         List<Comment> comments = getResource().path(
     410    public void testManipulateCommentFromPublicProfile() throws Exception {
     411       
     412        fillUpPublicItems();
     413       
     414        List<Comment> comments = this.getAuthenticatedResource(getResource().path(
    369415                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
    370                         + "profile1/comments").get(COMMENT_LIST_GENERICTYPE);
     416                        + "profile1/comments")).get(COMMENT_LIST_GENERICTYPE);
    371417        assertEquals(2, comments.size());
    372         Comment aComment = getResource().path(
     418        Comment aComment = this.getAuthenticatedResource(getResource().path(
    373419                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
    374                         + "profile1/comments/"+profile1Comment2.getId()).get(Comment.class);
     420                        + "profile1/comments/"+profile1Comment2.getId())).get(Comment.class);
    375421        assertNotNull(aComment);
    376422
     
    384430        assertEquals(200, response.getStatus());
    385431
    386         comments = getResource().path(
     432        comments = this.getAuthenticatedResource(getResource().path(
    387433                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
    388                         + "profile1/comments/").get(COMMENT_LIST_GENERICTYPE);
     434                        + "profile1/comments/")).get(COMMENT_LIST_GENERICTYPE);
    389435        assertEquals(1, comments.size());
    390436    }
    391437
    392438    @Test
    393     public void testDeleteRegisteredComponent() throws Exception {
    394         fillUp();
    395         List<ComponentDescription> components = getResource().path(
    396                 "/registry/components").get(COMPONENT_LIST_GENERICTYPE);
     439    public void testDeletePublicComponent() throws Exception {
     440       
     441        fillUpPublicItems();
     442       
     443        List<ComponentDescription> components = this.getAuthenticatedResource(getResource().path(
     444                "/registry/components")).get(COMPONENT_LIST_GENERICTYPE);
    397445        assertEquals(2, components.size());
    398         CMDComponentSpec profile = getResource().path(
     446        CMDComponentSpec profile = this.getAuthenticatedResource(getResource().path(
    399447                "/registry/components/" + ComponentDescription.COMPONENT_PREFIX
    400                         + "component1").get(CMDComponentSpec.class);
     448                        + "component1")).get(CMDComponentSpec.class);
    401449        assertNotNull(profile);
    402450        ClientResponse response = getAuthenticatedResource(
     
    405453        assertEquals(200, response.getStatus());
    406454
    407         components = getResource().path("/registry/components").get(
     455        components = this.getAuthenticatedResource(getResource().path("/registry/components")).get(
    408456                COMPONENT_LIST_GENERICTYPE);
    409457        assertEquals(1, components.size());
     
    414462        assertEquals(200, response.getStatus());
    415463
    416         components = getResource().path("/registry/components").get(
     464        components = this.getAuthenticatedResource(getResource().path("/registry/components")).get(
    417465                COMPONENT_LIST_GENERICTYPE);
    418466        assertEquals(0, components.size());
     
    425473
    426474    @Test
    427     public void testDeleteRegisteredComponentStillUsed() throws Exception {
    428         String content = "";
     475    public void testDeletePublicComponentStillUsed() throws Exception {
     476       
     477        fillUpPublicItems();
     478       
     479        String content = "";
    429480        content += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
    430481        content += "    xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n";
     
    435486        content += "</CMD_ComponentSpec>\n";
    436487        ComponentDescription compDesc1 = RegistryTestHelper.addComponent(
    437                 getTestRegistry(), "XXX1", content);
     488                baseRegistry, "XXX1", content, true);
    438489
    439490        content = "";
     
    448499        content += "</CMD_ComponentSpec>\n";
    449500        ComponentDescription compDesc2 = RegistryTestHelper.addComponent(
    450                 getTestRegistry(), "YYY1", content);
     501                baseRegistry, "YYY1", content,true);
    451502
    452503        content = "";
     
    461512        content += "</CMD_ComponentSpec>\n";
    462513        ProfileDescription profile = RegistryTestHelper.addProfile(
    463                 getTestRegistry(), "TestProfile3", content);
    464 
    465         List<ComponentDescription> components = getResource().path(
    466                 "/registry/components").get(COMPONENT_LIST_GENERICTYPE);
    467         assertEquals(2, components.size());
     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());
    468519
    469520        ClientResponse response = getAuthenticatedResource(
     
    475526                response.getEntity(String.class));
    476527
    477         components = getResource().path("/registry/components").get(
     528        components = this.getAuthenticatedResource(getResource().path("/registry/components")).get(
    478529                COMPONENT_LIST_GENERICTYPE);
    479         assertEquals(2, components.size());
     530        assertEquals(4, components.size());
    480531
    481532        response = getAuthenticatedResource(
     
    491542                ClientResponse.class);
    492543        assertEquals(200, response.getStatus());
    493         components = getResource().path("/registry/components").get(
     544        components = this.getAuthenticatedResource(getResource().path("/registry/components")).get(
    494545                COMPONENT_LIST_GENERICTYPE);
    495         assertEquals(0, components.size());
    496     }
    497 
    498     @Test
    499     public void testManipulateRegisteredComponent() throws Exception {
    500         fillUp();
    501         List<ComponentDescription> components = getResource().path(
    502                 "/registry/components").get(COMPONENT_LIST_GENERICTYPE);
    503546        assertEquals(2, components.size());
    504         CMDComponentSpec profile = getResource().path(
     547    }
     548
     549    @Test
     550    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(
    505558                "/registry/components/" + ComponentDescription.COMPONENT_PREFIX
    506                         + "component1").get(CMDComponentSpec.class);
     559                        + "component1")).get(CMDComponentSpec.class);
    507560        assertNotNull(profile);
    508561
     
    516569        assertEquals(200, response.getStatus());
    517570
    518         components = getResource().path("/registry/components").get(
     571        components = this.getAuthenticatedResource(getResource().path("/registry/components")).get(
    519572                COMPONENT_LIST_GENERICTYPE);
    520573        assertEquals(1, components.size());
     
    529582    @Test
    530583    public void testGetRegisteredProfile() throws Exception {
    531         fillUp();
     584       
     585        fillUpPublicItems();
     586       
    532587        String id = ProfileDescription.PROFILE_PREFIX + "profile1";
    533588        String id2 = ProfileDescription.PROFILE_PREFIX + "profile2";
    534         CMDComponentSpec profile = getResource()
    535                 .path("/registry/profiles/" + id)
     589        CMDComponentSpec profile = this.getAuthenticatedResource(getResource()
     590                .path("/registry/profiles/" + id))
    536591                .accept(MediaType.APPLICATION_JSON).get(CMDComponentSpec.class);
    537592        assertNotNull(profile);
    538593        assertEquals("Actor", profile.getCMDComponent().getName());
    539         profile = getResource().path("/registry/profiles/" + id2)
     594        profile = this.getAuthenticatedResource(getResource().path("/registry/profiles/" + id2))
    540595                .accept(MediaType.APPLICATION_XML).get(CMDComponentSpec.class);
    541596        assertNotNull(profile);
     
    547602
    548603        try {
    549             profile = getResource()
     604            profile = this.getAuthenticatedResource(getResource()
    550605                    .path("/registry/profiles/"
    551                             + ProfileDescription.PROFILE_PREFIX + "profileXXXX")
     606                            + ProfileDescription.PROFILE_PREFIX + "profileXXXX"))
    552607                    .accept(MediaType.APPLICATION_XML)
    553608                    .get(CMDComponentSpec.class);
     
    560615    @Test
    561616    public void testGetRegisteredProfileRawData() throws Exception {
    562         fillUp();
    563         String profile = getResource()
     617       
     618        fillUpPublicItems();
     619       
     620        String profile = this.getAuthenticatedResource(getResource()
    564621                .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
    565                         + "profile1/xsd").accept(MediaType.TEXT_XML)
     622                        + "profile1/xsd")).accept(MediaType.TEXT_XML)
    566623                .get(String.class).trim();
    567624        assertTrue(profile
     
    569626        assertTrue(profile.endsWith("</xs:schema>"));
    570627
    571         profile = getResource()
     628        profile = this.getAuthenticatedResource(getResource()
    572629                .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
    573                         + "profile1/xml").accept(MediaType.TEXT_XML)
     630                        + "profile1/xml")).accept(MediaType.TEXT_XML)
    574631                .get(String.class).trim();
    575632        assertTrue(profile
     
    579636
    580637        try {
    581             getResource()
     638            this.getAuthenticatedResource(getResource()
    582639                    .path("/registry/components/"
    583640                            + ComponentDescription.COMPONENT_PREFIX
    584                             + "component1/xsl").accept(MediaType.TEXT_XML)
     641                            + "component1/xsl")).accept(MediaType.TEXT_XML)
    585642                    .get(String.class);
    586643            fail("Should have thrown exception, unsupported path parameter");
     
    589646    }
    590647
     648    //
    591649    @Test
    592650    public void testPrivateProfileXsd() throws Exception {
     651       
     652        fillUpPublicItems();
     653       
    593654        FormDataMultiPart form = createFormData(RegistryTestHelper
    594655                .getTestProfileContent());
    595         RegisterResponse response = getAuthenticatedResource(
    596                 getResource().path("/registry/profiles").queryParam(
    597                         USERSPACE_PARAM, "true")).type(
     656        RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/profiles").queryParam(
     657                        REGISTRY_SPACE_PARAM, "private")).type(
    598658                MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class,
    599659                form);
     
    601661        assertEquals(1, getUserProfiles().size());
    602662        BaseDescription desc = response.getDescription();
    603         String profile = getResource()
    604                 .path("/registry/profiles/" + desc.getId() + "/xsd")
     663        String profile = this.getAuthenticatedResource(getResource()
     664                .path("/registry/profiles/" + desc.getId() + "/xsd"))
    605665                .accept(MediaType.TEXT_XML).get(String.class).trim();
    606666        assertTrue(profile
     
    611671    @Test
    612672    public void testPrivateComponentXsd() throws Exception {
     673       
     674        fillUpPublicItems();
     675       
    613676        FormDataMultiPart form = createFormData(RegistryTestHelper
    614677                .getComponentTestContent());
    615678        RegisterResponse response = getAuthenticatedResource(
    616679                getResource().path("/registry/components").queryParam(
    617                         USERSPACE_PARAM, "true")).type(
     680                        REGISTRY_SPACE_PARAM, "private")).type(
    618681                MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class,
    619682                form);
     
    621684        assertEquals(1, getUserComponents().size());
    622685        BaseDescription desc = response.getDescription();
    623         String profile = getResource()
    624                 .path("/registry/components/" + desc.getId() + "/xsd")
     686        String profile = this.getAuthenticatedResource(getResource()
     687                .path("/registry/components/" + desc.getId() + "/xsd"))
    625688                .accept(MediaType.TEXT_XML).get(String.class).trim();
    626689        assertTrue(profile
     
    631694    @Test
    632695    public void testDeleteRegisteredProfile() throws Exception {
    633         fillUp();
    634         List<ProfileDescription> profiles = getResource().path(
    635                 "/registry/profiles").get(PROFILE_LIST_GENERICTYPE);
     696       
     697        fillUpPublicItems();
     698       
     699        List<ProfileDescription> profiles = this.getAuthenticatedResource(getResource().path(
     700                "/registry/profiles")).get(PROFILE_LIST_GENERICTYPE);
    636701        assertEquals(2, profiles.size());
    637         CMDComponentSpec profile = getResource().path(
     702        CMDComponentSpec profile = this.getAuthenticatedResource(getResource().path(
    638703                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
    639                         + "profile1").get(CMDComponentSpec.class);
     704                        + "profile1")).get(CMDComponentSpec.class);
    640705        assertNotNull(profile);
    641706
     
    645710        assertEquals(200, response.getStatus());
    646711
    647         profiles = getResource().path("/registry/profiles").get(
     712        profiles = this.getAuthenticatedResource(getResource().path("/registry/profiles")).get(
    648713                PROFILE_LIST_GENERICTYPE);
    649714        assertEquals(1, profiles.size());
     
    654719        assertEquals(200, response.getStatus());
    655720
    656         profiles = getResource().path("/registry/profiles").get(
     721        profiles = this.getAuthenticatedResource(getResource().path("/registry/profiles")).get(
    657722                PROFILE_LIST_GENERICTYPE);
    658723        assertEquals(0, profiles.size());
     
    661726                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
    662727                        + "profile1").delete(ClientResponse.class);
    663         assertEquals(200, response.getStatus());
     728        assertEquals(404, response.getStatus());
    664729    }
    665730
    666731    @Test
    667732    public void testManipulateRegisteredProfile() throws Exception {
    668         fillUp();
    669         List<ProfileDescription> profiles = getResource().path(
    670                 "/registry/profiles").get(PROFILE_LIST_GENERICTYPE);
     733       
     734        fillUpPublicItems();
     735       
     736        List<ProfileDescription> profiles = this.getAuthenticatedResource(getResource().path(
     737                "/registry/profiles")).get(PROFILE_LIST_GENERICTYPE);
    671738        assertEquals(2, profiles.size());
    672         CMDComponentSpec profile = getResource().path(
     739        CMDComponentSpec profile = this.getAuthenticatedResource(getResource().path(
    673740                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
    674                         + "profile1").get(CMDComponentSpec.class);
     741                        + "profile1")).get(CMDComponentSpec.class);
    675742        assertNotNull(profile);
    676743
     
    684751        assertEquals(200, response.getStatus());
    685752
    686         profiles = getResource().path("/registry/profiles").get(
     753        profiles = this.getAuthenticatedResource(getResource().path("/registry/profiles")).get(
    687754                PROFILE_LIST_GENERICTYPE);
    688755        assertEquals(1, profiles.size());
     
    697764    @Test
    698765    public void testGetRegisteredComponentRawData() throws Exception {
    699         fillUp();
     766       
     767        fillUpPublicItems();
     768       
    700769        String id = ComponentDescription.COMPONENT_PREFIX + "component1";
    701         String component = getResource()
    702                 .path("/registry/components/" + id + "/xsd")
     770        String component = this.getAuthenticatedResource(getResource()
     771                .path("/registry/components/" + id + "/xsd"))
    703772                .accept(MediaType.TEXT_XML).get(String.class).trim();
    704773        assertTrue(component
     
    706775        assertTrue(component.endsWith("</xs:schema>"));
    707776
    708         component = getResource().path("/registry/components/" + id + "/xml")
     777        component = this.getAuthenticatedResource(getResource().path("/registry/components/" + id + "/xml"))
    709778                .accept(MediaType.TEXT_XML).get(String.class).trim();
    710779        assertTrue(component
     
    714783
    715784        try {
    716             getResource()
     785            this.getAuthenticatedResource(getResource()
    717786                    .path("/registry/components/"
    718787                            + ComponentDescription.COMPONENT_PREFIX
    719                             + "component1/jpg").accept(MediaType.TEXT_XML)
     788                            + "component1/jpg")).accept(MediaType.TEXT_XML)
    720789                    .get(String.class);
    721790            fail("Should have thrown exception, unsopported path parameter");
     
    726795    @Test
    727796    public void testRegisterProfile() throws Exception {
     797       
     798        fillUpPublicItems();
     799       
    728800        FormDataMultiPart form = new FormDataMultiPart();
    729801        form.field(IComponentRegistryRestService.DATA_FORM_FIELD,
     
    742814                RegisterResponse.class, form);
    743815        assertTrue(response.isProfile());
    744         assertFalse(response.isInUserSpace());
     816        assertTrue(response.isInUserSpace());
    745817        ProfileDescription profileDesc = (ProfileDescription) response
    746818                .getDescription();
     
    762834    @Test
    763835    public void testPublishProfile() throws Exception {
    764         assertEquals("user registered profiles", 0, getUserProfiles().size());
    765         assertEquals("public registered profiles", 0, getPublicProfiles()
     836       
     837        fillUpPrivateItems();
     838        fillUpPublicItems();
     839       
     840        assertEquals("user registered profiles", 1, getUserProfiles().size());
     841        assertEquals("public registered profiles", 2, getPublicProfiles()
    766842                .size());
    767843        FormDataMultiPart form = createFormData(
    768844                RegistryTestHelper.getTestProfileContent(), "Unpublished");
    769         RegisterResponse response = getAuthenticatedResource(
    770                 getResource().path("/registry/profiles").queryParam(
    771                         USERSPACE_PARAM, "true")).type(
     845        RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/profiles")).type(
    772846                MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class,
    773847                form);
     
    775849        BaseDescription desc = response.getDescription();
    776850        assertEquals("Unpublished", desc.getDescription());
    777         assertEquals(1, getUserProfiles().size());
    778         assertEquals(0, getPublicProfiles().size());
     851        assertEquals(2, getUserProfiles().size());
     852        assertEquals(2, getPublicProfiles().size());
    779853        form = createFormData(
    780854                RegistryTestHelper.getTestProfileContent("publishedName"),
    781855                "Published");
    782         response = getAuthenticatedResource(
    783                 getResource().path(
     856        response = getAuthenticatedResource(getResource().path(
    784857                        "/registry/profiles/" + desc.getId() + "/publish"))
    785858                .type(MediaType.MULTIPART_FORM_DATA).post(
    786859                        RegisterResponse.class, form);
    787860
    788         assertEquals(0, getUserProfiles().size());
     861        assertEquals(1, getUserProfiles().size());
    789862        List<ProfileDescription> profiles = getPublicProfiles();
    790         assertEquals(1, profiles.size());
    791         ProfileDescription profileDescription = profiles.get(0);
     863        assertEquals(3, profiles.size());
     864        ProfileDescription profileDescription = profiles.get(2);
    792865        assertNotNull(profileDescription.getId());
    793866        assertEquals(desc.getId(), profileDescription.getId());
     
    801874    private CMDComponentSpec getPublicSpec(BaseDescription desc) {
    802875        if (desc.isProfile()) {
    803             return getResource().path("/registry/profiles/" + desc.getId())
     876            return this.getAuthenticatedResource(getResource().path("/registry/profiles/" + desc.getId()))
    804877                    .get(CMDComponentSpec.class);
    805878        } else {
    806             return getResource().path("/registry/components/" + desc.getId())
     879            return this.getAuthenticatedResource(getResource().path("/registry/components/" + desc.getId()))
    807880                    .get(CMDComponentSpec.class);
    808881        }
     
    810883
    811884    @Test
    812     public void testPublishComponent() throws Exception {
    813         assertEquals(0, getUserComponents().size());
    814         assertEquals(0, getPublicComponents().size());
     885    public void testPublishRegisteredComponent() throws Exception {
     886       
     887        fillUpPrivateItems();
     888        fillUpPublicItems();
     889       
     890        assertEquals(1, getUserComponents().size());
     891        assertEquals(2, getPublicComponents().size());
     892       
    815893        FormDataMultiPart form = createFormData(
    816894                RegistryTestHelper.getComponentTestContent(), "Unpublished");
    817         RegisterResponse response = getAuthenticatedResource(
    818                 getResource().path("/registry/components").queryParam(
    819                         USERSPACE_PARAM, "true")).type(
     895        RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/components")).type(
    820896                MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class,
    821897                form);
     
    823899        BaseDescription desc = response.getDescription();
    824900        assertEquals("Unpublished", desc.getDescription());
    825         assertEquals(1, getUserComponents().size());
    826         assertEquals(0, getPublicComponents().size());
     901        assertEquals(2, getUserComponents().size());
     902        assertEquals(2, getPublicComponents().size());
    827903        form = createFormData(
    828904                RegistryTestHelper.getComponentTestContentAsStream("publishedName"),
    829905                "Published");
    830         response = getAuthenticatedResource(
    831                 getResource().path(
     906        response = getAuthenticatedResource(getResource().path(
    832907                        "/registry/components/" + desc.getId() + "/publish"))
    833908                .type(MediaType.MULTIPART_FORM_DATA).post(
    834909                        RegisterResponse.class, form);
    835910
    836         assertEquals(0, getUserComponents().size());
     911        assertEquals(1, getUserComponents().size());
    837912        List<ComponentDescription> components = getPublicComponents();
    838         assertEquals(1, components.size());
    839         ComponentDescription componentDescription = components.get(0);
     913        assertEquals(3, components.size());
     914        ComponentDescription componentDescription = components.get(2);
    840915        assertNotNull(componentDescription.getId());
    841916        assertEquals(desc.getId(), componentDescription.getId());
     
    848923    }
    849924
     925    // duplicates ("extendedly") testRegisterProfile, since you can pot only in user space, and then publish or move to group or so
    850926    @Test
    851927    public void testRegisterUserspaceProfile() throws Exception {
     928       
     929        fillUpPrivateItems();
     930        fillUpPublicItems();
     931       
    852932        List<ProfileDescription> profiles = getUserProfiles();
    853         assertEquals("user registered profiles", 0, profiles.size());
    854         assertEquals("public registered profiles", 0, getPublicProfiles()
     933        assertEquals("user registered profiles", 1, profiles.size());
     934        assertEquals("public registered profiles", 2, getPublicProfiles()
    855935                .size());
    856936        FormDataMultiPart form = createFormData(RegistryTestHelper
    857937                .getTestProfileContent());
    858         RegisterResponse response = getAuthenticatedResource(
    859                 getResource().path("/registry/profiles").queryParam(
    860                         USERSPACE_PARAM, "true")).type(
     938        RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/profiles")).type(
    861939                MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class,
    862940                form);
     
    875953        assertEquals(
    876954                "http://localhost:9998/registry/profiles/"
    877                         + profileDesc.getId() + "?userspace=true",
     955                        + profileDesc.getId(),
    878956                profileDesc.getHref());
    879957
    880958        profiles = getUserProfiles();
    881         assertEquals(1, profiles.size());
    882         assertEquals(0, getPublicProfiles().size());
     959        assertEquals(2, profiles.size());
     960        assertEquals(2, getPublicProfiles().size());
    883961
    884962        // Try to post unauthenticated
    885963        ClientResponse cResponse = getResource().path("/registry/profiles")
    886                 .queryParam(USERSPACE_PARAM, "true")
    887964                .type(MediaType.MULTIPART_FORM_DATA)
    888965                .post(ClientResponse.class, form);
    889966        assertEquals(401, cResponse.getStatus());
    890967
    891         // Try get from public registry
    892         cResponse = getResource()
    893                 .path("/registry/profiles/" + profileDesc.getId())
    894                 .accept(MediaType.APPLICATION_XML).get(ClientResponse.class);
    895         // Should return 404 = not found
    896         assertEquals(404, cResponse.getStatus());
    897         CMDComponentSpec spec = getAuthenticatedResource(
    898                 getResource().path("/registry/profiles/" + profileDesc.getId())
    899                         .queryParam(USERSPACE_PARAM, "true")).accept(
     968       
     969       
     970        CMDComponentSpec spec = getAuthenticatedResource(getResource().path("/registry/profiles/" + profileDesc.getId())
     971                        .queryParam(REGISTRY_SPACE_PARAM, "private")).accept(
    900972                MediaType.APPLICATION_XML).get(CMDComponentSpec.class);
    901973        assertNotNull(spec);
    902974
    903         cResponse = getResource()
    904                 .path("/registry/profiles/" + profileDesc.getId() + "/xsd")
     975        cResponse = this.getAuthenticatedResource(getResource()
     976                .path("/registry/profiles/" + profileDesc.getId() + "/xsd"))
    905977                .accept(MediaType.TEXT_XML).get(ClientResponse.class);
    906978        assertEquals(200, cResponse.getStatus());
     
    908980        assertTrue(profile.length() > 0);
    909981
    910         profile = getAuthenticatedResource(
    911                 getResource().path(
     982        profile = getAuthenticatedResource(getResource().path(
    912983                        "/registry/profiles/" + profileDesc.getId() + "/xml"))
    913984                .accept(MediaType.TEXT_XML).get(String.class);
    914985        assertTrue(profile.length() > 0);
    915986
    916         cResponse = getAuthenticatedResource(
    917                 getResource().path("/registry/profiles/" + profileDesc.getId())
    918                         .queryParam(USERSPACE_PARAM, "true")).delete(
     987        cResponse = getAuthenticatedResource(getResource().path("/registry/profiles/" + profileDesc.getId())
     988                        .queryParam(REGISTRY_SPACE_PARAM, "private")).delete(
    919989                ClientResponse.class);
    920990        assertEquals(200, cResponse.getStatus());
    921991
    922992        profiles = getUserProfiles();
    923         assertEquals(0, profiles.size());
     993        assertEquals(1, profiles.size());
    924994    }
    925995
     
    9301000
    9311001    private List<ProfileDescription> getUserProfiles() {
    932         return getAuthenticatedResource(
    933                 getResource().path("/registry/profiles").queryParam(
    934                         USERSPACE_PARAM, "true")).accept(
     1002        return getAuthenticatedResource(getResource().path("/registry/profiles").queryParam(
     1003                        REGISTRY_SPACE_PARAM, "private")).accept(
    9351004                MediaType.APPLICATION_XML).get(PROFILE_LIST_GENERICTYPE);
    9361005    }
     
    9541023    @Test
    9551024    public void testRegisterWithUserComponents() throws Exception {
    956         ComponentRegistry userRegistry = componentRegistryFactory
    957                 .getComponentRegistry(ComponentStatus.PRIVATE, null,
    958                         DummyPrincipal.DUMMY_CREDENTIALS);
     1025        fillUpPrivateItems();
     1026       
     1027        // kid component, not public
    9591028        String content = "";
    9601029        content += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
     
    9661035        content += "</CMD_ComponentSpec>\n";
    9671036        ComponentDescription compDesc1 = RegistryTestHelper.addComponent(
    968                 userRegistry, "XXX1", content);
    969 
     1037                baseRegistry, "XXX1", content, false);
     1038
     1039        // a containing component, referring to the kid (which is not public, so the containing component cannot be registered
    9701040        content = "";
    9711041        content += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
     
    9821052                "/registry/components").type(MediaType.MULTIPART_FORM_DATA)
    9831053                .post(RegisterResponse.class, form);
    984         assertFalse(response.isRegistered());
    985         assertEquals(1, response.getErrors().size());
    986         assertEquals(
    987                 "referenced component cannot be found in the published components: "
    988                         + compDesc1.getName() + " (" + compDesc1.getId() + ")",
    989                 response.getErrors().get(0));
    990 
    991         response = getAuthenticatedResource(
    992                 getResource().path("/registry/components").queryParam(
    993                         USERSPACE_PARAM, "true")).type(
    994                 MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class,
    995                 form);
     1054        // we first alway register in a private space, so reference to a private component should work
    9961055        assertTrue(response.isRegistered());
    997         ComponentDescription comp2 = (ComponentDescription) response
    998                 .getDescription();
    999 
     1056
     1057
     1058        /// profiles ///
    10001059        content = "";
    10011060        content += "<CMD_ComponentSpec isProfile=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
     
    10031062        content += "    <Header/>\n";
    10041063        content += "    <CMD_Component name=\"ZZZ\" CardinalityMin=\"1\" CardinalityMax=\"unbounded\">\n";
    1005         content += "        <CMD_Component ComponentId=\"" + comp2.getId()
     1064        content += "        <CMD_Component ComponentId=\"" + compDesc1.getId()
    10061065                + "\" CardinalityMin=\"0\" CardinalityMax=\"99\">\n";
    10071066        content += "        </CMD_Component>\n";
     
    10131072                MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class,
    10141073                form);
    1015         assertFalse(response.isRegistered());
    1016         assertEquals(1, response.getErrors().size());
    1017         assertEquals(
    1018                 "referenced component cannot be found in the published components: "
    1019                         + comp2.getName() + " (" + comp2.getId() + ")",
    1020                 response.getErrors().get(0));
    1021 
    1022         response = getAuthenticatedResource(
    1023                 getResource().path("/registry/profiles").queryParam(
    1024                         USERSPACE_PARAM, "true")).type(
    1025                 MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class,
    1026                 form);
    10271074        assertTrue(response.isRegistered());
     1075
    10281076    }
    10291077
    10301078    @Test
    10311079    public void testRegisterUserspaceComponent() throws Exception {
     1080       
     1081        fillUpPrivateItems();
     1082       
    10321083        List<ComponentDescription> components = getUserComponents();
    1033         assertEquals("user registered components", 0, components.size());
     1084        assertEquals("user registered components", 1, components.size());
    10341085        assertEquals("public registered components", 0, getPublicComponents()
    10351086                .size());
     
    10371088                .getComponentTestContent());
    10381089
    1039         RegisterResponse response = getAuthenticatedResource(
    1040                 getResource().path("/registry/components").queryParam(
    1041                         USERSPACE_PARAM, "true")).type(
     1090        RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/components")).type(
    10421091                MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class,
    10431092                form);
     
    10571106        assertNotNull(desc.getRegistrationDate());
    10581107        String url = getResource().getUriBuilder().build().toString();
    1059         assertEquals(url + "registry/components/" + desc.getId()
    1060                 + "?userspace=true", desc.getHref());
     1108        assertEquals(url + "registry/components/" + desc.getId(), desc.getHref());
    10611109
    10621110        components = getUserComponents();
    1063         assertEquals(1, components.size());
     1111        assertEquals(2, components.size());
    10641112        assertEquals(0, getPublicComponents().size());
    10651113
    10661114        // Try to post unauthenticated
    10671115        ClientResponse cResponse = getResource().path("/registry/components")
    1068                 .queryParam(USERSPACE_PARAM, "true")
    10691116                .type(MediaType.MULTIPART_FORM_DATA)
    10701117                .post(ClientResponse.class, form);
    10711118        assertEquals(401, cResponse.getStatus());
    10721119
    1073         // Try to get from public registry
    1074         cResponse = getResource().path("/registry/components/" + desc.getId())
     1120        // Try to get
     1121        cResponse = this.getAuthenticatedResource(getResource().path("/registry/components/" + desc.getId()))
    10751122                .accept(MediaType.APPLICATION_XML).get(ClientResponse.class);
    1076         // Should return 404 = not found
    1077         assertEquals(404, cResponse.getStatus());
     1123       
     1124        assertEquals(200, cResponse.getStatus());
    10781125        CMDComponentSpec spec = getUserComponent(desc);
    10791126        assertNotNull(spec);
    10801127
    1081         cResponse = getResource()
    1082                 .path("/registry/components/" + desc.getId() + "/xsd")
     1128        cResponse = this.getAuthenticatedResource(getResource()
     1129                .path("/registry/components/" + desc.getId() + "/xsd"))
    10831130                .accept(MediaType.TEXT_XML).get(ClientResponse.class);
    10841131        assertEquals(200, cResponse.getStatus());
     
    10861133        assertTrue(result.length() > 0);
    10871134
    1088         result = getAuthenticatedResource(
    1089                 getResource().path(
     1135        result = getAuthenticatedResource(getResource().path(
    10901136                        "/registry/components/" + desc.getId() + "/xml"))
    10911137                .accept(MediaType.TEXT_XML).get(String.class);
    10921138        assertTrue(result.length() > 0);
    10931139
    1094         cResponse = getAuthenticatedResource(
    1095                 getResource().path("/registry/components/" + desc.getId())
    1096                         .queryParam(USERSPACE_PARAM, "true")).delete(
     1140        cResponse = getAuthenticatedResource(getResource().path("/registry/components/" + desc.getId())).delete(
    10971141                ClientResponse.class);
    10981142        assertEquals(200, cResponse.getStatus());
    10991143
    11001144        components = getUserComponents();
    1101         assertEquals(0, components.size());
    1102     }
    1103 
    1104     @Test
    1105     public void testCreateComponentWithRecursion() throws Exception {
     1145        assertEquals(1, components.size());
     1146    }
     1147//
     1148    @Test
     1149    public void testCreatePrivateComponentWithRecursion() throws Exception {
     1150       
     1151        fillUpPrivateItems();
    11061152        // Create new componet
    11071153        FormDataMultiPart form = createFormData(RegistryTestHelper
    11081154                .getComponentTestContent());
    1109         ClientResponse cResponse = getAuthenticatedResource(
    1110                 getResource().path("/registry/components").queryParam(
    1111                         USERSPACE_PARAM, "true")).type(
     1155        ClientResponse cResponse = getAuthenticatedResource(getResource().path("/registry/components")).type(
    11121156                MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form);
    11131157        assertEquals(ClientResponse.Status.OK.getStatusCode(),
     
    11401184                RegistryTestHelper.getComponentContentAsStream(compContent),
    11411185                "UPDATE DESCRIPTION!");
    1142         cResponse = getAuthenticatedResource(
    1143                 getResource().path(
    1144                         "/registry/components/" + desc.getId() + "/update")
    1145                         .queryParam(USERSPACE_PARAM, "true")).type(
     1186        cResponse = getAuthenticatedResource(getResource().path(
     1187                        "/registry/components/" + desc.getId() + "/update")).type(
    11461188                MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form);
    11471189        assertEquals(ClientResponse.Status.OK.getStatusCode(),
     
    11591201
    11601202    @Test
    1161     public void testUpdateComponent() throws Exception {
     1203    public void testUpdatePrivateComponent() throws Exception {
     1204       
     1205        fillUpPrivateItems();
     1206       
    11621207        List<ComponentDescription> components = getUserComponents();
    1163         assertEquals("user registered components", 0, components.size());
     1208        assertEquals("user registered components", 1, components.size());
    11641209        assertEquals("public registered components", 0, getPublicComponents()
    11651210                .size());
    1166 
     1211       
     1212        // first, post a component to update
    11671213        FormDataMultiPart form = createFormData(RegistryTestHelper
    11681214                .getComponentTestContent());
    1169         ClientResponse cResponse = getAuthenticatedResource(
    1170                 getResource().path("/registry/components").queryParam(
    1171                         USERSPACE_PARAM, "true")).type(
     1215        ClientResponse cResponse = getAuthenticatedResource(getResource().path("/registry/components")).type(
    11721216                MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form);
    11731217        assertEquals(ClientResponse.Status.OK.getStatusCode(),
     
    11871231        assertEquals("Access", spec.getCMDComponent().getName());
    11881232        components = getUserComponents();
    1189         assertEquals(1, components.size());
     1233        assertEquals(2, components.size());
    11901234        assertEquals(0, getPublicComponents().size());
    11911235
    1192         // Now update
     1236        // second, now update
    11931237        form = createFormData(
    11941238                RegistryTestHelper.getComponentTestContentAsStream("TESTNAME"),
    11951239                "UPDATE DESCRIPTION!");
    1196         cResponse = getAuthenticatedResource(
    1197                 getResource().path(
     1240        cResponse = getAuthenticatedResource(getResource().path(
    11981241                        "/registry/components/" + desc.getId() + "/update")
    1199                         .queryParam(USERSPACE_PARAM, "true")).type(
     1242                        .queryParam(REGISTRY_SPACE_PARAM, "private")).type(
    12001243                MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form);
    12011244        assertEquals(ClientResponse.Status.OK.getStatusCode(),
     
    12161259        assertEquals("TESTNAME", spec.getCMDComponent().getName());
    12171260        components = getUserComponents();
    1218         assertEquals(1, components.size());
     1261        assertEquals(2, components.size());
    12191262        assertEquals(0, getPublicComponents().size());
    12201263    }
    12211264
    12221265    @Test
    1223     public void testUpdateProfile() throws Exception {
     1266    public void testUpdatePrivateProfile() throws Exception {
     1267       
     1268        fillUpPrivateItems();
     1269       
    12241270        List<ProfileDescription> profiles = getUserProfiles();
    1225         assertEquals(0, profiles.size());
     1271        assertEquals(1, profiles.size());
    12261272        assertEquals(0, getPublicProfiles().size());
    12271273
    12281274        FormDataMultiPart form = createFormData(RegistryTestHelper
    12291275                .getTestProfileContent());
    1230         ClientResponse cResponse = getAuthenticatedResource(
    1231                 getResource().path("/registry/profiles").queryParam(
    1232                         USERSPACE_PARAM, "true")).type(
     1276        ClientResponse cResponse = getAuthenticatedResource(getResource().path("/registry/profiles")).type(
    12331277                MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form);
    12341278        assertEquals(ClientResponse.Status.OK.getStatusCode(),
     
    12491293        assertEquals("Actor", spec.getCMDComponent().getName());
    12501294        profiles = getUserProfiles();
    1251         assertEquals(1, profiles.size());
     1295        assertEquals(2, profiles.size());
    12521296        assertEquals(0, getPublicComponents().size());
    12531297
     
    12561300                RegistryTestHelper.getTestProfileContent("TESTNAME"),
    12571301                "UPDATE DESCRIPTION!");
    1258         cResponse = getAuthenticatedResource(
    1259                 getResource().path(
    1260                         "/registry/profiles/" + desc.getId() + "/update")
    1261                         .queryParam(USERSPACE_PARAM, "true")).type(
     1302        cResponse = getAuthenticatedResource(getResource().path(
     1303                        "/registry/profiles/" + desc.getId() + "/update")).type(
    12621304                MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form);
    12631305        assertEquals(ClientResponse.Status.OK.getStatusCode(),
     
    12781320        assertEquals("TESTNAME", spec.getCMDComponent().getName());
    12791321        profiles = getUserProfiles();
    1280         assertEquals(1, profiles.size());
     1322        assertEquals(2, profiles.size());
    12811323        assertEquals(0, getPublicComponents().size());
    12821324    }
    12831325
    12841326    private CMDComponentSpec getUserComponent(ComponentDescription desc) {
    1285         return getAuthenticatedResource(
    1286                 getResource().path("/registry/components/" + desc.getId())
    1287                         .queryParam(USERSPACE_PARAM, "true")).accept(
     1327        return getAuthenticatedResource(getResource().path("/registry/components/" + desc.getId())
     1328                        .queryParam(REGISTRY_SPACE_PARAM, "private")).accept(
    12881329                MediaType.APPLICATION_XML).get(CMDComponentSpec.class);
    12891330    }
    12901331
    12911332    private CMDComponentSpec getUserProfile(ProfileDescription desc) {
    1292         return getAuthenticatedResource(
    1293                 getResource().path("/registry/profiles/" + desc.getId())
    1294                         .queryParam(USERSPACE_PARAM, "true")).accept(
     1333        return getAuthenticatedResource(getResource().path("/registry/profiles/" + desc.getId())
     1334                        .queryParam(REGISTRY_SPACE_PARAM, "private")).accept(
    12951335                MediaType.APPLICATION_XML).get(CMDComponentSpec.class);
    12961336    }
     
    13021342
    13031343    private List<ComponentDescription> getUserComponents() {
    1304         return getAuthenticatedResource(
    1305                 getResource().path("/registry/components").queryParam(
    1306                         USERSPACE_PARAM, "true")).accept(
     1344        return getAuthenticatedResource(getResource().path("/registry/components").queryParam(
     1345                        REGISTRY_SPACE_PARAM, "private")).accept(
    13071346                MediaType.APPLICATION_XML).get(COMPONENT_LIST_GENERICTYPE);
    13081347    }
     
    13101349    @Test
    13111350    public void testRegisterComponent() throws Exception {
     1351       
     1352        fillUpPrivateItems();
     1353       
    13121354        FormDataMultiPart form = new FormDataMultiPart();
    13131355        form.field(IComponentRegistryRestService.DATA_FORM_FIELD,
     
    13261368        assertTrue(response.isRegistered());
    13271369        assertFalse(response.isProfile());
    1328         assertFalse(response.isInUserSpace());
     1370        assertTrue(response.isInUserSpace());
    13291371        ComponentDescription desc = (ComponentDescription) response
    13301372                .getDescription();
     
    13461388    @Test
    13471389    public void testRegisterComment() throws Exception {
     1390       
     1391        fillUpPublicItems();
     1392       
    13481393        FormDataMultiPart form = new FormDataMultiPart();
    13491394        form.field(IComponentRegistryRestService.DATA_FORM_FIELD,
    13501395                RegistryTestHelper.getCommentTestContent(),
    13511396                MediaType.APPLICATION_OCTET_STREAM_TYPE);
    1352         fillUp();
    13531397        String id = ProfileDescription.PROFILE_PREFIX + "profile1";
    13541398        CommentResponse response = getAuthenticatedResource(
     
    13711415    @Test
    13721416    public void testRegisterCommentToNonExistent() throws Exception {
     1417        fillUpPublicItems();
     1418       
    13731419        FormDataMultiPart form = new FormDataMultiPart();
    13741420        form.field(IComponentRegistryRestService.DATA_FORM_FIELD,
    13751421                RegistryTestHelper.getCommentTestContent(),
    13761422                MediaType.APPLICATION_OCTET_STREAM_TYPE);
    1377         fillUp();
    13781423        ClientResponse cResponse = getAuthenticatedResource(
    13791424                "/registry/profiles/clarin.eu:cr1:profile99/comments").type(
    13801425                MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form);
    1381         assertEquals(500, cResponse.getStatus());
     1426        assertEquals(404, cResponse.getStatus());
    13821427    }
    13831428
    13841429    @Test
    13851430    public void testRegisterCommentUnauthenticated() throws Exception {
     1431        fillUpPublicItems();
     1432       
    13861433        FormDataMultiPart form = new FormDataMultiPart();
    13871434        form.field(IComponentRegistryRestService.DATA_FORM_FIELD,
    13881435                RegistryTestHelper.getCommentTestContent(),
    13891436                MediaType.APPLICATION_OCTET_STREAM_TYPE);
    1390         fillUp();
    13911437        ClientResponse cResponse = getResource()
    13921438                .path("/registry/profiles/clarin.eu:cr1:profile1/comments")
     
    13981444    @Test
    13991445    public void testRegisterProfileInvalidData() throws Exception {
     1446        fillUpPrivateItems();
    14001447        FormDataMultiPart form = new FormDataMultiPart();
    14011448        String notAValidProfile = "<CMD_ComponentSpec> </CMD_ComponentSpec>";
     
    14261473    @Test
    14271474    public void testRegisterInvalidProfile() throws Exception {
     1475        fillUpPrivateItems();
    14281476        FormDataMultiPart form = new FormDataMultiPart();
    14291477        String profileContent = "";
     
    14691517    public void testRegisterProfileInvalidDescriptionAndContent()
    14701518            throws Exception {
     1519        fillUpPrivateItems();
    14711520        FormDataMultiPart form = new FormDataMultiPart();
    14721521        String profileContent = "";
     
    14991548    @Test
    15001549    public void testRegisterLargeProfile() throws Exception {
     1550        //fillUpPrivateItems(); not necessary
    15011551        FormDataMultiPart form = new FormDataMultiPart();
    15021552        form.field(IComponentRegistryRestService.DATA_FORM_FIELD,
     
    15191569    @Test
    15201570    public void testRegisterComponentAsProfile() throws Exception {
     1571        //fillUpPrivateItems();; not necessary
    15211572        FormDataMultiPart form = new FormDataMultiPart();
    15221573        form.field(IComponentRegistryRestService.DATA_FORM_FIELD,
     
    16411692    @Test
    16421693    public void testGetDescription() throws Exception{
    1643         fillUp();
    1644         String id = ComponentDescription.COMPONENT_PREFIX + "component1";
     1694        fillUpPublicItems();
     1695        String id = ComponentDescription.COMPONENT_PREFIX + "component1";
    16451696        ComponentDescription component = getAuthenticatedResource(getResource().path("/registry/items/" + id)).accept(MediaType.APPLICATION_JSON).get(ComponentDescription.class);
    16461697        assertNotNull(component);
Note: See TracChangeset for help on using the changeset viewer.