Browse Source
Relocate `RestTestClientBuilderCustomizer` to `spring-boot-test` and break the direct link to web-server by making use of `spring.factories` and the new `BaseUrlProviders` class. See gh-46356pull/47381/head
125 changed files with 291 additions and 192 deletions
@ -0,0 +1,84 @@
@@ -0,0 +1,84 @@
|
||||
/* |
||||
* Copyright 2012-present the original author or authors. |
||||
* |
||||
* 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 |
||||
* |
||||
* https://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 org.springframework.boot.test.web.servlet.client; |
||||
|
||||
import java.net.URI; |
||||
import java.util.Map; |
||||
|
||||
import org.jspecify.annotations.Nullable; |
||||
|
||||
import org.springframework.boot.test.http.server.BaseUrl; |
||||
import org.springframework.util.Assert; |
||||
import org.springframework.web.util.DefaultUriBuilderFactory; |
||||
import org.springframework.web.util.UriBuilder; |
||||
import org.springframework.web.util.UriBuilderFactory; |
||||
import org.springframework.web.util.UriComponentsBuilder; |
||||
|
||||
/** |
||||
* {@link UriBuilderFactory} to support {@link BaseUrl}. |
||||
* |
||||
* @author Phillip Webb |
||||
* @since 4.0.0 |
||||
*/ |
||||
public class BaseUrlUriBuilderFactory implements UriBuilderFactory { |
||||
|
||||
private final UriBuilderFactory delegate; |
||||
|
||||
private final BaseUrl baseUrl; |
||||
|
||||
/** |
||||
* Create a new {@link BaseUrlUriBuilderFactory} instance. |
||||
* @param delegate the delegate {@link UriBuilderFactory} |
||||
* @param baseUrl the base URL to use |
||||
*/ |
||||
public BaseUrlUriBuilderFactory(UriBuilderFactory delegate, BaseUrl baseUrl) { |
||||
Assert.notNull(delegate, "'delegate' must not be null"); |
||||
Assert.notNull(baseUrl, "'baseUrl' must not be null"); |
||||
this.delegate = delegate; |
||||
this.baseUrl = baseUrl; |
||||
} |
||||
|
||||
@Override |
||||
public UriBuilder uriString(String uriTemplate) { |
||||
return UriComponentsBuilder.fromUriString(apply(uriTemplate)); |
||||
} |
||||
|
||||
@Override |
||||
public UriBuilder builder() { |
||||
return UriComponentsBuilder.newInstance(); |
||||
} |
||||
|
||||
@Override |
||||
public URI expand(String uriTemplate, Map<String, ?> uriVariables) { |
||||
return this.delegate.expand(apply(uriTemplate), uriVariables); |
||||
} |
||||
|
||||
@Override |
||||
public URI expand(String uriTemplate, @Nullable Object... uriVariables) { |
||||
return this.delegate.expand(apply(uriTemplate), uriVariables); |
||||
} |
||||
|
||||
String apply(String uriTemplate) { |
||||
return (uriTemplate.startsWith("/")) ? this.baseUrl.resolve(uriTemplate) : uriTemplate; |
||||
} |
||||
|
||||
public static UriBuilderFactory get(@Nullable BaseUrl baseUrl) { |
||||
DefaultUriBuilderFactory delegate = new DefaultUriBuilderFactory(); |
||||
return (baseUrl != null) ? new BaseUrlUriBuilderFactory(delegate, baseUrl) : delegate; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,24 @@
@@ -0,0 +1,24 @@
|
||||
/* |
||||
* Copyright 2012-present the original author or authors. |
||||
* |
||||
* 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 |
||||
* |
||||
* https://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. |
||||
*/ |
||||
|
||||
/** |
||||
* Spring Boot support for testing Spring Servlet server endpoints via |
||||
* {@link org.springframework.test.web.servlet.client.RestTestClient}. |
||||
*/ |
||||
@NullMarked |
||||
package org.springframework.boot.test.web.servlet.client; |
||||
|
||||
import org.jspecify.annotations.NullMarked; |
||||
2
module/spring-boot-web-server-test/src/test/java/org/springframework/boot/web/server/test/client/TestRestTemplateContextCustomizerIntegrationTests.java → integration-test/spring-boot-test-integration-tests/src/test/java/org/springframework/boot/restclient/test/TestRestTemplateContextCustomizerIntegrationTests.java
2
module/spring-boot-web-server-test/src/test/java/org/springframework/boot/web/server/test/client/TestRestTemplateContextCustomizerIntegrationTests.java → integration-test/spring-boot-test-integration-tests/src/test/java/org/springframework/boot/restclient/test/TestRestTemplateContextCustomizerIntegrationTests.java
4
module/spring-boot-web-server-test/src/test/java/org/springframework/boot/web/server/test/client/TestRestTemplateContextCustomizerWithFactoryBeanTests.java → integration-test/spring-boot-test-integration-tests/src/test/java/org/springframework/boot/restclient/test/TestRestTemplateContextCustomizerWithFactoryBeanTests.java
4
module/spring-boot-web-server-test/src/test/java/org/springframework/boot/web/server/test/client/TestRestTemplateContextCustomizerWithFactoryBeanTests.java → integration-test/spring-boot-test-integration-tests/src/test/java/org/springframework/boot/restclient/test/TestRestTemplateContextCustomizerWithFactoryBeanTests.java
2
module/spring-boot-web-server-test/src/test/java/org/springframework/boot/web/server/test/client/TestRestTemplateContextCustomizerWithOverrideIntegrationTests.java → integration-test/spring-boot-test-integration-tests/src/test/java/org/springframework/boot/restclient/test/TestRestTemplateContextCustomizerWithOverrideIntegrationTests.java
2
module/spring-boot-web-server-test/src/test/java/org/springframework/boot/web/server/test/client/TestRestTemplateContextCustomizerWithOverrideIntegrationTests.java → integration-test/spring-boot-test-integration-tests/src/test/java/org/springframework/boot/restclient/test/TestRestTemplateContextCustomizerWithOverrideIntegrationTests.java
6
module/spring-boot-web-server-test/src/test/java/org/springframework/boot/web/server/test/client/RestTestClientContextCustomizerIntegrationTests.java → integration-test/spring-boot-test-integration-tests/src/test/java/org/springframework/boot/test/web/servlet/client/RestTestClientContextCustomizerIntegrationTests.java
6
module/spring-boot-web-server-test/src/test/java/org/springframework/boot/web/server/test/client/RestTestClientContextCustomizerIntegrationTests.java → integration-test/spring-boot-test-integration-tests/src/test/java/org/springframework/boot/test/web/servlet/client/RestTestClientContextCustomizerIntegrationTests.java
6
module/spring-boot-web-server-test/src/test/java/org/springframework/boot/web/server/test/client/RestTestClientContextCustomizerWithCustomContextPathIntegrationTests.java → integration-test/spring-boot-test-integration-tests/src/test/java/org/springframework/boot/test/web/servlet/client/RestTestClientContextCustomizerWithCustomContextPathIntegrationTests.java
6
module/spring-boot-web-server-test/src/test/java/org/springframework/boot/web/server/test/client/RestTestClientContextCustomizerWithCustomContextPathIntegrationTests.java → integration-test/spring-boot-test-integration-tests/src/test/java/org/springframework/boot/test/web/servlet/client/RestTestClientContextCustomizerWithCustomContextPathIntegrationTests.java
6
module/spring-boot-web-server-test/src/test/java/org/springframework/boot/web/server/test/client/RestTestClientContextCustomizerWithOverridePathIntegrationTests.java → integration-test/spring-boot-test-integration-tests/src/test/java/org/springframework/boot/test/web/servlet/client/RestTestClientContextCustomizerWithOverridePathIntegrationTests.java
6
module/spring-boot-web-server-test/src/test/java/org/springframework/boot/web/server/test/client/RestTestClientContextCustomizerWithOverridePathIntegrationTests.java → integration-test/spring-boot-test-integration-tests/src/test/java/org/springframework/boot/test/web/servlet/client/RestTestClientContextCustomizerWithOverridePathIntegrationTests.java
2
module/spring-boot-web-server-test/src/test/java/org/springframework/boot/web/server/test/AbstractSpringBootTestEmbeddedReactiveWebEnvironmentTests.java → integration-test/spring-boot-test-integration-tests/src/test/java/org/springframework/boot/web/server/test/AbstractSpringBootTestEmbeddedReactiveWebEnvironmentTests.java
2
module/spring-boot-web-server-test/src/test/java/org/springframework/boot/web/server/test/AbstractSpringBootTestEmbeddedReactiveWebEnvironmentTests.java → integration-test/spring-boot-test-integration-tests/src/test/java/org/springframework/boot/web/server/test/AbstractSpringBootTestEmbeddedReactiveWebEnvironmentTests.java
2
module/spring-boot-web-server-test/src/test/java/org/springframework/boot/web/server/test/AbstractSpringBootTestWebServerWebEnvironmentTests.java → integration-test/spring-boot-test-integration-tests/src/test/java/org/springframework/boot/web/server/test/AbstractSpringBootTestWebServerWebEnvironmentTests.java
2
module/spring-boot-web-server-test/src/test/java/org/springframework/boot/web/server/test/AbstractSpringBootTestWebServerWebEnvironmentTests.java → integration-test/spring-boot-test-integration-tests/src/test/java/org/springframework/boot/web/server/test/AbstractSpringBootTestWebServerWebEnvironmentTests.java
0
module/spring-boot-web-server-test/src/test/java/org/springframework/boot/web/server/test/SpringBootTestRandomPortEnvironmentPostProcessorTests.java → integration-test/spring-boot-test-integration-tests/src/test/java/org/springframework/boot/web/server/test/SpringBootTestRandomPortEnvironmentPostProcessorTests.java
0
module/spring-boot-web-server-test/src/test/java/org/springframework/boot/web/server/test/SpringBootTestRandomPortEnvironmentPostProcessorTests.java → integration-test/spring-boot-test-integration-tests/src/test/java/org/springframework/boot/web/server/test/SpringBootTestRandomPortEnvironmentPostProcessorTests.java
0
module/spring-boot-web-server-test/src/test/java/org/springframework/boot/web/server/test/SpringBootTestReactiveWebEnvironmentDefinedPortTests.java → integration-test/spring-boot-test-integration-tests/src/test/java/org/springframework/boot/web/server/test/SpringBootTestReactiveWebEnvironmentDefinedPortTests.java
0
module/spring-boot-web-server-test/src/test/java/org/springframework/boot/web/server/test/SpringBootTestReactiveWebEnvironmentDefinedPortTests.java → integration-test/spring-boot-test-integration-tests/src/test/java/org/springframework/boot/web/server/test/SpringBootTestReactiveWebEnvironmentDefinedPortTests.java
0
module/spring-boot-web-server-test/src/test/java/org/springframework/boot/web/server/test/SpringBootTestReactiveWebEnvironmentRandomPortTests.java → integration-test/spring-boot-test-integration-tests/src/test/java/org/springframework/boot/web/server/test/SpringBootTestReactiveWebEnvironmentRandomPortTests.java
0
module/spring-boot-web-server-test/src/test/java/org/springframework/boot/web/server/test/SpringBootTestReactiveWebEnvironmentRandomPortTests.java → integration-test/spring-boot-test-integration-tests/src/test/java/org/springframework/boot/web/server/test/SpringBootTestReactiveWebEnvironmentRandomPortTests.java
0
module/spring-boot-web-server-test/src/test/java/org/springframework/boot/web/server/test/SpringBootTestReactiveWebEnvironmentUserDefinedTestRestTemplateTests.java → integration-test/spring-boot-test-integration-tests/src/test/java/org/springframework/boot/web/server/test/SpringBootTestReactiveWebEnvironmentUserDefinedTestRestTemplateTests.java
0
module/spring-boot-web-server-test/src/test/java/org/springframework/boot/web/server/test/SpringBootTestReactiveWebEnvironmentUserDefinedTestRestTemplateTests.java → integration-test/spring-boot-test-integration-tests/src/test/java/org/springframework/boot/web/server/test/SpringBootTestReactiveWebEnvironmentUserDefinedTestRestTemplateTests.java
0
module/spring-boot-web-server-test/src/test/java/org/springframework/boot/web/server/test/SpringBootTestUserDefinedTestRestTemplateTests.java → integration-test/spring-boot-test-integration-tests/src/test/java/org/springframework/boot/web/server/test/SpringBootTestUserDefinedTestRestTemplateTests.java
0
module/spring-boot-web-server-test/src/test/java/org/springframework/boot/web/server/test/SpringBootTestUserDefinedTestRestTemplateTests.java → integration-test/spring-boot-test-integration-tests/src/test/java/org/springframework/boot/web/server/test/SpringBootTestUserDefinedTestRestTemplateTests.java
0
module/spring-boot-web-server-test/src/test/java/org/springframework/boot/web/server/test/SpringBootTestWebEnvironmentContextHierarchyTests.java → integration-test/spring-boot-test-integration-tests/src/test/java/org/springframework/boot/web/server/test/SpringBootTestWebEnvironmentContextHierarchyTests.java
0
module/spring-boot-web-server-test/src/test/java/org/springframework/boot/web/server/test/SpringBootTestWebEnvironmentContextHierarchyTests.java → integration-test/spring-boot-test-integration-tests/src/test/java/org/springframework/boot/web/server/test/SpringBootTestWebEnvironmentContextHierarchyTests.java
0
module/spring-boot-web-server-test/src/test/java/org/springframework/boot/web/server/test/SpringBootTestWebEnvironmentDefinedPortTests.java → integration-test/spring-boot-test-integration-tests/src/test/java/org/springframework/boot/web/server/test/SpringBootTestWebEnvironmentDefinedPortTests.java
0
module/spring-boot-web-server-test/src/test/java/org/springframework/boot/web/server/test/SpringBootTestWebEnvironmentDefinedPortTests.java → integration-test/spring-boot-test-integration-tests/src/test/java/org/springframework/boot/web/server/test/SpringBootTestWebEnvironmentDefinedPortTests.java
0
module/spring-boot-web-server-test/src/test/java/org/springframework/boot/web/server/test/SpringBootTestWebEnvironmentRandomPortCustomPortTests.java → integration-test/spring-boot-test-integration-tests/src/test/java/org/springframework/boot/web/server/test/SpringBootTestWebEnvironmentRandomPortCustomPortTests.java
0
module/spring-boot-web-server-test/src/test/java/org/springframework/boot/web/server/test/SpringBootTestWebEnvironmentRandomPortCustomPortTests.java → integration-test/spring-boot-test-integration-tests/src/test/java/org/springframework/boot/web/server/test/SpringBootTestWebEnvironmentRandomPortCustomPortTests.java
@ -1,3 +1,7 @@
@@ -1,3 +1,7 @@
|
||||
# Spring Test Execution Listeners |
||||
org.springframework.test.context.TestExecutionListener=\ |
||||
org.springframework.boot.restclient.test.autoconfigure.MockRestServiceServerResetTestExecutionListener |
||||
|
||||
# Spring Test Context Customizer Factories |
||||
org.springframework.test.context.ContextCustomizerFactory=\ |
||||
org.springframework.boot.restclient.test.TestRestTemplateContextCustomizerFactory |
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue