Rachelle 8 yıl önce
ebeveyn
işleme
be93099540

+ 45
- 0
initial/pom.xml Dosyayı Görüntüle

18
             <groupId>org.springframework.boot</groupId>
18
             <groupId>org.springframework.boot</groupId>
19
             <artifactId>spring-boot-starter-web</artifactId>
19
             <artifactId>spring-boot-starter-web</artifactId>
20
         </dependency>
20
         </dependency>
21
+        <dependency>
22
+            <groupId>org.springframework.boot</groupId>
23
+            <artifactId>spring-boot-starter-test</artifactId>
24
+            <scope>test</scope>
25
+        </dependency>
26
+        <dependency>
27
+            <groupId>org.hamcrest</groupId>
28
+            <artifactId>hamcrest-library</artifactId>
29
+        </dependency>
30
+        <dependency>
31
+            <groupId>org.springframework.boot</groupId>
32
+            <artifactId>spring-boot-test</artifactId>
33
+        </dependency>
34
+        <dependency>
35
+            <groupId>junit</groupId>
36
+            <artifactId>junit</artifactId>
37
+        </dependency>
38
+        <dependency>
39
+            <groupId>org.springframework</groupId>
40
+            <artifactId>spring-test</artifactId>
41
+            <version>RELEASE</version>
42
+            <scope>compile</scope>
43
+        </dependency>
44
+        <dependency>
45
+            <groupId>org.springframework</groupId>
46
+            <artifactId>spring-test</artifactId>
47
+            <version>RELEASE</version>
48
+            <scope>compile</scope>
49
+        </dependency>
50
+        <dependency>
51
+            <groupId>org.mockito</groupId>
52
+            <artifactId>mockito-core</artifactId>
53
+        </dependency>
54
+        <dependency>
55
+            <groupId>org.assertj</groupId>
56
+            <artifactId>assertj-core</artifactId>
57
+        </dependency>
58
+        <dependency>
59
+            <groupId>org.springframework.boot</groupId>
60
+            <artifactId>spring-boot-test-autoconfigure</artifactId>
61
+        </dependency>
62
+        <dependency>
63
+            <groupId>org.springframework.boot</groupId>
64
+            <artifactId>spring-boot-starter-actuator</artifactId>
65
+        </dependency>
21
     </dependencies>
66
     </dependencies>
22
 
67
 
23
     <properties>
68
     <properties>

+ 43
- 0
initial/src/main/java/hello/HelloControllerITTest.java Dosyayı Görüntüle

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

+ 33
- 0
initial/src/main/java/hello/HelloControllerTest.java Dosyayı Görüntüle

1
+package hello;
2
+
3
+import static org.hamcrest.Matchers.equalTo;
4
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
5
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
6
+
7
+import org.hamcrest.Matchers;
8
+import org.junit.Test;
9
+import org.junit.runner.RunWith;
10
+import org.springframework.beans.factory.annotation.Autowired;
11
+import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
12
+import org.springframework.boot.test.context.SpringBootTest;
13
+import org.springframework.http.MediaType;
14
+import org.springframework.test.context.junit4.SpringRunner;
15
+import org.springframework.test.web.servlet.MockMvc;
16
+import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
17
+import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
18
+
19
+@RunWith(SpringRunner.class)
20
+@SpringBootTest
21
+@AutoConfigureMockMvc
22
+public class HelloControllerTest {
23
+
24
+    @Autowired
25
+    private MockMvc mvc;
26
+
27
+    @Test
28
+    public void getHello() throws Exception {
29
+        mvc.perform(MockMvcRequestBuilders.get("/").accept(MediaType.APPLICATION_JSON))
30
+                .andExpect(MockMvcResultMatchers.status().isOk())
31
+                .andExpect(MockMvcResultMatchers.content().string(Matchers.equalTo("Greetings from Spring Boot!")));
32
+    }
33
+}

+ 12
- 0
initial/src/main/java/hello/app.groovy Dosyayı Görüntüle

1
+import org.springframework.web.bind.annotation.RequestMapping
2
+import org.springframework.web.bind.annotation.RestController
3
+
4
+@RestController
5
+class ThisWillActuallyRun {
6
+
7
+    @RequestMapping("/")
8
+    String home() {
9
+        return "Hello World!"
10
+    }
11
+
12
+}