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