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, Andreas Czerniak
19
 *
20
 */
21
public class RestCollectorPluginTest {
22

    
23
	//Settings for FCT rest endpoint
24

    
25
	private String baseUrl = "https://etl.ptcris.pt/services/searches/projects";
26
	private String resumptionType = "page";
27
	private String resumptionParam = "page";
28
	private String resumptionXpath = "";
29
	private String resultTotalXpath = "//*[local-name()='paging']/*[local-name()='maxPages']";
30
	private String entityXpath = "//*[local-name()='ListRecords']/*[local-name()='record']";
31
	private String resultFormatParam = "";
32
	private String resultFormatValue = "xml";              //  Change from lowerCase to one UpperCase
33
	private String resultSizeParam = "recordsPerPage";
34
	private String resultSizeValue = "100";
35
	private String authMethod = "basic";
36
	private String authToken = "T1BFTkFJUkVfQURNSU46NC01ITM1NkZNOQ==";
37
	private String resultOffsetParam = "";
38
	private String query = "startDateFrom=1999-01-01&startDateTo=1999-12-31&pagination=true";
39

    
40
	//private String baseUrl = "https://share.osf.io/api/v2/search/creativeworks/_search";
41
	//private String resumptionType = "count";
42
	//private String resumptionParam = "from";
43
	//private String entityXpath = "//hits/hits";
44
	//private String resumptionXpath = "//hits";
45
	//private String resultTotalXpath = "//hits/total";
46
	//private String resultFormatParam = "format";
47
	//private String resultFormatValue = "json";
48
	//private String resultSizeParam = "size";
49
    //    private String resultSizeValue = "10";
50
	//// private String query = "q=%28sources%3ASocArXiv+AND+type%3Apreprint%29";
51
	//private String query = "q=%28sources%3AengrXiv+AND+type%3Apreprint%29";
52
    //// private String query = "=(sources:engrXiv AND type:preprint)";
53
    
54
	private String protocolDescriptor = "rest_json2xml"; 
55
	private InterfaceDescriptor ifDesc = new InterfaceDescriptor();
56
	private RestCollectorPlugin rcp;
57
	
58
	@Before
59
	public void setUp() {
60
		HashMap<String, String> params = new HashMap<>();
61
		params.put("resumptionType", resumptionType);
62
		params.put("resumptionParam", resumptionParam);
63
		params.put("resumptionXpath", resumptionXpath);
64
		params.put("resultTotalXpath", resultTotalXpath);
65
		params.put("resultFormatParam", resultFormatParam);
66
		params.put("resultFormatValue", resultFormatValue);
67
		params.put("resultSizeParam", resultSizeParam);
68
                params.put("resultSizeValue", resultSizeValue);
69
		params.put("queryParams", query);
70
		params.put("entityXpath", entityXpath);
71

    
72
		params.put("authMethod", authMethod);
73
		params.put("authToken", authToken);
74
		
75
		ifDesc.setBaseUrl(baseUrl);
76
		ifDesc.setParams(params);
77
		
78
		ProtocolDescriptor pd = new ProtocolDescriptor();
79
		pd.setName(protocolDescriptor);
80
		rcp = new RestCollectorPlugin();
81
		rcp.setProtocolDescriptor(pd);
82
	}
83

    
84
	@Ignore
85
	@Test
86
	public void test() throws CollectorServiceException{
87
		
88
		int i = 0;
89
		for (String s : rcp.collect(ifDesc, "", "")) {
90
			Assert.assertTrue(s.length() > 0);
91
			i++;
92
			System.out.println(s);
93
//			if (i > 200)
94
//				break;
95
		}
96
		System.out.println(i);
97
		Assert.assertTrue(i > 0);
98
	}
99

    
100

    
101

    
102
}
103

    
(1-1/2)