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