diff --git a/pass-deposit-services/deposit-core/src/test/java/org/eclipse/pass/deposit/provider/nihms/NihmsAssemblerIT.java b/pass-deposit-services/deposit-core/src/test/java/org/eclipse/pass/deposit/provider/nihms/NihmsAssemblerIT.java index f1b021b9..3b3dc15f 100644 --- a/pass-deposit-services/deposit-core/src/test/java/org/eclipse/pass/deposit/provider/nihms/NihmsAssemblerIT.java +++ b/pass-deposit-services/deposit-core/src/test/java/org/eclipse/pass/deposit/provider/nihms/NihmsAssemblerIT.java @@ -27,16 +27,22 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.io.StringWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Set; import java.util.function.Function; import java.util.stream.Collectors; import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; @@ -246,10 +252,19 @@ public void testPackageMetadata() throws Exception { //Ensure that the grants in the metadata matches a Grant on the submission, Check the attributes of a grant on //submission against what is found in the metadata //TODO: add test here for the grants - List grantElements = asList(root.getElementsByTagName("grants")); + List grantElements = asList(root.getElementsByTagName("grant")); + + // Convert root Document to String + //TODO remove + TransformerFactory transformerFactory = TransformerFactory.newInstance(); + Transformer transformer = transformerFactory.newTransformer(); + StringWriter writer = new StringWriter(); + transformer.transform(new DOMSource(root), new StreamResult(writer)); + String documentString = writer.toString(); + // Assert that there is only two grants present in the metadata. If more grants are needed to test, // add to the setup - assertEquals(1, grantElements.size()); + assertEquals(2, grantElements.size()); List asGrants = grantElements.stream().map(element -> { DepositMetadata.Grant asGrant = new DepositMetadata.Grant(); @@ -270,13 +285,22 @@ public void testPackageMetadata() throws Exception { }).toList(); //TODO add assertions checking the serialized metadata is in the submission metadata - for (DepositMetadata.Grant grant : asGrants) { + List subGrantMetaData = submission.getMetadata().getGrantsMetadata(); + for (DepositMetadata.Grant subGrant : subGrantMetaData) { + String subGrantId = subGrant.getGrantId(); + + // Find the associated grant from asGrants that matches the ID + Optional metaDataGrant = asGrants.stream() + .filter(asGrant -> asGrant.getGrantId().equals(subGrantId)) + .findFirst(); + //assert that the grant ID exists and is valid to the submission data - //assertTrue(submission.getMetadata().getGrantsMetadata().get()); + assertEquals(subGrant.getGrantId(), metaDataGrant.get().getGrantId()); + assertEquals(subGrant.getGrantPi().getFirstName(), metaDataGrant.get().getGrantPi().getFirstName()); + assertEquals(subGrant.getGrantPi().getLastName(), metaDataGrant.get().getGrantPi().getLastName()); } - // Assert that the DOI is present in the metadata assertEquals(submission.getMetadata().getArticleMetadata().getDoi().toString(), root.getAttribute("doi")); diff --git a/pass-deposit-services/deposit-core/src/test/resources/submissions/sample1.json b/pass-deposit-services/deposit-core/src/test/resources/submissions/sample1.json index 5b1d56aa..70d649a3 100644 --- a/pass-deposit-services/deposit-core/src/test/resources/submissions/sample1.json +++ b/pass-deposit-services/deposit-core/src/test/resources/submissions/sample1.json @@ -167,6 +167,24 @@ "id": "13", "@type": "Grant" }, + { + "awardNumber": "R01EY026618", + "awardStatus": "ACTIVE", + "localKey": "112234", + "projectName": "Optimal magnification and oculomotor strategies in low vision patients", + "awardDate": "2017-08-01T00:00:00.000Z", + "startDate": "2017-09-01T00:00:00.000Z", + "endDate": "2020-06-01T00:00:00.000Z", + "primaryFunder": "11", + "directFunder": "12", + "pi": "2", + "coPis": [ + "3", + "1" + ], + "id": "14", + "@type": "Grant" + }, { "metadata": "{\n \"agreements\": {\n \"JScholarship\": \"NON-EXCLUSIVE LICENSE FOR USE OF MATERIALS This non-exclusive license defines the terms for the deposit of Materials in all formats into the digital repository of materials collected, preserved and made available through the Johns Hopkins Digital Repository, JScholarship. The Contributor hereby grants to Johns Hopkins a royalty free, non-exclusive worldwide license to use, re-use, display, distribute, transmit, publish, re-publish or copy the Materials, either digitally or in print, or in any other medium, now or hereafter known, for the purpose of including the Materials hereby licensed in the collection of materials in the Johns Hopkins Digital Repository for educational use worldwide. In some cases, access to content may be restricted according to provisions established in negotiation with the copyright holder. This license shall not authorize the commercial use of the Materials by Johns Hopkins or any other person or organization, but such Materials shall be restricted to non-profit educational use. Persons may apply for commercial use by contacting the copyright holder. Copyright and any other intellectual property right in or to the Materials shall not be transferred by this agreement and shall remain with the Contributor, or the Copyright holder if different from the Contributor. Other than this limited license, the Contributor or Copyright holder retains all rights, title, copyright and other interest in the images licensed. If the submission contains material for which the Contributor does not hold copyright, the Contributor represents that s/he has obtained the permission of the Copyright owner to grant Johns Hopkins the rights required by this license, and that such third-party owned material is clearly identified and acknowledged within the text or content of the submission. If the submission is based upon work that has been sponsored or supported by an agency or organization other than Johns Hopkins, the Contributor represents that s/he has fulfilled any right of review or other obligations required by such contract or agreement. Johns Hopkins will not make any alteration, other than as allowed by this license, to your submission. This agreement embodies the entire agreement of the parties. No modification of this agreement shall be of any effect unless it is made in writing and signed by all of the parties to the agreement.\"\n },\n \"abstract\": \"Differential enhancement of luminal growth factor bioactivity and targeted regional gut growth occurs dependent on dietary protein supplement.\",\n \"authors\": [\n {\n \"author\": \"Tania Marchbank\",\n \"orcid\": \"http://orcid.org/0000-0003-2076-9098\"\n },\n {\n \"author\": \"Nikki Mandir\"\n },\n {\n \"author\": \"Denis Calnan\"\n },\n {\n \"author\": \"Robert A. Goodlad\"\n },\n {\n \"author\": \"Theo Podas\"\n },\n {\n \"author\": \"Raymond J. Playford\",\n \"orcid\": \"http://orcid.org/0000-0003-1235-8504\"\n }\n ],\n \"doi\": \"10.1039/c7fo01251a\",\n \"Embargo-end-date\": \"2018-06-30\",\n \"journal-NLMTA-ID\": \"Food Funct\",\n \"journal-title\": \"Food & Function\",\n \"journal-title-short\": \"Food Funct.\",\n \"issue\": \"1\",\n \"issns\": [\n {\n \"issn\": \"2042-6496\",\n \"pubType\": \"Print\"\n },\n {\n \"issn\": \"2042-650X\",\n \"pubType\": \"Online\"\n }\n ],\n \"publisher\": \"Royal Society of Chemistry (RSC)\",\n \"publicationDate\": \"2018-09-12\",\n \"title\": \"Specific protein supplementation using soya, casein or whey differentially affects regional gut growth and luminal growth factor bioactivity in rats; implications for the treatment of gut injury and stimulating repair\",\n \"volume\": \"9\"\n}", "source": "PASS", @@ -183,9 +201,10 @@ ], "submitter": "2", "grants": [ - "13" + "13", + "14" ], - "id": "14", + "id": "15", "@type": "Submission" }, { @@ -194,8 +213,8 @@ "description": "Custodial content", "fileRole": "SUPPLEMENTAL", "mimeType": "image/jpg", - "submission": "14", - "id": "15", + "submission": "15", + "id": "16", "@type": "File" }, { @@ -204,8 +223,8 @@ "description": "Custodial content", "fileRole": "FIGURE", "mimeType": "image/tiff", - "submission": "14", - "id": "16", + "submission": "15", + "id": "17", "@type": "File" }, { @@ -214,8 +233,8 @@ "description": "Custodial content", "fileRole": "FIGURE", "mimeType": "image/png", - "submission": "14", - "id": "17", + "submission": "15", + "id": "18", "@type": "File" }, { @@ -224,8 +243,8 @@ "description": "Custodial content", "fileRole": "MANUSCRIPT", "mimeType": "application/msword", - "submission": "14", - "id": "18", + "submission": "15", + "id": "19", "@type": "File" }, { @@ -234,8 +253,8 @@ "description": "Custodial content", "fileRole": "TABLE", "mimeType": "application/vnd.oasis.opendocument.spreadsheet", - "submission": "14", - "id": "19", + "submission": "15", + "id": "20", "@type": "File" }, { @@ -244,8 +263,8 @@ "description": "Custodial content, meant to conflict with NIH package spec", "fileRole": "SUPPLEMENTAL", "mimeType": "application/xml", - "submission": "14", - "id": "20", + "submission": "15", + "id": "21", "@type": "File" }, { @@ -254,8 +273,8 @@ "description": "Custodial content, meant to conflict with NIH package spec", "fileRole": "SUPPLEMENTAL", "mimeType": "text/plain", - "submission": "14", - "id": "21", + "submission": "15", + "id": "22", "@type": "File" }, { @@ -264,8 +283,8 @@ "description": "Custodial content with a space in the filename", "fileRole": "SUPPLEMENTAL", "mimeType": "text/plain", - "submission": "14", - "id": "22", + "submission": "15", + "id": "23", "@type": "File" } ]