Merge pull request #477 from Pierre-Jean Vardanega

* gh-477:
  Convert query parameters list as param=1&param=2 instead of param=1,2
This commit is contained in:
Andy Wilkinson
2018-03-27 14:26:14 +01:00
4 changed files with 28 additions and 10 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2017 the original author or authors.
* Copyright 2014-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -141,7 +141,15 @@ class RestAssuredRequestConverter
private Parameters extractParameters(FilterableRequestSpecification requestSpec) {
Parameters parameters = new Parameters();
for (Entry<String, ?> entry : requestSpec.getQueryParams().entrySet()) {
parameters.add(entry.getKey(), entry.getValue().toString());
if (entry.getValue() instanceof Collection) {
Collection<?> queryParams = ((Collection<?>) entry.getValue());
for (Object queryParam : queryParams) {
parameters.add(entry.getKey(), queryParam.toString());
}
}
else {
parameters.add(entry.getKey(), entry.getValue().toString());
}
}
for (Entry<String, ?> entry : requestSpec.getRequestParams().entrySet()) {
parameters.add(entry.getKey(), entry.getValue().toString());

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2017 the original author or authors.
* Copyright 2014-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -140,7 +140,15 @@ class RestAssuredRequestConverter
private Parameters extractParameters(FilterableRequestSpecification requestSpec) {
Parameters parameters = new Parameters();
for (Entry<String, ?> entry : requestSpec.getQueryParams().entrySet()) {
parameters.add(entry.getKey(), entry.getValue().toString());
if (entry.getValue() instanceof Collection) {
Collection<?> queryParams = ((Collection<?>) entry.getValue());
for (Object queryParam : queryParams) {
parameters.add(entry.getKey(), queryParam.toString());
}
}
else {
parameters.add(entry.getKey(), entry.getValue().toString());
}
}
for (Entry<String, ?> entry : requestSpec.getRequestParams().entrySet()) {
parameters.add(entry.getKey(), entry.getValue().toString());

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2017 the original author or authors.
* Copyright 2014-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -91,11 +91,12 @@ public class RestAssuredRequestConverterTests {
@Test
public void queryStringFromUrlParameters() {
RequestSpecification requestSpec = RestAssured.given().port(tomcat.getPort());
requestSpec.get("/?foo=bar");
requestSpec.get("/?foo=bar&foo=qix");
OperationRequest request = this.factory
.convert((FilterableRequestSpecification) requestSpec);
assertThat(request.getParameters().size(), is(1));
assertThat(request.getParameters().get("foo"), is(equalTo(Arrays.asList("bar"))));
assertThat(request.getParameters().get("foo"),
is(equalTo(Arrays.asList("bar", "qix"))));
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2017 the original author or authors.
* Copyright 2014-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -91,11 +91,12 @@ public class RestAssuredRequestConverterTests {
@Test
public void queryStringFromUrlParameters() {
RequestSpecification requestSpec = RestAssured.given().port(tomcat.getPort());
requestSpec.get("/?foo=bar");
requestSpec.get("/?foo=bar&foo=qix");
OperationRequest request = this.factory
.convert((FilterableRequestSpecification) requestSpec);
assertThat(request.getParameters().size(), is(1));
assertThat(request.getParameters().get("foo"), is(equalTo(Arrays.asList("bar"))));
assertThat(request.getParameters().get("foo"),
is(equalTo(Arrays.asList("bar", "qix"))));
}
@Test