@@ -10789,12 +10789,12 @@ public void enforceRequiredRelationTiltedLeftTest() throws Exception {
1078910789 .andExpect(status().isUnprocessableEntity());
1079010790 }
1079110791
10792- @Test
10792+ @Test
1079310793 public void uploadAndReplaceTest() throws Exception {
1079410794 context.turnOffAuthorisationSystem();
10795- configurationService.setProperty("replace-bitstream.enabled", true);
10795+ configurationService.setProperty("replace-bitstream.enabled", true);
1079610796
10797- parentCommunity = CommunityBuilder.createCommunity(context)
10797+ parentCommunity = CommunityBuilder.createCommunity(context)
1079810798 .withName("Parent Community")
1079910799 .build();
1080010800 Collection collection = CollectionBuilder.createCollection(context, parentCommunity)
@@ -10813,13 +10813,26 @@ public void uploadAndReplaceTest() throws Exception {
1081310813 .withMimeType("text/plain")
1081410814 .build();
1081510815 }
10816+ // Set access conditions on the old file; they should be copied to the new one
10817+ LocalDate startDate = LocalDate.now();
10818+ DateTimeFormatter dateFmt = DateTimeFormatter.ISO_LOCAL_DATE;
10819+ String startDateStr = dateFmt.format(LocalDate.now());
10820+
10821+ ResourcePolicyBuilder.createResourcePolicy(context, null, anonymousGroup)
10822+ .withDspaceObject(originalBitstream)
10823+ .withAction(Constants.READ)
10824+ .withPolicyType(TYPE_CUSTOM)
10825+ .withName("embargo")
10826+ .withStartDate(startDate);
1081610827 InputStream pdf = getClass().getResourceAsStream("simple-article.pdf");
1081710828 final MockMultipartFile newFile =
1081810829 new MockMultipartFile("file", "/local/path/simple-article.pdf", "application/pdf", pdf);
1081910830
1082010831 context.restoreAuthSystemState();
1082110832
1082210833 String token = getAuthToken(admin.getEmail(), password);
10834+
10835+
1082310836 // Upload new file, to replace old one
1082410837 getClient(token).perform(multipart("/api/submission/workspaceitems/" + workspaceItem.getID())
1082510838 .file(newFile)
@@ -10833,14 +10846,20 @@ public void uploadAndReplaceTest() throws Exception {
1083310846 .andExpect(jsonPath("$.sections.upload.files[0].metadata['dspace.bitstream.isReplacementOf'][0].authority",
1083410847 is(originalBitstream.getID().toString())))
1083510848 .andExpect(jsonPath("$.sections.upload.files[0].metadata['dc.source'][0].value",
10836- is("/local/path/simple-article.pdf")));
10837- // Check new file metadata
10849+ is("/local/path/simple-article.pdf")))
10850+ .andExpect(jsonPath("$.sections.upload.files[0].accessConditions[0].name", is("embargo")))
10851+ .andExpect(jsonPath("$.sections.upload.files[0].accessConditions[0].startDate", is(startDateStr)))
10852+ .andExpect(jsonPath("$.sections.upload.files[0].accessConditions[0].endDate", nullValue()));
10853+ // Check new file metadata and access conditions
1083810854 getClient(token).perform(get("/api/submission/workspaceitems/" + workspaceItem.getID()))
1083910855 .andExpect(status().isOk())
1084010856 .andExpect(jsonPath("$.sections.upload.files[0].metadata['dc.title'][0].value",
1084110857 is("simple-article.pdf")))
1084210858 .andExpect(jsonPath("$.sections.upload.files[0].metadata['dc.source'][0].value",
10843- is("/local/path/simple-article.pdf")));
10859+ is("/local/path/simple-article.pdf")))
10860+ .andExpect(jsonPath("$.sections.upload.files[0].accessConditions[0].name", is("embargo")))
10861+ .andExpect(jsonPath("$.sections.upload.files[0].accessConditions[0].startDate", is(startDateStr)))
10862+ .andExpect(jsonPath("$.sections.upload.files[0].accessConditions[0].endDate", nullValue()));
1084410863 originalBitstream = bitstreamService.find(context, originalBitstream.getID());
1084510864 List<MetadataValue> originalMetadata = bitstreamService.getMetadata(originalBitstream, DSPACE,
1084610865 BITSTREAM, IS_REPLACED_BY, null);
0 commit comments