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.CommentsDao; |
---|
20 | import clarin.cmdi.componentregistry.persistence.jpa.UserDao; |
---|
21 | import com.sun.jersey.api.client.ClientResponse; |
---|
22 | import java.text.ParseException; |
---|
23 | import java.util.List; |
---|
24 | import javax.ws.rs.core.MediaType; |
---|
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 | @Autowired |
---|
49 | private CommentsDao commentsDao; |
---|
50 | |
---|
51 | private ComponentRegistry baseRegistry; |
---|
52 | |
---|
53 | @Before |
---|
54 | public void init() { |
---|
55 | ComponentRegistryTestDatabase.resetAndCreateAllTables(jdbcTemplate); |
---|
56 | createUserRecord(); |
---|
57 | baseRegistry = componentRegistryFactory.getBaseRegistry(DummyPrincipal.DUMMY_CREDENTIALS); |
---|
58 | } |
---|
59 | |
---|
60 | private String expectedUserId(String principal) { |
---|
61 | return getUserDao().getByPrincipalName(principal).getId().toString(); |
---|
62 | } |
---|
63 | private ComponentDescription component1; |
---|
64 | private ComponentDescription component2; |
---|
65 | private ProfileDescription profile1; |
---|
66 | private ProfileDescription profile2; |
---|
67 | private ComponentDescription component3; |
---|
68 | private ProfileDescription profile3; |
---|
69 | private Comment profile1Comment1; |
---|
70 | private Comment profile1Comment2; |
---|
71 | private Comment component1Comment3; |
---|
72 | private Comment component1Comment4; |
---|
73 | private Comment profile3Comment5; |
---|
74 | private Comment component3Comment7; |
---|
75 | |
---|
76 | private void fillUpPublicItems() throws Exception { |
---|
77 | |
---|
78 | profile1 = RegistryTestHelper.addProfile(baseRegistry, "profile2", true); |
---|
79 | profile2 = RegistryTestHelper.addProfile(baseRegistry, "profile1", true); |
---|
80 | component1 = RegistryTestHelper.addComponent(baseRegistry, |
---|
81 | "component2", true); |
---|
82 | component2 = RegistryTestHelper.addComponent(baseRegistry, |
---|
83 | "component1", true); |
---|
84 | profile1Comment2 = RegistryTestHelper.addComment(baseRegistry, "comment2", |
---|
85 | ProfileDescription.PROFILE_PREFIX + "profile1", |
---|
86 | "JUnit@test.com"); |
---|
87 | profile1Comment1 = RegistryTestHelper.addComment(baseRegistry, "comment1", |
---|
88 | ProfileDescription.PROFILE_PREFIX + "profile1", |
---|
89 | "JUnit@test.com"); |
---|
90 | component1Comment3 = RegistryTestHelper.addComment(baseRegistry, "comment3", |
---|
91 | ComponentDescription.COMPONENT_PREFIX + "component1", |
---|
92 | "JUnit@test.com"); |
---|
93 | component1Comment4 = RegistryTestHelper.addComment(baseRegistry, "comment4", |
---|
94 | ComponentDescription.COMPONENT_PREFIX + "component1", |
---|
95 | "JUnit@test.com"); |
---|
96 | } |
---|
97 | |
---|
98 | private void fillUpPrivateItems() throws Exception { |
---|
99 | profile3 = RegistryTestHelper.addProfile(baseRegistry, "profile3", false); |
---|
100 | component3 = RegistryTestHelper.addComponent(baseRegistry, |
---|
101 | "component3", false); |
---|
102 | profile3Comment5 = RegistryTestHelper.addComment(baseRegistry, "comment5", |
---|
103 | ProfileDescription.PROFILE_PREFIX + "profile3", |
---|
104 | "JUnit@test.com"); |
---|
105 | component3Comment7 = RegistryTestHelper.addComment(baseRegistry, "comment7", |
---|
106 | ComponentDescription.COMPONENT_PREFIX + "component3", |
---|
107 | "JUnit@test.com"); |
---|
108 | } |
---|
109 | |
---|
110 | protected void createAntherUserRecord() { |
---|
111 | RegistryUser user = new RegistryUser(); |
---|
112 | user.setName("Another database test user"); |
---|
113 | user.setPrincipalName("anotherPrincipal"); |
---|
114 | userDao.save(user); |
---|
115 | } |
---|
116 | |
---|
117 | private void MakeGroupA(){ |
---|
118 | groupService.createNewGroup("group A", DummyPrincipal.DUMMY_PRINCIPAL.getName()); |
---|
119 | } |
---|
120 | |
---|
121 | private void fillUpGroupA() throws ParseException, JAXBException, ItemNotFoundException{ |
---|
122 | |
---|
123 | MakeGroupA(); |
---|
124 | |
---|
125 | RegistryTestHelper.addProfile(baseRegistry, "profile-1", false); |
---|
126 | RegistryTestHelper.addComponent(baseRegistry, "component-1", false); |
---|
127 | RegistryTestHelper.addComponent(baseRegistry, "component-2", false); |
---|
128 | |
---|
129 | Ownership ownership = new Ownership(); |
---|
130 | ownership.setComponentId(ProfileDescription.PROFILE_PREFIX+"profile-1"); |
---|
131 | ownership.setGroupId(1); |
---|
132 | ownership.setUserId(0); |
---|
133 | groupService.addOwnership(ownership); |
---|
134 | |
---|
135 | ownership.setComponentId(ComponentDescription.COMPONENT_PREFIX+"component-1"); |
---|
136 | ownership.setGroupId(1); |
---|
137 | ownership.setUserId(0); |
---|
138 | groupService.addOwnership(ownership); |
---|
139 | |
---|
140 | ownership.setComponentId(ComponentDescription.COMPONENT_PREFIX+"component-2"); |
---|
141 | ownership.setGroupId(1); |
---|
142 | ownership.setUserId(0); |
---|
143 | groupService.addOwnership(ownership); |
---|
144 | |
---|
145 | } |
---|
146 | |
---|
147 | |
---|
148 | |
---|
149 | private void MakeGroupB() throws ItemNotFoundException{ |
---|
150 | createAntherUserRecord(); |
---|
151 | groupService.createNewGroup("group B", "anotherPrincipal"); |
---|
152 | groupService.makeMember(DummyPrincipal.DUMMY_PRINCIPAL.getName(), "group B"); |
---|
153 | } |
---|
154 | |
---|
155 | private void MakeGroupC() throws ItemNotFoundException{ |
---|
156 | groupService.createNewGroup("group C", "anotherPrincipal"); |
---|
157 | } |
---|
158 | |
---|
159 | private void fillUpGroupB() throws ParseException, JAXBException, ItemNotFoundException{ |
---|
160 | |
---|
161 | MakeGroupB(); |
---|
162 | |
---|
163 | RegistryTestHelper.addProfile(baseRegistry, "Bprofile-1", false); |
---|
164 | RegistryTestHelper.addComponent(baseRegistry, "Bcomponent-1", false); |
---|
165 | RegistryTestHelper.addComponent(baseRegistry, "Bcomponent-2", false); |
---|
166 | |
---|
167 | Ownership ownership = new Ownership(); |
---|
168 | ownership.setComponentId(ProfileDescription.PROFILE_PREFIX+"Bprofile-1"); |
---|
169 | ownership.setGroupId(2); |
---|
170 | ownership.setUserId(0); |
---|
171 | groupService.addOwnership(ownership); |
---|
172 | |
---|
173 | ownership.setComponentId(ComponentDescription.COMPONENT_PREFIX+"Bcomponent-1"); |
---|
174 | ownership.setGroupId(2); |
---|
175 | ownership.setUserId(0); |
---|
176 | groupService.addOwnership(ownership); |
---|
177 | |
---|
178 | ownership.setComponentId(ComponentDescription.COMPONENT_PREFIX+"Bcomponent-2"); |
---|
179 | ownership.setGroupId(2); |
---|
180 | ownership.setUserId(0); |
---|
181 | groupService.addOwnership(ownership); |
---|
182 | |
---|
183 | } |
---|
184 | |
---|
185 | private void fillUpGroupC() throws ParseException, JAXBException, ItemNotFoundException{ |
---|
186 | |
---|
187 | MakeGroupC(); |
---|
188 | |
---|
189 | RegistryTestHelper.addProfileAnotherPrincipal(baseRegistry, "Cprofile-1", false); |
---|
190 | RegistryTestHelper.addComponentAnotherPrincipal(baseRegistry, "Ccomponent-1", false); |
---|
191 | RegistryTestHelper.addComponentAnotherPrincipal(baseRegistry, "Ccomponent-2", false); |
---|
192 | |
---|
193 | Ownership ownership = new Ownership(); |
---|
194 | ownership.setComponentId(ProfileDescription.PROFILE_PREFIX+"Cprofile-1"); |
---|
195 | ownership.setGroupId(3); |
---|
196 | ownership.setUserId(0); |
---|
197 | groupService.addOwnership(ownership); |
---|
198 | |
---|
199 | ownership.setComponentId(ComponentDescription.COMPONENT_PREFIX+"Ccomponent-1"); |
---|
200 | ownership.setGroupId(3); |
---|
201 | ownership.setUserId(0); |
---|
202 | groupService.addOwnership(ownership); |
---|
203 | |
---|
204 | ownership.setComponentId(ComponentDescription.COMPONENT_PREFIX+"Ccomponent-2"); |
---|
205 | ownership.setGroupId(3); |
---|
206 | ownership.setUserId(0); |
---|
207 | groupService.addOwnership(ownership); |
---|
208 | |
---|
209 | } |
---|
210 | |
---|
211 | // Response createNewGroup(String groupName) throws IOException; |
---|
212 | |
---|
213 | @Test |
---|
214 | public void testCreateNewGroup() { |
---|
215 | System.out.println("test createNewGroup"); |
---|
216 | ClientResponse cr = this.getAuthenticatedResource(getResource() |
---|
217 | .path("/registry/groups/create").queryParam("groupName", "newGroup")) |
---|
218 | .accept(MediaType.TEXT_XML).post(ClientResponse.class); |
---|
219 | assertEquals(200, cr.getStatus()); |
---|
220 | assertEquals("Group with the name newGroup is created and given an id 1", cr.getEntity(String.class)); |
---|
221 | } |
---|
222 | |
---|
223 | |
---|
224 | |
---|
225 | |
---|
226 | // List<Group> getGroupsOwnedByUser(String pricipalName) throws IOException; |
---|
227 | |
---|
228 | @Test |
---|
229 | public void testGetGroupsOwnedByUser() { |
---|
230 | System.out.println("test GetGroupsOwnedByUser"); |
---|
231 | ClientResponse cr = this.getAuthenticatedResource(getResource() |
---|
232 | .path("/registry/groups/create").queryParam("groupName", "newGroup1")) |
---|
233 | .accept(MediaType.TEXT_XML).post(ClientResponse.class); |
---|
234 | assertEquals(200, cr.getStatus()); |
---|
235 | ClientResponse cr1 = this.getAuthenticatedResource(getResource() |
---|
236 | .path("/registry/groups/create").queryParam("groupName", "newGroup2")) |
---|
237 | .accept(MediaType.TEXT_XML).post(ClientResponse.class); |
---|
238 | assertEquals(200, cr1.getStatus()); |
---|
239 | |
---|
240 | // test itself |
---|
241 | |
---|
242 | List<Group> result = this.getAuthenticatedResource(getResource() |
---|
243 | .path("/registry/groups/principal").queryParam("principalName", DummyPrincipal.DUMMY_PRINCIPAL.getName())) |
---|
244 | .accept(MediaType.APPLICATION_XML).get(GROUP_LIST_GENERICTYPE); |
---|
245 | |
---|
246 | assertEquals(2, result.size()); |
---|
247 | assertEquals("newGroup1", result.get(0).getName()); |
---|
248 | assertEquals("newGroup2", result.get(1).getName()); |
---|
249 | } |
---|
250 | |
---|
251 | |
---|
252 | // List<Group> getGroupsTheCurrentUserIsAMemberOf(); |
---|
253 | |
---|
254 | @Test |
---|
255 | public void testGetGroupsTheCurrentUserIsAMemberOf() throws ItemNotFoundException{ |
---|
256 | System.out.println("test getGroupsTheCurrentUserIsAMemberOfr"); |
---|
257 | |
---|
258 | MakeGroupA(); |
---|
259 | MakeGroupB(); |
---|
260 | // test itself |
---|
261 | |
---|
262 | List<Group> result = this.getAuthenticatedResource(getResource() |
---|
263 | .path("/registry/groups/usermembership")) |
---|
264 | .accept(MediaType.APPLICATION_XML).get(GROUP_LIST_GENERICTYPE); |
---|
265 | |
---|
266 | assertEquals(1, result.size()); |
---|
267 | assertEquals("group B", result.get(0).getName()); |
---|
268 | } |
---|
269 | // |
---|
270 | // List<Group> getGroupsTheItemIsAMemberOf(String itemId); |
---|
271 | |
---|
272 | @Test |
---|
273 | public void testGetGroupsTheItemIsAMemberOf() throws ParseException, JAXBException, ItemNotFoundException{ |
---|
274 | System.out.println("test getGroupsTheItemIsAMemberOf"); |
---|
275 | |
---|
276 | fillUpGroupA(); |
---|
277 | fillUpGroupB(); |
---|
278 | // test itself |
---|
279 | |
---|
280 | List<Group> result = this.getAuthenticatedResource(getResource() |
---|
281 | .path("/registry/items/"+ComponentDescription.COMPONENT_PREFIX+"component-1/groups")) |
---|
282 | .accept(MediaType.APPLICATION_XML).get(GROUP_LIST_GENERICTYPE); |
---|
283 | |
---|
284 | assertEquals(1, result.size()); |
---|
285 | assertEquals("group A", result.get(0).getName()); |
---|
286 | |
---|
287 | result = this.getAuthenticatedResource(getResource() |
---|
288 | .path("/registry/items/"+ComponentDescription.COMPONENT_PREFIX+"Bcomponent-1/groups")) |
---|
289 | .accept(MediaType.APPLICATION_XML).get(GROUP_LIST_GENERICTYPE); |
---|
290 | |
---|
291 | assertEquals(1, result.size()); |
---|
292 | assertEquals("group B", result.get(0).getName()); |
---|
293 | |
---|
294 | result = this.getAuthenticatedResource(getResource() |
---|
295 | .path("/registry/items/"+ProfileDescription.PROFILE_PREFIX+"Bprofile-1/groups")) |
---|
296 | .accept(MediaType.APPLICATION_XML).get(GROUP_LIST_GENERICTYPE); |
---|
297 | |
---|
298 | assertEquals(1, result.size()); |
---|
299 | assertEquals("group B", result.get(0).getName()); |
---|
300 | |
---|
301 | result = this.getAuthenticatedResource(getResource() |
---|
302 | .path("/registry/items/"+ProfileDescription.PROFILE_PREFIX+"profile-1/groups")) |
---|
303 | .accept(MediaType.APPLICATION_XML).get(GROUP_LIST_GENERICTYPE); |
---|
304 | |
---|
305 | assertEquals(1, result.size()); |
---|
306 | assertEquals("group A", result.get(0).getName()); |
---|
307 | } |
---|
308 | |
---|
309 | |
---|
310 | |
---|
311 | |
---|
312 | |
---|
313 | @Test |
---|
314 | public void testListGroupNames() throws ItemNotFoundException{ |
---|
315 | System.out.println("test listGroupNames"); |
---|
316 | |
---|
317 | MakeGroupA(); |
---|
318 | MakeGroupB(); |
---|
319 | |
---|
320 | // test itself |
---|
321 | |
---|
322 | ClientResponse cr = this.getAuthenticatedResource(getResource() |
---|
323 | .path("/registry/groups/names")).accept(MediaType.APPLICATION_XML).get(ClientResponse.class); |
---|
324 | assertEquals(200, cr.getStatus()); |
---|
325 | List<String> result = cr.getEntity(ComponentRegistryRestService.StringsWrapper.class).strings; |
---|
326 | assertEquals(2, result.size()); |
---|
327 | assertEquals("group A", result.get(0)); |
---|
328 | assertEquals("group B", result.get(1)); |
---|
329 | } |
---|
330 | |
---|
331 | // |
---|
332 | // Response isOwner(String groupName) throws IOException; |
---|
333 | |
---|
334 | @Test |
---|
335 | public void testIsOwner() throws ItemNotFoundException{ |
---|
336 | System.out.println("test isOwner"); |
---|
337 | |
---|
338 | MakeGroupA(); |
---|
339 | MakeGroupB(); |
---|
340 | |
---|
341 | // test itself |
---|
342 | |
---|
343 | ClientResponse cr = this.getAuthenticatedResource(getResource() |
---|
344 | .path("/registry/groups/ownership").queryParam("groupName", "group A")).accept(MediaType.APPLICATION_XML).get(ClientResponse.class); |
---|
345 | assertEquals(200, cr.getStatus()); |
---|
346 | String result = cr.getEntity(String.class); |
---|
347 | assertEquals("true", result); |
---|
348 | |
---|
349 | cr = this.getAuthenticatedResource(getResource() |
---|
350 | .path("/registry/groups/ownership").queryParam("groupName", "group B")).accept(MediaType.APPLICATION_XML).get(ClientResponse.class); |
---|
351 | assertEquals(200, cr.getStatus()); |
---|
352 | result = cr.getEntity(String.class); |
---|
353 | assertEquals("false", result); |
---|
354 | } |
---|
355 | |
---|
356 | |
---|
357 | // |
---|
358 | // Response makeGroupMember(String groupName, String principalName) throws IOException; |
---|
359 | |
---|
360 | @Test |
---|
361 | public void testMakeGroupMember() throws ItemNotFoundException{ |
---|
362 | System.out.println("test makeGroupMember"); |
---|
363 | |
---|
364 | MakeGroupA(); |
---|
365 | MakeGroupB(); |
---|
366 | // test itself |
---|
367 | |
---|
368 | //MultivaluedMap<String, String> params = new MultivaluedHashMap<String, String>(); |
---|
369 | ClientResponse cr = this.getAuthenticatedResource(getResource() |
---|
370 | .path("/registry/groups/makemember").queryParam("groupName", "group A").queryParam("principalName", "anotherPrincipal")).accept(MediaType.APPLICATION_XML).post(ClientResponse.class); |
---|
371 | assertEquals(200, cr.getStatus()); |
---|
372 | |
---|
373 | assertTrue(groupService.userGroupMember("anotherPrincipal", "1")); |
---|
374 | |
---|
375 | ; |
---|
376 | cr = this.getAuthenticatedResource(getResource() |
---|
377 | .path("/registry/groups/makemember").queryParam("groupName", "group B").queryParam("principalName", "anotherPrincipal")).accept(MediaType.APPLICATION_XML).post(ClientResponse.class); |
---|
378 | assertEquals(403, cr.getStatus()); |
---|
379 | } |
---|
380 | |
---|
381 | // |
---|
382 | // Response listProfiles(String groupId) throws IOException; |
---|
383 | |
---|
384 | @Test |
---|
385 | public void testListProfilesAndComponents() throws Exception{ |
---|
386 | System.out.println("test listProfilesAndComponents"); |
---|
387 | |
---|
388 | fillUpGroupA(); |
---|
389 | |
---|
390 | // test itself |
---|
391 | |
---|
392 | ClientResponse cr = this.getAuthenticatedResource(getResource() |
---|
393 | .path("/registry/groups/profiles").queryParam("groupId", "1")).accept(MediaType.APPLICATION_XML).get(ClientResponse.class); |
---|
394 | assertEquals(200, cr.getStatus()); |
---|
395 | List<String> result = cr.getEntity(ComponentRegistryRestService.StringsWrapper.class).strings; |
---|
396 | assertEquals(1, result.size()); |
---|
397 | assertEquals(ProfileDescription.PROFILE_PREFIX+"profile-1", result.get(0)); |
---|
398 | |
---|
399 | cr = this.getAuthenticatedResource(getResource() |
---|
400 | .path("/registry/groups/components").queryParam("groupId", "1")).accept(MediaType.APPLICATION_XML).get(ClientResponse.class); |
---|
401 | assertEquals(200, cr.getStatus()); |
---|
402 | result = cr.getEntity(ComponentRegistryRestService.StringsWrapper.class).strings; |
---|
403 | assertEquals(2, result.size()); |
---|
404 | assertEquals(ComponentDescription.COMPONENT_PREFIX+"component-1", result.get(0)); |
---|
405 | assertEquals(ComponentDescription.COMPONENT_PREFIX+"component-2", result.get(1)); |
---|
406 | } |
---|
407 | |
---|
408 | |
---|
409 | |
---|
410 | // |
---|
411 | // Response getGroupNameById(String groupId) throws IOException; |
---|
412 | |
---|
413 | @Test |
---|
414 | public void testGetGroupNamebyId() throws Exception{ |
---|
415 | System.out.println("test getGroupNamebyId"); |
---|
416 | |
---|
417 | MakeGroupA(); |
---|
418 | MakeGroupB(); |
---|
419 | // test itself |
---|
420 | |
---|
421 | ClientResponse cr = this.getAuthenticatedResource(getResource() |
---|
422 | .path("/registry/groups/nameById").queryParam("groupId", "1")).accept(MediaType.APPLICATION_XML).get(ClientResponse.class); |
---|
423 | assertEquals(200, cr.getStatus()); |
---|
424 | String result = cr.getEntity(String.class); |
---|
425 | assertEquals("group A", result); |
---|
426 | |
---|
427 | cr = this.getAuthenticatedResource(getResource() |
---|
428 | .path("/registry/groups/nameById").queryParam("groupId", "2")).accept(MediaType.APPLICATION_XML).get(ClientResponse.class); |
---|
429 | assertEquals(200, cr.getStatus()); |
---|
430 | result = cr.getEntity(String.class); |
---|
431 | assertEquals("group B", result); |
---|
432 | } |
---|
433 | |
---|
434 | // |
---|
435 | // Response getGroupIdByName(String groupName) throws IOException; |
---|
436 | |
---|
437 | @Test |
---|
438 | public void testGetIdByGroupName() throws Exception{ |
---|
439 | System.out.println("test getIdByGroupName"); |
---|
440 | |
---|
441 | MakeGroupA(); |
---|
442 | MakeGroupB(); |
---|
443 | // test itself |
---|
444 | |
---|
445 | ClientResponse cr = this.getAuthenticatedResource(getResource() |
---|
446 | .path("/registry/groups/idByName").queryParam("groupName", "group B")).accept(MediaType.APPLICATION_XML).get(ClientResponse.class); |
---|
447 | assertEquals(200, cr.getStatus()); |
---|
448 | String result = cr.getEntity(String.class); |
---|
449 | assertEquals("2", result); |
---|
450 | |
---|
451 | cr = this.getAuthenticatedResource(getResource() |
---|
452 | .path("/registry/groups/idByName").queryParam("groupName", "group A")).accept(MediaType.APPLICATION_XML).get(ClientResponse.class); |
---|
453 | assertEquals(200, cr.getStatus()); |
---|
454 | result = cr.getEntity(String.class); |
---|
455 | assertEquals("1", result); |
---|
456 | } |
---|
457 | |
---|
458 | |
---|
459 | // Response transferItemOwnershipToGroup(String itemId, long groupId) throws IOException; |
---|
460 | // |
---|
461 | |
---|
462 | @Test |
---|
463 | public void testTransferOwnership() throws Exception{ |
---|
464 | System.out.println("test makeTransferOwnership"); |
---|
465 | |
---|
466 | fillUpGroupA(); |
---|
467 | fillUpGroupB(); |
---|
468 | fillUpGroupC(); |
---|
469 | // test itself |
---|
470 | |
---|
471 | |
---|
472 | RegistryTestHelper.addComponent(baseRegistry, "test_component", false); |
---|
473 | RegistryTestHelper.addProfile(baseRegistry, "test_profile", false); |
---|
474 | String test_profile_id = ProfileDescription.PROFILE_PREFIX+"test_profile"; |
---|
475 | String test_component_id = ComponentDescription.COMPONENT_PREFIX+"test_component"; |
---|
476 | //I'm not a member |
---|
477 | ClientResponse cr = this.getAuthenticatedResource(getResource() |
---|
478 | .path("/registry/items/"+test_profile_id+"/transferownership").queryParam("groupId", "3")).accept(MediaType.APPLICATION_XML).post(ClientResponse.class); |
---|
479 | assertEquals(403, cr.getStatus()); |
---|
480 | |
---|
481 | //make me a member |
---|
482 | groupService.makeMember(DummyPrincipal.DUMMY_PRINCIPAL.getName(), "group C"); |
---|
483 | assertTrue(groupService.userGroupMember(DummyPrincipal.DUMMY_PRINCIPAL.getName(), "3")); |
---|
484 | |
---|
485 | cr = this.getAuthenticatedResource(getResource() |
---|
486 | .path("/registry/items/"+test_profile_id+"/transferownership").queryParam("groupId", "3")).accept(MediaType.APPLICATION_XML).post(ClientResponse.class); |
---|
487 | assertEquals(200, cr.getStatus()); |
---|
488 | cr = this.getAuthenticatedResource(getResource() |
---|
489 | .path("/registry/items/"+test_component_id+"/transferownership").queryParam("groupId", "3")).accept(MediaType.APPLICATION_XML).post(ClientResponse.class); |
---|
490 | assertEquals(200, cr.getStatus()); |
---|
491 | |
---|
492 | |
---|
493 | List<String> components = groupService.getComponentIdsInGroup(3); |
---|
494 | assertEquals(3, components.size()); |
---|
495 | assertEquals(test_component_id, components.get(2)); |
---|
496 | List<String> profiles = groupService.getProfileIdsInGroup(3); |
---|
497 | assertEquals(2, profiles.size()); |
---|
498 | assertEquals(test_profile_id, profiles.get(1)); |
---|
499 | |
---|
500 | } |
---|
501 | |
---|
502 | @Test |
---|
503 | public void testGetGroupProfilesAndComponents() throws Exception { |
---|
504 | |
---|
505 | System.out.println("test getGroupProfiles"); |
---|
506 | |
---|
507 | fillUpGroupA(); |
---|
508 | fillUpGroupB(); |
---|
509 | fillUpGroupC(); |
---|
510 | |
---|
511 | // lists |
---|
512 | |
---|
513 | List<ProfileDescription> response = this.getAuthenticatedResource(getResource() |
---|
514 | .path("/registry/profiles").queryParam("registrySpace", "group").queryParam("groupid", "1")).accept(MediaType.APPLICATION_XML) |
---|
515 | .get(PROFILE_LIST_GENERICTYPE); |
---|
516 | assertEquals(1, response.size()); |
---|
517 | |
---|
518 | List<ComponentDescription> responseC = this.getAuthenticatedResource(getResource() |
---|
519 | .path("/registry/components").queryParam("registrySpace", "group").queryParam("groupid", "1")).accept(MediaType.APPLICATION_XML) |
---|
520 | .get(COMPONENT_LIST_GENERICTYPE); |
---|
521 | assertEquals(2, responseC.size()); |
---|
522 | |
---|
523 | response = this.getAuthenticatedResource(getResource() |
---|
524 | .path("/registry/profiles").queryParam("registrySpace", "group").queryParam("groupid", "2")).accept(MediaType.APPLICATION_XML) |
---|
525 | .get(PROFILE_LIST_GENERICTYPE); |
---|
526 | assertEquals(1, response.size()); |
---|
527 | |
---|
528 | responseC = this.getAuthenticatedResource(getResource() |
---|
529 | .path("/registry/components").queryParam("registrySpace", "group").queryParam("groupid", "2")).accept(MediaType.APPLICATION_XML) |
---|
530 | .get(COMPONENT_LIST_GENERICTYPE); |
---|
531 | assertEquals(2, responseC.size()); |
---|
532 | |
---|
533 | ClientResponse clientResponse = this.getAuthenticatedResource(getResource() |
---|
534 | .path("/registry/components").queryParam("registrySpace", "group").queryParam("groupid", "3")).accept(MediaType.APPLICATION_XML) |
---|
535 | .get(ClientResponse.class); |
---|
536 | |
---|
537 | assertEquals(403, clientResponse.getStatus()); |
---|
538 | |
---|
539 | // particular components and profiles |
---|
540 | |
---|
541 | CMDComponentSpec component = this.getAuthenticatedResource(getResource() |
---|
542 | .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX+"profile-1")) |
---|
543 | .accept(MediaType.APPLICATION_JSON).get(CMDComponentSpec.class); |
---|
544 | assertNotNull(component); |
---|
545 | assertEquals("Actor", component.getCMDComponent().getName()); |
---|
546 | |
---|
547 | component = this.getAuthenticatedResource(getResource() |
---|
548 | .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX+"component-1")) |
---|
549 | .accept(MediaType.APPLICATION_JSON).get(CMDComponentSpec.class); |
---|
550 | assertNotNull(component); |
---|
551 | assertEquals("Access", component.getCMDComponent().getName()); |
---|
552 | |
---|
553 | component = this.getAuthenticatedResource(getResource() |
---|
554 | .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX+"Bprofile-1")) |
---|
555 | .accept(MediaType.APPLICATION_JSON).get(CMDComponentSpec.class); |
---|
556 | assertNotNull(component); |
---|
557 | assertEquals("Actor", component.getCMDComponent().getName()); |
---|
558 | |
---|
559 | component = this.getAuthenticatedResource(getResource() |
---|
560 | .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX+"Bcomponent-1")) |
---|
561 | .accept(MediaType.APPLICATION_JSON).get(CMDComponentSpec.class); |
---|
562 | assertNotNull(component); |
---|
563 | assertEquals("Access", component.getCMDComponent().getName()); |
---|
564 | |
---|
565 | clientResponse = this.getAuthenticatedResource(getResource() |
---|
566 | .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX+"Cprofile-1")) |
---|
567 | .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); |
---|
568 | assertEquals(403, clientResponse.getStatus()); |
---|
569 | |
---|
570 | clientResponse = this.getAuthenticatedResource(getResource() |
---|
571 | .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX+"Ccomponent-1")) |
---|
572 | .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); |
---|
573 | assertEquals(403, clientResponse.getStatus()); |
---|
574 | |
---|
575 | } |
---|
576 | |
---|
577 | @Test |
---|
578 | public void testGetGroupComments() throws Exception { |
---|
579 | |
---|
580 | System.out.println("test getGroupComments"); |
---|
581 | |
---|
582 | fillUpGroupA(); |
---|
583 | fillUpGroupB(); |
---|
584 | fillUpGroupC(); |
---|
585 | |
---|
586 | |
---|
587 | RegistryTestHelper.addComment(baseRegistry, "COMMENTc1", ComponentDescription.COMPONENT_PREFIX + "component-1", |
---|
588 | "JUnit@test.com"); |
---|
589 | RegistryTestHelper.addComment(baseRegistry, "COMMENTp1", ProfileDescription.PROFILE_PREFIX + "profile-1", |
---|
590 | "JUnit@test.com"); |
---|
591 | RegistryTestHelper.addComment(baseRegistry, "COMMENTBc1", ComponentDescription.COMPONENT_PREFIX + "Bcomponent-1", |
---|
592 | "anotherPrincipal"); |
---|
593 | RegistryTestHelper.addComment(baseRegistry, "COMMENTBp1", ProfileDescription.PROFILE_PREFIX + "Bprofile-1", |
---|
594 | "anotherPrincipal"); |
---|
595 | (new RegistryTestHelper()).addCommentBypassAuthorisation(commentsDao, "COMMENTCc1", ComponentDescription.COMPONENT_PREFIX + "Ccomponent-1", |
---|
596 | "anotherPrincipal"); |
---|
597 | (new RegistryTestHelper()).addCommentBypassAuthorisation(commentsDao, "COMMENTCp1", ProfileDescription.PROFILE_PREFIX + "Cprofile-1","anotherPrincipal"); |
---|
598 | |
---|
599 | |
---|
600 | // lists |
---|
601 | |
---|
602 | List<Comment> response = this.getAuthenticatedResource(getResource() |
---|
603 | .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX + "component-1" + "/comments/")) |
---|
604 | .accept(MediaType.APPLICATION_XML) |
---|
605 | .get(COMMENT_LIST_GENERICTYPE); |
---|
606 | assertEquals(1, response.size()); |
---|
607 | |
---|
608 | response = this.getAuthenticatedResource(getResource() |
---|
609 | .path("/registry/components/" + ProfileDescription.PROFILE_PREFIX + "profile-1" + "/comments/")) |
---|
610 | .accept(MediaType.APPLICATION_XML) |
---|
611 | .get(COMMENT_LIST_GENERICTYPE); |
---|
612 | assertEquals(1, response.size()); |
---|
613 | |
---|
614 | response = this.getAuthenticatedResource(getResource() |
---|
615 | .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX + "Bcomponent-1" + "/comments/")) |
---|
616 | .accept(MediaType.APPLICATION_XML) |
---|
617 | .get(COMMENT_LIST_GENERICTYPE); |
---|
618 | assertEquals(1, response.size()); |
---|
619 | |
---|
620 | response = this.getAuthenticatedResource(getResource() |
---|
621 | .path("/registry/components/" + ProfileDescription.PROFILE_PREFIX + "Bprofile-1" + "/comments/")) |
---|
622 | .accept(MediaType.APPLICATION_XML) |
---|
623 | .get(COMMENT_LIST_GENERICTYPE); |
---|
624 | assertEquals(1, response.size()); |
---|
625 | |
---|
626 | |
---|
627 | |
---|
628 | ClientResponse clientResponse = this.getAuthenticatedResource(getResource() |
---|
629 | .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX+"Cprofile-1")) |
---|
630 | .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); |
---|
631 | assertEquals(403, clientResponse.getStatus()); |
---|
632 | |
---|
633 | clientResponse = this.getAuthenticatedResource(getResource() |
---|
634 | .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX+"Ccomponent-1")) |
---|
635 | .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); |
---|
636 | assertEquals(403, clientResponse.getStatus()); |
---|
637 | |
---|
638 | // particular comments |
---|
639 | |
---|
640 | Comment responseComment = this.getAuthenticatedResource(getResource() |
---|
641 | .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX + "component-1" + "/comments/1")) |
---|
642 | .accept(MediaType.APPLICATION_XML) |
---|
643 | .get(Comment.class); |
---|
644 | assertNotNull(responseComment); |
---|
645 | |
---|
646 | assertEquals(1, Long.parseLong(responseComment.getId())); |
---|
647 | |
---|
648 | responseComment = this.getAuthenticatedResource(getResource() |
---|
649 | .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX + "profile-1" + "/comments/2")) |
---|
650 | .accept(MediaType.APPLICATION_XML) |
---|
651 | .get(Comment.class); |
---|
652 | assertNotNull(responseComment); |
---|
653 | |
---|
654 | assertEquals(2, Long.parseLong(responseComment.getId())); |
---|
655 | |
---|
656 | responseComment = this.getAuthenticatedResource(getResource() |
---|
657 | .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX + "Bcomponent-1" + "/comments/3")) |
---|
658 | .accept(MediaType.APPLICATION_XML) |
---|
659 | .get(Comment.class); |
---|
660 | assertNotNull(responseComment); |
---|
661 | assertEquals(3, Long.parseLong(responseComment.getId())); |
---|
662 | |
---|
663 | responseComment = this.getAuthenticatedResource(getResource() |
---|
664 | .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX + "Bprofile-1" + "/comments/4")) |
---|
665 | .accept(MediaType.APPLICATION_XML) |
---|
666 | .get(Comment.class); |
---|
667 | assertNotNull(responseComment); |
---|
668 | assertEquals(4, Long.parseLong(responseComment.getId())); |
---|
669 | |
---|
670 | clientResponse = this.getAuthenticatedResource(getResource() |
---|
671 | .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX+"Cprofile-1/comments/6")) |
---|
672 | .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); |
---|
673 | assertEquals(403, clientResponse.getStatus()); |
---|
674 | |
---|
675 | clientResponse = this.getAuthenticatedResource(getResource() |
---|
676 | .path("/registry/components/" + ComponentDescription.COMPONENT_PREFIX+"Ccomponent-1/comments/5")) |
---|
677 | .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); |
---|
678 | assertEquals(403, clientResponse.getStatus()); |
---|
679 | |
---|
680 | } |
---|
681 | |
---|
682 | } |
---|