Skip to content

Commit 24cf028

Browse files
committed
Add tests for hierarchical and opaque base IRIs
See #232
1 parent 44c1bba commit 24cf028

File tree

5 files changed

+44
-1
lines changed

5 files changed

+44
-1
lines changed

core/src/test/java/com/github/jsonldjava/core/ArrayContextToRDFTest.java renamed to core/src/test/java/com/github/jsonldjava/core/ToRDFTest.java

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,21 @@
44
import static org.junit.Assert.assertFalse;
55
import static org.junit.Assert.assertNotNull;
66

7+
import java.io.BufferedReader;
8+
import java.io.IOException;
9+
import java.io.InputStreamReader;
710
import java.net.URL;
11+
import java.nio.charset.StandardCharsets;
12+
import java.util.List;
13+
import java.util.stream.Collectors;
814

15+
import org.junit.Ignore;
916
import org.junit.Test;
1017

1118
import com.github.jsonldjava.utils.JsonUtils;
19+
import com.github.jsonldjava.utils.TestUtils;
1220

13-
public class ArrayContextToRDFTest {
21+
public class ToRDFTest {
1422
@Test
1523
public void toRdfWithNamespace() throws Exception {
1624

@@ -43,4 +51,35 @@ public RemoteDocument loadDocument(String url) throws JsonLdError {
4351
assertFalse(rdf.getNamespaces().containsKey("term1"));
4452

4553
}
54+
55+
@Test
56+
// See https://github.com/jsonld-java/jsonld-java/issues/232
57+
public void toRdfWithHttpBaseIri() throws IOException, JsonLdError {
58+
testToRdf("/custom/toRdf-0001-in.jsonld", "/custom/toRdf-0001-out.nq", "http://example.org/");
59+
}
60+
61+
@Test
62+
// See https://github.com/jsonld-java/jsonld-java/issues/232
63+
public void toRdfWithHierarchicalBaseIri() throws IOException, JsonLdError {
64+
testToRdf("/custom/toRdf-0001-in.jsonld", "/custom/toRdf-0002-out.nq", "tag:/example/");
65+
}
66+
67+
@Test
68+
@Ignore
69+
// See https://github.com/jsonld-java/jsonld-java/issues/232#issuecomment-493454096
70+
public void toRdfWithOpaqueBaseIri() throws IOException, JsonLdError {
71+
testToRdf("/custom/toRdf-0001-in.jsonld", "/custom/toRdf-0003-out.nq", "tag:example/");
72+
}
73+
74+
private void testToRdf(String inFile, String outFile, String baseIri) throws IOException {
75+
final Object input = JsonUtils
76+
.fromInputStream(getClass().getResourceAsStream(inFile));
77+
List<String> resultLines = new BufferedReader(new InputStreamReader(
78+
getClass().getResourceAsStream(outFile), StandardCharsets.UTF_8)).lines()
79+
.collect(Collectors.toList());
80+
JsonLdOptions options = new JsonLdOptions(baseIri);
81+
options.format = JsonLdConsts.APPLICATION_NQUADS;
82+
Object result = JsonLdProcessor.toRDF(input, options);
83+
assertEquals(TestUtils.join(resultLines, "\n").trim(), ((String) result).trim());
84+
}
4685
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"@id":"relativeURIWithNoBase","@type":"http://example.org/SomeRDFSClass"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<http://example.org/relativeURIWithNoBase> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/SomeRDFSClass> .
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<tag:/example/relativeURIWithNoBase> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/SomeRDFSClass> .
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<tag:example/relativeURIWithNoBase> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/SomeRDFSClass> .

0 commit comments

Comments
 (0)