1
|
package eu.dnetlib.data.mapreduce.actions;
|
2
|
|
3
|
import java.io.BufferedReader;
|
4
|
import java.io.IOException;
|
5
|
import java.io.InputStream;
|
6
|
import java.io.InputStreamReader;
|
7
|
import java.util.List;
|
8
|
|
9
|
import org.apache.commons.lang3.StringUtils;
|
10
|
import org.junit.Before;
|
11
|
import org.junit.Test;
|
12
|
|
13
|
import com.google.gson.Gson;
|
14
|
import com.google.gson.JsonObject;
|
15
|
import com.google.gson.JsonParser;
|
16
|
|
17
|
import eu.dnetlib.actionmanager.actions.ActionFactory;
|
18
|
import eu.dnetlib.actionmanager.actions.AtomicAction;
|
19
|
import eu.dnetlib.actionmanager.common.Agent;
|
20
|
import eu.dnetlib.data.mapreduce.hbase.Reporter;
|
21
|
import eu.dnetlib.data.mapreduce.hbase.dataimport.OrcidToActions;
|
22
|
|
23
|
public class OrcidToActionsTest {
|
24
|
|
25
|
private String setName;
|
26
|
private Agent agent;
|
27
|
private Reporter reporter;
|
28
|
|
29
|
@Before
|
30
|
public void setup() {
|
31
|
setName = "ORCID";
|
32
|
agent = new Agent("agentId", "agentName", Agent.AGENT_TYPE.service);
|
33
|
reporter =
|
34
|
(Reporter) (counterGroup, counterName, delta) -> System.out.println(String.format("COUNTER: %s - %s : %d", counterGroup, counterName, delta));
|
35
|
}
|
36
|
|
37
|
@Test
|
38
|
public void testUnicodeAction() throws IOException {
|
39
|
doTestSingleAction("/eu/dnetlib/data/mapreduce/actions/OrcidAction_1.json");
|
40
|
|
41
|
}
|
42
|
|
43
|
@Test
|
44
|
public void testSourceWorkIdAction() throws IOException {
|
45
|
doTestSingleAction("/eu/dnetlib/data/mapreduce/actions/OrcidAction_2.json");
|
46
|
|
47
|
}
|
48
|
|
49
|
@Test
|
50
|
public void testAuthorsRank() throws IOException {
|
51
|
doTestSingleAction("/eu/dnetlib/data/mapreduce/actions/OrcidAction_3.json");
|
52
|
doTestSingleAction("/eu/dnetlib/data/mapreduce/actions/OrcidAction_4.json");
|
53
|
doTestSingleAction("/eu/dnetlib/data/mapreduce/actions/OrcidAction_5.json");
|
54
|
|
55
|
}
|
56
|
|
57
|
@Test
|
58
|
public void testUrl() throws IOException {
|
59
|
doTestSingleAction("/eu/dnetlib/data/mapreduce/actions/OrcidAction_6.json");
|
60
|
|
61
|
}
|
62
|
|
63
|
@Test
|
64
|
public void testNullUrlAction() throws IOException {
|
65
|
doTestSingleAction("/eu/dnetlib/data/mapreduce/actions/OrcidAction_7.json");
|
66
|
|
67
|
}
|
68
|
|
69
|
@Test
|
70
|
public void testMassiveOrcidAction() throws IOException {
|
71
|
doTestAllOrcidAction("/eu/dnetlib/data/mapreduce/actions/part-100");
|
72
|
}
|
73
|
|
74
|
private void doTestSingleAction(final String filePath) throws IOException {
|
75
|
final InputStream is = this.getClass().getResourceAsStream(filePath);
|
76
|
final BufferedReader in = new BufferedReader(new InputStreamReader(is));
|
77
|
|
78
|
final String line = in.readLine();
|
79
|
|
80
|
final JsonParser parser = new JsonParser();
|
81
|
final JsonObject root = parser.parse(line).getAsJsonObject();
|
82
|
final List<AtomicAction> lista = OrcidToActions.generatePublicationActionsFromDump(root, new ActionFactory(), setName, agent, reporter);
|
83
|
System.out.println(new Gson().toJson(lista));
|
84
|
}
|
85
|
|
86
|
private void doTestAllOrcidAction(final String filePath) throws IOException {
|
87
|
final InputStream is = this.getClass().getResourceAsStream(filePath);
|
88
|
final BufferedReader in = new BufferedReader(new InputStreamReader(is));
|
89
|
String line = in.readLine();
|
90
|
int i = 0;
|
91
|
while (StringUtils.isNotBlank(line)) {
|
92
|
final JsonParser parser = new JsonParser();
|
93
|
final JsonObject root = parser.parse(line).getAsJsonObject();
|
94
|
try {
|
95
|
OrcidToActions.generatePublicationActionsFromDump(root, new ActionFactory(), setName, agent, reporter);
|
96
|
} catch (final Throwable e) {
|
97
|
System.out.println("Exception parsing: " + line);
|
98
|
throw new RuntimeException(e);
|
99
|
}
|
100
|
line = in.readLine();
|
101
|
i += 1;
|
102
|
}
|
103
|
System.out.println("parsed: " + i);
|
104
|
}
|
105
|
}
|