|
14 | 14 | import static org.junit.Assert.assertNotNull; |
15 | 15 |
|
16 | 16 | import java.nio.file.Path; |
| 17 | +import java.sql.SQLException; |
17 | 18 | import java.util.List; |
18 | 19 |
|
19 | 20 | import org.dspace.app.rest.test.AbstractWebClientIntegrationTest; |
| 21 | +import org.dspace.authorize.AuthorizeException; |
20 | 22 | import org.dspace.builder.CollectionBuilder; |
21 | 23 | import org.dspace.builder.CommunityBuilder; |
22 | 24 | import org.dspace.builder.ItemBuilder; |
@@ -228,6 +230,84 @@ public void depositItemWithEmbargo() throws Exception { |
228 | 230 | assertEquals(ATOM_ENTRY_CONTENT_TYPE, response.getHeaders().getContentType().toString()); |
229 | 231 | } |
230 | 232 |
|
| 233 | + // Test when the `swordv2-server.url` is null. The swordv2 server URL should be constructed using the default value |
| 234 | + @Test |
| 235 | + public void editMediaPathTest() throws SQLException, AuthorizeException { |
| 236 | + context.turnOffAuthorisationSystem(); |
| 237 | + // The `swordv2` server URL is constructed, and the default value is used if `swordv2-server.url` is null. |
| 238 | + configurationService.setProperty("swordv2-server.url", null); |
| 239 | + // The `dspace.server.url` must be updated following the same logic as the `swordv2-server.url`. |
| 240 | + // The `getURL` method used a specific port. |
| 241 | + String dspaceServerUrl = configurationService.getProperty("dspace.server.url"); |
| 242 | + configurationService.setProperty("dspace.server.url", getURL("")); |
| 243 | + try { |
| 244 | + // Create a top level community and one Collection |
| 245 | + parentCommunity = CommunityBuilder.createCommunity(context) |
| 246 | + .withName("Parent Community") |
| 247 | + .build(); |
| 248 | + // Make sure our Collection allows the "eperson" user to submit into it |
| 249 | + Collection collection = CollectionBuilder.createCollection(context, parentCommunity) |
| 250 | + .withName("Test SWORDv2 Collection") |
| 251 | + .withSubmitterGroup(eperson) |
| 252 | + .build(); |
| 253 | + // Above changes MUST be committed to the database for SWORDv2 to see them. |
| 254 | + context.commit(); |
| 255 | + context.restoreAuthSystemState(); |
| 256 | + |
| 257 | + // Add file |
| 258 | + LinkedMultiValueMap<Object, Object> multipart = new LinkedMultiValueMap<>(); |
| 259 | + multipart.add("file", new FileSystemResource(Path.of("src", "test", "resources", |
| 260 | + "org", "dspace", "app", "sword2", "example.zip"))); |
| 261 | + // Add required headers |
| 262 | + HttpHeaders headers = new HttpHeaders(); |
| 263 | + headers.setContentType(MediaType.MULTIPART_FORM_DATA); |
| 264 | + headers.setContentDisposition(ContentDisposition.attachment().filename("example.zip").build()); |
| 265 | + headers.set("Packaging", "http://purl.org/net/sword/package/METSDSpaceSIP"); |
| 266 | + headers.setAccept(List.of(MediaType.APPLICATION_ATOM_XML)); |
| 267 | + |
| 268 | + //---- |
| 269 | + // STEP 1: Verify upload/submit via SWORDv2 works |
| 270 | + //---- |
| 271 | + // Send POST to upload Zip file via SWORD |
| 272 | + ResponseEntity<String> response = postResponseAsString(COLLECTION_PATH + "/" + collection.getHandle(), |
| 273 | + eperson.getEmail(), password, |
| 274 | + new HttpEntity<>(multipart, headers)); |
| 275 | + |
| 276 | + // Expect a 201 CREATED response with ATOM "entry" content returned |
| 277 | + assertEquals(HttpStatus.CREATED, response.getStatusCode()); |
| 278 | + assertEquals(ATOM_ENTRY_CONTENT_TYPE, response.getHeaders().getContentType().toString()); |
| 279 | + // MUST return a "Location" header which is the "/swordv2/edit/[uuid]" URI of the created item |
| 280 | + assertNotNull(response.getHeaders().getLocation()); |
| 281 | + |
| 282 | + String editLink = response.getHeaders().getLocation().toString(); |
| 283 | + |
| 284 | + // Body should include that link as the rel="edit" URL |
| 285 | + assertThat(response.getBody(), containsString("<link href=\"" + editLink + "\" rel=\"edit\"/>")); |
| 286 | + |
| 287 | + //---- |
| 288 | + // STEP 2: Verify uploaded content can be read via SWORDv2 |
| 289 | + //---- |
| 290 | + // Edit URI should work when requested by the EPerson who did the deposit |
| 291 | + HttpHeaders authHeaders = new HttpHeaders(); |
| 292 | + authHeaders.setBasicAuth(eperson.getEmail(), password); |
| 293 | + RequestEntity request = RequestEntity.get(editLink) |
| 294 | + .accept(MediaType.valueOf("application/atom+xml")) |
| 295 | + .headers(authHeaders) |
| 296 | + .build(); |
| 297 | + response = responseAsString(request); |
| 298 | + // Expect a 200 response with ATOM feed content returned |
| 299 | + assertEquals(HttpStatus.OK, response.getStatusCode()); |
| 300 | + assertEquals(ATOM_FEED_CONTENT_TYPE, response.getHeaders().getContentType().toString()); |
| 301 | + // Body should include links to bitstreams from the zip. |
| 302 | + // This just verifies at least one /swordv2/edit-media/bitstream/* link exists. |
| 303 | + assertThat(response.getBody(), containsString(getURL(MEDIA_RESOURCE_PATH + "/bitstream"))); |
| 304 | + // Verify Item title also is returned in the body |
| 305 | + assertThat(response.getBody(), containsString("Attempts to detect retrotransposition")); |
| 306 | + } finally { |
| 307 | + configurationService.setProperty("dspace.server.url", dspaceServerUrl); |
| 308 | + } |
| 309 | + } |
| 310 | + |
231 | 311 | /** |
232 | 312 | * This tests four different SWORDv2 actions, as these all require starting with a new deposit. |
233 | 313 | * 1. Depositing a new item via SWORD (via POST /collections/[collection-uuid]) |
|
0 commit comments