Skip to content

Commit 9b15b4b

Browse files
committedMar 12, 2025
Consolidate mock web server factories
Closes gh-44674
1 parent 3a6e4e9 commit 9b15b4b

File tree

24 files changed

+210
-408
lines changed

24 files changed

+210
-408
lines changed
 

‎buildSrc/src/main/java/org/springframework/boot/build/ConventionsPlugin.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2024 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -50,6 +50,7 @@ public void apply(Project project) {
5050
new KotlinConventions().apply(project);
5151
new WarConventions().apply(project);
5252
new EclipseConventions().apply(project);
53+
new TestFixturesConventions().apply(project);
5354
RepositoryTransformersExtension.apply(project);
5455
}
5556

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright 2012-2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.build;
18+
19+
import org.gradle.api.Project;
20+
import org.gradle.api.artifacts.ConfigurationContainer;
21+
import org.gradle.api.component.AdhocComponentWithVariants;
22+
import org.gradle.api.plugins.JavaTestFixturesPlugin;
23+
24+
/**
25+
* Conventions that are applied in the presence of the {@link JavaTestFixturesPlugin}.
26+
* When the plugin is applied:
27+
*
28+
* <ul>
29+
* <li>Publishing of the test fixtures is disabled.
30+
* </ul>
31+
*
32+
* @author Andy Wilkinson
33+
*/
34+
class TestFixturesConventions {
35+
36+
void apply(Project project) {
37+
project.getPlugins().withType(JavaTestFixturesPlugin.class, (testFixtures) -> disablePublishing(project));
38+
}
39+
40+
private void disablePublishing(Project project) {
41+
ConfigurationContainer configurations = project.getConfigurations();
42+
AdhocComponentWithVariants javaComponent = (AdhocComponentWithVariants) project.getComponents()
43+
.getByName("java");
44+
javaComponent.withVariantsFromConfiguration(configurations.getByName("testFixturesApiElements"),
45+
(variant) -> variant.skip());
46+
javaComponent.withVariantsFromConfiguration(configurations.getByName("testFixturesRuntimeElements"),
47+
(variant) -> variant.skip());
48+
}
49+
50+
}

