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