Skip to content

Commit a723d04

Browse files
committed
Add query to RestTestClient
Signed-off-by: Mario Daniel Ruiz Saavedra <[email protected]>
1 parent d78d11b commit a723d04

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
@@ -115,6 +115,11 @@ public RequestHeadersUriSpec<?> delete() {
115115
return methodInternal(HttpMethod.DELETE);
116116
}
117117

118+
@Override
119+
public RequestBodyUriSpec query() {
120+
return methodInternal(HttpMethod.QUERY);
121+
}
122+
118123
@Override
119124
public RequestHeadersUriSpec<?> options() {
120125
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
@@ -119,6 +119,12 @@ public interface RestTestClient {
119119
*/
120120
RequestHeadersUriSpec<?> delete();
121121

122+
/**
123+
* Prepare an HTTP QUERY request.
124+
* @return a spec for specifying the target URL
125+
*/
126+
RequestBodyUriSpec query();
127+
122128
/**
123129
* Prepare an HTTP OPTIONS request.
124130
* @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
@@ -64,7 +64,7 @@ void setUp() {
6464
class HttpMethods {
6565

6666
@ParameterizedTest
67-
@ValueSource(strings = {"GET", "POST", "PUT", "DELETE", "PATCH", "HEAD"})
67+
@ValueSource(strings = {"GET", "POST", "PUT", "DELETE", "PATCH", "QUERY", "HEAD"})
6868
void testMethod(String method) {
6969
RestTestClientTests.this.client.method(HttpMethod.valueOf(method)).uri("/test")
7070
.exchange()
@@ -125,10 +125,18 @@ void testOptions() {
125125
RestTestClientTests.this.client.options().uri("/test")
126126
.exchange()
127127
.expectStatus().isOk()
128-
.expectHeader().valueEquals("Allow", "GET,HEAD,POST,PUT,PATCH,DELETE,OPTIONS")
128+
.expectHeader().valueEquals("Allow", "GET,HEAD,POST,PUT,PATCH,DELETE,OPTIONS,QUERY")
129129
.expectBody().isEmpty();
130130
}
131131

132+
@Test
133+
void testQuery() {
134+
RestTestClientTests.this.client.query().uri("/test")
135+
.exchange()
136+
.expectStatus().isOk()
137+
.expectBody().jsonPath("$.method").isEqualTo("QUERY");
138+
}
139+
132140
}
133141

134142

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)