From 61f65ea10e508ea0bcccf123670dcfb3c8c7322c Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Tue, 27 Dec 2016 12:24:32 -0800 Subject: [PATCH] Add test for devtools + serving from `/public` Add a simple test to show that basic serving of `/public` resources works with devtoos. See gh-7752 --- .../src/main/resources/public/public.txt | 1 + ...leDevToolsApplicationIntegrationTests.java | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 spring-boot-samples/spring-boot-sample-devtools/src/main/resources/public/public.txt diff --git a/spring-boot-samples/spring-boot-sample-devtools/src/main/resources/public/public.txt b/spring-boot-samples/spring-boot-sample-devtools/src/main/resources/public/public.txt new file mode 100644 index 0000000000..e258b6c5c8 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-devtools/src/main/resources/public/public.txt @@ -0,0 +1 @@ +public file diff --git a/spring-boot-samples/spring-boot-sample-devtools/src/test/java/sample/devtools/SampleDevToolsApplicationIntegrationTests.java b/spring-boot-samples/spring-boot-sample-devtools/src/test/java/sample/devtools/SampleDevToolsApplicationIntegrationTests.java index 41091ebf97..978353e4e5 100644 --- a/spring-boot-samples/spring-boot-sample-devtools/src/test/java/sample/devtools/SampleDevToolsApplicationIntegrationTests.java +++ b/spring-boot-samples/spring-boot-sample-devtools/src/test/java/sample/devtools/SampleDevToolsApplicationIntegrationTests.java @@ -16,11 +16,48 @@ package sample.devtools; +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.assertj.core.api.Assertions.assertThat; + /** * Integration tests for {@link SampleDevToolsApplication}. * * @author Andy Wilkinson + * @author Phillip Webb */ +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +@DirtiesContext public class SampleDevToolsApplicationIntegrationTests { + @Autowired + private TestRestTemplate restTemplate; + + @Test + public void testStaticResource() throws Exception { + ResponseEntity entity = this.restTemplate + .getForEntity("/css/application.css", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("color: green;"); + } + + @Test + public void testPublicResource() throws Exception { + ResponseEntity entity = this.restTemplate.getForEntity("/public.txt", + String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("public file"); + } + }