001/*
002 * Copyright 2002-2019 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 at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * 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 and
014 * limitations under the License.
015 */
016
017package org.springframework.test.web.reactive.server;
018
019import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
020
021/**
022 * Contract that frameworks or applications can use to pre-package a set of
023 * customizations to a {@link WebTestClient.MockServerSpec} and expose that
024 * as a shortcut.
025 *
026 * <p>An implementation of this interface can be plugged in via
027 * {@link WebTestClient.MockServerSpec#apply} where instances are likely obtained
028 * via static methods, e.g.:
029 *
030 * <pre class="code">
031 * import static org.example.ExampleSetup.securitySetup;
032 *
033 * // ...
034 *
035 * WebTestClient.bindToController(new TestController())
036 *     .apply(securitySetup("foo","bar"))
037 *     .build();
038 * </pre>
039 *
040 * @author Rossen Stoyanchev
041 * @since 5.0
042 * @see WebTestClientConfigurer
043 */
044public interface MockServerConfigurer {
045
046        /**
047         * Invoked immediately, i.e. before this method returns.
048         * @param serverSpec the serverSpec to which the configurer is added
049         */
050        default void afterConfigureAdded(WebTestClient.MockServerSpec<?> serverSpec) {
051        }
052
053        /**
054         * Invoked just before the mock server is built. Use this hook to inspect
055         * and/or modify application-declared filters and exception handlers.
056         * @param builder the builder for the {@code HttpHandler} that will handle
057         * requests (i.e. the mock server)
058         */
059        default void beforeServerCreated(WebHttpHandlerBuilder builder) {
060        }
061
062}