#235 #192 support multiple matchers for request body

Merged tommysitu
Coverage Reach
core/Hoverfly.java core/model/Request.java core/model/Response.java core/model/RequestFieldMatcher.java core/model/RequestDetails.java core/model/HoverflyMetaData.java core/model/Simulation.java core/model/JournalEntry.java core/model/DelaySettings.java core/model/Journal.java core/model/RequestResponsePair.java core/model/HoverflyData.java core/model/GlobalActions.java core/config/HoverflyConfiguration.java core/config/LocalHoverflyConfig.java core/config/HoverflyConfigValidator.java core/config/RemoteHoverflyConfig.java core/config/LogLevel.java core/config/LocalMiddleware.java core/SslConfigurer.java core/TempFileManager.java core/ProxyConfigurer.java core/SimulationSource.java core/SystemConfigFactory.java core/LoggingOutputStream.java core/HoverflyConfig.java core/HoverflyUtils.java core/SystemConfig.java core/HoverflyMode.java core/SystemInfo.java api/OkHttpHoverflyClient.java api/view/HoverflyInfoView.java api/view/ResponseDiffForRequestView.java api/view/DiffReport.java api/view/SimpleRequestDefinitionView.java api/view/StateView.java api/view/DiffReportEntry.java api/view/DiffView.java api/command/ModeCommand.java api/command/SortParams.java api/command/DestinationCommand.java api/command/JournalSearchCommand.java api/model/ModeArguments.java api/HoverflyClient.java api/AuthHeaderInterceptor.java api/HoverflyClientException.java dsl/StubServiceBuilder.java dsl/RequestMatcherBuilder.java dsl/matchers/HoverflyMatchers.java dsl/ResponseBuilder.java dsl/SingleQuoteHttpBodyConverter.java dsl/HttpBodyConverter.java dsl/ResponseCreators.java dsl/AbstractDelaySettingsBuilder.java dsl/StubServiceDelaySettingsBuilder.java dsl/ResponseDelaySettingsBuilder.java dsl/HoverflyDsl.java dsl/HoverflyDslException.java rule/HoverflyRule.java rule/NoDiffAssertionRule.java rule/HoverflyRuleUtils.java verification/HoverflyVerifications.java verification/VerificationUtils.java verification/VerificationData.java verification/HoverflyVerificationError.java

No flags found

Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.

e.g., #unittest #integration

#production #enterprise

#frontend #backend

Learn more about Codecov Flags here.


@@ -28,16 +28,17 @@
Loading
28 28
 */
29 29
public class RequestMatcherBuilder {
30 30
31 -
    private StubServiceBuilder invoker;
31 +
    private final StubServiceBuilder invoker;
32 32
    private final List<RequestFieldMatcher> method;
33 33
    private final List<RequestFieldMatcher> scheme;
34 34
    private final List<RequestFieldMatcher> destination;
35 35
    private final List<RequestFieldMatcher> path;
36 36
    private final Map<String, List<RequestFieldMatcher>> headers = new HashMap<>();
37 37
    private final Map<String, String> requiresState = new HashMap<>();
38 -
    private Map<String, List<RequestFieldMatcher>> query = new HashMap<>(); // default to match on empty query
39 -
    private List<RequestFieldMatcher> body = singletonList(newExactMatcher("")); // default to match on empty body
40 -
38 +
    private final Map<String, List<RequestFieldMatcher>> query = new HashMap<>(); // default to match on empty query
39 +
    private final List<RequestFieldMatcher> body = new ArrayList<>();
40 +
    private boolean isAnyBody = false;
41 +
    private boolean isAnyQuery = false;
41 42
42 43
    RequestMatcherBuilder(final StubServiceBuilder invoker,
43 44
                          final StubServiceBuilder.HttpMethod method,
@@ -57,7 +58,7 @@
Loading
57 58
     * @return the {@link RequestMatcherBuilder} for further customizations
58 59
     */
59 60
    public RequestMatcherBuilder body(final String body) {
60 -
        this.body = singletonList(newExactMatcher(body));
61 +
        this.body.add(newExactMatcher(body));
61 62
        return this;
62 63
    }
63 64
@@ -67,17 +68,17 @@
Loading
67 68
     * @return the {@link RequestMatcherBuilder} for further customizations
68 69
     */
69 70
    public RequestMatcherBuilder body(HttpBodyConverter httpBodyConverter) {
70 -
        this.body = singletonList(newExactMatcher(httpBodyConverter.body()));
71 +
        this.body.add(newExactMatcher(httpBodyConverter.body()));
71 72
        return this;
72 73
    }
73 74
74 75
    public RequestMatcherBuilder body(RequestFieldMatcher matcher) {
75 -
        this.body = singletonList(matcher);
76 +
        this.body.add(matcher);
76 77
        return this;
77 78
    }
78 79
79 80
    public RequestMatcherBuilder anyBody() {
80 -
        this.body = null;
81 +
        this.isAnyBody = true;
81 82
        return this;
82 83
    }
83 84
@@ -156,7 +157,7 @@
Loading
156 157
     * @return the {@link RequestMatcherBuilder} for further customizations
157 158
     */
158 159
    public RequestMatcherBuilder anyQueryParams() {
159 -
        query = null;
160 +
        this.isAnyQuery = true;
160 161
        return this;
161 162
    }
162 163
@@ -175,6 +176,12 @@
Loading
175 176
176 177
    public Request build() {
177 178
179 +
        if (body.isEmpty()) {
180 +
            body.add(newExactMatcher("")); // default to match on empty body
181 +
        }
182 +
183 +
        Map<String, List<RequestFieldMatcher>> query = isAnyQuery ? null : this.query;
184 +
        List<RequestFieldMatcher> body = isAnyBody ? null : this.body;
178 185
        return new Request(path, method, destination, scheme, query, null, body, headers, requiresState);
179 186
    }
180 187

Everything is accounted for!

No changes detected that need to be reviewed.
What changes does Codecov check for?
Lines, not adjusted in diff, that have changed coverage data.
Files that introduced coverage data that had none before.
Files that have missing coverage data that once were tracked.
Files Complexity Coverage
src/main/java/io/specto/hoverfly/junit +3.00% 83.74% 0.05% 85.26%
Project Totals (65 files) 83.74% 85.26%
Loading