Skip to content

Commit b07e4fd

Browse files
committed
Avoid using JSONPath#getPath()
It does not return the original path and omits expressions. Closes gh-377
1 parent 8549060 commit b07e4fd

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

spring-graphql-test/src/main/java/org/springframework/graphql/test/tester/DefaultGraphQlTester.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -330,24 +330,25 @@ private static final class DefaultPath implements Path {
330330
private final JsonPathExpectationsHelper pathHelper;
331331

332332
private DefaultPath(String path, ResponseDelegate delegate) {
333-
334333
Assert.notNull(path, "`path` is required");
335334
Assert.notNull(delegate, "ResponseContainer is required");
336335

336+
String fullPath = initFullPath(path);
337+
337338
this.path = path;
338339
this.delegate = delegate;
339-
this.jsonPath = initJsonPath(path);
340-
this.pathHelper = new JsonPathExpectationsHelper(this.jsonPath.getPath());
340+
this.jsonPath = JsonPath.compile(fullPath);
341+
this.pathHelper = new JsonPathExpectationsHelper(fullPath);
341342
}
342343

343-
private static JsonPath initJsonPath(String path) {
344+
private static String initFullPath(String path) {
344345
if (!StringUtils.hasText(path)) {
345346
path = "$.data";
346347
}
347348
else if (!path.startsWith("$") && !path.startsWith("data.")) {
348349
path = "$.data." + path;
349350
}
350-
return JsonPath.compile(path);
351+
return path;
351352
}
352353

353354
@Override

spring-graphql-test/src/test/java/org/springframework/graphql/test/tester/GraphQlTesterTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ void hasValue() {
4848
GraphQlTester.Response response = graphQlTester().document(document).execute();
4949
response.path("me.name").hasValue();
5050
response.path("me.friends").hasValue();
51+
response.path("me[?(@.name == 'Luke Skywalker')].name").hasValue(); // gh-377
5152

5253
assertThatThrownBy(() -> response.path("hero").hasValue())
53-
.hasMessageContaining("No value at JSON path \"$['data']['hero']");
54+
.hasMessageContaining("No value at JSON path \"$.data.hero\"");
5455

5556
assertThat(getActualRequestDocument()).contains(document);
5657
}
@@ -152,7 +153,7 @@ void entityList() {
152153
"{" +
153154
" \"me\":{" +
154155
" \"name\":\"Luke Skywalker\","
155-
+ " \"friends\":[{\"name\":\"Han Solo\"}, {\"name\":\"Leia Organa\"}]" +
156+
+ " \"friends\":[{\"name\":\"Han Solo\"}, {\"name\":\"Leia Organa\"}]" +
156157
" }" +
157158
"}");
158159

0 commit comments

Comments
 (0)