Skip to content

Commit d8fa71b

Browse files
isopovsnicoll
authored andcommitted
Samples cleanup
- Modifying dependencies to starter-web with tomcat exclusion plus alternative servlet container instead of manual dependency on spring-webmvc as it is the preferrable way to use alternative servlet container - Previously RestTemplate with ssl was configured manually in tests - now it rellies on autoconfiguration - changed this for multi-connector test and added test to ensure that ssl autoconfiguration is working - Most samples with alterntative servlet containers used some kind of service reading property and returning default since it wasn't configured - removed it, since it is not specific to using alternative servlet containers. See spring-projectsgh-10548
1 parent 792de8f commit d8fa71b

File tree

63 files changed

+91
-377
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+91
-377
lines changed

spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/CorsSampleActuatorApplicationTests.java

-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import org.springframework.http.RequestEntity;
1717
import org.springframework.http.ResponseEntity;
1818
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
19-
import org.springframework.test.annotation.DirtiesContext;
2019
import org.springframework.test.context.ActiveProfiles;
2120
import org.springframework.test.context.junit4.SpringRunner;
2221
import org.springframework.web.client.RestTemplate;
@@ -30,7 +29,6 @@
3029
*/
3130
@RunWith(SpringRunner.class)
3231
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
33-
@DirtiesContext
3432
@ActiveProfiles("cors")
3533
public class CorsSampleActuatorApplicationTests {
3634

spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/InsecureManagementPortAndPathSampleActuatorApplicationTests.java

-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.springframework.boot.web.server.LocalServerPort;
2727
import org.springframework.http.HttpStatus;
2828
import org.springframework.http.ResponseEntity;
29-
import org.springframework.test.annotation.DirtiesContext;
3029
import org.springframework.test.context.junit4.SpringRunner;
3130

3231
import static org.assertj.core.api.Assertions.assertThat;
@@ -40,7 +39,6 @@
4039
@RunWith(SpringRunner.class)
4140
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
4241
"management.server.port=0", "management.server.context-path=/management" })
43-
@DirtiesContext
4442
public class InsecureManagementPortAndPathSampleActuatorApplicationTests {
4543

4644
@LocalServerPort

spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/SampleActuatorCustomSecurityApplicationTests.java

-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import org.springframework.boot.test.web.client.TestRestTemplate;
1111
import org.springframework.http.HttpStatus;
1212
import org.springframework.http.ResponseEntity;
13-
import org.springframework.test.annotation.DirtiesContext;
1413
import org.springframework.test.context.junit4.SpringRunner;
1514

1615
import static org.assertj.core.api.Assertions.assertThat;
@@ -20,7 +19,6 @@
2019
*/
2120
@RunWith(SpringRunner.class)
2221
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
23-
@DirtiesContext
2422
public class SampleActuatorCustomSecurityApplicationTests {
2523

2624
@Autowired

spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationPortTests.java

-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.springframework.boot.web.server.LocalServerPort;
2929
import org.springframework.http.HttpStatus;
3030
import org.springframework.http.ResponseEntity;
31-
import org.springframework.test.annotation.DirtiesContext;
3231
import org.springframework.test.context.junit4.SpringRunner;
3332

3433
import static org.assertj.core.api.Assertions.assertThat;
@@ -41,7 +40,6 @@
4140
@RunWith(SpringRunner.class)
4241
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
4342
"management.server.port:0" })
44-
@DirtiesContext
4543
public class SampleActuatorUiApplicationPortTests {
4644

4745
@LocalServerPort

spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationTests.java

-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import org.springframework.http.HttpStatus;
3333
import org.springframework.http.MediaType;
3434
import org.springframework.http.ResponseEntity;
35-
import org.springframework.test.annotation.DirtiesContext;
3635
import org.springframework.test.context.junit4.SpringRunner;
3736

3837
import static org.assertj.core.api.Assertions.assertThat;
@@ -44,7 +43,6 @@
4443
*/
4544
@RunWith(SpringRunner.class)
4645
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
47-
@DirtiesContext
4846
public class SampleActuatorUiApplicationTests {
4947

5048
@Autowired

spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/EndpointsPropertiesSampleActuatorApplicationTests.java

-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.springframework.boot.test.web.client.TestRestTemplate;
2828
import org.springframework.http.HttpStatus;
2929
import org.springframework.http.ResponseEntity;
30-
import org.springframework.test.annotation.DirtiesContext;
3130
import org.springframework.test.context.ActiveProfiles;
3231
import org.springframework.test.context.junit4.SpringRunner;
3332

@@ -40,7 +39,6 @@
4039
*/
4140
@RunWith(SpringRunner.class)
4241
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
43-
@DirtiesContext
4442
@ActiveProfiles("endpoints")
4543
public class EndpointsPropertiesSampleActuatorApplicationTests {
4644

spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementAddressActuatorApplicationTests.java

-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.springframework.boot.web.server.LocalServerPort;
2929
import org.springframework.http.HttpStatus;
3030
import org.springframework.http.ResponseEntity;
31-
import org.springframework.test.annotation.DirtiesContext;
3231
import org.springframework.test.context.junit4.SpringRunner;
3332

3433
import static org.assertj.core.api.Assertions.assertThat;
@@ -42,7 +41,6 @@
4241
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
4342
"management.server.port=0", "management.server.address=127.0.0.1",
4443
"management.server.context-path:/admin" })
45-
@DirtiesContext
4644
public class ManagementAddressActuatorApplicationTests {
4745

4846
@LocalServerPort

spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPathSampleActuatorApplicationTests.java

-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.springframework.boot.test.web.client.TestRestTemplate;
2828
import org.springframework.http.HttpStatus;
2929
import org.springframework.http.ResponseEntity;
30-
import org.springframework.test.annotation.DirtiesContext;
3130
import org.springframework.test.context.junit4.SpringRunner;
3231

3332
import static org.assertj.core.api.Assertions.assertThat;
@@ -40,7 +39,6 @@
4039
@RunWith(SpringRunner.class)
4140
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
4241
"management.endpoints.web.base-path=/admin" })
43-
@DirtiesContext
4442
public class ManagementPathSampleActuatorApplicationTests {
4543

4644
@Autowired

spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortAndPathSampleActuatorApplicationTests.java

-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.springframework.boot.web.server.LocalServerPort;
2929
import org.springframework.http.HttpStatus;
3030
import org.springframework.http.ResponseEntity;
31-
import org.springframework.test.annotation.DirtiesContext;
3231
import org.springframework.test.context.junit4.SpringRunner;
3332

3433
import static org.assertj.core.api.Assertions.assertThat;
@@ -41,7 +40,6 @@
4140
@RunWith(SpringRunner.class)
4241
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
4342
"management.server.port=0", "management.endpoints.web.base-path=/admin" })
44-
@DirtiesContext
4543
public class ManagementPortAndPathSampleActuatorApplicationTests {
4644

4745
@LocalServerPort

spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortSampleActuatorApplicationTests.java

-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.springframework.boot.web.server.LocalServerPort;
2929
import org.springframework.http.HttpStatus;
3030
import org.springframework.http.ResponseEntity;
31-
import org.springframework.test.annotation.DirtiesContext;
3231
import org.springframework.test.context.junit4.SpringRunner;
3332

3433
import static org.assertj.core.api.Assertions.assertThat;
@@ -41,7 +40,6 @@
4140
@RunWith(SpringRunner.class)
4241
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
4342
"management.server.port=0" })
44-
@DirtiesContext
4543
public class ManagementPortSampleActuatorApplicationTests {
4644

4745
@LocalServerPort

spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/NoManagementSampleActuatorApplicationTests.java

-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.springframework.boot.test.web.client.TestRestTemplate;
2828
import org.springframework.http.HttpStatus;
2929
import org.springframework.http.ResponseEntity;
30-
import org.springframework.test.annotation.DirtiesContext;
3130
import org.springframework.test.context.junit4.SpringRunner;
3231

3332
import static org.assertj.core.api.Assertions.assertThat;
@@ -40,7 +39,6 @@
4039
@RunWith(SpringRunner.class)
4140
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
4241
"management.server.port=-1" })
43-
@DirtiesContext
4442
public class NoManagementSampleActuatorApplicationTests {
4543

4644
@Autowired

spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/SampleActuatorApplicationTests.java

-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import org.springframework.http.HttpStatus;
3535
import org.springframework.http.MediaType;
3636
import org.springframework.http.ResponseEntity;
37-
import org.springframework.test.annotation.DirtiesContext;
3837
import org.springframework.test.context.junit4.SpringRunner;
3938

4039
import static org.assertj.core.api.Assertions.assertThat;
@@ -47,7 +46,6 @@
4746
*/
4847
@RunWith(SpringRunner.class)
4948
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
50-
@DirtiesContext
5149
public class SampleActuatorApplicationTests {
5250

5351
@Autowired

spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ServletPathSampleActuatorApplicationTests.java

-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.springframework.boot.test.web.client.TestRestTemplate;
2828
import org.springframework.http.HttpStatus;
2929
import org.springframework.http.ResponseEntity;
30-
import org.springframework.test.annotation.DirtiesContext;
3130
import org.springframework.test.context.junit4.SpringRunner;
3231

3332
import static org.assertj.core.api.Assertions.assertThat;
@@ -40,7 +39,6 @@
4039
@RunWith(SpringRunner.class)
4140
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
4241
"server.servlet.path=/spring" })
43-
@DirtiesContext
4442
public class ServletPathSampleActuatorApplicationTests {
4543

4644
@Autowired

spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ShutdownSampleActuatorApplicationTests.java

-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.springframework.boot.test.web.client.TestRestTemplate;
2828
import org.springframework.http.HttpStatus;
2929
import org.springframework.http.ResponseEntity;
30-
import org.springframework.test.annotation.DirtiesContext;
3130
import org.springframework.test.context.junit4.SpringRunner;
3231

3332
import static org.assertj.core.api.Assertions.assertThat;
@@ -39,7 +38,6 @@
3938
*/
4039
@RunWith(SpringRunner.class)
4140
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
42-
@DirtiesContext
4341
public class ShutdownSampleActuatorApplicationTests {
4442

4543
@Autowired

spring-boot-samples/spring-boot-sample-atmosphere/src/test/java/sample/atmosphere/SampleAtmosphereApplicationTests.java

-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import org.springframework.context.ConfigurableApplicationContext;
3636
import org.springframework.context.annotation.Bean;
3737
import org.springframework.context.annotation.Configuration;
38-
import org.springframework.test.annotation.DirtiesContext;
3938
import org.springframework.test.context.junit4.SpringRunner;
4039
import org.springframework.web.socket.TextMessage;
4140
import org.springframework.web.socket.WebSocketSession;
@@ -47,7 +46,6 @@
4746

4847
@RunWith(SpringRunner.class)
4948
@SpringBootTest(classes = SampleAtmosphereApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT)
50-
@DirtiesContext
5149
public class SampleAtmosphereApplicationTests {
5250

5351
private static Log logger = LogFactory.getLog(SampleAtmosphereApplicationTests.class);

spring-boot-samples/spring-boot-sample-devtools/src/test/java/sample/devtools/SampleDevToolsApplicationIntegrationTests.java

-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.springframework.boot.test.web.client.TestRestTemplate;
2626
import org.springframework.http.HttpStatus;
2727
import org.springframework.http.ResponseEntity;
28-
import org.springframework.test.annotation.DirtiesContext;
2928
import org.springframework.test.context.junit4.SpringRunner;
3029

3130
import static org.assertj.core.api.Assertions.assertThat;
@@ -38,7 +37,6 @@
3837
*/
3938
@RunWith(SpringRunner.class)
4039
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
41-
@DirtiesContext
4240
public class SampleDevToolsApplicationIntegrationTests {
4341

4442
@Autowired

spring-boot-samples/spring-boot-sample-jetty-jsp/pom.xml

-10
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,6 @@
2828
</exclusion>
2929
</exclusions>
3030
</dependency>
31-
<dependency>
32-
<groupId>org.springframework.boot</groupId>
33-
<artifactId>spring-boot-starter-validation</artifactId>
34-
<exclusions>
35-
<exclusion>
36-
<groupId>org.apache.tomcat.embed</groupId>
37-
<artifactId>tomcat-embed-el</artifactId>
38-
</exclusion>
39-
</exclusions>
40-
</dependency>
4131
<dependency>
4232
<groupId>javax.servlet</groupId>
4333
<artifactId>jstl</artifactId>

spring-boot-samples/spring-boot-sample-jetty-jsp/src/test/java/sample/jetty/jsp/SampleWebJspApplicationTests.java

-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.springframework.boot.test.web.client.TestRestTemplate;
2626
import org.springframework.http.HttpStatus;
2727
import org.springframework.http.ResponseEntity;
28-
import org.springframework.test.annotation.DirtiesContext;
2928
import org.springframework.test.context.junit4.SpringRunner;
3029

3130
import static org.assertj.core.api.Assertions.assertThat;
@@ -37,7 +36,6 @@
3736
*/
3837
@RunWith(SpringRunner.class)
3938
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
40-
@DirtiesContext
4139
public class SampleWebJspApplicationTests {
4240

4341
@Autowired

spring-boot-samples/spring-boot-sample-jetty-ssl/pom.xml

+7-5
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,18 @@
1818
<!-- Compile -->
1919
<dependency>
2020
<groupId>org.springframework.boot</groupId>
21-
<artifactId>spring-boot-starter</artifactId>
21+
<artifactId>spring-boot-starter-web</artifactId>
22+
<exclusions>
23+
<exclusion>
24+
<groupId>org.springframework.boot</groupId>
25+
<artifactId>spring-boot-starter-tomcat</artifactId>
26+
</exclusion>
27+
</exclusions>
2228
</dependency>
2329
<dependency>
2430
<groupId>org.springframework.boot</groupId>
2531
<artifactId>spring-boot-starter-jetty</artifactId>
2632
</dependency>
27-
<dependency>
28-
<groupId>org.springframework</groupId>
29-
<artifactId>spring-webmvc</artifactId>
30-
</dependency>
3133
<!-- Test -->
3234
<dependency>
3335
<groupId>org.springframework.boot</groupId>

spring-boot-samples/spring-boot-sample-jetty-ssl/src/main/java/sample/jetty/ssl/service/HelloWorldService.java

-32
This file was deleted.

spring-boot-samples/spring-boot-sample-jetty-ssl/src/main/java/sample/jetty/ssl/web/SampleController.java

+3-13
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,13 @@
1616

1717
package sample.jetty.ssl.web;
1818

19-
import sample.jetty.ssl.service.HelloWorldService;
20-
21-
import org.springframework.beans.factory.annotation.Autowired;
22-
import org.springframework.stereotype.Controller;
2319
import org.springframework.web.bind.annotation.GetMapping;
24-
import org.springframework.web.bind.annotation.ResponseBody;
20+
import org.springframework.web.bind.annotation.RestController;
2521

26-
@Controller
22+
@RestController
2723
public class SampleController {
28-
29-
@Autowired
30-
private HelloWorldService helloWorldService;
31-
3224
@GetMapping("/")
33-
@ResponseBody
3425
public String helloWorld() {
35-
return this.helloWorldService.getHelloMessage();
26+
return "Hello World";
3627
}
37-
3828
}

0 commit comments

Comments
 (0)