Revision 56011
Added by Alessia Bardi almost 5 years ago
OrcidToActionsTest.java | ||
---|---|---|
6 | 6 |
import java.io.InputStreamReader; |
7 | 7 |
import java.util.List; |
8 | 8 |
|
9 |
import org.apache.commons.lang3.StringUtils; |
|
10 |
import org.junit.Before; |
|
11 |
import org.junit.Test; |
|
12 |
|
|
13 | 9 |
import com.google.gson.JsonObject; |
14 | 10 |
import com.google.gson.JsonParser; |
15 |
|
|
11 |
import com.googlecode.protobuf.format.JsonFormat; |
|
12 |
import com.googlecode.protobuf.format.JsonFormat.ParseException; |
|
16 | 13 |
import eu.dnetlib.actionmanager.actions.ActionFactory; |
17 | 14 |
import eu.dnetlib.actionmanager.actions.AtomicAction; |
18 | 15 |
import eu.dnetlib.actionmanager.common.Agent; |
19 | 16 |
import eu.dnetlib.data.mapreduce.hbase.Reporter; |
20 | 17 |
import eu.dnetlib.data.mapreduce.hbase.dataimport.OrcidToActions; |
18 |
import eu.dnetlib.data.proto.OafProtos.Oaf; |
|
19 |
import org.apache.commons.lang3.StringUtils; |
|
20 |
import org.junit.Before; |
|
21 |
import org.junit.Test; |
|
21 | 22 |
|
22 | 23 |
public class OrcidToActionsTest { |
23 | 24 |
|
... | ... | |
25 | 26 |
private Agent agent; |
26 | 27 |
private Reporter reporter; |
27 | 28 |
|
29 |
private String generatedJson = "{\"kind\": \"entity\",\"entity\": {\"type\": \"result\",\"result\": {\"metadata\": {\"title\": [{\"value\": \"Compulsory Licences and Trade Marks\",\"qualifier\": {\"classid\": \"main title\",\"classname\": \"main title\",\"schemeid\": \"dnet:dataCite_title\",\"schemename\": \"dnet:dataCite_title\"}}],\"relevantdate\": [{\"value\": \"2012-01-01\",\"qualifier\": {\"classid\": \"issued\",\"classname\": \"issued\",\"schemeid\": \"dnet:dataCite_date\",\"schemename\": \"dnet:dataCite_date\"}}],\"resulttype\": {\"classid\": \"publication\",\"classname\": \"publication\",\"schemeid\": \"dnet:result_typologies\",\"schemename\": \"dnet:result_typologies\"},\"resourcetype\": {\"classid\": \"journal-article\",\"classname\": \"journal-article\",\"schemeid\": \"dnet:dataCite_resource\",\"schemename\": \"dnet:dataCite_resource\"},\"source\": [{\"value\": \"University of Copenhagen\"}],\"author\": [{\"fullname\": \"Thomas Riis\",\"rank\": 1},{\"fullname\": \"Jens Hemmingsen Schovsbo\",\"name\": \"Jens Hemmingsen\",\"surname\": \"Schovsbo\",\"rank\": 2,\"pid\": [{\"key\": \"ORCID\",\"value\": \"0000-0003-4872-879X\"}]}]},\"instance\": [{\"accessright\": {\"classid\": \"UNKNOWN\",\"classname\": \"UNKNOWN\",\"schemeid\": \"dnet:access_modes\",\"schemename\": \"dnet:access_modes\"},\"instancetype\": {\"classid\": \"0001\",\"classname\": \"Article\",\"schemeid\": \"dnet:publication_resource\",\"schemename\": \"dnet:publication_resource\"},\"hostedby\": {\"key\": \"10|openaire____::55045bd2a65019fd8e6741a755395c8c\",\"value\": \"Unknown Repository\"},\"url\": [\"https://curis.ku.dk/portal/en/publications/compulsory-licences-and-trade-marks(93dc5709-2675-4463-bb27-eb54844c2381).html\"],\"collectedfrom\": {\"key\": \"10|openaire____::806360c771262b4d6770e7cdf04b5c5a\",\"value\": \"ORCID\"},\"dateofacceptance\": {\"value\": \"2012-01-01\"}}]},\"pid\": [{\"value\": \"93dc5709-2675-4463-bb27-eb54844c2381\",\"qualifier\": {\"classid\": \"orcidworkid\",\"classname\": \"orcidworkid\",\"schemeid\": \"dnet:pid_types\",\"schemename\": \"dnet:pid_types\"}}],\"dateofcollection\": \"2018-10-22\",\"id\": \"50|orcid____::1523b5ccb7304c768c5c540b747983a3\"}}"; |
|
28 | 30 |
@Before |
29 | 31 |
public void setup() { |
30 | 32 |
setName = "ORCID"; |
... | ... | |
70 | 72 |
doTestAllOrcidAction("/eu/dnetlib/data/mapreduce/actions/part-100"); |
71 | 73 |
} |
72 | 74 |
|
75 |
@Test |
|
76 |
public void testJsonToProto() throws ParseException { |
|
77 |
Oaf.Builder builder = Oaf.newBuilder(); |
|
78 |
JsonFormat.merge(generatedJson, builder); |
|
79 |
System.out.println(builder.build()); |
|
80 |
} |
|
81 |
|
|
73 | 82 |
private void doTestSingleAction(final String filePath) throws IOException { |
74 | 83 |
final InputStream is = this.getClass().getResourceAsStream(filePath); |
75 | 84 |
final BufferedReader in = new BufferedReader(new InputStreamReader(is)); |
... | ... | |
79 | 88 |
final JsonParser parser = new JsonParser(); |
80 | 89 |
final JsonObject root = parser.parse(line).getAsJsonObject(); |
81 | 90 |
final List<AtomicAction> lista = OrcidToActions.generatePublicationActionsFromDump(root, new ActionFactory(), setName, agent, reporter); |
82 |
// System.out.println(new Gson().toJson(lista));
|
|
91 |
//System.out.println(new Gson().toJson(lista)); |
|
83 | 92 |
} |
84 | 93 |
|
85 | 94 |
private void doTestAllOrcidAction(final String filePath) throws IOException { |
Also available in: Unified diff
print json but commented out.
Added test to get a proto from a json