1
|
/**
|
2
|
*
|
3
|
*/
|
4
|
package eu.dnetlib.data.collector.plugins.rest;
|
5
|
|
6
|
import java.io.FileWriter;
|
7
|
|
8
|
import org.junit.Test;
|
9
|
|
10
|
/**
|
11
|
* @author js
|
12
|
*
|
13
|
*/
|
14
|
public class RestIteratorTest {
|
15
|
|
16
|
private String baseUrl = "https://share.osf.io/api/v2/search/creativeworks/_search";
|
17
|
private String resumptionType = "count";
|
18
|
private String resumptionParam = "from";
|
19
|
private String resumptionXpath = "";
|
20
|
private String resultTotalXpath = "//hits/total";
|
21
|
private String resultFormatParam = "format";
|
22
|
private String resultFormatValue = "json";
|
23
|
private String resultSizeParam = "size";
|
24
|
private int resultSizeValue = 100;
|
25
|
private String query = "q=%28sources%3ASocArXiv+AND+type%3Apreprint%29";
|
26
|
|
27
|
|
28
|
@Test
|
29
|
public void test(){
|
30
|
final RestIterator iterator = new RestIterator(baseUrl, resumptionType, resumptionParam, resumptionXpath, resultTotalXpath, resultFormatParam, resultFormatValue, resultSizeParam, resultSizeValue, query);
|
31
|
int i =20;
|
32
|
while (iterator.hasNext() && i > 0) {
|
33
|
String result = iterator.next();
|
34
|
// try {
|
35
|
// FileWriter writer = new FileWriter("/tmp/" + i + ".xml");
|
36
|
// writer.write(result);
|
37
|
// writer.close();
|
38
|
// }catch(Exception e) {
|
39
|
// e.printStackTrace();
|
40
|
// }
|
41
|
|
42
|
i--;
|
43
|
}
|
44
|
}
|
45
|
}
|
46
|
|