Skip to content

Commit 824fc54

Browse files
author
Bence Erős
committed
fixing #407 (incorrect SchemaException#schemaLocation when a remote shema fails to parse)
1 parent 23cad68 commit 824fc54

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-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: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class JsonPointerEvaluatorTest {
3232
private static final ResourceLoader LOADER = ResourceLoader.DEFAULT;
3333

3434
@Test
35-
public void sameDocumentSuccess() {
35+
void sameDocumentSuccess() {
3636
JsonPointerEvaluator pointer = JsonPointerEvaluator.forDocument(rootSchemaJson, "#/definitions/Bar");
3737
JsonObject actual = pointer.query().getQueryResult().requireObject();
3838
assertEquals("dummy schema at #/definitions/Bar", actual.require("description").requireString());
@@ -41,7 +41,7 @@ public void sameDocumentSuccess() {
4141
}
4242

4343
@Test
44-
public void sameDocumentNotFound() {
44+
void sameDocumentNotFound() {
4545
Assertions.assertThrows(SchemaException.class, () -> {
4646
JsonPointerEvaluator pointer = JsonPointerEvaluator.forDocument(rootSchemaJson, "#/definitions/NotFound");
4747
JsonObject actual = pointer.query().getQueryResult().requireObject();
@@ -52,21 +52,21 @@ public void sameDocumentNotFound() {
5252
}
5353

5454
@Test
55-
public void arrayIndexSuccess() {
55+
void arrayIndexSuccess() {
5656
JsonPointerEvaluator pointer = JsonPointerEvaluator.forDocument(rootSchemaJson, "#/definitions/Array/0");
5757
JsonObject actual = pointer.query().getQueryResult().requireObject();
5858
assertEquals("dummy schema in array", actual.require("description").requireString());
5959
}
6060

6161
@Test
62-
public void rootRefSuccess() {
62+
void rootRefSuccess() {
6363
JsonPointerEvaluator pointer = JsonPointerEvaluator.forDocument(rootSchemaJson, "#");
6464
JsonObject actual = pointer.query().getQueryResult().requireObject();
6565
assertSame(rootSchemaJson, actual);
6666
}
6767

6868
@Test
69-
public void escaping() {
69+
void escaping() {
7070
JsonPointerEvaluator pointer = JsonPointerEvaluator.forDocument(rootSchemaJson, "#/definitions/Escaping/sla~1sh/ti~0lde");
7171
JsonObject actual = pointer.query().getQueryResult().requireObject();
7272
assertEquals("tiled", actual.require("description").requireString());
@@ -82,7 +82,7 @@ private LoadingState createLoadingState(SchemaClient schemaClient, String ref) {
8282
}
8383

8484
@Test
85-
public void remoteDocumentSuccess() throws URISyntaxException {
85+
void remoteDocumentSuccess() throws URISyntaxException {
8686
SchemaClient schemaClient = mock(SchemaClient.class);
8787
when(schemaClient.get("http://localhost:1234/hello")).thenReturn(rootSchemaJsonAsStream());
8888
JsonPointerEvaluator pointer = JsonPointerEvaluator
@@ -94,9 +94,21 @@ public void remoteDocumentSuccess() throws URISyntaxException {
9494
assertEquals(new SchemaLocation(new URI("http://localhost:1234/hello"), asList("definitions", "Bar")),
9595
actual.ls.pointerToCurrentObj);
9696
}
97+
98+
@Test
99+
void remoteDocument_jsonParsingFailure() {
100+
SchemaClient schemaClient = mock(SchemaClient.class);
101+
when(schemaClient.get("http://localhost:1234/hello")).thenReturn(asStream("unparseable"));
102+
try {
103+
JsonPointerEvaluator.forURL(schemaClient, "http://localhost:1234/hello#/foo", createLoadingState(schemaClient, "")).query();
104+
fail("did not throw exception for unparseable json");
105+
} catch (SchemaException e) {
106+
assertEquals("http://localhost:1234/hello", e.getSchemaLocation());
107+
}
108+
}
97109

98110
@Test
99-
public void schemaExceptionForInvalidURI() {
111+
void schemaExceptionForInvalidURI() {
100112
try {
101113
SchemaClient schemaClient = mock(SchemaClient.class);
102114
JsonPointerEvaluator subject = JsonPointerEvaluator.forURL(schemaClient, "||||",

0 commit comments

Comments
 (0)