Project

General

Profile

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

    
3
import org.apache.commons.logging.Log;
4
import org.apache.commons.logging.LogFactory;
5
import org.junit.Assert;
6
import org.junit.Before;
7
import org.junit.Test;
8
import org.junit.runner.RunWith;
9
import org.mockito.Mock;
10
import org.mockito.junit.MockitoJUnitRunner;
11

    
12
import static org.mockito.Mockito.when;
13

    
14
@RunWith(MockitoJUnitRunner.class)
15
public class DOIResolverIteratorTest {
16

    
17
    private static final Log log = LogFactory.getLog(DOIResolverIteratorTest.class);
18
    @Mock
19
    CrossrefResolver resolver;
20
    DOIResolverIterator it;
21

    
22
    String dirpath;
23

    
24
    @Before
25
    public void setup(){
26
        when(resolver.resolve("1")).thenReturn("RECORD1");
27
        when(resolver.resolve("2")).thenReturn(null);
28
        when(resolver.resolve("3")).thenReturn("RECORD3");
29
        dirpath = getClass().getResource("/eu/dnetlib/data/collector/plugins/doiresolver").getPath();
30

    
31
    }
32

    
33
    @Test
34
    public void test(){
35
        it = new DOIResolverIterator(dirpath, resolver, null);
36
        int count = 0;
37
        while(it.hasNext()){
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++;
43
        }
44
        Assert.assertEquals(2, count);
45
    }
46

    
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
70
    public void testCleanOk(){
71
        it = new DOIResolverIterator(dirpath, resolver, null);
72
        String doi = "10.1234/1234";
73
        Assert.assertEquals(doi, it.cleanDOI(doi));
74
    }
75

    
76
    @Test
77
    public void testCleanHttp(){
78
        it = new DOIResolverIterator(dirpath, resolver, null);
79
        String doi = "10.1234/1234";
80
        String doiURL = "http://dx.doi.org/"+doi;
81
        Assert.assertEquals(doi, it.cleanDOI(doiURL));
82
    }
83

    
84
    @Test
85
    public void testCleanHttps(){
86
        it = new DOIResolverIterator(dirpath, resolver, null);
87
        String doi = "10.1234/1234";
88
        String doiURL = "https://dx.doi.org/"+doi;
89
        Assert.assertEquals(doi, it.cleanDOI(doiURL));
90
    }
91
}
(2-2/2)