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

110 lines
3.0 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;
import org.apache.commons.io.IOUtils;
2020-08-10 11:59:10 +02:00
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
2020-08-10 11:59:10 +02:00
import org.junit.jupiter.api.Test;
2020-10-27 17:45:58 +01:00
@Disabled
2021-08-11 12:13:22 +02:00
class ZenodoAPIClientTest {
2020-08-10 11:59:10 +02:00
private final String URL_STRING = "https://sandbox.zenodo.org/api/deposit/depositions";
2020-08-12 09:39:58 +02:00
private final String ACCESS_TOKEN = "";
2020-08-10 11:59:10 +02:00
private final String CONCEPT_REC_ID = "657113";
2020-09-25 16:33:43 +02:00
private final String depositionId = "674915";
@Test
2021-08-11 12:13:22 +02:00
void testUploadOldDeposition() throws IOException, MissingConceptDoiException {
2020-09-25 16:33:43 +02:00
ZenodoAPIClient client = new ZenodoAPIClient(URL_STRING,
ACCESS_TOKEN);
Assertions.assertEquals(200, client.uploadOpenDeposition(depositionId));
File file = new File(getClass()
.getResource("/eu/dnetlib/dhp/common/api/COVID-19.json.gz")
.getPath());
InputStream is = new FileInputStream(file);
Assertions.assertEquals(200, client.uploadIS(is, "COVID-19.json.gz", file.length()));
String metadata = IOUtils.toString(getClass().getResourceAsStream("/eu/dnetlib/dhp/common/api/metadata.json"));
Assertions.assertEquals(200, client.sendMretadata(metadata));
Assertions.assertEquals(202, client.publish());
}
2020-08-10 11:59:10 +02:00
@Test
2021-08-11 12:13:22 +02:00
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/COVID-19.json.gz")
2020-08-10 11:59:10 +02:00
.getPath());
2020-08-10 11:59:10 +02:00
InputStream is = new FileInputStream(file);
Assertions.assertEquals(200, client.uploadIS(is, "COVID-19.json.gz", file.length()));
String metadata = IOUtils.toString(getClass().getResourceAsStream("/eu/dnetlib/dhp/common/api/metadata.json"));
2020-08-10 11:59:10 +02:00
Assertions.assertEquals(200, client.sendMretadata(metadata));
Assertions.assertEquals(202, client.publish());
2020-08-10 11:59:10 +02:00
}
2020-08-10 11:59:10 +02:00
@Test
2021-08-11 12:13:22 +02:00
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
2021-08-11 12:13:22 +02:00
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
}
}