‎spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ dependencies {
135135

136136
testImplementation(project(":spring-boot-project:spring-boot-test"))
137137
testImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support"))
138+
testImplementation(testFixtures(project(":spring-boot-project:spring-boot")))
138139
testImplementation("io.micrometer:micrometer-observation-test")
139140
testImplementation("io.projectreactor:reactor-test")
140141
testImplementation("io.prometheus:prometheus-metrics-exposition-formats")

‎spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/servlet/MockServletWebServerFactory.java

-79
This file was deleted.

‎spring-boot-project/spring-boot-autoconfigure/build.gradle

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ dependencies {
2424

2525
dockerTestImplementation(project(":spring-boot-project:spring-boot-test"))
2626
dockerTestImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support-docker"))
27+
dockerTestImplementation(testFixtures(project(":spring-boot-project:spring-boot")))
2728
dockerTestImplementation("org.assertj:assertj-core")
2829
dockerTestImplementation("org.junit.jupiter:junit-jupiter")
2930
dockerTestImplementation("org.mockito:mockito-core")
@@ -230,6 +231,7 @@ dependencies {
230231

231232
testImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support"))
232233
testImplementation(project(":spring-boot-project:spring-boot-test"))
234+
testImplementation(testFixtures(project(":spring-boot-project:spring-boot")))
233235
testImplementation("ch.qos.logback:logback-classic")
234236
testImplementation("commons-fileupload:commons-fileupload")
235237
testImplementation("com.github.h-thurow:simple-jndi")

‎spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnNotWebApplicationTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,10 +19,10 @@
1919
import org.junit.jupiter.api.Test;
2020
import reactor.core.publisher.Mono;
2121

22-
import org.springframework.boot.autoconfigure.web.reactive.MockReactiveWebServerFactory;
2322
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
2423
import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner;
2524
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
25+
import org.springframework.boot.web.reactive.server.MockReactiveWebServerFactory;
2626
import org.springframework.boot.web.reactive.server.ReactiveWebServerFactory;
2727
import org.springframework.context.annotation.Bean;
2828
import org.springframework.context.annotation.Configuration;

‎spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnWebApplicationTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,8 +21,8 @@
2121
import reactor.core.publisher.Mono;
2222

2323
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
24-
import org.springframework.boot.autoconfigure.web.reactive.MockReactiveWebServerFactory;
2524
import org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebApplicationContext;
25+
import org.springframework.boot.web.reactive.server.MockReactiveWebServerFactory;
2626
import org.springframework.boot.web.reactive.server.ReactiveWebServerFactory;
2727
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext;
2828
import org.springframework.context.ConfigurableApplicationContext;

‎spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/AbstractSessionAutoConfigurationTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,11 +19,11 @@
1919
import java.util.Collections;
2020
import java.util.function.Consumer;
2121

22-
import org.springframework.boot.autoconfigure.web.reactive.MockReactiveWebServerFactory;
2322
import org.springframework.boot.test.context.assertj.AssertableReactiveWebApplicationContext;
2423
import org.springframework.boot.test.context.assertj.AssertableWebApplicationContext;
2524
import org.springframework.boot.test.context.runner.ContextConsumer;
2625
import org.springframework.boot.web.reactive.context.ReactiveWebApplicationContext;
26+
import org.springframework.boot.web.reactive.server.MockReactiveWebServerFactory;
2727
import org.springframework.context.annotation.Bean;
2828
import org.springframework.context.annotation.Configuration;
2929
import org.springframework.mock.http.server.reactive.MockServerHttpRequest;

‎spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/MockReactiveWebServerFactory.java

-90
This file was deleted.

‎spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/ReactiveWebServerFactoryAutoConfigurationTests.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -45,6 +45,7 @@
4545
import org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebApplicationContext;
4646
import org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext;
4747
import org.springframework.boot.web.reactive.server.ConfigurableReactiveWebServerFactory;
48+
import org.springframework.boot.web.reactive.server.MockReactiveWebServerFactory;
4849
import org.springframework.boot.web.reactive.server.ReactiveWebServerFactory;
4950
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
5051
import org.springframework.context.ApplicationContextException;

‎spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfigurationTests.java

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
import org.springframework.boot.web.codec.CodecCustomizer;
6262
import org.springframework.boot.web.reactive.context.ReactiveWebApplicationContext;
6363
import org.springframework.boot.web.reactive.filter.OrderedHiddenHttpMethodFilter;
64+
import org.springframework.boot.web.reactive.server.MockReactiveWebServerFactory;
6465
import org.springframework.context.ApplicationContext;
6566
import org.springframework.context.annotation.Bean;
6667
import org.springframework.context.annotation.Configuration;

‎spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/FilterOrderingIntegrationTests.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,11 +28,12 @@
2828
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
2929
import org.springframework.boot.autoconfigure.session.SessionAutoConfiguration;
3030
import org.springframework.boot.test.util.TestPropertyValues;
31-
import org.springframework.boot.testsupport.web.servlet.MockServletWebServer.RegisteredFilter;
3231
import org.springframework.boot.web.server.WebServerFactoryCustomizerBeanPostProcessor;
3332
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext;
3433
import org.springframework.boot.web.servlet.filter.OrderedCharacterEncodingFilter;
3534
import org.springframework.boot.web.servlet.filter.OrderedRequestContextFilter;
35+
import org.springframework.boot.web.servlet.server.MockServletWebServer.RegisteredFilter;
36+
import org.springframework.boot.web.servlet.server.MockServletWebServerFactory;
3637
import org.springframework.context.annotation.Bean;
3738
import org.springframework.context.annotation.Configuration;
3839
import org.springframework.data.redis.connection.RedisConnection;

‎spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/HttpEncodingAutoConfigurationTests.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -33,6 +33,7 @@
3333
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext;
3434
import org.springframework.boot.web.servlet.filter.OrderedFormContentFilter;
3535
import org.springframework.boot.web.servlet.filter.OrderedHiddenHttpMethodFilter;
36+
import org.springframework.boot.web.servlet.server.MockServletWebServerFactory;
3637
import org.springframework.context.annotation.Bean;
3738
import org.springframework.context.annotation.Configuration;
3839
import org.springframework.core.annotation.AnnotationAwareOrderComparator;

0 commit comments

Comments
 (0)
Failed to load comments.