|
| 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 | +import static org.junit.Assert.assertTrue; |
| 7 | + |
| 8 | +import java.io.BufferedReader; |
| 9 | +import java.io.InputStreamReader; |
| 10 | +import java.io.Reader; |
| 11 | +import java.net.URL; |
| 12 | +import java.nio.charset.Charset; |
| 13 | + |
| 14 | +import org.junit.Test; |
| 15 | + |
| 16 | +import com.github.jsonldjava.utils.JsonUtils; |
| 17 | + |
| 18 | +public class LocalBaseTest { |
| 19 | + @Test |
| 20 | + public void testMixedLocalRemoteBaseRemoteContextFirst() throws Exception { |
| 21 | + |
| 22 | + final Reader reader = new BufferedReader(new InputStreamReader( |
| 23 | + this.getClass().getResourceAsStream("/custom/base-0001-in.jsonld"), |
| 24 | + Charset.forName("UTF-8"))); |
| 25 | + final Object context = JsonUtils.fromReader(reader); |
| 26 | + assertNotNull(context); |
| 27 | + |
| 28 | + final JsonLdOptions options = new JsonLdOptions(); |
| 29 | + final Object expanded = JsonLdProcessor.expand(context, options); |
| 30 | + System.out.println(JsonUtils.toPrettyString(expanded)); |
| 31 | + |
| 32 | + final Reader outReader = new BufferedReader(new InputStreamReader( |
| 33 | + this.getClass().getResourceAsStream("/custom/base-0001-out.jsonld"), |
| 34 | + Charset.forName("UTF-8"))); |
| 35 | + final Object output = JsonUtils.fromReader(outReader); |
| 36 | + assertNotNull(output); |
| 37 | + assertEquals(expanded, output); |
| 38 | + } |
| 39 | + |
| 40 | + @Test |
| 41 | + public void testMixedLocalRemoteBaseLocalContextFirst() throws Exception { |
| 42 | + |
| 43 | + final Reader reader = new BufferedReader(new InputStreamReader( |
| 44 | + this.getClass().getResourceAsStream("/custom/base-0002-in.jsonld"), |
| 45 | + Charset.forName("UTF-8"))); |
| 46 | + final Object context = JsonUtils.fromReader(reader); |
| 47 | + assertNotNull(context); |
| 48 | + |
| 49 | + final JsonLdOptions options = new JsonLdOptions(); |
| 50 | + final Object expanded = JsonLdProcessor.expand(context, options); |
| 51 | + System.out.println(JsonUtils.toPrettyString(expanded)); |
| 52 | + |
| 53 | + final Reader outReader = new BufferedReader(new InputStreamReader( |
| 54 | + this.getClass().getResourceAsStream("/custom/base-0002-out.jsonld"), |
| 55 | + Charset.forName("UTF-8"))); |
| 56 | + final Object output = JsonUtils.fromReader(outReader); |
| 57 | + assertNotNull(output); |
| 58 | + assertEquals(expanded, output); |
| 59 | + } |
| 60 | + |
| 61 | +} |
0 commit comments