37
37
import org .springframework .test .web .servlet .MockMvc ;
38
38
import org .springframework .test .web .servlet .MockMvcBuilder ;
39
39
import org .springframework .test .web .servlet .setup .DefaultMockMvcBuilder ;
40
- import org .springframework .test .web .servlet .setup .MockMvcBuilders ;
41
40
import org .springframework .test .web .servlet .setup .RouterFunctionMockMvcBuilder ;
42
41
import org .springframework .test .web .servlet .setup .StandaloneMockMvcBuilder ;
43
42
import org .springframework .util .MultiValueMap ;
51
50
* Client for testing web servers.
52
51
*
53
52
* @author Rob Worsnop
53
+ * @author Rossen Stoyanchev
54
+ * @since 7.0
54
55
*/
55
56
public interface RestTestClient {
56
57
@@ -126,9 +127,8 @@ public interface RestTestClient {
126
127
* {@link org.springframework.test.web.servlet.setup.MockMvcBuilders#standaloneSetup(Object...)}
127
128
* to initialize {@link MockMvc}.
128
129
*/
129
- static MockServerBuilder <StandaloneMockMvcBuilder > standaloneSetup (Object ... controllers ) {
130
- StandaloneMockMvcBuilder builder = MockMvcBuilders .standaloneSetup (controllers );
131
- return new DefaultMockServerBuilder <>(builder );
130
+ static StandaloneSetupBuilder bindToController (Object ... controllers ) {
131
+ return new DefaultRestTestClientBuilder .DefaultStandaloneSetupBuilder (controllers );
132
132
}
133
133
134
134
/**
@@ -138,9 +138,8 @@ static MockServerBuilder<StandaloneMockMvcBuilder> standaloneSetup(Object... con
138
138
* {@link org.springframework.test.web.servlet.setup.MockMvcBuilders#routerFunctions(RouterFunction[])}
139
139
* to initialize {@link MockMvc}.
140
140
*/
141
- static MockServerBuilder <RouterFunctionMockMvcBuilder > bindToRouterFunction (RouterFunction <?>... routerFunctions ) {
142
- RouterFunctionMockMvcBuilder builder = MockMvcBuilders .routerFunctions (routerFunctions );
143
- return new DefaultMockServerBuilder <>(builder );
141
+ static RouterFunctionSetupBuilder bindToRouterFunction (RouterFunction <?>... routerFunctions ) {
142
+ return new DefaultRestTestClientBuilder .DefaultRouterFunctionSetupBuilder (routerFunctions );
144
143
}
145
144
146
145
/**
@@ -151,16 +150,15 @@ static MockServerBuilder<RouterFunctionMockMvcBuilder> bindToRouterFunction(Rout
151
150
* {@link org.springframework.test.web.servlet.setup.MockMvcBuilders#webAppContextSetup(WebApplicationContext)}
152
151
* to initialize {@code MockMvc}.
153
152
*/
154
- static MockServerBuilder <DefaultMockMvcBuilder > bindToApplicationContext (WebApplicationContext context ) {
155
- DefaultMockMvcBuilder builder = MockMvcBuilders .webAppContextSetup (context );
156
- return new DefaultMockServerBuilder <>(builder );
153
+ static WebAppContextSetupBuilder bindToApplicationContext (WebApplicationContext context ) {
154
+ return new DefaultRestTestClientBuilder .DefaultWebAppContextSetupBuilder (context );
157
155
}
158
156
159
157
/**
160
158
* Begin creating a {@link RestTestClient} by providing an already
161
159
* initialized {@link MockMvc} instance to use as the server.
162
160
*/
163
- static < B extends Builder <B >> Builder < B > bindTo (MockMvc mockMvc ) {
161
+ static Builder <? > bindTo (MockMvc mockMvc ) {
164
162
ClientHttpRequestFactory requestFactory = new MockMvcClientHttpRequestFactory (mockMvc );
165
163
return RestTestClient .bindToServer (requestFactory );
166
164
}
@@ -175,15 +173,15 @@ static <B extends Builder<B>> Builder<B> bindTo(MockMvc mockMvc) {
175
173
* </pre>
176
174
* @return chained API to customize client config
177
175
*/
178
- static < B extends Builder <B >> Builder < B > bindToServer () {
176
+ static Builder <? > bindToServer () {
179
177
return new DefaultRestTestClientBuilder <>();
180
178
}
181
179
182
180
/**
183
181
* A variant of {@link #bindToServer()} with a pre-configured request factory.
184
182
* @return chained API to customize client config
185
183
*/
186
- static < B extends Builder <B >> Builder < B > bindToServer (ClientHttpRequestFactory requestFactory ) {
184
+ static Builder <? > bindToServer (ClientHttpRequestFactory requestFactory ) {
187
185
return new DefaultRestTestClientBuilder <>(RestClient .builder ().requestFactory (requestFactory ));
188
186
}
189
187
@@ -195,20 +193,20 @@ interface Builder<B extends Builder<B>> {
195
193
* {@link RestClient#create(String)
196
194
* WebClient.create(String)}.
197
195
*/
198
- Builder < B > baseUrl (String baseUrl );
196
+ < T extends B > T baseUrl (String baseUrl );
199
197
200
198
/**
201
199
* Provide a pre-configured {@link UriBuilderFactory} instance as an
202
200
* alternative to and effectively overriding {@link #baseUrl(String)}.
203
201
*/
204
- Builder < B > uriBuilderFactory (UriBuilderFactory uriBuilderFactory );
202
+ < T extends B > T uriBuilderFactory (UriBuilderFactory uriBuilderFactory );
205
203
206
204
/**
207
205
* Add the given header to all requests that haven't added it.
208
206
* @param headerName the header name
209
207
* @param headerValues the header values
210
208
*/
211
- Builder < B > defaultHeader (String headerName , String ... headerValues );
209
+ < T extends B > T defaultHeader (String headerName , String ... headerValues );
212
210
213
211
/**
214
212
* Manipulate the default headers with the given consumer. The
@@ -219,14 +217,14 @@ interface Builder<B extends Builder<B>> {
219
217
* @param headersConsumer a function that consumes the {@code HttpHeaders}
220
218
* @return this builder
221
219
*/
222
- Builder < B > defaultHeaders (Consumer <HttpHeaders > headersConsumer );
220
+ < T extends B > T defaultHeaders (Consumer <HttpHeaders > headersConsumer );
223
221
224
222
/**
225
223
* Add the given cookie to all requests.
226
224
* @param cookieName the cookie name
227
225
* @param cookieValues the cookie values
228
226
*/
229
- Builder < B > defaultCookie (String cookieName , String ... cookieValues );
227
+ < T extends B > T defaultCookie (String cookieName , String ... cookieValues );
230
228
231
229
/**
232
230
* Manipulate the default cookies with the given consumer. The
@@ -237,29 +235,41 @@ interface Builder<B extends Builder<B>> {
237
235
* @param cookiesConsumer a function that consumes the cookies map
238
236
* @return this builder
239
237
*/
240
- Builder < B > defaultCookies (Consumer <MultiValueMap <String , String >> cookiesConsumer );
238
+ < T extends B > T defaultCookies (Consumer <MultiValueMap <String , String >> cookiesConsumer );
241
239
242
240
/**
243
241
* Apply the given {@code Consumer} to this builder instance.
244
242
* <p>This can be useful for applying pre-packaged customizations.
245
243
* @param builderConsumer the consumer to apply
246
244
*/
247
- Builder < B > apply (Consumer <Builder <B >> builderConsumer );
245
+ < T extends B > T apply (Consumer <Builder <B >> builderConsumer );
248
246
249
247
/**
250
248
* Build the {@link RestTestClient} instance.
251
249
*/
252
250
RestTestClient build ();
251
+ }
252
+
253
+
254
+ interface MockMvcSetupBuilder <B extends Builder <B >, M extends MockMvcBuilder > extends Builder <B > {
255
+
256
+ <T extends B > T configureServer (Consumer <M > consumer );
257
+ }
258
+
259
+
260
+ interface StandaloneSetupBuilder extends MockMvcSetupBuilder <StandaloneSetupBuilder , StandaloneMockMvcBuilder > {
253
261
}
254
262
255
263
256
- interface MockServerBuilder <M extends MockMvcBuilder > extends Builder <MockServerBuilder <M >> {
264
+ interface RouterFunctionSetupBuilder extends MockMvcSetupBuilder <RouterFunctionSetupBuilder , RouterFunctionMockMvcBuilder > {
265
+ }
257
266
258
- MockServerBuilder <M > configureServer (Consumer <M > consumer );
259
267
268
+ interface WebAppContextSetupBuilder extends MockMvcSetupBuilder <WebAppContextSetupBuilder , DefaultMockMvcBuilder > {
260
269
}
261
270
262
271
272
+
263
273
/**
264
274
* Specification for providing the URI of a request.
265
275
*
0 commit comments