1 | /* |
---|
2 | * To change this template, choose Tools | Templates |
---|
3 | * and open the template in the editor. |
---|
4 | */ |
---|
5 | package clarin.cmdi.componentregistry.rest; |
---|
6 | |
---|
7 | import clarin.cmdi.componentregistry.ComponentRegistry; |
---|
8 | import clarin.cmdi.componentregistry.ComponentRegistryFactory; |
---|
9 | import clarin.cmdi.componentregistry.ItemNotFoundException; |
---|
10 | import clarin.cmdi.componentregistry.components.CMDComponentSpec; |
---|
11 | import clarin.cmdi.componentregistry.impl.database.ComponentRegistryTestDatabase; |
---|
12 | import clarin.cmdi.componentregistry.impl.database.GroupService; |
---|
13 | import clarin.cmdi.componentregistry.model.Comment; |
---|
14 | import clarin.cmdi.componentregistry.model.ComponentDescription; |
---|
15 | import clarin.cmdi.componentregistry.model.Group; |
---|
16 | import clarin.cmdi.componentregistry.model.Ownership; |
---|
17 | import clarin.cmdi.componentregistry.model.ProfileDescription; |
---|
18 | import clarin.cmdi.componentregistry.model.RegistryUser; |
---|
19 | import clarin.cmdi.componentregistry.persistence.jpa.UserDao; |
---|
20 | import com.sun.jersey.api.client.ClientResponse; |
---|
21 | import java.text.ParseException; |
---|
22 | import java.util.List; |
---|
23 | import javax.ws.rs.core.MediaType; |
---|
24 | import javax.ws.rs.core.MultivaluedMap; |
---|
25 | import javax.xml.bind.JAXBException; |
---|
26 | import org.junit.Before; |
---|
27 | import org.springframework.beans.factory.annotation.Autowired; |
---|
28 | import org.springframework.jdbc.core.JdbcTemplate; |
---|
29 | |
---|
30 | import static org.junit.Assert.*; |
---|
31 | import org.junit.Test; |
---|
32 | |
---|
33 | /** |
---|
34 | * |
---|
35 | * @author olhsha |
---|
36 | */ |
---|
37 | public class RestGroupServiceTest extends ComponentRegistryRestServiceTestCase { |
---|
38 | |
---|
39 | @Autowired |
---|
40 | private ComponentRegistryFactory componentRegistryFactory; |
---|
41 | |
---|
42 | @Autowired |
---|
43 | private JdbcTemplate jdbcTemplate; |
---|
44 | @Autowired |
---|
45 | private GroupService groupService; |
---|
46 | @Autowired |
---|
47 | private UserDao userDao; |
---|
48 | |
---|
49 | private ComponentRegistry baseRegistry; |
---|
50 | |
---|
51 | @Before |
---|
52 | public void init() { |
---|
53 | ComponentRegistryTestDatabase.resetAndCreateAllTables(jdbcTemplate); |
---|
54 | createUserRecord(); |
---|
55 | baseRegistry = componentRegistryFactory.getBaseRegistry(DummyPrincipal.DUMMY_CREDENTIALS); |
---|
56 | } |
---|
57 | |
---|
58 | private String expectedUserId(String principal) { |
---|
59 | return getUserDao().getByPrincipalName(principal).getId().toString(); |
---|
60 | } |
---|
61 | private ComponentDescription component1; |
---|
62 | private ComponentDescription component2; |
---|
63 | private ProfileDescription profile1; |
---|
64 | private ProfileDescription profile2; |
---|
65 | private ComponentDescription component3; |
---|
66 | private ProfileDescription profile3; |
---|
67 | private Comment profile1Comment1; |
---|
68 | private Comment profile1Comment2; |
---|
69 | private Comment component1Comment3; |
---|
70 | private Comment component1Comment4; |
---|
71 | private Comment profile3Comment5; |
---|
72 | private Comment component3Comment7; |
---|
73 | |
---|
74 | private void fillUpPublicItems() throws Exception { |
---|
75 | |
---|
76 | profile1 = RegistryTestHelper.addProfile(baseRegistry, "profile2", true); |
---|
77 | profile2 = RegistryTestHelper.addProfile(baseRegistry, "profile1", true); |
---|
78 | component1 = RegistryTestHelper.addComponent(baseRegistry, |
---|
79 | "component2", true); |
---|
80 | component2 = RegistryTestHelper.addComponent(baseRegistry, |
---|
81 | "component1", true); |
---|
82 | profile1Comment2 = RegistryTestHelper.addComment(baseRegistry, "comment2", |
---|
83 | ProfileDescription.PROFILE_PREFIX + "profile1", |
---|
84 | "JUnit@test.com"); |
---|
85 | profile1Comment1 = RegistryTestHelper.addComment(baseRegistry, "comment1", |
---|
86 | ProfileDescription.PROFILE_PREFIX + "profile1", |
---|
87 | "JUnit@test.com"); |
---|
88 | component1Comment3 = RegistryTestHelper.addComment(baseRegistry, "comment3", |
---|
89 | ComponentDescription.COMPONENT_PREFIX + "component1", |
---|
90 | "JUnit@test.com"); |
---|
91 | component1Comment4 = RegistryTestHelper.addComment(baseRegistry, "comment4", |
---|
92 | ComponentDescription.COMPONENT_PREFIX + "component1", |
---|
93 | "JUnit@test.com"); |
---|
94 | } |
---|
95 | |
---|
96 | private void fillUpPrivateItems() throws Exception { |
---|
97 | profile3 = RegistryTestHelper.addProfile(baseRegistry, "profile3", false); |
---|
98 | component3 = RegistryTestHelper.addComponent(baseRegistry, |
---|
99 | "component3", false); |
---|
100 | profile3Comment5 = RegistryTestHelper.addComment(baseRegistry, "comment5", |
---|
101 | ProfileDescription.PROFILE_PREFIX + "profile3", |
---|
102 | "JUnit@test.com"); |
---|
103 | component3Comment7 = RegistryTestHelper.addComment(baseRegistry, "comment7", |
---|
104 | ComponentDescription.COMPONENT_PREFIX + "component3", |
---|
105 | "JUnit@test.com"); |
---|
106 | } |
---|
107 | |
---|
108 | protected void createAntherUserRecord() { |
---|
109 | RegistryUser user = new RegistryUser(); |
---|
110 | user.setName("Another database test user"); |
---|
111 | user.setPrincipalName("anotherPrincipal"); |
---|
112 | userDao.save(user); |
---|
113 | } |
---|
114 | |
---|
115 | private void MakeGroupA(){ |
---|
116 | groupService.createNewGroup("group A", DummyPrincipal.DUMMY_PRINCIPAL.getName()); |
---|
117 | } |
---|
118 | |
---|
119 | private void fillUpGroupA() throws ParseException, JAXBException, ItemNotFoundException{ |
---|
120 | |
---|
121 | MakeGroupA(); |
---|
122 | |
---|
123 | RegistryTestHelper.addProfile(baseRegistry, "profile-1", false); |
---|
124 | RegistryTestHelper.addComponent(baseRegistry, "component-1", false); |
---|
125 | RegistryTestHelper.addComponent(baseRegistry, "component-2", false); |
---|
126 | |
---|
127 | Ownership ownership = new Ownership(); |
---|
128 | ownership.setComponentId(ProfileDescription.PROFILE_PREFIX+"profile-1"); |
---|
129 | ownership.setGroupId(1); |
---|
130 | ownership.setUserId(0); |
---|
131 | groupService.addOwnership(ownership); |
---|
132 | |
---|
133 | ownership.setComponentId(ComponentDescription.COMPONENT_PREFIX+"component-1"); |
---|
134 | ownership.setGroupId(1); |
---|
135 | ownership.setUserId(0); |
---|
136 | groupService.addOwnership(ownership); |
---|
137 | |
---|
138 | ownership.setComponentId(ComponentDescription.COMPONENT_PREFIX+"component-2"); |
---|
139 | ownership.setGroupId(1); |
---|
140 | ownership.setUserId(0); |
---|
141 | groupService.addOwnership(ownership); |
---|
142 | |
---|
143 | } |
---|
144 | |
---|
145 | |
---|
146 | |
---|
147 | private void MakeGroupB() throws ItemNotFoundException{ |
---|
148 | createAntherUserRecord(); |
---|
149 | groupService.createNewGroup("group B", "anotherPrincipal"); |
---|
150 | groupService.makeMember(DummyPrincipal.DUMMY_PRINCIPAL.getName(), "group B"); |
---|
151 | } |
---|
152 | |
---|
153 | private void MakeGroupC() throws ItemNotFoundException{ |
---|
154 | groupService.createNewGroup("group C", "anotherPrincipal"); |
---|
155 | } |
---|
156 | |
---|
157 | private void fillUpGroupB() throws ParseException, JAXBException, ItemNotFoundException{ |
---|
158 | |
---|
159 | MakeGroupB(); |
---|
160 | |
---|
161 | RegistryTestHelper.addProfile(baseRegistry, "Bprofile-1", false); |
---|
162 | RegistryTestHelper.addComponent(baseRegistry, "Bcomponent-1", false); |
---|
163 | RegistryTestHelper.addComponent(baseRegistry, "Bcomponent-2", false); |
---|
164 | |
---|
165 | Ownership ownership = new Ownership(); |
---|
166 | ownership.setComponentId(ProfileDescription.PROFILE_PREFIX+"Bprofile-1"); |
---|
167 | ownership.setGroupId(2); |
---|
168 | ownership.setUserId(0); |
---|
169 | groupService.addOwnership(ownership); |
---|
170 | |
---|
171 | ownership.setComponentId(ComponentDescription.COMPONENT_PREFIX+"Bcomponent-1"); |
---|
172 | ownership.setGroupId(2); |
---|
173 | ownership.setUserId(0); |
---|
174 | groupService.addOwnership(ownership); |
---|
175 | |
---|
176 | ownership.setComponentId(ComponentDescription.COMPONENT_PREFIX+"Bcomponent-2"); |
---|
177 | ownership.setGroupId(2); |
---|
178 | ownership.setUserId(0); |
---|
179 | groupService.addOwnership(ownership); |
---|
180 | |
---|
181 | } |
---|
182 | |
---|
183 | private void fillUpGroupC() throws ParseException, JAXBException, ItemNotFoundException{ |
---|
184 | |
---|
185 | MakeGroupC(); |
---|
186 | |
---|
187 | RegistryTestHelper.addProfileAnotherPrincipal(baseRegistry, "Cprofile-1", false); |
---|
188 | RegistryTestHelper.addComponentAnotherPrincipal(baseRegistry, "Ccomponent-1", false); |
---|
189 | RegistryTestHelper.addComponentAnotherPrincipal(baseRegistry, "Ccomponent-2", false); |
---|
190 | |
---|
191 | Ownership ownership = new Ownership(); |
---|
192 | ownership.setComponentId(ProfileDescription.PROFILE_PREFIX+"Cprofile-1"); |
---|
193 | ownership.setGroupId(3); |
---|
194 | ownership.setUserId(0); |
---|
195 | groupService.addOwnership(ownership); |
---|
196 | |
---|
197 | ownership.setComponentId(ComponentDescription.COMPONENT_PREFIX+"Ccomponent-1"); |
---|
198 | ownership.setGroupId(3); |
---|
199 | ownership.setUserId(0); |
---|
200 | groupService.addOwnership(ownership); |
---|
201 | |
---|
202 | ownership.setComponentId(ComponentDescription.COMPONENT_PREFIX+"Ccomponent-2"); |
---|
203 | ownership.setGroupId(3); |
---|
204 | ownership.setUserId(0); |
---|
205 | groupService.addOwnership(ownership); |
---|
206 | |
---|
207 | } |
---|
208 | |
---|
209 | // Response createNewGroup(String groupName) throws IOException; |
---|
210 | |
---|
211 | @Test |
---|
212 | public void testCreateNewGroup() { |
---|
213 | System.out.println("test createNewGroup"); |
---|
214 | ClientResponse cr = this.getAuthenticatedResource(getResource() |
---|
215 | .path("/registry/groups/create").queryParam("groupName", "newGroup")) |
---|
216 | .accept(MediaType.TEXT_XML).post(ClientResponse.class); |
---|
217 | assertEquals(200, cr.getStatus()); |
---|
218 | assertEquals("Group with the name newGroup is created and given an id 1", cr.getEntity(String.class)); |
---|
219 | } |
---|
220 | |
---|
221 | |
---|
222 | |
---|
223 | |
---|
224 | // List<Group> getGroupsOwnedByUser(String pricipalName) throws IOException; |
---|
225 | |
---|
226 | @Test |
---|
227 | public void testGetGroupsOwnedByUser() { |
---|
228 | System.out.println("test GetGroupsOwnedByUser"); |
---|
229 | ClientResponse cr = this.getAuthenticatedResource(getResource() |
---|
230 | .path("/registry/groups/create").queryParam("groupName", "newGroup1")) |
---|
231 | .accept(MediaType.TEXT_XML).post(ClientResponse.class); |
---|
232 | assertEquals(200, cr.getStatus()); |
---|
233 | ClientResponse cr1 = this.getAuthenticatedResource(getResource() |
---|
234 | .path("/registry/groups/create").queryParam("groupName", "newGroup2")) |
---|
235 | .accept(MediaType.TEXT_XML).post(ClientResponse.class); |
---|
236 | assertEquals(200, cr1.getStatus()); |
---|
237 | |
---|
238 | // test itself |
---|
239 | |
---|
240 | List<Group> result = this.getAuthenticatedResource(getResource() |
---|
241 | .path("/registry/groups/principal").queryParam("principalName", DummyPrincipal.DUMMY_PRINCIPAL.getName())) |
---|
242 | .accept(MediaType.APPLICATION_XML).get(GROUP_LIST_GENERICTYPE); |
---|
243 | |
---|
244 | assertEquals(2, result.size()); |
---|
245 | assertEquals("newGroup1", result.get(0).getName()); |
---|
246 | assertEquals("newGroup2", result.get(1).getName()); |
---|
247 | } |
---|
248 | |
---|
249 | |
---|
250 | // List<Group> getGroupsTheCurrentUserIsAMemberOf(); |
---|
251 | |
---|
252 | @Test |
---|
253 | public void testGetGroupsTheCurrentUserIsAMemberOf() throws ItemNotFoundException{ |
---|
254 | System.out.println("test getGroupsTheCurrentUserIsAMemberOfr"); |
---|
255 | |
---|
256 | MakeGroupA(); |
---|
257 | MakeGroupB(); |
---|
258 | // test itself |
---|
259 | |
---|
260 | List<Group> result = this.getAuthenticatedResource(getResource() |
---|
261 | .path("/registry/groups/usermembership")) |
---|
262 | .accept(MediaType.APPLICATION_XML).get(GROUP_LIST_GENERICTYPE); |
---|
263 | |
---|
264 | assertEquals(1, result.size()); |
---|
265 | assertEquals("group B", result.get(0).getName()); |
---|
266 | } |
---|
267 | // |
---|
268 | // List<Group> getGroupsTheItemIsAMemberOf(String itemId); |
---|
269 | |
---|
270 | @Test |
---|
271 | public void testGetGroupsTheItemIsAMemberOf() throws ParseException, JAXBException, ItemNotFoundException{ |
---|
272 | System.out.println("test getGroupsTheItemIsAMemberOf"); |
---|
273 | |
---|
274 | fillUpGroupA(); |
---|
275 | fillUpGroupB(); |
---|
276 | // test itself |
---|
277 | |
---|
278 | List<Group> result = this.getAuthenticatedResource(getResource() |
---|
279 | .path("/registry/items/"+ComponentDescription.COMPONENT_PREFIX+"component-1/groups")) |
---|
280 | .accept(MediaType.APPLICATION_XML).get(GROUP_LIST_GENERICTYPE); |
---|
281 | |
---|
282 | assertEquals(1, result.size()); |
---|
283 | assertEquals("group A", result.get(0).getName()); |
---|
284 | |
---|
285 | result = this.getAuthenticatedResource(getResource() |
---|
286 | .path("/registry/items/"+ComponentDescription.COMPONENT_PREFIX+"Bcomponent-1/groups")) |
---|
287 | .accept(MediaType.APPLICATION_XML).get(GROUP_LIST_GENERICTYPE); |
---|
288 | |
---|
289 | assertEquals(1, result.size()); |
---|
290 | assertEquals("group B", result.get(0).getName()); |
---|
291 | |
---|
292 | result = this.getAuthenticatedResource(getResource() |
---|
293 | .path("/registry/items/"+ProfileDescription.PROFILE_PREFIX+"Bprofile-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+"profile-1/groups")) |
---|
301 | .accept(MediaType.APPLICATION_XML).get(GROUP_LIST_GENERICTYPE); |
---|
302 | |
---|
303 | assertEquals(1, result.size()); |
---|
304 | assertEquals("group A", result.get(0).getName()); |
---|
305 | } |
---|
306 | |
---|
307 | |
---|
308 | |
---|
309 | |
---|
310 | |
---|
311 | @Test |
---|
312 | public void testListGroupNames() throws ItemNotFoundException{ |
---|
313 | System.out.println("test listGroupNames"); |
---|
314 | |
---|
315 | MakeGroupA(); |
---|
316 | MakeGroupB(); |
---|
317 | |
---|
318 | // test itself |
---|
319 | |
---|
320 | ClientResponse cr = this.getAuthenticatedResource(getResource() |
---|
321 | .path("/registry/groups/names")).accept(MediaType.APPLICATION_XML).get(ClientResponse.class); |
---|
322 | assertEquals(200, cr.getStatus()); |
---|
323 | List<String> result = cr.getEntity(ComponentRegistryRestService.StringsWrapper.class).strings; |
---|
324 | assertEquals(2, result.size()); |
---|
325 | assertEquals("group A", result.get(0)); |
---|
326 | assertEquals("group B", result.get(1)); |
---|
327 | } |
---|
328 | |
---|
329 | // |
---|
330 | // Response isOwner(String groupName) throws IOException; |
---|
331 | |
---|
332 | @Test |
---|
333 | public void testIsOwner() throws ItemNotFoundException{ |
---|
334 | System.out.println("test isOwner"); |
---|
335 | |
---|
336 | MakeGroupA(); |
---|
337 | MakeGroupB(); |
---|
338 | |
---|
339 | // test itself |
---|
340 | |
---|
341 | ClientResponse cr = this.getAuthenticatedResource(getResource() |
---|
342 | .path("/registry/groups/ownership").queryParam("groupName", "group A")).accept(MediaType.APPLICATION_XML).get(ClientResponse.class); |
---|
343 | assertEquals(200, cr.getStatus()); |
---|
344 | String result = cr.getEntity(String.class); |
---|
345 | assertEquals("true", result); |
---|
346 | |
---|
347 | cr = this.getAuthenticatedResource(getResource() |
---|
348 | .path("/registry/groups/ownership").queryParam("groupName", "group B")).accept(MediaType.APPLICATION_XML).get(ClientResponse.class); |
---|
349 | assertEquals(200, cr.getStatus()); |
---|
350 | result = cr.getEntity(String.class); |
---|
351 | assertEquals("false", result); |
---|
352 | } |
---|
353 | |
---|
354 | |
---|
355 | // |
---|
356 | // Response makeGroupMember(String groupName, String principalName) throws IOException; |
---|
357 | |
---|
358 | @Test |
---|
359 | public void testMakeGroupMember() throws ItemNotFoundException{ |
---|
360 | System.out.println("test makeGroupMember"); |
---|
361 | |
---|
362 | MakeGroupA(); |
---|
363 | MakeGroupB(); |
---|
364 | // test itself |
---|
365 | |
---|
366 | //MultivaluedMap<String, String> params = new MultivaluedHashMap<String, String>(); |
---|
367 | ClientResponse cr = this.getAuthenticatedResource(getResource() |
---|
368 | .path("/registry/groups/makemember").queryParam("groupName", "group A").queryParam("principalName", "anotherPrincipal")).accept(MediaType.APPLICATION_XML).post(ClientResponse.class); |
---|
369 | assertEquals(200, cr.getStatus()); |
---|
370 | |
---|
371 | assertTrue(groupService.userGroupMember("anotherPrincipal", "1")); |
---|
372 | |
---|
373 | ; |
---|
374 | cr = this.getAuthenticatedResource(getResource() |
---|
375 | .path("/registry/groups/makemember").queryParam("groupName", "group B").queryParam("principalName", "anotherPrincipal")).accept(MediaType.APPLICATION_XML).post(ClientResponse.class); |
---|
376 | assertEquals(403, cr.getStatus()); |
---|
377 | } |
---|
378 | |
---|
379 | // |
---|
380 | // Response listProfiles(String groupId) throws IOException; |
---|
381 | |
---|
382 | @Test |
---|
383 | public void testListProfilesAndComponents() throws Exception{ |
---|
384 | System.out.println("test listProfilesAndComponents"); |
---|
385 | |
---|
386 | fillUpGroupA(); |
---|
387 | |
---|
388 | // test itself |
---|
389 | |
---|
390 | ClientResponse cr = this.getAuthenticatedResource(getResource() |
---|
391 | .path("/registry/groups/profiles").queryParam("groupId", "1")).accept(MediaType.APPLICATION_XML).get(ClientResponse.class); |
---|
392 | assertEquals(200, cr.getStatus()); |
---|
393 | List<String> result = cr.getEntity(ComponentRegistryRestService.StringsWrapper.class).strings; |
---|
394 | assertEquals(1, result.size()); |
---|
395 | assertEquals(ProfileDescription.PROFILE_PREFIX+"profile-1", result.get(0)); |
---|
396 | |
---|
397 | cr = this.getAuthenticatedResource(getResource() |
---|
398 | .path("/registry/groups/components").queryParam("groupId", "1")).accept(MediaType.APPLICATION_XML).get(ClientResponse.class); |
---|
399 | assertEquals(200, cr.getStatus()); |
---|
400 | result = cr.getEntity(ComponentRegistryRestService.StringsWrapper.class).strings; |
---|
401 | assertEquals(2, result.size()); |
---|
402 | assertEquals(ComponentDescription.COMPONENT_PREFIX+"component-1", result.get(0)); |
---|
403 | assertEquals(ComponentDescription.COMPONENT_PREFIX+"component-2", result.get(1)); |
---|
404 | } |
---|
405 | |
---|
406 | |
---|
407 | |
---|
408 | // |
---|
409 | // Response getGroupNameById(String groupId) throws IOException; |
---|
410 | |
---|
411 | @Test |
---|
412 | public void testGetGroupNamebyId() throws Exception{ |
---|
413 | System.out.println("test getGroupNamebyId"); |
---|
414 | |
---|
415 | MakeGroupA(); |
---|
416 | MakeGroupB(); |
---|
417 | // test itself |
---|
418 | |
---|
419 | ClientResponse cr = this.getAuthenticatedResource(getResource() |
---|
420 | .path("/registry/groups/nameById").queryParam("groupId", "1")).accept(MediaType.APPLICATION_XML).get(ClientResponse.class); |
---|
421 | assertEquals(200, cr.getStatus()); |
---|
422 | String result = cr.getEntity(String.class); |
---|
423 | assertEquals("group A", result); |
---|
424 | |
---|
425 | cr = this.getAuthenticatedResource(getResource() |
---|
426 | .path("/registry/groups/nameById").queryParam("groupId", "2")).accept(MediaType.APPLICATION_XML).get(ClientResponse.class); |
---|
427 | assertEquals(200, cr.getStatus()); |
---|
428 | result = cr.getEntity(String.class); |
---|
429 | assertEquals("group B", result); |
---|
430 | } |
---|
431 | |
---|
432 | // |
---|
433 | // Response getGroupIdByName(String groupName) throws IOException; |
---|
434 | |
---|
435 | @Test |
---|
436 | public void testGetIdByGroupName() throws Exception{ |
---|
437 | System.out.println("test getIdByGroupName"); |
---|
438 | |
---|
439 | MakeGroupA(); |
---|
440 | MakeGroupB(); |
---|
441 | // test itself |
---|
442 | |
---|
443 | ClientResponse cr = this.getAuthenticatedResource(getResource() |
---|
444 | .path("/registry/groups/idByName").queryParam("groupName", "group B")).accept(MediaType.APPLICATION_XML).get(ClientResponse.class); |
---|
445 | assertEquals(200, cr.getStatus()); |
---|
446 | String result = cr.getEntity(String.class); |
---|
447 | assertEquals("2", result); |
---|
448 | |
---|
449 | cr = this.getAuthenticatedResource(getResource() |
---|
450 | .path("/registry/groups/idByName").queryParam("groupName", "group A")).accept(MediaType.APPLICATION_XML).get(ClientResponse.class); |
---|
451 | assertEquals(200, cr.getStatus()); |
---|
452 | result = cr.getEntity(String.class); |
---|
453 | assertEquals("1", result); |
---|
454 | } |
---|
455 | |
---|
456 | |
---|
457 | // Response transferItemOwnershipToGroup(String itemId, long groupId) throws IOException; |
---|
458 | // |
---|
459 | |
---|
460 | @Test |
---|
461 | public void testTransferOwnership() throws Exception{ |
---|
462 | System.out.println("test makeTransferOwnership"); |
---|
463 | |
---|
464 | fillUpGroupA(); |
---|
465 | fillUpGroupB(); |
---|
466 | fillUpGroupC(); |
---|
467 | // test itself |
---|
468 | |
---|
469 | |
---|
470 | RegistryTestHelper.addComponent(baseRegistry, "test_component", false); |
---|
471 | RegistryTestHelper.addProfile(baseRegistry, "test_profile", false); |
---|
472 | String test_profile_id = ProfileDescription.PROFILE_PREFIX+"test_profile"; |
---|
473 | String test_component_id = ComponentDescription.COMPONENT_PREFIX+"test_component"; |
---|
474 | //I'm not a member |
---|
475 | ClientResponse cr = this.getAuthenticatedResource(getResource() |
---|
476 | .path("/registry/items/"+test_profile_id+"/transferownership").queryParam("groupId", "3")).accept(MediaType.APPLICATION_XML).post(ClientResponse.class); |
---|
477 | assertEquals(403, cr.getStatus()); |
---|
478 | |
---|
479 | //make me a member |
---|
480 | groupService.makeMember(DummyPrincipal.DUMMY_PRINCIPAL.getName(), "group C"); |
---|
481 | assertTrue(groupService.userGroupMember(DummyPrincipal.DUMMY_PRINCIPAL.getName(), "3")); |
---|
482 | |
---|
483 | cr = this.getAuthenticatedResource(getResource() |
---|
484 | .path("/registry/items/"+test_profile_id+"/transferownership").queryParam("groupId", "3")).accept(MediaType.APPLICATION_XML).post(ClientResponse.class); |
---|
485 | assertEquals(200, cr.getStatus()); |
---|
486 | cr = this.getAuthenticatedResource(getResource() |
---|
487 | .path("/registry/items/"+test_component_id+"/transferownership").queryParam("groupId", "3")).accept(MediaType.APPLICATION_XML).post(ClientResponse.class); |
---|
488 | assertEquals(200, cr.getStatus()); |
---|
489 | |
---|
490 | |
---|
491 | List<String> components = groupService.getComponentIdsInGroup(3); |
---|
492 | assertEquals(3, components.size()); |
---|
493 | assertEquals(test_component_id, components.get(2)); |
---|
494 | List<String> profiles = groupService.getProfileIdsInGroup(3); |
---|
495 | assertEquals(2, profiles.size()); |
---|
496 | assertEquals(test_profile_id, profiles.get(1)); |
---|
497 | |
---|
498 | } |
---|
499 | |
---|
500 | @Test |
---|
501 | public void testGetGroupProfilesAndComponents() throws Exception { |
---|
502 | |
---|
503 | System.out.println("test getGroupProfiles"); |
---|
504 | |
---|
505 | fillUpGroupA(); |
---|
506 | fillUpGroupB(); |
---|
507 | fillUpGroupC(); |
---|
508 | |
---|
509 | |
---|
510 | List<ProfileDescription> response = this.getAuthenticatedResource(getResource() |
---|
511 | .path("/registry/profiles").queryParam("registrySpace", "group").queryParam("groupid", "1")).accept(MediaType.APPLICATION_XML) |
---|
512 | .get(PROFILE_LIST_GENERICTYPE); |
---|
513 | assertEquals(1, response.size()); |
---|
514 | |
---|
515 | List<ComponentDescription> responseC = this.getAuthenticatedResource(getResource() |
---|
516 | .path("/registry/components").queryParam("registrySpace", "group").queryParam("groupid", "1")).accept(MediaType.APPLICATION_XML) |
---|
517 | .get(COMPONENT_LIST_GENERICTYPE); |
---|
518 | assertEquals(2, responseC.size()); |
---|
519 | |
---|
520 | response = this.getAuthenticatedResource(getResource() |
---|
521 | .path("/registry/profiles").queryParam("registrySpace", "group").queryParam("groupid", "2")).accept(MediaType.APPLICATION_XML) |
---|
522 | .get(PROFILE_LIST_GENERICTYPE); |
---|
523 | assertEquals(1, response.size()); |
---|
524 | |
---|
525 | responseC = this.getAuthenticatedResource(getResource() |
---|
526 | .path("/registry/components").queryParam("registrySpace", "group").queryParam("groupid", "2")).accept(MediaType.APPLICATION_XML) |
---|
527 | .get(COMPONENT_LIST_GENERICTYPE); |
---|
528 | assertEquals(2, responseC.size()); |
---|
529 | |
---|
530 | ClientResponse clientResponse = this.getAuthenticatedResource(getResource() |
---|
531 | .path("/registry/components").queryParam("registrySpace", "group").queryParam("groupid", "3")).accept(MediaType.APPLICATION_XML) |
---|
532 | .get(ClientResponse.class); |
---|
533 | |
---|
534 | assertEquals(403, clientResponse.getStatus()); |
---|
535 | |
---|
536 | |
---|
537 | CMDComponentSpec component = this.getAuthenticatedResource(getResource() |
---|
538 | .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX+"profile-1")) |
---|
539 | .accept(MediaType.APPLICATION_JSON).get(CMDComponentSpec.class); |
---|
540 | assertNotNull(component); |
---|
541 | assertEquals("Actor", component.getCMDComponent().getName()); |
---|
542 | |
---|
543 | component = this.getAuthenticatedResource(getResource() |
---|
544 | .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX+"component-1")) |
---|
545 | .accept(MediaType.APPLICATION_JSON).get(CMDComponentSpec.class); |
---|
546 | assertNotNull(component); |
---|
547 | assertEquals("Access", component.getCMDComponent().getName()); |
---|
548 | |
---|
549 | component = this.getAuthenticatedResource(getResource() |
---|
550 | .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX+"Bprofile-1")) |
---|
551 | .accept(MediaType.APPLICATION_JSON).get(CMDComponentSpec.class); |
---|
552 | assertNotNull(component); |
---|
553 | assertEquals("Actor", component.getCMDComponent().getName()); |
---|
554 | |
---|
555 | component = this.getAuthenticatedResource(getResource() |
---|
556 | .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX+"Bcomponent-1")) |
---|
557 | .accept(MediaType.APPLICATION_JSON).get(CMDComponentSpec.class); |
---|
558 | assertNotNull(component); |
---|
559 | assertEquals("Access", component.getCMDComponent().getName()); |
---|
560 | |
---|
561 | clientResponse = this.getAuthenticatedResource(getResource() |
---|
562 | .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX+"Cprofile-1")) |
---|
563 | .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); |
---|
564 | assertEquals(403, clientResponse.getStatus()); |
---|
565 | |
---|
566 | clientResponse = this.getAuthenticatedResource(getResource() |
---|
567 | .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX+"Ccomponent-1")) |
---|
568 | .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); |
---|
569 | assertEquals(403, clientResponse.getStatus()); |
---|
570 | |
---|
571 | } |
---|
572 | |
---|
573 | } |
---|