source: ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/RestGroupServiceTest.java @ 5565

Last change on this file since 5565 was 5565, checked in by olhsha@mpi.nl, 10 years ago

Unit test for deleting profiles and components from groups.

File size: 52.4 KB
Line 
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5package clarin.cmdi.componentregistry.rest;
6
7import clarin.cmdi.componentregistry.ComponentRegistry;
8import clarin.cmdi.componentregistry.ComponentRegistryFactory;
9import clarin.cmdi.componentregistry.ItemNotFoundException;
10import clarin.cmdi.componentregistry.RegistrySpace;
11import clarin.cmdi.componentregistry.components.CMDComponentSpec;
12import clarin.cmdi.componentregistry.impl.database.ComponentRegistryTestDatabase;
13import clarin.cmdi.componentregistry.impl.database.GroupService;
14import clarin.cmdi.componentregistry.model.Comment;
15import clarin.cmdi.componentregistry.model.ComponentDescription;
16import clarin.cmdi.componentregistry.model.Group;
17import clarin.cmdi.componentregistry.model.Ownership;
18import clarin.cmdi.componentregistry.model.ProfileDescription;
19import clarin.cmdi.componentregistry.model.RegisterResponse;
20import clarin.cmdi.componentregistry.model.RegistryUser;
21import clarin.cmdi.componentregistry.persistence.jpa.CommentsDao;
22import clarin.cmdi.componentregistry.persistence.jpa.UserDao;
23import clarin.cmdi.componentregistry.rss.Rss;
24import com.sun.jersey.api.client.ClientResponse;
25import com.sun.jersey.multipart.FormDataMultiPart;
26import java.text.ParseException;
27import java.util.Date;
28import java.util.List;
29import javax.ws.rs.core.MediaType;
30import javax.xml.bind.JAXBException;
31import org.junit.Before;
32import org.springframework.beans.factory.annotation.Autowired;
33import org.springframework.jdbc.core.JdbcTemplate;
34
35import static org.junit.Assert.*;
36import org.junit.Test;
37
38/**
39 *
40 * @author olhsha
41 */
42public class RestGroupServiceTest extends ComponentRegistryRestServiceTestCase {
43   
44    @Autowired
45    private ComponentRegistryFactory componentRegistryFactory;
46   
47    @Autowired
48    private JdbcTemplate jdbcTemplate;
49    @Autowired 
50    private GroupService groupService;
51    @Autowired 
52    private UserDao userDao;
53    @Autowired 
54    private CommentsDao commentsDao;
55   
56    private ComponentRegistry baseRegistry;
57
58    @Before
59    public void init() {
60        ComponentRegistryTestDatabase.resetAndCreateAllTables(jdbcTemplate);
61        createUserRecord();
62        baseRegistry = componentRegistryFactory.getBaseRegistry(DummyPrincipal.DUMMY_CREDENTIALS);
63    }
64
65    private String expectedUserId(String principal) {
66        return getUserDao().getByPrincipalName(principal).getId().toString();
67    }
68    private ComponentDescription component1;
69    private ComponentDescription component2;
70    private ProfileDescription profile1;
71    private ProfileDescription profile2;
72    private ComponentDescription component3;
73    private ProfileDescription profile3;
74    private Comment profile1Comment1;
75    private Comment profile1Comment2;
76    private Comment component1Comment3;
77    private Comment component1Comment4;
78    private Comment profile3Comment5;
79    private Comment component3Comment7;
80
81    private void fillUpPublicItems() throws Exception {
82
83        profile1 = RegistryTestHelper.addProfile(baseRegistry, "profile2", true);
84        profile2 = RegistryTestHelper.addProfile(baseRegistry, "profile1", true);
85        component1 = RegistryTestHelper.addComponent(baseRegistry,
86                "component2", true);
87        component2 = RegistryTestHelper.addComponent(baseRegistry,
88                "component1", true);
89        profile1Comment2 = RegistryTestHelper.addComment(baseRegistry, "comment2",
90                ProfileDescription.PROFILE_PREFIX + "profile1",
91                "JUnit@test.com");
92        profile1Comment1 = RegistryTestHelper.addComment(baseRegistry, "comment1",
93                ProfileDescription.PROFILE_PREFIX + "profile1",
94                "JUnit@test.com");
95        component1Comment3 = RegistryTestHelper.addComment(baseRegistry, "comment3",
96                ComponentDescription.COMPONENT_PREFIX + "component1",
97                "JUnit@test.com");
98        component1Comment4 = RegistryTestHelper.addComment(baseRegistry, "comment4",
99                ComponentDescription.COMPONENT_PREFIX + "component1",
100                "JUnit@test.com");
101    }
102
103    private void fillUpPrivateItems() throws Exception {
104        profile3 = RegistryTestHelper.addProfile(baseRegistry, "profile3", false);
105        component3 = RegistryTestHelper.addComponent(baseRegistry,
106                "component3", false);
107        profile3Comment5 = RegistryTestHelper.addComment(baseRegistry, "comment5",
108                ProfileDescription.PROFILE_PREFIX + "profile3",
109                "JUnit@test.com");
110        component3Comment7 = RegistryTestHelper.addComment(baseRegistry, "comment7",
111                ComponentDescription.COMPONENT_PREFIX + "component3",
112                "JUnit@test.com");
113    }
114   
115     protected void createAntherUserRecord() {
116        RegistryUser user = new RegistryUser();
117        user.setName("Another database test user");
118        user.setPrincipalName("anotherPrincipal");
119        userDao.save(user);
120    }
121     
122    private void MakeGroupA(){
123        groupService.createNewGroup("group A", DummyPrincipal.DUMMY_PRINCIPAL.getName());
124    }
125   
126     private void fillUpGroupA() throws ParseException, JAXBException, ItemNotFoundException{
127         
128        MakeGroupA();
129       
130        RegistryTestHelper.addProfile(baseRegistry, "profile-1", false);
131        RegistryTestHelper.addComponent(baseRegistry, "component-1", false);
132        RegistryTestHelper.addComponent(baseRegistry, "component-2", false);
133       
134        Ownership ownership = new Ownership();
135        ownership.setComponentId(ProfileDescription.PROFILE_PREFIX+"profile-1");
136        ownership.setGroupId(1);
137        ownership.setUserId(0);
138        groupService.addOwnership(ownership);
139       
140        ownership.setComponentId(ComponentDescription.COMPONENT_PREFIX+"component-1");
141        ownership.setGroupId(1);
142        ownership.setUserId(0);
143        groupService.addOwnership(ownership);
144       
145        ownership.setComponentId(ComponentDescription.COMPONENT_PREFIX+"component-2");
146        ownership.setGroupId(1);
147        ownership.setUserId(0);
148        groupService.addOwnership(ownership);
149       
150    }
151     
152     
153   
154    private void MakeGroupB() throws ItemNotFoundException{
155        createAntherUserRecord();
156        groupService.createNewGroup("group B", "anotherPrincipal");
157        groupService.makeMember(DummyPrincipal.DUMMY_PRINCIPAL.getName(), "group B");
158    }
159   
160     private void MakeGroupC() throws ItemNotFoundException{
161        groupService.createNewGroup("group C", "anotherPrincipal");
162    }
163   
164     private void fillUpGroupB() throws ParseException, JAXBException, ItemNotFoundException{
165         
166        MakeGroupB();
167       
168        RegistryTestHelper.addProfile(baseRegistry, "Bprofile-1", false);
169        RegistryTestHelper.addComponent(baseRegistry, "Bcomponent-1", false);
170        RegistryTestHelper.addComponent(baseRegistry, "Bcomponent-2", false);
171       
172        Ownership ownership = new Ownership();
173        ownership.setComponentId(ProfileDescription.PROFILE_PREFIX+"Bprofile-1");
174        ownership.setGroupId(2);
175        ownership.setUserId(0);
176        groupService.addOwnership(ownership);
177       
178        ownership.setComponentId(ComponentDescription.COMPONENT_PREFIX+"Bcomponent-1");
179        ownership.setGroupId(2);
180        ownership.setUserId(0);
181        groupService.addOwnership(ownership);
182       
183        ownership.setComponentId(ComponentDescription.COMPONENT_PREFIX+"Bcomponent-2");
184        ownership.setGroupId(2);
185        ownership.setUserId(0);
186        groupService.addOwnership(ownership);
187       
188    }
189     
190     private void fillUpGroupC() throws ParseException, JAXBException, ItemNotFoundException{
191         
192        MakeGroupC();
193       
194        RegistryTestHelper.addProfileAnotherPrincipal(baseRegistry, "Cprofile-1", false);
195        RegistryTestHelper.addComponentAnotherPrincipal(baseRegistry, "Ccomponent-1", false);
196        RegistryTestHelper.addComponentAnotherPrincipal(baseRegistry, "Ccomponent-2", false);
197       
198        Ownership ownership = new Ownership();
199        ownership.setComponentId(ProfileDescription.PROFILE_PREFIX+"Cprofile-1");
200        ownership.setGroupId(3);
201        ownership.setUserId(0);
202        groupService.addOwnership(ownership);
203       
204        ownership.setComponentId(ComponentDescription.COMPONENT_PREFIX+"Ccomponent-1");
205        ownership.setGroupId(3);
206        ownership.setUserId(0);
207        groupService.addOwnership(ownership);
208       
209        ownership.setComponentId(ComponentDescription.COMPONENT_PREFIX+"Ccomponent-2");
210        ownership.setGroupId(3);
211        ownership.setUserId(0);
212        groupService.addOwnership(ownership);
213       
214    }
215   
216 //    Response createNewGroup(String groupName) throws IOException;
217   
218    @Test
219    public void testCreateNewGroup() {
220        System.out.println("test createNewGroup");
221        ClientResponse cr = this.getAuthenticatedResource(getResource()
222                .path("/registry/groups/create").queryParam("groupName", "newGroup"))
223                .accept(MediaType.TEXT_XML).post(ClientResponse.class);
224        assertEquals(200, cr.getStatus());
225        assertEquals("Group with the name newGroup is created and given an id 1", cr.getEntity(String.class));
226    }
227   
228   
229   
230   
231//  List<Group> getGroupsOwnedByUser(String pricipalName) throws IOException;
232   
233    @Test
234    public void testGetGroupsOwnedByUser() {
235        System.out.println("test GetGroupsOwnedByUser");
236        ClientResponse cr = this.getAuthenticatedResource(getResource()
237                .path("/registry/groups/create").queryParam("groupName", "newGroup1"))
238                .accept(MediaType.TEXT_XML).post(ClientResponse.class);
239        assertEquals(200, cr.getStatus());
240        ClientResponse cr1 = this.getAuthenticatedResource(getResource()
241                .path("/registry/groups/create").queryParam("groupName", "newGroup2"))
242                .accept(MediaType.TEXT_XML).post(ClientResponse.class);
243        assertEquals(200, cr1.getStatus());
244       
245        // test itself
246       
247       List<Group> result = this.getAuthenticatedResource(getResource()
248                .path("/registry/groups/principal").queryParam("principalName", DummyPrincipal.DUMMY_PRINCIPAL.getName()))
249                .accept(MediaType.APPLICATION_XML).get(GROUP_LIST_GENERICTYPE);
250       
251       assertEquals(2, result.size());
252       assertEquals("newGroup1", result.get(0).getName());
253       assertEquals("newGroup2", result.get(1).getName());
254    }
255   
256   
257//    List<Group> getGroupsTheCurrentUserIsAMemberOf();   
258   
259    @Test
260    public void testGetGroupsTheCurrentUserIsAMemberOf() throws ItemNotFoundException{
261        System.out.println("test getGroupsTheCurrentUserIsAMemberOfr");
262       
263        MakeGroupA();
264        MakeGroupB();
265        // test itself
266       
267       List<Group> result = this.getAuthenticatedResource(getResource()
268                .path("/registry/groups/usermembership"))
269                .accept(MediaType.APPLICATION_XML).get(GROUP_LIST_GENERICTYPE);
270       
271       assertEquals(1, result.size());
272       assertEquals("group B", result.get(0).getName());
273    }
274//   
275//    List<Group> getGroupsTheItemIsAMemberOf(String itemId);
276   
277    @Test
278    public void testGetGroupsTheItemIsAMemberOf() throws ParseException, JAXBException, ItemNotFoundException{
279        System.out.println("test getGroupsTheItemIsAMemberOf");
280       
281        fillUpGroupA();
282        fillUpGroupB();
283        // test itself
284       
285       List<Group> result = this.getAuthenticatedResource(getResource()
286                .path("/registry/items/"+ComponentDescription.COMPONENT_PREFIX+"component-1/groups"))
287                .accept(MediaType.APPLICATION_XML).get(GROUP_LIST_GENERICTYPE);
288       
289       assertEquals(1, result.size());
290       assertEquals("group A", result.get(0).getName());
291       
292       result = this.getAuthenticatedResource(getResource()
293                .path("/registry/items/"+ComponentDescription.COMPONENT_PREFIX+"Bcomponent-1/groups"))
294                .accept(MediaType.APPLICATION_XML).get(GROUP_LIST_GENERICTYPE);
295       
296       assertEquals(1, result.size());
297       assertEquals("group B", result.get(0).getName());
298       
299       result = this.getAuthenticatedResource(getResource()
300                .path("/registry/items/"+ProfileDescription.PROFILE_PREFIX+"Bprofile-1/groups"))
301                .accept(MediaType.APPLICATION_XML).get(GROUP_LIST_GENERICTYPE);
302       
303       assertEquals(1, result.size());
304       assertEquals("group B", result.get(0).getName());
305       
306       result = this.getAuthenticatedResource(getResource()
307                .path("/registry/items/"+ProfileDescription.PROFILE_PREFIX+"profile-1/groups"))
308                .accept(MediaType.APPLICATION_XML).get(GROUP_LIST_GENERICTYPE);
309       
310       assertEquals(1, result.size());
311       assertEquals("group A", result.get(0).getName());
312    }
313   
314
315
316 
317     
318    @Test
319    public void testListGroupNames() throws ItemNotFoundException{
320        System.out.println("test listGroupNames");
321       
322        MakeGroupA();
323        MakeGroupB();
324       
325        // test itself
326       
327       ClientResponse cr  = this.getAuthenticatedResource(getResource()
328                .path("/registry/groups/names")).accept(MediaType.APPLICATION_XML).get(ClientResponse.class);
329       assertEquals(200, cr.getStatus());
330       List<String> result = cr.getEntity(ComponentRegistryRestService.StringsWrapper.class).strings;
331       assertEquals(2, result.size());
332       assertEquals("group A", result.get(0));
333       assertEquals("group B", result.get(1));
334    }
335   
336//
337//    Response isOwner(String groupName) throws IOException;
338   
339    @Test
340    public void testIsOwner() throws ItemNotFoundException{
341        System.out.println("test isOwner");
342       
343        MakeGroupA();
344        MakeGroupB();
345       
346        // test itself
347       
348       ClientResponse cr  = this.getAuthenticatedResource(getResource()
349                .path("/registry/groups/ownership").queryParam("groupName", "group A")).accept(MediaType.APPLICATION_XML).get(ClientResponse.class);
350       assertEquals(200, cr.getStatus());
351       String result = cr.getEntity(String.class);
352       assertEquals("true", result);
353       
354       cr  = this.getAuthenticatedResource(getResource()
355                .path("/registry/groups/ownership").queryParam("groupName", "group B")).accept(MediaType.APPLICATION_XML).get(ClientResponse.class);
356       assertEquals(200, cr.getStatus());
357       result = cr.getEntity(String.class);
358       assertEquals("false", result);
359    }
360   
361   
362//
363//    Response makeGroupMember(String groupName, String principalName) throws IOException;
364   
365    @Test
366    public void testMakeGroupMember() throws ItemNotFoundException{
367        System.out.println("test makeGroupMember");
368       
369        MakeGroupA();
370        MakeGroupB();
371        // test itself
372       
373       //MultivaluedMap<String, String> params  = new  MultivaluedHashMap<String, String>();
374       ClientResponse cr  = this.getAuthenticatedResource(getResource()
375                .path("/registry/groups/makemember").queryParam("groupName", "group A").queryParam("principalName", "anotherPrincipal")).accept(MediaType.APPLICATION_XML).post(ClientResponse.class);
376       assertEquals(200, cr.getStatus());
377       
378       assertTrue(groupService.userGroupMember("anotherPrincipal", "1"));
379       
380               ;
381       cr  = this.getAuthenticatedResource(getResource()
382                .path("/registry/groups/makemember").queryParam("groupName", "group B").queryParam("principalName", "anotherPrincipal")).accept(MediaType.APPLICATION_XML).post(ClientResponse.class);
383       assertEquals(403, cr.getStatus());
384    }
385   
386//
387//   Response listProfiles(String groupId) throws IOException;
388   
389    @Test
390    public void testListProfilesAndComponents() throws Exception{
391        System.out.println("test listProfilesAndComponents");
392       
393        fillUpGroupA();
394       
395        // test itself
396       
397       ClientResponse cr  = this.getAuthenticatedResource(getResource()
398                .path("/registry/groups/profiles").queryParam("groupId", "1")).accept(MediaType.APPLICATION_XML).get(ClientResponse.class);
399       assertEquals(200, cr.getStatus());
400       List<String> result = cr.getEntity(ComponentRegistryRestService.StringsWrapper.class).strings;
401       assertEquals(1, result.size());
402       assertEquals(ProfileDescription.PROFILE_PREFIX+"profile-1", result.get(0));
403       
404       cr  = this.getAuthenticatedResource(getResource()
405                .path("/registry/groups/components").queryParam("groupId", "1")).accept(MediaType.APPLICATION_XML).get(ClientResponse.class);
406       assertEquals(200, cr.getStatus());
407       result = cr.getEntity(ComponentRegistryRestService.StringsWrapper.class).strings;
408       assertEquals(2, result.size());
409       assertEquals(ComponentDescription.COMPONENT_PREFIX+"component-1", result.get(0));
410       assertEquals(ComponentDescription.COMPONENT_PREFIX+"component-2", result.get(1));
411    }
412   
413
414 
415//
416//    Response getGroupNameById(String groupId) throws IOException;
417   
418    @Test
419    public void testGetGroupNamebyId() throws Exception{
420        System.out.println("test getGroupNamebyId");
421       
422        MakeGroupA();
423        MakeGroupB();
424        // test itself
425       
426       ClientResponse cr  = this.getAuthenticatedResource(getResource()
427                .path("/registry/groups/nameById").queryParam("groupId", "1")).accept(MediaType.APPLICATION_XML).get(ClientResponse.class);
428       assertEquals(200, cr.getStatus());
429       String result = cr.getEntity(String.class);
430       assertEquals("group A", result);
431       
432      cr  = this.getAuthenticatedResource(getResource()
433                .path("/registry/groups/nameById").queryParam("groupId", "2")).accept(MediaType.APPLICATION_XML).get(ClientResponse.class);
434       assertEquals(200, cr.getStatus());
435       result = cr.getEntity(String.class);
436       assertEquals("group B", result);
437    }
438   
439//
440//    Response getGroupIdByName(String groupName) throws IOException;
441   
442    @Test
443    public void testGetIdByGroupName() throws Exception{
444        System.out.println("test getIdByGroupName");
445       
446        MakeGroupA();
447        MakeGroupB();
448        // test itself
449       
450       ClientResponse cr  = this.getAuthenticatedResource(getResource()
451                .path("/registry/groups/idByName").queryParam("groupName", "group B")).accept(MediaType.APPLICATION_XML).get(ClientResponse.class);
452       assertEquals(200, cr.getStatus());
453       String result = cr.getEntity(String.class);
454       assertEquals("2", result);
455       
456      cr  = this.getAuthenticatedResource(getResource()
457                .path("/registry/groups/idByName").queryParam("groupName", "group A")).accept(MediaType.APPLICATION_XML).get(ClientResponse.class);
458       assertEquals(200, cr.getStatus());
459       result = cr.getEntity(String.class);
460       assertEquals("1", result);
461    }
462   
463     
464//    Response transferItemOwnershipToGroup(String itemId, long groupId) throws IOException;   
465//   
466
467    @Test
468    public void testTransferOwnership() throws Exception{
469        System.out.println("test makeTransferOwnership");
470       
471        fillUpGroupA();
472        fillUpGroupB();       
473        fillUpGroupC();
474        // test itself
475       
476       
477       RegistryTestHelper.addComponent(baseRegistry, "test_component", false);
478       RegistryTestHelper.addProfile(baseRegistry, "test_profile", false);
479       String test_profile_id = ProfileDescription.PROFILE_PREFIX+"test_profile";
480       String test_component_id = ComponentDescription.COMPONENT_PREFIX+"test_component";
481       //I'm not a member
482       ClientResponse cr  = this.getAuthenticatedResource(getResource()
483                .path("/registry/items/"+test_profile_id+"/transferownership").queryParam("groupId", "3")).accept(MediaType.APPLICATION_XML).post(ClientResponse.class);
484       assertEquals(403, cr.getStatus());
485       
486       //make me a member
487       groupService.makeMember(DummyPrincipal.DUMMY_PRINCIPAL.getName(), "group C");
488       assertTrue(groupService.userGroupMember(DummyPrincipal.DUMMY_PRINCIPAL.getName(), "3"));
489       
490       cr  = this.getAuthenticatedResource(getResource()
491                .path("/registry/items/"+test_profile_id+"/transferownership").queryParam("groupId", "3")).accept(MediaType.APPLICATION_XML).post(ClientResponse.class);
492       assertEquals(200, cr.getStatus());
493       cr  = this.getAuthenticatedResource(getResource()
494                .path("/registry/items/"+test_component_id+"/transferownership").queryParam("groupId", "3")).accept(MediaType.APPLICATION_XML).post(ClientResponse.class);
495       assertEquals(200, cr.getStatus());
496       
497       
498       List<String> components = groupService.getComponentIdsInGroup(3);
499       assertEquals(3, components.size());
500       assertEquals(test_component_id, components.get(2));
501       List<String> profiles = groupService.getProfileIdsInGroup(3);
502       assertEquals(2, profiles.size());
503       assertEquals(test_profile_id, profiles.get(1));
504       
505    }
506   
507    @Test
508    public void testGetGroupProfilesAndComponents() throws Exception {
509
510        System.out.println("test getGroupProfiles");
511
512        fillUpGroupA();
513        fillUpGroupB();       
514        fillUpGroupC();
515
516        // lists
517       
518        List<ProfileDescription> response = this.getAuthenticatedResource(getResource()
519                .path("/registry/profiles").queryParam("registrySpace", "group").queryParam("groupid", "1")).accept(MediaType.APPLICATION_XML)
520                .get(PROFILE_LIST_GENERICTYPE);
521        assertEquals(1, response.size());
522       
523        List<ComponentDescription> responseC = this.getAuthenticatedResource(getResource()
524                .path("/registry/components").queryParam("registrySpace", "group").queryParam("groupid", "1")).accept(MediaType.APPLICATION_XML)
525                .get(COMPONENT_LIST_GENERICTYPE);
526        assertEquals(2, responseC.size());
527       
528        response = this.getAuthenticatedResource(getResource()
529                .path("/registry/profiles").queryParam("registrySpace", "group").queryParam("groupid", "2")).accept(MediaType.APPLICATION_XML)
530                .get(PROFILE_LIST_GENERICTYPE);
531        assertEquals(1, response.size());
532       
533        responseC = this.getAuthenticatedResource(getResource()
534                .path("/registry/components").queryParam("registrySpace", "group").queryParam("groupid", "2")).accept(MediaType.APPLICATION_XML)
535                .get(COMPONENT_LIST_GENERICTYPE);
536        assertEquals(2, responseC.size());
537       
538        ClientResponse clientResponse = this.getAuthenticatedResource(getResource()
539                .path("/registry/components").queryParam("registrySpace", "group").queryParam("groupid", "3")).accept(MediaType.APPLICATION_XML)
540                .get(ClientResponse.class);
541       
542        assertEquals(403, clientResponse.getStatus());
543       
544        // particular components and profiles
545       
546        CMDComponentSpec component = this.getAuthenticatedResource(getResource()
547                .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX+"profile-1"))
548                .accept(MediaType.APPLICATION_JSON).get(CMDComponentSpec.class);
549        assertNotNull(component);
550        assertEquals("Actor", component.getCMDComponent().getName());
551   
552        component = this.getAuthenticatedResource(getResource()
553                .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX+"component-1"))
554                .accept(MediaType.APPLICATION_JSON).get(CMDComponentSpec.class);
555        assertNotNull(component);
556        assertEquals("Access", component.getCMDComponent().getName());
557   
558        component = this.getAuthenticatedResource(getResource()
559                .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX+"Bprofile-1"))
560                .accept(MediaType.APPLICATION_JSON).get(CMDComponentSpec.class);
561        assertNotNull(component);
562        assertEquals("Actor", component.getCMDComponent().getName());
563   
564        component = this.getAuthenticatedResource(getResource()
565                .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX+"Bcomponent-1"))
566                .accept(MediaType.APPLICATION_JSON).get(CMDComponentSpec.class);
567        assertNotNull(component);
568        assertEquals("Access", component.getCMDComponent().getName());
569   
570        clientResponse = this.getAuthenticatedResource(getResource()
571                .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX+"Cprofile-1"))
572                .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
573        assertEquals(403, clientResponse.getStatus());
574       
575         clientResponse = this.getAuthenticatedResource(getResource()
576                .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX+"Ccomponent-1"))
577                .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
578        assertEquals(403, clientResponse.getStatus());
579       
580    }
581   
582   @Test
583    public void testGetGroupComments() throws Exception {
584
585        System.out.println("test getGroupComments");
586
587        fillUpGroupA();
588        fillUpGroupB();       
589        fillUpGroupC();
590
591       
592        RegistryTestHelper.addComment(baseRegistry, "COMMENTc1",  ComponentDescription.COMPONENT_PREFIX + "component-1",
593                "JUnit@test.com");
594        RegistryTestHelper.addComment(baseRegistry, "COMMENTp1",  ProfileDescription.PROFILE_PREFIX + "profile-1",
595                "JUnit@test.com");
596        RegistryTestHelper.addComment(baseRegistry, "COMMENTBc1",  ComponentDescription.COMPONENT_PREFIX + "Bcomponent-1",
597                "anotherPrincipal");
598        RegistryTestHelper.addComment(baseRegistry, "COMMENTBp1",  ProfileDescription.PROFILE_PREFIX + "Bprofile-1",
599                "anotherPrincipal");
600       (new RegistryTestHelper()).addCommentBypassAuthorisation(commentsDao, "COMMENTCc1",  ComponentDescription.COMPONENT_PREFIX + "Ccomponent-1",
601                "anotherPrincipal");
602       (new RegistryTestHelper()).addCommentBypassAuthorisation(commentsDao, "COMMENTCp1",  ProfileDescription.PROFILE_PREFIX + "Cprofile-1","anotherPrincipal");
603         
604         
605                // lists
606       
607        List<Comment> response = this.getAuthenticatedResource(getResource()
608                .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX + "component-1" + "/comments/"))
609                .accept(MediaType.APPLICATION_XML)
610                .get(COMMENT_LIST_GENERICTYPE);       
611        assertEquals(1, response.size());
612       
613        response = this.getAuthenticatedResource(getResource()
614                .path("/registry/components/" + ProfileDescription.PROFILE_PREFIX + "profile-1" + "/comments/"))
615                .accept(MediaType.APPLICATION_XML)
616                .get(COMMENT_LIST_GENERICTYPE);       
617        assertEquals(1, response.size());
618       
619        response = this.getAuthenticatedResource(getResource()
620                .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX + "Bcomponent-1" + "/comments/"))
621                .accept(MediaType.APPLICATION_XML)
622                .get(COMMENT_LIST_GENERICTYPE);       
623        assertEquals(1, response.size());
624       
625        response = this.getAuthenticatedResource(getResource()
626                .path("/registry/components/" + ProfileDescription.PROFILE_PREFIX + "Bprofile-1" + "/comments/"))
627                .accept(MediaType.APPLICATION_XML)
628                .get(COMMENT_LIST_GENERICTYPE);       
629        assertEquals(1, response.size());
630       
631       
632   
633        ClientResponse clientResponse = this.getAuthenticatedResource(getResource()
634                .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX+"Cprofile-1/comments"))
635                .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
636        assertEquals(403, clientResponse.getStatus());
637       
638         clientResponse = this.getAuthenticatedResource(getResource()
639                .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX+"Ccomponent-1/comments"))
640                .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
641        assertEquals(403, clientResponse.getStatus());
642       
643        // particular comments
644       
645       Comment responseComment = this.getAuthenticatedResource(getResource()
646                .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX + "component-1" + "/comments/1"))
647                .accept(MediaType.APPLICATION_XML)
648                .get(Comment.class);       
649        assertNotNull(responseComment);
650     
651        assertEquals(1, Long.parseLong(responseComment.getId()));
652       
653        responseComment = this.getAuthenticatedResource(getResource()
654                .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX + "profile-1" + "/comments/2"))
655                .accept(MediaType.APPLICATION_XML)
656                .get(Comment.class);       
657        assertNotNull(responseComment);
658       
659        assertEquals(2, Long.parseLong(responseComment.getId()));
660       
661       responseComment = this.getAuthenticatedResource(getResource()
662                .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX + "Bcomponent-1" + "/comments/3"))
663                .accept(MediaType.APPLICATION_XML)
664                .get(Comment.class);       
665        assertNotNull(responseComment);
666        assertEquals(3, Long.parseLong(responseComment.getId()));
667       
668        responseComment = this.getAuthenticatedResource(getResource()
669                .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX + "Bprofile-1" + "/comments/4"))
670                .accept(MediaType.APPLICATION_XML)
671                .get(Comment.class);       
672        assertNotNull(responseComment);
673        assertEquals(4, Long.parseLong(responseComment.getId()));
674       
675        clientResponse = this.getAuthenticatedResource(getResource()
676                .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX+"Cprofile-1/comments/6"))
677                .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
678        assertEquals(403, clientResponse.getStatus());
679       
680         clientResponse = this.getAuthenticatedResource(getResource()
681                .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX+"Ccomponent-1/comments/5"))
682                .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
683        assertEquals(403, clientResponse.getStatus());
684       
685    }
686   
687    @Test
688    public void testGetGroupRss() throws Exception {
689
690        System.out.println("test getGroupRss");
691
692        fillUpGroupA();
693        fillUpGroupB();       
694        fillUpGroupC();
695
696       
697         // lists of profiles and components
698       
699        Rss response = this.getAuthenticatedResource(getResource()
700                .path("/registry/profiles/rss").queryParam("registrySpace", "group").queryParam("groupid", "1")).accept(MediaType.APPLICATION_XML)
701                .get(Rss.class);
702        assertEquals(1, response.getChannel().getItem().size());
703       
704         response = this.getAuthenticatedResource(getResource()
705                .path("/registry/components/rss").queryParam("registrySpace", "group").queryParam("groupid", "1")).accept(MediaType.APPLICATION_XML)
706                .get(Rss.class);
707        assertEquals(2, response.getChannel().getItem().size());
708       
709        response = this.getAuthenticatedResource(getResource()
710                .path("/registry/profiles/rss").queryParam("registrySpace", "group").queryParam("groupid", "2")).accept(MediaType.APPLICATION_XML)
711                .get(Rss.class);
712        assertEquals(1, response.getChannel().getItem().size());
713       
714        response = this.getAuthenticatedResource(getResource()
715                .path("/registry/components/rss").queryParam("registrySpace", "group").queryParam("groupid", "2")).accept(MediaType.APPLICATION_XML)
716                .get(Rss.class);
717        assertEquals(2, response.getChannel().getItem().size());
718       
719        ClientResponse clientResponse = this.getAuthenticatedResource(getResource()
720                .path("/registry/components").queryParam("registrySpace", "group").queryParam("groupid", "3")).accept(MediaType.APPLICATION_XML)
721                .get(ClientResponse.class);
722       
723        assertEquals(403, clientResponse.getStatus());
724       
725        RegistryTestHelper.addComment(baseRegistry, "COMMENTc1",  ComponentDescription.COMPONENT_PREFIX + "component-1",
726                "JUnit@test.com");
727        RegistryTestHelper.addComment(baseRegistry, "COMMENTp1",  ProfileDescription.PROFILE_PREFIX + "profile-1",
728                "JUnit@test.com");
729        RegistryTestHelper.addComment(baseRegistry, "COMMENTBc1",  ComponentDescription.COMPONENT_PREFIX + "Bcomponent-1",
730                "anotherPrincipal");
731        RegistryTestHelper.addComment(baseRegistry, "COMMENTBp1",  ProfileDescription.PROFILE_PREFIX + "Bprofile-1",
732                "anotherPrincipal");
733       (new RegistryTestHelper()).addCommentBypassAuthorisation(commentsDao, "COMMENTCc1",  ComponentDescription.COMPONENT_PREFIX + "Ccomponent-1",
734                "anotherPrincipal");
735       (new RegistryTestHelper()).addCommentBypassAuthorisation(commentsDao, "COMMENTCp1",  ProfileDescription.PROFILE_PREFIX + "Cprofile-1","anotherPrincipal");
736         
737         
738                // lists
739       
740        response = this.getAuthenticatedResource(getResource()
741                .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX + "component-1" + "/comments/rss"))
742                .accept(MediaType.APPLICATION_XML)
743                .get(Rss.class);       
744        assertEquals(1, response.getChannel().getItem().size());
745       
746        response = this.getAuthenticatedResource(getResource()
747                .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX + "profile-1" + "/comments/rss"))
748                .accept(MediaType.APPLICATION_XML)
749                .get(Rss.class);       
750        assertEquals(1, response.getChannel().getItem().size());
751       
752        response = this.getAuthenticatedResource(getResource()
753                .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX + "Bcomponent-1" + "/comments/rss"))
754                .accept(MediaType.APPLICATION_XML)
755                .get(Rss.class);       
756        assertEquals(1, response.getChannel().getItem().size());
757       
758        response = this.getAuthenticatedResource(getResource()
759                .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX + "Bprofile-1" + "/comments/rss"))
760                .accept(MediaType.APPLICATION_XML)
761                .get(Rss.class);       
762        assertEquals(1, response.getChannel().getItem().size());
763       
764       
765   
766        clientResponse = this.getAuthenticatedResource(getResource()
767                .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX+"Cprofile-1/comments/rss"))
768                .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
769        assertEquals(403, clientResponse.getStatus());
770       
771         clientResponse = this.getAuthenticatedResource(getResource()
772                .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX+"Ccomponent-1/comments/rss"))
773                .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
774        assertEquals(403, clientResponse.getStatus());
775       
776        // particular comments
777       
778       Comment responseComment = this.getAuthenticatedResource(getResource()
779                .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX + "component-1" + "/comments/1"))
780                .accept(MediaType.APPLICATION_XML)
781                .get(Comment.class);       
782        assertNotNull(responseComment);
783     
784        assertEquals(1, Long.parseLong(responseComment.getId()));
785       
786        responseComment = this.getAuthenticatedResource(getResource()
787                .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX + "profile-1" + "/comments/2"))
788                .accept(MediaType.APPLICATION_XML)
789                .get(Comment.class);       
790        assertNotNull(responseComment);
791       
792        assertEquals(2, Long.parseLong(responseComment.getId()));
793       
794       responseComment = this.getAuthenticatedResource(getResource()
795                .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX + "Bcomponent-1" + "/comments/3"))
796                .accept(MediaType.APPLICATION_XML)
797                .get(Comment.class);       
798        assertNotNull(responseComment);
799        assertEquals(3, Long.parseLong(responseComment.getId()));
800       
801        responseComment = this.getAuthenticatedResource(getResource()
802                .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX + "Bprofile-1" + "/comments/4"))
803                .accept(MediaType.APPLICATION_XML)
804                .get(Comment.class);       
805        assertNotNull(responseComment);
806        assertEquals(4, Long.parseLong(responseComment.getId()));
807       
808        clientResponse = this.getAuthenticatedResource(getResource()
809                .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX+"Cprofile-1/comments/6"))
810                .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
811        assertEquals(403, clientResponse.getStatus());
812       
813         clientResponse = this.getAuthenticatedResource(getResource()
814                .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX+"Ccomponent-1/comments/5"))
815                .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
816        assertEquals(403, clientResponse.getStatus());
817       
818    }
819   
820   
821    private FormDataMultiPart createFormData(Object content) {
822        return createFormData(content, "My Test");
823    }
824
825    private FormDataMultiPart createFormData(Object content, String description) {
826        FormDataMultiPart form = new FormDataMultiPart();
827        form.field(IComponentRegistryRestService.DATA_FORM_FIELD, content,
828                MediaType.APPLICATION_OCTET_STREAM_TYPE);
829        form.field(IComponentRegistryRestService.NAME_FORM_FIELD, "Test1");
830        form.field(IComponentRegistryRestService.DESCRIPTION_FORM_FIELD,
831                description);
832        form.field(IComponentRegistryRestService.DOMAIN_FORM_FIELD, "My domain");
833        form.field(IComponentRegistryRestService.GROUP_FORM_FIELD, "TestGroup");
834        return form;
835    }
836   
837   
838    @Test
839    public void testUpdateGroupComponentAndProfile() throws Exception {
840
841        System.out.println("test updateGorupComponent");
842
843        fillUpGroupA();
844        fillUpGroupB();       
845        fillUpGroupC();
846
847     
848       
849        FormDataMultiPart form = createFormData(
850                RegistryTestHelper.getComponentTestContentAsStream("TESTNAME"),
851                "UPDATE DESCRIPTION!");
852        ClientResponse cResponse = getAuthenticatedResource(getResource().path(
853                "/registry/components/" + ComponentDescription.COMPONENT_PREFIX+"component-1" + "/update")).type(
854                MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form);
855        assertEquals(ClientResponse.Status.OK.getStatusCode(),
856                cResponse.getStatus());
857        RegisterResponse response = cResponse.getEntity(RegisterResponse.class);
858        assertTrue(response.isRegistered());
859        assertFalse(response.isProfile());
860        assertTrue(response.isInUserSpace());
861        ComponentDescription desc = (ComponentDescription) response.getDescription();
862        assertNotNull(desc);
863        assertEquals("Test1", desc.getName());
864        assertEquals("UPDATE DESCRIPTION!", desc.getDescription());
865       
866        form = createFormData(
867                RegistryTestHelper.getComponentTestContentAsStream("TESTNAME"),
868                "UPDATE DESCRIPTION!");
869        cResponse = getAuthenticatedResource(getResource().path(
870                "/registry/components/" + ComponentDescription.COMPONENT_PREFIX+"Bcomponent-1" + "/update")).type(
871                MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form);
872        assertEquals(ClientResponse.Status.OK.getStatusCode(),
873                cResponse.getStatus());
874        response = cResponse.getEntity(RegisterResponse.class);
875        assertTrue(response.isRegistered());
876        assertFalse(response.isProfile());
877        assertTrue(response.isInUserSpace());
878        desc = (ComponentDescription) response.getDescription();
879        assertNotNull(desc);
880        assertEquals("Test1", desc.getName());
881        assertEquals("UPDATE DESCRIPTION!", desc.getDescription());
882       
883        form = createFormData(
884                RegistryTestHelper.getComponentTestContentAsStream("TESTNAME"),
885                "UPDATE DESCRIPTION!");
886        cResponse = getAuthenticatedResource(getResource().path(
887                "/registry/components/" + ComponentDescription.COMPONENT_PREFIX+"Ccomponent-1" + "/update")).type(
888                MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form);
889        assertEquals(403, cResponse.getStatus());
890       
891        // profile
892       
893        form = createFormData(RegistryTestHelper.getTestProfileContent("TESTNAME"),
894                "UPDATE DESCRIPTION!");
895        cResponse = getAuthenticatedResource(getResource().path(
896                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX+"profile-1" + "/update")).type(
897                MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form);
898        assertEquals(ClientResponse.Status.OK.getStatusCode(),
899                cResponse.getStatus());
900        response = cResponse.getEntity(RegisterResponse.class);
901        assertTrue(response.isRegistered());
902        assertTrue(response.isProfile());
903        assertTrue(response.isInUserSpace());
904        ProfileDescription pdesc = (ProfileDescription) response.getDescription();
905        assertNotNull(pdesc);
906        assertEquals("Test1", pdesc.getName());
907        assertEquals("UPDATE DESCRIPTION!", pdesc.getDescription());
908       
909        form = createFormData(
910                RegistryTestHelper.getTestProfileContent("TESTNAME"),
911                "UPDATE DESCRIPTION!");
912        cResponse = getAuthenticatedResource(getResource().path(
913                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX+"Bprofile-1" + "/update")).type(
914                MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form);
915        assertEquals(ClientResponse.Status.OK.getStatusCode(),
916                cResponse.getStatus());
917        response = cResponse.getEntity(RegisterResponse.class);
918        assertTrue(response.isRegistered());
919        assertTrue(response.isProfile());
920        assertTrue(response.isInUserSpace());
921        pdesc = (ProfileDescription) response.getDescription();
922        assertNotNull(pdesc);
923        assertEquals("Test1", pdesc.getName());
924        assertEquals("UPDATE DESCRIPTION!", pdesc.getDescription());
925       
926         form = createFormData(
927                RegistryTestHelper.getTestProfileContent("TESTNAME"),
928                "UPDATE DESCRIPTION!");
929        cResponse = getAuthenticatedResource(getResource().path(
930                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX+"Cprofile-1" + "/update")).type(
931                MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form);
932        assertEquals(403, cResponse.getStatus());
933       
934    }
935
936     @Test
937    public void testPublishGroupProfileAndComponent() throws Exception {
938
939        System.out.println("testPublishProfile");
940
941        fillUpGroupA();
942        fillUpGroupB();       
943        fillUpGroupC();
944       
945        baseRegistry.setRegistrySpace(RegistrySpace.PUBLISHED);
946       
947        FormDataMultiPart  form = createFormData(
948                RegistryTestHelper.getTestProfileContent("publishedName"),
949                "Published");
950        RegisterResponse response = getAuthenticatedResource(getResource().path(
951                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX+"profile-1" + "/publish"))
952                .type(MediaType.MULTIPART_FORM_DATA).post(
953                RegisterResponse.class, form);
954        assertFalse(response.isInUserSpace());
955        assertTrue(response.isProfile());
956        assertEquals(ProfileDescription.PROFILE_PREFIX+"profile-1", response.getDescription().getId());
957       
958       
959        List<ProfileDescription> profiles = baseRegistry.getProfileDescriptions();
960        assertEquals(1, profiles.size());       
961        ProfileDescription profileDescription = profiles.get(0);
962        assertEquals(ProfileDescription.PROFILE_PREFIX+"profile-1", profileDescription.getId());
963        assertEquals("link:" + ProfileDescription.PROFILE_PREFIX+"profile-1",
964                profileDescription.getHref());
965        assertEquals("Published", profileDescription.getDescription());
966       
967       
968         
969       
970        // not my profile from "my" group
971       
972        form = createFormData(
973                RegistryTestHelper.getTestProfileContent("publishedName"),
974                "Published");
975        response = getAuthenticatedResource(getResource().path(
976                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX+"Bprofile-1" + "/publish"))
977                .type(MediaType.MULTIPART_FORM_DATA).post(
978                RegisterResponse.class, form);
979        assertFalse(response.isInUserSpace());
980        assertTrue(response.isProfile());
981        assertEquals(ProfileDescription.PROFILE_PREFIX+"Bprofile-1", response.getDescription().getId());
982     
983        profiles = baseRegistry.getProfileDescriptions();
984        assertEquals(2, profiles.size());       
985        profileDescription = profiles.get(0);
986        assertEquals(ProfileDescription.PROFILE_PREFIX+"Bprofile-1", profileDescription.getId());
987        assertEquals("link:" + ProfileDescription.PROFILE_PREFIX+"Bprofile-1",
988                profileDescription.getHref());
989        assertEquals("Published", profileDescription.getDescription());
990       
991        // not my profile, not my group
992       
993       form = createFormData(
994                RegistryTestHelper.getTestProfileContent("publishedName"),
995                "Published");
996        ClientResponse cr = getAuthenticatedResource(getResource().path(
997                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX+"Cprofile-1" + "/publish"))
998                .type(MediaType.MULTIPART_FORM_DATA).post(
999                ClientResponse.class, form);
1000        assertEquals(403, cr.getStatus());
1001        profiles = baseRegistry.getProfileDescriptions();
1002        assertEquals(2, profiles.size()); 
1003       
1004        /// components
1005       
1006       
1007        form = createFormData(
1008                RegistryTestHelper.getComponentTestContentAsStream("publishedName"),
1009                "Published");
1010        response = getAuthenticatedResource(getResource().path(
1011                "/registry/components/" + ComponentDescription.COMPONENT_PREFIX+"component-1" + "/publish"))
1012                .type(MediaType.MULTIPART_FORM_DATA).post(
1013                RegisterResponse.class, form);
1014        assertFalse(response.isInUserSpace());
1015        assertFalse(response.isProfile());
1016        assertEquals(ComponentDescription.COMPONENT_PREFIX+"component-1", response.getDescription().getId());
1017       
1018       
1019        List<ComponentDescription> components = baseRegistry.getComponentDescriptions();
1020        assertEquals(1, components.size());       
1021        ComponentDescription componentDescription = components.get(0);
1022        assertEquals(ComponentDescription.COMPONENT_PREFIX+"component-1", componentDescription.getId());
1023        assertEquals("link:" + ComponentDescription.COMPONENT_PREFIX+"component-1",
1024                componentDescription.getHref());
1025        assertEquals("Published", componentDescription.getDescription());
1026       
1027       
1028         
1029       
1030        // not my profile from "my" group
1031       
1032       
1033         form = createFormData(
1034                RegistryTestHelper.getComponentTestContentAsStream("publishedName"),
1035                "Published");
1036        response = getAuthenticatedResource(getResource().path(
1037                "/registry/components/" + ComponentDescription.COMPONENT_PREFIX+"Bcomponent-1" + "/publish"))
1038                .type(MediaType.MULTIPART_FORM_DATA).post(
1039                RegisterResponse.class, form);
1040        assertFalse(response.isInUserSpace());
1041        assertFalse(response.isProfile());
1042        assertEquals(ComponentDescription.COMPONENT_PREFIX+"Bcomponent-1", response.getDescription().getId());
1043       
1044       
1045        components = baseRegistry.getComponentDescriptions();
1046        assertEquals(2, components.size());       
1047        componentDescription = components.get(0);
1048        assertEquals(ComponentDescription.COMPONENT_PREFIX+"Bcomponent-1", componentDescription.getId());
1049        assertEquals("link:" + ComponentDescription.COMPONENT_PREFIX+"Bcomponent-1",
1050                componentDescription.getHref());
1051        assertEquals("Published", componentDescription.getDescription());
1052       
1053       
1054        // not my profile, not my group
1055       
1056        form = createFormData(
1057                RegistryTestHelper.getComponentTestContentAsStream("publishedName"),
1058                "Published");
1059        cr = getAuthenticatedResource(getResource().path(
1060                "/registry/components/" + ComponentDescription.COMPONENT_PREFIX+"Ccomponent-1" + "/publish"))
1061                .type(MediaType.MULTIPART_FORM_DATA).post(
1062                ClientResponse.class, form);
1063        assertEquals(403, cr.getStatus());
1064        components = baseRegistry.getComponentDescriptions();
1065        assertEquals(2, components.size()); 
1066    }
1067   
1068      @Test
1069    public void testDeleteProfileAndComponentFromGroup() throws Exception {
1070
1071        System.out.println("test deleteProfileAndComponentFromGroup");
1072
1073        fillUpGroupA();
1074        fillUpGroupB();       
1075        fillUpGroupC();
1076       
1077        ClientResponse response = getAuthenticatedResource(
1078                "/registry/components/" + ComponentDescription.COMPONENT_PREFIX
1079                + "component-1").delete(ClientResponse.class);
1080        assertEquals(200, response.getStatus());
1081       
1082        response = getAuthenticatedResource(
1083                "/registry/components/" + ComponentDescription.COMPONENT_PREFIX
1084                + "component-1").get(ClientResponse.class);
1085        assertEquals(404, response.getStatus());
1086       
1087        // my group, not my component
1088       
1089        response = getAuthenticatedResource(
1090                "/registry/components/" + ComponentDescription.COMPONENT_PREFIX
1091                + "Bcomponent-1").delete(ClientResponse.class);
1092        assertEquals(200, response.getStatus());
1093       
1094        response = getAuthenticatedResource(
1095                "/registry/components/" + ComponentDescription.COMPONENT_PREFIX
1096                + "Bcomponent-1").get(ClientResponse.class);
1097        assertEquals(404, response.getStatus());
1098       
1099        // not my group
1100        response = getAuthenticatedResource(
1101                "/registry/components/" + ComponentDescription.COMPONENT_PREFIX
1102                + "Ccomponent-1").delete(ClientResponse.class);
1103        assertEquals(403, response.getStatus());
1104       
1105        baseRegistry.setRegistrySpace(RegistrySpace.GROUP);
1106        baseRegistry.setGroupId(1);
1107        assertEquals(1, baseRegistry.getComponentDescriptions().size());
1108        baseRegistry.setGroupId(2);
1109        assertEquals(1, baseRegistry.getComponentDescriptions().size());
1110//        baseRegistry.setGroupId(3);
1111//        assertEquals(2, baseRegistry.getComponentDescriptions().size());
1112       
1113        baseRegistry.setRegistrySpace(null);
1114        baseRegistry.setGroupId(null);
1115       
1116        // profiles
1117       
1118        response = getAuthenticatedResource(
1119                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
1120                + "profile-1").delete(ClientResponse.class);
1121        assertEquals(200, response.getStatus());
1122       
1123        response = getAuthenticatedResource(
1124                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
1125                + "profile-1").get(ClientResponse.class);
1126        assertEquals(404, response.getStatus());
1127       
1128        // my group, not my component
1129       
1130        response = getAuthenticatedResource(
1131                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
1132                + "Bprofile-1").delete(ClientResponse.class);
1133        assertEquals(200, response.getStatus());
1134       
1135        response = getAuthenticatedResource(
1136                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
1137                + "Bprofile-1").get(ClientResponse.class);
1138        assertEquals(404, response.getStatus());
1139       
1140        // not my group
1141        response = getAuthenticatedResource(
1142                "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
1143                + "Cprofile-1").delete(ClientResponse.class);
1144        assertEquals(403, response.getStatus());
1145       
1146        baseRegistry.setRegistrySpace(RegistrySpace.GROUP);
1147        baseRegistry.setGroupId(1);
1148        assertEquals(0, baseRegistry.getProfileDescriptions().size());
1149        baseRegistry.setGroupId(2);
1150        assertEquals(0, baseRegistry.getProfileDescriptions().size());
1151    }
1152}
Note: See TracBrowser for help on using the repository browser.