From f5043f15c37d4ecfbc81e8c84c8b27cd700d560e Mon Sep 17 00:00:00 2001 From: Ben Bosman Date: Tue, 23 Feb 2021 13:19:03 +0100 Subject: [PATCH] The relationship metadata is created Also add checks based on plain metadata only --- .../RelationshipMetadataServiceIT.java | 36 +++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) 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 ab1d8cfc97..798a549f9e 100644 --- a/dspace-api/src/test/java/org/dspace/content/RelationshipMetadataServiceIT.java +++ b/dspace-api/src/test/java/org/dspace/content/RelationshipMetadataServiceIT.java @@ -14,6 +14,7 @@ import static org.junit.Assert.assertTrue; import java.sql.SQLException; import java.util.List; +import java.util.stream.Collectors; import org.dspace.AbstractIntegrationTestWithDatabase; import org.dspace.authorize.AuthorizeException; @@ -233,12 +234,36 @@ public class RelationshipMetadataServiceIT extends AbstractIntegrationTestWithDa public void testDeleteAuthorRelationshipCopyToBothItems() 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 both items relationshipService.delete(context, relationship, true, true); 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")); @@ -246,10 +271,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