Skip to content

Commit 258303c

Browse files
committed
Add query to RestTestClient
1 parent ecf0bb6 commit 258303c

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

spring-test/src/main/java/org/springframework/test/web/servlet/client/DefaultRestTestClient.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ public RequestHeadersUriSpec<?> delete() {
103103
return methodInternal(HttpMethod.DELETE);
104104
}
105105

106+
@Override
107+
public RequestBodyUriSpec query() {
108+
return methodInternal(HttpMethod.QUERY);
109+
}
110+
106111
@Override
107112
public RequestHeadersUriSpec<?> options() {
108113
return methodInternal(HttpMethod.OPTIONS);

spring-test/src/main/java/org/springframework/test/web/servlet/client/RestTestClient.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ public interface RestTestClient {
120120
*/
121121
RequestHeadersUriSpec<?> delete();
122122

123+
/**
124+
* Prepare an HTTP QUERY request.
125+
* @return a spec for specifying the target URL
126+
*/
127+
RequestBodyUriSpec query();
128+
123129
/**
124130
* Prepare an HTTP OPTIONS request.
125131
* @return a spec for specifying the target URL

spring-test/src/test/java/org/springframework/test/web/servlet/client/RestTestClientTests.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ void setUp() {
6161
class HttpMethods {
6262

6363
@ParameterizedTest
64-
@ValueSource(strings = {"GET", "POST", "PUT", "DELETE", "PATCH", "HEAD"})
64+
@ValueSource(strings = {"GET", "POST", "PUT", "DELETE", "PATCH", "QUERY", "HEAD"})
6565
void testMethod(String method) {
6666
RestTestClientTests.this.client.method(HttpMethod.valueOf(method)).uri("/test")
6767
.exchange()
@@ -122,10 +122,18 @@ void testOptions() {
122122
RestTestClientTests.this.client.options().uri("/test")
123123
.exchange()
124124
.expectStatus().isOk()
125-
.expectHeader().valueEquals("Allow", "GET,HEAD,POST,PUT,PATCH,DELETE,OPTIONS")
125+
.expectHeader().valueEquals("Allow", "GET,HEAD,POST,PUT,PATCH,DELETE,OPTIONS,QUERY")
126126
.expectBody().isEmpty();
127127
}
128128

129+
@Test
130+
void testQuery() {
131+
RestTestClientTests.this.client.query().uri("/test")
132+
.exchange()
133+
.expectStatus().isOk()
134+
.expectBody().jsonPath("$.method").isEqualTo("QUERY");
135+
}
136+
129137
}
130138

131139

spring-web/src/test/java/org/springframework/web/client/AbstractMockWebServerTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ private MockResponse queryRequest(RecordedRequest request, String expectedReques
244244
String contentType, byte[] responseBody) {
245245

246246
assertThat(request.getHeaders().values(CONTENT_LENGTH)).hasSize(1);
247-
assertThat(Integer.parseInt(request.getHeaders().get(CONTENT_LENGTH))).as("Invalid request content-length").isGreaterThan(0);
247+
assertThat(Integer.parseInt(request.getHeaders().get(CONTENT_LENGTH))).as("Invalid request content-length").isGreaterThan(0);
248248
String requestContentType = request.getHeaders().get(CONTENT_TYPE);
249249
assertThat(requestContentType).as("No content-type").isNotNull();
250250
Charset charset = StandardCharsets.ISO_8859_1;

0 commit comments

Comments
 (0)