1
|
/**
|
2
|
*
|
3
|
*/
|
4
|
package eu.dnetlib.data.collector.plugins.rest;
|
5
|
|
6
|
import com.google.common.collect.Maps;
|
7
|
import org.junit.Before;
|
8
|
import org.junit.Ignore;
|
9
|
import org.junit.Test;
|
10
|
|
11
|
import java.util.Map;
|
12
|
|
13
|
/**
|
14
|
*
|
15
|
* @author js, Andreas Czerniak
|
16
|
* @date 2020-04-08
|
17
|
*/
|
18
|
public class RestIteratorTest {
|
19
|
|
20
|
private Map<String, String> requestHeader = Maps.newHashMap();
|
21
|
|
22
|
// private String baseUrl = "https://share.osf.io/api/v2/search/creativeworks/_search";
|
23
|
// private String resumptionType = "count";
|
24
|
// private String resumptionParam = "from";
|
25
|
// private String resumptionXpath = "";
|
26
|
// private String resultTotalXpath = "//hits/total";
|
27
|
// private String entityXpath = "//hits/hits";
|
28
|
// private String resultFormatParam = "format";
|
29
|
// private String resultFormatValue = "Json"; // Change from lowerCase to one UpperCase
|
30
|
// private String resultSizeParam = "size";
|
31
|
// private String resultSizeValue = "10";
|
32
|
// private String authMethod = "";
|
33
|
// private String authToken = "";
|
34
|
// private String resultOffsetParam = "cursor";
|
35
|
// private String query = "q=%28sources%3ASocArXiv+AND+type%3Apreprint%29";
|
36
|
|
37
|
// private String baseUrl = "https://etl.ptcris.pt/services/searches/projects";
|
38
|
// private String resumptionType = "page";
|
39
|
// private String resumptionParam = "page";
|
40
|
// private String resumptionXpath = "";
|
41
|
// private String resultTotalXpath = "//*[local-name()='paging']/*[local-name()='maxPages']";
|
42
|
// private String entityXpath = "//*[local-name()='ListRecords']/*[local-name()='record']";
|
43
|
// private String resultFormatParam = "";
|
44
|
// private String resultFormatValue = "xml"; // Change from lowerCase to one UpperCase
|
45
|
// private String resultSizeParam = "recordsPerPage";
|
46
|
// private String resultSizeValue = "100";
|
47
|
// private String authMethod = "basic";
|
48
|
// private String authToken = "T1BFTkFJUkVfQURNSU46NC01ITM1NkZNOQ==";
|
49
|
// private String resultOffsetParam = "";
|
50
|
// private String query = "startDateFrom=2019-01-01&startDateTo=2019-12-31&pagination=true";
|
51
|
|
52
|
//config for Enermaps
|
53
|
// private String baseUrl = "https://lab.idiap.ch/enermaps/api/datacite";
|
54
|
// private String authMethod = "";
|
55
|
// private String authToken = "";
|
56
|
// private String entityXpath = "//data";
|
57
|
// private String query = " ";
|
58
|
//
|
59
|
//
|
60
|
// private String resultFormatParam = "";
|
61
|
// private String resultFormatValue = "json";
|
62
|
// private String resultOutputFormat = "json";
|
63
|
// private String resultSizeParam = "";
|
64
|
// private String resultSizeValue = "50";
|
65
|
// private String resultTotalXpath = "fake";
|
66
|
// private String resumptionParam = "fake";
|
67
|
// private String resumptionType = "discover";
|
68
|
// private String resumptionXpath = "/fake";
|
69
|
// private String idxpath = "//data/id";
|
70
|
|
71
|
//config for d4science
|
72
|
private String baseUrl = "https://api.d4science.org/catalogue/items";
|
73
|
private String resumptionType = "discover";
|
74
|
private String resumptionParam = "offset";
|
75
|
private String resumptionXpath = "";
|
76
|
private String resultTotalXpath = "//unused";
|
77
|
private String entityXpath = "//*[local-name()='data']";
|
78
|
private String resultFormatParam = "";
|
79
|
private String resultFormatValue = ""; // Change from lowerCase to one UpperCase
|
80
|
private String resultOutputFormat = "json";
|
81
|
private String resultSizeParam = "limit";
|
82
|
private String resultSizeValue = "10";
|
83
|
private String authMethod = "bearer";
|
84
|
private String authToken = "keep-me-secret" ;
|
85
|
private String query = "all_fields=true";
|
86
|
|
87
|
|
88
|
|
89
|
@Before
|
90
|
public void setup(){
|
91
|
requestHeader.put("Accept", "application/vnd.api+json");
|
92
|
}
|
93
|
|
94
|
@Ignore
|
95
|
@Test
|
96
|
public void test(){
|
97
|
final RestIterator iterator = new RestIterator(baseUrl, resumptionType, resumptionParam, resumptionXpath, resultTotalXpath, resultFormatParam, resultFormatValue, resultSizeParam,
|
98
|
resultSizeValue, query, entityXpath, authMethod, authToken, resultOutputFormat, requestHeader);
|
99
|
int i =50;
|
100
|
while (iterator.hasNext() && i > 0) {
|
101
|
String result = iterator.next();
|
102
|
System.out.println(result);
|
103
|
i--;
|
104
|
}
|
105
|
}
|
106
|
|
107
|
|
108
|
}
|
109
|
|