Skip to content

Commit 3c22c68

Browse files
committed
Add custom integration test, tweak assertion to handle null
Add test using a full document with base and relative IDs based on the original report by @ebremer on the users@jena.apache.org list See #279
1 parent 90ccfac commit 3c22c68

File tree

4 files changed

+50
-2
lines changed

4 files changed

+50
-2
lines changed

core/src/test/java/com/github/jsonldjava/core/LocalBaseTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package com.github.jsonldjava.core;
22

33
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertFalse;
45
import static org.junit.Assert.assertNotNull;
56

67
import java.io.BufferedReader;
78
import java.io.InputStreamReader;
89
import java.io.Reader;
910
import java.nio.charset.Charset;
11+
import java.util.List;
1012

1113
import org.junit.Test;
1214

@@ -55,4 +57,25 @@ public void testMixedLocalRemoteBaseLocalContextFirst() throws Exception {
5557
assertEquals(expanded, output);
5658
}
5759

60+
@Test
61+
public void testUriResolveWhenExpandingBase() throws Exception {
62+
63+
final Reader reader = new BufferedReader(new InputStreamReader(
64+
this.getClass().getResourceAsStream("/custom/base-0003-in.jsonld"),
65+
Charset.forName("UTF-8")));
66+
final Object input = JsonUtils.fromReader(reader);
67+
assertNotNull(input);
68+
69+
final JsonLdOptions options = new JsonLdOptions();
70+
final List<Object> expanded = JsonLdProcessor.expand(input, options);
71+
assertFalse("expanded form must not be empty", expanded.isEmpty());
72+
73+
final Reader outReader = new BufferedReader(new InputStreamReader(
74+
this.getClass().getResourceAsStream("/custom/base-0003-out.jsonld"),
75+
Charset.forName("UTF-8")));
76+
final Object expected = JsonLdProcessor.expand(JsonUtils.fromReader(outReader), options);
77+
assertNotNull(expected);
78+
assertEquals(expected, expanded);
79+
}
80+
5881
}

core/src/test/java/com/github/jsonldjava/utils/JsonUtilsTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.github.jsonldjava.utils;
22

3+
4+
import static org.junit.Assert.assertEquals;
35
import static org.junit.Assert.assertTrue;
46

57
import java.io.IOException;
@@ -26,8 +28,7 @@ public void resolveTest() {
2628
} catch (final Exception e) {
2729
assertTrue(false);
2830
}
29-
30-
assertTrue(resolve.equals(baseUri + "/" + pathToResolve));
31+
assertEquals(baseUri + "/" + pathToResolve, resolve);
3132
}
3233

3334
@SuppressWarnings("unchecked")
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"@context": {
3+
"@base": "http://mysite.net",
4+
"DataSet": "http://schema.org/DataSet",
5+
"CreativeWork": "http://schema.org/CreativeWork"
6+
},
7+
"@graph": [
8+
{
9+
"@type": "CreativeWork",
10+
"@id": "picture.jpg"
11+
},
12+
{
13+
"@id": "./",
14+
"@type": "DataSet"
15+
}
16+
]
17+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[ {
2+
"@id" : "http://mysite.net/picture.jpg",
3+
"@type" : [ "http://schema.org/CreativeWork" ]
4+
}, {
5+
"@id" : "http://mysite.net/",
6+
"@type" : [ "http://schema.org/DataSet" ]
7+
} ]

0 commit comments

Comments
 (0)