|
@@ -8,36 +8,31 @@ import java.net.URL;
|
8
|
8
|
import org.junit.Before;
|
9
|
9
|
import org.junit.Test;
|
10
|
10
|
import org.junit.runner.RunWith;
|
11
|
|
-import org.springframework.beans.factory.annotation.Value;
|
12
|
|
-import org.springframework.boot.test.IntegrationTest;
|
13
|
|
-import org.springframework.boot.test.SpringApplicationConfiguration;
|
14
|
|
-import org.springframework.boot.test.TestRestTemplate;
|
|
11
|
+import org.springframework.boot.context.embedded.LocalServerPort;
|
|
12
|
+import org.springframework.boot.test.context.SpringBootTest;
|
|
13
|
+import org.springframework.boot.test.web.client.TestRestTemplate;
|
15
|
14
|
import org.springframework.http.ResponseEntity;
|
16
|
15
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
17
|
|
-import org.springframework.test.context.web.WebAppConfiguration;
|
18
|
|
-import org.springframework.web.client.RestTemplate;
|
19
|
16
|
|
20
|
17
|
@RunWith(SpringJUnit4ClassRunner.class)
|
21
|
|
-@SpringApplicationConfiguration(classes = Application.class)
|
22
|
|
-@WebAppConfiguration
|
23
|
|
-@IntegrationTest({"server.port=0"})
|
|
18
|
+@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
24
|
19
|
public class HelloControllerIT {
|
25
|
20
|
|
26
|
|
- @Value("${local.server.port}")
|
|
21
|
+ @LocalServerPort
|
27
|
22
|
private int port;
|
28
|
23
|
|
29
|
|
- private URL base;
|
30
|
|
- private RestTemplate template;
|
|
24
|
+ private URL base;
|
|
25
|
+ private TestRestTemplate template;
|
31
|
26
|
|
32
|
|
- @Before
|
33
|
|
- public void setUp() throws Exception {
|
34
|
|
- this.base = new URL("http://localhost:" + port + "/");
|
35
|
|
- template = new TestRestTemplate();
|
36
|
|
- }
|
|
27
|
+ @Before
|
|
28
|
+ public void setUp() throws Exception {
|
|
29
|
+ this.base = new URL("http://localhost:" + port + "/");
|
|
30
|
+ template = new TestRestTemplate();
|
|
31
|
+ }
|
37
|
32
|
|
38
|
|
- @Test
|
39
|
|
- public void getHello() throws Exception {
|
40
|
|
- ResponseEntity<String> response = template.getForEntity(base.toString(), String.class);
|
41
|
|
- assertThat(response.getBody(), equalTo("Greetings from Spring Boot!"));
|
42
|
|
- }
|
|
33
|
+ @Test
|
|
34
|
+ public void getHello() throws Exception {
|
|
35
|
+ ResponseEntity<String> response = template.getForEntity(base.toString(), String.class);
|
|
36
|
+ assertThat(response.getBody(), equalTo("Greetings from Spring Boot!"));
|
|
37
|
+ }
|
43
|
38
|
}
|