2020-05-15 19:49:26 +02:00
|
|
|
|
|
|
|
package eu.dnetlib.doiboost.orcid;
|
|
|
|
|
2021-09-20 18:25:00 +02:00
|
|
|
import static org.junit.jupiter.api.Assertions.*;
|
2020-05-15 19:49:26 +02:00
|
|
|
|
2020-07-03 23:30:31 +02:00
|
|
|
import java.io.*;
|
|
|
|
import java.nio.file.Files;
|
2020-11-23 09:49:22 +01:00
|
|
|
import java.nio.file.Path;
|
|
|
|
import java.nio.file.StandardOpenOption;
|
2020-05-15 19:49:26 +02:00
|
|
|
import java.text.ParseException;
|
|
|
|
import java.text.SimpleDateFormat;
|
2021-04-01 17:07:49 +02:00
|
|
|
import java.util.*;
|
2020-05-15 19:49:26 +02:00
|
|
|
|
2020-11-23 09:49:22 +01:00
|
|
|
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
|
|
|
|
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
|
|
|
|
import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
|
2021-04-01 17:07:49 +02:00
|
|
|
import org.apache.commons.compress.utils.Lists;
|
2020-05-15 19:49:26 +02:00
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
|
import org.apache.http.client.methods.HttpGet;
|
|
|
|
import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
|
import org.apache.http.impl.client.HttpClients;
|
2021-04-01 17:07:49 +02:00
|
|
|
import org.junit.jupiter.api.BeforeAll;
|
|
|
|
import org.junit.jupiter.api.Disabled;
|
2020-05-15 19:49:26 +02:00
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
|
|
|
import eu.dnetlib.dhp.application.ArgumentApplicationParser;
|
2021-09-20 18:25:00 +02:00
|
|
|
import eu.dnetlib.dhp.common.collection.CollectorException;
|
|
|
|
import eu.dnetlib.dhp.common.collection.HttpClientParams;
|
2021-04-01 17:07:49 +02:00
|
|
|
import eu.dnetlib.dhp.schema.orcid.AuthorData;
|
2021-09-20 18:25:00 +02:00
|
|
|
import eu.dnetlib.doiboost.orcid.util.DownloadsReport;
|
|
|
|
import eu.dnetlib.doiboost.orcid.util.MultiAttemptsHttpConnector;
|
2020-05-15 19:49:26 +02:00
|
|
|
|
|
|
|
public class OrcidClientTest {
|
|
|
|
final int REQ_LIMIT = 24;
|
|
|
|
final int REQ_MAX_TEST = 100;
|
|
|
|
final int RECORD_DOWNLOADED_COUNTER_LOG_INTERVAL = 10;
|
|
|
|
final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
|
|
|
|
final String toRetrieveDate = "2020-05-06 23:59:46.031145";
|
|
|
|
String toNotRetrieveDate = "2019-09-29 23:59:59.000000";
|
|
|
|
String lastUpdate = "2019-09-30 00:00:00";
|
|
|
|
String shortDate = "2020-05-06 16:06:11";
|
2021-04-01 17:07:49 +02:00
|
|
|
final String REQUEST_TYPE_RECORD = "record";
|
|
|
|
final String REQUEST_TYPE_WORK = "work/47652866";
|
|
|
|
final String REQUEST_TYPE_WORKS = "works";
|
|
|
|
|
|
|
|
private static Path testPath;
|
|
|
|
|
|
|
|
@BeforeAll
|
|
|
|
private static void setUp() throws IOException {
|
2021-09-20 18:25:00 +02:00
|
|
|
testPath = Files.createTempDirectory(OrcidClientTest.class.getName());
|
2021-04-01 17:07:49 +02:00
|
|
|
System.out.println("using test path: " + testPath);
|
|
|
|
}
|
2020-05-15 19:49:26 +02:00
|
|
|
|
2020-07-03 23:30:31 +02:00
|
|
|
// curl -i -H "Accept: application/vnd.orcid+xml"
|
2020-05-15 19:49:26 +02:00
|
|
|
// -H 'Authorization: Bearer 78fdb232-7105-4086-8570-e153f4198e3d'
|
|
|
|
// 'https://api.orcid.org/v3.0/0000-0001-7291-3210/record'
|
|
|
|
|
2020-07-03 23:30:31 +02:00
|
|
|
@Test
|
2021-08-11 12:13:22 +02:00
|
|
|
void downloadTest() throws Exception {
|
2021-04-01 17:07:49 +02:00
|
|
|
final String orcid = "0000-0001-7291-3210";
|
|
|
|
String record = testDownloadRecord(orcid, REQUEST_TYPE_RECORD);
|
|
|
|
String filename = testPath + "/downloaded_record_".concat(orcid).concat(".xml");
|
2020-11-23 09:49:22 +01:00
|
|
|
File f = new File(filename);
|
2020-07-03 23:30:31 +02:00
|
|
|
OutputStream outStream = new FileOutputStream(f);
|
|
|
|
IOUtils.write(record.getBytes(), outStream);
|
|
|
|
}
|
|
|
|
|
2021-04-01 17:07:49 +02:00
|
|
|
private String testDownloadRecord(String orcidId, String dataType) throws Exception {
|
2020-05-15 19:49:26 +02:00
|
|
|
try (CloseableHttpClient client = HttpClients.createDefault()) {
|
2021-04-01 17:07:49 +02:00
|
|
|
HttpGet httpGet = new HttpGet("https://api.orcid.org/v3.0/" + orcidId + "/" + dataType);
|
2020-05-15 19:49:26 +02:00
|
|
|
httpGet.addHeader("Accept", "application/vnd.orcid+xml");
|
|
|
|
httpGet.addHeader("Authorization", "Bearer 78fdb232-7105-4086-8570-e153f4198e3d");
|
2021-04-01 17:07:49 +02:00
|
|
|
long start = System.currentTimeMillis();
|
2020-05-15 19:49:26 +02:00
|
|
|
CloseableHttpResponse response = client.execute(httpGet);
|
2021-04-01 17:07:49 +02:00
|
|
|
long end = System.currentTimeMillis();
|
2020-05-15 19:49:26 +02:00
|
|
|
if (response.getStatusLine().getStatusCode() != 200) {
|
2021-04-01 17:07:49 +02:00
|
|
|
logToFile(
|
|
|
|
testPath, "Downloading " + orcidId + " status code: " + response.getStatusLine().getStatusCode());
|
2020-05-15 19:49:26 +02:00
|
|
|
}
|
2021-04-01 17:07:49 +02:00
|
|
|
logToFile(testPath, orcidId + " " + dataType + " " + (end - start) / 1000 + " seconds");
|
2020-05-15 19:49:26 +02:00
|
|
|
return IOUtils.toString(response.getEntity().getContent());
|
|
|
|
} catch (Throwable e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2021-05-14 10:58:12 +02:00
|
|
|
return "";
|
2020-05-15 19:49:26 +02:00
|
|
|
}
|
|
|
|
|
2020-11-23 09:49:22 +01:00
|
|
|
// @Test
|
2020-07-02 18:46:20 +02:00
|
|
|
private void testLambdaFileParser() throws Exception {
|
2020-05-15 19:49:26 +02:00
|
|
|
try (BufferedReader br = new BufferedReader(
|
|
|
|
new InputStreamReader(this.getClass().getResourceAsStream("last_modified.csv")))) {
|
|
|
|
String line;
|
|
|
|
int counter = 0;
|
|
|
|
int nReqTmp = 0;
|
|
|
|
long startDownload = System.currentTimeMillis();
|
|
|
|
long startReqTmp = System.currentTimeMillis();
|
|
|
|
while ((line = br.readLine()) != null) {
|
|
|
|
counter++;
|
|
|
|
// skip headers line
|
|
|
|
if (counter == 1) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
String[] values = line.split(",");
|
|
|
|
List<String> recordInfo = Arrays.asList(values);
|
2021-04-01 17:07:49 +02:00
|
|
|
testDownloadRecord(recordInfo.get(0), REQUEST_TYPE_RECORD);
|
2020-05-15 19:49:26 +02:00
|
|
|
long endReq = System.currentTimeMillis();
|
|
|
|
nReqTmp++;
|
|
|
|
if (nReqTmp == REQ_LIMIT) {
|
|
|
|
long reqSessionDuration = endReq - startReqTmp;
|
|
|
|
if (reqSessionDuration <= 1000) {
|
|
|
|
System.out
|
|
|
|
.println(
|
|
|
|
"\nreqSessionDuration: " + reqSessionDuration + " nReqTmp: " + nReqTmp + " wait ....");
|
|
|
|
Thread.sleep(1000 - reqSessionDuration);
|
|
|
|
} else {
|
|
|
|
nReqTmp = 0;
|
|
|
|
startReqTmp = System.currentTimeMillis();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (counter > REQ_MAX_TEST) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ((counter % RECORD_DOWNLOADED_COUNTER_LOG_INTERVAL) == 0) {
|
|
|
|
System.out.println("Current record downloaded: " + counter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
long endDownload = System.currentTimeMillis();
|
|
|
|
long downloadTime = endDownload - startDownload;
|
|
|
|
System.out.println("Download time: " + ((downloadTime / 1000) / 60) + " minutes");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-23 09:49:22 +01:00
|
|
|
// @Test
|
2020-07-03 23:30:31 +02:00
|
|
|
private void getRecordDatestamp() throws ParseException {
|
2020-05-15 19:49:26 +02:00
|
|
|
Date toRetrieveDateDt = new SimpleDateFormat(DATE_FORMAT).parse(toRetrieveDate);
|
|
|
|
Date toNotRetrieveDateDt = new SimpleDateFormat(DATE_FORMAT).parse(toNotRetrieveDate);
|
|
|
|
Date lastUpdateDt = new SimpleDateFormat(DATE_FORMAT).parse(lastUpdate);
|
|
|
|
assertTrue(toRetrieveDateDt.after(lastUpdateDt));
|
|
|
|
assertTrue(!toNotRetrieveDateDt.after(lastUpdateDt));
|
|
|
|
}
|
|
|
|
|
2020-07-03 23:30:31 +02:00
|
|
|
private void testDate(String value) throws ParseException {
|
2021-05-14 10:58:12 +02:00
|
|
|
System.out.println(value);
|
2020-05-15 19:49:26 +02:00
|
|
|
if (value.length() != 19) {
|
|
|
|
value = value.substring(0, 19);
|
|
|
|
}
|
|
|
|
Date valueDt = new SimpleDateFormat(DATE_FORMAT).parse(value);
|
|
|
|
System.out.println(valueDt.toString());
|
|
|
|
}
|
|
|
|
|
2020-11-23 09:49:22 +01:00
|
|
|
// @Test
|
2023-12-18 15:46:36 +01:00
|
|
|
@Disabled
|
2020-07-03 23:30:31 +02:00
|
|
|
private void testModifiedDate() throws ParseException {
|
2020-05-15 19:49:26 +02:00
|
|
|
testDate(toRetrieveDate);
|
|
|
|
testDate(toNotRetrieveDate);
|
|
|
|
testDate(shortDate);
|
|
|
|
}
|
|
|
|
|
2020-11-23 09:49:22 +01:00
|
|
|
@Test
|
2021-08-11 15:02:51 +02:00
|
|
|
@Disabled
|
2022-07-25 12:37:39 +02:00
|
|
|
void testReadBase64CompressedWork() throws Exception {
|
2020-05-15 19:49:26 +02:00
|
|
|
final String base64CompressedRecord = IOUtils
|
2022-07-25 12:37:39 +02:00
|
|
|
.toString(getClass().getResourceAsStream("0000-0001-7281-6306.compressed.base64"));
|
2020-05-15 19:49:26 +02:00
|
|
|
final String recordFromSeqFile = ArgumentApplicationParser.decompressValue(base64CompressedRecord);
|
2021-04-01 17:07:49 +02:00
|
|
|
logToFile(testPath, "\n\ndownloaded \n\n" + recordFromSeqFile);
|
2020-05-15 19:49:26 +02:00
|
|
|
}
|
2020-11-23 09:49:22 +01:00
|
|
|
|
|
|
|
@Test
|
2021-04-01 17:07:49 +02:00
|
|
|
@Disabled
|
2021-08-11 12:13:22 +02:00
|
|
|
void lambdaFileReaderTest() throws Exception {
|
2021-04-01 17:07:49 +02:00
|
|
|
String last_update = "2021-01-12 00:00:06.685137";
|
2020-11-23 09:49:22 +01:00
|
|
|
TarArchiveInputStream input = new TarArchiveInputStream(
|
2021-04-01 17:07:49 +02:00
|
|
|
new GzipCompressorInputStream(new FileInputStream("/tmp/last_modified.csv.tar")));
|
2020-11-23 09:49:22 +01:00
|
|
|
TarArchiveEntry entry = input.getNextTarEntry();
|
|
|
|
BufferedReader br = null;
|
|
|
|
StringBuilder sb = new StringBuilder();
|
2021-04-01 17:07:49 +02:00
|
|
|
int rowNum = 1;
|
|
|
|
int modifiedNum = 1;
|
2020-11-23 09:49:22 +01:00
|
|
|
int entryNum = 0;
|
2021-04-01 17:07:49 +02:00
|
|
|
boolean firstNotModifiedFound = false;
|
2020-11-23 09:49:22 +01:00
|
|
|
while (entry != null) {
|
|
|
|
br = new BufferedReader(new InputStreamReader(input)); // Read directly from tarInput
|
|
|
|
String line;
|
|
|
|
while ((line = br.readLine()) != null) {
|
2021-05-14 10:58:12 +02:00
|
|
|
String[] values = line.split(",");
|
2020-11-23 09:49:22 +01:00
|
|
|
List<String> recordInfo = Arrays.asList(values);
|
2021-08-11 12:13:22 +02:00
|
|
|
assertEquals(4, recordInfo.size());
|
2021-04-01 17:07:49 +02:00
|
|
|
String orcid = recordInfo.get(0);
|
|
|
|
String modifiedDate = recordInfo.get(3);
|
2020-11-23 09:49:22 +01:00
|
|
|
rowNum++;
|
2021-04-01 17:07:49 +02:00
|
|
|
if (rowNum == 2) {
|
2020-11-23 09:49:22 +01:00
|
|
|
assertTrue(recordInfo.get(3).equals("last_modified"));
|
2021-04-01 17:07:49 +02:00
|
|
|
} else {
|
|
|
|
// SparkDownloadOrcidAuthors.lastUpdate = last_update;
|
|
|
|
// boolean isModified = SparkDownloadOrcidAuthors.isModified(orcid, modifiedDate);
|
|
|
|
// if (isModified) {
|
|
|
|
// modifiedNum++;
|
|
|
|
// } else {
|
|
|
|
// if (!firstNotModifiedFound) {
|
|
|
|
// firstNotModifiedFound = true;
|
|
|
|
// logToFile(orcid + " - " + modifiedDate + " > " + isModified);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
2020-11-23 09:49:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
entryNum++;
|
|
|
|
assertTrue(entryNum == 1);
|
|
|
|
entry = input.getNextTarEntry();
|
|
|
|
|
|
|
|
}
|
2021-04-01 17:07:49 +02:00
|
|
|
logToFile(testPath, "modifiedNum : " + modifiedNum + " / " + rowNum);
|
2020-11-23 09:49:22 +01:00
|
|
|
}
|
|
|
|
|
2021-04-01 17:07:49 +02:00
|
|
|
public static void logToFile(Path basePath, String log) throws IOException {
|
2020-11-23 09:49:22 +01:00
|
|
|
log = log.concat("\n");
|
2021-04-01 17:07:49 +02:00
|
|
|
Path path = basePath.resolve("orcid_log.txt");
|
|
|
|
if (!Files.exists(path)) {
|
|
|
|
Files.createFile(path);
|
|
|
|
}
|
2020-11-23 09:49:22 +01:00
|
|
|
Files.write(path, log.getBytes(), StandardOpenOption.APPEND);
|
|
|
|
}
|
2020-11-24 17:49:32 +01:00
|
|
|
|
|
|
|
@Test
|
2021-04-01 17:07:49 +02:00
|
|
|
@Disabled
|
2020-11-24 17:49:32 +01:00
|
|
|
private void slowedDownDownloadTest() throws Exception {
|
|
|
|
String orcid = "0000-0001-5496-1243";
|
|
|
|
String record = slowedDownDownload(orcid);
|
|
|
|
String filename = "/tmp/downloaded_".concat(orcid).concat(".xml");
|
|
|
|
File f = new File(filename);
|
|
|
|
OutputStream outStream = new FileOutputStream(f);
|
|
|
|
IOUtils.write(record.getBytes(), outStream);
|
|
|
|
}
|
|
|
|
|
|
|
|
private String slowedDownDownload(String orcidId) throws Exception {
|
|
|
|
try (CloseableHttpClient client = HttpClients.createDefault()) {
|
|
|
|
HttpGet httpGet = new HttpGet("https://api.orcid.org/v3.0/" + orcidId + "/record");
|
|
|
|
httpGet.addHeader("Accept", "application/vnd.orcid+xml");
|
|
|
|
httpGet.addHeader("Authorization", "Bearer 78fdb232-7105-4086-8570-e153f4198e3d");
|
|
|
|
long start = System.currentTimeMillis();
|
|
|
|
CloseableHttpResponse response = client.execute(httpGet);
|
|
|
|
long endReq = System.currentTimeMillis();
|
|
|
|
long reqSessionDuration = endReq - start;
|
2021-04-01 17:07:49 +02:00
|
|
|
logToFile(testPath, "req time (millisec): " + reqSessionDuration);
|
2020-11-24 17:49:32 +01:00
|
|
|
if (reqSessionDuration < 1000) {
|
2021-04-01 17:07:49 +02:00
|
|
|
logToFile(testPath, "wait ....");
|
2020-11-24 17:49:32 +01:00
|
|
|
Thread.sleep(1000 - reqSessionDuration);
|
|
|
|
}
|
|
|
|
long end = System.currentTimeMillis();
|
|
|
|
long total = end - start;
|
2021-04-01 17:07:49 +02:00
|
|
|
logToFile(testPath, "total time (millisec): " + total);
|
2020-11-24 17:49:32 +01:00
|
|
|
if (response.getStatusLine().getStatusCode() != 200) {
|
2021-04-01 17:07:49 +02:00
|
|
|
logToFile(
|
|
|
|
testPath, "Downloading " + orcidId + " status code: " + response.getStatusLine().getStatusCode());
|
2020-11-24 17:49:32 +01:00
|
|
|
}
|
|
|
|
return IOUtils.toString(response.getEntity().getContent());
|
|
|
|
} catch (Throwable e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2021-05-14 10:58:12 +02:00
|
|
|
return "";
|
2020-11-24 17:49:32 +01:00
|
|
|
}
|
2021-04-01 17:07:49 +02:00
|
|
|
|
|
|
|
@Test
|
2021-08-11 12:13:22 +02:00
|
|
|
void downloadWorkTest() throws Exception {
|
2021-04-01 17:07:49 +02:00
|
|
|
String orcid = "0000-0003-0015-1952";
|
|
|
|
String record = testDownloadRecord(orcid, REQUEST_TYPE_WORK);
|
|
|
|
String filename = "/tmp/downloaded_work_".concat(orcid).concat(".xml");
|
|
|
|
File f = new File(filename);
|
|
|
|
OutputStream outStream = new FileOutputStream(f);
|
|
|
|
IOUtils.write(record.getBytes(), outStream);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2021-08-11 12:13:22 +02:00
|
|
|
void downloadRecordTest() throws Exception {
|
2021-04-01 17:07:49 +02:00
|
|
|
String orcid = "0000-0001-5004-5918";
|
|
|
|
String record = testDownloadRecord(orcid, REQUEST_TYPE_RECORD);
|
|
|
|
String filename = "/tmp/downloaded_record_".concat(orcid).concat(".xml");
|
|
|
|
File f = new File(filename);
|
|
|
|
OutputStream outStream = new FileOutputStream(f);
|
|
|
|
IOUtils.write(record.getBytes(), outStream);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2021-08-11 12:13:22 +02:00
|
|
|
void downloadWorksTest() throws Exception {
|
2021-04-01 17:07:49 +02:00
|
|
|
String orcid = "0000-0001-5004-5918";
|
|
|
|
String record = testDownloadRecord(orcid, REQUEST_TYPE_WORKS);
|
|
|
|
String filename = "/tmp/downloaded_works_".concat(orcid).concat(".xml");
|
|
|
|
File f = new File(filename);
|
|
|
|
OutputStream outStream = new FileOutputStream(f);
|
|
|
|
IOUtils.write(record.getBytes(), outStream);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2021-08-11 12:13:22 +02:00
|
|
|
void downloadSingleWorkTest() throws Exception {
|
2021-04-01 17:07:49 +02:00
|
|
|
String orcid = "0000-0001-5004-5918";
|
|
|
|
String record = testDownloadRecord(orcid, REQUEST_TYPE_WORK);
|
|
|
|
String filename = "/tmp/downloaded_work_47652866_".concat(orcid).concat(".xml");
|
|
|
|
File f = new File(filename);
|
|
|
|
OutputStream outStream = new FileOutputStream(f);
|
|
|
|
IOUtils.write(record.getBytes(), outStream);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2021-08-11 12:13:22 +02:00
|
|
|
void cleanAuthorListTest() throws Exception {
|
2021-04-01 17:07:49 +02:00
|
|
|
AuthorData a1 = new AuthorData();
|
|
|
|
a1.setOid("1");
|
|
|
|
a1.setName("n1");
|
|
|
|
a1.setSurname("s1");
|
|
|
|
a1.setCreditName("c1");
|
|
|
|
AuthorData a2 = new AuthorData();
|
|
|
|
a2.setOid("1");
|
|
|
|
a2.setName("n1");
|
|
|
|
a2.setSurname("s1");
|
|
|
|
a2.setCreditName("c1");
|
|
|
|
AuthorData a3 = new AuthorData();
|
|
|
|
a3.setOid("3");
|
|
|
|
a3.setName("n3");
|
|
|
|
a3.setSurname("s3");
|
|
|
|
a3.setCreditName("c3");
|
|
|
|
List<AuthorData> list = Lists.newArrayList();
|
|
|
|
list.add(a1);
|
|
|
|
list.add(a2);
|
|
|
|
list.add(a3);
|
|
|
|
|
|
|
|
Set<String> namesAlreadySeen = new HashSet<>();
|
|
|
|
assertTrue(list.size() == 3);
|
|
|
|
list.removeIf(a -> !namesAlreadySeen.add(a.getOid()));
|
|
|
|
assertTrue(list.size() == 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2023-12-18 15:46:36 +01:00
|
|
|
@Disabled
|
2021-08-11 12:13:22 +02:00
|
|
|
void testUpdatedRecord() throws Exception {
|
2021-04-01 17:07:49 +02:00
|
|
|
final String base64CompressedRecord = IOUtils
|
2022-07-25 12:37:39 +02:00
|
|
|
.toString(getClass().getResourceAsStream("0000-0001-7281-6306.compressed.base64"));
|
2021-04-01 17:07:49 +02:00
|
|
|
final String record = ArgumentApplicationParser.decompressValue(base64CompressedRecord);
|
|
|
|
logToFile(testPath, "\n\nrecord updated \n\n" + record);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2023-12-18 15:46:36 +01:00
|
|
|
@Disabled
|
2021-08-11 12:13:22 +02:00
|
|
|
void testUpdatedWork() throws Exception {
|
2021-04-01 17:07:49 +02:00
|
|
|
final String base64CompressedWork = "H4sIAAAAAAAAAM1XS2/jNhC+51cQOuxJsiXZSR03Vmq0G6Bo013E6R56oyXaZiOJWpKy4y783zvUg5Ksh5uiCJogisX5Zjj85sHx3f1rFKI94YKyeGE4I9tAJPZZQOPtwvj9+cGaGUhIHAc4ZDFZGEcijHvv6u7A+MtcPVCSSgsUQObYzuzaccBEguVuYYxt+LHgbwKP6a11M3WnY6UzrpB7KuiahlQeF0aSrkPqGwhcisWcxpLwGIcLYydlMh+PD4fDiHGfBvDcjmMxLhGlBglSH8vsIH0qGlLqBFRIGvvDWjWQ1iMJJ2CKBANqGlNqMbkj3IpxRPq1KkypFZFoDRHa0aRfq8JoNjhnfIAJJS6xPouiIQJyeYmGQzE+cO5cXqITcItBlKyASExD0a93jiwtvJDjYXDDAqBPHoH2wMmVWGNf8xyyaEBiSTeUDHHWBpd2Nmmc10yfbgHQrHCyIRxKjQwRUoFKPRwEnIgBnQJQVdGeQgJaCRN0OMnPkaUFVbD9WkpaIndQJowf+8EFoIpTErJjBFQOBavElFpfUxwC9ZcqvQErdQXhe+oPFF8BaObupYzVsYEOARzSoZBWmKqaBMHcV0Wf8oG0beIqD+Gdkz0lhyE3NajUW6fhQFSV9Nw/MCBYyofYa0EN7wrBz13eP+Y+J6obWgE8Pdd2JpYD94P77Ezmjj13b0bu5PqPu3EXumEnxEJaEVxSUIHammsra+53z44zt2/m1/bItaeVtQ6dhs3c4XytvW75IYUchMKvEHVUyqmnWBFAS0VJrqSvQde6vp251ux2NtFuKcVOi+oK9YY0M0Cn6o4J6WkvtEK2XJ1vfPGAZxSoK8lb+SxJBbLQx1CohOLndjJUywQWUFmqEi3G6Zaqf/7buOyYJd5IYpfmf0XipfP18pDR9cQCeEuJQI/Lx36bFbVnpBeL2UwmqQw7ApAvf4GeGGQdEbENgolui/wdpjHaYCmPCIPPAmGBIsxfoLUhyRCB0SeCakEBJRKBtfJ+UBbI15TG4PaGBAhWthx8DmFYtHZQujv1CWbLLdzmmUKmHEOWCe1/zdu78bn/+YH+hCOqOzcXfFwuP6OVT/P710crwqGXFrpNaM2GT3MXarw01i15TIi3pmtJXgtbTVGf3h6HKfF+wBAnPyTfdCChudlm5gZaoG//F9pPZsGQcqqbyZN5hBau5OoIJ3PPwjTKDuG4s5MZp2rMzF5PZoK34IT6PIFOPrk+mTiVO5aJH2C+JJRjE/06eoRfpJxa4VgyYaLlaJUv/EhCfATMU/76gEOfmehL/qbJNNHjaFna+CQYB8wvo9PpPFJ5MOrJ1Ix7USBZqBl7KRNOx1d3jex7SG6zuijqCMWRusBsncjZSrM2u82UJmqzpGhvUJN2t6caIM9QQgO9c0t40UROnWsJd2Rbs+nsxpna9u30ttNkjechmzHjEST+X5CkkuNY0GzQkzyFseAf7lSZuLwdh1xSXKvvQJ4g4abTYgPV7uMt3rskohlJmMa82kQkshtyBEIYqQ+YB8X3oRHg7iFKi/bZP+Ao+T6BJhIT/vNPi8ffZs+flk+r2v0WNroZiyWn6xRmadHqTJXsjLJczElAZX6TnJdoWTM1SI2gfutv3rjeBt5t06rVvNuWup29246tlvluO+u2/G92bK9DXheL6uFd/Q3EaRDZqBIAAA==";
|
|
|
|
final String work = ArgumentApplicationParser.decompressValue(base64CompressedWork);
|
|
|
|
logToFile(testPath, "\n\nwork updated \n\n" + work);
|
|
|
|
}
|
2021-09-20 18:25:00 +02:00
|
|
|
|
|
|
|
@Test
|
|
|
|
void downloadUnknownHostExceptionTest() throws Exception {
|
|
|
|
logToFile(testPath, "downloadUnknownHostExceptionTest");
|
|
|
|
final String orcid = "0000-0001-7291-3210";
|
|
|
|
final HttpClientParams clientParams = new HttpClientParams();
|
|
|
|
clientParams.setMaxNumberOfRetry(2);
|
|
|
|
MultiAttemptsHttpConnector httpConnector = new MultiAttemptsHttpConnector(clientParams);
|
|
|
|
httpConnector.setAuthMethod(MultiAttemptsHttpConnector.BEARER);
|
|
|
|
httpConnector.setAcceptHeaderValue("application/vnd.orcid+xml");
|
|
|
|
httpConnector.setAuthToken("78fdb232-7105-4086-8570-e153f4198e3d");
|
|
|
|
String wrongApiUrl = "https://api.orcid_UNKNOWN.org/v3.0/" + orcid + "/" + REQUEST_TYPE_RECORD;
|
|
|
|
String url = "UNKNOWN";
|
|
|
|
DownloadsReport report = new DownloadsReport();
|
|
|
|
try {
|
|
|
|
httpConnector.getInputSource(wrongApiUrl, report);
|
|
|
|
} catch (CollectorException ce) {
|
|
|
|
logToFile(testPath, "CollectorException downloading: " + ce.getMessage());
|
|
|
|
} catch (Throwable t) {
|
|
|
|
logToFile(testPath, "Throwable downloading: " + t.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void downloadAttemptSuccessTest() throws Exception {
|
|
|
|
logToFile(testPath, "downloadAttemptSuccessTest");
|
|
|
|
final String orcid = "0000-0001-7291-3210";
|
|
|
|
final HttpClientParams clientParams = new HttpClientParams();
|
|
|
|
clientParams.setMaxNumberOfRetry(2);
|
|
|
|
MultiAttemptsHttpConnector httpConnector = new MultiAttemptsHttpConnector(clientParams);
|
|
|
|
httpConnector.setAuthMethod(MultiAttemptsHttpConnector.BEARER);
|
|
|
|
httpConnector.setAcceptHeaderValue("application/vnd.orcid+xml");
|
|
|
|
httpConnector.setAuthToken("78fdb232-7105-4086-8570-e153f4198e3d");
|
|
|
|
String apiUrl = "https://api.orcid.org/v3.0/" + orcid + "/" + REQUEST_TYPE_RECORD;
|
|
|
|
String url = "UNKNOWN";
|
|
|
|
DownloadsReport report = new DownloadsReport();
|
|
|
|
String record = httpConnector.getInputSource(apiUrl, report);
|
|
|
|
logToFile(testPath, "Downloaded at first attempt record: " + record);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void downloadAttemptNotFoundTest() throws Exception {
|
|
|
|
logToFile(testPath, "downloadAttemptNotFoundTest");
|
|
|
|
final HttpClientParams clientParams = new HttpClientParams();
|
|
|
|
clientParams.setMaxNumberOfRetry(2);
|
|
|
|
MultiAttemptsHttpConnector httpConnector = new MultiAttemptsHttpConnector(clientParams);
|
|
|
|
httpConnector.setAuthMethod(MultiAttemptsHttpConnector.BEARER);
|
|
|
|
httpConnector.setAcceptHeaderValue("application/vnd.orcid+xml");
|
|
|
|
httpConnector.setAuthToken("78fdb232-7105-4086-8570-e153f4198e3d");
|
|
|
|
String apiUrl = "https://api.orcid.org/v3.0/NOTFOUND/" + REQUEST_TYPE_RECORD;
|
|
|
|
DownloadsReport report = new DownloadsReport();
|
|
|
|
try {
|
|
|
|
httpConnector.getInputSource(apiUrl, report);
|
|
|
|
} catch (CollectorException ce) {
|
|
|
|
|
|
|
|
}
|
|
|
|
report.forEach((k, v) -> {
|
|
|
|
try {
|
|
|
|
logToFile(testPath, k + " " + v);
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2023-12-18 15:46:36 +01:00
|
|
|
@Disabled
|
2021-09-20 18:25:00 +02:00
|
|
|
void testDownloadedAuthor() throws Exception {
|
|
|
|
final String base64CompressedWork = "H4sIAAAAAAAAAI2Yy26jMBSG932KiD0hIe1MiwiVZjGLkWbX2XRHsFOsgs3YJmnefszFFy4+mUhtVPz9P/gcH/vQ9PWrrjYXzAVh9Bjst7tgg2nBEKEfx+DP28/wOdgImVOUV4ziY3DDInjNHlKOC8ZRMnxtmlyWxyDaqU+ofg7h/uX7IYwfn+Ngo25ARUKoxJzm1TEopWySKLper1vGC4LU74+IikgTWoFRW+SyfyyfxCBag4iQhBawyoGMDjdqJrnECJAZRquYLDEPaV5jv8oyWlXj+qTiXZLGr7KMiQbnjAOR6IY1W7C6hgIwjGt6SKGfHsY13ajHYipLIcIyJ5Xw6+akdvjEtyt4wxEwM6+VGph5N2zYr2ENhQRhKsmZYChmS1j7nFs6VIBPOwImKhyfMVeFg6GAWEjrcoQ4FoBmBGwVXYhagGHDBIEX+ZzUDiqyn35VN6rJUpUJ4zc/PAI2T03FbrUKJZQszWjV3zavVOjvVfoE01qB+YUUQPGNwHTt3luxJjdqh1AxJFBKLWOrSeCcF13RtxxYtlPOPqH6m+MLwVfoMQ2kdae2ArLajc6fTxkI1nIoegs0yB426pMO+0fSw07xDKMu0XKSde5C2VvrlVMijRzFwqY7XTJI1QMLWcmEzMxtDdxfHiYSgTNJnYJ1K9y5k0tUrMgrnGGaRiuXxxuClulYUbr0nBvpkYLjvgTCGsuSoex3f1CEvRPHKI184NJKtKeaiO7cD5E61bJ4F+9DFd7d01u8Tw6H5BBvvz8f3q3nXLGIeJULGdaqeVBBRK7rS7h/fNvvk/gpedxt4923dxP7Fc3KtKuc1BhlkrfYmeN4dcmrhmbw60+HmWw2CKgbTuqc32CXKTTmeTWT6bDBjPsQ0DTpnchdaYO0ayQ2FyLIiVREqs25aU8VKYLRbK0BsyZuqvr1MU2Sm/rDdhe/2CRN6FU/b+oBVyj1zqRtC5F8kAumfTclsl+s7EoNQu64nfOaVLeezX60Z3XCULLi6GI2IZGTEeey7fec9lBAuXawIHKcpifE7GABHWfoxLVfpUNPBXoMbZWrHFsR3bPAk9J9i2sw9nW6AQT1mpk++7JhW+v44Hmt8PomJqfD13jRnvFOSxCKtu6qHoyBbQ7cMFo750UEfGaXm6bEeplXIXj2hvL6mA7tzvIwmM9pbJFBG834POZdLGi2gH2u9u0K9HMwn5PTioFWLufzmrS4oNuU9Pkt2rf/2jMs7fMdm2rQTTM+j+49AzToAVuXYA1mD2k0+XdE9vAP+JYR5NcQAAA=";
|
|
|
|
final String work = ArgumentApplicationParser.decompressValue(base64CompressedWork);
|
|
|
|
logToFile(testPath, "\n\ndownloaded author \n\n" + work);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2023-12-18 15:46:36 +01:00
|
|
|
@Disabled
|
2021-09-20 18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TIt4rH94j7s4dHbSY/HJ90e3qriBQL+MMxCGETs9j/QxiSQ5PaS63/QsZqdS8vOxdvtj7Oc//fL4dTI2LvDAfVA6erSDKe3+cPxw70j4c5HHZlfLT9iAEZYKjZkxOYKZxymJy659l/t+QZllC5bvVJrzShD5GN0/NkiaZyqNcJh0NrdngtTfp7wviaHB+SS1Ng7O+Sk3h5HodT4S8RyY78pUmGM6eEg1l8tVCa1KnvY/SgrzDKsxRLF46j+uahNKH3BE6lsIb1lUxpUhdS3WUE+u6nPP/qiyAsklumMhMz9SBNqeus0oQ+QXqwIa7m3qy87IhXnBLPI8kVXXlZMaASm5vAEqWuKYkvHMtbPdiPiIdm6dVmeVMZjX+lfnKDWmaRAT7ev6ctTfhEF3RoWnJeXlKfSXcHcsf69rk0wTd4Qx30RV9yl5et2Ipwqe/SS5MJXiU8vbIv2b/qZaC8PZ65AUwj9QJR3vx1mQ9b7VPy1FFebnSpWq7xi0qJuwA+fLYpL7rwJdLXobcSa97kM4Cl35f3YXmofp0+8R9gBc/XeXL9Vn38pH7mLTs27z9T8ky1n7ynlZ0I4le78rYzl6t/woG5krwQlpcRcLDD2UPkH5F73C9G5tFKfY0q/wa1TIHI0CgAAA==";
|
|
|
|
final String work = ArgumentApplicationParser.decompressValue(base64CompressedWork);
|
|
|
|
logToFile(testPath, "\n\ndownloaded work \n\n" + work);
|
|
|
|
}
|
2020-05-15 19:49:26 +02:00
|
|
|
}
|