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