Project

General

Profile

1
package eu.dnetlib.data.collector.plugins.excel;
2

    
3
import java.util.HashMap;
4
import java.util.Iterator;
5

    
6
import eu.dnetlib.data.collector.plugins.HttpCSVCollectorPlugin;
7
import eu.dnetlib.data.collector.rmi.InterfaceDescriptor;
8
import org.junit.Assert;
9
import org.junit.Before;
10
import org.junit.Ignore;
11
import org.junit.Test;
12
/**
13
 * Created by miriam on 10/05/2017.
14
 */
15
@Ignore
16
public class ReadExcelTest {
17
	private InterfaceDescriptor descr;
18
	private Read r;
19

    
20
	//private String excelPath = "eu/dnetlib/data/collector/plugins/excel/fwf_projects_100.xlsx";
21

    
22

    
23
	@Before
24
	public void setUp() throws Exception {
25
		descr = new InterfaceDescriptor();
26
		//descr.setBaseUrl("https://pf.fwf.ac.at/en/research-in-practice/project-finder.xlsx?&&&search%5Bcall%5D=&search%5Bdecision_board_ids%5D=&search%5Bend_date%5D=&search%5Binstitute_name%5D=&search%5Blead_firstname%5D=&search%5Blead_lastname%5D=&search%5Bper_page%5D=10&search%5Bproject_number%5D=&search%5Bproject_title%5D=&search%5Bscience_discipline_id%5D=&search%5Bstart_date%5D=&search%5Bstatus_id%5D=&search%5Bwhat%5D=&action=index&controller=projects&locale=en&per_page=10" );
27
		HashMap<String, String> params = new HashMap<String, String>();
28

    
29
		params.put("argument", "{\"replace\":{\"header\":[{\"from\":\"&\",\"to\":\"and\"}],\"body\":[{\"from\":\"\\n\",\"to\":\" \"}]}, \"replace_currency\":[{\"from\":\"a\", \"to\":\"b\"}],\"col_currency\":3}");
30

    
31

    
32
		params.put("header_row","4");
33
		params.put("tmp_file","//tmp//fwf.xslx");
34
		params.put("remove_empty_lines","yes");
35
		params.put("remove_lines_with_id"," – ");
36
		params.put("col_id","1");
37
		params.put("remove_tmp_file","no");
38
		params.put("sheet_number","0");
39
		params.put("file_to_save","/tmp/project_search.2017.05.10.csv");
40
		params.put("separator", ",");
41
		params.put("quote","\"");
42
		descr.setParams(params);
43

    
44

    
45
		//descr.setBaseUrl(excelPath);
46
//		HashMap<String, String> params = new HashMap<String, String>();
47
//
48
//		params.put("header_row","0");
49
//		params.put("tmp_file","/tmp/RSF.xslx");
50
//		params.put("remove_empty_lines","yes");
51
//		params.put("remove_lines_with_id","-“ ");
52
//		params.put("col_id","0");
53
//		params.put("remove_tmp_file","no");
54
//		params.put("sheet_number","1");
55
//		params.put("file_to_save","/tmp/RSF.csv");
56
//		params.put("separator", ",");
57
//		params.put("quote","\"");
58
//		descr.setParams(params);
59
		r = new Read(descr);
60
		r.setCollector(new HttpCSVCollectorPlugin());
61
	}
62

    
63
//	@Test
64
//	//@Ignore
65
//	public void readExcelFromUrl()throws Exception{
66
//		Iterator<String> it = r.parseFile().iterator();
67
//		int i = 0;
68
//		String st = null;
69
//		try {
70
//			while (it.hasNext()) {
71
//				st = it.next();
72
//				Assert.assertNotNull(st);
73
//				i++;
74
//				//System.out.println(it.next());
75
//			}
76
//		}catch(Exception e){
77
//			System.out.println("linea " + i);
78
//			e.printStackTrace();
79
//			System.out.println(st);
80
//		}
81
//
82
//	}
83

    
84
	@Test
85
	public void readExcelFromFile() throws Exception{
86
		Iterator<String> it = r.parseFile().iterator();
87
		int i =1;
88
		String st = null;
89
		try {
90
			while (it.hasNext()) {
91
				st = it.next();
92
				Assert.assertNotNull(st);
93
				i++;
94
				//System.out.println(it.next());
95
			}
96
		}catch(Exception e){
97
			System.out.println("linea " + i);
98
			e.printStackTrace();
99
			System.out.println(st);
100
		}
101

    
102

    
103
	}
104
}
    (1-1/1)