Project

General

Profile

1
/**
2
 * 
3
 */
4
package eu.dnetlib.data.collector.plugins.rest;
5

    
6
import java.util.HashMap;
7

    
8
import org.junit.Assert;
9
import org.junit.Before;
10
import org.junit.Ignore;
11
import org.junit.Test;
12

    
13
import eu.dnetlib.data.collector.rmi.CollectorServiceException;
14
import eu.dnetlib.data.collector.rmi.InterfaceDescriptor;
15
import eu.dnetlib.data.collector.rmi.ProtocolDescriptor;
16

    
17
/**
18
 * @author js
19
 *
20
 */
21
public class RestCollectorPluginTest {
22

    
23
	private String baseUrl = "https://share.osf.io/api/v2/search/creativeworks/_search";
24
	private String resumptionType = "count";
25
	private String resumptionParam = "from";
26
	private String entityXpath = "//hits/hits";
27
	private String resumptionXpath = "//hits";
28
	private String resultTotalXpath = "//hits/total";
29
	private String resultFormatParam = "format";
30
	private String resultFormatValue = "json";
31
	private String resultSizeParam = "size";
32
	// private String query = "q=%28sources%3ASocArXiv+AND+type%3Apreprint%29";
33
	private String query = "q=%28sources%3AengrXiv+AND+type%3Apreprint%29";
34
    // private String query = "=(sources:engrXiv AND type:preprint)";
35
    
36
	private String protocolDescriptor = "rest_json2xml"; 
37
	private InterfaceDescriptor ifDesc = new InterfaceDescriptor();
38
	private RestCollectorPlugin rcp;
39
	
40
	@Before
41
	public void setUp() {
42
		HashMap<String, String> params = new HashMap<>();
43
		params.put("resumptionType", resumptionType);
44
		params.put("resumptionParam", resumptionParam);
45
		params.put("resumptionXpath", resumptionXpath);
46
		params.put("resultTotalXpath", resultTotalXpath);
47
		params.put("resultFormatParam", resultFormatParam);
48
		params.put("resultFormatValue", resultFormatValue);
49
		params.put("resultSizeParam", resultSizeParam);
50
		params.put("queryParams", query);
51
		params.put("entityXpath", entityXpath);
52
		
53
		ifDesc.setBaseUrl(baseUrl);
54
		ifDesc.setParams(params);
55
		
56
		ProtocolDescriptor pd = new ProtocolDescriptor();
57
		pd.setName(protocolDescriptor);
58
		rcp = new RestCollectorPlugin();
59
		rcp.setProtocolDescriptor(pd);
60
	}
61

    
62
	@Ignore
63
	@Test
64
	public void test() throws CollectorServiceException{
65
		
66
		int i = 0;
67
		for (String s : rcp.collect(ifDesc, "", "")) {
68
			Assert.assertTrue(s.length() > 0);
69
			i++;
70
			System.out.println(s);
71
			if (i > 200)
72
				break;
73
		}
74
		System.out.println(i);
75
		Assert.assertTrue(i > 0);
76
	}
77
}
78

    
(1-1/2)