Browse Source

everything working but actuator and groovy

Tommy Rogers 6 years ago
parent
commit
eff810d231

+ 54
- 0
initial/pom.xml View File

@@ -18,6 +18,60 @@
18 18
             <groupId>org.springframework.boot</groupId>
19 19
             <artifactId>spring-boot-starter-web</artifactId>
20 20
         </dependency>
21
+
22
+        <dependency>
23
+            <groupId>org.springframework.boot</groupId>
24
+            <artifactId>spring-boot-starter-actuator</artifactId>
25
+        </dependency>
26
+
27
+        <dependency>
28
+            <groupId>org.springframework.boot</groupId>
29
+            <artifactId>spring-boot-starter-test</artifactId>
30
+            <scope>test</scope>
31
+        </dependency>
32
+        <dependency>
33
+            <groupId>junit</groupId>
34
+            <artifactId>junit</artifactId>
35
+        </dependency>
36
+        <dependency>
37
+            <groupId>org.springframework.boot</groupId>
38
+            <artifactId>spring-boot-test</artifactId>
39
+        </dependency>
40
+        <dependency>
41
+            <groupId>org.springframework.boot</groupId>
42
+            <artifactId>spring-boot-test-autoconfigure</artifactId>
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.hamcrest</groupId>
52
+            <artifactId>hamcrest-library</artifactId>
53
+        </dependency>
54
+
55
+
56
+
57
+        <dependency>
58
+            <groupId>org.hibernate</groupId>
59
+            <artifactId>hibernate-validator</artifactId>
60
+            <version>6.0.10.Final</version>
61
+        </dependency>
62
+
63
+        <dependency>
64
+            <groupId>org.glassfish</groupId>
65
+            <artifactId>javax.el</artifactId>
66
+            <version>3.0.1-b09</version>
67
+        </dependency>
68
+
69
+        <dependency>
70
+            <groupId>org.hibernate</groupId>
71
+            <artifactId>hibernate-validator-cdi</artifactId>
72
+            <version>6.0.10.Final</version>
73
+        </dependency>
74
+
21 75
     </dependencies>
22 76
 
23 77
     <properties>

+ 20
- 9
initial/src/main/java/hello/Application.java View File

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

+ 41
- 0
initial/src/main/java/hello/HelloControllerIT.java View File

@@ -0,0 +1,41 @@
1
+package hello;
2
+
3
+import static org.hamcrest.core.IsEqual.equalTo;
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
+}

+ 32
- 0
initial/src/main/java/hello/HelloControllerTest.java View File

@@ -0,0 +1,32 @@
1
+package hello;
2
+import static org.hamcrest.core.IsEqual.equalTo;
3
+
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
+
32
+}

+ 3
- 0
initial/src/main/resources/application.properties View File

@@ -0,0 +1,3 @@
1
+management.endpoints.web.exposure.include=*
2
+
3
+management.endpoint.shutdown.enabled=true