Skip to content

Commit 8119958

Browse files
authored
Merge pull request #408 from erosb/issue407
Fixing #407
2 parents eae88ed + 4840a51 commit 8119958

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

core/src/main/java/org/everit/json/schema/loader/JsonPointerEvaluator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private static JsonObject executeWith(final SchemaClient client, final String ur
9090
} catch (IOException e) {
9191
throw new UncheckedIOException(e);
9292
} catch (JSONException e) {
93-
throw new SchemaException("failed to parse " + resp, e);
93+
throw new SchemaException(url, e);
9494
} finally {
9595
try {
9696
if (buffReader != null) {

core/src/test/java/org/everit/json/schema/loader/JsonPointerEvaluatorTest.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import static org.hamcrest.MatcherAssert.assertThat;
99
import static org.junit.jupiter.api.Assertions.assertEquals;
1010
import static org.junit.jupiter.api.Assertions.assertSame;
11+
import static org.junit.jupiter.api.Assertions.assertThrows;
1112
import static org.junit.jupiter.api.Assertions.fail;
1213
import static org.mockito.Mockito.mock;
1314
import static org.mockito.Mockito.when;
@@ -32,7 +33,7 @@ public class JsonPointerEvaluatorTest {
3233
private static final ResourceLoader LOADER = ResourceLoader.DEFAULT;
3334

3435
@Test
35-
public void sameDocumentSuccess() {
36+
void sameDocumentSuccess() {
3637
JsonPointerEvaluator pointer = JsonPointerEvaluator.forDocument(rootSchemaJson, "#/definitions/Bar");
3738
JsonObject actual = pointer.query().getQueryResult().requireObject();
3839
assertEquals("dummy schema at #/definitions/Bar", actual.require("description").requireString());
@@ -41,7 +42,7 @@ public void sameDocumentSuccess() {
4142
}
4243

4344
@Test
44-
public void sameDocumentNotFound() {
45+
void sameDocumentNotFound() {
4546
Assertions.assertThrows(SchemaException.class, () -> {
4647
JsonPointerEvaluator pointer = JsonPointerEvaluator.forDocument(rootSchemaJson, "#/definitions/NotFound");
4748
JsonObject actual = pointer.query().getQueryResult().requireObject();
@@ -52,21 +53,21 @@ public void sameDocumentNotFound() {
5253
}
5354

5455
@Test
55-
public void arrayIndexSuccess() {
56+
void arrayIndexSuccess() {
5657
JsonPointerEvaluator pointer = JsonPointerEvaluator.forDocument(rootSchemaJson, "#/definitions/Array/0");
5758
JsonObject actual = pointer.query().getQueryResult().requireObject();
5859
assertEquals("dummy schema in array", actual.require("description").requireString());
5960
}
6061

6162
@Test
62-
public void rootRefSuccess() {
63+
void rootRefSuccess() {
6364
JsonPointerEvaluator pointer = JsonPointerEvaluator.forDocument(rootSchemaJson, "#");
6465
JsonObject actual = pointer.query().getQueryResult().requireObject();
6566
assertSame(rootSchemaJson, actual);
6667
}
6768

6869
@Test
69-
public void escaping() {
70+
void escaping() {
7071
JsonPointerEvaluator pointer = JsonPointerEvaluator.forDocument(rootSchemaJson, "#/definitions/Escaping/sla~1sh/ti~0lde");
7172
JsonObject actual = pointer.query().getQueryResult().requireObject();
7273
assertEquals("tiled", actual.require("description").requireString());
@@ -82,7 +83,7 @@ private LoadingState createLoadingState(SchemaClient schemaClient, String ref) {
8283
}
8384

8485
@Test
85-
public void remoteDocumentSuccess() throws URISyntaxException {
86+
void remoteDocumentSuccess() throws URISyntaxException {
8687
SchemaClient schemaClient = mock(SchemaClient.class);
8788
when(schemaClient.get("http://localhost:1234/hello")).thenReturn(rootSchemaJsonAsStream());
8889
JsonPointerEvaluator pointer = JsonPointerEvaluator
@@ -94,9 +95,19 @@ public void remoteDocumentSuccess() throws URISyntaxException {
9495
assertEquals(new SchemaLocation(new URI("http://localhost:1234/hello"), asList("definitions", "Bar")),
9596
actual.ls.pointerToCurrentObj);
9697
}
98+
99+
@Test
100+
void remoteDocument_jsonParsingFailure() {
101+
SchemaClient schemaClient = mock(SchemaClient.class);
102+
when(schemaClient.get("http://localhost:1234/hello")).thenReturn(asStream("unparseable"));
103+
SchemaException actual = assertThrows(SchemaException.class,
104+
() -> JsonPointerEvaluator.forURL(schemaClient, "http://localhost:1234/hello#/foo", createLoadingState(schemaClient, "")).query()
105+
);
106+
assertEquals("http://localhost:1234/hello", actual.getSchemaLocation());
107+
}
97108

98109
@Test
99-
public void schemaExceptionForInvalidURI() {
110+
void schemaExceptionForInvalidURI() {
100111
try {
101112
SchemaClient schemaClient = mock(SchemaClient.class);
102113
JsonPointerEvaluator subject = JsonPointerEvaluator.forURL(schemaClient, "||||",

0 commit comments

Comments
 (0)