1
|
package eu.dnetlib.data.collector.plugins.csv;
|
2
|
|
3
|
import java.net.URISyntaxException;
|
4
|
import java.util.HashMap;
|
5
|
|
6
|
import eu.dnetlib.data.collector.plugins.HttpCSVCollectorPlugin;
|
7
|
import eu.dnetlib.data.collector.rmi.CollectorServiceException;
|
8
|
import eu.dnetlib.data.collector.rmi.InterfaceDescriptor;
|
9
|
import org.junit.Test;
|
10
|
|
11
|
import static org.junit.Assert.assertFalse;
|
12
|
import static org.junit.Assert.assertTrue;
|
13
|
|
14
|
public class HTTPCSVCollectorPluginTest {
|
15
|
|
16
|
private String FILE_URL = HTTPCSVCollectorPluginTest.class.getResource("testCSVwithBOM.csv").toString();
|
17
|
final HttpCSVCollectorPlugin plugin = new HttpCSVCollectorPlugin();
|
18
|
|
19
|
@Test
|
20
|
public void testCSVHeader() throws URISyntaxException, CollectorServiceException {
|
21
|
|
22
|
final InterfaceDescriptor descr = new InterfaceDescriptor();
|
23
|
final HashMap<String, String> params = new HashMap<String, String>();
|
24
|
|
25
|
params.put("separator", ",");
|
26
|
params.put("quote", "\"");
|
27
|
params.put("identifier", "ID");
|
28
|
descr.setBaseUrl(FILE_URL);
|
29
|
descr.setParams(params);
|
30
|
|
31
|
int i = 0;
|
32
|
for (final String s : plugin.collect(descr, null, null)) {
|
33
|
assertTrue(s.length() > 0);
|
34
|
System.out.println(s);
|
35
|
i++;
|
36
|
}
|
37
|
System.out.println(i);
|
38
|
assertTrue(i > 0);
|
39
|
}
|
40
|
|
41
|
@Test
|
42
|
public void testVerifyQuotesOk(){
|
43
|
String correct = "\"5\",\"Il Padrino\",\"EEEEEEEE \"\"ZZZZZ\"\" EEEEEEEEEE\",1970";
|
44
|
assertTrue(plugin.verifyQuotes(correct, ','));
|
45
|
}
|
46
|
|
47
|
@Test
|
48
|
public void testVerifyQuotesWRONG(){
|
49
|
String correct = "5\",\"Il Padrino\",\"EEEEEEEE \"ZZZZZ\" EEEEEEEEEE\",1970";
|
50
|
assertFalse(plugin.verifyQuotes(correct, ','));
|
51
|
}
|
52
|
|
53
|
@Test
|
54
|
public void testSNSF(){
|
55
|
String s = "\"8773\";\"3101-008773\";\"EMBO workshop on structure, function and regulation of membrane transport proteins\";\"\";\"Rossier Bernard C.\";\"Scientific Conferences\";\"Science communication\";\"Département de Pharmacologie & Toxicologie Faculté de Biologie et de Médecine Université de Lausanne\";\"Université de Lausanne - LA\";\"30103\";\"Cellular Biology, Cytology\";\"Biology and Medicine;Basic Biological Research\";\"01.04.1987\";\"30.09.1987\";\"10000.00\";\"\";\"30103\"" ;
|
56
|
assertTrue(plugin.verifyQuotes(s, ';'));
|
57
|
}
|
58
|
|
59
|
@Test
|
60
|
public void testSNSF2(){
|
61
|
String s = "\"11000\";\"4021-011000\";\"Literarische und nationale Erziehung : Schweizerisches Selbstverständnis in der Literatur für Kinder und Jugend- liche\";\"\";\"Tschirky Rosmarie\";\"NRP 21 Cultural Diversity and National Identity\";\"Programmes;National Research Programmes (NRPs)\";\"Schweiz. Inst. für Kinder- und Jugendmedien\";\"Universität Zürich - ZH\";\"10501\";\"German and English languages and literature\";\"Human and Social Sciences;Linguistics and literature, philosophy\";\"10501\";\"01.10.1986\";\"31.03.1990\";\"308807.00\";\"\"";
|
62
|
assertTrue(plugin.verifyQuotes(s, ';'));
|
63
|
}
|
64
|
|
65
|
@Test
|
66
|
public void testSNSFInvalid(){
|
67
|
String s = "\"35918\";\"1113-035918\";\"Entwicklung eines dreisprachigen Thesaurus des schweizerischen Rechts zur Unterstützung der Suche in Volltextdatenbanken.\";\"\";\"Verein \"Schweizerische Juristische Datenbank\"\";\"Project funding (Div. I-III)\";\"Project funding\";\"Verein \"\"Schweizerische Juristische Datenbank\"\"\";\"NPO (Biblioth., Museen, Verwalt.) - NPO\";\"10205\";\"Legal sciences\";\"Human and Social Sciences;Economics, law\";\"10205\";\"01.12.1992\";\"31.03.1995\";\"500366.00\";\"\"";
|
68
|
assertFalse(plugin.verifyQuotes(s, ';'));
|
69
|
}
|
70
|
|
71
|
}
|