Skip to content

Commit 4a7f351

Browse files
committed
Map array matcher configs
1 parent a09b1c7 commit 4a7f351

File tree

5 files changed

+99
-4
lines changed

5 files changed

+99
-4
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package io.specto.hoverfly.junit.core.model;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.fasterxml.jackson.annotation.JsonInclude;
5+
import org.apache.commons.lang3.builder.EqualsBuilder;
6+
import org.apache.commons.lang3.builder.HashCodeBuilder;
7+
import org.apache.commons.lang3.builder.ToStringBuilder;
8+
9+
@JsonIgnoreProperties(ignoreUnknown = true)
10+
@JsonInclude(JsonInclude.Include.NON_NULL)
11+
public class ArrayMatcherConfig implements MatcherConfig {
12+
13+
private boolean ignoreUnknown;
14+
private boolean ignoreOrder;
15+
private boolean ignoreOccurrences;
16+
17+
public ArrayMatcherConfig() {
18+
}
19+
20+
public ArrayMatcherConfig(boolean ignoreUnknown, boolean ignoreOrder, boolean ignoreOccurrences) {
21+
this.ignoreUnknown = ignoreUnknown;
22+
this.ignoreOrder = ignoreOrder;
23+
this.ignoreOccurrences = ignoreOccurrences;
24+
}
25+
26+
public boolean isIgnoreUnknown() {
27+
return ignoreUnknown;
28+
}
29+
30+
public void setIgnoreUnknown(boolean ignoreUnknown) {
31+
this.ignoreUnknown = ignoreUnknown;
32+
}
33+
34+
public boolean isIgnoreOrder() {
35+
return ignoreOrder;
36+
}
37+
38+
public void setIgnoreOrder(boolean ignoreOrder) {
39+
this.ignoreOrder = ignoreOrder;
40+
}
41+
42+
public boolean isIgnoreOccurrences() {
43+
return ignoreOccurrences;
44+
}
45+
46+
public void setIgnoreOccurrences(boolean ignoreOccurrences) {
47+
this.ignoreOccurrences = ignoreOccurrences;
48+
}
49+
50+
@Override
51+
public boolean equals(Object obj) {
52+
return EqualsBuilder.reflectionEquals(this, obj);
53+
}
54+
55+
@Override
56+
public int hashCode() {
57+
return HashCodeBuilder.reflectionHashCode(this);
58+
}
59+
60+
@Override
61+
public String toString() {
62+
return ToStringBuilder.reflectionToString(this);
63+
}
64+
65+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package io.specto.hoverfly.junit.core.model;
2+
3+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
4+
5+
@JsonDeserialize(as = ArrayMatcherConfig.class)
6+
public interface MatcherConfig {
7+
}

src/main/java/io/specto/hoverfly/junit/core/model/RequestFieldMatcher.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,22 @@ public class RequestFieldMatcher<T> {
1515

1616
private MatcherType matcher;
1717
private T value;
18+
private MatcherConfig config;
1819

1920
public RequestFieldMatcher() {
2021
}
2122

22-
public RequestFieldMatcher(MatcherType matcher,
23-
T value) {
23+
public RequestFieldMatcher(MatcherType matcher, T value) {
2424
this.matcher = matcher;
2525
this.value = value;
2626
}
2727

28+
public RequestFieldMatcher(MatcherType matcher, T value, MatcherConfig config) {
29+
this.matcher = matcher;
30+
this.value = value;
31+
this.config = config;
32+
}
33+
2834
public MatcherType getMatcher() {
2935
return matcher;
3036
}
@@ -41,6 +47,14 @@ public void setValue(T value) {
4147
this.value = value;
4248
}
4349

50+
public MatcherConfig getConfig() {
51+
return config;
52+
}
53+
54+
public void setConfig(MatcherConfig config) {
55+
this.config = config;
56+
}
57+
4458
public static RequestFieldMatcher<String> newExactMatcher(String value) {
4559
return new RequestFieldMatcher<>(EXACT, value);
4660
}
@@ -57,6 +71,10 @@ public static RequestFieldMatcher<List<String>> newArrayMatcher(List<String> val
5771
return new RequestFieldMatcher<>(ARRAY, value);
5872
}
5973

74+
public static RequestFieldMatcher<List<String>> newArrayMatcher(List<String> value, ArrayMatcherConfig arrayMatcherConfig) {
75+
return new RequestFieldMatcher<>(ARRAY, value, arrayMatcherConfig);
76+
}
77+
6078
public static RequestFieldMatcher<String> newJwtMatcher(String value) {
6179
return new RequestFieldMatcher<>(JWT, value);
6280
}

src/test/java/io/specto/hoverfly/junit/core/model/SimulationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public void shouldNotIncludeNullGlobalActionsFieldWhenSerialize() throws Excepti
121121
private Simulation getSimulationWithV5_2Matchers() {
122122
Request.Builder requestBuilder = getTestRequestBuilder()
123123
// Array Matcher
124-
.query(ImmutableMap.of("key", singletonList(RequestFieldMatcher.newArrayMatcher(Arrays.asList("value1", "value2")))))
124+
.query(ImmutableMap.of("key", singletonList(RequestFieldMatcher.newArrayMatcher(Arrays.asList("value1", "value2"), new ArrayMatcherConfig(true, true, false)))))
125125
// JWT Matcher
126126
.headers(ImmutableMap.of("Authorization", singletonList(RequestFieldMatcher.newJwtMatcher("{\"header\":{\"alg\":\"HS256\"},\"payload\":{\"sub\":\"1234567890\",\"name\":\"John Doe\"}}"))))
127127
.requiresState(ImmutableMap.of("requiresStateKey", "requiresStateValue"));

src/test/resources/simulations/v5_2-simulation.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,12 @@
4545
"key": [
4646
{
4747
"matcher": "array",
48-
"value": ["value1", "value2"]
48+
"value": ["value1", "value2"],
49+
"config": {
50+
"ignoreUnknown": true,
51+
"ignoreOrder": true,
52+
"ignoreOccurrences": false
53+
}
4954
}
5055
]
5156
},

0 commit comments

Comments
 (0)