Request param not accepting empty values; fixes gh-886
This commit is contained in:
@@ -157,7 +157,8 @@ public class WireMockSnippet implements Snippet {
|
||||
}
|
||||
for (String queryPair : rawQuery.split("&")) {
|
||||
String[] splitQueryPair = queryPair.split("=");
|
||||
request = request.withQueryParam(splitQueryPair[0], WireMock.equalTo(splitQueryPair[1]));
|
||||
String value = splitQueryPair.length > 1 ? splitQueryPair[1] : "" ;
|
||||
request = request.withQueryParam(splitQueryPair[0], WireMock.equalTo(value));
|
||||
}
|
||||
return request;
|
||||
}
|
||||
|
||||
@@ -139,6 +139,19 @@ public class WireMockSnippetTests {
|
||||
.isEqualTo(HttpStatus.ACCEPTED.value());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_accept_empty_value_for_query_params() throws IOException {
|
||||
this.operation = operation(requestPostWithEmptyQueryParamValue(), response(), this.context);
|
||||
WireMockSnippet snippet = new WireMockSnippet();
|
||||
|
||||
snippet.document(this.operation);
|
||||
|
||||
File stub = new File(this.outputFolder, "stubs/foo.json");
|
||||
assertThat(stub).exists();
|
||||
WireMockStubMapping
|
||||
.buildFrom(new String(Files.readAllBytes(stub.toPath())));
|
||||
}
|
||||
|
||||
private Operation operation(OperationRequest request, OperationResponse response,
|
||||
RestDocumentationContext context) {
|
||||
return operation("foo", request, response, context);
|
||||
@@ -385,4 +398,53 @@ public class WireMockSnippetTests {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private OperationRequest requestPostWithEmptyQueryParamValue() {
|
||||
return new OperationRequest() {
|
||||
@Override
|
||||
public byte[] getContent() {
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContentAsString() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpHeaders getHeaders() {
|
||||
HttpHeaders httpHeaders = new HttpHeaders();
|
||||
httpHeaders
|
||||
.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
|
||||
return httpHeaders;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpMethod getMethod() {
|
||||
return HttpMethod.POST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Parameters getParameters() {
|
||||
Parameters parameters = new Parameters();
|
||||
parameters.put("myParam", Collections.singletonList(""));
|
||||
return parameters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<OperationRequestPart> getParts() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI getUri() {
|
||||
return URI.create("http://foo/bar?myParam=");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<RequestCookie> getCookies() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user