1
|
package eu.dnetlib.data.mapreduce.actions;
|
2
|
|
3
|
import com.google.gson.JsonObject;
|
4
|
import com.google.gson.JsonParser;
|
5
|
import eu.dnetlib.actionmanager.actions.ActionFactory;
|
6
|
import eu.dnetlib.actionmanager.actions.AtomicAction;
|
7
|
import eu.dnetlib.actionmanager.common.Agent;
|
8
|
import eu.dnetlib.data.mapreduce.hbase.dataimport.CrossRefToActions;
|
9
|
import org.apache.commons.lang3.StringUtils;
|
10
|
import org.junit.Before;
|
11
|
import org.junit.Test;
|
12
|
|
13
|
import java.io.BufferedReader;
|
14
|
import java.io.IOException;
|
15
|
import java.io.InputStream;
|
16
|
import java.io.InputStreamReader;
|
17
|
|
18
|
public class CrossRefToActionTest {
|
19
|
|
20
|
private String setName;
|
21
|
private Agent agent;
|
22
|
|
23
|
@Before
|
24
|
public void setup() {
|
25
|
setName = "DLI";
|
26
|
agent= new Agent("agentId","agentName", Agent.AGENT_TYPE.service);
|
27
|
}
|
28
|
|
29
|
|
30
|
@Test
|
31
|
public void testSingleScholixAction2() throws IOException {
|
32
|
doTestSingleCrossRefAction("/eu/dnetlib/data/mapreduce/actions/broken");
|
33
|
}
|
34
|
|
35
|
@Test
|
36
|
public void testAllScholixAction() throws IOException {
|
37
|
doTestAllCrossRefAction("/eu/dnetlib/data/mapreduce/actions/part-06036");
|
38
|
}
|
39
|
|
40
|
|
41
|
private void doTestSingleCrossRefAction(final String filePath) throws IOException {
|
42
|
final InputStream is = this.getClass().getResourceAsStream(filePath);
|
43
|
final BufferedReader in = new BufferedReader(new InputStreamReader(is));
|
44
|
|
45
|
String line = in.readLine();
|
46
|
System.out.println(line);
|
47
|
final JsonParser parser = new JsonParser();
|
48
|
JsonObject root = parser.parse(line).getAsJsonObject();
|
49
|
AtomicAction actions = CrossRefToActions.generateActionsFromDump(root, new ActionFactory(), setName, agent, false);
|
50
|
System.out.println(actions.toJSON());
|
51
|
}
|
52
|
|
53
|
|
54
|
|
55
|
|
56
|
private void doTestAllCrossRefAction(final String filePath) throws IOException {
|
57
|
final InputStream is = this.getClass().getResourceAsStream(filePath);
|
58
|
final BufferedReader in = new BufferedReader(new InputStreamReader(is));
|
59
|
|
60
|
String line = in.readLine();
|
61
|
while(StringUtils.isNotBlank(line)) {
|
62
|
|
63
|
final JsonParser parser = new JsonParser();
|
64
|
JsonObject root = parser.parse(line).getAsJsonObject();
|
65
|
try {
|
66
|
CrossRefToActions.generateActionsFromDump(root, new ActionFactory(), setName, agent, false);
|
67
|
} catch (Throwable e) {
|
68
|
System.out.println(line);
|
69
|
throw new RuntimeException(e);
|
70
|
}
|
71
|
line= in.readLine();
|
72
|
}
|
73
|
}
|
74
|
|
75
|
|
76
|
|
77
|
}
|