chitraB преди 8 години
родител
ревизия
c3c354725a

+ 17
- 0
initial/pom.xml Целия файл

@@ -18,6 +18,23 @@
18 18
             <groupId>org.springframework.boot</groupId>
19 19
             <artifactId>spring-boot-starter-web</artifactId>
20 20
         </dependency>
21
+        <dependency>
22
+            <groupId>io.springfox</groupId>
23
+            <artifactId>springfox-swagger-ui</artifactId>
24
+            <version>2.2.2</version>
25
+            <scope>compile</scope>
26
+        </dependency>
27
+        <dependency>
28
+            <groupId>io.springfox</groupId>
29
+            <artifactId>springfox-swagger2</artifactId>
30
+            <version>2.2.2</version>
31
+            <scope>compile</scope>
32
+        </dependency>
33
+        <dependency>
34
+            <groupId>org.springframework.boot</groupId>
35
+            <artifactId>spring-boot-starter-test</artifactId>
36
+            <scope>test</scope>
37
+        </dependency>
21 38
     </dependencies>
22 39
 
23 40
     <properties>

+ 5
- 1
initial/src/main/java/hello/Application.java Целия файл

@@ -5,13 +5,17 @@ import java.util.Arrays;
5 5
 import org.springframework.boot.SpringApplication;
6 6
 import org.springframework.boot.autoconfigure.SpringBootApplication;
7 7
 import org.springframework.context.ApplicationContext;
8
+import springfox.documentation.swagger2.annotations.EnableSwagger2;
8 9
 
10
+@EnableSwagger2
9 11
 @SpringBootApplication
10 12
 public class Application {
11 13
     
12 14
     public static void main(String[] args) {
15
+
13 16
         ApplicationContext ctx = SpringApplication.run(Application.class, args);
14
-        
17
+
18
+
15 19
         System.out.println("Let's inspect the beans provided by Spring Boot:");
16 20
         
17 21
         String[] beanNames = ctx.getBeanDefinitionNames();

+ 5
- 2
initial/src/main/java/hello/HelloController.java Целия файл

@@ -1,12 +1,15 @@
1 1
 package hello;
2 2
 
3
+import io.swagger.annotations.ApiOperation;
4
+import org.springframework.web.bind.annotation.RequestMethod;
3 5
 import org.springframework.web.bind.annotation.RestController;
4 6
 import org.springframework.web.bind.annotation.RequestMapping;
5 7
 
6 8
 @RestController
7 9
 public class HelloController {
8
-    
9
-    @RequestMapping("/")
10
+
11
+    @ApiOperation(value = "Get Index")
12
+    @RequestMapping(method = RequestMethod.GET, value = "/index")
10 13
     public String index() {
11 14
         return "Greetings from Spring Boot!";
12 15
     }

+ 12
- 0
initial/src/main/java/hello/app.groovy Целия файл

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

+ 31
- 0
initial/src/test/java/hello/HelloControllerTest.java Целия файл

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