001/*002 * Copyright 2002-2018 the original author or authors.003 *004 * Licensed under the Apache License, Version 2.0 (the "License");005 * you may not use this file except in compliance with the License.006 * You may obtain a copy of the License at007 *008 * https://www.apache.org/licenses/LICENSE-2.0009 *010 * Unless required by applicable law or agreed to in writing, software011 * distributed under the License is distributed on an "AS IS" BASIS,012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.013 * See the License for the specific language governing permissions and014 * limitations under the License.015 */016017package org.springframework.test.web.client;018019import java.io.IOException;020021import org.springframework.http.client.ClientHttpRequest;022import org.springframework.http.client.ClientHttpResponse;023024/**025 * Encapsulates the behavior required to implement {@link MockRestServiceServer}026 * including its public API (create expectations + verify/reset) along with an027 * extra method for verifying actual requests.028 *029 * <p>This contract is not used directly in applications but a custom030 * implementation can be031 * {@link org.springframework.test.web.client.MockRestServiceServer.MockRestServiceServerBuilder#build(RequestExpectationManager)032 * plugged} in through the {@code MockRestServiceServer} builder.033 *034 * @author Rossen Stoyanchev035 * @since 4.3036 */037public interface RequestExpectationManager {038039 /**040 * Set up a new request expectation. The returned {@link ResponseActions} is041 * used to add more expectations and define a response.042 * <p>This is a delegate for043 * {@link MockRestServiceServer#expect(ExpectedCount, RequestMatcher)}.044 *045 * @param requestMatcher a request expectation046 * @return for setting up further expectations and define a response047 * @see MockRestServiceServer#expect(RequestMatcher)048 * @see MockRestServiceServer#expect(ExpectedCount, RequestMatcher)049 */050 ResponseActions expectRequest(ExpectedCount count, RequestMatcher requestMatcher);051052 /**053 * Verify that all expectations have been met.054 * <p>This is a delegate for {@link MockRestServiceServer#verify()}.055 * @throws AssertionError when some expectations were not met056 * @see MockRestServiceServer#verify()057 */058 void verify();059060 /**061 * Reset the internal state removing all expectations and recorded requests.062 * <p>This is a delegate for {@link MockRestServiceServer#reset()}.063 * @see MockRestServiceServer#reset()064 */065 void reset();066067068 /**069 * Validate the given actual request against the declared expectations.070 * Is successful return the mock response to use or raise an error.071 * <p>This is used in {@link MockRestServiceServer} against actual requests.072 * @param request the request073 * @return the response to return if the request was validate