1 | package clarin.cmdi.componentregistry.rest; |
---|
2 | |
---|
3 | import clarin.cmdi.componentregistry.ComponentRegistry; |
---|
4 | import clarin.cmdi.componentregistry.ComponentRegistryFactory; |
---|
5 | import clarin.cmdi.componentregistry.components.CMDComponentSpec; |
---|
6 | import clarin.cmdi.componentregistry.components.CMDComponentType; |
---|
7 | import clarin.cmdi.componentregistry.impl.database.ComponentRegistryBeanFactory; |
---|
8 | import clarin.cmdi.componentregistry.impl.database.ComponentRegistryTestDatabase; |
---|
9 | import clarin.cmdi.componentregistry.model.BaseDescription; |
---|
10 | import clarin.cmdi.componentregistry.model.Comment; |
---|
11 | import clarin.cmdi.componentregistry.model.CommentResponse; |
---|
12 | import clarin.cmdi.componentregistry.model.ComponentDescription; |
---|
13 | import clarin.cmdi.componentregistry.model.ProfileDescription; |
---|
14 | import clarin.cmdi.componentregistry.model.RegisterResponse; |
---|
15 | import static clarin.cmdi.componentregistry.rest.ComponentRegistryRestService.REGISTRY_SPACE_PARAM; |
---|
16 | |
---|
17 | import com.sun.jersey.api.client.ClientResponse; |
---|
18 | import com.sun.jersey.api.client.UniformInterfaceException; |
---|
19 | import com.sun.jersey.api.representation.Form; |
---|
20 | import com.sun.jersey.multipart.FormDataMultiPart; |
---|
21 | |
---|
22 | import java.io.ByteArrayInputStream; |
---|
23 | import java.util.ArrayList; |
---|
24 | import java.util.Date; |
---|
25 | import java.util.List; |
---|
26 | import javax.ws.rs.WebApplicationException; |
---|
27 | |
---|
28 | import javax.ws.rs.core.MediaType; |
---|
29 | import javax.ws.rs.core.Response.Status; |
---|
30 | |
---|
31 | import static org.junit.Assert.*; |
---|
32 | |
---|
33 | import org.junit.Before; |
---|
34 | import org.junit.Ignore; |
---|
35 | import org.junit.Test; |
---|
36 | import org.springframework.beans.factory.annotation.Autowired; |
---|
37 | import org.springframework.jdbc.core.JdbcTemplate; |
---|
38 | import org.springframework.util.Assert; |
---|
39 | |
---|
40 | /** |
---|
41 | * Launches a servlet container environment and performs HTTP calls to the |
---|
42 | * {@link ComponentRegistryRestService} |
---|
43 | * |
---|
44 | * @author george.georgovassilis@mpi.nl |
---|
45 | * |
---|
46 | */ |
---|
47 | public class ComponentRegistryRestServiceTest extends ComponentRegistryRestServiceTestCase { |
---|
48 | |
---|
49 | @Autowired |
---|
50 | private ComponentRegistryFactory componentRegistryFactory; |
---|
51 | @Autowired |
---|
52 | private ComponentRegistryBeanFactory componentRegistryBeanFactory; |
---|
53 | @Autowired |
---|
54 | private JdbcTemplate jdbcTemplate; |
---|
55 | private ComponentRegistry baseRegistry; |
---|
56 | |
---|
57 | @Before |
---|
58 | public void init() { |
---|
59 | ComponentRegistryTestDatabase.resetAndCreateAllTables(jdbcTemplate); |
---|
60 | createUserRecord(); |
---|
61 | baseRegistry = componentRegistryFactory.getBaseRegistry(DummyPrincipal.DUMMY_CREDENTIALS); |
---|
62 | } |
---|
63 | |
---|
64 | private String expectedUserId(String principal) { |
---|
65 | return getUserDao().getByPrincipalName(principal).getId().toString(); |
---|
66 | } |
---|
67 | private ComponentDescription component1; |
---|
68 | private ComponentDescription component2; |
---|
69 | private ProfileDescription profile1; |
---|
70 | private ProfileDescription profile2; |
---|
71 | private ComponentDescription component3; |
---|
72 | private ProfileDescription profile3; |
---|
73 | private Comment profile1Comment1; |
---|
74 | private Comment profile1Comment2; |
---|
75 | private Comment component1Comment3; |
---|
76 | private Comment component1Comment4; |
---|
77 | private Comment profile3Comment5; |
---|
78 | private Comment component3Comment7; |
---|
79 | |
---|
80 | private void fillUpPublicItems() throws Exception { |
---|
81 | |
---|
82 | profile1 = RegistryTestHelper.addProfile(baseRegistry, "profile2", true); |
---|
83 | profile2 = RegistryTestHelper.addProfile(baseRegistry, "profile1", true); |
---|
84 | component1 = RegistryTestHelper.addComponent(baseRegistry, |
---|
85 | "component2", true); |
---|
86 | component2 = RegistryTestHelper.addComponent(baseRegistry, |
---|
87 | "component1", true); |
---|
88 | profile1Comment2 = RegistryTestHelper.addComment(baseRegistry, "comment2", |
---|
89 | ProfileDescription.PROFILE_PREFIX + "profile1", |
---|
90 | "JUnit@test.com"); |
---|
91 | profile1Comment1 = RegistryTestHelper.addComment(baseRegistry, "comment1", |
---|
92 | ProfileDescription.PROFILE_PREFIX + "profile1", |
---|
93 | "JUnit@test.com"); |
---|
94 | component1Comment3 = RegistryTestHelper.addComment(baseRegistry, "comment3", |
---|
95 | ComponentDescription.COMPONENT_PREFIX + "component1", |
---|
96 | "JUnit@test.com"); |
---|
97 | component1Comment4 = RegistryTestHelper.addComment(baseRegistry, "comment4", |
---|
98 | ComponentDescription.COMPONENT_PREFIX + "component1", |
---|
99 | "JUnit@test.com"); |
---|
100 | } |
---|
101 | |
---|
102 | private void fillUpPrivateItems() throws Exception { |
---|
103 | profile3 = RegistryTestHelper.addProfile(baseRegistry, "profile3", false); |
---|
104 | component3 = RegistryTestHelper.addComponent(baseRegistry, |
---|
105 | "component3", false); |
---|
106 | profile3Comment5 = RegistryTestHelper.addComment(baseRegistry, "comment5", |
---|
107 | ProfileDescription.PROFILE_PREFIX + "profile3", |
---|
108 | "JUnit@test.com"); |
---|
109 | component3Comment7 = RegistryTestHelper.addComment(baseRegistry, "comment7", |
---|
110 | ComponentDescription.COMPONENT_PREFIX + "component3", |
---|
111 | "JUnit@test.com"); |
---|
112 | } |
---|
113 | |
---|
114 | @Test |
---|
115 | public void testGetPublicProfiles() throws Exception { |
---|
116 | |
---|
117 | System.out.println("testGetPublicProfiles"); |
---|
118 | |
---|
119 | fillUpPublicItems(); |
---|
120 | |
---|
121 | RegistryTestHelper.addProfile(baseRegistry, "PROFILE2", true); |
---|
122 | List<ProfileDescription> response = this.getAuthenticatedResource(getResource() |
---|
123 | .path("/registry/profiles")).accept(MediaType.APPLICATION_XML) |
---|
124 | .get(PROFILE_LIST_GENERICTYPE); |
---|
125 | assertEquals(3, response.size()); |
---|
126 | response = this.getAuthenticatedResource(getResource() |
---|
127 | .path("/registry/profiles")) |
---|
128 | .accept(MediaType.APPLICATION_JSON) |
---|
129 | .get(PROFILE_LIST_GENERICTYPE); |
---|
130 | assertEquals(3, response.size()); |
---|
131 | assertEquals("profile1", response.get(0).getName()); |
---|
132 | assertEquals("PROFILE2", response.get(1).getName()); |
---|
133 | assertEquals("profile2", response.get(2).getName()); |
---|
134 | } |
---|
135 | |
---|
136 | @Test //ok |
---|
137 | public void testGetPublicComponents() throws Exception { |
---|
138 | |
---|
139 | System.out.println("testGetPublicComponents"); |
---|
140 | |
---|
141 | fillUpPublicItems(); |
---|
142 | |
---|
143 | RegistryTestHelper.addComponent(baseRegistry, "COMPONENT2", true); |
---|
144 | List<ComponentDescription> response = this.getAuthenticatedResource(getResource() |
---|
145 | .path("/registry/components")).accept(MediaType.APPLICATION_XML) |
---|
146 | .get(COMPONENT_LIST_GENERICTYPE); |
---|
147 | assertEquals(3, response.size()); |
---|
148 | response = this.getAuthenticatedResource(getResource() |
---|
149 | .path("/registry/components")) |
---|
150 | .accept(MediaType.APPLICATION_JSON) |
---|
151 | .get(COMPONENT_LIST_GENERICTYPE); |
---|
152 | assertEquals(3, response.size()); |
---|
153 | assertEquals("component1", response.get(0).getName()); |
---|
154 | assertEquals("COMPONENT2", response.get(1).getName()); |
---|
155 | assertEquals("component2", response.get(2).getName()); |
---|
156 | } |
---|
157 | |
---|
158 | @Test //ok |
---|
159 | public void testGetUserComponents() throws Exception { |
---|
160 | |
---|
161 | System.out.println("testGetUserComponents"); |
---|
162 | |
---|
163 | fillUpPrivateItems(); |
---|
164 | |
---|
165 | List<ComponentDescription> response = this.getUserComponents(); |
---|
166 | assertEquals(1, response.size()); |
---|
167 | |
---|
168 | //// |
---|
169 | |
---|
170 | fillUpPublicItems(); |
---|
171 | response = getAuthenticatedResource(getResource().path("/registry/components")).accept( |
---|
172 | MediaType.APPLICATION_JSON).get(COMPONENT_LIST_GENERICTYPE); |
---|
173 | assertEquals("Get public components", 2, response.size()); |
---|
174 | |
---|
175 | ClientResponse cResponse = getResource().path("/registry/components") |
---|
176 | .queryParam(REGISTRY_SPACE_PARAM, "private") |
---|
177 | .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); |
---|
178 | assertEquals("Trying to get userspace without credentials", 401, |
---|
179 | cResponse.getStatus()); |
---|
180 | } |
---|
181 | |
---|
182 | @Test //ok |
---|
183 | public void testGetPublicComponent() throws Exception { |
---|
184 | |
---|
185 | System.out.println("testGetPublicComponents"); |
---|
186 | |
---|
187 | fillUpPublicItems(); |
---|
188 | |
---|
189 | String id = ComponentDescription.COMPONENT_PREFIX + "component1"; |
---|
190 | String id2 = ComponentDescription.COMPONENT_PREFIX + "component2"; |
---|
191 | CMDComponentSpec component = this.getAuthenticatedResource(getResource() |
---|
192 | .path("/registry/components/" + id)) |
---|
193 | .accept(MediaType.APPLICATION_JSON).get(CMDComponentSpec.class); |
---|
194 | assertNotNull(component); |
---|
195 | assertEquals("Access", component.getCMDComponent().getName()); |
---|
196 | |
---|
197 | |
---|
198 | component = this.getAuthenticatedResource(getResource().path("/registry/components/" + id2)) |
---|
199 | .accept(MediaType.APPLICATION_XML).get(CMDComponentSpec.class); |
---|
200 | assertNotNull(component); |
---|
201 | assertEquals("Access", component.getCMDComponent().getName()); |
---|
202 | assertEquals(id2, component.getHeader().getID()); |
---|
203 | assertEquals("component2", component.getHeader().getName()); |
---|
204 | assertEquals("Test Description", component.getHeader().getDescription()); |
---|
205 | } |
---|
206 | |
---|
207 | @Test // ok |
---|
208 | public void testGetCommentsInPublicProfile() throws Exception { |
---|
209 | |
---|
210 | System.out.println("testGetCommentsInPublicPrfile"); |
---|
211 | |
---|
212 | fillUpPublicItems(); |
---|
213 | |
---|
214 | String id = ProfileDescription.PROFILE_PREFIX + "profile1"; |
---|
215 | RegistryTestHelper.addComment(baseRegistry, "COMMENT1", id, |
---|
216 | "JUnit@test.com"); |
---|
217 | List<Comment> response = this.getAuthenticatedResource(getResource() |
---|
218 | .path("/registry/profiles/" + id + "/comments/")) |
---|
219 | .accept(MediaType.APPLICATION_XML) |
---|
220 | .get(COMMENT_LIST_GENERICTYPE); |
---|
221 | assertEquals(3, response.size()); |
---|
222 | |
---|
223 | response = this.getAuthenticatedResource(getResource().path("/registry/profiles/" + id + "/comments")) |
---|
224 | .accept(MediaType.APPLICATION_JSON) |
---|
225 | .get(COMMENT_LIST_GENERICTYPE); |
---|
226 | assertEquals(3, response.size()); |
---|
227 | assertEquals("comment2", response.get(0).getComment()); |
---|
228 | assertEquals("comment1", response.get(1).getComment()); |
---|
229 | assertEquals("COMMENT1", response.get(2).getComment()); |
---|
230 | |
---|
231 | assertEquals("Database test user", response.get(0).getUserName()); |
---|
232 | } |
---|
233 | |
---|
234 | @Test // ok |
---|
235 | public void testGetCommentsInPubliComponent() throws Exception { |
---|
236 | |
---|
237 | System.out.println("testGetCoomentsInPublicComponent"); |
---|
238 | |
---|
239 | fillUpPublicItems(); |
---|
240 | |
---|
241 | String id = ComponentDescription.COMPONENT_PREFIX + "component1"; |
---|
242 | RegistryTestHelper.addComment(baseRegistry, "COMMENT2", id, |
---|
243 | "JUnit@test.com"); |
---|
244 | List<Comment> response = this.getAuthenticatedResource(getResource() |
---|
245 | .path("/registry/components/" + id + "/comments/")) |
---|
246 | .accept(MediaType.APPLICATION_XML) |
---|
247 | .get(COMMENT_LIST_GENERICTYPE); |
---|
248 | assertEquals(3, response.size()); |
---|
249 | response = this.getAuthenticatedResource(getResource() |
---|
250 | .path("/registry/components/" + id + "/comments")) |
---|
251 | .accept(MediaType.APPLICATION_JSON) |
---|
252 | .get(COMMENT_LIST_GENERICTYPE); |
---|
253 | assertEquals(3, response.size()); |
---|
254 | assertEquals("comment3", response.get(0).getComment()); |
---|
255 | assertEquals("comment4", response.get(1).getComment()); |
---|
256 | assertEquals("COMMENT2", response.get(2).getComment()); |
---|
257 | |
---|
258 | assertEquals("Database test user", response.get(0).getUserName()); |
---|
259 | } |
---|
260 | |
---|
261 | @Test // ok |
---|
262 | public void testGetSpecifiedCommentInPublicComponent() throws Exception { |
---|
263 | |
---|
264 | System.out.println("testSpecifiedCommentInPublicComponent"); |
---|
265 | |
---|
266 | fillUpPublicItems(); |
---|
267 | |
---|
268 | String id = ComponentDescription.COMPONENT_PREFIX + "component1"; |
---|
269 | Comment comment = this.getAuthenticatedResource(getResource() |
---|
270 | .path("/registry/components/" + id + "/comments/" + component1Comment3.getId())) |
---|
271 | .accept(MediaType.APPLICATION_JSON).get(Comment.class); |
---|
272 | assertNotNull(comment); |
---|
273 | assertEquals("comment3", comment.getComment()); |
---|
274 | assertEquals(component1Comment3.getId(), comment.getId()); |
---|
275 | comment = this.getAuthenticatedResource(getResource() |
---|
276 | .path("/registry/components/" + id + "/comments/" + component1Comment4.getId())) |
---|
277 | .accept(MediaType.APPLICATION_JSON).get(Comment.class); |
---|
278 | assertNotNull(comment); |
---|
279 | assertEquals("comment4", comment.getComment()); |
---|
280 | assertEquals(component1Comment4.getId(), comment.getId()); |
---|
281 | assertEquals(id, comment.getComponentId()); |
---|
282 | } |
---|
283 | |
---|
284 | @Test //ok |
---|
285 | public void testGetSpecifiedCommentInPublicProfile() throws Exception { |
---|
286 | |
---|
287 | System.out.println("testGetSpecifiedCoomentInPublicProfile"); |
---|
288 | |
---|
289 | fillUpPublicItems(); |
---|
290 | |
---|
291 | String id = ProfileDescription.PROFILE_PREFIX + "profile1"; |
---|
292 | Comment comment = this.getAuthenticatedResource(getResource() |
---|
293 | .path("/registry/profiles/" + id + "/comments/" + profile1Comment2.getId())) |
---|
294 | .accept(MediaType.APPLICATION_JSON).get(Comment.class); |
---|
295 | assertNotNull(comment); |
---|
296 | assertEquals("comment2", comment.getComment()); |
---|
297 | assertEquals(profile1Comment2.getId(), comment.getId()); |
---|
298 | |
---|
299 | comment = this.getAuthenticatedResource(getResource() |
---|
300 | .path("/registry/profiles/" + id + "/comments/" + profile1Comment1.getId())) |
---|
301 | .accept(MediaType.APPLICATION_JSON).get(Comment.class); |
---|
302 | assertNotNull(comment); |
---|
303 | assertEquals("comment1", comment.getComment()); |
---|
304 | assertEquals(profile1Comment1.getId(), comment.getId()); |
---|
305 | assertEquals(id, comment.getComponentId()); |
---|
306 | } |
---|
307 | |
---|
308 | @Test //ok |
---|
309 | public void testDeleteCommentFromPublicComponent() throws Exception { |
---|
310 | |
---|
311 | System.out.println("testDeleteCommentFromPublicComponent"); |
---|
312 | |
---|
313 | fillUpPublicItems(); |
---|
314 | |
---|
315 | String id = ComponentDescription.COMPONENT_PREFIX + "component1"; |
---|
316 | String id2 = ComponentDescription.COMPONENT_PREFIX + "component2"; |
---|
317 | List<Comment> comments = this.getAuthenticatedResource(getResource().path( |
---|
318 | "/registry/components/" + id + "/comments")).get( |
---|
319 | COMMENT_LIST_GENERICTYPE); |
---|
320 | assertEquals(2, comments.size()); |
---|
321 | Comment aComment = this.getAuthenticatedResource(getResource().path( |
---|
322 | "/registry/components/" + id + "/comments/" + component1Comment3.getId())) |
---|
323 | .get(Comment.class); |
---|
324 | assertNotNull(aComment); |
---|
325 | |
---|
326 | // Try to delete from other component |
---|
327 | ClientResponse response = getAuthenticatedResource( |
---|
328 | "/registry/components/" + id2 + "/comments/" + component1Comment4.getId()).delete( |
---|
329 | ClientResponse.class); |
---|
330 | assertEquals(404, response.getStatus()); |
---|
331 | // Delete from correct component |
---|
332 | response = getAuthenticatedResource( |
---|
333 | "/registry/components/" + id + "/comments/" + component1Comment3.getId()).delete( |
---|
334 | ClientResponse.class); |
---|
335 | assertEquals(200, response.getStatus()); |
---|
336 | |
---|
337 | comments = this.getAuthenticatedResource(getResource().path( |
---|
338 | "/registry/components/" + id + "/comments/")).get( |
---|
339 | COMMENT_LIST_GENERICTYPE); |
---|
340 | assertEquals(1, comments.size()); |
---|
341 | |
---|
342 | response = getAuthenticatedResource( |
---|
343 | "/registry/components/" + id + "/comments/" + component1Comment4.getId()).delete( |
---|
344 | ClientResponse.class); |
---|
345 | assertEquals(200, response.getStatus()); |
---|
346 | |
---|
347 | comments = this.getAuthenticatedResource(getResource().path( |
---|
348 | "/registry/components/" + id + "/comments")).get( |
---|
349 | COMMENT_LIST_GENERICTYPE); |
---|
350 | assertEquals(0, comments.size()); |
---|
351 | } |
---|
352 | |
---|
353 | @Test |
---|
354 | public void testManipulateCommentFromPublicComponent() throws Exception { |
---|
355 | |
---|
356 | System.out.println("testManipulateCommentFromPublicComponent"); |
---|
357 | |
---|
358 | fillUpPublicItems(); |
---|
359 | |
---|
360 | List<Comment> comments = this.getAuthenticatedResource(getResource().path( |
---|
361 | "/registry/components/" + ComponentDescription.COMPONENT_PREFIX |
---|
362 | + "component1/comments")).get(COMMENT_LIST_GENERICTYPE); |
---|
363 | assertEquals(2, comments.size()); |
---|
364 | Comment aComment = this.getAuthenticatedResource(getResource().path( |
---|
365 | "/registry/components/" + ComponentDescription.COMPONENT_PREFIX |
---|
366 | + "component1/comments/" + component1Comment3.getId())).get(Comment.class); |
---|
367 | assertNotNull(aComment); |
---|
368 | |
---|
369 | Form manipulateForm = new Form(); |
---|
370 | manipulateForm.add("method", "delete"); |
---|
371 | |
---|
372 | // Try to delete from other component |
---|
373 | ClientResponse response = getAuthenticatedResource( |
---|
374 | "/registry/components/" + ComponentDescription.COMPONENT_PREFIX |
---|
375 | + "component1/comments/" + component1Comment3.getId()).post(ClientResponse.class, |
---|
376 | manipulateForm); |
---|
377 | assertEquals(200, response.getStatus()); |
---|
378 | |
---|
379 | comments = this.getAuthenticatedResource(getResource().path( |
---|
380 | "/registry/components/" + ComponentDescription.COMPONENT_PREFIX |
---|
381 | + "component1/comments/")).get(COMMENT_LIST_GENERICTYPE); |
---|
382 | assertEquals(1, comments.size()); |
---|
383 | } |
---|
384 | |
---|
385 | @Test |
---|
386 | public void testDeleteCommentFromPublicProfile() throws Exception { |
---|
387 | |
---|
388 | System.out.println("testDeleteCommentFromPublicProfile"); |
---|
389 | |
---|
390 | fillUpPublicItems(); |
---|
391 | |
---|
392 | List<Comment> comments = this.getAuthenticatedResource(getResource().path( |
---|
393 | "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX |
---|
394 | + "profile1/comments")).get(COMMENT_LIST_GENERICTYPE); |
---|
395 | assertEquals(2, comments.size()); |
---|
396 | Comment aComment = this.getAuthenticatedResource(getResource().path( |
---|
397 | "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX |
---|
398 | + "profile1/comments/" + profile1Comment1.getId())).get(Comment.class); |
---|
399 | assertNotNull(aComment); |
---|
400 | |
---|
401 | // Try to delete from other profile |
---|
402 | ClientResponse response = getAuthenticatedResource( |
---|
403 | "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX |
---|
404 | + "profile2/comments/9999").delete(ClientResponse.class); |
---|
405 | assertEquals(404, response.getStatus()); |
---|
406 | // Delete from correct profile |
---|
407 | response = getAuthenticatedResource( |
---|
408 | "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX |
---|
409 | + "profile1/comments/" + profile1Comment1.getId()).delete(ClientResponse.class); |
---|
410 | assertEquals(200, response.getStatus()); |
---|
411 | |
---|
412 | comments = this.getAuthenticatedResource(getResource().path( |
---|
413 | "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX |
---|
414 | + "profile1/comments/")).get(COMMENT_LIST_GENERICTYPE); |
---|
415 | assertEquals(1, comments.size()); |
---|
416 | |
---|
417 | response = getAuthenticatedResource( |
---|
418 | "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX |
---|
419 | + "profile1/comments/" + profile1Comment2.getId()).delete(ClientResponse.class); |
---|
420 | assertEquals(200, response.getStatus()); |
---|
421 | |
---|
422 | comments = this.getAuthenticatedResource(getResource().path( |
---|
423 | "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX |
---|
424 | + "profile1/comments")).get(COMMENT_LIST_GENERICTYPE); |
---|
425 | assertEquals(0, comments.size()); |
---|
426 | } |
---|
427 | |
---|
428 | @Test |
---|
429 | public void testManipulateCommentFromPublicProfile() throws Exception { |
---|
430 | |
---|
431 | System.out.println("testManipulatreCommentFromPublicProfile"); |
---|
432 | |
---|
433 | fillUpPublicItems(); |
---|
434 | |
---|
435 | List<Comment> comments = this.getAuthenticatedResource(getResource().path( |
---|
436 | "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX |
---|
437 | + "profile1/comments")).get(COMMENT_LIST_GENERICTYPE); |
---|
438 | assertEquals(2, comments.size()); |
---|
439 | Comment aComment = this.getAuthenticatedResource(getResource().path( |
---|
440 | "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX |
---|
441 | + "profile1/comments/" + profile1Comment2.getId())).get(Comment.class); |
---|
442 | assertNotNull(aComment); |
---|
443 | |
---|
444 | Form manipulateForm = new Form(); |
---|
445 | manipulateForm.add("method", "delete"); |
---|
446 | // Delete from correct profile |
---|
447 | ClientResponse response = getAuthenticatedResource( |
---|
448 | "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX |
---|
449 | + "profile1/comments/" + profile1Comment2.getId()).post(ClientResponse.class, |
---|
450 | manipulateForm); |
---|
451 | assertEquals(200, response.getStatus()); |
---|
452 | |
---|
453 | comments = this.getAuthenticatedResource(getResource().path( |
---|
454 | "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX |
---|
455 | + "profile1/comments/")).get(COMMENT_LIST_GENERICTYPE); |
---|
456 | assertEquals(1, comments.size()); |
---|
457 | } |
---|
458 | |
---|
459 | @Test |
---|
460 | public void testDeletePublicComponent() throws Exception { |
---|
461 | |
---|
462 | System.out.println("testDeletePublicComponent"); |
---|
463 | |
---|
464 | fillUpPublicItems(); |
---|
465 | |
---|
466 | List<ComponentDescription> components = this.getAuthenticatedResource(getResource().path( |
---|
467 | "/registry/components")).get(COMPONENT_LIST_GENERICTYPE); |
---|
468 | assertEquals(2, components.size()); |
---|
469 | CMDComponentSpec profile = this.getAuthenticatedResource(getResource().path( |
---|
470 | "/registry/components/" + ComponentDescription.COMPONENT_PREFIX |
---|
471 | + "component1")).get(CMDComponentSpec.class); |
---|
472 | assertNotNull(profile); |
---|
473 | ClientResponse response = getAuthenticatedResource( |
---|
474 | "/registry/components/" + ComponentDescription.COMPONENT_PREFIX |
---|
475 | + "component1").delete(ClientResponse.class); |
---|
476 | assertEquals(200, response.getStatus()); |
---|
477 | |
---|
478 | components = this.getAuthenticatedResource(getResource().path("/registry/components")).get( |
---|
479 | COMPONENT_LIST_GENERICTYPE); |
---|
480 | assertEquals(1, components.size()); |
---|
481 | |
---|
482 | response = getAuthenticatedResource( |
---|
483 | "/registry/components/" + ComponentDescription.COMPONENT_PREFIX |
---|
484 | + "component2").delete(ClientResponse.class); |
---|
485 | assertEquals(200, response.getStatus()); |
---|
486 | |
---|
487 | components = this.getAuthenticatedResource(getResource().path("/registry/components")).get( |
---|
488 | COMPONENT_LIST_GENERICTYPE); |
---|
489 | assertEquals(0, components.size()); |
---|
490 | |
---|
491 | response = getAuthenticatedResource( |
---|
492 | "/registry/components/" + ComponentDescription.COMPONENT_PREFIX |
---|
493 | + "component1").delete(ClientResponse.class); |
---|
494 | assertEquals(404, response.getStatus()); |
---|
495 | } |
---|
496 | |
---|
497 | @Test |
---|
498 | public void testDeletePublicComponentStillUsed() throws Exception { |
---|
499 | |
---|
500 | System.out.println("testDeletePublicComponentStillUsed"); |
---|
501 | |
---|
502 | fillUpPublicItems(); |
---|
503 | |
---|
504 | String content = ""; |
---|
505 | content += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"; |
---|
506 | content += " xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n"; |
---|
507 | content += " <Header/>\n"; |
---|
508 | content += " <CMD_Component name=\"XXX\" CardinalityMin=\"1\" CardinalityMax=\"10\">\n"; |
---|
509 | content += " <CMD_Element name=\"Availability\" ValueScheme=\"string\" />\n"; |
---|
510 | content += " </CMD_Component>\n"; |
---|
511 | content += "</CMD_ComponentSpec>\n"; |
---|
512 | ComponentDescription compDesc1 = RegistryTestHelper.addComponent( |
---|
513 | baseRegistry, "XXX1", content, true); |
---|
514 | |
---|
515 | content = ""; |
---|
516 | content += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"; |
---|
517 | content += " xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n"; |
---|
518 | content += " <Header/>\n"; |
---|
519 | content += " <CMD_Component name=\"YYY\" CardinalityMin=\"1\" CardinalityMax=\"unbounded\">\n"; |
---|
520 | content += " <CMD_Component ComponentId=\"" + compDesc1.getId() |
---|
521 | + "\" CardinalityMin=\"0\" CardinalityMax=\"99\">\n"; |
---|
522 | content += " </CMD_Component>\n"; |
---|
523 | content += " </CMD_Component>\n"; |
---|
524 | content += "</CMD_ComponentSpec>\n"; |
---|
525 | ComponentDescription compDesc2 = RegistryTestHelper.addComponent( |
---|
526 | baseRegistry, "YYY1", content, true); |
---|
527 | |
---|
528 | content = ""; |
---|
529 | content += "<CMD_ComponentSpec isProfile=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"; |
---|
530 | content += " xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n"; |
---|
531 | content += " <Header/>\n"; |
---|
532 | content += " <CMD_Component name=\"ZZZ\" CardinalityMin=\"1\" CardinalityMax=\"unbounded\">\n"; |
---|
533 | content += " <CMD_Component ComponentId=\"" + compDesc1.getId() |
---|
534 | + "\" CardinalityMin=\"0\" CardinalityMax=\"99\">\n"; |
---|
535 | content += " </CMD_Component>\n"; |
---|
536 | content += " </CMD_Component>\n"; |
---|
537 | content += "</CMD_ComponentSpec>\n"; |
---|
538 | ProfileDescription profile = RegistryTestHelper.addProfile( |
---|
539 | baseRegistry, "TestProfile3", content, true); |
---|
540 | |
---|
541 | List<ComponentDescription> components = this.getAuthenticatedResource(getResource().path( |
---|
542 | "/registry/components")).get(COMPONENT_LIST_GENERICTYPE); |
---|
543 | assertEquals(4, components.size()); |
---|
544 | |
---|
545 | ClientResponse response = getAuthenticatedResource( |
---|
546 | "/registry/components/" + compDesc1.getId()).delete( |
---|
547 | ClientResponse.class); |
---|
548 | assertEquals(Status.FORBIDDEN.getStatusCode(), response.getStatus()); |
---|
549 | assertEquals( |
---|
550 | "Component is still in use by other components or profiles. Request component usage for details.", |
---|
551 | response.getEntity(String.class)); |
---|
552 | |
---|
553 | components = this.getAuthenticatedResource(getResource().path("/registry/components")).get( |
---|
554 | COMPONENT_LIST_GENERICTYPE); |
---|
555 | assertEquals(4, components.size()); |
---|
556 | |
---|
557 | response = getAuthenticatedResource( |
---|
558 | "/registry/profiles/" + profile.getId()).delete( |
---|
559 | ClientResponse.class); |
---|
560 | assertEquals(200, response.getStatus()); |
---|
561 | response = getAuthenticatedResource( |
---|
562 | "/registry/components/" + compDesc2.getId()).delete( |
---|
563 | ClientResponse.class); |
---|
564 | assertEquals(200, response.getStatus()); |
---|
565 | response = getAuthenticatedResource( |
---|
566 | "/registry/components/" + compDesc1.getId()).delete( |
---|
567 | ClientResponse.class); |
---|
568 | assertEquals(200, response.getStatus()); |
---|
569 | components = this.getAuthenticatedResource(getResource().path("/registry/components")).get( |
---|
570 | COMPONENT_LIST_GENERICTYPE); |
---|
571 | assertEquals(2, components.size()); |
---|
572 | } |
---|
573 | |
---|
574 | @Test |
---|
575 | public void testManipulatePublicComponent() throws Exception { |
---|
576 | |
---|
577 | System.out.println("testManipulatePublicComponent"); |
---|
578 | |
---|
579 | fillUpPublicItems(); |
---|
580 | |
---|
581 | List<ComponentDescription> components = this.getAuthenticatedResource(getResource().path( |
---|
582 | "/registry/components")).get(COMPONENT_LIST_GENERICTYPE); |
---|
583 | assertEquals(2, components.size()); |
---|
584 | CMDComponentSpec profile = this.getAuthenticatedResource(getResource().path( |
---|
585 | "/registry/components/" + ComponentDescription.COMPONENT_PREFIX |
---|
586 | + "component1")).get(CMDComponentSpec.class); |
---|
587 | assertNotNull(profile); |
---|
588 | |
---|
589 | Form manipulateForm = new Form(); |
---|
590 | manipulateForm.add("method", "delete"); |
---|
591 | |
---|
592 | ClientResponse response = getAuthenticatedResource( |
---|
593 | "/registry/components/" + ComponentDescription.COMPONENT_PREFIX |
---|
594 | + "component1").post(ClientResponse.class, |
---|
595 | manipulateForm); |
---|
596 | assertEquals(200, response.getStatus()); |
---|
597 | |
---|
598 | components = this.getAuthenticatedResource(getResource().path("/registry/components")).get( |
---|
599 | COMPONENT_LIST_GENERICTYPE); |
---|
600 | assertEquals(1, components.size()); |
---|
601 | |
---|
602 | response = getAuthenticatedResource( |
---|
603 | "/registry/components/" + ComponentDescription.COMPONENT_PREFIX |
---|
604 | + "component2").post(ClientResponse.class, |
---|
605 | manipulateForm); |
---|
606 | assertEquals(200, response.getStatus()); |
---|
607 | } |
---|
608 | |
---|
609 | @Test |
---|
610 | public void testGetRegisteredProfile() throws Exception { |
---|
611 | |
---|
612 | System.out.println("testGetRegisteredProfile"); |
---|
613 | |
---|
614 | fillUpPublicItems(); |
---|
615 | |
---|
616 | String id = ProfileDescription.PROFILE_PREFIX + "profile1"; |
---|
617 | String id2 = ProfileDescription.PROFILE_PREFIX + "profile2"; |
---|
618 | CMDComponentSpec profile = this.getAuthenticatedResource(getResource() |
---|
619 | .path("/registry/profiles/" + id)) |
---|
620 | .accept(MediaType.APPLICATION_JSON).get(CMDComponentSpec.class); |
---|
621 | assertNotNull(profile); |
---|
622 | assertEquals("Actor", profile.getCMDComponent().getName()); |
---|
623 | profile = this.getAuthenticatedResource(getResource().path("/registry/profiles/" + id2)) |
---|
624 | .accept(MediaType.APPLICATION_XML).get(CMDComponentSpec.class); |
---|
625 | assertNotNull(profile); |
---|
626 | assertEquals("Actor", profile.getCMDComponent().getName()); |
---|
627 | |
---|
628 | assertEquals(id2, profile.getHeader().getID()); |
---|
629 | assertEquals("profile2", profile.getHeader().getName()); |
---|
630 | assertEquals("Test Description", profile.getHeader().getDescription()); |
---|
631 | |
---|
632 | try { |
---|
633 | profile = this.getAuthenticatedResource(getResource() |
---|
634 | .path("/registry/profiles/" |
---|
635 | + ProfileDescription.PROFILE_PREFIX + "profileXXXX")) |
---|
636 | .accept(MediaType.APPLICATION_XML) |
---|
637 | .get(CMDComponentSpec.class); |
---|
638 | fail("Exception should have been thrown resource does not exist, HttpStatusCode 404"); |
---|
639 | } catch (UniformInterfaceException e) { |
---|
640 | assertEquals(404, e.getResponse().getStatus()); |
---|
641 | } |
---|
642 | } |
---|
643 | |
---|
644 | @Test |
---|
645 | public void testGetRegisteredProfileRawData() { |
---|
646 | |
---|
647 | System.out.println("testGetRegisteredProfileRawData"); |
---|
648 | |
---|
649 | try { |
---|
650 | fillUpPublicItems(); |
---|
651 | } catch (Exception e) { |
---|
652 | System.out.println("test fails due to exception: " + e.getMessage()); |
---|
653 | return; |
---|
654 | } |
---|
655 | |
---|
656 | String profile = this.getAuthenticatedResource(getResource() |
---|
657 | .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX |
---|
658 | + "profile1/xsd")).accept(MediaType.TEXT_XML) |
---|
659 | .get(String.class).trim(); |
---|
660 | assertTrue(profile |
---|
661 | .startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?><xs:schema")); |
---|
662 | assertTrue(profile.endsWith("</xs:schema>")); |
---|
663 | |
---|
664 | profile = this.getAuthenticatedResource(getResource() |
---|
665 | .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX |
---|
666 | + "profile1/xml")).accept(MediaType.TEXT_XML) |
---|
667 | .get(String.class).trim(); |
---|
668 | assertTrue(profile |
---|
669 | .startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<CMD_ComponentSpec")); |
---|
670 | assertTrue(profile.endsWith("</CMD_ComponentSpec>")); |
---|
671 | assertTrue(profile.contains("xsi:schemaLocation")); |
---|
672 | |
---|
673 | |
---|
674 | ClientResponse respie = this.getAuthenticatedResource(getResource() |
---|
675 | .path("/registry/profiles/" |
---|
676 | + ProfileDescription.PROFILE_PREFIX |
---|
677 | + "profile1/xsl")).accept(MediaType.TEXT_XML).head(); |
---|
678 | assertEquals(404, respie.getStatus()); |
---|
679 | } |
---|
680 | |
---|
681 | // |
---|
682 | @Test |
---|
683 | public void testPrivateProfileXsd() { |
---|
684 | |
---|
685 | System.out.println("testPrivateProfileXsd"); |
---|
686 | |
---|
687 | try { |
---|
688 | fillUpPublicItems(); |
---|
689 | } catch (Exception e) { |
---|
690 | System.out.println("test fails due to exception: " + e.getMessage()); |
---|
691 | return; |
---|
692 | } |
---|
693 | |
---|
694 | FormDataMultiPart form = createFormData(RegistryTestHelper |
---|
695 | .getTestProfileContent()); |
---|
696 | RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/profiles").queryParam( |
---|
697 | REGISTRY_SPACE_PARAM, "private")).type( |
---|
698 | MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, |
---|
699 | form); |
---|
700 | assertTrue(response.isProfile()); |
---|
701 | assertEquals(1, getUserProfiles().size()); |
---|
702 | BaseDescription desc = response.getDescription(); |
---|
703 | String profile = this.getAuthenticatedResource(getResource() |
---|
704 | .path("/registry/profiles/" + desc.getId() + "/xsd")) |
---|
705 | .accept(MediaType.TEXT_XML).get(String.class).trim(); |
---|
706 | assertTrue(profile |
---|
707 | .startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?><xs:schema")); |
---|
708 | assertTrue(profile.endsWith("</xs:schema>")); |
---|
709 | } |
---|
710 | |
---|
711 | @Test |
---|
712 | public void testPrivateComponentXsd() throws Exception { |
---|
713 | |
---|
714 | System.out.println("testPrivateComponentXsd"); |
---|
715 | |
---|
716 | fillUpPublicItems(); |
---|
717 | |
---|
718 | FormDataMultiPart form = createFormData(RegistryTestHelper |
---|
719 | .getComponentTestContent()); |
---|
720 | RegisterResponse response = getAuthenticatedResource( |
---|
721 | getResource().path("/registry/components").queryParam( |
---|
722 | REGISTRY_SPACE_PARAM, "private")).type( |
---|
723 | MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, |
---|
724 | form); |
---|
725 | assertFalse(response.isProfile()); |
---|
726 | assertEquals(1, getUserComponents().size()); |
---|
727 | BaseDescription desc = response.getDescription(); |
---|
728 | String profile = this.getAuthenticatedResource(getResource() |
---|
729 | .path("/registry/components/" + desc.getId() + "/xsd")) |
---|
730 | .accept(MediaType.TEXT_XML).get(String.class).trim(); |
---|
731 | assertTrue(profile |
---|
732 | .startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?><xs:schema")); |
---|
733 | assertTrue(profile.endsWith("</xs:schema>")); |
---|
734 | } |
---|
735 | |
---|
736 | @Test |
---|
737 | public void testDeleteRegisteredProfile() throws Exception { |
---|
738 | |
---|
739 | System.out.println("testDeleteRegistredProfile"); |
---|
740 | |
---|
741 | fillUpPublicItems(); |
---|
742 | |
---|
743 | List<ProfileDescription> profiles = this.getAuthenticatedResource(getResource().path( |
---|
744 | "/registry/profiles")).get(PROFILE_LIST_GENERICTYPE); |
---|
745 | assertEquals(2, profiles.size()); |
---|
746 | CMDComponentSpec profile = this.getAuthenticatedResource(getResource().path( |
---|
747 | "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX |
---|
748 | + "profile1")).get(CMDComponentSpec.class); |
---|
749 | assertNotNull(profile); |
---|
750 | |
---|
751 | ClientResponse response = getAuthenticatedResource( |
---|
752 | "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX |
---|
753 | + "profile1").delete(ClientResponse.class); |
---|
754 | assertEquals(200, response.getStatus()); |
---|
755 | |
---|
756 | profiles = this.getAuthenticatedResource(getResource().path("/registry/profiles")).get( |
---|
757 | PROFILE_LIST_GENERICTYPE); |
---|
758 | assertEquals(1, profiles.size()); |
---|
759 | |
---|
760 | response = getAuthenticatedResource( |
---|
761 | "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX |
---|
762 | + "profile2").delete(ClientResponse.class); |
---|
763 | assertEquals(200, response.getStatus()); |
---|
764 | |
---|
765 | profiles = this.getAuthenticatedResource(getResource().path("/registry/profiles")).get( |
---|
766 | PROFILE_LIST_GENERICTYPE); |
---|
767 | assertEquals(0, profiles.size()); |
---|
768 | |
---|
769 | response = getAuthenticatedResource( |
---|
770 | "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX |
---|
771 | + "profile1").delete(ClientResponse.class); |
---|
772 | assertEquals(404, response.getStatus()); |
---|
773 | } |
---|
774 | |
---|
775 | @Test |
---|
776 | public void testManipulateRegisteredProfile() throws Exception { |
---|
777 | |
---|
778 | System.out.println("testManipulateRegisteredProfile"); |
---|
779 | |
---|
780 | fillUpPublicItems(); |
---|
781 | |
---|
782 | List<ProfileDescription> profiles = this.getAuthenticatedResource(getResource().path( |
---|
783 | "/registry/profiles")).get(PROFILE_LIST_GENERICTYPE); |
---|
784 | assertEquals(2, profiles.size()); |
---|
785 | CMDComponentSpec profile = this.getAuthenticatedResource(getResource().path( |
---|
786 | "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX |
---|
787 | + "profile1")).get(CMDComponentSpec.class); |
---|
788 | assertNotNull(profile); |
---|
789 | |
---|
790 | Form manipulateForm = new Form(); |
---|
791 | manipulateForm.add("method", "delete"); |
---|
792 | |
---|
793 | ClientResponse response = getAuthenticatedResource( |
---|
794 | "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX |
---|
795 | + "profile1") |
---|
796 | .post(ClientResponse.class, manipulateForm); |
---|
797 | assertEquals(200, response.getStatus()); |
---|
798 | |
---|
799 | profiles = this.getAuthenticatedResource(getResource().path("/registry/profiles")).get( |
---|
800 | PROFILE_LIST_GENERICTYPE); |
---|
801 | assertEquals(1, profiles.size()); |
---|
802 | |
---|
803 | response = getAuthenticatedResource( |
---|
804 | "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX |
---|
805 | + "profile2") |
---|
806 | .post(ClientResponse.class, manipulateForm); |
---|
807 | assertEquals(200, response.getStatus()); |
---|
808 | } |
---|
809 | |
---|
810 | @Test |
---|
811 | public void testGetRegisteredComponentRawData() throws Exception { |
---|
812 | |
---|
813 | System.out.println("testGetRegisteredComponentRawData"); |
---|
814 | |
---|
815 | fillUpPublicItems(); |
---|
816 | |
---|
817 | String id = ComponentDescription.COMPONENT_PREFIX + "component1"; |
---|
818 | String component = this.getAuthenticatedResource(getResource() |
---|
819 | .path("/registry/components/" + id + "/xsd")) |
---|
820 | .accept(MediaType.TEXT_XML).get(String.class).trim(); |
---|
821 | assertTrue(component |
---|
822 | .startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?><xs:schema")); |
---|
823 | assertTrue(component.endsWith("</xs:schema>")); |
---|
824 | |
---|
825 | component = this.getAuthenticatedResource(getResource().path("/registry/components/" + id + "/xml")) |
---|
826 | .accept(MediaType.TEXT_XML).get(String.class).trim(); |
---|
827 | assertTrue(component |
---|
828 | .startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<CMD_ComponentSpec")); |
---|
829 | assertTrue(component.endsWith("</CMD_ComponentSpec>")); |
---|
830 | assertTrue(component.contains("xsi:schemaLocation")); |
---|
831 | |
---|
832 | ClientResponse respie = this.getAuthenticatedResource(getResource() |
---|
833 | .path("/registry/components/" |
---|
834 | + ComponentDescription.COMPONENT_PREFIX |
---|
835 | + "component1/jpg")).accept(MediaType.TEXT_XML) |
---|
836 | .head(); |
---|
837 | assertEquals(404, respie.getStatus()); |
---|
838 | } |
---|
839 | |
---|
840 | @Test |
---|
841 | public void testRegisterProfile() throws Exception { |
---|
842 | |
---|
843 | System.out.println("testRegisterProfile"); |
---|
844 | |
---|
845 | fillUpPublicItems(); |
---|
846 | |
---|
847 | FormDataMultiPart form = new FormDataMultiPart(); |
---|
848 | form.field(IComponentRegistryRestService.DATA_FORM_FIELD, |
---|
849 | RegistryTestHelper.getTestProfileContent(), |
---|
850 | MediaType.APPLICATION_OCTET_STREAM_TYPE); |
---|
851 | form.field(IComponentRegistryRestService.NAME_FORM_FIELD, |
---|
852 | "ProfileTest1"); |
---|
853 | form.field(IComponentRegistryRestService.DOMAIN_FORM_FIELD, |
---|
854 | "TestDomain"); |
---|
855 | form.field(IComponentRegistryRestService.DESCRIPTION_FORM_FIELD, |
---|
856 | "My Test Profile"); |
---|
857 | form.field(IComponentRegistryRestService.GROUP_FORM_FIELD, |
---|
858 | "My Test Group"); |
---|
859 | RegisterResponse response = getAuthenticatedResource( |
---|
860 | "/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post( |
---|
861 | RegisterResponse.class, form); |
---|
862 | assertTrue(response.isProfile()); |
---|
863 | assertTrue(response.isPrivate()); |
---|
864 | ProfileDescription profileDesc = (ProfileDescription) response |
---|
865 | .getDescription(); |
---|
866 | assertNotNull(profileDesc); |
---|
867 | assertEquals("ProfileTest1", profileDesc.getName()); |
---|
868 | assertEquals("My Test Profile", profileDesc.getDescription()); |
---|
869 | assertEquals("TestDomain", profileDesc.getDomainName()); |
---|
870 | assertEquals("My Test Group", profileDesc.getGroupName()); |
---|
871 | assertEquals(expectedUserId("JUnit@test.com"), profileDesc.getUserId()); |
---|
872 | assertEquals("Database test user", profileDesc.getCreatorName()); |
---|
873 | assertTrue(profileDesc.getId().startsWith( |
---|
874 | ComponentRegistry.REGISTRY_ID + "p_")); |
---|
875 | assertNotNull(profileDesc.getRegistrationDate()); |
---|
876 | assertEquals( |
---|
877 | "http://localhost:9998/registry/profiles/" |
---|
878 | + profileDesc.getId(), profileDesc.getHref()); |
---|
879 | } |
---|
880 | |
---|
881 | @Test |
---|
882 | public void testPublishProfile() throws Exception { |
---|
883 | |
---|
884 | System.out.println("testPublishProfile"); |
---|
885 | |
---|
886 | fillUpPrivateItems(); |
---|
887 | fillUpPublicItems(); |
---|
888 | |
---|
889 | assertEquals("user registered profiles", 1, getUserProfiles().size()); |
---|
890 | assertEquals("public registered profiles", 2, getPublicProfiles() |
---|
891 | .size()); |
---|
892 | FormDataMultiPart form = createFormData( |
---|
893 | RegistryTestHelper.getTestProfileContent(), "Unpublished"); |
---|
894 | RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/profiles")).type( |
---|
895 | MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, |
---|
896 | form); |
---|
897 | assertTrue(response.isProfile()); |
---|
898 | BaseDescription desc = response.getDescription(); |
---|
899 | assertEquals("Unpublished", desc.getDescription()); |
---|
900 | assertEquals(2, getUserProfiles().size()); |
---|
901 | assertEquals(2, getPublicProfiles().size()); |
---|
902 | form = createFormData( |
---|
903 | RegistryTestHelper.getTestProfileContent("publishedName"), |
---|
904 | "Published"); |
---|
905 | response = getAuthenticatedResource(getResource().path( |
---|
906 | "/registry/profiles/" + desc.getId() + "/publish")) |
---|
907 | .type(MediaType.MULTIPART_FORM_DATA).post( |
---|
908 | RegisterResponse.class, form); |
---|
909 | |
---|
910 | assertEquals(1, getUserProfiles().size()); |
---|
911 | List<ProfileDescription> profiles = getPublicProfiles(); |
---|
912 | assertEquals(3, profiles.size()); |
---|
913 | ProfileDescription profileDescription = profiles.get(2); |
---|
914 | assertNotNull(profileDescription.getId()); |
---|
915 | assertEquals(desc.getId(), profileDescription.getId()); |
---|
916 | assertEquals("http://localhost:9998/registry/profiles/" + desc.getId(), |
---|
917 | profileDescription.getHref()); |
---|
918 | assertEquals("Published", profileDescription.getDescription()); |
---|
919 | CMDComponentSpec spec = getPublicSpec(profileDescription); |
---|
920 | assertEquals("publishedName", spec.getCMDComponent().getName()); |
---|
921 | } |
---|
922 | |
---|
923 | private CMDComponentSpec getPublicSpec(BaseDescription desc) { |
---|
924 | if (desc.isProfile()) { |
---|
925 | return this.getAuthenticatedResource(getResource().path("/registry/profiles/" + desc.getId())) |
---|
926 | .get(CMDComponentSpec.class); |
---|
927 | } else { |
---|
928 | return this.getAuthenticatedResource(getResource().path("/registry/components/" + desc.getId())) |
---|
929 | .get(CMDComponentSpec.class); |
---|
930 | } |
---|
931 | } |
---|
932 | |
---|
933 | @Test |
---|
934 | public void testPublishRegisteredComponent() throws Exception { |
---|
935 | |
---|
936 | System.out.println("testPublishRegisteredComponent"); |
---|
937 | |
---|
938 | fillUpPrivateItems(); |
---|
939 | fillUpPublicItems(); |
---|
940 | |
---|
941 | assertEquals(1, getUserComponents().size()); |
---|
942 | assertEquals(2, getPublicComponents().size()); |
---|
943 | |
---|
944 | FormDataMultiPart form = createFormData( |
---|
945 | RegistryTestHelper.getComponentTestContent(), "Unpublished"); |
---|
946 | RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/components")).type( |
---|
947 | MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, |
---|
948 | form); |
---|
949 | assertFalse(response.isProfile()); |
---|
950 | BaseDescription desc = response.getDescription(); |
---|
951 | assertEquals("Unpublished", desc.getDescription()); |
---|
952 | assertEquals(2, getUserComponents().size()); |
---|
953 | assertEquals(2, getPublicComponents().size()); |
---|
954 | form = createFormData( |
---|
955 | RegistryTestHelper.getComponentTestContentAsStream("publishedName"), |
---|
956 | "Published"); |
---|
957 | response = getAuthenticatedResource(getResource().path( |
---|
958 | "/registry/components/" + desc.getId() + "/publish")) |
---|
959 | .type(MediaType.MULTIPART_FORM_DATA).post( |
---|
960 | RegisterResponse.class, form); |
---|
961 | |
---|
962 | assertEquals(1, getUserComponents().size()); |
---|
963 | List<ComponentDescription> components = getPublicComponents(); |
---|
964 | assertEquals(3, components.size()); |
---|
965 | ComponentDescription componentDescription = components.get(2); |
---|
966 | assertNotNull(componentDescription.getId()); |
---|
967 | assertEquals(desc.getId(), componentDescription.getId()); |
---|
968 | assertEquals( |
---|
969 | "http://localhost:9998/registry/components/" + desc.getId(), |
---|
970 | componentDescription.getHref()); |
---|
971 | assertEquals("Published", componentDescription.getDescription()); |
---|
972 | CMDComponentSpec spec = getPublicSpec(componentDescription); |
---|
973 | assertEquals("publishedName", spec.getCMDComponent().getName()); |
---|
974 | } |
---|
975 | |
---|
976 | // duplicates ("extendedly") testRegisterProfile, since you can pot only in user space, and then publish or move to group or so |
---|
977 | @Test |
---|
978 | public void testRegisterUserspaceProfile() throws Exception { |
---|
979 | |
---|
980 | System.out.println("testRegisterUserspacProfile"); |
---|
981 | |
---|
982 | fillUpPrivateItems(); |
---|
983 | fillUpPublicItems(); |
---|
984 | |
---|
985 | List<ProfileDescription> profiles = getUserProfiles(); |
---|
986 | assertEquals("user registered profiles", 1, profiles.size()); |
---|
987 | assertEquals("public registered profiles", 2, getPublicProfiles() |
---|
988 | .size()); |
---|
989 | FormDataMultiPart form = createFormData(RegistryTestHelper |
---|
990 | .getTestProfileContent()); |
---|
991 | RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/profiles")).type( |
---|
992 | MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, |
---|
993 | form); |
---|
994 | assertTrue(response.isProfile()); |
---|
995 | assertTrue(response.isPrivate()); |
---|
996 | ProfileDescription profileDesc = (ProfileDescription) response |
---|
997 | .getDescription(); |
---|
998 | assertNotNull(profileDesc); |
---|
999 | assertEquals("Test1", profileDesc.getName()); |
---|
1000 | assertEquals("My Test", profileDesc.getDescription()); |
---|
1001 | assertEquals(expectedUserId("JUnit@test.com"), profileDesc.getUserId()); |
---|
1002 | assertEquals("Database test user", profileDesc.getCreatorName()); |
---|
1003 | assertTrue(profileDesc.getId().startsWith( |
---|
1004 | ComponentRegistry.REGISTRY_ID + "p_")); |
---|
1005 | assertNotNull(profileDesc.getRegistrationDate()); |
---|
1006 | assertEquals( |
---|
1007 | "http://localhost:9998/registry/profiles/" |
---|
1008 | + profileDesc.getId(), |
---|
1009 | profileDesc.getHref()); |
---|
1010 | |
---|
1011 | profiles = getUserProfiles(); |
---|
1012 | assertEquals(2, profiles.size()); |
---|
1013 | assertEquals(2, getPublicProfiles().size()); |
---|
1014 | |
---|
1015 | // Try to post unauthenticated |
---|
1016 | ClientResponse cResponse = getResource().path("/registry/profiles") |
---|
1017 | .type(MediaType.MULTIPART_FORM_DATA) |
---|
1018 | .post(ClientResponse.class, form); |
---|
1019 | assertEquals(401, cResponse.getStatus()); |
---|
1020 | |
---|
1021 | |
---|
1022 | |
---|
1023 | CMDComponentSpec spec = getAuthenticatedResource(getResource().path("/registry/profiles/" + profileDesc.getId()) |
---|
1024 | .queryParam(REGISTRY_SPACE_PARAM, "private")).accept( |
---|
1025 | MediaType.APPLICATION_XML).get(CMDComponentSpec.class); |
---|
1026 | assertNotNull(spec); |
---|
1027 | |
---|
1028 | cResponse = this.getAuthenticatedResource(getResource() |
---|
1029 | .path("/registry/profiles/" + profileDesc.getId() + "/xsd")) |
---|
1030 | .accept(MediaType.TEXT_XML).get(ClientResponse.class); |
---|
1031 | assertEquals(200, cResponse.getStatus()); |
---|
1032 | String profile = cResponse.getEntity(String.class); |
---|
1033 | assertTrue(profile.length() > 0); |
---|
1034 | |
---|
1035 | profile = getAuthenticatedResource(getResource().path( |
---|
1036 | "/registry/profiles/" + profileDesc.getId() + "/xml")) |
---|
1037 | .accept(MediaType.TEXT_XML).get(String.class); |
---|
1038 | assertTrue(profile.length() > 0); |
---|
1039 | |
---|
1040 | cResponse = getAuthenticatedResource(getResource().path("/registry/profiles/" + profileDesc.getId()) |
---|
1041 | .queryParam(REGISTRY_SPACE_PARAM, "private")).delete( |
---|
1042 | ClientResponse.class); |
---|
1043 | assertEquals(200, cResponse.getStatus()); |
---|
1044 | |
---|
1045 | profiles = getUserProfiles(); |
---|
1046 | assertEquals(1, profiles.size()); |
---|
1047 | } |
---|
1048 | |
---|
1049 | private List<ProfileDescription> getPublicProfiles() { |
---|
1050 | return getAuthenticatedResource("/registry/profiles").accept( |
---|
1051 | MediaType.APPLICATION_XML).get(PROFILE_LIST_GENERICTYPE); |
---|
1052 | } |
---|
1053 | |
---|
1054 | private List<ProfileDescription> getUserProfiles() { |
---|
1055 | return getAuthenticatedResource(getResource().path("/registry/profiles").queryParam( |
---|
1056 | REGISTRY_SPACE_PARAM, "private")).accept( |
---|
1057 | MediaType.APPLICATION_XML).get(PROFILE_LIST_GENERICTYPE); |
---|
1058 | } |
---|
1059 | |
---|
1060 | private FormDataMultiPart createFormData(Object content) { |
---|
1061 | return createFormData(content, "My Test"); |
---|
1062 | } |
---|
1063 | |
---|
1064 | private FormDataMultiPart createFormData(Object content, String description) { |
---|
1065 | FormDataMultiPart form = new FormDataMultiPart(); |
---|
1066 | form.field(IComponentRegistryRestService.DATA_FORM_FIELD, content, |
---|
1067 | MediaType.APPLICATION_OCTET_STREAM_TYPE); |
---|
1068 | form.field(IComponentRegistryRestService.NAME_FORM_FIELD, "Test1"); |
---|
1069 | form.field(IComponentRegistryRestService.DESCRIPTION_FORM_FIELD, |
---|
1070 | description); |
---|
1071 | form.field(IComponentRegistryRestService.DOMAIN_FORM_FIELD, "My domain"); |
---|
1072 | form.field(IComponentRegistryRestService.GROUP_FORM_FIELD, "TestGroup"); |
---|
1073 | return form; |
---|
1074 | } |
---|
1075 | |
---|
1076 | @Test |
---|
1077 | public void testRegisterWithUserComponents() throws Exception { |
---|
1078 | |
---|
1079 | System.out.println("testRegisterWithUserComponents"); |
---|
1080 | |
---|
1081 | fillUpPrivateItems(); |
---|
1082 | |
---|
1083 | // kid component, not public |
---|
1084 | String content = ""; |
---|
1085 | content += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"; |
---|
1086 | content += " xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n"; |
---|
1087 | content += " <Header/>\n"; |
---|
1088 | content += " <CMD_Component name=\"XXX\" CardinalityMin=\"1\" CardinalityMax=\"10\">\n"; |
---|
1089 | content += " <CMD_Element name=\"Availability\" ValueScheme=\"string\" />\n"; |
---|
1090 | content += " </CMD_Component>\n"; |
---|
1091 | content += "</CMD_ComponentSpec>\n"; |
---|
1092 | ComponentDescription compDesc1 = RegistryTestHelper.addComponent( |
---|
1093 | baseRegistry, "XXX1", content, false); |
---|
1094 | |
---|
1095 | // a containing component, referring to the kid (which is not public, so the containing component cannot be registered |
---|
1096 | content = ""; |
---|
1097 | content += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"; |
---|
1098 | content += " xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n"; |
---|
1099 | content += " <Header/>\n"; |
---|
1100 | content += " <CMD_Component name=\"YYY\" CardinalityMin=\"1\" CardinalityMax=\"unbounded\">\n"; |
---|
1101 | content += " <CMD_Component ComponentId=\"" + compDesc1.getId() |
---|
1102 | + "\" CardinalityMin=\"0\" CardinalityMax=\"99\">\n"; |
---|
1103 | content += " </CMD_Component>\n"; |
---|
1104 | content += " </CMD_Component>\n"; |
---|
1105 | content += "</CMD_ComponentSpec>\n"; |
---|
1106 | FormDataMultiPart form = createFormData(content); |
---|
1107 | RegisterResponse response = getAuthenticatedResource( |
---|
1108 | "/registry/components").type(MediaType.MULTIPART_FORM_DATA) |
---|
1109 | .post(RegisterResponse.class, form); |
---|
1110 | // we first alway register in a private space, so reference to a private component should work |
---|
1111 | assertTrue(response.isRegistered()); |
---|
1112 | |
---|
1113 | |
---|
1114 | /// profiles /// |
---|
1115 | content = ""; |
---|
1116 | content += "<CMD_ComponentSpec isProfile=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"; |
---|
1117 | content += " xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n"; |
---|
1118 | content += " <Header/>\n"; |
---|
1119 | content += " <CMD_Component name=\"ZZZ\" CardinalityMin=\"1\" CardinalityMax=\"unbounded\">\n"; |
---|
1120 | content += " <CMD_Component ComponentId=\"" + compDesc1.getId() |
---|
1121 | + "\" CardinalityMin=\"0\" CardinalityMax=\"99\">\n"; |
---|
1122 | content += " </CMD_Component>\n"; |
---|
1123 | content += " </CMD_Component>\n"; |
---|
1124 | content += "</CMD_ComponentSpec>\n"; |
---|
1125 | |
---|
1126 | form = createFormData(content); |
---|
1127 | response = getAuthenticatedResource("/registry/profiles").type( |
---|
1128 | MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, |
---|
1129 | form); |
---|
1130 | assertTrue(response.isRegistered()); |
---|
1131 | |
---|
1132 | } |
---|
1133 | |
---|
1134 | @Test |
---|
1135 | public void testRegisterUserspaceComponent() throws Exception { |
---|
1136 | |
---|
1137 | System.out.println("testREgisterUserspaceComponent"); |
---|
1138 | |
---|
1139 | fillUpPrivateItems(); |
---|
1140 | |
---|
1141 | List<ComponentDescription> components = getUserComponents(); |
---|
1142 | assertEquals("user registered components", 1, components.size()); |
---|
1143 | assertEquals("public registered components", 0, getPublicComponents() |
---|
1144 | .size()); |
---|
1145 | FormDataMultiPart form = createFormData(RegistryTestHelper |
---|
1146 | .getComponentTestContent()); |
---|
1147 | |
---|
1148 | RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/components")).type( |
---|
1149 | MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, |
---|
1150 | form); |
---|
1151 | assertTrue(response.isRegistered()); |
---|
1152 | assertFalse(response.isProfile()); |
---|
1153 | assertTrue(response.isPrivate()); |
---|
1154 | ComponentDescription desc = (ComponentDescription) response |
---|
1155 | .getDescription(); |
---|
1156 | assertNotNull(desc); |
---|
1157 | assertEquals("Test1", desc.getName()); |
---|
1158 | assertEquals("My Test", desc.getDescription()); |
---|
1159 | assertEquals(expectedUserId("JUnit@test.com"), desc.getUserId()); |
---|
1160 | assertEquals("Database test user", desc.getCreatorName()); |
---|
1161 | assertEquals("TestGroup", desc.getGroupName()); |
---|
1162 | assertTrue(desc.getId() |
---|
1163 | .startsWith(ComponentRegistry.REGISTRY_ID + "c_")); |
---|
1164 | assertNotNull(desc.getRegistrationDate()); |
---|
1165 | String url = getResource().getUriBuilder().build().toString(); |
---|
1166 | assertEquals(url + "registry/components/" + desc.getId(), desc.getHref()); |
---|
1167 | |
---|
1168 | components = getUserComponents(); |
---|
1169 | assertEquals(2, components.size()); |
---|
1170 | assertEquals(0, getPublicComponents().size()); |
---|
1171 | |
---|
1172 | // Try to post unauthenticated |
---|
1173 | ClientResponse cResponse = getResource().path("/registry/components") |
---|
1174 | .type(MediaType.MULTIPART_FORM_DATA) |
---|
1175 | .post(ClientResponse.class, form); |
---|
1176 | assertEquals(401, cResponse.getStatus()); |
---|
1177 | |
---|
1178 | // Try to get |
---|
1179 | cResponse = this.getAuthenticatedResource(getResource().path("/registry/components/" + desc.getId())) |
---|
1180 | .accept(MediaType.APPLICATION_XML).get(ClientResponse.class); |
---|
1181 | |
---|
1182 | assertEquals(200, cResponse.getStatus()); |
---|
1183 | CMDComponentSpec spec = getUserComponent(desc); |
---|
1184 | assertNotNull(spec); |
---|
1185 | |
---|
1186 | cResponse = this.getAuthenticatedResource(getResource() |
---|
1187 | .path("/registry/components/" + desc.getId() + "/xsd")) |
---|
1188 | .accept(MediaType.TEXT_XML).get(ClientResponse.class); |
---|
1189 | assertEquals(200, cResponse.getStatus()); |
---|
1190 | String result = cResponse.getEntity(String.class); |
---|
1191 | assertTrue(result.length() > 0); |
---|
1192 | |
---|
1193 | result = getAuthenticatedResource(getResource().path( |
---|
1194 | "/registry/components/" + desc.getId() + "/xml")) |
---|
1195 | .accept(MediaType.TEXT_XML).get(String.class); |
---|
1196 | assertTrue(result.length() > 0); |
---|
1197 | |
---|
1198 | cResponse = getAuthenticatedResource(getResource().path("/registry/components/" + desc.getId())).delete( |
---|
1199 | ClientResponse.class); |
---|
1200 | assertEquals(200, cResponse.getStatus()); |
---|
1201 | |
---|
1202 | components = getUserComponents(); |
---|
1203 | assertEquals(1, components.size()); |
---|
1204 | } |
---|
1205 | // |
---|
1206 | |
---|
1207 | @Test |
---|
1208 | public void testCreatePrivateComponentWithRecursion() throws Exception { |
---|
1209 | |
---|
1210 | System.out.println("testCreatePrivateComponentWithRecursion"); |
---|
1211 | |
---|
1212 | fillUpPrivateItems(); |
---|
1213 | // Create new componet |
---|
1214 | FormDataMultiPart form = createFormData(RegistryTestHelper |
---|
1215 | .getComponentTestContent()); |
---|
1216 | ClientResponse cResponse = getAuthenticatedResource(getResource().path("/registry/components")).type( |
---|
1217 | MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form); |
---|
1218 | assertEquals(ClientResponse.Status.OK.getStatusCode(), |
---|
1219 | cResponse.getStatus()); |
---|
1220 | RegisterResponse response = cResponse.getEntity(RegisterResponse.class); |
---|
1221 | assertTrue(response.isRegistered()); |
---|
1222 | ComponentDescription desc = (ComponentDescription) response |
---|
1223 | .getDescription(); |
---|
1224 | |
---|
1225 | // Re-define with self-recursion |
---|
1226 | String compContent = ""; |
---|
1227 | compContent += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; |
---|
1228 | compContent += "\n"; |
---|
1229 | compContent += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"; |
---|
1230 | compContent += " xsi:noNamespaceSchemaLocation=\"../../general-component-schema.xsd\">\n"; |
---|
1231 | compContent += " \n"; |
---|
1232 | compContent += " <Header/>\n"; |
---|
1233 | compContent += " \n"; |
---|
1234 | compContent += " <CMD_Component name=\"Nested\" CardinalityMin=\"1\" CardinalityMax=\"1\">\n"; |
---|
1235 | compContent += " <CMD_Element name=\"Availability\" ValueScheme=\"string\" />\n"; |
---|
1236 | compContent += " <CMD_Component ComponentId=\"" |
---|
1237 | + desc.getId() |
---|
1238 | + "\" name=\"Recursive\" CardinalityMin=\"1\" CardinalityMax=\"1\" />\n"; |
---|
1239 | compContent += " </CMD_Component>\n"; |
---|
1240 | compContent += "\n"; |
---|
1241 | compContent += "</CMD_ComponentSpec>\n"; |
---|
1242 | |
---|
1243 | // Update component |
---|
1244 | form = createFormData( |
---|
1245 | RegistryTestHelper.getComponentContentAsStream(compContent), |
---|
1246 | "UPDATE DESCRIPTION!"); |
---|
1247 | cResponse = getAuthenticatedResource(getResource().path( |
---|
1248 | "/registry/components/" + desc.getId() + "/update")).type( |
---|
1249 | MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form); |
---|
1250 | assertEquals(ClientResponse.Status.OK.getStatusCode(), |
---|
1251 | cResponse.getStatus()); |
---|
1252 | response = cResponse.getEntity(RegisterResponse.class); |
---|
1253 | assertFalse("Recursive definition should fail", response.isRegistered()); |
---|
1254 | assertEquals("There should be an error message for the recursion", 1, |
---|
1255 | response.getErrors().size()); |
---|
1256 | assertTrue( |
---|
1257 | "There error message should specify the point of recursion", |
---|
1258 | response.getErrors().get(0) |
---|
1259 | .contains("already contains " + desc.getId())); |
---|
1260 | |
---|
1261 | } |
---|
1262 | |
---|
1263 | @Test |
---|
1264 | public void testUpdatePrivateComponent() throws Exception { |
---|
1265 | |
---|
1266 | System.out.println("testUpdatePrivateComponent"); |
---|
1267 | |
---|
1268 | fillUpPrivateItems(); |
---|
1269 | |
---|
1270 | List<ComponentDescription> components = getUserComponents(); |
---|
1271 | assertEquals("user registered components", 1, components.size()); |
---|
1272 | assertEquals("public registered components", 0, getPublicComponents() |
---|
1273 | .size()); |
---|
1274 | |
---|
1275 | // first, post a component to update |
---|
1276 | FormDataMultiPart form = createFormData(RegistryTestHelper |
---|
1277 | .getComponentTestContent()); |
---|
1278 | ClientResponse cResponse = getAuthenticatedResource(getResource().path("/registry/components")).type( |
---|
1279 | MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form); |
---|
1280 | assertEquals(ClientResponse.Status.OK.getStatusCode(), |
---|
1281 | cResponse.getStatus()); |
---|
1282 | RegisterResponse response = cResponse.getEntity(RegisterResponse.class); |
---|
1283 | assertTrue(response.isRegistered()); |
---|
1284 | assertFalse(response.isProfile()); |
---|
1285 | assertTrue(response.isPrivate()); |
---|
1286 | ComponentDescription desc = (ComponentDescription) response |
---|
1287 | .getDescription(); |
---|
1288 | assertNotNull(desc); |
---|
1289 | assertEquals("Test1", desc.getName()); |
---|
1290 | assertEquals("My Test", desc.getDescription()); |
---|
1291 | Date firstDate = desc.getRegistrationDate(); |
---|
1292 | CMDComponentSpec spec = getUserComponent(desc); |
---|
1293 | assertNotNull(spec); |
---|
1294 | assertEquals("Access", spec.getCMDComponent().getName()); |
---|
1295 | components = getUserComponents(); |
---|
1296 | assertEquals(2, components.size()); |
---|
1297 | assertEquals(0, getPublicComponents().size()); |
---|
1298 | |
---|
1299 | // second, now update |
---|
1300 | form = createFormData( |
---|
1301 | RegistryTestHelper.getComponentTestContentAsStream("TESTNAME"), |
---|
1302 | "UPDATE DESCRIPTION!"); |
---|
1303 | cResponse = getAuthenticatedResource(getResource().path( |
---|
1304 | "/registry/components/" + desc.getId() + "/update")).type( |
---|
1305 | MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form); |
---|
1306 | assertEquals(ClientResponse.Status.OK.getStatusCode(), |
---|
1307 | cResponse.getStatus()); |
---|
1308 | response = cResponse.getEntity(RegisterResponse.class); |
---|
1309 | assertTrue(response.isRegistered()); |
---|
1310 | assertFalse(response.isProfile()); |
---|
1311 | assertTrue(response.isPrivate()); |
---|
1312 | desc = (ComponentDescription) response.getDescription(); |
---|
1313 | assertNotNull(desc); |
---|
1314 | assertEquals("Test1", desc.getName()); |
---|
1315 | assertEquals("UPDATE DESCRIPTION!", desc.getDescription()); |
---|
1316 | Date secondDate = desc.getRegistrationDate(); |
---|
1317 | assertTrue(firstDate.before(secondDate) || firstDate.equals(secondDate)); |
---|
1318 | |
---|
1319 | spec = getUserComponent(desc); |
---|
1320 | assertNotNull(spec); |
---|
1321 | assertEquals("TESTNAME", spec.getCMDComponent().getName()); |
---|
1322 | components = getUserComponents(); |
---|
1323 | assertEquals(2, components.size()); |
---|
1324 | assertEquals(0, getPublicComponents().size()); |
---|
1325 | } |
---|
1326 | |
---|
1327 | @Test |
---|
1328 | public void testUpdatePrivateProfile() throws Exception { |
---|
1329 | |
---|
1330 | System.out.println("testUpdatePrivateProfile"); |
---|
1331 | |
---|
1332 | fillUpPrivateItems(); |
---|
1333 | |
---|
1334 | List<ProfileDescription> profiles = getUserProfiles(); |
---|
1335 | assertEquals(1, profiles.size()); |
---|
1336 | assertEquals(0, getPublicProfiles().size()); |
---|
1337 | |
---|
1338 | FormDataMultiPart form = createFormData(RegistryTestHelper |
---|
1339 | .getTestProfileContent()); |
---|
1340 | ClientResponse cResponse = getAuthenticatedResource(getResource().path("/registry/profiles")).type( |
---|
1341 | MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form); |
---|
1342 | assertEquals(ClientResponse.Status.OK.getStatusCode(), |
---|
1343 | cResponse.getStatus()); |
---|
1344 | RegisterResponse response = cResponse.getEntity(RegisterResponse.class); |
---|
1345 | assertTrue(response.isRegistered()); |
---|
1346 | assertTrue(response.isProfile()); |
---|
1347 | assertTrue(response.isPrivate()); |
---|
1348 | ProfileDescription desc = (ProfileDescription) response |
---|
1349 | .getDescription(); |
---|
1350 | assertNotNull(desc); |
---|
1351 | assertEquals("Test1", desc.getName()); |
---|
1352 | assertEquals("My Test", desc.getDescription()); |
---|
1353 | assertEquals("TestGroup", desc.getGroupName()); |
---|
1354 | Date firstDate = desc.getRegistrationDate(); |
---|
1355 | CMDComponentSpec spec = getUserProfile(desc); |
---|
1356 | assertNotNull(spec); |
---|
1357 | assertEquals("Actor", spec.getCMDComponent().getName()); |
---|
1358 | profiles = getUserProfiles(); |
---|
1359 | assertEquals(2, profiles.size()); |
---|
1360 | assertEquals(0, getPublicComponents().size()); |
---|
1361 | |
---|
1362 | // Now update |
---|
1363 | form = createFormData( |
---|
1364 | RegistryTestHelper.getTestProfileContent("TESTNAME"), |
---|
1365 | "UPDATE DESCRIPTION!"); |
---|
1366 | cResponse = getAuthenticatedResource(getResource().path( |
---|
1367 | "/registry/profiles/" + desc.getId() + "/update")).type( |
---|
1368 | MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form); |
---|
1369 | assertEquals(ClientResponse.Status.OK.getStatusCode(), |
---|
1370 | cResponse.getStatus()); |
---|
1371 | response = cResponse.getEntity(RegisterResponse.class); |
---|
1372 | assertTrue(response.isRegistered()); |
---|
1373 | assertTrue(response.isProfile()); |
---|
1374 | assertTrue(response.isPrivate()); |
---|
1375 | desc = (ProfileDescription) response.getDescription(); |
---|
1376 | assertNotNull(desc); |
---|
1377 | assertEquals("Test1", desc.getName()); |
---|
1378 | assertEquals("UPDATE DESCRIPTION!", desc.getDescription()); |
---|
1379 | Date secondDate = desc.getRegistrationDate(); |
---|
1380 | assertTrue(firstDate.before(secondDate) || firstDate.equals(secondDate)); |
---|
1381 | |
---|
1382 | spec = getUserProfile(desc); |
---|
1383 | assertNotNull(spec); |
---|
1384 | assertEquals("TESTNAME", spec.getCMDComponent().getName()); |
---|
1385 | profiles = getUserProfiles(); |
---|
1386 | assertEquals(2, profiles.size()); |
---|
1387 | assertEquals(0, getPublicComponents().size()); |
---|
1388 | } |
---|
1389 | |
---|
1390 | private CMDComponentSpec getUserComponent(ComponentDescription desc) { |
---|
1391 | return getAuthenticatedResource(getResource().path("/registry/components/" + desc.getId()) |
---|
1392 | .queryParam(REGISTRY_SPACE_PARAM, "private")).accept( |
---|
1393 | MediaType.APPLICATION_XML).get(CMDComponentSpec.class); |
---|
1394 | } |
---|
1395 | |
---|
1396 | private CMDComponentSpec getUserProfile(ProfileDescription desc) { |
---|
1397 | return getAuthenticatedResource(getResource().path("/registry/profiles/" + desc.getId()) |
---|
1398 | .queryParam(REGISTRY_SPACE_PARAM, "private")).accept( |
---|
1399 | MediaType.APPLICATION_XML).get(CMDComponentSpec.class); |
---|
1400 | } |
---|
1401 | |
---|
1402 | private List<ComponentDescription> getPublicComponents() { |
---|
1403 | return getAuthenticatedResource("/registry/components").accept( |
---|
1404 | MediaType.APPLICATION_XML).get(COMPONENT_LIST_GENERICTYPE); |
---|
1405 | } |
---|
1406 | |
---|
1407 | private List<ComponentDescription> getUserComponents() { |
---|
1408 | return getAuthenticatedResource(getResource().path("/registry/components").queryParam( |
---|
1409 | REGISTRY_SPACE_PARAM, "private")).accept( |
---|
1410 | MediaType.APPLICATION_XML).get(COMPONENT_LIST_GENERICTYPE); |
---|
1411 | } |
---|
1412 | |
---|
1413 | @Test |
---|
1414 | public void testRegisterComponent() throws Exception { |
---|
1415 | |
---|
1416 | System.out.println("testRegisterComponent"); |
---|
1417 | |
---|
1418 | fillUpPrivateItems(); |
---|
1419 | |
---|
1420 | FormDataMultiPart form = new FormDataMultiPart(); |
---|
1421 | form.field(IComponentRegistryRestService.DATA_FORM_FIELD, |
---|
1422 | RegistryTestHelper.getComponentTestContent(), |
---|
1423 | MediaType.APPLICATION_OCTET_STREAM_TYPE); |
---|
1424 | form.field(IComponentRegistryRestService.NAME_FORM_FIELD, |
---|
1425 | "ComponentTest1"); |
---|
1426 | form.field(IComponentRegistryRestService.DESCRIPTION_FORM_FIELD, |
---|
1427 | "My Test Component"); |
---|
1428 | form.field(IComponentRegistryRestService.DOMAIN_FORM_FIELD, |
---|
1429 | "TestDomain"); |
---|
1430 | form.field(IComponentRegistryRestService.GROUP_FORM_FIELD, "TestGroup"); |
---|
1431 | RegisterResponse response = getAuthenticatedResource( |
---|
1432 | "/registry/components").type(MediaType.MULTIPART_FORM_DATA) |
---|
1433 | .post(RegisterResponse.class, form); |
---|
1434 | assertTrue(response.isRegistered()); |
---|
1435 | assertFalse(response.isProfile()); |
---|
1436 | assertTrue(response.isPrivate()); |
---|
1437 | ComponentDescription desc = (ComponentDescription) response |
---|
1438 | .getDescription(); |
---|
1439 | assertNotNull(desc); |
---|
1440 | assertEquals("ComponentTest1", desc.getName()); |
---|
1441 | assertEquals("My Test Component", desc.getDescription()); |
---|
1442 | assertEquals(expectedUserId("JUnit@test.com"), desc.getUserId()); |
---|
1443 | assertEquals("Database test user", desc.getCreatorName()); |
---|
1444 | assertEquals("TestGroup", desc.getGroupName()); |
---|
1445 | assertEquals("TestDomain", desc.getDomainName()); |
---|
1446 | assertTrue(desc.getId() |
---|
1447 | .startsWith(ComponentRegistry.REGISTRY_ID + "c_")); |
---|
1448 | assertNotNull(desc.getRegistrationDate()); |
---|
1449 | String url = getResource().getUriBuilder().build().toString(); |
---|
1450 | assertEquals(url + "registry/components/" + desc.getId(), |
---|
1451 | desc.getHref()); |
---|
1452 | } |
---|
1453 | |
---|
1454 | @Test |
---|
1455 | public void testRegisterComment() throws Exception { |
---|
1456 | |
---|
1457 | System.out.println("testRegisterComponent"); |
---|
1458 | |
---|
1459 | fillUpPublicItems(); |
---|
1460 | |
---|
1461 | FormDataMultiPart form = new FormDataMultiPart(); |
---|
1462 | form.field(IComponentRegistryRestService.DATA_FORM_FIELD, |
---|
1463 | RegistryTestHelper.getCommentTestContent(), |
---|
1464 | MediaType.APPLICATION_OCTET_STREAM_TYPE); |
---|
1465 | String id = ProfileDescription.PROFILE_PREFIX + "profile1"; |
---|
1466 | CommentResponse response = getAuthenticatedResource( |
---|
1467 | "/registry/profiles/" + id + "/comments").type( |
---|
1468 | MediaType.MULTIPART_FORM_DATA) |
---|
1469 | .post(CommentResponse.class, form); |
---|
1470 | assertTrue(response.isRegistered()); |
---|
1471 | assertFalse(response.isPrivate()); |
---|
1472 | Comment comment = response.getComment(); |
---|
1473 | assertNotNull(comment); |
---|
1474 | assertEquals("Actual", comment.getComment()); |
---|
1475 | assertEquals("Database test user", comment.getUserName()); |
---|
1476 | Assert.notNull(comment.getCommentDate()); |
---|
1477 | Assert.hasText(comment.getId()); |
---|
1478 | |
---|
1479 | // User id should not be serialized! |
---|
1480 | assertEquals(0, comment.getUserId()); |
---|
1481 | } |
---|
1482 | |
---|
1483 | @Test |
---|
1484 | public void testRegisterCommentToNonExistent() throws Exception { |
---|
1485 | fillUpPublicItems(); |
---|
1486 | |
---|
1487 | FormDataMultiPart form = new FormDataMultiPart(); |
---|
1488 | form.field(IComponentRegistryRestService.DATA_FORM_FIELD, |
---|
1489 | RegistryTestHelper.getCommentTestContent(), |
---|
1490 | MediaType.APPLICATION_OCTET_STREAM_TYPE); |
---|
1491 | ClientResponse cResponse = getAuthenticatedResource( |
---|
1492 | "/registry/profiles/clarin.eu:cr1:profile99/comments").type( |
---|
1493 | MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form); |
---|
1494 | assertEquals(404, cResponse.getStatus()); |
---|
1495 | } |
---|
1496 | |
---|
1497 | @Test |
---|
1498 | public void testRegisterCommentUnauthenticated() throws Exception { |
---|
1499 | |
---|
1500 | System.out.println("testREgisterCommentUnauthentified"); |
---|
1501 | |
---|
1502 | fillUpPublicItems(); |
---|
1503 | |
---|
1504 | FormDataMultiPart form = new FormDataMultiPart(); |
---|
1505 | form.field(IComponentRegistryRestService.DATA_FORM_FIELD, |
---|
1506 | RegistryTestHelper.getCommentTestContent(), |
---|
1507 | MediaType.APPLICATION_OCTET_STREAM_TYPE); |
---|
1508 | ClientResponse cResponse = getResource() |
---|
1509 | .path("/registry/profiles/clarin.eu:cr1:profile1/comments") |
---|
1510 | .type(MediaType.MULTIPART_FORM_DATA) |
---|
1511 | .post(ClientResponse.class, form); |
---|
1512 | assertEquals(401, cResponse.getStatus()); |
---|
1513 | } |
---|
1514 | |
---|
1515 | @Test |
---|
1516 | public void testRegisterProfileInvalidData() throws Exception { |
---|
1517 | System.out.println("testRegisterProfileInvalidData"); |
---|
1518 | fillUpPrivateItems(); |
---|
1519 | FormDataMultiPart form = new FormDataMultiPart(); |
---|
1520 | String notAValidProfile = "<CMD_ComponentSpec> </CMD_ComponentSpec>"; |
---|
1521 | form.field(IComponentRegistryRestService.DATA_FORM_FIELD, |
---|
1522 | new ByteArrayInputStream(notAValidProfile.getBytes()), |
---|
1523 | MediaType.APPLICATION_OCTET_STREAM_TYPE); |
---|
1524 | form.field(IComponentRegistryRestService.NAME_FORM_FIELD, |
---|
1525 | "ProfileTest1"); |
---|
1526 | form.field(IComponentRegistryRestService.DOMAIN_FORM_FIELD, "Domain"); |
---|
1527 | form.field(IComponentRegistryRestService.GROUP_FORM_FIELD, "Group"); |
---|
1528 | form.field(IComponentRegistryRestService.DESCRIPTION_FORM_FIELD, |
---|
1529 | "My Test Profile"); |
---|
1530 | RegisterResponse postResponse = getAuthenticatedResource( |
---|
1531 | "/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post( |
---|
1532 | RegisterResponse.class, form); |
---|
1533 | assertTrue(postResponse.isProfile()); |
---|
1534 | assertFalse(postResponse.isRegistered()); |
---|
1535 | assertEquals(1, postResponse.getErrors().size()); |
---|
1536 | assertTrue(postResponse.getErrors().get(0).contains("isProfile")); |
---|
1537 | } |
---|
1538 | |
---|
1539 | /** |
---|
1540 | * Two elements on the same level with the same name violates schematron |
---|
1541 | * rule, and should fail validation |
---|
1542 | * |
---|
1543 | * @throws Exception |
---|
1544 | */ |
---|
1545 | @Test |
---|
1546 | public void testRegisterInvalidProfile() throws Exception { |
---|
1547 | System.out.println("testRegisterInvalidProfile"); |
---|
1548 | fillUpPrivateItems(); |
---|
1549 | FormDataMultiPart form = new FormDataMultiPart(); |
---|
1550 | String profileContent = ""; |
---|
1551 | profileContent += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; |
---|
1552 | profileContent += "<CMD_ComponentSpec isProfile=\"true\" xmlns:xml=\"http://www.w3.org/XML/1998/namespace\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"; |
---|
1553 | profileContent += " xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n"; |
---|
1554 | profileContent += " <Header />\n"; |
---|
1555 | profileContent += " <CMD_Component name=\"ProfileTest1\" CardinalityMin=\"0\" CardinalityMax=\"unbounded\">\n"; |
---|
1556 | profileContent += " <CMD_Element name=\"Age\">\n"; |
---|
1557 | profileContent += " <ValueScheme>\n"; |
---|
1558 | profileContent += " <pattern>[23][0-9]</pattern>\n"; |
---|
1559 | profileContent += " </ValueScheme>\n"; |
---|
1560 | profileContent += " </CMD_Element>\n"; |
---|
1561 | profileContent += " <CMD_Element name=\"Age\">\n"; |
---|
1562 | profileContent += " <ValueScheme>\n"; |
---|
1563 | profileContent += " <pattern>[23][0-9]</pattern>\n"; |
---|
1564 | profileContent += " </ValueScheme>\n"; |
---|
1565 | profileContent += " </CMD_Element>\n"; |
---|
1566 | profileContent += " </CMD_Component>\n"; |
---|
1567 | profileContent += "</CMD_ComponentSpec>\n"; |
---|
1568 | form.field(IComponentRegistryRestService.DATA_FORM_FIELD, |
---|
1569 | RegistryTestHelper.getComponentContentAsStream(profileContent), |
---|
1570 | MediaType.APPLICATION_OCTET_STREAM_TYPE); |
---|
1571 | form.field(IComponentRegistryRestService.NAME_FORM_FIELD, |
---|
1572 | "ProfileTest1"); |
---|
1573 | form.field(IComponentRegistryRestService.DOMAIN_FORM_FIELD, |
---|
1574 | "TestDomain"); |
---|
1575 | form.field(IComponentRegistryRestService.DESCRIPTION_FORM_FIELD, |
---|
1576 | "My Test Profile"); |
---|
1577 | form.field(IComponentRegistryRestService.GROUP_FORM_FIELD, |
---|
1578 | "My Test Group"); |
---|
1579 | RegisterResponse response = getAuthenticatedResource( |
---|
1580 | "/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post( |
---|
1581 | RegisterResponse.class, form); |
---|
1582 | assertFalse( |
---|
1583 | "Subsequent elements should not be allowed to have the same name", |
---|
1584 | response.isRegistered()); |
---|
1585 | assertTrue(response.getErrors().get(0) |
---|
1586 | .contains(MDValidator.PARSE_ERROR)); |
---|
1587 | } |
---|
1588 | |
---|
1589 | @Test |
---|
1590 | public void testRegisterProfileInvalidDescriptionAndContent() |
---|
1591 | throws Exception { |
---|
1592 | System.out.println("testRegisterProfileInvalidDescriptionAndContent"); |
---|
1593 | fillUpPrivateItems(); |
---|
1594 | FormDataMultiPart form = new FormDataMultiPart(); |
---|
1595 | String profileContent = ""; |
---|
1596 | profileContent += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; |
---|
1597 | profileContent += "<CMD_ComponentSpec> \n"; // No isProfile attribute |
---|
1598 | profileContent += " <Header />\n"; |
---|
1599 | profileContent += " <CMD_Component name=\"Actor\" CardinalityMin=\"0\" CardinalityMax=\"unbounded\">\n"; |
---|
1600 | profileContent += " <AttributeList>\n"; |
---|
1601 | profileContent += " <Attribute>\n"; |
---|
1602 | profileContent += " <Name>Name</Name>\n"; |
---|
1603 | profileContent += " <Type>string</Type>\n"; |
---|
1604 | profileContent += " </Attribute>\n"; |
---|
1605 | profileContent += " </AttributeList>\n"; |
---|
1606 | profileContent += " </CMD_Component>\n"; |
---|
1607 | profileContent += "</CMD_ComponentSpec>\n"; |
---|
1608 | form.field("data", new ByteArrayInputStream(profileContent.getBytes()), |
---|
1609 | MediaType.APPLICATION_OCTET_STREAM_TYPE); |
---|
1610 | form.field("name", "");// Empty name so invalid |
---|
1611 | form.field("description", "My Test Profile"); |
---|
1612 | RegisterResponse response = getAuthenticatedResource( |
---|
1613 | "/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post( |
---|
1614 | RegisterResponse.class, form); |
---|
1615 | assertFalse(response.isRegistered()); |
---|
1616 | assertEquals(2, response.getErrors().size()); |
---|
1617 | assertNotNull(response.getErrors().get(0)); |
---|
1618 | assertEquals(MDValidator.PARSE_ERROR, response.getErrors().get(1) |
---|
1619 | .substring(0, MDValidator.PARSE_ERROR.length())); |
---|
1620 | } |
---|
1621 | |
---|
1622 | @Test |
---|
1623 | public void testRegisterLargeProfile() throws Exception { |
---|
1624 | System.out.println("testRegisterLargeProfile"); |
---|
1625 | //fillUpPrivateItems(); not necessary |
---|
1626 | FormDataMultiPart form = new FormDataMultiPart(); |
---|
1627 | form.field(IComponentRegistryRestService.DATA_FORM_FIELD, |
---|
1628 | RegistryTestHelper.getLargeProfileContent(), |
---|
1629 | MediaType.APPLICATION_OCTET_STREAM_TYPE); |
---|
1630 | form.field(IComponentRegistryRestService.NAME_FORM_FIELD, |
---|
1631 | "ProfileTest1"); |
---|
1632 | form.field(IComponentRegistryRestService.DOMAIN_FORM_FIELD, |
---|
1633 | "TestDomain"); |
---|
1634 | form.field(IComponentRegistryRestService.DESCRIPTION_FORM_FIELD, |
---|
1635 | "My Test Profile"); |
---|
1636 | form.field(IComponentRegistryRestService.GROUP_FORM_FIELD, |
---|
1637 | "My Test Group"); |
---|
1638 | ClientResponse response = getAuthenticatedResource("/registry/profiles") |
---|
1639 | .type(MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, |
---|
1640 | form); |
---|
1641 | assertEquals(200, response.getStatus()); |
---|
1642 | } |
---|
1643 | |
---|
1644 | @Test |
---|
1645 | public void testRegisterComponentAsProfile() throws Exception { |
---|
1646 | System.out.println("tesRegisterComponentAsProfile"); |
---|
1647 | //fillUpPrivateItems();; not necessary |
---|
1648 | FormDataMultiPart form = new FormDataMultiPart(); |
---|
1649 | form.field(IComponentRegistryRestService.DATA_FORM_FIELD, |
---|
1650 | RegistryTestHelper.getComponentTestContent(), |
---|
1651 | MediaType.APPLICATION_OCTET_STREAM_TYPE); |
---|
1652 | form.field(IComponentRegistryRestService.NAME_FORM_FIELD, "t"); |
---|
1653 | form.field(IComponentRegistryRestService.DOMAIN_FORM_FIELD, "domain"); |
---|
1654 | form.field(IComponentRegistryRestService.DESCRIPTION_FORM_FIELD, |
---|
1655 | "My Test"); |
---|
1656 | form.field(IComponentRegistryRestService.GROUP_FORM_FIELD, "My Group"); |
---|
1657 | RegisterResponse response = getAuthenticatedResource( |
---|
1658 | "/registry/profiles").type(MediaType.MULTIPART_FORM_DATA).post( |
---|
1659 | RegisterResponse.class, form); |
---|
1660 | assertFalse(response.isRegistered()); |
---|
1661 | assertTrue(response.isProfile()); |
---|
1662 | assertEquals(1, response.getErrors().size()); |
---|
1663 | assertEquals(MDValidator.MISMATCH_ERROR, response.getErrors().get(0)); |
---|
1664 | } |
---|
1665 | |
---|
1666 | /** |
---|
1667 | * creates a tree-like component, whose root has two kids, and the kids have |
---|
1668 | * three their own kids each the corresponding filenames are: "wortel", |
---|
1669 | * "nodel-L", "node-R", "leaf-LL", "leaf-LM", "leaf-LR", "leaf-RL", |
---|
1670 | * "leaf-RM", "leaf-RR" |
---|
1671 | * |
---|
1672 | * @throws Exception |
---|
1673 | */ |
---|
1674 | @Test |
---|
1675 | public void testSetFilenamesToNull() throws Exception { |
---|
1676 | System.out.println("testSetfilenamesTonull"); |
---|
1677 | // helper assists in generating a test component |
---|
1678 | CMDComponentSetFilenamesToNullTestRunner helper = new CMDComponentSetFilenamesToNullTestRunner(); |
---|
1679 | |
---|
1680 | // making an (up to ternary) tree of test components |
---|
1681 | // inductive explaination of the variable names, an example: leaf-LM is |
---|
1682 | // the middle child of the nodeL |
---|
1683 | // the filename is this leaf is "leaf-LM" |
---|
1684 | |
---|
1685 | // making children of the node L |
---|
1686 | CMDComponentType leafLR = helper.makeTestComponent("leaf-LR", null); |
---|
1687 | CMDComponentType leafLM = helper.makeTestComponent("leaf-LM", null); |
---|
1688 | CMDComponentType leafLL = helper.makeTestComponent("leaf-LL", null); |
---|
1689 | |
---|
1690 | // making node L |
---|
1691 | List<CMDComponentType> nodeLchild = (new ArrayList<CMDComponentType>()); |
---|
1692 | nodeLchild.add(leafLL); |
---|
1693 | nodeLchild.add(leafLM); |
---|
1694 | nodeLchild.add(leafLR); |
---|
1695 | CMDComponentType nodeL = helper.makeTestComponent("node-L", nodeLchild); |
---|
1696 | |
---|
1697 | // making children of the node R |
---|
1698 | CMDComponentType leafRR = helper.makeTestComponent("leaf-RR", null); |
---|
1699 | CMDComponentType leafRM = helper.makeTestComponent("leaf-RM", null); |
---|
1700 | CMDComponentType leafRL = helper.makeTestComponent("leaf-RL", null); |
---|
1701 | |
---|
1702 | // making node R |
---|
1703 | List<CMDComponentType> nodeRchild = (new ArrayList<CMDComponentType>()); |
---|
1704 | nodeRchild.add(leafRL); |
---|
1705 | nodeRchild.add(leafRM); |
---|
1706 | nodeRchild.add(leafRR); |
---|
1707 | CMDComponentType nodeR = helper.makeTestComponent("node-R", nodeRchild); |
---|
1708 | |
---|
1709 | // making the root, which has children NodeL and nodeR |
---|
1710 | List<CMDComponentType> wortelchild = (new ArrayList<CMDComponentType>()); |
---|
1711 | wortelchild.add(nodeL); |
---|
1712 | wortelchild.add(nodeR); |
---|
1713 | CMDComponentType root = helper.makeTestComponent("wortel", wortelchild); |
---|
1714 | |
---|
1715 | // checking if the test compnent has the expected structure and the |
---|
1716 | // expected filenames |
---|
1717 | // ALSO this checking code below shows the strtucture of the tree |
---|
1718 | |
---|
1719 | assertEquals(root.getCMDComponent().size(), 2); |
---|
1720 | assertEquals(root.getCMDComponent().get(0).getCMDComponent().size(), 3); |
---|
1721 | assertEquals(root.getCMDComponent().get(1).getCMDComponent().size(), 3); |
---|
1722 | |
---|
1723 | assertEquals(root.getFilename(), "wortel"); |
---|
1724 | |
---|
1725 | assertEquals(root.getCMDComponent().get(0).getFilename(), "node-L"); |
---|
1726 | assertEquals(root.getCMDComponent().get(1).getFilename(), "node-R"); |
---|
1727 | |
---|
1728 | assertEquals(root.getCMDComponent().get(0).getCMDComponent().get(0) |
---|
1729 | .getFilename(), "leaf-LL"); |
---|
1730 | assertEquals(root.getCMDComponent().get(0).getCMDComponent().get(1) |
---|
1731 | .getFilename(), "leaf-LM"); |
---|
1732 | assertEquals(root.getCMDComponent().get(0).getCMDComponent().get(2) |
---|
1733 | .getFilename(), "leaf-LR"); |
---|
1734 | |
---|
1735 | assertEquals(root.getCMDComponent().get(1).getCMDComponent().get(0) |
---|
1736 | .getFilename(), "leaf-RL"); |
---|
1737 | assertEquals(root.getCMDComponent().get(1).getCMDComponent().get(1) |
---|
1738 | .getFilename(), "leaf-RM"); |
---|
1739 | assertEquals(root.getCMDComponent().get(1).getCMDComponent().get(2) |
---|
1740 | .getFilename(), "leaf-RR"); |
---|
1741 | |
---|
1742 | // the actual job |
---|
1743 | // nulling the filenames will be called as a method of testrestservice |
---|
1744 | ComponentRegistryRestService restservice = new ComponentRegistryRestService(); |
---|
1745 | restservice.setFileNamesToNullCurrent(root); |
---|
1746 | |
---|
1747 | // check if the filenames are nulled |
---|
1748 | assertEquals(root.getFilename(), null); |
---|
1749 | |
---|
1750 | assertEquals(root.getCMDComponent().get(0).getFilename(), null); |
---|
1751 | assertEquals(root.getCMDComponent().get(1).getFilename(), null); |
---|
1752 | |
---|
1753 | assertEquals(root.getCMDComponent().get(0).getCMDComponent().get(0) |
---|
1754 | .getFilename(), null); |
---|
1755 | assertEquals(root.getCMDComponent().get(0).getCMDComponent().get(1) |
---|
1756 | .getFilename(), null); |
---|
1757 | assertEquals(root.getCMDComponent().get(0).getCMDComponent().get(2) |
---|
1758 | .getFilename(), null); |
---|
1759 | |
---|
1760 | assertEquals(root.getCMDComponent().get(1).getCMDComponent().get(0) |
---|
1761 | .getFilename(), null); |
---|
1762 | assertEquals(root.getCMDComponent().get(1).getCMDComponent().get(1) |
---|
1763 | .getFilename(), null); |
---|
1764 | assertEquals(root.getCMDComponent().get(1).getCMDComponent().get(2) |
---|
1765 | .getFilename(), null); |
---|
1766 | } |
---|
1767 | |
---|
1768 | @Test |
---|
1769 | public void testGetDescription() throws Exception { |
---|
1770 | System.out.println("testGetDescription"); |
---|
1771 | fillUpPublicItems(); |
---|
1772 | String id = ComponentDescription.COMPONENT_PREFIX + "component1"; |
---|
1773 | ComponentDescription component = getAuthenticatedResource(getResource().path("/registry/items/" + id)).accept(MediaType.APPLICATION_JSON).get(ComponentDescription.class); |
---|
1774 | assertNotNull(component); |
---|
1775 | assertEquals(id, component.getId()); |
---|
1776 | assertEquals("component1", component.getName()); |
---|
1777 | assertEquals("Test Description", component.getDescription()); |
---|
1778 | |
---|
1779 | } |
---|
1780 | } |
---|