com.stehno.ersatz.cfg.OptionsExpectations Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ersatz Show documentation
Show all versions of ersatz Show documentation
Mock server library for testing HTTP clients.
The newest version!
/**
* Copyright (C) 2019 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.stehno.ersatz.cfg;
import groovy.lang.Closure;
import groovy.lang.DelegatesTo;
import org.hamcrest.Matcher;
import space.jasan.support.groovy.closure.ConsumerWithDelegate;
import java.util.function.Consumer;
import static com.stehno.ersatz.match.ErsatzMatchers.pathMatcher;
import static groovy.lang.Closure.DELEGATE_FIRST;
/**
* Defines the available OPTIONS request expectations.
*/
public interface OptionsExpectations {
/**
* Allows configuration of a OPTIONS request expectation.
*
* @param path the expected request path.
* @return a Request
configuration object
*/
default Request OPTIONS(String path) {
return OPTIONS(pathMatcher(path));
}
/**
* Allows configuration of a OPTIONS request expectation.
*
* @param matcher the path matcher
* @return a Request
configuration object
*/
default Request OPTIONS(Matcher matcher) {
return OPTIONS(matcher, (Consumer) null);
}
/**
* Allows configuration of a OPTIONS request expectation using the Groovy DSL.
*
* @param path the expected request path
* @param closure the Groovy closure containing the configuration
* @return a Request
configuration object
*/
default Request OPTIONS(String path, @DelegatesTo(value = Request.class, strategy = DELEGATE_FIRST) Closure closure) {
return OPTIONS(pathMatcher(path), closure);
}
/**
* Allows configuration of a OPTIONS request expectation using the Groovy DSL.
*
* @param matcher the path matcher
* @param closure the Groovy closure containing the configuration
* @return a Request
configuration object
*/
default Request OPTIONS(Matcher matcher, @DelegatesTo(value = Request.class, strategy = DELEGATE_FIRST) Closure closure) {
return OPTIONS(matcher, ConsumerWithDelegate.create(closure));
}
/**
* Allows configuration of a OPTIONS request expectation using the provided Consumer<Request>
.
* The Consumer<Request>
will have an instance of Request
passed into it for configuration.
*
* @param path the expected request path
* @param config the configuration consumer
* @return a Request
configuration object
*/
default Request OPTIONS(String path, Consumer config) {
return OPTIONS(pathMatcher(path), config);
}
/**
* Allows configuration of a OPTIONS request expectation using the provided Consumer<Request>
. The
* Consumer<Request>
will have an instance of Request
passed into it for configuration.
*
* @param matcher the path matcher
* @param config the configuration consumer
* @return a Request
configuration object
*/
Request OPTIONS(Matcher matcher, Consumer config);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy