ganhuan 10 лет назад
Родитель
Сommit
d8dab132ce
2 измененных файлов: 67 добавлений и 2 удалений
  1. 16
    2
      initial/pom.xml
  2. 51
    0
      initial/src/test/java/com/yiifaa/HelloControllerTest.java

+ 16
- 2
initial/pom.xml Просмотреть файл

@@ -4,8 +4,8 @@
4 4
     <modelVersion>4.0.0</modelVersion>
5 5
 
6 6
     <groupId>org.springframework</groupId>
7
-    <artifactId>gs-spring-boot</artifactId>
8
-    <version>0.1.0</version>
7
+    <artifactId>yii-framework</artifactId>
8
+    <version>1.0</version>
9 9
 
10 10
     <parent>
11 11
         <groupId>org.springframework.boot</groupId>
@@ -18,6 +18,12 @@
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-test</artifactId>
25
+            <scope>test</scope>
26
+        </dependency>
21 27
     </dependencies>
22 28
 
23 29
     <properties>
@@ -33,5 +39,13 @@
33 39
             </plugin>
34 40
         </plugins>
35 41
     </build>
42
+    
43
+    <repositories>
44
+	    <repository> 
45
+	        <id>repository.spring.release</id> 
46
+	        <name>Spring GA Repository</name> 
47
+	        <url>http://repo.spring.io/release</url> 
48
+	    </repository>
49
+	</repositories>
36 50
 
37 51
 </project>

+ 51
- 0
initial/src/test/java/com/yiifaa/HelloControllerTest.java Просмотреть файл

@@ -0,0 +1,51 @@
1
+/*
2
+ * (c) Copyright 2016 大头蚁
3
+ * https://github.com/yiifaa
4
+ */
5
+package com.yiifaa;
6
+
7
+import static org.hamcrest.Matchers.equalTo;
8
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
9
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
10
+
11
+import org.junit.Before;
12
+import org.junit.Test;
13
+import org.junit.runner.RunWith;
14
+import org.springframework.boot.test.SpringApplicationConfiguration;
15
+import org.springframework.http.MediaType;
16
+import org.springframework.mock.web.MockServletContext;
17
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
18
+import org.springframework.test.context.web.WebAppConfiguration;
19
+import org.springframework.test.web.servlet.MockMvc;
20
+import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
21
+import org.springframework.test.web.servlet.setup.MockMvcBuilders;
22
+
23
+import hello.HelloController;
24
+
25
+/**
26
+ * 
27
+ * @author <a href="mailto:yiifaa@163.com>大头蚁</a> 
28
+ * since 1.0
29
+ * 2016年5月12日 下午5:45:23
30
+ */
31
+
32
+@RunWith(SpringJUnit4ClassRunner.class)
33
+@SpringApplicationConfiguration(classes = MockServletContext.class)
34
+@WebAppConfiguration
35
+public class HelloControllerTest {
36
+	
37
+	private MockMvc mvc;
38
+
39
+	@Before
40
+	public void setUp() throws Exception {
41
+		mvc = MockMvcBuilders.standaloneSetup(new HelloController()).build();
42
+	}
43
+
44
+	@Test	
45
+	public void getHello() throws Exception {
46
+		mvc.perform(MockMvcRequestBuilders.get("/").accept(MediaType.APPLICATION_JSON))
47
+				.andExpect(status().isOk())
48
+				.andExpect(content().string(equalTo("Greetings from Spring Boot!")));
49
+	}
50
+
51
+}