Skip to content

Commit 31e33dc

Browse files
committed
Add regression test for issue #153
1 parent 850166a commit 31e33dc

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.github.jsonldjava.core;
2+
3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertFalse;
5+
import static org.junit.Assert.assertNotNull;
6+
7+
import java.net.URL;
8+
import java.util.Map;
9+
10+
import org.junit.Test;
11+
12+
import com.github.jsonldjava.utils.JsonUtils;
13+
14+
public class LongestPrefixTest {
15+
@Test
16+
public void toRdfWithNamespace() throws Exception {
17+
18+
final URL contextUrl = getClass().getResource("/custom/contexttest-0003.jsonld");
19+
assertNotNull(contextUrl);
20+
final Object context = JsonUtils.fromURL(contextUrl);
21+
assertNotNull(context);
22+
23+
final JsonLdOptions options = new JsonLdOptions();
24+
options.useNamespaces = true;
25+
final RDFDataset rdf = (RDFDataset) JsonLdProcessor.toRDF(context, options);
26+
System.out.println(rdf.getNamespaces());
27+
assertEquals("http://vocab.getty.edu/aat/", rdf.getNamespace("aat"));
28+
assertEquals("http://vocab.getty.edu/aat/rev/", rdf.getNamespace("aat_rev"));
29+
}
30+
31+
@Test
32+
public void fromRdfWithNamespace() throws Exception {
33+
34+
RDFDataset inputRdf = new RDFDataset();
35+
inputRdf.setNamespace("aat", "http://vocab.getty.edu/aat/");
36+
inputRdf.setNamespace("aat_rev", "http://vocab.getty.edu/aat/rev/");
37+
38+
inputRdf.addTriple("http://vocab.getty.edu/aat/rev/5001065997", JsonLdConsts.RDF_TYPE, "http://vocab.getty.edu/aat/datatype");
39+
40+
final JsonLdOptions options = new JsonLdOptions();
41+
options.useNamespaces = true;
42+
43+
Object fromRDF = JsonLdProcessor.compact(new JsonLdApi(options).fromRDF(inputRdf),inputRdf.getContext(), options);
44+
45+
final RDFDataset rdf = (RDFDataset) JsonLdProcessor.toRDF(fromRDF, options);
46+
System.out.println(rdf.getNamespaces());
47+
assertEquals("http://vocab.getty.edu/aat/", rdf.getNamespace("aat"));
48+
assertEquals("http://vocab.getty.edu/aat/rev/", rdf.getNamespace("aat_rev"));
49+
50+
String toJSONLD = JsonUtils.toPrettyString(fromRDF);
51+
System.out.println(toJSONLD);
52+
53+
assertFalse("Longest prefix was not used", toJSONLD.contains("aat:rev/"));
54+
}
55+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"@context": {
3+
"aat" : "http://vocab.getty.edu/aat/",
4+
"aat_rev" : "http://vocab.getty.edu/aat/rev/"
5+
},
6+
"@id" : "aat_rev:5001065997",
7+
"@type": "aat_rev:datatype",
8+
"used" : "aat:300016954"
9+
}

0 commit comments

Comments
 (0)