From a6df01d329b8d3e993d1f7ab56e0574b9c024af4 Mon Sep 17 00:00:00 2001 From: "miriam.baglioni" Date: Mon, 10 Aug 2020 11:59:10 +0200 Subject: [PATCH] - --- .../dhp/common/api/ZenodoAPIClientTest.java | 99 ++++++++----------- 1 file changed, 43 insertions(+), 56 deletions(-) diff --git a/dhp-common/src/test/java/eu/dnetlib/dhp/common/api/ZenodoAPIClientTest.java b/dhp-common/src/test/java/eu/dnetlib/dhp/common/api/ZenodoAPIClientTest.java index c18394f8b..a091e2668 100644 --- a/dhp-common/src/test/java/eu/dnetlib/dhp/common/api/ZenodoAPIClientTest.java +++ b/dhp-common/src/test/java/eu/dnetlib/dhp/common/api/ZenodoAPIClientTest.java @@ -1,93 +1,80 @@ package eu.dnetlib.dhp.common.api; -import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.fs.*; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; -import java.nio.file.Files; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class ZenodoAPIClientTest { - private final String URL_STRING = "https://sandbox.zenodo.org/api/deposit/depositions"; - private final String ACCESS_TOKEN = "5ImUj0VC1ICg4ifK5dc3AGzJhcfAB4osxrFlsr8WxHXxjaYgCE0hY8HZcDoe"; + private final String URL_STRING = "https://sandbox.zenodo.org/api/deposit/depositions"; + private final String ACCESS_TOKEN = ""; - private final String CONCEPT_REC_ID = "657113"; + private final String CONCEPT_REC_ID = "657113"; + @Test + public void testNewDeposition() throws IOException { + ZenodoAPIClient client = new ZenodoAPIClient(URL_STRING, + ACCESS_TOKEN); + Assertions.assertEquals(201, client.newDeposition()); - @Test - public void testNewDeposition() throws IOException { + File file = new File(getClass() + .getResource("/eu/dnetlib/dhp/common/api/newDeposition") + .getPath()); - ZenodoAPIClient client = new ZenodoAPIClient(URL_STRING, - ACCESS_TOKEN); - Assertions.assertEquals(201, client.newDeposition()); + InputStream is = new FileInputStream(file); - File file = new File(getClass() - .getResource("/eu/dnetlib/dhp/common/api/newDeposition") - .getPath()); + Assertions.assertEquals(200, client.uploadIS(is, "first_deposition", file.length())); - InputStream is = new FileInputStream(file); + String metadata = "{\"metadata\":{\"access_right\":\"open\",\"creators\":[{\"affiliation\":\"ISTI - CNR\",\"name\":\"Baglioni, Miriam\",\"orcid\":\"0000-0002-2273-9004\"}],\"description\":\"\\u003cp\\u003eThis is a test for the automatic upload of files in a new deposition\\u003c/p\\u003e \",\"title\":\"Test.\",\"upload_type\":\"other\",\"version\":\"1.0\"}}"; - Assertions.assertEquals(200,client.uploadIS(is, "first_deposition", file.length())); + Assertions.assertEquals(200, client.sendMretadata(metadata)); + Assertions.assertEquals(202, client.publish()); - String metadata = "{\"metadata\":{\"access_right\":\"open\",\"creators\":[{\"affiliation\":\"ISTI - CNR\",\"name\":\"Baglioni, Miriam\",\"orcid\":\"0000-0002-2273-9004\"}],\"description\":\"\\u003cp\\u003eThis is a test for the automatic upload of files in a new deposition\\u003c/p\\u003e \",\"title\":\"Test.\",\"upload_type\":\"other\",\"version\":\"1.0\"}}"; + } - Assertions.assertEquals(200, client.sendMretadata(metadata)); + @Test + public void testNewVersionNewName() throws IOException, MissingConceptDoiException { - Assertions.assertEquals(202, client.publish()); + ZenodoAPIClient client = new ZenodoAPIClient(URL_STRING, + ACCESS_TOKEN); - } + Assertions.assertEquals(201, client.newVersion(CONCEPT_REC_ID)); + File file = new File(getClass() + .getResource("/eu/dnetlib/dhp/common/api/newVersion") + .getPath()); - @Test - public void testNewVersionNewName() throws IOException, MissingConceptDoiException { + InputStream is = new FileInputStream(file); + Assertions.assertEquals(200, client.uploadIS(is, "newVersion_deposition", file.length())); - ZenodoAPIClient client = new ZenodoAPIClient(URL_STRING, - ACCESS_TOKEN); + Assertions.assertEquals(202, client.publish()); - Assertions.assertEquals(201, client.newVersion(CONCEPT_REC_ID)); + } - File file = new File(getClass() - .getResource("/eu/dnetlib/dhp/common/api/newVersion") - .getPath()); + @Test + public void testNewVersionOldName() throws IOException, MissingConceptDoiException { - InputStream is = new FileInputStream(file); + ZenodoAPIClient client = new ZenodoAPIClient(URL_STRING, + ACCESS_TOKEN); - Assertions.assertEquals(200, client.uploadIS(is, "newVersion_deposition", file.length())); + Assertions.assertEquals(201, client.newVersion(CONCEPT_REC_ID)); + File file = new File(getClass() + .getResource("/eu/dnetlib/dhp/common/api/newVersion2") + .getPath()); - Assertions.assertEquals(202, client.publish()); + InputStream is = new FileInputStream(file); - } + Assertions.assertEquals(200, client.uploadIS(is, "newVersion_deposition", file.length())); - @Test - public void testNewVersionOldName() throws IOException, MissingConceptDoiException { + Assertions.assertEquals(202, client.publish()); - - ZenodoAPIClient client = new ZenodoAPIClient(URL_STRING, - ACCESS_TOKEN); - - Assertions.assertEquals(201, client.newVersion(CONCEPT_REC_ID)); - - File file = new File(getClass() - .getResource("/eu/dnetlib/dhp/common/api/newVersion2") - .getPath()); - - InputStream is = new FileInputStream(file); - - Assertions.assertEquals(200, client.uploadIS(is, "newVersion_deposition", file.length())); - - - Assertions.assertEquals(202, client.publish()); - - } + } }