Parcourir la source

finished commit

Joshua Chung il y a 6 ans
Parent
révision
80b1f01ff7

BIN
.DS_Store Voir le fichier


BIN
complete/.DS_Store Voir le fichier


BIN
complete/src/.DS_Store Voir le fichier


BIN
complete/src/main/.DS_Store Voir le fichier


BIN
complete/src/main/java/.DS_Store Voir le fichier


BIN
complete/src/test/.DS_Store Voir le fichier


BIN
complete/src/test/java/.DS_Store Voir le fichier


+ 33
- 2
initial/pom.xml Voir le fichier

@@ -1,6 +1,6 @@
1 1
 <?xml version="1.0" encoding="UTF-8"?>
2 2
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
-    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4 4
     <modelVersion>4.0.0</modelVersion>
5 5
 
6 6
     <groupId>org.springframework</groupId>
@@ -16,8 +16,39 @@
16 16
     <dependencies>
17 17
         <dependency>
18 18
             <groupId>org.springframework.boot</groupId>
19
+            <artifactId>spring-boot-starter-actuator</artifactId>
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.springframework.boot</groupId>
19 28
             <artifactId>spring-boot-starter-web</artifactId>
20 29
         </dependency>
30
+        <dependency>
31
+            <groupId>org.hamcrest</groupId>
32
+            <artifactId>hamcrest-library</artifactId>
33
+        </dependency>
34
+        <dependency>
35
+            <groupId>org.springframework</groupId>
36
+            <artifactId>spring-test</artifactId>
37
+            <version>RELEASE</version>
38
+            <scope>compile</scope>
39
+        </dependency>
40
+        <dependency>
41
+            <groupId>org.springframework.boot</groupId>
42
+            <artifactId>spring-boot-test</artifactId>
43
+        </dependency>
44
+        <dependency>
45
+            <groupId>junit</groupId>
46
+            <artifactId>junit</artifactId>
47
+        </dependency>
48
+        <dependency>
49
+            <groupId>org.springframework.boot</groupId>
50
+            <artifactId>spring-boot-test-autoconfigure</artifactId>
51
+        </dependency>
21 52
     </dependencies>
22 53
 
23 54
     <properties>
@@ -34,4 +65,4 @@
34 65
         </plugins>
35 66
     </build>
36 67
 
37
-</project>
68
+</project>

+ 41
- 0
initial/src/main/java/hello/HelloControllerIT.java Voir le fichier

@@ -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
+}

+ 31
- 0
initial/src/main/java/hello/HelloControllerTest.java Voir le fichier

@@ -0,0 +1,31 @@
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.junit.Test;
8
+import org.junit.runner.RunWith;
9
+import org.springframework.beans.factory.annotation.Autowired;
10
+import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
11
+import org.springframework.boot.test.context.SpringBootTest;
12
+import org.springframework.http.MediaType;
13
+import org.springframework.test.context.junit4.SpringRunner;
14
+import org.springframework.test.web.servlet.MockMvc;
15
+import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
16
+
17
+@RunWith(SpringRunner.class)
18
+@SpringBootTest
19
+@AutoConfigureMockMvc
20
+public class HelloControllerTest {
21
+
22
+    @Autowired
23
+    private MockMvc mvc;
24
+
25
+    @Test
26
+    public void getHello() throws Exception {
27
+        mvc.perform(MockMvcRequestBuilders.get("/").accept(MediaType.APPLICATION_JSON))
28
+                .andExpect(status().isOk())
29
+                .andExpect(content().string(equalTo("Greetings from Spring Boot!")));
30
+    }
31
+}

+ 12
- 0
initial/src/main/java/hello/app.groovy Voir le fichier

@@ -0,0 +1,12 @@
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
+}