Skip to content

Commit 586de30

Browse files
Pierre-Jean Vardanegawilkinsona
authored andcommitted
Convert query parameters list as param=1&param=2 instead of param=1,2
Closes gh-477
1 parent a7e91ad commit 586de30

File tree

4 files changed

+28
-10
lines changed

4 files changed

+28
-10
lines changed

spring-restdocs-restassured/src/main/java/org/springframework/restdocs/restassured/RestAssuredRequestConverter.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2017 the original author or authors.
2+
* Copyright 2014-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -141,7 +141,15 @@ private boolean isAllMediaTypesAcceptHeader(Header header) {
141141
private Parameters extractParameters(FilterableRequestSpecification requestSpec) {
142142
Parameters parameters = new Parameters();
143143
for (Entry<String, ?> entry : requestSpec.getQueryParams().entrySet()) {
144-
parameters.add(entry.getKey(), entry.getValue().toString());
144+
if (entry.getValue() instanceof Collection) {
145+
Collection<?> queryParams = ((Collection<?>) entry.getValue());
146+
for (Object queryParam : queryParams) {
147+
parameters.add(entry.getKey(), queryParam.toString());
148+
}
149+
}
150+
else {
151+
parameters.add(entry.getKey(), entry.getValue().toString());
152+
}
145153
}
146154
for (Entry<String, ?> entry : requestSpec.getRequestParams().entrySet()) {
147155
parameters.add(entry.getKey(), entry.getValue().toString());

spring-restdocs-restassured/src/main/java/org/springframework/restdocs/restassured3/RestAssuredRequestConverter.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2017 the original author or authors.
2+
* Copyright 2014-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -140,7 +140,15 @@ private boolean isAllMediaTypesAcceptHeader(Header header) {
140140
private Parameters extractParameters(FilterableRequestSpecification requestSpec) {
141141
Parameters parameters = new Parameters();
142142
for (Entry<String, ?> entry : requestSpec.getQueryParams().entrySet()) {
143-
parameters.add(entry.getKey(), entry.getValue().toString());
143+
if (entry.getValue() instanceof Collection) {
144+
Collection<?> queryParams = ((Collection<?>) entry.getValue());
145+
for (Object queryParam : queryParams) {
146+
parameters.add(entry.getKey(), queryParam.toString());
147+
}
148+
}
149+
else {
150+
parameters.add(entry.getKey(), entry.getValue().toString());
151+
}
144152
}
145153
for (Entry<String, ?> entry : requestSpec.getRequestParams().entrySet()) {
146154
parameters.add(entry.getKey(), entry.getValue().toString());

spring-restdocs-restassured/src/test/java/org/springframework/restdocs/restassured/RestAssuredRequestConverterTests.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2017 the original author or authors.
2+
* Copyright 2014-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -91,11 +91,12 @@ public void queryStringParameters() {
9191
@Test
9292
public void queryStringFromUrlParameters() {
9393
RequestSpecification requestSpec = RestAssured.given().port(tomcat.getPort());
94-
requestSpec.get("/?foo=bar");
94+
requestSpec.get("/?foo=bar&foo=qix");
9595
OperationRequest request = this.factory
9696
.convert((FilterableRequestSpecification) requestSpec);
9797
assertThat(request.getParameters().size(), is(1));
98-
assertThat(request.getParameters().get("foo"), is(equalTo(Arrays.asList("bar"))));
98+
assertThat(request.getParameters().get("foo"),
99+
is(equalTo(Arrays.asList("bar", "qix"))));
99100
}
100101

101102
@Test

spring-restdocs-restassured/src/test/java/org/springframework/restdocs/restassured3/RestAssuredRequestConverterTests.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2017 the original author or authors.
2+
* Copyright 2014-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -91,11 +91,12 @@ public void queryStringParameters() {
9191
@Test
9292
public void queryStringFromUrlParameters() {
9393
RequestSpecification requestSpec = RestAssured.given().port(tomcat.getPort());
94-
requestSpec.get("/?foo=bar");
94+
requestSpec.get("/?foo=bar&foo=qix");
9595
OperationRequest request = this.factory
9696
.convert((FilterableRequestSpecification) requestSpec);
9797
assertThat(request.getParameters().size(), is(1));
98-
assertThat(request.getParameters().get("foo"), is(equalTo(Arrays.asList("bar"))));
98+
assertThat(request.getParameters().get("foo"),
99+
is(equalTo(Arrays.asList("bar", "qix"))));
99100
}
100101

101102
@Test

0 commit comments

Comments
 (0)