|
4 | 4 | import static org.junit.Assert.assertFalse; |
5 | 5 | import static org.junit.Assert.assertNotNull; |
6 | 6 |
|
| 7 | +import java.io.BufferedReader; |
| 8 | +import java.io.IOException; |
| 9 | +import java.io.InputStreamReader; |
7 | 10 | import java.net.URL; |
| 11 | +import java.nio.charset.StandardCharsets; |
| 12 | +import java.util.List; |
| 13 | +import java.util.stream.Collectors; |
8 | 14 |
|
| 15 | +import org.junit.Ignore; |
9 | 16 | import org.junit.Test; |
10 | 17 |
|
11 | 18 | import com.github.jsonldjava.utils.JsonUtils; |
| 19 | +import com.github.jsonldjava.utils.TestUtils; |
12 | 20 |
|
13 | | -public class ArrayContextToRDFTest { |
| 21 | +public class ToRDFTest { |
14 | 22 | @Test |
15 | 23 | public void toRdfWithNamespace() throws Exception { |
16 | 24 |
|
@@ -43,4 +51,35 @@ public RemoteDocument loadDocument(String url) throws JsonLdError { |
43 | 51 | assertFalse(rdf.getNamespaces().containsKey("term1")); |
44 | 52 |
|
45 | 53 | } |
| 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 | + } |
46 | 85 | } |
0 commit comments