|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+package hello;
|
|
|
2
|
+
|
|
|
3
|
+import static org.hamcrest.Matchers.*;
|
|
|
4
|
+import static org.junit.Assert.*;
|
|
|
5
|
+
|
|
|
6
|
+import java.net.URL;
|
|
|
7
|
+
|
|
|
8
|
+import org.junit.Before;
|
|
|
9
|
+import org.junit.Test;
|
|
|
10
|
+import org.junit.runner.RunWith;
|
|
|
11
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
12
|
+import org.springframework.boot.test.context.SpringBootTest;
|
|
|
13
|
+import org.springframework.boot.test.web.client.TestRestTemplate;
|
|
|
14
|
+import org.springframework.boot.web.server.LocalServerPort;
|
|
|
15
|
+import org.springframework.http.ResponseEntity;
|
|
|
16
|
+import org.springframework.test.context.junit4.SpringRunner;
|
|
|
17
|
+
|
|
|
18
|
+@RunWith(SpringRunner.class)
|
|
|
19
|
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
|
|
20
|
+public class HelloControllerIT {
|
|
|
21
|
+
|
|
|
22
|
+ @LocalServerPort
|
|
|
23
|
+ private int port;
|
|
|
24
|
+
|
|
|
25
|
+ private URL base;
|
|
|
26
|
+
|
|
|
27
|
+ @Autowired
|
|
|
28
|
+ private TestRestTemplate template;
|
|
|
29
|
+
|
|
|
30
|
+ @Before
|
|
|
31
|
+ public void setUp() throws Exception {
|
|
|
32
|
+ this.base = new URL("http://localhost:" + port + "/");
|
|
|
33
|
+ }
|
|
|
34
|
+
|
|
|
35
|
+ @Test
|
|
|
36
|
+ public void getHello() throws Exception {
|
|
|
37
|
+ ResponseEntity<String> response = template.getForEntity(base.toString(),
|
|
|
38
|
+ String.class);
|
|
|
39
|
+ assertThat(response.getBody(), equalTo("Greetings from Spring Boot!"));
|
|
|
40
|
+ }
|
|
|
41
|
+}
|