Revision 59095
Added by Alessia Bardi almost 4 years ago
DOIResolverIteratorTest.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.data.collector.plugins.doiresolver; |
2 | 2 |
|
3 |
import org.apache.commons.logging.Log; |
|
4 |
import org.apache.commons.logging.LogFactory; |
|
3 | 5 |
import org.junit.Assert; |
4 | 6 |
import org.junit.Before; |
5 | 7 |
import org.junit.Test; |
... | ... | |
12 | 14 |
@RunWith(MockitoJUnitRunner.class) |
13 | 15 |
public class DOIResolverIteratorTest { |
14 | 16 |
|
17 |
private static final Log log = LogFactory.getLog(DOIResolverIteratorTest.class); |
|
15 | 18 |
@Mock |
16 | 19 |
CrossrefResolver resolver; |
17 | 20 |
DOIResolverIterator it; |
18 | 21 |
|
22 |
String dirpath; |
|
23 |
|
|
19 | 24 |
@Before |
20 | 25 |
public void setup(){ |
21 | 26 |
when(resolver.resolve("1")).thenReturn("RECORD1"); |
22 | 27 |
when(resolver.resolve("2")).thenReturn(null); |
23 | 28 |
when(resolver.resolve("3")).thenReturn("RECORD3"); |
24 |
String file = getClass().getResource("/eu/dnetlib/data/collector/plugins/doiresolver/doi_list.csv").getFile();
|
|
25 |
it = new DOIResolverIterator(file, resolver); |
|
29 |
dirpath = getClass().getResource("/eu/dnetlib/data/collector/plugins/doiresolver").getPath();
|
|
30 |
|
|
26 | 31 |
} |
27 | 32 |
|
28 | 33 |
@Test |
29 | 34 |
public void test(){ |
35 |
it = new DOIResolverIterator(dirpath, resolver, null); |
|
36 |
int count = 0; |
|
30 | 37 |
while(it.hasNext()){ |
31 |
System.out.println(it.next()); |
|
38 |
String res = it.next(); |
|
39 |
log.info(res); |
|
40 |
if(count == 0) Assert.assertEquals("RECORD1", res); |
|
41 |
if(count == 1) Assert.assertEquals("RECORD3", res); |
|
42 |
count++; |
|
32 | 43 |
} |
44 |
Assert.assertEquals(2, count); |
|
33 | 45 |
} |
34 | 46 |
|
35 | 47 |
@Test |
48 |
public void testIncremental(){ |
|
49 |
it = new DOIResolverIterator(dirpath, resolver, "2020-07-13"); |
|
50 |
int count = 0; |
|
51 |
while(it.hasNext()){ |
|
52 |
String res = it.next(); |
|
53 |
count++; |
|
54 |
} |
|
55 |
Assert.assertEquals(0, count); |
|
56 |
} |
|
57 |
|
|
58 |
@Test |
|
59 |
public void testIncremental2(){ |
|
60 |
it = new DOIResolverIterator(dirpath, resolver, "2020-01-13"); |
|
61 |
int count = 0; |
|
62 |
while(it.hasNext()){ |
|
63 |
String res = it.next(); |
|
64 |
count++; |
|
65 |
} |
|
66 |
Assert.assertEquals(2, count); |
|
67 |
} |
|
68 |
|
|
69 |
@Test |
|
36 | 70 |
public void testCleanOk(){ |
71 |
it = new DOIResolverIterator(dirpath, resolver, null); |
|
37 | 72 |
String doi = "10.1234/1234"; |
38 | 73 |
Assert.assertEquals(doi, it.cleanDOI(doi)); |
39 | 74 |
} |
40 | 75 |
|
41 | 76 |
@Test |
42 | 77 |
public void testCleanHttp(){ |
78 |
it = new DOIResolverIterator(dirpath, resolver, null); |
|
43 | 79 |
String doi = "10.1234/1234"; |
44 | 80 |
String doiURL = "http://dx.doi.org/"+doi; |
45 | 81 |
Assert.assertEquals(doi, it.cleanDOI(doiURL)); |
... | ... | |
47 | 83 |
|
48 | 84 |
@Test |
49 | 85 |
public void testCleanHttps(){ |
86 |
it = new DOIResolverIterator(dirpath, resolver, null); |
|
50 | 87 |
String doi = "10.1234/1234"; |
51 | 88 |
String doiURL = "https://dx.doi.org/"+doi; |
52 | 89 |
Assert.assertEquals(doi, it.cleanDOI(doiURL)); |
Also available in: Unified diff
DOIResolver plugin now supports multiple csv files in the input folder (baseURL) and incremental