Project

General

Profile

1
package eu.dnetlib.data.collector.plugins.HTTPWithFileName;
2
import java.util.Iterator;
3

    
4
import org.json.JSONObject;
5
import org.json.XML;
6
import org.junit.Ignore;
7
import org.junit.Test;
8

    
9

    
10
/**
11
 * Created by miriam on 07/05/2018.
12
 */
13
public class HTTPWithFileNameTest {
14

    
15
    private void iterate(Iterator<String> iterator, boolean exit){
16
        try{
17
            while (iterator.hasNext()){
18

    
19
                System.out.println(iterator.next());
20
                if(exit)
21
                    System.exit(0);
22

    
23

    
24
            }
25

    
26
        }catch(Exception ex){
27
            ex.printStackTrace();
28
        }
29
    }
30

    
31
    @Test
32
    @Ignore
33
    public void testRSCollectorFrontiers()
34
    {
35
        HTTPWithFileNameCollectorIterable rsc = new HTTPWithFileNameCollectorIterable("https://dev-openaire.d4science.org/RS/Frontiers/data/Frontiers/metadata/000/",null);
36
        iterate(rsc.iterator(),false);
37

    
38
    }
39

    
40
    @Test
41
    @Ignore
42
    public void testRSCollectorPLOSCount()
43
    {
44
        HTTPWithFileNameCollectorIterable rsc = new HTTPWithFileNameCollectorIterable("https://dev-openaire.d4science.org/RS/PLOS/data/public_library_of_science/metadata/354/","article-type=\"correction\"");
45
        Iterator<String> iterator = rsc.iterator();
46
        int count = 0;
47
        int body = 0;
48
        int corrections = 0;
49
        try{
50
            while (iterator.hasNext()){
51

    
52
                String meta = iterator.next();
53
                if (!meta.contains("article-type=\"correction\"")){
54
                    count++;
55
                    int index = meta.indexOf("<body>");
56
                    if(meta.substring(index).contains("<sec"))
57
                        body++;
58
                    else {
59
                        System.out.println(meta);
60
                        System.out.println(count);
61
                    }
62

    
63
                }else
64
                    corrections++;
65

    
66
            }
67
            System.out.println(count + "       "  + body + "                  " + corrections);
68
        }catch(Exception ex){
69
            ex.printStackTrace();
70
        }
71
    }
72

    
73
    @Test
74
    @Ignore
75
    public void testRSCollectorPLOS()
76
    {
77
        HTTPWithFileNameCollectorIterable rsc = new HTTPWithFileNameCollectorIterable("https://dev-openaire.d4science.org/RS/PLOS/data/public_library_of_science/metadata/400/","article-type=\"correction\"");
78

    
79

    
80
        iterate(rsc.iterator(),false);
81
    }
82

    
83
    @Test
84
    @Ignore
85
    public void testRSCollectorSpringer()
86
    {
87
        HTTPWithFileNameCollectorIterable rsc = new HTTPWithFileNameCollectorIterable("https://dev-openaire.d4science.org/RS/Springer-OA/data/Springer-OA/metadata/8a0/",null);
88

    
89
        iterate(rsc.iterator(),false);
90

    
91
    }
92

    
93
    @Test
94
    public void testEmptyCollection()
95
    {
96
        HTTPWithFileNameCollectorIterable rsc = new HTTPWithFileNameCollectorIterable("",null);
97

    
98
        iterate(rsc.iterator(),true);
99
    }
100

    
101

    
102

    
103
    @Test
104
    public void testJsonToXml() {
105
        System.out.println(XML.toString(new JSONObject("{'resource':{'DOI':'JUNK','url':'asd'}}")));
106

    
107
    }
108

    
109
}
    (1-1/1)