Skip to content

Commit 906ec5f

Browse files
committed
Add regression test for both versions of the issue
Ie, local and remote function differently if they are first or last
1 parent ea5e779 commit 906ec5f

File tree

5 files changed

+113
-0
lines changed

5 files changed

+113
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"@context": [
3+
"https://raw.githubusercontent.com/monarch-initiative/monarch-app/master/conf/monarch-context.jsonld",
4+
{
5+
"@base": "http://example.org/base/",
6+
"ex": "http://example.org/",
7+
"ex:friendOf": {
8+
"@type": "@id"
9+
}
10+
}
11+
],
12+
"@id": "3456",
13+
"ex:name": "Jim",
14+
"ex:friendOf": "1234",
15+
"@type": "Person"
16+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[ {
2+
"@id" : "http://example.org/base/3456",
3+
"@type" : [ "http://example.org/base/Person" ],
4+
"http://example.org/friendOf" : [ {
5+
"@id" : "http://example.org/base/1234"
6+
} ],
7+
"http://example.org/name" : [ {
8+
"@value" : "Jim"
9+
} ]
10+
} ]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"@context": [
3+
{
4+
"@base": "http://example.org/base/",
5+
"ex": "http://example.org/",
6+
"ex:friendOf": {
7+
"@type": "@id"
8+
}
9+
},
10+
"https://raw.githubusercontent.com/monarch-initiative/monarch-app/master/conf/monarch-context.jsonld"
11+
],
12+
"@id": "3456",
13+
"ex:name": "Jim",
14+
"ex:friendOf": "1234",
15+
"@type": "Person"
16+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[ {
2+
"@id" : "http://example.org/base/3456",
3+
"@type" : [ "http://example.org/base/Person" ],
4+
"http://example.org/friendOf" : [ {
5+
"@id" : "http://example.org/base/1234"
6+
} ],
7+
"http://example.org/name" : [ {
8+
"@value" : "Jim"
9+
} ]
10+
} ]

0 commit comments

Comments
 (0)