Changeset 5549 for ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestServiceTest.java
- Timestamp:
- 08/11/14 16:07:55 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestServiceTest.java
r4550 r5549 3 3 import clarin.cmdi.componentregistry.ComponentRegistry; 4 4 import clarin.cmdi.componentregistry.ComponentRegistryFactory; 5 import clarin.cmdi.componentregistry.ComponentStatus;6 5 import clarin.cmdi.componentregistry.components.CMDComponentSpec; 7 6 import clarin.cmdi.componentregistry.components.CMDComponentType; … … 14 13 import clarin.cmdi.componentregistry.model.ProfileDescription; 15 14 import clarin.cmdi.componentregistry.model.RegisterResponse; 16 import static clarin.cmdi.componentregistry.rest.ComponentRegistryRestService. USERSPACE_PARAM;15 import static clarin.cmdi.componentregistry.rest.ComponentRegistryRestService.REGISTRY_SPACE_PARAM; 17 16 18 17 import com.sun.jersey.api.client.ClientResponse; … … 32 31 33 32 import org.junit.Before; 33 import org.junit.Ignore; 34 34 import org.junit.Test; 35 35 import org.springframework.beans.factory.annotation.Autowired; … … 53 53 @Autowired 54 54 private JdbcTemplate jdbcTemplate; 55 private ComponentRegistry testRegistry;55 private ComponentRegistry baseRegistry; 56 56 57 57 @Before … … 59 59 ComponentRegistryTestDatabase.resetAndCreateAllTables(jdbcTemplate); 60 60 createUserRecord(); 61 // Get public component registry 62 testRegistry = componentRegistryBeanFactory.getNewComponentRegistry(); 63 } 64 65 private ComponentRegistry getTestRegistry() { 66 return testRegistry; 61 baseRegistry = componentRegistryFactory.getBaseRegistry(DummyPrincipal.DUMMY_CREDENTIALS); 67 62 } 68 63 … … 76 71 private ProfileDescription profile2; 77 72 73 private ComponentDescription component3; 74 private ProfileDescription profile3; 75 78 76 private Comment profile1Comment1; 79 77 private Comment profile1Comment2; 80 78 private Comment component1Comment3; 81 79 private Comment component1Comment4; 82 83 private void fillUp() throws Exception { 84 profile1 = RegistryTestHelper.addProfile(getTestRegistry(), "profile2"); 85 profile2 = RegistryTestHelper.addProfile(getTestRegistry(), "profile1"); 86 component1 = RegistryTestHelper.addComponent(getTestRegistry(), 87 "component2"); 88 component2 = RegistryTestHelper.addComponent(getTestRegistry(), 89 "component1"); 90 profile1Comment2 = RegistryTestHelper.addComment(getTestRegistry(), "comment2", 80 81 private Comment profile3Comment5; 82 private Comment component3Comment7; 83 84 private void fillUpPublicItems() throws Exception { 85 86 profile1 = RegistryTestHelper.addProfile(baseRegistry, "profile2", true); 87 profile2 = RegistryTestHelper.addProfile(baseRegistry, "profile1", true); 88 component1 = RegistryTestHelper.addComponent(baseRegistry, 89 "component2", true); 90 component2 = RegistryTestHelper.addComponent(baseRegistry, 91 "component1", true); 92 profile1Comment2 = RegistryTestHelper.addComment(baseRegistry, "comment2", 91 93 ProfileDescription.PROFILE_PREFIX + "profile1", 92 94 "JUnit@test.com"); 93 profile1Comment1 = RegistryTestHelper.addComment( getTestRegistry(), "comment1",95 profile1Comment1 = RegistryTestHelper.addComment(baseRegistry, "comment1", 94 96 ProfileDescription.PROFILE_PREFIX + "profile1", 95 97 "JUnit@test.com"); 96 component1Comment3 = RegistryTestHelper.addComment( getTestRegistry(), "comment3",98 component1Comment3 = RegistryTestHelper.addComment(baseRegistry, "comment3", 97 99 ComponentDescription.COMPONENT_PREFIX + "component1", 98 100 "JUnit@test.com"); 99 component1Comment4 = RegistryTestHelper.addComment( getTestRegistry(), "comment4",101 component1Comment4 = RegistryTestHelper.addComment(baseRegistry, "comment4", 100 102 ComponentDescription.COMPONENT_PREFIX + "component1", 101 103 "JUnit@test.com"); 102 104 } 103 104 @Test 105 public void testGetRegisteredProfiles() throws Exception { 106 fillUp(); 107 RegistryTestHelper.addProfile(getTestRegistry(), "PROFILE2"); 108 List<ProfileDescription> response = getResource() 109 .path("/registry/profiles").accept(MediaType.APPLICATION_XML) 105 106 private void fillUpPrivateItems() throws Exception { 107 profile3 = RegistryTestHelper.addProfile(baseRegistry, "profile3", false); 108 component3 = RegistryTestHelper.addComponent(baseRegistry, 109 "component3", false); 110 profile3Comment5 = RegistryTestHelper.addComment(baseRegistry, "comment5", 111 ProfileDescription.PROFILE_PREFIX + "profile3", 112 "JUnit@test.com"); 113 component3Comment7 = RegistryTestHelper.addComment(baseRegistry, "comment7", 114 ComponentDescription.COMPONENT_PREFIX + "component3", 115 "JUnit@test.com"); 116 } 117 118 @Test//ok 119 public void testGetPublicProfiles() throws Exception { 120 121 fillUpPublicItems(); 122 123 RegistryTestHelper.addProfile(baseRegistry, "PROFILE2", true); 124 List<ProfileDescription> response = this.getAuthenticatedResource(getResource() 125 .path("/registry/profiles")).accept(MediaType.APPLICATION_XML) 110 126 .get(PROFILE_LIST_GENERICTYPE); 111 127 assertEquals(3, response.size()); 112 response = getResource().path("/registry/profiles") 128 response = this.getAuthenticatedResource(getResource() 129 .path("/registry/profiles")) 113 130 .accept(MediaType.APPLICATION_JSON) 114 131 .get(PROFILE_LIST_GENERICTYPE); … … 119 136 } 120 137 121 @Test 122 public void testGetRegisteredComponents() throws Exception { 123 fillUp(); 124 RegistryTestHelper.addComponent(getTestRegistry(), "COMPONENT2"); 125 List<ComponentDescription> response = getResource() 126 .path("/registry/components").accept(MediaType.APPLICATION_XML) 138 @Test //ok 139 public void testGetPublicComponents() throws Exception { 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) 127 146 .get(COMPONENT_LIST_GENERICTYPE); 128 147 assertEquals(3, response.size()); 129 response = getResource().path("/registry/components") 148 response = this.getAuthenticatedResource(getResource() 149 .path("/registry/components")) 130 150 .accept(MediaType.APPLICATION_JSON) 131 151 .get(COMPONENT_LIST_GENERICTYPE); … … 136 156 } 137 157 138 @Test 158 @Test //ok 139 159 public void testGetUserComponents() throws Exception { 140 fillUp(); 141 List<ComponentDescription> response = getUserComponents(); 142 assertEquals(0, response.size()); 143 response = getAuthenticatedResource( 144 getResource().path("/registry/components")).accept( 160 161 fillUpPrivateItems(); 162 163 List<ComponentDescription> response = this.getUserComponents(); 164 assertEquals(1, response.size()); 165 166 //// 167 168 fillUpPublicItems(); 169 response = getAuthenticatedResource(getResource().path("/registry/components")).accept( 145 170 MediaType.APPLICATION_JSON).get(COMPONENT_LIST_GENERICTYPE); 146 171 assertEquals("Get public components", 2, response.size()); 172 147 173 ClientResponse cResponse = getResource().path("/registry/components") 148 .queryParam( USERSPACE_PARAM, "true")174 .queryParam(REGISTRY_SPACE_PARAM, "private") 149 175 .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); 150 176 assertEquals("Trying to get userspace without credentials", 401, … … 152 178 } 153 179 154 @Test 155 public void testGetRegisteredComponent() throws Exception { 156 fillUp(); 157 String id = ComponentDescription.COMPONENT_PREFIX + "component1"; 180 @Test //ok 181 public void testGetPublicComponent() throws Exception { 182 183 fillUpPublicItems(); 184 185 String id = ComponentDescription.COMPONENT_PREFIX + "component1"; 158 186 String id2 = ComponentDescription.COMPONENT_PREFIX + "component2"; 159 CMDComponentSpec component = getResource()160 .path("/registry/components/" + id) 187 CMDComponentSpec component = this.getAuthenticatedResource(getResource() 188 .path("/registry/components/" + id)) 161 189 .accept(MediaType.APPLICATION_JSON).get(CMDComponentSpec.class); 162 190 assertNotNull(component); 163 191 assertEquals("Access", component.getCMDComponent().getName()); 164 component = getResource().path("/registry/components/" + id2) 192 193 194 component = this.getAuthenticatedResource(getResource().path("/registry/components/" + id2)) 165 195 .accept(MediaType.APPLICATION_XML).get(CMDComponentSpec.class); 166 196 assertNotNull(component); 167 197 assertEquals("Access", component.getCMDComponent().getName()); 168 169 198 assertEquals(id2, component.getHeader().getID()); 170 199 assertEquals("component2", component.getHeader().getName()); … … 172 201 } 173 202 174 @Test 175 public void testGetRegisteredCommentsInProfile() throws Exception { 176 fillUp(); 203 @Test // ok 204 public void testGetCommentsInPublicProfile() throws Exception { 205 206 fillUpPublicItems(); 207 177 208 String id = ProfileDescription.PROFILE_PREFIX + "profile1"; 178 RegistryTestHelper.addComment( getTestRegistry(), "COMMENT1", id,209 RegistryTestHelper.addComment(baseRegistry, "COMMENT1", id, 179 210 "JUnit@test.com"); 180 List<Comment> response = getResource()181 .path("/registry/profiles/" + id + "/comments/") 211 List<Comment> response = this.getAuthenticatedResource(getResource() 212 .path("/registry/profiles/" + id + "/comments/")) 182 213 .accept(MediaType.APPLICATION_XML) 183 214 .get(COMMENT_LIST_GENERICTYPE); 184 215 assertEquals(3, response.size()); 185 response = getResource().path("/registry/profiles/" + id + "/comments") 216 217 response = this.getAuthenticatedResource(getResource().path("/registry/profiles/" + id + "/comments")) 186 218 .accept(MediaType.APPLICATION_JSON) 187 219 .get(COMMENT_LIST_GENERICTYPE); … … 194 226 } 195 227 196 @Test 197 public void testGetRegisteredCommentsInComponent() throws Exception { 198 fillUp(); 228 @Test // ok 229 public void testGetCommentsInPubliComponent() throws Exception { 230 fillUpPublicItems(); 231 199 232 String id = ComponentDescription.COMPONENT_PREFIX + "component1"; 200 RegistryTestHelper.addComment( getTestRegistry(), "COMMENT2", id,233 RegistryTestHelper.addComment(baseRegistry, "COMMENT2", id, 201 234 "JUnit@test.com"); 202 List<Comment> response = getResource()203 .path("/registry/components/" + id + "/comments/") 235 List<Comment> response = this.getAuthenticatedResource(getResource() 236 .path("/registry/components/" + id + "/comments/")) 204 237 .accept(MediaType.APPLICATION_XML) 205 238 .get(COMMENT_LIST_GENERICTYPE); 206 239 assertEquals(3, response.size()); 207 response = getResource()208 .path("/registry/components/" + id + "/comments") 240 response = this.getAuthenticatedResource(getResource() 241 .path("/registry/components/" + id + "/comments")) 209 242 .accept(MediaType.APPLICATION_JSON) 210 243 .get(COMMENT_LIST_GENERICTYPE); … … 217 250 } 218 251 219 @Test 220 public void testGetSpecifiedCommentInComponent() throws Exception { 221 fillUp(); 252 @Test // ok 253 public void testGetSpecifiedCommentInPublicComponent() throws Exception { 254 255 fillUpPublicItems(); 256 222 257 String id = ComponentDescription.COMPONENT_PREFIX + "component1"; 223 Comment comment = getResource()224 .path("/registry/components/" + id + "/comments/"+component1Comment3.getId()) 258 Comment comment = this.getAuthenticatedResource(getResource() 259 .path("/registry/components/" + id + "/comments/"+component1Comment3.getId())) 225 260 .accept(MediaType.APPLICATION_JSON).get(Comment.class); 226 261 assertNotNull(comment); 227 262 assertEquals("comment3", comment.getComment()); 228 263 assertEquals(component1Comment3.getId(), comment.getId()); 229 comment = getResource()230 .path("/registry/components/" + id + "/comments/"+component1Comment4.getId()) 264 comment = this.getAuthenticatedResource(getResource() 265 .path("/registry/components/" + id + "/comments/"+component1Comment4.getId())) 231 266 .accept(MediaType.APPLICATION_JSON).get(Comment.class); 232 267 assertNotNull(comment); … … 236 271 } 237 272 238 @Test 239 public void testGetSpecifiedCommentInProfile() throws Exception { 240 fillUp(); 273 @Test //ok 274 public void testGetSpecifiedCommentInPublicProfile() throws Exception { 275 276 fillUpPublicItems(); 277 241 278 String id = ProfileDescription.PROFILE_PREFIX + "profile1"; 242 Comment comment = getResource()243 .path("/registry/profiles/" + id + "/comments/"+profile1Comment2.getId()) 279 Comment comment = this.getAuthenticatedResource(getResource() 280 .path("/registry/profiles/" + id + "/comments/"+profile1Comment2.getId())) 244 281 .accept(MediaType.APPLICATION_JSON).get(Comment.class); 245 282 assertNotNull(comment); 246 283 assertEquals("comment2", comment.getComment()); 247 284 assertEquals(profile1Comment2.getId(), comment.getId()); 248 comment = getResource() 249 .path("/registry/profiles/" + id + "/comments/"+profile1Comment1.getId()) 250 .accept(MediaType.APPLICATION_JSON).get(Comment.class); 285 286 comment = this.getAuthenticatedResource(getResource() 287 .path("/registry/profiles/" + id + "/comments/"+profile1Comment1.getId())) 288 .accept(MediaType.APPLICATION_JSON).get(Comment.class); 251 289 assertNotNull(comment); 252 290 assertEquals("comment1", comment.getComment()); … … 255 293 } 256 294 257 @Test 258 public void testDeleteCommentFromComponent() throws Exception { 259 fillUp(); 295 @Test //ok 296 public void testDeleteCommentFromPublicComponent() throws Exception { 297 298 fillUpPublicItems(); 299 260 300 String id = ComponentDescription.COMPONENT_PREFIX + "component1"; 261 301 String id2 = ComponentDescription.COMPONENT_PREFIX + "component2"; 262 List<Comment> comments = getResource().path(263 "/registry/components/" + id + "/comments") .get(302 List<Comment> comments = this.getAuthenticatedResource(getResource().path( 303 "/registry/components/" + id + "/comments")).get( 264 304 COMMENT_LIST_GENERICTYPE); 265 305 assertEquals(2, comments.size()); 266 Comment aComment = getResource().path(267 "/registry/components/" + id + "/comments/"+component1Comment3.getId()) 306 Comment aComment = this.getAuthenticatedResource(getResource().path( 307 "/registry/components/" + id + "/comments/"+component1Comment3.getId())) 268 308 .get(Comment.class); 269 309 assertNotNull(aComment); … … 280 320 assertEquals(200, response.getStatus()); 281 321 282 comments = getResource().path(283 "/registry/components/" + id + "/comments/") .get(322 comments = this.getAuthenticatedResource(getResource().path( 323 "/registry/components/" + id + "/comments/")).get( 284 324 COMMENT_LIST_GENERICTYPE); 285 325 assertEquals(1, comments.size()); … … 290 330 assertEquals(200, response.getStatus()); 291 331 292 comments = getResource().path(293 "/registry/components/" + id + "/comments") .get(332 comments = this.getAuthenticatedResource(getResource().path( 333 "/registry/components/" + id + "/comments")).get( 294 334 COMMENT_LIST_GENERICTYPE); 295 335 assertEquals(0, comments.size()); … … 297 337 298 338 @Test 299 public void testManipulateCommentFromComponent() throws Exception { 300 fillUp(); 301 List<Comment> comments = getResource().path( 339 public void testManipulateCommentFromPublicComponent() throws Exception { 340 341 fillUpPublicItems(); 342 343 List<Comment> comments = this.getAuthenticatedResource(getResource().path( 302 344 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX 303 + "component1/comments") .get(COMMENT_LIST_GENERICTYPE);345 + "component1/comments")).get(COMMENT_LIST_GENERICTYPE); 304 346 assertEquals(2, comments.size()); 305 Comment aComment = getResource().path(347 Comment aComment = this.getAuthenticatedResource(getResource().path( 306 348 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX 307 + "component1/comments/"+component1Comment3.getId()) .get(Comment.class);349 + "component1/comments/"+component1Comment3.getId())).get(Comment.class); 308 350 assertNotNull(aComment); 309 351 … … 318 360 assertEquals(200, response.getStatus()); 319 361 320 comments = getResource().path(362 comments = this.getAuthenticatedResource(getResource().path( 321 363 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX 322 + "component1/comments/") .get(COMMENT_LIST_GENERICTYPE);364 + "component1/comments/")).get(COMMENT_LIST_GENERICTYPE); 323 365 assertEquals(1, comments.size()); 324 366 } 325 367 326 368 @Test 327 public void testDeleteCommentFromProfile() throws Exception { 328 fillUp(); 329 List<Comment> comments = getResource().path( 369 public void testDeleteCommentFromPublicProfile() throws Exception { 370 371 fillUpPublicItems(); 372 373 List<Comment> comments = this.getAuthenticatedResource(getResource().path( 330 374 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 331 + "profile1/comments") .get(COMMENT_LIST_GENERICTYPE);375 + "profile1/comments")).get(COMMENT_LIST_GENERICTYPE); 332 376 assertEquals(2, comments.size()); 333 Comment aComment = getResource().path(377 Comment aComment = this.getAuthenticatedResource(getResource().path( 334 378 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 335 + "profile1/comments/"+profile1Comment1.getId()) .get(Comment.class);379 + "profile1/comments/"+profile1Comment1.getId())).get(Comment.class); 336 380 assertNotNull(aComment); 337 381 … … 347 391 assertEquals(200, response.getStatus()); 348 392 349 comments = getResource().path(393 comments = this.getAuthenticatedResource(getResource().path( 350 394 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 351 + "profile1/comments/") .get(COMMENT_LIST_GENERICTYPE);395 + "profile1/comments/")).get(COMMENT_LIST_GENERICTYPE); 352 396 assertEquals(1, comments.size()); 353 397 … … 357 401 assertEquals(200, response.getStatus()); 358 402 359 comments = getResource().path(403 comments = this.getAuthenticatedResource(getResource().path( 360 404 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 361 + "profile1/comments") .get(COMMENT_LIST_GENERICTYPE);405 + "profile1/comments")).get(COMMENT_LIST_GENERICTYPE); 362 406 assertEquals(0, comments.size()); 363 407 } 364 408 365 409 @Test 366 public void testManipulateCommentFromProfile() throws Exception { 367 fillUp(); 368 List<Comment> comments = getResource().path( 410 public void testManipulateCommentFromPublicProfile() throws Exception { 411 412 fillUpPublicItems(); 413 414 List<Comment> comments = this.getAuthenticatedResource(getResource().path( 369 415 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 370 + "profile1/comments") .get(COMMENT_LIST_GENERICTYPE);416 + "profile1/comments")).get(COMMENT_LIST_GENERICTYPE); 371 417 assertEquals(2, comments.size()); 372 Comment aComment = getResource().path(418 Comment aComment = this.getAuthenticatedResource(getResource().path( 373 419 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 374 + "profile1/comments/"+profile1Comment2.getId()) .get(Comment.class);420 + "profile1/comments/"+profile1Comment2.getId())).get(Comment.class); 375 421 assertNotNull(aComment); 376 422 … … 384 430 assertEquals(200, response.getStatus()); 385 431 386 comments = getResource().path(432 comments = this.getAuthenticatedResource(getResource().path( 387 433 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 388 + "profile1/comments/") .get(COMMENT_LIST_GENERICTYPE);434 + "profile1/comments/")).get(COMMENT_LIST_GENERICTYPE); 389 435 assertEquals(1, comments.size()); 390 436 } 391 437 392 438 @Test 393 public void testDeleteRegisteredComponent() throws Exception { 394 fillUp(); 395 List<ComponentDescription> components = getResource().path( 396 "/registry/components").get(COMPONENT_LIST_GENERICTYPE); 439 public void testDeletePublicComponent() throws Exception { 440 441 fillUpPublicItems(); 442 443 List<ComponentDescription> components = this.getAuthenticatedResource(getResource().path( 444 "/registry/components")).get(COMPONENT_LIST_GENERICTYPE); 397 445 assertEquals(2, components.size()); 398 CMDComponentSpec profile = getResource().path(446 CMDComponentSpec profile = this.getAuthenticatedResource(getResource().path( 399 447 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX 400 + "component1") .get(CMDComponentSpec.class);448 + "component1")).get(CMDComponentSpec.class); 401 449 assertNotNull(profile); 402 450 ClientResponse response = getAuthenticatedResource( … … 405 453 assertEquals(200, response.getStatus()); 406 454 407 components = getResource().path("/registry/components").get(455 components = this.getAuthenticatedResource(getResource().path("/registry/components")).get( 408 456 COMPONENT_LIST_GENERICTYPE); 409 457 assertEquals(1, components.size()); … … 414 462 assertEquals(200, response.getStatus()); 415 463 416 components = getResource().path("/registry/components").get(464 components = this.getAuthenticatedResource(getResource().path("/registry/components")).get( 417 465 COMPONENT_LIST_GENERICTYPE); 418 466 assertEquals(0, components.size()); … … 425 473 426 474 @Test 427 public void testDeleteRegisteredComponentStillUsed() throws Exception { 428 String content = ""; 475 public void testDeletePublicComponentStillUsed() throws Exception { 476 477 fillUpPublicItems(); 478 479 String content = ""; 429 480 content += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"; 430 481 content += " xsi:noNamespaceSchemaLocation=\"general-component-schema.xsd\">\n"; … … 435 486 content += "</CMD_ComponentSpec>\n"; 436 487 ComponentDescription compDesc1 = RegistryTestHelper.addComponent( 437 getTestRegistry(), "XXX1", content);488 baseRegistry, "XXX1", content, true); 438 489 439 490 content = ""; … … 448 499 content += "</CMD_ComponentSpec>\n"; 449 500 ComponentDescription compDesc2 = RegistryTestHelper.addComponent( 450 getTestRegistry(), "YYY1", content);501 baseRegistry, "YYY1", content,true); 451 502 452 503 content = ""; … … 461 512 content += "</CMD_ComponentSpec>\n"; 462 513 ProfileDescription profile = RegistryTestHelper.addProfile( 463 getTestRegistry(), "TestProfile3", content);464 465 List<ComponentDescription> components = getResource().path(466 "/registry/components") .get(COMPONENT_LIST_GENERICTYPE);467 assertEquals( 2, components.size());514 baseRegistry, "TestProfile3", content, true); 515 516 List<ComponentDescription> components = this.getAuthenticatedResource(getResource().path( 517 "/registry/components")).get(COMPONENT_LIST_GENERICTYPE); 518 assertEquals(4, components.size()); 468 519 469 520 ClientResponse response = getAuthenticatedResource( … … 475 526 response.getEntity(String.class)); 476 527 477 components = getResource().path("/registry/components").get(528 components = this.getAuthenticatedResource(getResource().path("/registry/components")).get( 478 529 COMPONENT_LIST_GENERICTYPE); 479 assertEquals( 2, components.size());530 assertEquals(4, components.size()); 480 531 481 532 response = getAuthenticatedResource( … … 491 542 ClientResponse.class); 492 543 assertEquals(200, response.getStatus()); 493 components = getResource().path("/registry/components").get(544 components = this.getAuthenticatedResource(getResource().path("/registry/components")).get( 494 545 COMPONENT_LIST_GENERICTYPE); 495 assertEquals(0, components.size());496 }497 498 @Test499 public void testManipulateRegisteredComponent() throws Exception {500 fillUp();501 List<ComponentDescription> components = getResource().path(502 "/registry/components").get(COMPONENT_LIST_GENERICTYPE);503 546 assertEquals(2, components.size()); 504 CMDComponentSpec profile = getResource().path( 547 } 548 549 @Test 550 public void testManipulatePublicComponent() throws Exception { 551 552 fillUpPublicItems(); 553 554 List<ComponentDescription> components = this.getAuthenticatedResource(getResource().path( 555 "/registry/components")).get(COMPONENT_LIST_GENERICTYPE); 556 assertEquals(2, components.size()); 557 CMDComponentSpec profile = this.getAuthenticatedResource(getResource().path( 505 558 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX 506 + "component1") .get(CMDComponentSpec.class);559 + "component1")).get(CMDComponentSpec.class); 507 560 assertNotNull(profile); 508 561 … … 516 569 assertEquals(200, response.getStatus()); 517 570 518 components = getResource().path("/registry/components").get(571 components = this.getAuthenticatedResource(getResource().path("/registry/components")).get( 519 572 COMPONENT_LIST_GENERICTYPE); 520 573 assertEquals(1, components.size()); … … 529 582 @Test 530 583 public void testGetRegisteredProfile() throws Exception { 531 fillUp(); 584 585 fillUpPublicItems(); 586 532 587 String id = ProfileDescription.PROFILE_PREFIX + "profile1"; 533 588 String id2 = ProfileDescription.PROFILE_PREFIX + "profile2"; 534 CMDComponentSpec profile = getResource()535 .path("/registry/profiles/" + id) 589 CMDComponentSpec profile = this.getAuthenticatedResource(getResource() 590 .path("/registry/profiles/" + id)) 536 591 .accept(MediaType.APPLICATION_JSON).get(CMDComponentSpec.class); 537 592 assertNotNull(profile); 538 593 assertEquals("Actor", profile.getCMDComponent().getName()); 539 profile = getResource().path("/registry/profiles/" + id2)594 profile = this.getAuthenticatedResource(getResource().path("/registry/profiles/" + id2)) 540 595 .accept(MediaType.APPLICATION_XML).get(CMDComponentSpec.class); 541 596 assertNotNull(profile); … … 547 602 548 603 try { 549 profile = getResource()604 profile = this.getAuthenticatedResource(getResource() 550 605 .path("/registry/profiles/" 551 + ProfileDescription.PROFILE_PREFIX + "profileXXXX") 606 + ProfileDescription.PROFILE_PREFIX + "profileXXXX")) 552 607 .accept(MediaType.APPLICATION_XML) 553 608 .get(CMDComponentSpec.class); … … 560 615 @Test 561 616 public void testGetRegisteredProfileRawData() throws Exception { 562 fillUp(); 563 String profile = getResource() 617 618 fillUpPublicItems(); 619 620 String profile = this.getAuthenticatedResource(getResource() 564 621 .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 565 + "profile1/xsd") .accept(MediaType.TEXT_XML)622 + "profile1/xsd")).accept(MediaType.TEXT_XML) 566 623 .get(String.class).trim(); 567 624 assertTrue(profile … … 569 626 assertTrue(profile.endsWith("</xs:schema>")); 570 627 571 profile = getResource()628 profile = this.getAuthenticatedResource(getResource() 572 629 .path("/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 573 + "profile1/xml") .accept(MediaType.TEXT_XML)630 + "profile1/xml")).accept(MediaType.TEXT_XML) 574 631 .get(String.class).trim(); 575 632 assertTrue(profile … … 579 636 580 637 try { 581 getResource()638 this.getAuthenticatedResource(getResource() 582 639 .path("/registry/components/" 583 640 + ComponentDescription.COMPONENT_PREFIX 584 + "component1/xsl") .accept(MediaType.TEXT_XML)641 + "component1/xsl")).accept(MediaType.TEXT_XML) 585 642 .get(String.class); 586 643 fail("Should have thrown exception, unsupported path parameter"); … … 589 646 } 590 647 648 // 591 649 @Test 592 650 public void testPrivateProfileXsd() throws Exception { 651 652 fillUpPublicItems(); 653 593 654 FormDataMultiPart form = createFormData(RegistryTestHelper 594 655 .getTestProfileContent()); 595 RegisterResponse response = getAuthenticatedResource( 596 getResource().path("/registry/profiles").queryParam( 597 USERSPACE_PARAM, "true")).type( 656 RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/profiles").queryParam( 657 REGISTRY_SPACE_PARAM, "private")).type( 598 658 MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, 599 659 form); … … 601 661 assertEquals(1, getUserProfiles().size()); 602 662 BaseDescription desc = response.getDescription(); 603 String profile = getResource()604 .path("/registry/profiles/" + desc.getId() + "/xsd") 663 String profile = this.getAuthenticatedResource(getResource() 664 .path("/registry/profiles/" + desc.getId() + "/xsd")) 605 665 .accept(MediaType.TEXT_XML).get(String.class).trim(); 606 666 assertTrue(profile … … 611 671 @Test 612 672 public void testPrivateComponentXsd() throws Exception { 673 674 fillUpPublicItems(); 675 613 676 FormDataMultiPart form = createFormData(RegistryTestHelper 614 677 .getComponentTestContent()); 615 678 RegisterResponse response = getAuthenticatedResource( 616 679 getResource().path("/registry/components").queryParam( 617 USERSPACE_PARAM, "true")).type(680 REGISTRY_SPACE_PARAM, "private")).type( 618 681 MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, 619 682 form); … … 621 684 assertEquals(1, getUserComponents().size()); 622 685 BaseDescription desc = response.getDescription(); 623 String profile = getResource()624 .path("/registry/components/" + desc.getId() + "/xsd") 686 String profile = this.getAuthenticatedResource(getResource() 687 .path("/registry/components/" + desc.getId() + "/xsd")) 625 688 .accept(MediaType.TEXT_XML).get(String.class).trim(); 626 689 assertTrue(profile … … 631 694 @Test 632 695 public void testDeleteRegisteredProfile() throws Exception { 633 fillUp(); 634 List<ProfileDescription> profiles = getResource().path( 635 "/registry/profiles").get(PROFILE_LIST_GENERICTYPE); 696 697 fillUpPublicItems(); 698 699 List<ProfileDescription> profiles = this.getAuthenticatedResource(getResource().path( 700 "/registry/profiles")).get(PROFILE_LIST_GENERICTYPE); 636 701 assertEquals(2, profiles.size()); 637 CMDComponentSpec profile = getResource().path(702 CMDComponentSpec profile = this.getAuthenticatedResource(getResource().path( 638 703 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 639 + "profile1") .get(CMDComponentSpec.class);704 + "profile1")).get(CMDComponentSpec.class); 640 705 assertNotNull(profile); 641 706 … … 645 710 assertEquals(200, response.getStatus()); 646 711 647 profiles = getResource().path("/registry/profiles").get(712 profiles = this.getAuthenticatedResource(getResource().path("/registry/profiles")).get( 648 713 PROFILE_LIST_GENERICTYPE); 649 714 assertEquals(1, profiles.size()); … … 654 719 assertEquals(200, response.getStatus()); 655 720 656 profiles = getResource().path("/registry/profiles").get(721 profiles = this.getAuthenticatedResource(getResource().path("/registry/profiles")).get( 657 722 PROFILE_LIST_GENERICTYPE); 658 723 assertEquals(0, profiles.size()); … … 661 726 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 662 727 + "profile1").delete(ClientResponse.class); 663 assertEquals( 200, response.getStatus());728 assertEquals(404, response.getStatus()); 664 729 } 665 730 666 731 @Test 667 732 public void testManipulateRegisteredProfile() throws Exception { 668 fillUp(); 669 List<ProfileDescription> profiles = getResource().path( 670 "/registry/profiles").get(PROFILE_LIST_GENERICTYPE); 733 734 fillUpPublicItems(); 735 736 List<ProfileDescription> profiles = this.getAuthenticatedResource(getResource().path( 737 "/registry/profiles")).get(PROFILE_LIST_GENERICTYPE); 671 738 assertEquals(2, profiles.size()); 672 CMDComponentSpec profile = getResource().path(739 CMDComponentSpec profile = this.getAuthenticatedResource(getResource().path( 673 740 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX 674 + "profile1") .get(CMDComponentSpec.class);741 + "profile1")).get(CMDComponentSpec.class); 675 742 assertNotNull(profile); 676 743 … … 684 751 assertEquals(200, response.getStatus()); 685 752 686 profiles = getResource().path("/registry/profiles").get(753 profiles = this.getAuthenticatedResource(getResource().path("/registry/profiles")).get( 687 754 PROFILE_LIST_GENERICTYPE); 688 755 assertEquals(1, profiles.size()); … … 697 764 @Test 698 765 public void testGetRegisteredComponentRawData() throws Exception { 699 fillUp(); 766 767 fillUpPublicItems(); 768 700 769 String id = ComponentDescription.COMPONENT_PREFIX + "component1"; 701 String component = getResource()702 .path("/registry/components/" + id + "/xsd") 770 String component = this.getAuthenticatedResource(getResource() 771 .path("/registry/components/" + id + "/xsd")) 703 772 .accept(MediaType.TEXT_XML).get(String.class).trim(); 704 773 assertTrue(component … … 706 775 assertTrue(component.endsWith("</xs:schema>")); 707 776 708 component = getResource().path("/registry/components/" + id + "/xml")777 component = this.getAuthenticatedResource(getResource().path("/registry/components/" + id + "/xml")) 709 778 .accept(MediaType.TEXT_XML).get(String.class).trim(); 710 779 assertTrue(component … … 714 783 715 784 try { 716 getResource()785 this.getAuthenticatedResource(getResource() 717 786 .path("/registry/components/" 718 787 + ComponentDescription.COMPONENT_PREFIX 719 + "component1/jpg") .accept(MediaType.TEXT_XML)788 + "component1/jpg")).accept(MediaType.TEXT_XML) 720 789 .get(String.class); 721 790 fail("Should have thrown exception, unsopported path parameter"); … … 726 795 @Test 727 796 public void testRegisterProfile() throws Exception { 797 798 fillUpPublicItems(); 799 728 800 FormDataMultiPart form = new FormDataMultiPart(); 729 801 form.field(IComponentRegistryRestService.DATA_FORM_FIELD, … … 742 814 RegisterResponse.class, form); 743 815 assertTrue(response.isProfile()); 744 assert False(response.isInUserSpace());816 assertTrue(response.isInUserSpace()); 745 817 ProfileDescription profileDesc = (ProfileDescription) response 746 818 .getDescription(); … … 762 834 @Test 763 835 public void testPublishProfile() throws Exception { 764 assertEquals("user registered profiles", 0, getUserProfiles().size()); 765 assertEquals("public registered profiles", 0, getPublicProfiles() 836 837 fillUpPrivateItems(); 838 fillUpPublicItems(); 839 840 assertEquals("user registered profiles", 1, getUserProfiles().size()); 841 assertEquals("public registered profiles", 2, getPublicProfiles() 766 842 .size()); 767 843 FormDataMultiPart form = createFormData( 768 844 RegistryTestHelper.getTestProfileContent(), "Unpublished"); 769 RegisterResponse response = getAuthenticatedResource( 770 getResource().path("/registry/profiles").queryParam( 771 USERSPACE_PARAM, "true")).type( 845 RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/profiles")).type( 772 846 MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, 773 847 form); … … 775 849 BaseDescription desc = response.getDescription(); 776 850 assertEquals("Unpublished", desc.getDescription()); 777 assertEquals( 1, getUserProfiles().size());778 assertEquals( 0, getPublicProfiles().size());851 assertEquals(2, getUserProfiles().size()); 852 assertEquals(2, getPublicProfiles().size()); 779 853 form = createFormData( 780 854 RegistryTestHelper.getTestProfileContent("publishedName"), 781 855 "Published"); 782 response = getAuthenticatedResource( 783 getResource().path( 856 response = getAuthenticatedResource(getResource().path( 784 857 "/registry/profiles/" + desc.getId() + "/publish")) 785 858 .type(MediaType.MULTIPART_FORM_DATA).post( 786 859 RegisterResponse.class, form); 787 860 788 assertEquals( 0, getUserProfiles().size());861 assertEquals(1, getUserProfiles().size()); 789 862 List<ProfileDescription> profiles = getPublicProfiles(); 790 assertEquals( 1, profiles.size());791 ProfileDescription profileDescription = profiles.get( 0);863 assertEquals(3, profiles.size()); 864 ProfileDescription profileDescription = profiles.get(2); 792 865 assertNotNull(profileDescription.getId()); 793 866 assertEquals(desc.getId(), profileDescription.getId()); … … 801 874 private CMDComponentSpec getPublicSpec(BaseDescription desc) { 802 875 if (desc.isProfile()) { 803 return getResource().path("/registry/profiles/" + desc.getId())876 return this.getAuthenticatedResource(getResource().path("/registry/profiles/" + desc.getId())) 804 877 .get(CMDComponentSpec.class); 805 878 } else { 806 return getResource().path("/registry/components/" + desc.getId())879 return this.getAuthenticatedResource(getResource().path("/registry/components/" + desc.getId())) 807 880 .get(CMDComponentSpec.class); 808 881 } … … 810 883 811 884 @Test 812 public void testPublishComponent() throws Exception { 813 assertEquals(0, getUserComponents().size()); 814 assertEquals(0, getPublicComponents().size()); 885 public void testPublishRegisteredComponent() throws Exception { 886 887 fillUpPrivateItems(); 888 fillUpPublicItems(); 889 890 assertEquals(1, getUserComponents().size()); 891 assertEquals(2, getPublicComponents().size()); 892 815 893 FormDataMultiPart form = createFormData( 816 894 RegistryTestHelper.getComponentTestContent(), "Unpublished"); 817 RegisterResponse response = getAuthenticatedResource( 818 getResource().path("/registry/components").queryParam( 819 USERSPACE_PARAM, "true")).type( 895 RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/components")).type( 820 896 MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, 821 897 form); … … 823 899 BaseDescription desc = response.getDescription(); 824 900 assertEquals("Unpublished", desc.getDescription()); 825 assertEquals( 1, getUserComponents().size());826 assertEquals( 0, getPublicComponents().size());901 assertEquals(2, getUserComponents().size()); 902 assertEquals(2, getPublicComponents().size()); 827 903 form = createFormData( 828 904 RegistryTestHelper.getComponentTestContentAsStream("publishedName"), 829 905 "Published"); 830 response = getAuthenticatedResource( 831 getResource().path( 906 response = getAuthenticatedResource(getResource().path( 832 907 "/registry/components/" + desc.getId() + "/publish")) 833 908 .type(MediaType.MULTIPART_FORM_DATA).post( 834 909 RegisterResponse.class, form); 835 910 836 assertEquals( 0, getUserComponents().size());911 assertEquals(1, getUserComponents().size()); 837 912 List<ComponentDescription> components = getPublicComponents(); 838 assertEquals( 1, components.size());839 ComponentDescription componentDescription = components.get( 0);913 assertEquals(3, components.size()); 914 ComponentDescription componentDescription = components.get(2); 840 915 assertNotNull(componentDescription.getId()); 841 916 assertEquals(desc.getId(), componentDescription.getId()); … … 848 923 } 849 924 925 // duplicates ("extendedly") testRegisterProfile, since you can pot only in user space, and then publish or move to group or so 850 926 @Test 851 927 public void testRegisterUserspaceProfile() throws Exception { 928 929 fillUpPrivateItems(); 930 fillUpPublicItems(); 931 852 932 List<ProfileDescription> profiles = getUserProfiles(); 853 assertEquals("user registered profiles", 0, profiles.size());854 assertEquals("public registered profiles", 0, getPublicProfiles()933 assertEquals("user registered profiles", 1, profiles.size()); 934 assertEquals("public registered profiles", 2, getPublicProfiles() 855 935 .size()); 856 936 FormDataMultiPart form = createFormData(RegistryTestHelper 857 937 .getTestProfileContent()); 858 RegisterResponse response = getAuthenticatedResource( 859 getResource().path("/registry/profiles").queryParam( 860 USERSPACE_PARAM, "true")).type( 938 RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/profiles")).type( 861 939 MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, 862 940 form); … … 875 953 assertEquals( 876 954 "http://localhost:9998/registry/profiles/" 877 + profileDesc.getId() + "?userspace=true",955 + profileDesc.getId(), 878 956 profileDesc.getHref()); 879 957 880 958 profiles = getUserProfiles(); 881 assertEquals( 1, profiles.size());882 assertEquals( 0, getPublicProfiles().size());959 assertEquals(2, profiles.size()); 960 assertEquals(2, getPublicProfiles().size()); 883 961 884 962 // Try to post unauthenticated 885 963 ClientResponse cResponse = getResource().path("/registry/profiles") 886 .queryParam(USERSPACE_PARAM, "true")887 964 .type(MediaType.MULTIPART_FORM_DATA) 888 965 .post(ClientResponse.class, form); 889 966 assertEquals(401, cResponse.getStatus()); 890 967 891 // Try get from public registry 892 cResponse = getResource() 893 .path("/registry/profiles/" + profileDesc.getId()) 894 .accept(MediaType.APPLICATION_XML).get(ClientResponse.class); 895 // Should return 404 = not found 896 assertEquals(404, cResponse.getStatus()); 897 CMDComponentSpec spec = getAuthenticatedResource( 898 getResource().path("/registry/profiles/" + profileDesc.getId()) 899 .queryParam(USERSPACE_PARAM, "true")).accept( 968 969 970 CMDComponentSpec spec = getAuthenticatedResource(getResource().path("/registry/profiles/" + profileDesc.getId()) 971 .queryParam(REGISTRY_SPACE_PARAM, "private")).accept( 900 972 MediaType.APPLICATION_XML).get(CMDComponentSpec.class); 901 973 assertNotNull(spec); 902 974 903 cResponse = getResource()904 .path("/registry/profiles/" + profileDesc.getId() + "/xsd") 975 cResponse = this.getAuthenticatedResource(getResource() 976 .path("/registry/profiles/" + profileDesc.getId() + "/xsd")) 905 977 .accept(MediaType.TEXT_XML).get(ClientResponse.class); 906 978 assertEquals(200, cResponse.getStatus()); … … 908 980 assertTrue(profile.length() > 0); 909 981 910 profile = getAuthenticatedResource( 911 getResource().path( 982 profile = getAuthenticatedResource(getResource().path( 912 983 "/registry/profiles/" + profileDesc.getId() + "/xml")) 913 984 .accept(MediaType.TEXT_XML).get(String.class); 914 985 assertTrue(profile.length() > 0); 915 986 916 cResponse = getAuthenticatedResource( 917 getResource().path("/registry/profiles/" + profileDesc.getId()) 918 .queryParam(USERSPACE_PARAM, "true")).delete( 987 cResponse = getAuthenticatedResource(getResource().path("/registry/profiles/" + profileDesc.getId()) 988 .queryParam(REGISTRY_SPACE_PARAM, "private")).delete( 919 989 ClientResponse.class); 920 990 assertEquals(200, cResponse.getStatus()); 921 991 922 992 profiles = getUserProfiles(); 923 assertEquals( 0, profiles.size());993 assertEquals(1, profiles.size()); 924 994 } 925 995 … … 930 1000 931 1001 private List<ProfileDescription> getUserProfiles() { 932 return getAuthenticatedResource( 933 getResource().path("/registry/profiles").queryParam( 934 USERSPACE_PARAM, "true")).accept( 1002 return getAuthenticatedResource(getResource().path("/registry/profiles").queryParam( 1003 REGISTRY_SPACE_PARAM, "private")).accept( 935 1004 MediaType.APPLICATION_XML).get(PROFILE_LIST_GENERICTYPE); 936 1005 } … … 954 1023 @Test 955 1024 public void testRegisterWithUserComponents() throws Exception { 956 ComponentRegistry userRegistry = componentRegistryFactory 957 .getComponentRegistry(ComponentStatus.PRIVATE, null, 958 DummyPrincipal.DUMMY_CREDENTIALS); 1025 fillUpPrivateItems(); 1026 1027 // kid component, not public 959 1028 String content = ""; 960 1029 content += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"; … … 966 1035 content += "</CMD_ComponentSpec>\n"; 967 1036 ComponentDescription compDesc1 = RegistryTestHelper.addComponent( 968 userRegistry, "XXX1", content); 969 1037 baseRegistry, "XXX1", content, false); 1038 1039 // a containing component, referring to the kid (which is not public, so the containing component cannot be registered 970 1040 content = ""; 971 1041 content += "<CMD_ComponentSpec isProfile=\"false\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"; … … 982 1052 "/registry/components").type(MediaType.MULTIPART_FORM_DATA) 983 1053 .post(RegisterResponse.class, form); 984 assertFalse(response.isRegistered()); 985 assertEquals(1, response.getErrors().size()); 986 assertEquals( 987 "referenced component cannot be found in the published components: " 988 + compDesc1.getName() + " (" + compDesc1.getId() + ")", 989 response.getErrors().get(0)); 990 991 response = getAuthenticatedResource( 992 getResource().path("/registry/components").queryParam( 993 USERSPACE_PARAM, "true")).type( 994 MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, 995 form); 1054 // we first alway register in a private space, so reference to a private component should work 996 1055 assertTrue(response.isRegistered()); 997 ComponentDescription comp2 = (ComponentDescription) response 998 .getDescription(); 999 1056 1057 1058 /// profiles /// 1000 1059 content = ""; 1001 1060 content += "<CMD_ComponentSpec isProfile=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"; … … 1003 1062 content += " <Header/>\n"; 1004 1063 content += " <CMD_Component name=\"ZZZ\" CardinalityMin=\"1\" CardinalityMax=\"unbounded\">\n"; 1005 content += " <CMD_Component ComponentId=\"" + comp 2.getId()1064 content += " <CMD_Component ComponentId=\"" + compDesc1.getId() 1006 1065 + "\" CardinalityMin=\"0\" CardinalityMax=\"99\">\n"; 1007 1066 content += " </CMD_Component>\n"; … … 1013 1072 MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, 1014 1073 form); 1015 assertFalse(response.isRegistered());1016 assertEquals(1, response.getErrors().size());1017 assertEquals(1018 "referenced component cannot be found in the published components: "1019 + comp2.getName() + " (" + comp2.getId() + ")",1020 response.getErrors().get(0));1021 1022 response = getAuthenticatedResource(1023 getResource().path("/registry/profiles").queryParam(1024 USERSPACE_PARAM, "true")).type(1025 MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class,1026 form);1027 1074 assertTrue(response.isRegistered()); 1075 1028 1076 } 1029 1077 1030 1078 @Test 1031 1079 public void testRegisterUserspaceComponent() throws Exception { 1080 1081 fillUpPrivateItems(); 1082 1032 1083 List<ComponentDescription> components = getUserComponents(); 1033 assertEquals("user registered components", 0, components.size());1084 assertEquals("user registered components", 1, components.size()); 1034 1085 assertEquals("public registered components", 0, getPublicComponents() 1035 1086 .size()); … … 1037 1088 .getComponentTestContent()); 1038 1089 1039 RegisterResponse response = getAuthenticatedResource( 1040 getResource().path("/registry/components").queryParam( 1041 USERSPACE_PARAM, "true")).type( 1090 RegisterResponse response = getAuthenticatedResource(getResource().path("/registry/components")).type( 1042 1091 MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, 1043 1092 form); … … 1057 1106 assertNotNull(desc.getRegistrationDate()); 1058 1107 String url = getResource().getUriBuilder().build().toString(); 1059 assertEquals(url + "registry/components/" + desc.getId() 1060 + "?userspace=true", desc.getHref()); 1108 assertEquals(url + "registry/components/" + desc.getId(), desc.getHref()); 1061 1109 1062 1110 components = getUserComponents(); 1063 assertEquals( 1, components.size());1111 assertEquals(2, components.size()); 1064 1112 assertEquals(0, getPublicComponents().size()); 1065 1113 1066 1114 // Try to post unauthenticated 1067 1115 ClientResponse cResponse = getResource().path("/registry/components") 1068 .queryParam(USERSPACE_PARAM, "true")1069 1116 .type(MediaType.MULTIPART_FORM_DATA) 1070 1117 .post(ClientResponse.class, form); 1071 1118 assertEquals(401, cResponse.getStatus()); 1072 1119 1073 // Try to get from public registry1074 cResponse = getResource().path("/registry/components/" + desc.getId())1120 // Try to get 1121 cResponse = this.getAuthenticatedResource(getResource().path("/registry/components/" + desc.getId())) 1075 1122 .accept(MediaType.APPLICATION_XML).get(ClientResponse.class); 1076 // Should return 404 = not found1077 assertEquals( 404, cResponse.getStatus());1123 1124 assertEquals(200, cResponse.getStatus()); 1078 1125 CMDComponentSpec spec = getUserComponent(desc); 1079 1126 assertNotNull(spec); 1080 1127 1081 cResponse = getResource()1082 .path("/registry/components/" + desc.getId() + "/xsd") 1128 cResponse = this.getAuthenticatedResource(getResource() 1129 .path("/registry/components/" + desc.getId() + "/xsd")) 1083 1130 .accept(MediaType.TEXT_XML).get(ClientResponse.class); 1084 1131 assertEquals(200, cResponse.getStatus()); … … 1086 1133 assertTrue(result.length() > 0); 1087 1134 1088 result = getAuthenticatedResource( 1089 getResource().path( 1135 result = getAuthenticatedResource(getResource().path( 1090 1136 "/registry/components/" + desc.getId() + "/xml")) 1091 1137 .accept(MediaType.TEXT_XML).get(String.class); 1092 1138 assertTrue(result.length() > 0); 1093 1139 1094 cResponse = getAuthenticatedResource( 1095 getResource().path("/registry/components/" + desc.getId()) 1096 .queryParam(USERSPACE_PARAM, "true")).delete( 1140 cResponse = getAuthenticatedResource(getResource().path("/registry/components/" + desc.getId())).delete( 1097 1141 ClientResponse.class); 1098 1142 assertEquals(200, cResponse.getStatus()); 1099 1143 1100 1144 components = getUserComponents(); 1101 assertEquals(0, components.size()); 1102 } 1103 1104 @Test 1105 public void testCreateComponentWithRecursion() throws Exception { 1145 assertEquals(1, components.size()); 1146 } 1147 // 1148 @Test 1149 public void testCreatePrivateComponentWithRecursion() throws Exception { 1150 1151 fillUpPrivateItems(); 1106 1152 // Create new componet 1107 1153 FormDataMultiPart form = createFormData(RegistryTestHelper 1108 1154 .getComponentTestContent()); 1109 ClientResponse cResponse = getAuthenticatedResource( 1110 getResource().path("/registry/components").queryParam( 1111 USERSPACE_PARAM, "true")).type( 1155 ClientResponse cResponse = getAuthenticatedResource(getResource().path("/registry/components")).type( 1112 1156 MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form); 1113 1157 assertEquals(ClientResponse.Status.OK.getStatusCode(), … … 1140 1184 RegistryTestHelper.getComponentContentAsStream(compContent), 1141 1185 "UPDATE DESCRIPTION!"); 1142 cResponse = getAuthenticatedResource( 1143 getResource().path( 1144 "/registry/components/" + desc.getId() + "/update") 1145 .queryParam(USERSPACE_PARAM, "true")).type( 1186 cResponse = getAuthenticatedResource(getResource().path( 1187 "/registry/components/" + desc.getId() + "/update")).type( 1146 1188 MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form); 1147 1189 assertEquals(ClientResponse.Status.OK.getStatusCode(), … … 1159 1201 1160 1202 @Test 1161 public void testUpdateComponent() throws Exception { 1203 public void testUpdatePrivateComponent() throws Exception { 1204 1205 fillUpPrivateItems(); 1206 1162 1207 List<ComponentDescription> components = getUserComponents(); 1163 assertEquals("user registered components", 0, components.size());1208 assertEquals("user registered components", 1, components.size()); 1164 1209 assertEquals("public registered components", 0, getPublicComponents() 1165 1210 .size()); 1166 1211 1212 // first, post a component to update 1167 1213 FormDataMultiPart form = createFormData(RegistryTestHelper 1168 1214 .getComponentTestContent()); 1169 ClientResponse cResponse = getAuthenticatedResource( 1170 getResource().path("/registry/components").queryParam( 1171 USERSPACE_PARAM, "true")).type( 1215 ClientResponse cResponse = getAuthenticatedResource(getResource().path("/registry/components")).type( 1172 1216 MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form); 1173 1217 assertEquals(ClientResponse.Status.OK.getStatusCode(), … … 1187 1231 assertEquals("Access", spec.getCMDComponent().getName()); 1188 1232 components = getUserComponents(); 1189 assertEquals( 1, components.size());1233 assertEquals(2, components.size()); 1190 1234 assertEquals(0, getPublicComponents().size()); 1191 1235 1192 // Now update1236 // second, now update 1193 1237 form = createFormData( 1194 1238 RegistryTestHelper.getComponentTestContentAsStream("TESTNAME"), 1195 1239 "UPDATE DESCRIPTION!"); 1196 cResponse = getAuthenticatedResource( 1197 getResource().path( 1240 cResponse = getAuthenticatedResource(getResource().path( 1198 1241 "/registry/components/" + desc.getId() + "/update") 1199 .queryParam( USERSPACE_PARAM, "true")).type(1242 .queryParam(REGISTRY_SPACE_PARAM, "private")).type( 1200 1243 MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form); 1201 1244 assertEquals(ClientResponse.Status.OK.getStatusCode(), … … 1216 1259 assertEquals("TESTNAME", spec.getCMDComponent().getName()); 1217 1260 components = getUserComponents(); 1218 assertEquals( 1, components.size());1261 assertEquals(2, components.size()); 1219 1262 assertEquals(0, getPublicComponents().size()); 1220 1263 } 1221 1264 1222 1265 @Test 1223 public void testUpdateProfile() throws Exception { 1266 public void testUpdatePrivateProfile() throws Exception { 1267 1268 fillUpPrivateItems(); 1269 1224 1270 List<ProfileDescription> profiles = getUserProfiles(); 1225 assertEquals( 0, profiles.size());1271 assertEquals(1, profiles.size()); 1226 1272 assertEquals(0, getPublicProfiles().size()); 1227 1273 1228 1274 FormDataMultiPart form = createFormData(RegistryTestHelper 1229 1275 .getTestProfileContent()); 1230 ClientResponse cResponse = getAuthenticatedResource( 1231 getResource().path("/registry/profiles").queryParam( 1232 USERSPACE_PARAM, "true")).type( 1276 ClientResponse cResponse = getAuthenticatedResource(getResource().path("/registry/profiles")).type( 1233 1277 MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form); 1234 1278 assertEquals(ClientResponse.Status.OK.getStatusCode(), … … 1249 1293 assertEquals("Actor", spec.getCMDComponent().getName()); 1250 1294 profiles = getUserProfiles(); 1251 assertEquals( 1, profiles.size());1295 assertEquals(2, profiles.size()); 1252 1296 assertEquals(0, getPublicComponents().size()); 1253 1297 … … 1256 1300 RegistryTestHelper.getTestProfileContent("TESTNAME"), 1257 1301 "UPDATE DESCRIPTION!"); 1258 cResponse = getAuthenticatedResource( 1259 getResource().path( 1260 "/registry/profiles/" + desc.getId() + "/update") 1261 .queryParam(USERSPACE_PARAM, "true")).type( 1302 cResponse = getAuthenticatedResource(getResource().path( 1303 "/registry/profiles/" + desc.getId() + "/update")).type( 1262 1304 MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form); 1263 1305 assertEquals(ClientResponse.Status.OK.getStatusCode(), … … 1278 1320 assertEquals("TESTNAME", spec.getCMDComponent().getName()); 1279 1321 profiles = getUserProfiles(); 1280 assertEquals( 1, profiles.size());1322 assertEquals(2, profiles.size()); 1281 1323 assertEquals(0, getPublicComponents().size()); 1282 1324 } 1283 1325 1284 1326 private CMDComponentSpec getUserComponent(ComponentDescription desc) { 1285 return getAuthenticatedResource( 1286 getResource().path("/registry/components/" + desc.getId()) 1287 .queryParam(USERSPACE_PARAM, "true")).accept( 1327 return getAuthenticatedResource(getResource().path("/registry/components/" + desc.getId()) 1328 .queryParam(REGISTRY_SPACE_PARAM, "private")).accept( 1288 1329 MediaType.APPLICATION_XML).get(CMDComponentSpec.class); 1289 1330 } 1290 1331 1291 1332 private CMDComponentSpec getUserProfile(ProfileDescription desc) { 1292 return getAuthenticatedResource( 1293 getResource().path("/registry/profiles/" + desc.getId()) 1294 .queryParam(USERSPACE_PARAM, "true")).accept( 1333 return getAuthenticatedResource(getResource().path("/registry/profiles/" + desc.getId()) 1334 .queryParam(REGISTRY_SPACE_PARAM, "private")).accept( 1295 1335 MediaType.APPLICATION_XML).get(CMDComponentSpec.class); 1296 1336 } … … 1302 1342 1303 1343 private List<ComponentDescription> getUserComponents() { 1304 return getAuthenticatedResource( 1305 getResource().path("/registry/components").queryParam( 1306 USERSPACE_PARAM, "true")).accept( 1344 return getAuthenticatedResource(getResource().path("/registry/components").queryParam( 1345 REGISTRY_SPACE_PARAM, "private")).accept( 1307 1346 MediaType.APPLICATION_XML).get(COMPONENT_LIST_GENERICTYPE); 1308 1347 } … … 1310 1349 @Test 1311 1350 public void testRegisterComponent() throws Exception { 1351 1352 fillUpPrivateItems(); 1353 1312 1354 FormDataMultiPart form = new FormDataMultiPart(); 1313 1355 form.field(IComponentRegistryRestService.DATA_FORM_FIELD, … … 1326 1368 assertTrue(response.isRegistered()); 1327 1369 assertFalse(response.isProfile()); 1328 assert False(response.isInUserSpace());1370 assertTrue(response.isInUserSpace()); 1329 1371 ComponentDescription desc = (ComponentDescription) response 1330 1372 .getDescription(); … … 1346 1388 @Test 1347 1389 public void testRegisterComment() throws Exception { 1390 1391 fillUpPublicItems(); 1392 1348 1393 FormDataMultiPart form = new FormDataMultiPart(); 1349 1394 form.field(IComponentRegistryRestService.DATA_FORM_FIELD, 1350 1395 RegistryTestHelper.getCommentTestContent(), 1351 1396 MediaType.APPLICATION_OCTET_STREAM_TYPE); 1352 fillUp();1353 1397 String id = ProfileDescription.PROFILE_PREFIX + "profile1"; 1354 1398 CommentResponse response = getAuthenticatedResource( … … 1371 1415 @Test 1372 1416 public void testRegisterCommentToNonExistent() throws Exception { 1417 fillUpPublicItems(); 1418 1373 1419 FormDataMultiPart form = new FormDataMultiPart(); 1374 1420 form.field(IComponentRegistryRestService.DATA_FORM_FIELD, 1375 1421 RegistryTestHelper.getCommentTestContent(), 1376 1422 MediaType.APPLICATION_OCTET_STREAM_TYPE); 1377 fillUp();1378 1423 ClientResponse cResponse = getAuthenticatedResource( 1379 1424 "/registry/profiles/clarin.eu:cr1:profile99/comments").type( 1380 1425 MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form); 1381 assertEquals( 500, cResponse.getStatus());1426 assertEquals(404, cResponse.getStatus()); 1382 1427 } 1383 1428 1384 1429 @Test 1385 1430 public void testRegisterCommentUnauthenticated() throws Exception { 1431 fillUpPublicItems(); 1432 1386 1433 FormDataMultiPart form = new FormDataMultiPart(); 1387 1434 form.field(IComponentRegistryRestService.DATA_FORM_FIELD, 1388 1435 RegistryTestHelper.getCommentTestContent(), 1389 1436 MediaType.APPLICATION_OCTET_STREAM_TYPE); 1390 fillUp();1391 1437 ClientResponse cResponse = getResource() 1392 1438 .path("/registry/profiles/clarin.eu:cr1:profile1/comments") … … 1398 1444 @Test 1399 1445 public void testRegisterProfileInvalidData() throws Exception { 1446 fillUpPrivateItems(); 1400 1447 FormDataMultiPart form = new FormDataMultiPart(); 1401 1448 String notAValidProfile = "<CMD_ComponentSpec> </CMD_ComponentSpec>"; … … 1426 1473 @Test 1427 1474 public void testRegisterInvalidProfile() throws Exception { 1475 fillUpPrivateItems(); 1428 1476 FormDataMultiPart form = new FormDataMultiPart(); 1429 1477 String profileContent = ""; … … 1469 1517 public void testRegisterProfileInvalidDescriptionAndContent() 1470 1518 throws Exception { 1519 fillUpPrivateItems(); 1471 1520 FormDataMultiPart form = new FormDataMultiPart(); 1472 1521 String profileContent = ""; … … 1499 1548 @Test 1500 1549 public void testRegisterLargeProfile() throws Exception { 1550 //fillUpPrivateItems(); not necessary 1501 1551 FormDataMultiPart form = new FormDataMultiPart(); 1502 1552 form.field(IComponentRegistryRestService.DATA_FORM_FIELD, … … 1519 1569 @Test 1520 1570 public void testRegisterComponentAsProfile() throws Exception { 1571 //fillUpPrivateItems();; not necessary 1521 1572 FormDataMultiPart form = new FormDataMultiPart(); 1522 1573 form.field(IComponentRegistryRestService.DATA_FORM_FIELD, … … 1641 1692 @Test 1642 1693 public void testGetDescription() throws Exception{ 1643 fillUp ();1644 1694 fillUpPublicItems(); 1695 String id = ComponentDescription.COMPONENT_PREFIX + "component1"; 1645 1696 ComponentDescription component = getAuthenticatedResource(getResource().path("/registry/items/" + id)).accept(MediaType.APPLICATION_JSON).get(ComponentDescription.class); 1646 1697 assertNotNull(component);
Note: See TracChangeset
for help on using the changeset viewer.