1
|
package eu.dnetlib.data.collector.plugins.projects.gtr2;
|
2
|
|
3
|
import java.util.Iterator;
|
4
|
|
5
|
import com.ximpleware.VTDGen;
|
6
|
import eu.dnetlib.data.collector.plugins.HttpConnector;
|
7
|
import eu.dnetlib.miscutils.functional.xml.TryIndentXmlString;
|
8
|
import org.junit.Before;
|
9
|
import org.junit.Ignore;
|
10
|
import org.junit.Test;
|
11
|
|
12
|
import static org.junit.Assert.assertEquals;
|
13
|
import static org.junit.Assert.assertNotNull;
|
14
|
|
15
|
@Ignore
|
16
|
public class Gtr2Test {
|
17
|
|
18
|
private String baseURL = "http://gtr.rcuk.ac.uk/gtr/api";
|
19
|
private Gtr2Helper helper;
|
20
|
private Gtr2ProjectsIterable it;
|
21
|
private HttpConnector connector;
|
22
|
|
23
|
@Before
|
24
|
public void prepare() {
|
25
|
helper = new Gtr2Helper();
|
26
|
//System.setProperty("jsse.enableSNIExtension","false");
|
27
|
}
|
28
|
|
29
|
@Test
|
30
|
public void testOne() throws Exception {
|
31
|
System.out.println("one project");
|
32
|
VTDGen vg_tmp = new VTDGen();
|
33
|
connector = new HttpConnector();
|
34
|
byte[] bytes = connector.getInputSource("http://gtr.rcuk.ac.uk/gtr/api/projects/E178742B-571B-498F-8402-122F17C47546").getBytes("UTF-8");
|
35
|
//vg_tmp.parseHttpUrl("https://gtr.rcuk.ac.uk/gtr/api/projects/E178742B-571B-498F-8402-122F17C47546", false);
|
36
|
vg_tmp.setDoc(bytes);
|
37
|
vg_tmp.parse(false);
|
38
|
String s = helper.processProject(vg_tmp.getNav(), "xmlns:ns=\"http:///afgshs\"");
|
39
|
System.out.println(s);
|
40
|
}
|
41
|
|
42
|
@Test
|
43
|
public void testPaging() throws Exception {
|
44
|
it = new Gtr2ProjectsIterable(baseURL, null, 2, 3);
|
45
|
TryIndentXmlString indenter = new TryIndentXmlString();
|
46
|
Iterator<String> iterator = it.iterator();
|
47
|
while (iterator.hasNext()) {
|
48
|
Thread.sleep(300);
|
49
|
String res = iterator.next();
|
50
|
assertNotNull(res);
|
51
|
indenter.evaluate(res);
|
52
|
}
|
53
|
}
|
54
|
|
55
|
@Test
|
56
|
public void testOnePage() throws Exception {
|
57
|
it = new Gtr2ProjectsIterable(baseURL, null, 12, 12);
|
58
|
int count = iterateAndCount(it.iterator());
|
59
|
assertEquals(20, count);
|
60
|
}
|
61
|
|
62
|
@Test
|
63
|
public void testIncrementalHarvestingNoRecords() throws Exception {
|
64
|
System.out.println("incremental Harvesting");
|
65
|
it = new Gtr2ProjectsIterable(baseURL, "2050-12-12", 11, 13);
|
66
|
int count = iterateAndCount(it.iterator());
|
67
|
assertEquals(0, count);
|
68
|
}
|
69
|
|
70
|
@Test
|
71
|
public void testIncrementalHarvesting() throws Exception {
|
72
|
System.out.println("incremental Harvesting");
|
73
|
it = new Gtr2ProjectsIterable(baseURL, "2016-11-30", 11, 11);
|
74
|
int count = iterateAndCount(it.iterator());
|
75
|
assertEquals(20, count);
|
76
|
}
|
77
|
|
78
|
@Test
|
79
|
public void testMultithreading() throws Exception {
|
80
|
System.out.println("testing new multithreading configuration");
|
81
|
it = new Gtr2ProjectsIterable(baseURL, null);
|
82
|
TryIndentXmlString indenter = new TryIndentXmlString();
|
83
|
it.setEndAtPage(3);
|
84
|
Iterator<String> iterator = it.iterator();
|
85
|
while (iterator.hasNext()) {
|
86
|
String res = iterator.next();
|
87
|
assertNotNull(res);
|
88
|
// System.out.println(res);
|
89
|
// Scanner keyboard = new Scanner(System.in);
|
90
|
// System.out.println("press enter for next record");
|
91
|
// keyboard.nextLine();
|
92
|
|
93
|
}
|
94
|
}
|
95
|
|
96
|
private int iterateAndCount(final Iterator<String> iterator) throws Exception{
|
97
|
int i = 0;
|
98
|
while (iterator.hasNext()) {
|
99
|
assertNotNull(iterator.next());
|
100
|
i++;
|
101
|
}
|
102
|
System.out.println("Got "+i+" projects");
|
103
|
return i;
|
104
|
}
|
105
|
}
|