BrBETA_dnet-hadoop/dhp-common/src/test/java/eu/dnetlib/dhp/common/api/ZenodoAPIClientTest.java

81 lines
2.4 KiB
Java
Raw Normal View History

package eu.dnetlib.dhp.common.api;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
2020-08-10 11:59:10 +02:00
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class ZenodoAPIClientTest {
2020-08-10 11:59:10 +02:00
private final String URL_STRING = "https://sandbox.zenodo.org/api/deposit/depositions";
private final String ACCESS_TOKEN = "";
2020-08-10 11:59:10 +02:00
private final String CONCEPT_REC_ID = "657113";
2020-08-10 11:59:10 +02:00
@Test
public void testNewDeposition() throws IOException {
2020-08-10 11:59:10 +02:00
ZenodoAPIClient client = new ZenodoAPIClient(URL_STRING,
ACCESS_TOKEN);
Assertions.assertEquals(201, client.newDeposition());
2020-08-10 11:59:10 +02:00
File file = new File(getClass()
.getResource("/eu/dnetlib/dhp/common/api/newDeposition")
.getPath());
2020-08-10 11:59:10 +02:00
InputStream is = new FileInputStream(file);
2020-08-10 11:59:10 +02:00
Assertions.assertEquals(200, client.uploadIS(is, "first_deposition", file.length()));
2020-08-10 11:59:10 +02:00
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\"}}";
2020-08-10 11:59:10 +02:00
Assertions.assertEquals(200, client.sendMretadata(metadata));
2020-08-10 11:59:10 +02:00
Assertions.assertEquals(202, client.publish());
2020-08-10 11:59:10 +02:00
}
2020-08-10 11:59:10 +02:00
@Test
public void testNewVersionNewName() throws IOException, MissingConceptDoiException {
2020-08-10 11:59:10 +02:00
ZenodoAPIClient client = new ZenodoAPIClient(URL_STRING,
ACCESS_TOKEN);
2020-08-10 11:59:10 +02:00
Assertions.assertEquals(201, client.newVersion(CONCEPT_REC_ID));
2020-08-10 11:59:10 +02:00
File file = new File(getClass()
.getResource("/eu/dnetlib/dhp/common/api/newVersion")
.getPath());
2020-08-10 11:59:10 +02:00
InputStream is = new FileInputStream(file);
2020-08-10 11:59:10 +02:00
Assertions.assertEquals(200, client.uploadIS(is, "newVersion_deposition", file.length()));
2020-08-10 11:59:10 +02:00
Assertions.assertEquals(202, client.publish());
2020-08-10 11:59:10 +02:00
}
2020-08-10 11:59:10 +02:00
@Test
public void testNewVersionOldName() throws IOException, MissingConceptDoiException {
2020-08-10 11:59:10 +02:00
ZenodoAPIClient client = new ZenodoAPIClient(URL_STRING,
ACCESS_TOKEN);
2020-08-10 11:59:10 +02:00
Assertions.assertEquals(201, client.newVersion(CONCEPT_REC_ID));
2020-08-10 11:59:10 +02:00
File file = new File(getClass()
.getResource("/eu/dnetlib/dhp/common/api/newVersion2")
.getPath());
2020-08-10 11:59:10 +02:00
InputStream is = new FileInputStream(file);
2020-08-10 11:59:10 +02:00
Assertions.assertEquals(200, client.uploadIS(is, "newVersion_deposition", file.length()));
2020-08-10 11:59:10 +02:00
Assertions.assertEquals(202, client.publish());
2020-08-10 11:59:10 +02:00
}
}