#1 DavidThornley

Öppen
DavidThornley vill sammanfoga 1 incheckningar från s[2]s in i master

+ 60
- 0
pom.xml Visa fil

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

+ 32
- 0
src/main/java/Hello/Application.java Visa fil

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

+ 13
- 0
src/main/java/Hello/HelloController.java Visa fil

@@ -0,0 +1,13 @@
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
+    @RequestMapping("/")
10
+    public String index(){
11
+        return "Greetings from the great unknown!";
12
+    }
13
+}

+ 32
- 0
src/test/java/Hello/HelloControllerTest.java Visa fil

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