Project

General

Profile

1
package eu.dnetlib.data.mapreduce.hbase.dataexport;
2

    
3
import com.fasterxml.jackson.databind.ObjectMapper;
4
import com.googlecode.protobuf.format.JsonFormat;
5
import eu.dnetlib.data.proto.OafProtos;
6
import eu.dnetlib.dhp.schema.oaf.*;
7
import org.apache.commons.io.IOUtils;
8
import org.junit.Test;
9

    
10
import java.io.IOException;
11

    
12
import static org.junit.Assert.assertNotNull;
13
import static org.junit.Assert.assertTrue;
14

    
15
public class ProtoConverterTest {
16

    
17

    
18
    @Test
19
    public void convertDatasourceTest() throws Exception {
20
        Oaf result = getOaf("/eu/dnetlib/data/mapreduce/hbase/dataexport/datasource.json");
21
        assertNotNull(result);
22
        assertTrue(result instanceof Datasource);
23
        Datasource ds = (Datasource) result;
24
        assertNotNull(ds.getId());
25

    
26
        System.out.println(ds.getId());
27

    
28

    
29
        ObjectMapper mapper = new ObjectMapper();
30
        System.out.println(mapper.writeValueAsString(result));
31
    }
32

    
33

    
34
    @Test
35
    public void convertOrganizationTest() throws Exception {
36

    
37
        Oaf result = getOaf("/eu/dnetlib/data/mapreduce/hbase/dataexport/organization.json");
38
        assertNotNull(result);
39
        assertTrue(result instanceof Organization);
40
        Organization ds = (Organization) result;
41
        assertNotNull(ds.getId());
42

    
43
        System.out.println(ds.getId());
44

    
45

    
46
        ObjectMapper mapper = new ObjectMapper();
47
        System.out.println(mapper.writeValueAsString(result));
48

    
49
    }
50

    
51
    @Test
52
    public void convertPublicationTest() throws Exception {
53
        Oaf result = getOaf("/eu/dnetlib/data/mapreduce/hbase/dataexport/publication.json");
54

    
55
        assertNotNull(result);
56
        assertTrue(result instanceof Publication);
57
        Publication p = (Publication) result;
58

    
59
        ObjectMapper mapper = new ObjectMapper();
60
        System.out.println(mapper.writeValueAsString(p));
61

    
62
    }
63

    
64
    @Test
65
    public void convertDatasetTest() throws Exception {
66
        Oaf result = getOaf("/eu/dnetlib/data/mapreduce/hbase/dataexport/dataset.json");
67

    
68
        assertNotNull(result);
69
        assertTrue(result instanceof Dataset);
70
        Dataset d = (Dataset) result;
71

    
72
        ObjectMapper mapper = new ObjectMapper();
73
        System.out.println(mapper.writeValueAsString(d));
74

    
75
    }
76

    
77
    @Test
78
    public void convertORPTest() throws Exception {
79
        Oaf result = getOaf("/eu/dnetlib/data/mapreduce/hbase/dataexport/orp.json");
80

    
81
        assertNotNull(result);
82
        assertTrue(result instanceof OtherResearchProduct);
83
        OtherResearchProduct orp = (OtherResearchProduct) result;
84

    
85
        ObjectMapper mapper = new ObjectMapper();
86
        System.out.println(mapper.writeValueAsString(orp));
87

    
88
    }
89

    
90
    @Test
91
    public void convertSoftware() throws Exception {
92
        Oaf result = getOaf("/eu/dnetlib/data/mapreduce/hbase/dataexport/software.json");
93

    
94
        assertNotNull(result);
95
        assertTrue(result instanceof Software);
96
        Software s = (Software) result;
97

    
98
        ObjectMapper mapper = new ObjectMapper();
99
        System.out.println(mapper.writeValueAsString(s));
100

    
101
    }
102

    
103
    private Oaf getOaf(String s2) throws IOException {
104
        final String json = IOUtils.toString(this.getClass().getResourceAsStream(s2));
105

    
106
        final OafProtos.Oaf.Builder b = OafProtos.Oaf.newBuilder();
107
        JsonFormat.merge(json, b);
108

    
109
        return ProtoConverter.convert(b.build());
110
    }
111

    
112
}
(1-1/2)