diff --git a/dspace-api/src/test/java/org/dspace/content/RelationshipMetadataServiceIT.java b/dspace-api/src/test/java/org/dspace/content/RelationshipMetadataServiceIT.java index 798a549f9e..41a7e3c85d 100644 --- a/dspace-api/src/test/java/org/dspace/content/RelationshipMetadataServiceIT.java +++ b/dspace-api/src/test/java/org/dspace/content/RelationshipMetadataServiceIT.java @@ -187,13 +187,38 @@ public class RelationshipMetadataServiceIT extends AbstractIntegrationTestWithDa public void testDeleteAuthorRelationshipCopyToLeftItem() throws Exception { initPublicationAuthor(); context.turnOffAuthorisationSystem(); + + //verify the dc.contributor.author virtual metadata + List authorList = itemService.getMetadata(leftItem, "dc", "contributor", "author", Item.ANY); + assertThat(authorList.size(), equalTo(1)); + + //verify the dc.contributor.author actual metadata + List plainMetadataAuthorList = leftItem.getMetadata().stream() + .filter(metadataValue -> metadataValue.getMetadataField().getQualifier() != null && + metadataValue.getMetadataField().getQualifier().equals("author")) + .collect(Collectors.toList()); + assertThat(plainMetadataAuthorList.size(), equalTo(0)); + + //verify there's no relation.isAuthorOfPublication actual metadata + List plainRelationshipMetadataList = leftItem.getMetadata().stream() + .filter(metadataValue -> metadataValue.getMetadataField().getElement().equals("isAuthorOfPublication")) + .collect(Collectors.toList()); + assertThat(plainRelationshipMetadataList.size(), equalTo(0)); + //delete the relationship, copying the virtual metadata to actual metadata on the leftItem //leftItem is the publication relationshipService.delete(context, relationship, true, false); context.restoreAuthSystemState(); //verify the dc.contributor.author actual metadata - List authorList = itemService.getMetadata(leftItem, "dc", "contributor", "author", Item.ANY); + plainMetadataAuthorList = leftItem.getMetadata().stream() + .filter(metadataValue -> metadataValue.getMetadataField().getQualifier() != null && + metadataValue.getMetadataField().getQualifier().equals("author")) + .collect(Collectors.toList()); + assertThat(plainMetadataAuthorList.size(), equalTo(1)); + + //verify the dc.contributor.author actual metadata + authorList = itemService.getMetadata(leftItem, "dc", "contributor", "author", Item.ANY); assertThat(authorList.size(), equalTo(1)); assertThat(authorList.get(0).getValue(), equalTo("familyName, firstName")); assertThat(authorList.get(0).getMetadataField().getMetadataSchema().getName(), equalTo("dc")); @@ -201,10 +226,15 @@ public class RelationshipMetadataServiceIT extends AbstractIntegrationTestWithDa assertThat(authorList.get(0).getMetadataField().getQualifier(), equalTo("author")); assertNull(authorList.get(0).getAuthority()); - //verify there's no relation.isAuthorOfPublication actual metadata + //verify there's relation.isAuthorOfPublication actual metadata + plainRelationshipMetadataList = leftItem.getMetadata().stream() + .filter(metadataValue -> metadataValue.getMetadataField().getElement().equals("isAuthorOfPublication")) + .collect(Collectors.toList()); + assertThat(plainRelationshipMetadataList.size(), equalTo(1)); + //verify there's relation.isAuthorOfPublication actual metadata List relationshipMetadataList = itemService .getMetadata(leftItem, MetadataSchemaEnum.RELATION.getName(), "isAuthorOfPublication", null, Item.ANY); - assertThat(relationshipMetadataList.size(), equalTo(0)); + assertThat(relationshipMetadataList.size(), equalTo(1)); //request the virtual metadata of the publication only List list = relationshipMetadataService.getRelationshipMetadata(leftItem, true); @@ -399,13 +429,38 @@ public class RelationshipMetadataServiceIT extends AbstractIntegrationTestWithDa public void testDeleteAuthorRelationshipCopyToLeftItemFromDefaultInDb() throws Exception { initPublicationAuthorWithCopyParams(true, false); context.turnOffAuthorisationSystem(); + + //verify the dc.contributor.author virtual metadata + List authorList = itemService.getMetadata(leftItem, "dc", "contributor", "author", Item.ANY); + assertThat(authorList.size(), equalTo(1)); + + //verify the dc.contributor.author actual metadata + List plainMetadataAuthorList = leftItem.getMetadata().stream() + .filter(metadataValue -> metadataValue.getMetadataField().getQualifier() != null && + metadataValue.getMetadataField().getQualifier().equals("author")) + .collect(Collectors.toList()); + assertThat(plainMetadataAuthorList.size(), equalTo(0)); + + //verify there's no relation.isAuthorOfPublication actual metadata + List plainRelationshipMetadataList = leftItem.getMetadata().stream() + .filter(metadataValue -> metadataValue.getMetadataField().getElement().equals("isAuthorOfPublication")) + .collect(Collectors.toList()); + assertThat(plainRelationshipMetadataList.size(), equalTo(0)); + //delete the relationship, copying the virtual metadata to actual metadata on the leftItem //leftItem is the publication relationshipService.delete(context, relationship); context.restoreAuthSystemState(); //verify the dc.contributor.author actual metadata - List authorList = itemService.getMetadata(leftItem, "dc", "contributor", "author", Item.ANY); + plainMetadataAuthorList = leftItem.getMetadata().stream() + .filter(metadataValue -> metadataValue.getMetadataField().getQualifier() != null && + metadataValue.getMetadataField().getQualifier().equals("author")) + .collect(Collectors.toList()); + assertThat(plainMetadataAuthorList.size(), equalTo(1)); + + //verify the dc.contributor.author actual metadata + authorList = itemService.getMetadata(leftItem, "dc", "contributor", "author", Item.ANY); assertThat(authorList.size(), equalTo(1)); assertThat(authorList.get(0).getValue(), equalTo("familyName, firstName")); assertThat(authorList.get(0).getMetadataField().getMetadataSchema().getName(), equalTo("dc")); @@ -413,10 +468,15 @@ public class RelationshipMetadataServiceIT extends AbstractIntegrationTestWithDa assertThat(authorList.get(0).getMetadataField().getQualifier(), equalTo("author")); assertNull(authorList.get(0).getAuthority()); - //verify there's no relation.isAuthorOfPublication actual metadata + //verify there's relation.isAuthorOfPublication actual metadata + plainRelationshipMetadataList = leftItem.getMetadata().stream() + .filter(metadataValue -> metadataValue.getMetadataField().getElement().equals("isAuthorOfPublication")) + .collect(Collectors.toList()); + assertThat(plainRelationshipMetadataList.size(), equalTo(1)); + //verify there's relation.isAuthorOfPublication actual metadata List relationshipMetadataList = itemService .getMetadata(leftItem, MetadataSchemaEnum.RELATION.getName(), "isAuthorOfPublication", null, Item.ANY); - assertThat(relationshipMetadataList.size(), equalTo(0)); + assertThat(relationshipMetadataList.size(), equalTo(1)); //request the virtual metadata of the publication only List list = relationshipMetadataService.getRelationshipMetadata(leftItem, true); @@ -446,12 +506,36 @@ public class RelationshipMetadataServiceIT extends AbstractIntegrationTestWithDa public void testDeleteAuthorRelationshipCopyToBothItemsFromDefaultsInDb() throws Exception { initPublicationAuthorWithCopyParams(true, true); context.turnOffAuthorisationSystem(); + //verify the dc.contributor.author virtual metadata + List authorList = itemService.getMetadata(leftItem, "dc", "contributor", "author", Item.ANY); + assertThat(authorList.size(), equalTo(1)); + + //verify the dc.contributor.author actual metadata + List plainMetadataAuthorList = leftItem.getMetadata().stream() + .filter(metadataValue -> metadataValue.getMetadataField().getQualifier() != null && + metadataValue.getMetadataField().getQualifier().equals("author")) + .collect(Collectors.toList()); + assertThat(plainMetadataAuthorList.size(), equalTo(0)); + + //verify there's no relation.isAuthorOfPublication actual metadata + List plainRelationshipMetadataList = leftItem.getMetadata().stream() + .filter(metadataValue -> metadataValue.getMetadataField().getElement().equals("isAuthorOfPublication")) + .collect(Collectors.toList()); + assertThat(plainRelationshipMetadataList.size(), equalTo(0)); + //delete the relationship, copying the virtual metadata to actual metadata on the both items relationshipService.delete(context, relationship); context.restoreAuthSystemState(); //verify the dc.contributor.author actual metadata - List authorList = itemService.getMetadata(leftItem, "dc", "contributor", "author", Item.ANY); + plainMetadataAuthorList = leftItem.getMetadata().stream() + .filter(metadataValue -> metadataValue.getMetadataField().getQualifier() != null && + metadataValue.getMetadataField().getQualifier().equals("author")) + .collect(Collectors.toList()); + assertThat(plainMetadataAuthorList.size(), equalTo(1)); + + //verify the dc.contributor.author actual metadata + authorList = itemService.getMetadata(leftItem, "dc", "contributor", "author", Item.ANY); assertThat(authorList.size(), equalTo(1)); assertThat(authorList.get(0).getValue(), equalTo("familyName, firstName")); assertThat(authorList.get(0).getMetadataField().getMetadataSchema().getName(), equalTo("dc")); @@ -459,10 +543,15 @@ public class RelationshipMetadataServiceIT extends AbstractIntegrationTestWithDa assertThat(authorList.get(0).getMetadataField().getQualifier(), equalTo("author")); assertNull(authorList.get(0).getAuthority()); - //verify there's no relation.isAuthorOfPublication actual metadata + //verify there's relation.isAuthorOfPublication actual metadata + plainRelationshipMetadataList = leftItem.getMetadata().stream() + .filter(metadataValue -> metadataValue.getMetadataField().getElement().equals("isAuthorOfPublication")) + .collect(Collectors.toList()); + assertThat(plainRelationshipMetadataList.size(), equalTo(1)); + //verify there's relation.isAuthorOfPublication actual metadata List relationshipMetadataList = itemService .getMetadata(leftItem, MetadataSchemaEnum.RELATION.getName(), "isAuthorOfPublication", null, Item.ANY); - assertThat(relationshipMetadataList.size(), equalTo(0)); + assertThat(relationshipMetadataList.size(), equalTo(1)); } @Test diff --git a/dspace-server-webapp/src/test/java/org/dspace/app/rest/RelationshipDeleteRestRepositoryIT.java b/dspace-server-webapp/src/test/java/org/dspace/app/rest/RelationshipDeleteRestRepositoryIT.java index 9cc9ce51c9..8d97dcc502 100644 --- a/dspace-server-webapp/src/test/java/org/dspace/app/rest/RelationshipDeleteRestRepositoryIT.java +++ b/dspace-server-webapp/src/test/java/org/dspace/app/rest/RelationshipDeleteRestRepositoryIT.java @@ -7,8 +7,12 @@ */ package org.dspace.app.rest; +import static java.util.Arrays.asList; +import static java.util.stream.Collectors.toList; +import static org.dspace.content.Item.ANY; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.startsWith; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; @@ -221,6 +225,35 @@ public class RelationshipDeleteRestRepositoryIT extends AbstractEntityIntegratio public void testDeleteAuthorRelationshipCopyToLeftItem() throws Exception { initPublicationAuthor(); + // Verify the dc.contributor.author virtual metadata of the left item + assertEquals( + 1, + itemService + .getMetadata(leftItem, "dc", "contributor", "author", Item.ANY) + .size() + ); + + // Verify there's no dc.contributor.author actual metadata on the left item + assertEquals( + 0, + leftItem.getMetadata() + .stream() + .filter(metadataValue -> "author".equals(metadataValue.getMetadataField().getQualifier())) + .collect(toList()) + .size() + ); + + // Verify there's no relation.isAuthorOfPublication actual metadata on the left item + assertEquals( + 0, + leftItem.getMetadata() + .stream() + .filter(metadataValue -> "isAuthorOfPublication" + .equals(metadataValue.getMetadataField().getElement())) + .collect(toList()) + .size() + ); + getClient(adminAuthToken).perform( delete("/api/core/relationships/" + relationship.getID() + "?copyVirtualMetadata=left")) .andExpect(status().isNoContent()); @@ -235,12 +268,35 @@ public class RelationshipDeleteRestRepositoryIT extends AbstractEntityIntegratio assertThat(authorList.get(0).getMetadataField().getQualifier(), equalTo("author")); assertNull(authorList.get(0).getAuthority()); - - // Check that the relation metadata values are gone because the relationship is gone List relationshipMetadataList = itemService .getMetadata(leftItem, "relation", "isAuthorOfPublication", null, Item.ANY); - assertThat(relationshipMetadataList.size(), equalTo(0)); + assertThat(relationshipMetadataList.size(), equalTo(1)); + // Verify there's dc.contributor.author actual metadata on the left item + assertEquals( + 1, + leftItem.getMetadata() + .stream() + .filter(metadataValue -> metadataValue.getMetadataField().getQualifier() != null && + metadataValue.getMetadataField().getQualifier().equals("author")) + .collect(toList()) + .size() + ); + + // Verify there's relation.isAuthorOfPublication actual metadata on the left item + assertEquals( + 1, + leftItem.getMetadata() + .stream() + .filter(metadataValue -> "isAuthorOfPublication" + .equals(metadataValue.getMetadataField().getElement())) + .collect(toList()) + .size() + ); + + // Check right item to ensure that no metadata is copied + + rightItem = context.reloadEntity(rightItem); relationshipMetadataList = itemService .getMetadata(rightItem, "relation", "isPublicationOfAuthor", null, Item.ANY); assertThat(relationshipMetadataList.size(), equalTo(0)); @@ -250,6 +306,27 @@ public class RelationshipDeleteRestRepositoryIT extends AbstractEntityIntegratio public void testAuthorDeleteRelationshipCopyToRightItem() throws Exception { initPublicationAuthor(); + // Verify there's no dc.contributor.author actual metadata on the right item + assertEquals( + 0, + rightItem.getMetadata() + .stream() + .filter(metadataValue -> "author".equals(metadataValue.getMetadataField().getQualifier())) + .collect(toList()) + .size() + ); + + // Verify there's no relation.isPublicationOfAuthor actual metadata on the right item + assertEquals( + 0, + rightItem.getMetadata() + .stream() + .filter(metadataValue -> "isPublicationOfAuthor" + .equals(metadataValue.getMetadataField().getElement())) + .collect(toList()) + .size() + ); + getClient(adminAuthToken).perform( delete("/api/core/relationships/" + relationship.getID() + "?copyVirtualMetadata=right")) .andExpect(status().isNoContent()); @@ -259,14 +336,27 @@ public class RelationshipDeleteRestRepositoryIT extends AbstractEntityIntegratio List authorList = itemService.getMetadata(leftItem, "dc", "contributor", "author", Item.ANY); assertThat(authorList.size(), equalTo(0)); - // Check that the relation metadata values are gone because the relationship is gone List relationshipMetadataList = itemService .getMetadata(leftItem, "relation", "isAuthorOfPublication", null, Item.ANY); assertThat(relationshipMetadataList.size(), equalTo(0)); + // Check right item to ensure that the metadata is copied + + rightItem = itemService.find(context, rightItem.getID()); relationshipMetadataList = itemService .getMetadata(rightItem, "relation", "isPublicationOfAuthor", null, Item.ANY); - assertThat(relationshipMetadataList.size(), equalTo(0)); + assertThat(relationshipMetadataList.size(), equalTo(1)); + + // Verify there's relation.isPublicationOfAuthor actual metadata on the right item + assertEquals( + 1, + rightItem.getMetadata() + .stream() + .filter(metadataValue -> "isPublicationOfAuthor" + .equals(metadataValue.getMetadataField().getElement())) + .collect(toList()) + .size() + ); // There is no additional Metadata to check on the rightItem because the configuration of the virtual // metadata holds no config to display virtual metadata on the author of the publication @@ -291,11 +381,44 @@ public class RelationshipDeleteRestRepositoryIT extends AbstractEntityIntegratio List relationshipMetadataList = itemService .getMetadata(leftItem, "relation", "isAuthorOfPublication", null, Item.ANY); - assertThat(relationshipMetadataList.size(), equalTo(0)); + assertThat(relationshipMetadataList.size(), equalTo(1)); + // Verify there's dc.contributor.author actual metadata on the left item + assertEquals( + 1, + leftItem.getMetadata() + .stream() + .filter(metadataValue -> "author".equals(metadataValue.getMetadataField().getQualifier())) + .collect(toList()) + .size() + ); + + // Verify there's relation.isAuthorOfPublication actual metadata on the left item + assertEquals( + 1, + leftItem.getMetadata() + .stream() + .filter(metadataValue -> "isAuthorOfPublication" + .equals(metadataValue.getMetadataField().getElement())) + .collect(toList()) + .size() + ); + + rightItem = itemService.find(context, rightItem.getID()); relationshipMetadataList = itemService .getMetadata(rightItem, "relation", "isPublicationOfAuthor", null, Item.ANY); - assertThat(relationshipMetadataList.size(), equalTo(0)); + assertThat(relationshipMetadataList.size(), equalTo(1)); + + // Verify there's relation.isPublicationOfAuthor actual metadata on the right item + assertEquals( + 1, + rightItem.getMetadata() + .stream() + .filter(metadataValue -> "isPublicationOfAuthor" + .equals(metadataValue.getMetadataField().getElement())) + .collect(toList()) + .size() + ); // There is no additional Metadata to check on the rightItem because the configuration of the virtual // metadata holds no config to display virtual metadata on the author of the publication @@ -375,6 +498,32 @@ public class RelationshipDeleteRestRepositoryIT extends AbstractEntityIntegratio public void deleteItemCopyVirtualMetadataAll() throws Exception { initPersonProjectPublication(); + for (Item item : asList(publicationItem, projectItem)) { + + // Verify the dc.contributor.author virtual metadata + assertEquals( + 1, + itemService.getMetadata(item, "dc", "contributor", "author", ANY).size() + ); + + // Verify there's no dc.contributor.author actual metadata on the item + assertEquals( + 0, + item.getMetadata().stream() + .filter(metadataValue -> "author".equals(metadataValue.getMetadataField().getQualifier())) + .collect(toList()).size() + ); + + // Verify there's no relation.isAuthorOfPublication actual metadata on the item + assertEquals( + 0, + item.getMetadata().stream() + .filter(metadataValue -> "isAuthorOfPublication" + .equals(metadataValue.getMetadataField().getElement())) + .collect(toList()).size() + ); + } + getClient(adminAuthToken).perform( delete("/api/core/items/" + personItem.getID() + "?copyVirtualMetadata=all")) .andExpect(status().isNoContent()); @@ -387,7 +536,26 @@ public class RelationshipDeleteRestRepositoryIT extends AbstractEntityIntegratio assertNull(publicationAuthorList.get(0).getAuthority()); List publicationRelationships = itemService.getMetadata(publicationItem, "relation", "isAuthorOfPublication", Item.ANY, Item.ANY); - assertThat(publicationRelationships.size(), equalTo(0)); + assertThat(publicationRelationships.size(), equalTo(1)); + + // Verify there's dc.contributor.author actual metadata on the publication item + assertEquals( + 1, + publicationItem.getMetadata().stream() + .filter(metadataValue -> "author".equals(metadataValue.getMetadataField().getQualifier())) + .collect(toList()) + .size() + ); + + // Verify there's relation.isAuthorOfPublication actual metadata on the publication item + assertEquals( + 1, + publicationItem.getMetadata().stream() + .filter(metadataValue -> "isAuthorOfPublication" + .equals(metadataValue.getMetadataField().getElement())) + .collect(toList()) + .size() + ); projectItem = itemService.find(context, projectItem.getID()); List projectAuthorList = itemService.getMetadata(projectItem, @@ -397,13 +565,58 @@ public class RelationshipDeleteRestRepositoryIT extends AbstractEntityIntegratio assertNull(projectAuthorList.get(0).getAuthority()); List projectRelationships = itemService.getMetadata(projectItem, "relation", "isPersonOfProject", Item.ANY, Item.ANY); - assertThat(projectRelationships.size(), equalTo(0)); + assertThat(projectRelationships.size(), equalTo(1)); + + // Verify there's dc.contributor.author actual metadata on the project item + assertEquals( + 1, + projectItem.getMetadata().stream() + .filter(metadataValue -> "author".equals(metadataValue.getMetadataField().getQualifier())) + .collect(toList()) + .size() + ); + + // Verify there's relation.isPersonOfProject actual metadata on the project item + assertEquals( + 1, + projectItem.getMetadata().stream() + .filter(metadataValue -> "isPersonOfProject" + .equals(metadataValue.getMetadataField().getElement())) + .collect(toList()) + .size() + ); } @Test public void deleteItemCopyVirtualMetadataOneType() throws Exception { initPersonProjectPublication(); + for (Item item : asList(publicationItem, projectItem)) { + + // Verify the dc.contributor.author virtual metadata + assertEquals( + 1, + itemService.getMetadata(item, "dc", "contributor", "author", ANY).size() + ); + + // Verify there's no dc.contributor.author actual metadata on the item + assertEquals( + 0, + item.getMetadata().stream() + .filter(metadataValue -> "author".equals(metadataValue.getMetadataField().getQualifier())) + .collect(toList()).size() + ); + + // Verify there's no relation.isAuthorOfPublication actual metadata on the item + assertEquals( + 0, + item.getMetadata().stream() + .filter(metadataValue -> "isAuthorOfPublication" + .equals(metadataValue.getMetadataField().getElement())) + .collect(toList()).size() + ); + } + getClient(adminAuthToken).perform( delete("/api/core/items/" + personItem.getID() + "?copyVirtualMetadata=" + publicationPersonRelationshipType.getID())) @@ -417,7 +630,26 @@ public class RelationshipDeleteRestRepositoryIT extends AbstractEntityIntegratio assertNull(publicationAuthorList.get(0).getAuthority()); List publicationRelationships = itemService.getMetadata(publicationItem, "relation", "isAuthorOfPublication", Item.ANY, Item.ANY); - assertThat(publicationRelationships.size(), equalTo(0)); + assertThat(publicationRelationships.size(), equalTo(1)); + + // Verify there's dc.contributor.author actual metadata on the publication item + assertEquals( + 1, + publicationItem.getMetadata().stream() + .filter(metadataValue -> "author".equals(metadataValue.getMetadataField().getQualifier())) + .collect(toList()) + .size() + ); + + // Verify there's relation.isAuthorOfPublication actual metadata on the publication item + assertEquals( + 1, + publicationItem.getMetadata().stream() + .filter(metadataValue -> "isAuthorOfPublication" + .equals(metadataValue.getMetadataField().getElement())) + .collect(toList()) + .size() + ); projectItem = itemService.find(context, projectItem.getID()); List projectAuthorList = itemService.getMetadata(projectItem, @@ -432,6 +664,32 @@ public class RelationshipDeleteRestRepositoryIT extends AbstractEntityIntegratio public void deleteItemCopyVirtualMetadataTwoTypes() throws Exception { initPersonProjectPublication(); + for (Item item : asList(publicationItem, projectItem)) { + + // Verify the dc.contributor.author virtual metadata + assertEquals( + 1, + itemService.getMetadata(item, "dc", "contributor", "author", ANY).size() + ); + + // Verify there's no dc.contributor.author actual metadata on the item + assertEquals( + 0, + item.getMetadata().stream() + .filter(metadataValue -> "author".equals(metadataValue.getMetadataField().getQualifier())) + .collect(toList()).size() + ); + + // Verify there's no relation.isAuthorOfPublication actual metadata on the item + assertEquals( + 0, + item.getMetadata().stream() + .filter(metadataValue -> "isAuthorOfPublication" + .equals(metadataValue.getMetadataField().getElement())) + .collect(toList()).size() + ); + } + getClient(adminAuthToken).perform( delete("/api/core/items/" + personItem.getID() + "?copyVirtualMetadata=" + publicationPersonRelationshipType.getID() @@ -446,7 +704,26 @@ public class RelationshipDeleteRestRepositoryIT extends AbstractEntityIntegratio assertNull(publicationAuthorList.get(0).getAuthority()); List publicationRelationships = itemService.getMetadata(publicationItem, "relation", "isAuthorOfPublication", Item.ANY, Item.ANY); - assertThat(publicationRelationships.size(), equalTo(0)); + assertThat(publicationRelationships.size(), equalTo(1)); + + // Verify there's dc.contributor.author actual metadata on the publication item + assertEquals( + 1, + publicationItem.getMetadata().stream() + .filter(metadataValue -> "author".equals(metadataValue.getMetadataField().getQualifier())) + .collect(toList()) + .size() + ); + + // Verify there's relation.isAuthorOfPublication actual metadata on the publication item + assertEquals( + 1, + publicationItem.getMetadata().stream() + .filter(metadataValue -> "isAuthorOfPublication" + .equals(metadataValue.getMetadataField().getElement())) + .collect(toList()) + .size() + ); projectItem = itemService.find(context, projectItem.getID()); List projectAuthorList = itemService.getMetadata(projectItem, @@ -456,7 +733,26 @@ public class RelationshipDeleteRestRepositoryIT extends AbstractEntityIntegratio assertNull(projectAuthorList.get(0).getAuthority()); List projectRelationships = itemService.getMetadata(projectItem, "relation", "isPersonOfProject", Item.ANY, Item.ANY); - assertThat(projectRelationships.size(), equalTo(0)); + assertThat(projectRelationships.size(), equalTo(1)); + + // Verify there's dc.contributor.author actual metadata on the project item + assertEquals( + 1, + projectItem.getMetadata().stream() + .filter(metadataValue -> "author".equals(metadataValue.getMetadataField().getQualifier())) + .collect(toList()) + .size() + ); + + // Verify there's relation.isPersonOfProject actual metadata on the project item + assertEquals( + 1, + projectItem.getMetadata().stream() + .filter(metadataValue -> "isPersonOfProject" + .equals(metadataValue.getMetadataField().getElement())) + .collect(toList()) + .size() + ); } @Test @@ -520,6 +816,32 @@ public class RelationshipDeleteRestRepositoryIT extends AbstractEntityIntegratio public void deleteItemCopyVirtualMetadataAllNoPermissions() throws Exception { initPersonProjectPublication(); + for (Item item : asList(publicationItem, projectItem)) { + + // Verify the dc.contributor.author virtual metadata + assertEquals( + 1, + itemService.getMetadata(item, "dc", "contributor", "author", ANY).size() + ); + + // Verify there's no dc.contributor.author actual metadata on the item + assertEquals( + 0, + item.getMetadata().stream() + .filter(metadataValue -> "author".equals(metadataValue.getMetadataField().getQualifier())) + .collect(toList()).size() + ); + + // Verify there's no relation.isAuthorOfPublication actual metadata on the item + assertEquals( + 0, + item.getMetadata().stream() + .filter(metadataValue -> "isAuthorOfPublication" + .equals(metadataValue.getMetadataField().getElement())) + .collect(toList()).size() + ); + } + getClient(getAuthToken(eperson.getEmail(), password)).perform( delete("/api/core/items/" + personItem.getID())) .andExpect(status().isForbidden()); @@ -608,6 +930,32 @@ public class RelationshipDeleteRestRepositoryIT extends AbstractEntityIntegratio public void deleteItemCopyVirtualMetadataConfigured() throws Exception { initPersonProjectPublication(); + for (Item item : asList(publicationItem, projectItem)) { + + // Verify the dc.contributor.author virtual metadata + assertEquals( + 1, + itemService.getMetadata(item, "dc", "contributor", "author", ANY).size() + ); + + // Verify there's no dc.contributor.author actual metadata on the item + assertEquals( + 0, + item.getMetadata().stream() + .filter(metadataValue -> "author".equals(metadataValue.getMetadataField().getQualifier())) + .collect(toList()).size() + ); + + // Verify there's no relation.isAuthorOfPublication actual metadata on the item + assertEquals( + 0, + item.getMetadata().stream() + .filter(metadataValue -> "isAuthorOfPublication" + .equals(metadataValue.getMetadataField().getElement())) + .collect(toList()).size() + ); + } + getClient(adminAuthToken).perform( delete("/api/core/items/" + personItem.getID() + "?copyVirtualMetadata=configured")) .andExpect(status().isNoContent()); @@ -629,7 +977,26 @@ public class RelationshipDeleteRestRepositoryIT extends AbstractEntityIntegratio assertNull(projectAuthorList.get(0).getAuthority()); List projectRelationships = itemService.getMetadata(projectItem, "relation", "isPersonOfProject", Item.ANY, Item.ANY); - assertThat(projectRelationships.size(), equalTo(0)); + assertThat(projectRelationships.size(), equalTo(1)); + + // Verify there's dc.contributor.author actual metadata on the project item + assertEquals( + 1, + projectItem.getMetadata().stream() + .filter(metadataValue -> "author".equals(metadataValue.getMetadataField().getQualifier())) + .collect(toList()) + .size() + ); + + // Verify there's relation.isPersonOfProject actual metadata on the project item + assertEquals( + 1, + projectItem.getMetadata().stream() + .filter(metadataValue -> "isPersonOfProject" + .equals(metadataValue.getMetadataField().getElement())) + .collect(toList()) + .size() + ); } @Test @@ -653,7 +1020,7 @@ public class RelationshipDeleteRestRepositoryIT extends AbstractEntityIntegratio assertNull(publicationAuthorList.get(0).getAuthority()); List publicationRelationships = itemService.getMetadata(publicationItem, "relation", "isAuthorOfPublication", Item.ANY, Item.ANY); - assertThat(publicationRelationships.size(), equalTo(0)); + assertThat(publicationRelationships.size(), equalTo(1)); projectItem = itemService.find(context, projectItem.getID()); List projectAuthorList = itemService.getMetadata(projectItem, diff --git a/dspace-server-webapp/src/test/java/org/dspace/app/rest/RelationshipRestRepositoryIT.java b/dspace-server-webapp/src/test/java/org/dspace/app/rest/RelationshipRestRepositoryIT.java index d8f4188a66..313bd0afc8 100644 --- a/dspace-server-webapp/src/test/java/org/dspace/app/rest/RelationshipRestRepositoryIT.java +++ b/dspace-server-webapp/src/test/java/org/dspace/app/rest/RelationshipRestRepositoryIT.java @@ -775,6 +775,7 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest .andExpect(status().isCreated()) .andDo(result -> idRef2.set(read(result.getResponse().getContentAsString(), "$.id"))); + publication1 = itemService.find(context, publication1.getID()); list = itemService.getMetadata(publication1, "dc", "contributor", "author", Item.ANY); // Ensure that we now have three dc.contributor.author mdv ("Smith, Donald", "plain text", "Smith, Maria" // In that order which will be checked below the rest call @@ -801,6 +802,7 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest itemService.update(context, publication1); context.restoreAuthSystemState(); + publication1 = itemService.find(context, publication1.getID()); list = itemService.getMetadata(publication1, "dc", "contributor", "author", Item.ANY); // Assert that the list of dc.contributor.author mdv is now of size 4 in the following order: @@ -838,6 +840,7 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest .andExpect(status().isCreated()) .andDo(result -> idRef3.set(read(result.getResponse().getContentAsString(), "$.id"))); + publication1 = itemService.find(context, publication1.getID()); list = itemService.getMetadata(publication1, "dc", "contributor", "author", Item.ANY); // Assert that our dc.contributor.author mdv list is now of size 5 assertEquals(5, list.size()); @@ -901,6 +904,7 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest itemService.update(context, publication1); context.restoreAuthSystemState(); + publication1 = itemService.find(context, publication1.getID()); list = itemService.getMetadata(publication1, "dc", "contributor", "author", Item.ANY); assertEquals(10, list.size());