#6 chitraBegerhotta

Offen
chitraBegerhotta möchte 1 Commits von chitraBegerhotta/ZCW-SpringOne:master nach master zusammenführen

+ 17
- 0
initial/pom.xml Datei anzeigen

18
             <groupId>org.springframework.boot</groupId>
18
             <groupId>org.springframework.boot</groupId>
19
             <artifactId>spring-boot-starter-web</artifactId>
19
             <artifactId>spring-boot-starter-web</artifactId>
20
         </dependency>
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
     </dependencies>
38
     </dependencies>
22
 
39
 
23
     <properties>
40
     <properties>

+ 5
- 1
initial/src/main/java/hello/Application.java Datei anzeigen

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

+ 5
- 2
initial/src/main/java/hello/HelloController.java Datei anzeigen

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

+ 12
- 0
initial/src/main/java/hello/app.groovy Datei anzeigen

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 Datei anzeigen

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