Ben Blinebury il y a 6 ans
Parent
révision
a33e09b285

BIN
.DS_Store Voir le fichier


+ 60
- 0
pom.xml Voir le fichier

@@ -0,0 +1,60 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
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">
4
+    <modelVersion>4.0.0</modelVersion>
5
+
6
+    <groupId>org.springframework</groupId>
7
+    <artifactId>gs-spring-boot</artifactId>
8
+    <version>0.1.0</version>
9
+
10
+    <parent>
11
+        <groupId>org.springframework.boot</groupId>
12
+        <artifactId>spring-boot-starter-parent</artifactId>
13
+        <version>2.0.3.RELEASE</version>
14
+    </parent>
15
+
16
+    <dependencies>
17
+        <dependency>
18
+            <groupId>org.springframework.boot</groupId>
19
+            <artifactId>spring-boot-starter-web</artifactId>
20
+        </dependency>
21
+        <!-- tag::actuator[] -->
22
+        <dependency>
23
+            <groupId>org.springframework.boot</groupId>
24
+            <artifactId>spring-boot-starter-actuator</artifactId>
25
+        </dependency>
26
+        <!-- end::actuator[] -->
27
+        <!-- tag::tests[] -->
28
+        <dependency>
29
+            <groupId>org.springframework.boot</groupId>
30
+            <artifactId>spring-boot-starter-test</artifactId>
31
+            <scope>test</scope>
32
+        </dependency>
33
+        <!-- end::tests[] -->
34
+    </dependencies>
35
+
36
+    <properties>
37
+        <java.version>1.8</java.version>
38
+    </properties>
39
+
40
+    <build>
41
+        <plugins>
42
+            <plugin>
43
+                <groupId>org.springframework.boot</groupId>
44
+                <artifactId>spring-boot-maven-plugin</artifactId>
45
+            </plugin>
46
+            <plugin>
47
+                <artifactId>maven-failsafe-plugin</artifactId>
48
+                <executions>
49
+                    <execution>
50
+                        <goals>
51
+                            <goal>integration-test</goal>
52
+                            <goal>verify</goal>
53
+                        </goals>
54
+                    </execution>
55
+                </executions>
56
+            </plugin>
57
+        </plugins>
58
+    </build>
59
+
60
+</project>

+ 30
- 0
src/main/java/Hello/Application.java Voir le fichier

@@ -0,0 +1,30 @@
1
+package Hello;
2
+
3
+import java.util.Arrays;
4
+
5
+import org.springframework.boot.CommandLineRunner;
6
+import org.springframework.boot.SpringApplication;
7
+import org.springframework.boot.autoconfigure.SpringBootApplication;
8
+import org.springframework.context.ApplicationContext;
9
+import org.springframework.context.annotation.Bean;
10
+
11
+@SpringBootApplication
12
+public class Application {
13
+
14
+    public static void main(String[] args) {
15
+        SpringApplication.run(Application.class, args);
16
+    }
17
+
18
+    @Bean
19
+    public CommandLineRunner commandLineRunner(ApplicationContext ctx){
20
+        return args -> {
21
+            System.out.println("Let's inspect the beans provided by Spring Boot!");
22
+
23
+            String[] beanNames = ctx.getBeanDefinitionNames();
24
+            Arrays.sort(beanNames);
25
+            for(String beanName: beanNames){
26
+                System.out.println(beanName);
27
+            }
28
+        };
29
+    }
30
+}

+ 15
- 0
src/main/java/Hello/HelloController.java Voir le fichier

@@ -0,0 +1,15 @@
1
+package Hello;
2
+
3
+import org.springframework.web.bind.annotation.RequestMapping;
4
+import org.springframework.web.bind.annotation.RestController;
5
+
6
+@RestController
7
+public class HelloController {
8
+
9
+
10
+    @RequestMapping("/")
11
+    public String index() {
12
+        return "Greetings from Spring Boot!";
13
+    }
14
+
15
+}

+ 31
- 0
src/test/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
+}