Skip to content

Commit 9658661

Browse files
committed
Merge branch '2.7.x'
2 parents 21ccd58 + 7789a18 commit 9658661

File tree

8 files changed

+186
-4
lines changed

8 files changed

+186
-4
lines changed

spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootTestContextBootstrapper.java

Lines changed: 6 additions & 2 deletions
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-2022 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.
@@ -290,9 +290,13 @@ protected void processPropertySourceProperties(MergedContextConfiguration merged
290290
// precedence
291291
propertySourceProperties.addAll(0, Arrays.asList(properties));
292292
}
293-
if (getWebEnvironment(testClass) == WebEnvironment.RANDOM_PORT) {
293+
WebEnvironment webEnvironment = getWebEnvironment(testClass);
294+
if (webEnvironment == WebEnvironment.RANDOM_PORT) {
294295
propertySourceProperties.add("server.port=0");
295296
}
297+
else if (webEnvironment == WebEnvironment.NONE) {
298+
propertySourceProperties.add("spring.main.web-application-type=none");
299+
}
296300
}
297301

298302
/**

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-profile/src/test/java/smoketest/profile/ActiveProfilesTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@
3333
*
3434
* @author Madhura Bhave
3535
*/
36-
@SpringBootTest(webEnvironment = WebEnvironment.NONE,
37-
properties = { "enableEnvironmentPostProcessor=true", "server.port=0" }) // gh-28530
36+
@SpringBootTest(webEnvironment = WebEnvironment.NONE, properties = { "enableEnvironmentPostProcessor=true" }) // gh-28530
3837
@ActiveProfiles("hello")
3938
class ActiveProfilesTests {
4039

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
plugins {
2+
id "java"
3+
id "org.springframework.boot.conventions"
4+
}
5+
6+
description = "Spring Boot web application type smoke test"
7+
8+
dependencies {
9+
implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-web"))
10+
implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-webflux"))
11+
12+
testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test"))
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2012-2022 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 smoketest.webapplicationtype;
18+
19+
import org.springframework.boot.SpringApplication;
20+
import org.springframework.boot.autoconfigure.SpringBootApplication;
21+
22+
@SpringBootApplication
23+
public class SampleWebApplicationTypeApplication {
24+
25+
public static void main(String[] args) {
26+
SpringApplication.run(SampleWebApplicationTypeApplication.class, args);
27+
}
28+
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
spring.main.web-application-type=reactive
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright 2012-2022 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 smoketest.webapplicationtype;
18+
19+
import org.junit.jupiter.api.Test;
20+
21+
import org.springframework.beans.factory.annotation.Autowired;
22+
import org.springframework.boot.test.context.SpringBootTest;
23+
import org.springframework.context.ApplicationContext;
24+
import org.springframework.web.context.WebApplicationContext;
25+
26+
import static org.assertj.core.api.Assertions.assertThat;
27+
28+
/**
29+
* Integration tests for an application using an overridden web application type
30+
*
31+
* @author Andy Wilkinson
32+
*/
33+
@SpringBootTest(properties = "spring.main.web-application-type=servlet")
34+
class OverriddenWebApplicationTypeApplicationTests {
35+
36+
@Autowired
37+
private ApplicationContext context;
38+
39+
@Test
40+
void contextIsServlet() {
41+
assertThat(this.context).isInstanceOf(WebApplicationContext.class);
42+
}
43+
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright 2012-2022 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 smoketest.webapplicationtype;
18+
19+
import org.junit.jupiter.api.Test;
20+
21+
import org.springframework.beans.factory.annotation.Autowired;
22+
import org.springframework.boot.test.context.SpringBootTest;
23+
import org.springframework.boot.web.reactive.context.ReactiveWebApplicationContext;
24+
import org.springframework.context.ApplicationContext;
25+
26+
import static org.assertj.core.api.Assertions.assertThat;
27+
28+
/**
29+
* Integration tests for an application using a configured web application type
30+
*
31+
* @author Andy Wilkinson
32+
*/
33+
@SpringBootTest
34+
class SampleWebApplicationTypeApplicationTests {
35+
36+
@Autowired
37+
private ApplicationContext context;
38+
39+
@Test
40+
void contextIsReactive() {
41+
assertThat(this.context).isInstanceOf(ReactiveWebApplicationContext.class);
42+
}
43+
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright 2012-2022 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 smoketest.webapplicationtype;
18+
19+
import org.junit.jupiter.api.Test;
20+
21+
import org.springframework.beans.factory.annotation.Autowired;
22+
import org.springframework.boot.test.context.SpringBootTest;
23+
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
24+
import org.springframework.boot.web.reactive.context.ReactiveWebApplicationContext;
25+
import org.springframework.context.ApplicationContext;
26+
import org.springframework.web.context.WebApplicationContext;
27+
28+
import static org.assertj.core.api.Assertions.assertThat;
29+
30+
/**
31+
* Integration tests for a web environment of none overriding the configured web
32+
* application type.
33+
*
34+
* @author Andy Wilkinson
35+
*/
36+
@SpringBootTest(webEnvironment = WebEnvironment.NONE)
37+
class WebEnvironmentNoneOverridesWebApplicationTypeTests {
38+
39+
@Autowired
40+
private ApplicationContext context;
41+
42+
@Test
43+
void contextIsPlain() {
44+
assertThat(this.context).isNotInstanceOf(ReactiveWebApplicationContext.class);
45+
assertThat(this.context).isNotInstanceOf(WebApplicationContext.class);
46+
}
47+
48+
}

0 commit comments

Comments
 (0)