-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRDF2GoRDFParserTest.java
More file actions
111 lines (99 loc) · 4.23 KB
/
RDF2GoRDFParserTest.java
File metadata and controls
111 lines (99 loc) · 4.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package com.github.jsonldjava.rdf2go;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.junit.Test;
import org.ontoware.rdf2go.RDF2Go;
import org.ontoware.rdf2go.model.Model;
import org.ontoware.rdf2go.model.Syntax;
import com.github.jsonldjava.core.JsonLdError;
import com.github.jsonldjava.core.JsonLdProcessor;
import com.github.jsonldjava.utils.Obj;
/**
* Unit tests for {@link RDF2GoRDFParser} containing a single test, including
* literals with datatype and language.
*
* @author Ismael Rivera
*/
public class RDF2GoRDFParserTest {
@Test
public void testFromRDF() throws JsonLdError, IOException {
final String turtle = "@prefix const: <http://foo.com/> .\n"
+ "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .\n"
+ "<http://localhost:8080/foo1> const:code \"123\" .\n"
+ "<http://localhost:8080/foo2> const:code \"23.3364\"^^xsd:decimal .\n"
+ "<http://localhost:8080/foo3> const:code \"ABC\"^^xsd:string .\n"
+ "<http://localhost:8080/foo4> const:code \"English\"@en .\n";
final List<Map<String, Object>> expected = new ArrayList<Map<String, Object>>() {
{
add(new LinkedHashMap<String, Object>() {
{
put("@id", "http://localhost:8080/foo1");
put("http://foo.com/code", new ArrayList<Object>() {
{
add(new LinkedHashMap<String, Object>() {
{
put("@value", "123");
}
});
}
});
}
});
add(new LinkedHashMap<String, Object>() {
{
put("@id", "http://localhost:8080/foo2");
put("http://foo.com/code", new ArrayList<Object>() {
{
add(new LinkedHashMap<String, Object>() {
{
put("@value", "23.3364");
put("@type", "http://www.w3.org/2001/XMLSchema#decimal");
}
});
}
});
}
});
add(new LinkedHashMap<String, Object>() {
{
put("@id", "http://localhost:8080/foo3");
put("http://foo.com/code", new ArrayList<Object>() {
{
add(new LinkedHashMap<String, Object>() {
{
put("@value", "ABC");
}
});
}
});
}
});
add(new LinkedHashMap<String, Object>() {
{
put("@id", "http://localhost:8080/foo4");
put("http://foo.com/code", new ArrayList<Object>() {
{
add(new LinkedHashMap<String, Object>() {
{
put("@value", "English");
put("@language", "en");
}
});
}
});
}
});
}
};
final RDF2GoRDFParser parser = new RDF2GoRDFParser();
final Model modelResult = RDF2Go.getModelFactory().createModel().open();
modelResult.readFrom(new ByteArrayInputStream(turtle.getBytes()), Syntax.Turtle);
final Object json = JsonLdProcessor.fromRDF(modelResult, parser);
assertTrue(Obj.equals(json, expected));
}
}