Skip to content

Commit 3569eb9

Browse files
committed
Build query matcher with array matcher
1 parent 1694ad3 commit 3569eb9

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

src/main/java/io/specto/hoverfly/junit/dsl/RequestMatcherBuilder.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,9 @@ public RequestMatcherBuilder queryParam(final String key, final Object... values
133133
if (values.length == 0 ) {
134134
query.put(key, singletonList(any()));
135135
} else {
136-
// TODO until we implement an array matcher, hoverfly currently match on array values that are joined by semicolon
137-
query.put(key, singletonList(newExactMatcher(Arrays.stream(values)
136+
query.put(key, singletonList(newArrayMatcher(Arrays.stream(values)
138137
.map(Object::toString)
139-
.collect(Collectors.joining(";")))));
138+
.collect(Collectors.toList()))));
140139
}
141140
return this;
142141
}

src/test/java/io/specto/hoverfly/junit/dsl/StubServiceBuilderTest.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,15 @@ public void shouldBuildAnyMethodRequestWithPathMatcher() {
102102
}
103103

104104
@Test
105-
public void shouldBuildExactQueryMatcher() {
105+
public void shouldBuildArrayQueryMatcher() {
106106
// When
107107
final Set<RequestResponsePair> pairs = service("www.base-url.com").get("/").queryParam("foo", "bar")
108108
.willReturn(response()).getRequestResponsePairs();
109109

110110
// Then
111111
assertThat(pairs).hasSize(1);
112112
Map<String, List<RequestFieldMatcher>> query = Iterables.getLast(pairs).getRequest().getQuery();
113-
assertThat(query).containsExactly(MapEntry.entry("foo", singletonList(newExactMatcher("bar"))));
113+
assertThat(query).containsExactly(MapEntry.entry("foo", singletonList(newArrayMatcher(singletonList("bar")))));
114114
}
115115

116116
// TODO Not supported
@@ -166,13 +166,13 @@ public void shouldBuildExactQueryWithMultipleKeyValuePairs() {
166166
assertThat(pairs).hasSize(1);
167167
Map<String, List<RequestFieldMatcher>> query = Iterables.getLast(pairs).getRequest().getQuery();
168168
assertThat(query).containsOnly(
169-
MapEntry.entry("page", singletonList(newExactMatcher("1"))),
170-
MapEntry.entry("size", singletonList(newExactMatcher("10")))
169+
MapEntry.entry("page", singletonList(newArrayMatcher(singletonList("1")))),
170+
MapEntry.entry("size", singletonList(newArrayMatcher(singletonList("10"))))
171171
);
172172
}
173173

174174
@Test
175-
public void shouldBuildExactQueryForKeyWithMultipleValues() {
175+
public void shouldBuildQueryArrayMatcherForKeyWithMultipleValues() {
176176
// When
177177
final Set<RequestResponsePair> pairs = service("www.base-url.com").get("/")
178178
.queryParam("category", "food", "drink")
@@ -182,7 +182,7 @@ public void shouldBuildExactQueryForKeyWithMultipleValues() {
182182
assertThat(pairs).hasSize(1);
183183
Map<String, List<RequestFieldMatcher>> query = Iterables.getLast(pairs).getRequest().getQuery();
184184
assertThat(query).containsExactly(
185-
MapEntry.entry("category", singletonList(newExactMatcher("food;drink")))
185+
MapEntry.entry("category", singletonList(newArrayMatcher(Arrays.asList("food", "drink"))))
186186
);
187187
}
188188

@@ -204,7 +204,7 @@ public void shouldBuildQueryWithMultipleFuzzyMatchers() {
204204
}
205205

206206
@Test
207-
public void shouldBuildQueryWithBothExactAndFuzzyMatchers() {
207+
public void shouldBuildQueryWithBothArrayAndFuzzyMatchers() {
208208
// When
209209
final Set<RequestResponsePair> pairs = service("www.base-url.com").get("/")
210210
.queryParam("page", any())
@@ -216,7 +216,7 @@ public void shouldBuildQueryWithBothExactAndFuzzyMatchers() {
216216
Map<String, List<RequestFieldMatcher>> query = Iterables.getLast(pairs).getRequest().getQuery();
217217
assertThat(query).containsOnly(
218218
MapEntry.entry("page", singletonList(newRegexMatcher(".*"))),
219-
MapEntry.entry("category", singletonList(newExactMatcher("food")))
219+
MapEntry.entry("category", singletonList(newArrayMatcher(singletonList("food"))))
220220
);
221221
}
222222

@@ -273,7 +273,7 @@ public void shouldNotEncodeSpacesInQueryParams() {
273273
assertThat(pairs).hasSize(1);
274274
Map<String, List<RequestFieldMatcher>> query = Iterables.getLast(pairs).getRequest().getQuery();
275275
assertThat(query).containsExactly(
276-
MapEntry.entry("destination", singletonList(newExactMatcher("New York")))
276+
MapEntry.entry("destination", singletonList(newArrayMatcher(singletonList("New York"))))
277277
);
278278
}
279279

0 commit comments

Comments
 (0)