|
22 | 22 | import org.dspace.builder.CollectionBuilder; |
23 | 23 | import org.dspace.builder.CommunityBuilder; |
24 | 24 | import org.dspace.builder.ItemBuilder; |
| 25 | +import org.dspace.builder.WorkflowItemBuilder; |
| 26 | +import org.dspace.builder.WorkspaceItemBuilder; |
25 | 27 | import org.dspace.content.Collection; |
26 | 28 | import org.dspace.content.Item; |
| 29 | +import org.dspace.content.WorkspaceItem; |
27 | 30 | import org.dspace.services.ConfigurationService; |
| 31 | +import org.dspace.workflow.WorkflowItem; |
28 | 32 | import org.junit.Assume; |
29 | 33 | import org.junit.Before; |
30 | 34 | import org.junit.ClassRule; |
@@ -445,6 +449,105 @@ public void depositAndEditViaSwordTest() throws Exception { |
445 | 449 | assertEquals(HttpStatus.NOT_FOUND, response.getStatusCode()); |
446 | 450 | } |
447 | 451 |
|
| 452 | + // test workspace delete - use org.dspace.sword2.WorkflowManagerDefault |
| 453 | + @Test |
| 454 | + public void testDeleteWorkspaceManagerDefault() throws SQLException, AuthorizeException { |
| 455 | + context.turnOffAuthorisationSystem(); |
| 456 | + // Create a top level community and one Collection |
| 457 | + parentCommunity = CommunityBuilder.createCommunity(context) |
| 458 | + .withName("Parent Community") |
| 459 | + .build(); |
| 460 | + // Make sure our Collection allows the "eperson" user to submit into it |
| 461 | + Collection collection = CollectionBuilder.createCollection(context, parentCommunity) |
| 462 | + .withName("Test SWORDv2 Collection") |
| 463 | + .withSubmitterGroup(eperson) |
| 464 | + .build(); |
| 465 | + // Above changes MUST be committed to the database for SWORDv2 to see them. |
| 466 | + WorkspaceItem wsi = WorkspaceItemBuilder.createWorkspaceItem(context, collection) |
| 467 | + .withTitle("Test SWORDv2 Item") |
| 468 | + .withAuthor("Test, Sam") |
| 469 | + .withSubmitter(eperson) |
| 470 | + .build(); |
| 471 | + context.commit(); |
| 472 | + context.restoreAuthSystemState(); |
| 473 | + |
| 474 | + // Edit URI should also allow user to DELETE the uploaded content |
| 475 | + // The Item is in Workspace and not in workflow, so we can use the WorkflowManagerDefault to delete it. |
| 476 | + configurationService.setProperty("plugin.single.org.dspace.sword2.WorkflowManager", |
| 477 | + "org.dspace.sword2.WorkflowManagerDefault"); |
| 478 | + String editLink = getURL(EDIT_PATH + "/" + wsi.getItem().getID().toString()); |
| 479 | + HttpHeaders authHeaders = new HttpHeaders(); |
| 480 | + authHeaders.setBasicAuth(admin.getEmail(), password); |
| 481 | + RequestEntity request = RequestEntity.delete(editLink) |
| 482 | + .headers(authHeaders) |
| 483 | + .build(); |
| 484 | + ResponseEntity<String> response = responseAsString(request); |
| 485 | + configurationService.setProperty("plugin.single.org.dspace.sword2.WorkflowManager", |
| 486 | + "org.dspace.sword2.WorkflowManagerUnrestricted"); |
| 487 | + |
| 488 | + // Expect a 204 No Content response |
| 489 | + assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode()); |
| 490 | + |
| 491 | + // Verify that Edit URI now returns a 404 (using eperson login info) |
| 492 | + authHeaders = new HttpHeaders(); |
| 493 | + authHeaders.setBasicAuth(eperson.getEmail(), password); |
| 494 | + request = RequestEntity.get(editLink) |
| 495 | + .accept(MediaType.valueOf("application/atom+xml")) |
| 496 | + .headers(authHeaders) |
| 497 | + .build(); |
| 498 | + response = responseAsString(request); |
| 499 | + // Expect a 404 response as content was deleted |
| 500 | + assertEquals(HttpStatus.NOT_FOUND, response.getStatusCode()); |
| 501 | + } |
| 502 | + |
| 503 | + // test workflow delete - use org.dspace.sword2.WorkflowManagerUnrestricted |
| 504 | + @Test |
| 505 | + public void testDeleteWorkflowManagerDefault() throws SQLException, AuthorizeException { |
| 506 | + context.turnOffAuthorisationSystem(); |
| 507 | + // Create a top level community and one Collection |
| 508 | + parentCommunity = CommunityBuilder.createCommunity(context) |
| 509 | + .withName("Parent Community") |
| 510 | + .build(); |
| 511 | + // Make sure our Collection allows the "eperson" user to submit into it |
| 512 | + Collection collection = CollectionBuilder.createCollection(context, parentCommunity) |
| 513 | + .withName("Test SWORDv2 Collection") |
| 514 | + .withSubmitterGroup(eperson) |
| 515 | + .build(); |
| 516 | + // Above changes MUST be committed to the database for SWORDv2 to see them. |
| 517 | + WorkflowItem wfi = WorkflowItemBuilder.createWorkflowItem(context, collection) |
| 518 | + .withTitle("Test SWORDv2 Item") |
| 519 | + .withAuthor("Test, Sam") |
| 520 | + .withSubmitter(eperson) |
| 521 | + .build(); |
| 522 | + context.commit(); |
| 523 | + context.restoreAuthSystemState(); |
| 524 | + |
| 525 | + // Edit URI should allow user to DELETE the uploaded content |
| 526 | + // The item is in workflow, so we need to use the WorkflowManagerUnrestricted to delete it. It is set in the |
| 527 | + // @Before method |
| 528 | + String editLink = getURL(EDIT_PATH + "/" + wfi.getItem().getID().toString()); |
| 529 | + HttpHeaders authHeaders = new HttpHeaders(); |
| 530 | + authHeaders.setBasicAuth(admin.getEmail(), password); |
| 531 | + RequestEntity request = RequestEntity.delete(editLink) |
| 532 | + .headers(authHeaders) |
| 533 | + .build(); |
| 534 | + ResponseEntity<String> response = responseAsString(request); |
| 535 | + |
| 536 | + // Expect a 204 No Content response |
| 537 | + assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode()); |
| 538 | + |
| 539 | + // Verify that Edit URI now returns a 404 (using eperson login info) |
| 540 | + authHeaders = new HttpHeaders(); |
| 541 | + authHeaders.setBasicAuth(eperson.getEmail(), password); |
| 542 | + request = RequestEntity.get(editLink) |
| 543 | + .accept(MediaType.valueOf("application/atom+xml")) |
| 544 | + .headers(authHeaders) |
| 545 | + .build(); |
| 546 | + response = responseAsString(request); |
| 547 | + // Expect a 404 response as content was deleted |
| 548 | + assertEquals(HttpStatus.NOT_FOUND, response.getStatusCode()); |
| 549 | + } |
| 550 | + |
448 | 551 | @Test |
449 | 552 | public void editUnauthorizedTest() throws Exception { |
450 | 553 | // Attempt to POST to /edit endpoint without sending authentication information |
|
0 commit comments