├── .gitignore
├── README.md
├── cobertura.bat
├── local_unitreport.bat
├── pom.xml
├── sample-test
├── .gitignore
├── README.md
├── build.bat
├── clover.bat
├── cobertura.bat
├── pom-clover.xml
├── pom-cobertura.xml
├── pom-jacoco.xml
├── pom.xml
├── show_test.bat
└── src
│ ├── main
│ ├── java
│ │ ├── config
│ │ │ └── cache
│ │ │ │ └── CacheConfig.java
│ │ ├── controller
│ │ │ ├── ErrorController.java
│ │ │ ├── SimpleController.java
│ │ │ ├── login
│ │ │ │ └── LoginController.java
│ │ │ └── order
│ │ │ │ └── OrderController.java
│ │ ├── dao
│ │ │ └── user
│ │ │ │ └── UserMapper.java
│ │ ├── model
│ │ │ ├── order
│ │ │ │ └── Order.java
│ │ │ └── user
│ │ │ │ └── User.java
│ │ ├── service
│ │ │ └── user
│ │ │ │ ├── UserService.java
│ │ │ │ └── impl
│ │ │ │ └── UserServiceImpl.java
│ │ └── util
│ │ │ └── SpringInitByWeb.java
│ ├── resources
│ │ ├── applicationContext.xml
│ │ ├── cache
│ │ │ └── spring-cache.xml
│ │ ├── dao
│ │ │ ├── dao.xml
│ │ │ └── datasource-prod.xml
│ │ ├── dispatcher-servlet.xml
│ │ └── service
│ │ │ └── spring-service.xml
│ └── webapp
│ │ ├── WEB-INF
│ │ ├── decorators.xml
│ │ ├── ftl
│ │ │ ├── login.ftl
│ │ │ └── order
│ │ │ │ ├── add.ftl
│ │ │ │ └── index.ftl
│ │ ├── layouts
│ │ │ ├── default.jsp
│ │ │ ├── footer.jsp
│ │ │ ├── header.jsp
│ │ │ ├── login_template.jsp
│ │ │ └── order_tpl.jsp
│ │ └── web.xml
│ │ ├── index.jsp
│ │ └── static
│ │ └── js
│ │ └── jquery
│ │ ├── jquery-1.9.1.min.js
│ │ ├── jquery.cookie.js
│ │ └── jquery.min.js
│ └── test
│ ├── java
│ ├── app
│ │ ├── AppTest.java
│ │ ├── Application.java
│ │ ├── HomeController.java
│ │ ├── JettryRun.java
│ │ └── TestApplicationContext.java
│ ├── config
│ │ └── cache
│ │ │ ├── CacheConfigDev.java
│ │ │ └── CacheManagerTest.java
│ ├── controller
│ │ ├── BaseContorllerMockTest.java
│ │ ├── BaseContorllerTest.java
│ │ ├── ErrorControllerTest.java
│ │ ├── SimpleControllerTest.java
│ │ └── login
│ │ │ ├── LoginControllerMockTest.java
│ │ │ └── LoginControllerTest.java
│ ├── dao
│ │ ├── AbstractDbBaseExporter.java
│ │ ├── BaseDaoTest.java
│ │ ├── BaseDbUnitTest.java
│ │ ├── SampleDbExporter.java
│ │ └── user
│ │ │ ├── UserMapperDbUnitTest.java
│ │ │ └── UserMapperTest.java
│ ├── service
│ │ ├── BaseTest.java
│ │ ├── MockBaseTest.java
│ │ └── user
│ │ │ ├── UserCacheTest.java
│ │ │ ├── UserServiceImplTest.java
│ │ │ └── UserServiceImplWithMockTest.java
│ └── test
│ │ ├── AppTest.java
│ │ ├── dbunit
│ │ └── SampleTest.java
│ │ ├── junit
│ │ ├── Fibonacci.java
│ │ ├── FibonacciTest.java
│ │ ├── TestAllFetures.java
│ │ └── TestMethodOrder.java
│ │ ├── mock
│ │ ├── AFinalClass.java
│ │ ├── AStaticClass.java
│ │ ├── ClassUnderTest.java
│ │ ├── MockStaticTest.java
│ │ ├── MockTest.java
│ │ ├── MockTest2.java
│ │ └── MyInterface.java
│ │ ├── selenium
│ │ ├── BaiduTestByTestNg.java
│ │ ├── BaiduWebTest.java
│ │ ├── BaiduWebTest2.java
│ │ └── BaiduWebTest3.java
│ │ ├── spring
│ │ ├── AnnotaionTest.java
│ │ ├── IfProfileTest.java
│ │ └── ProfileTest.java
│ │ ├── testframework
│ │ └── DataProviderTest.java
│ │ ├── testng
│ │ ├── FindNumbers.java
│ │ └── TestAllFetures.java
│ │ └── utilstest
│ │ ├── User.java
│ │ └── UtilsTest.java
│ └── resources
│ ├── clover.license
│ ├── config
│ └── application.properties
│ ├── controller
│ └── LoginController
│ │ └── testLogin.csv
│ ├── dao
│ ├── datasource-dev.xml
│ ├── init-data.xml
│ ├── mockdao.xml
│ └── user
│ │ ├── Users.xml
│ │ ├── Users2.xml
│ │ └── left.xml
│ ├── data
│ ├── schema.sql
│ └── test-data.sql
│ ├── service
│ ├── UserService
│ │ └── testCalRank.csv
│ └── mockservice.xml
│ └── testng.xml
└── show_test.bat
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea
2 | *.iml
3 | .clover
4 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # sample-test
2 |
3 | [](https://gitter.im/superproxy/sample-test?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4 |
5 | ##单元测试示例
6 |
7 | testng和单元覆盖工具集成
8 | testng和spring test集成
9 | mockito和spring mvc mock对象集成
10 | controller service dao 单元测试和集成测试的方法
11 | 添加csv和json测试文件支持
12 |
13 |
14 | ###使用
15 | 1. 本地查看
16 | 执行local_unitreport.bat
17 | 在target/surefire-reports中查看测试结果
18 | 在target/site/cobertura中查看测试覆盖率
19 |
20 | 2. sonar集成查看
21 | 下载sonar
22 | 下载单元测试覆盖率插件cobertura
23 | http://docs.sonarqube.org/display/PLUG/Cobertura+Plugin
24 |
25 | 运行 cobertura.bat,在sonar上查看结果
26 |
--------------------------------------------------------------------------------
/cobertura.bat:
--------------------------------------------------------------------------------
1 | mvn -Dmaven.test.failure.ignore=true -Dcobertura.report.format=xml clean cobertura:cobertura sonar:sonar
2 |
3 | rem mvn -Dmaven.test.failure.ignore=true clean cobertura:cobertura -Dcobertura.report.format=xml sonar:sonar
4 |
5 | rem mvn -Dmaven.test.skip clean compile cobertura:cobertura -Dcobertura.report.format=xml install sonar:sonar
--------------------------------------------------------------------------------
/local_unitreport.bat:
--------------------------------------------------------------------------------
1 | mvn -Dmaven.test.failure.ignore=true clean cobertura:cobertura
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | org.springframework.boot
8 | spring-boot-starter-parent
9 |
10 | 1.2.6.RELEASE
11 |
12 | sample
13 | sample-parent
14 | 1.0-SNAPSHOT
15 | pom
16 |
17 |
18 | sample-test
19 |
20 |
21 |
22 | java
23 | cobertura
24 | UTF-8
25 | UTF-8
26 | target/surefire-reports/junitreports
27 | reuseReports
28 |
29 |
30 |
31 | target/site/cobertura/coverage.xml
32 |
33 | 1.6.2
34 | 4.1.7.RELEASE
35 |
36 | 1.1.3
37 |
38 |
39 |
40 |
41 |
42 |
43 | org.springframework.boot
44 | spring-boot-dependencies
45 | 1.2.6.RELEASE
46 | pom
47 | import
48 |
49 |
50 | org.testng
51 | testng
52 | 6.1.1
53 |
54 |
55 | org.apache.commons
56 | commons-lang3
57 | 3.4
58 |
59 |
60 |
61 | org.slf4j
62 | slf4j-api
63 | 1.6.2
64 |
65 |
66 | org.slf4j
67 | jcl-over-slf4j
68 | 1.6.2
69 |
70 |
71 | ch.qos.logback
72 | logback-core
73 | ${logback.version}
74 |
75 |
76 | ch.qos.logback
77 | logback-classic
78 | ${logback.version}
79 |
80 |
81 |
82 | com.h2database
83 | h2
84 | 1.4.178
85 |
86 |
87 | org.springframework
88 | spring-context
89 | ${spring.version}
90 |
91 |
92 | org.springframework
93 | spring-beans
94 | ${spring.version}
95 |
96 |
97 | org.springframework
98 | spring-context-support
99 | ${spring.version}
100 |
101 |
102 | org.springframework
103 | spring-orm
104 | ${spring.version}
105 |
106 |
107 | org.springframework
108 | spring-webmvc
109 | ${spring.version}
110 |
111 |
112 | com.alibaba
113 | druid
114 | 1.0.2
115 |
116 |
117 |
118 | org.mybatis
119 | mybatis
120 | 3.2.2
121 |
122 |
123 | org.mybatis
124 | mybatis-spring
125 | 1.2.0
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 | org.apache.geronimo.specs
139 | geronimo-servlet_3.0_spec
140 | 1.0
141 |
142 |
143 |
144 | javax.servlet
145 | jstl
146 | 1.2
147 | provided
148 |
149 |
150 |
151 | opensymphony
152 | sitemesh
153 | 2.4.2
154 |
155 |
156 |
157 | org.freemarker
158 | freemarker
159 | 2.3.15
160 |
161 |
162 | org.springframework
163 | spring-test
164 | ${spring.version}
165 |
166 |
167 |
168 | com.alibaba
169 | fastjson
170 | 1.2.5
171 |
172 |
173 |
174 |
175 | javassist
176 | javassist
177 | 3.12.1.GA
178 |
179 |
180 | org.mockito
181 | mockito-all
182 | 1.10.19
183 |
184 |
185 |
186 | org.powermock
187 | powermock-api-mockito
188 | ${powermock.version}
189 |
190 |
191 | org.powermock
192 | powermock-module-testng
193 | ${powermock.version}
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 | org.apache.maven.plugins
202 | maven-surefire-plugin
203 | 2.18.1
204 |
205 |
206 |
207 |
208 | src/test/resources/testng.xml
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 | org.codehaus.mojo
219 | cobertura-maven-plugin
220 | 2.6
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 | Codehaus repository
233 | http://repository.codehaus.org/
234 |
235 |
236 |
237 |
238 |
--------------------------------------------------------------------------------
/sample-test/.gitignore:
--------------------------------------------------------------------------------
1 | .clover
2 | /target
3 | /.idea
4 |
--------------------------------------------------------------------------------
/sample-test/README.md:
--------------------------------------------------------------------------------
1 | # sample-test
2 |
3 | ##单元测试示例
4 |
5 | testng和单元覆盖工具集成
6 | testng和spring test集成
7 | mockito和spring mvc mock对象集成
8 | controller service dao 单元测试和集成测试的方法
9 |
10 |
11 | ###2015/8/29
12 | 扩展了testng dataprovider的功能
13 | 添加cvs和json测试文件支持
14 |
15 | ###2015/8/30
16 | 添加powermock演示
17 |
18 |
19 | ###2015/8/31
20 | TODO:添加性能测试演示
21 |
22 |
23 |
--------------------------------------------------------------------------------
/sample-test/build.bat:
--------------------------------------------------------------------------------
1 | rem mvn clean install
2 | mvn clean clover2:setup test clover2:aggregate clover2:clover
3 | mvn sonar:sonar
--------------------------------------------------------------------------------
/sample-test/clover.bat:
--------------------------------------------------------------------------------
1 | rem mvn clean install
2 | mvn clean clover2:setup test clover2:aggregate clover2:clover
3 | mvn sonar:sonar
--------------------------------------------------------------------------------
/sample-test/cobertura.bat:
--------------------------------------------------------------------------------
1 | mvn -Dmaven.test.failure.ignore=true -Dcobertura.report.format=xml clean cobertura:cobertura sonar:sonar
2 |
3 | rem mvn -Dmaven.test.failure.ignore=true clean cobertura:cobertura -Dcobertura.report.format=xml sonar:sonar
4 |
5 | rem mvn -Dmaven.test.skip clean compile cobertura:cobertura -Dcobertura.report.format=xml install sonar:sonar
--------------------------------------------------------------------------------
/sample-test/pom-clover.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | sample
8 | sample-test
9 | 1.0-SNAPSHOT
10 |
11 |
12 | 4.0.5
13 | java
14 | clover
15 | UTF-8
16 | UTF-8
17 | target/surefire-reports/junitreports
18 | reuseReports
19 | target/site/clover/clover.xml
20 |
21 |
22 |
23 | org.testng
24 | testng
25 | 6.1.1
26 | test
27 |
28 |
29 |
30 | org.slf4j
31 | slf4j-api
32 | 1.6.2
33 |
34 |
35 | org.slf4j
36 | jcl-over-slf4j
37 | 1.6.2
38 |
39 |
40 | ch.qos.logback
41 | logback-core
42 | 0.9.29
43 |
44 |
45 | ch.qos.logback
46 | logback-classic
47 | 0.9.29
48 |
49 |
50 |
51 |
52 | org.springframework
53 | spring-context
54 | 3.2.4.RELEASE
55 |
56 |
57 |
58 | org.springframework
59 | spring-webmvc
60 | 3.2.4.RELEASE
61 |
62 |
63 |
64 | com.h2database
65 | h2
66 | 1.4.178
67 |
68 |
69 |
70 | org.springframework
71 | spring-beans
72 | 3.2.4.RELEASE
73 |
74 |
75 | org.springframework
76 | spring-context-support
77 | 3.2.4.RELEASE
78 |
79 |
80 | org.springframework
81 | spring-orm
82 | 3.2.4.RELEASE
83 |
84 |
85 | com.alibaba
86 | druid
87 | 1.0.2
88 |
89 |
90 | org.springframework
91 | spring-test
92 | 3.2.4.RELEASE
93 |
94 |
95 | org.mybatis
96 | mybatis
97 | 3.2.2
98 |
99 |
100 |
101 | org.springframework
102 | spring-oxm
103 | 3.2.4.RELEASE
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 | org.mybatis
114 | mybatis-spring
115 | 1.2.0
116 |
117 |
118 |
119 | org.apache.geronimo.specs
120 | geronimo-servlet_3.0_spec
121 | 1.0
122 | provided
123 |
124 |
125 |
126 | javax.servlet
127 | jstl
128 | 1.2
129 | provided
130 |
131 |
132 |
133 | opensymphony
134 | sitemesh
135 | 2.4.2
136 |
137 |
138 |
139 | org.freemarker
140 | freemarker
141 | 2.3.15
142 |
143 |
144 |
145 | com.alibaba
146 | fastjson
147 | 1.1.41
148 |
149 |
150 |
151 |
152 | org.mockito
153 | mockito-all
154 | 1.8.5
155 | test
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 | org.apache.maven.plugins
164 | maven-surefire-plugin
165 | 2.18.1
166 |
167 |
168 |
169 |
170 | src/test/resources/testng.xml
171 |
172 |
173 |
174 |
175 | com.atlassian.maven.plugins
176 | maven-clover2-plugin
177 | ${clover.version}
178 |
179 | /src/test/resources/clover.license
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 | com.atlassian.maven.plugins
191 | maven-clover2-plugin
192 | ${clover.version}
193 |
194 | /src/test/resources/clover.license
195 |
196 |
197 |
198 |
199 |
200 |
201 | Codehaus repository
202 | http://repository.codehaus.org/
203 |
204 |
205 |
206 |
--------------------------------------------------------------------------------
/sample-test/pom-cobertura.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | sn-test
8 | testng-test
9 | 1.0-SNAPSHOT
10 |
11 |
12 | java
13 | cobertura
14 | UTF-8
15 | UTF-8
16 |
17 | reuseReports
18 | target/cobertura/cobertura.ser
19 |
20 |
21 |
22 | org.testng
23 | testng
24 | 6.1.1
25 | test
26 |
27 |
28 |
29 | org.slf4j
30 | slf4j-api
31 | 1.6.2
32 |
33 |
34 | org.slf4j
35 | jcl-over-slf4j
36 | 1.6.2
37 |
38 |
39 | ch.qos.logback
40 | logback-core
41 | 0.9.29
42 |
43 |
44 | ch.qos.logback
45 | logback-classic
46 | 0.9.29
47 |
48 |
49 |
50 |
51 | org.springframework
52 | spring-context
53 | 3.2.4.RELEASE
54 |
55 |
56 |
57 | org.springframework
58 | spring-webmvc
59 | 3.2.4.RELEASE
60 |
61 |
62 |
63 | com.h2database
64 | h2
65 | 1.4.178
66 |
67 |
68 |
69 | org.springframework
70 | spring-beans
71 | 3.2.4.RELEASE
72 |
73 |
74 | org.springframework
75 | spring-context-support
76 | 3.2.4.RELEASE
77 |
78 |
79 | org.springframework
80 | spring-orm
81 | 3.2.4.RELEASE
82 |
83 |
84 | com.alibaba
85 | druid
86 | 1.0.2
87 |
88 |
89 | org.springframework
90 | spring-test
91 | 3.2.4.RELEASE
92 |
93 |
94 | org.mybatis
95 | mybatis
96 | 3.2.2
97 |
98 |
99 |
100 | org.springframework
101 | spring-oxm
102 | 3.2.4.RELEASE
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 | org.mybatis
113 | mybatis-spring
114 | 1.2.0
115 |
116 |
117 |
118 | javaee
119 | javaee-api
120 | 5
121 | provided
122 |
123 |
124 |
125 | javax.servlet
126 | jstl
127 | 1.2
128 |
129 |
130 |
131 | opensymphony
132 | sitemesh
133 | 2.4.2
134 |
135 |
136 |
137 | org.freemarker
138 | freemarker
139 | 2.3.15
140 |
141 |
142 |
143 | com.alibaba
144 | fastjson
145 | 1.1.41
146 |
147 |
148 |
149 |
150 | org.mockito
151 | mockito-all
152 | 1.8.5
153 | test
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 | org.apache.maven.plugins
162 | maven-surefire-plugin
163 | 2.18.1
164 |
165 | methods
166 | 1
167 |
168 | src/test/resources/testng.xml
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 | org.codehaus.mojo
180 | cobertura-maven-plugin
181 | 2.6
182 |
183 |
184 | html
185 | xml
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 | Codehaus repository
194 | http://repository.codehaus.org/
195 |
196 |
197 |
198 |
--------------------------------------------------------------------------------
/sample-test/pom-jacoco.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | sn-test
8 | testng-test
9 | 1.0-SNAPSHOT
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | org.testng
21 | testng
22 | 6.1.1
23 | test
24 |
25 |
26 |
27 | org.slf4j
28 | slf4j-api
29 | 1.6.2
30 |
31 |
32 | org.slf4j
33 | jcl-over-slf4j
34 | 1.6.2
35 |
36 |
37 | ch.qos.logback
38 | logback-core
39 | 0.9.29
40 |
41 |
42 | ch.qos.logback
43 | logback-classic
44 | 0.9.29
45 |
46 |
47 |
48 | org.jacoco
49 | org.jacoco.agent
50 | runtime
51 | 0.5.3.201107060350
52 | test
53 |
54 |
55 |
56 |
57 |
58 |
59 | org.apache.maven.plugins
60 | maven-surefire-plugin
61 | 2.18.1
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 | target/jacoco.exec
72 |
73 |
74 |
75 |
76 | org.jacoco
77 | jacoco-maven-plugin
78 | 0.5.3.201107060350
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 | org.jacoco
91 | jacoco-maven-plugin
92 | 0.5.3.201107060350
93 |
94 |
95 | org.codehaus.mojo
96 | cobertura-maven-plugin
97 | 2.7
98 |
99 |
100 |
101 |
102 |
103 | Codehaus repository
104 | http://repository.codehaus.org/
105 |
106 |
107 |
108 |
--------------------------------------------------------------------------------
/sample-test/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | sample
7 | sample-parent
8 | 1.0-SNAPSHOT
9 |
10 |
11 | 4.0.0
12 | sample
13 | sample-test
14 | 1.0-SNAPSHOT
15 | war
16 |
17 |
18 | 2.5.1
19 | java
20 | cobertura
21 | UTF-8
22 | UTF-8
23 | target/surefire-reports/junitreports
24 | reuseReports
25 |
26 |
27 |
28 | target/site/cobertura/coverage.xml
29 |
30 |
31 |
32 |
33 | com.github.superproxy
34 | test-data-provider
35 | 0.1.0
36 | test
37 |
38 |
39 |
40 | org.seleniumhq.selenium
41 | selenium-java
42 | 2.47.1
43 | test
44 |
45 |
46 |
47 | net.sf.ehcache
48 | ehcache
49 | 2.10.2
50 |
51 |
52 | net.sf.ehcache
53 | ehcache-core
54 | 2.6.11
55 |
56 |
57 |
58 |
59 | com.github.springtestdbunit
60 | spring-test-dbunit
61 | 1.0.1
62 | test
63 |
64 |
65 |
66 | org.testng
67 | testng
68 | test
69 |
70 |
71 |
72 |
73 | org.dbunit
74 | dbunit
75 | ${dbunitVersion}
76 | test
77 |
78 |
79 |
80 | org.powermock
81 | powermock-api-mockito
82 | test
83 |
84 |
85 | org.powermock
86 | powermock-module-testng
87 | test
88 |
89 |
90 | org.apache.commons
91 | commons-lang3
92 |
93 |
94 |
95 | org.slf4j
96 | slf4j-api
97 |
98 |
99 | org.slf4j
100 | jcl-over-slf4j
101 |
102 |
103 | ch.qos.logback
104 | logback-core
105 |
106 |
107 | ch.qos.logback
108 | logback-classic
109 |
110 |
111 |
112 |
113 | org.springframework
114 | spring-context
115 |
116 |
117 |
118 | org.springframework
119 | spring-webmvc
120 |
121 |
122 |
123 | com.h2database
124 | h2
125 |
126 |
127 |
128 | org.springframework
129 | spring-beans
130 |
131 |
132 | org.springframework
133 | spring-context-support
134 |
135 |
136 | org.springframework
137 | spring-orm
138 |
139 |
140 | com.alibaba
141 | druid
142 |
143 |
144 |
145 | org.mybatis
146 | mybatis
147 |
148 |
149 |
150 | org.mybatis
151 | mybatis-spring
152 |
153 |
154 |
155 | org.unitils
156 | unitils-core
157 | 3.4.2
158 | test
159 |
160 |
161 |
162 |
163 | junit
164 | junit
165 | 4.12
166 | test
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 | org.apache.geronimo.specs
180 | geronimo-servlet_3.0_spec
181 | provided
182 |
183 |
184 |
185 | javax.servlet
186 | jstl
187 | provided
188 |
189 |
190 |
191 | opensymphony
192 | sitemesh
193 |
194 |
195 |
196 | org.freemarker
197 | freemarker
198 |
199 |
200 |
201 | org.mockito
202 | mockito-all
203 | test
204 |
205 |
206 | org.springframework
207 | spring-test
208 |
209 |
210 | com.alibaba
211 | fastjson
212 |
213 |
214 | org.springframework.boot
215 | spring-boot-autoconfigure
216 | 1.2.6.RELEASE
217 | test
218 |
219 |
220 | org.eclipse.jetty
221 | jetty-server
222 | 9.3.5.v20151012
223 | test
224 |
225 |
226 | org.mortbay.jetty
227 | jetty
228 | 6.1.25
229 | test
230 |
231 |
232 | org.eclipse.jetty
233 | jetty-http
234 | 9.3.5.v20151012
235 | test
236 |
237 |
238 | org.eclipse.jetty
239 | jetty-util
240 | 9.3.5.v20151012
241 | test
242 |
243 |
244 | org.eclipse.jetty
245 | jetty-util
246 | 9.2.13.v20150730
247 | test
248 |
249 |
250 |
251 |
--------------------------------------------------------------------------------
/sample-test/show_test.bat:
--------------------------------------------------------------------------------
1 | mvn test
2 |
3 | mvn sonar:sonar
--------------------------------------------------------------------------------
/sample-test/src/main/java/config/cache/CacheConfig.java:
--------------------------------------------------------------------------------
1 | package config.cache;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 | import org.springframework.cache.CacheManager;
6 | import org.springframework.cache.ehcache.EhCacheCacheManager;
7 | import org.springframework.cache.ehcache.EhCacheManagerFactoryBean;
8 | import org.springframework.context.annotation.Bean;
9 | import org.springframework.context.annotation.Configuration;
10 | import org.springframework.core.io.ClassPathResource;
11 |
12 | @Configuration
13 | //@Profile("prod")
14 | public class CacheConfig {
15 |
16 | private static final Logger log = LoggerFactory.getLogger(CacheConfig.class);
17 |
18 | @Bean
19 | public CacheManager cacheManager() {
20 | log.debug("Cache manager is ehCacheCacheManager");
21 | return new EhCacheCacheManager(ehCacheCacheManager().getObject());
22 | }
23 |
24 | @Bean
25 | public EhCacheManagerFactoryBean ehCacheCacheManager() {
26 | EhCacheManagerFactoryBean cmfb = new EhCacheManagerFactoryBean();
27 | cmfb.setConfigLocation(new ClassPathResource("ehcache.xml"));
28 | cmfb.setShared(true);
29 | return cmfb;
30 | }
31 |
32 | }
--------------------------------------------------------------------------------
/sample-test/src/main/java/controller/ErrorController.java:
--------------------------------------------------------------------------------
1 | package controller;
2 |
3 | import org.springframework.stereotype.Controller;
4 | import org.springframework.web.bind.annotation.RequestMapping;
5 |
6 | import javax.servlet.http.HttpServletRequest;
7 |
8 | @Controller
9 | @RequestMapping("/")
10 | public class ErrorController {
11 |
12 | @RequestMapping("error")
13 | public String error(HttpServletRequest request) {
14 | return "error.ftl";
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/sample-test/src/main/java/controller/SimpleController.java:
--------------------------------------------------------------------------------
1 | package controller;
2 |
3 | import org.springframework.http.HttpHeaders;
4 | import org.springframework.http.HttpStatus;
5 | import org.springframework.http.MediaType;
6 | import org.springframework.http.ResponseEntity;
7 | import org.springframework.stereotype.Controller;
8 | import org.springframework.ui.Model;
9 | import org.springframework.ui.ModelMap;
10 | import org.springframework.web.bind.annotation.RequestMapping;
11 | import org.springframework.web.bind.annotation.RequestMethod;
12 | import org.springframework.web.bind.annotation.ResponseBody;
13 | import org.springframework.web.servlet.ModelAndView;
14 |
15 | import javax.servlet.http.HttpServletRequest;
16 | import javax.servlet.http.HttpServletResponse;
17 | import java.io.IOException;
18 | import java.io.PrintWriter;
19 |
20 | @Controller
21 | public class SimpleController {
22 |
23 | @RequestMapping(value = "/testModelAndView", method = RequestMethod.GET)
24 | public ModelAndView testModelAndView() {
25 | ModelAndView modelAndView = new ModelAndView("test2");
26 | modelAndView.addObject("ss");
27 | return modelAndView;
28 | }
29 |
30 | @RequestMapping(value = "/testVoid", method = RequestMethod.GET)
31 | public void testVoid(HttpServletRequest request, HttpServletResponse response) throws IOException {
32 | try {
33 | PrintWriter writer = response.getWriter();
34 | writer.write("hello");
35 | writer.flush();
36 | writer.close();
37 | } catch (IOException e) {
38 | e.printStackTrace();
39 | }
40 | }
41 |
42 | @RequestMapping(value = "/testHello", method = RequestMethod.GET)
43 | public String testHello(String msg, Model model) {
44 | model.addAttribute("msg", "hi");
45 | return "index";
46 | }
47 |
48 | @RequestMapping(value = "/testEcho", method = RequestMethod.GET)
49 | public String testEcho(String msg, ModelMap model) {
50 | model.addAttribute("msg", msg);
51 | return "index";
52 | }
53 |
54 |
55 | @RequestMapping(value = "/testResponseBody", method = RequestMethod.GET)
56 | @ResponseBody
57 | public String testResponseBody() {
58 | return "{json:\"abc\"}";
59 | }
60 |
61 | @RequestMapping(value = "/testReponseEntity", method = RequestMethod.GET)
62 | public ResponseEntity testReponseEntity() {
63 | HttpHeaders headers = new HttpHeaders();
64 | headers.setContentType(MediaType.TEXT_PLAIN);
65 | return new ResponseEntity("The String ResponseBody with custom header Content-Type=text/plain",
66 | headers, HttpStatus.OK);
67 | }
68 |
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/sample-test/src/main/java/controller/login/LoginController.java:
--------------------------------------------------------------------------------
1 | package controller.login;
2 |
3 | import model.user.User;
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.stereotype.Controller;
6 | import org.springframework.ui.ModelMap;
7 | import org.springframework.util.StringUtils;
8 | import org.springframework.web.bind.annotation.RequestMapping;
9 | import org.springframework.web.bind.annotation.RequestMethod;
10 | import service.user.UserService;
11 |
12 | import javax.servlet.http.HttpServletRequest;
13 | import javax.servlet.http.HttpServletResponse;
14 |
15 | /**
16 | * 登陆服务
17 | */
18 | @Controller
19 | public class LoginController {
20 |
21 | @Autowired
22 | private UserService userService;
23 |
24 |
25 | /**
26 | * 登录页面
27 | *
28 | * @return
29 | */
30 | @RequestMapping(value = "/login", method = RequestMethod.GET)
31 | public String login() {
32 | return "login";
33 | }
34 |
35 | /**
36 | * 登录验证
37 | *
38 | * @param userName
39 | * @param password
40 | * @param validate
41 | * @param request
42 | * @return
43 | */
44 | @RequestMapping("/logon")
45 | public String logon(String userName, String password, String validate,
46 | HttpServletRequest request,
47 | HttpServletResponse response, ModelMap model) {
48 | model.addAttribute("userName", userName);
49 | if (StringUtils.isEmpty(validate)) {
50 | model.addAttribute("message", "验证码不能为空");
51 | return "login";
52 | }
53 |
54 | if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(password)) {
55 | model.addAttribute("message", "用户名或密码不能为空");
56 | return "login";
57 | }
58 |
59 | User user;
60 | try {
61 | user = userService.queryUser(userName, password);
62 | } catch (Exception e) {
63 | return "error";
64 | }
65 | if (user != null) {
66 | return "index";
67 | } else {
68 | model.addAttribute("message", "用户名或密码不正确");
69 | return "login";
70 | }
71 | }
72 | }
--------------------------------------------------------------------------------
/sample-test/src/main/java/controller/order/OrderController.java:
--------------------------------------------------------------------------------
1 | package controller.order;
2 |
3 | import model.order.Order;
4 | import org.springframework.stereotype.Controller;
5 | import org.springframework.ui.Model;
6 | import org.springframework.web.bind.annotation.RequestMapping;
7 |
8 | import javax.servlet.http.HttpServletRequest;
9 |
10 | @Controller
11 | public class OrderController {
12 |
13 | @RequestMapping("/order/create")
14 | public String addOrder(Model model, String item, HttpServletRequest request) {
15 | Object order = request.getSession().getAttribute("order");
16 | if (order == null) {
17 | order = new Order();
18 | request.getSession().setAttribute("order", order);
19 | }
20 | ((Order) order).addItem(item);
21 | return "order/index";
22 | }
23 |
24 |
25 | /**
26 | * 界面
27 | *
28 | * @return
29 | */
30 | @RequestMapping("/order/")
31 | public String index() {
32 | return "order/index";
33 | }
34 |
35 |
36 | /**
37 | * 界面
38 | *
39 | * @return
40 | */
41 | @RequestMapping("/order/add")
42 | public String add() {
43 | return "order/add";
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/sample-test/src/main/java/dao/user/UserMapper.java:
--------------------------------------------------------------------------------
1 | package dao.user;
2 |
3 | import model.user.User;
4 | import org.apache.ibatis.annotations.*;
5 |
6 | import java.util.List;
7 |
8 | public interface UserMapper {
9 | @Select("SELECT * FROM users WHERE name = #{username} AND password=#{password}")
10 | User query(@Param("username")
11 | String userName, @Param("password")
12 | String password);
13 | @Select("SELECT * FROM users WHERE name = #{username}")
14 | User queryByUserName(@Param("username")
15 | String userName);
16 |
17 | @Update("UPDATE users SET age = #{age} WHERE name = #{name}")
18 | int update(User user);
19 |
20 | @Select("SELECT * FROM users")
21 | List getAllUsers();
22 |
23 | @Delete("DELETE FROM users WHERE name = #{username}")
24 | int delete(@Param("username") String userName);
25 |
26 | @Insert("INSERT INTO users(name, password, age) VALUES(#{name}, #{password}, #{age})")
27 | int create(User user);
28 | }
29 |
--------------------------------------------------------------------------------
/sample-test/src/main/java/model/order/Order.java:
--------------------------------------------------------------------------------
1 | package model.order;
2 |
3 | import java.io.Serializable;
4 | import java.util.ArrayList;
5 | import java.util.List;
6 |
7 | public class Order implements Serializable {
8 |
9 | private List items = new ArrayList();
10 |
11 |
12 | public void addItem(String item) {
13 | items.add(item);
14 | }
15 |
16 | public String[] getItems() {
17 | return items.toArray(new String[0]);
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/sample-test/src/main/java/model/user/User.java:
--------------------------------------------------------------------------------
1 | package model.user;
2 |
3 | import org.apache.commons.lang3.builder.ToStringBuilder;
4 |
5 | import java.io.Serializable;
6 |
7 | public class User implements Serializable {
8 | private String name;
9 | private String password;
10 | private int age;
11 | private int rank;
12 |
13 | public User(String name, String password, int age) {
14 | this.age = age;
15 | this.name = name;
16 | this.password = password;
17 | }
18 |
19 | public User(String name, String password) {
20 | this.name = name;
21 | this.password = password;
22 | }
23 |
24 |
25 | public int getRank() {
26 | return rank;
27 | }
28 |
29 | public void setRank(int rank) {
30 | this.rank = rank;
31 | }
32 |
33 | public String getPassword() {
34 | return password;
35 | }
36 |
37 | public void setPassword(String password) {
38 | this.password = password;
39 | }
40 |
41 | public User(int age, String name) {
42 | this.age = age;
43 | this.name = name;
44 | }
45 |
46 | public User() {
47 | }
48 |
49 | public int getAge() {
50 | return age;
51 | }
52 |
53 | public void setAge(int age) {
54 | this.age = age;
55 | }
56 |
57 | public String getName() {
58 | return name;
59 | }
60 |
61 | public void setName(String name) {
62 | this.name = name;
63 | }
64 |
65 | @Override
66 | public String toString() {
67 | return ToStringBuilder.reflectionToString(this);
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/sample-test/src/main/java/service/user/UserService.java:
--------------------------------------------------------------------------------
1 | package service.user;
2 |
3 | import model.user.User;
4 |
5 | public interface UserService {
6 | User queryUser(String userName, String password) throws Exception;
7 |
8 | User queryUser(String userName);
9 |
10 | boolean addUser(User user);
11 | boolean updateUser(User user);
12 |
13 | /**
14 | * 计算用户等级
15 | *
16 | * @param user 用户
17 | * @return 返回用户等级,数字表示
18 | */
19 | int calRank(User user);
20 | }
21 |
--------------------------------------------------------------------------------
/sample-test/src/main/java/service/user/impl/UserServiceImpl.java:
--------------------------------------------------------------------------------
1 | package service.user.impl;
2 |
3 | import cache.CommonCacheManager;
4 | import dao.user.UserMapper;
5 | import model.user.User;
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.cache.CacheManager;
8 | import org.springframework.cache.annotation.CacheConfig;
9 | import org.springframework.cache.annotation.CacheEvict;
10 | import org.springframework.cache.annotation.Cacheable;
11 | import org.springframework.stereotype.Service;
12 | import service.user.UserService;
13 |
14 | import javax.annotation.Resource;
15 |
16 | @CacheConfig(cacheNames = {"test"})
17 | @Service
18 | public class UserServiceImpl implements UserService, CommonCacheManager {
19 |
20 | @Resource
21 | private UserMapper userMapper;
22 |
23 | @Autowired
24 | private CacheManager cacheManager;
25 |
26 | @Override
27 | public boolean addUser(User user) {
28 | return userMapper.create(user) > 0;
29 | }
30 |
31 | @Override
32 | public int calRank(User user) {
33 | if (user.getAge() < 10) {
34 | return 0;
35 | }
36 |
37 | if (user.getAge() < 20) {
38 | return 1;
39 | }
40 |
41 | if (user.getAge() < 30) {
42 | return 2;
43 | }
44 |
45 | return 3;
46 | }
47 |
48 | @Override
49 | public User queryUser(String userName, String password) {
50 | return userMapper.query(userName, password);
51 | }
52 |
53 | @Override
54 | @Cacheable(key = "'user_'+#userName")
55 | public User queryUser(String userName) {
56 | System.out.println("query user");
57 | return userMapper.queryByUserName(userName);
58 | }
59 |
60 | @Override
61 | @CacheEvict(value = "test", key = "'user_'+#user.name")
62 | public boolean updateUser(User user) {
63 | return userMapper.update(user) > 0;
64 | }
65 |
66 | @Override
67 | public void removeCache(String key) {
68 | cacheManager.getCache("test").evict(key);
69 | }
70 |
71 | @Override
72 | public void addCache(String key, User object) {
73 | cacheManager.getCache("test").put(key, object);
74 | }
75 |
76 | @Override
77 | public User getCache(String key) {
78 | return (User) cacheManager.getCache("test").get(key);
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/sample-test/src/main/java/util/SpringInitByWeb.java:
--------------------------------------------------------------------------------
1 | package util;
2 |
3 | import org.springframework.context.ApplicationContext;
4 | import org.springframework.web.context.WebApplicationContext;
5 | import org.springframework.web.context.support.WebApplicationContextUtils;
6 |
7 | import javax.servlet.ServletContextEvent;
8 | import javax.servlet.ServletContextListener;
9 |
10 | public class SpringInitByWeb implements ServletContextListener {
11 | private static WebApplicationContext springContext;
12 |
13 | public static ApplicationContext getApplicationContext() {
14 | return springContext;
15 | }
16 |
17 | public void contextInitialized(ServletContextEvent event) {
18 | springContext = WebApplicationContextUtils.getWebApplicationContext(event.getServletContext());
19 | }
20 |
21 | public void contextDestroyed(ServletContextEvent event) {
22 | }
23 |
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/sample-test/src/main/resources/applicationContext.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/sample-test/src/main/resources/cache/spring-cache.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/sample-test/src/main/resources/dao/dao.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/sample-test/src/main/resources/dao/datasource-prod.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
16 |
17 |
18 |
19 |
20 |
21 |
22 | java:comp/env/sample-test
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/sample-test/src/main/resources/dispatcher-servlet.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
25 |
26 |
27 |
28 | 0
29 | UTF-8
30 | 0.##########
31 | yyyy-MM-dd HH:mm:ss
32 | true
33 | ignore
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/sample-test/src/main/resources/service/spring-service.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/sample-test/src/main/webapp/WEB-INF/decorators.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | /static/*
5 | /common/*
6 |
7 |
8 |
9 | /login
10 | /logon
11 | /logout
12 |
13 |
14 | /order/*
15 |
16 |
17 |
18 | /*
19 |
20 |
21 |
--------------------------------------------------------------------------------
/sample-test/src/main/webapp/WEB-INF/ftl/login.ftl:
--------------------------------------------------------------------------------
1 |
15 |
16 |
--------------------------------------------------------------------------------
/sample-test/src/main/webapp/WEB-INF/ftl/order/add.ftl:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/sample-test/src/main/webapp/WEB-INF/ftl/order/index.ftl:
--------------------------------------------------------------------------------
1 | <#if Session["order"]?exists>
2 | 订单
3 | <#list Session["order"].items as item>
4 | ${item}
5 | #list>
6 | #if>
7 |
--------------------------------------------------------------------------------
/sample-test/src/main/webapp/WEB-INF/layouts/default.jsp:
--------------------------------------------------------------------------------
1 | <%@ page contentType="text/html;charset=UTF-8" %>
2 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
3 | <%@ taglib prefix="sitemesh"
4 | uri="http://www.opensymphony.com/sitemesh/decorator" %>
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
16 |
17 |
18 |
19 |
20 |
23 |
24 |
25 |
26 |
27 | <%@ include file="/WEB-INF/layouts/footer.jsp" %>
28 |
29 |
30 |
--------------------------------------------------------------------------------
/sample-test/src/main/webapp/WEB-INF/layouts/footer.jsp:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/sample-test/src/main/webapp/WEB-INF/layouts/header.jsp:
--------------------------------------------------------------------------------
1 | <%@ page contentType="text/html;charset=UTF-8" %>
2 | 首页
3 |
--------------------------------------------------------------------------------
/sample-test/src/main/webapp/WEB-INF/layouts/login_template.jsp:
--------------------------------------------------------------------------------
1 | <%@ page contentType="text/html;charset=UTF-8" %>
2 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
3 | <%@ taglib prefix="sitemesh"
4 | uri="http://www.opensymphony.com/sitemesh/decorator" %>
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | <%@ include file="/WEB-INF/layouts/footer.jsp" %>
21 |
22 |
23 |
--------------------------------------------------------------------------------
/sample-test/src/main/webapp/WEB-INF/layouts/order_tpl.jsp:
--------------------------------------------------------------------------------
1 | <%@ page contentType="text/html;charset=UTF-8" %>
2 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
3 | <%@ taglib prefix="sitemesh"
4 | uri="http://www.opensymphony.com/sitemesh/decorator" %>
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 | <%@ include file="/WEB-INF/layouts/header.jsp" %>
20 |
21 | <%@ include file="/WEB-INF/layouts/footer.jsp" %>
22 |
23 |
24 |
--------------------------------------------------------------------------------
/sample-test/src/main/webapp/WEB-INF/web.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
11 | DruidStatView
12 | com.alibaba.druid.support.http.StatViewServlet
13 |
14 |
15 | DruidStatView
16 | /druid/*
17 |
18 |
19 |
20 | contextConfigLocation
21 | classpath:applicationContext.xml
22 |
23 |
24 |
25 | org.springframework.web.context.ContextLoaderListener
26 |
27 |
28 |
29 | Set Character Encoding
30 | org.springframework.web.filter.CharacterEncodingFilter
31 |
32 | encoding
33 | UTF-8
34 |
35 |
36 | forceEncoding
37 | true
38 |
39 |
40 |
41 | Set Character Encoding
42 | /*
43 |
44 |
45 |
46 | dispatcher
47 | org.springframework.web.servlet.DispatcherServlet
48 |
49 | contextConfigLocation
50 | classpath:dispatcher-servlet.xml
51 |
52 | 1
53 |
54 |
55 | dispatcher
56 | /
57 |
58 |
59 |
60 |
61 | sitemesh
62 | com.opensymphony.sitemesh.webapp.SiteMeshFilter
63 |
64 |
65 | sitemesh
66 | /*
67 |
68 |
69 |
70 |
71 | authFilter
72 | filter.AuthFilter2
73 |
74 | logoutUrl
75 | http://www.yxz.com:8180/logout
76 |
77 |
78 | redirectUrl
79 | http://passport.yxz.com:8080/login?target=
80 |
81 |
82 | validateTicketUrl
83 | http://passport.yxz.com:8080/validate
84 |
85 |
86 |
87 | authFilter
88 | /*
89 |
90 |
91 |
92 |
93 | util.SpringInitByWeb
94 |
95 |
96 |
97 |
98 | /
99 |
100 |
101 |
102 |
--------------------------------------------------------------------------------
/sample-test/src/main/webapp/index.jsp:
--------------------------------------------------------------------------------
1 | <%--
2 | Created by IntelliJ IDEA.
3 | User: 14120295
4 | Date: 2015/8/24
5 | Time: 10:56
6 | To change this template use File | Settings | File Templates.
7 | --%>
8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %>
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/sample-test/src/main/webapp/static/js/jquery/jquery.cookie.js:
--------------------------------------------------------------------------------
1 | /*!
2 | * jQuery Cookie Plugin v1.4.1
3 | * https://github.com/carhartl/jquery-cookie
4 | *
5 | * Copyright 2013 Klaus Hartl
6 | * Released under the MIT license
7 | */
8 | (function (factory) {
9 | if (typeof define === 'function' && define.amd) {
10 | // AMD
11 | define(['jquery'], factory);
12 | } else if (typeof exports === 'object') {
13 | // CommonJS
14 | factory(require('jquery'));
15 | } else {
16 | // Browser globals
17 | factory(jQuery);
18 | }
19 | }(function ($) {
20 |
21 | var pluses = /\+/g;
22 |
23 | function encode(s) {
24 | return config.raw ? s : encodeURIComponent(s);
25 | }
26 |
27 | function decode(s) {
28 | return config.raw ? s : decodeURIComponent(s);
29 | }
30 |
31 | function stringifyCookieValue(value) {
32 | return encode(config.json ? JSON.stringify(value) : String(value));
33 | }
34 |
35 | function parseCookieValue(s) {
36 | if (s.indexOf('"') === 0) {
37 | // This is test quoted cookie as according to RFC2068, unescape...
38 | s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
39 | }
40 |
41 | try {
42 | // Replace server-side written pluses with spaces.
43 | // If we can't decode the cookie, ignore it, it's unusable.
44 | // If we can't parse the cookie, ignore it, it's unusable.
45 | s = decodeURIComponent(s.replace(pluses, ' '));
46 | return config.json ? JSON.parse(s) : s;
47 | } catch (e) {
48 | }
49 | }
50 |
51 | function read(s, converter) {
52 | var value = config.raw ? s : parseCookieValue(s);
53 | return $.isFunction(converter) ? converter(value) : value;
54 | }
55 |
56 | var config = $.cookie = function (key, value, options) {
57 |
58 | // Write
59 |
60 | if (value !== undefined && !$.isFunction(value)) {
61 | options = $.extend({}, config.defaults, options);
62 |
63 | if (typeof options.expires === 'number') {
64 | var days = options.expires, t = options.expires = new Date();
65 | t.setTime(+t + days * 864e+5);
66 | }
67 |
68 | return (document.cookie = [
69 | encode(key), '=', stringifyCookieValue(value),
70 | options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
71 | options.path ? '; path=' + options.path : '',
72 | options.domain ? '; domain=' + options.domain : '',
73 | options.secure ? '; secure' : ''
74 | ].join(''));
75 | }
76 |
77 | // Read
78 |
79 | var result = key ? undefined : {};
80 |
81 | // To prevent the for loop in the first place assign an empty array
82 | // in case there are no cookies at all. Also prevents odd result when
83 | // calling $.cookie().
84 | var cookies = document.cookie ? document.cookie.split('; ') : [];
85 |
86 | for (var i = 0, l = cookies.length; i < l; i++) {
87 | var parts = cookies[i].split('=');
88 | var name = decode(parts.shift());
89 | var cookie = parts.join('=');
90 |
91 | if (key && key === name) {
92 | // If second argument (value) is test function it's test converter...
93 | result = read(cookie, value);
94 | break;
95 | }
96 |
97 | // Prevent storing test cookie that we couldn't decode.
98 | if (!key && (cookie = read(cookie)) !== undefined) {
99 | result[name] = cookie;
100 | }
101 | }
102 |
103 | return result;
104 | };
105 |
106 | config.defaults = {};
107 |
108 | $.removeCookie = function (key, options) {
109 | if ($.cookie(key) === undefined) {
110 | return false;
111 | }
112 |
113 | // Must not alter options, thus extending test fresh object...
114 | $.cookie(key, '', $.extend({}, options, {expires: -1}));
115 | return !$.cookie(key);
116 | };
117 |
118 | }));
119 |
--------------------------------------------------------------------------------
/sample-test/src/test/java/app/AppTest.java:
--------------------------------------------------------------------------------
1 | package app;
2 |
3 | import controller.SimpleController;
4 | import org.springframework.boot.SpringApplication;
5 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
6 | import org.springframework.boot.test.SpringApplicationConfiguration;
7 | import org.springframework.boot.test.WebIntegrationTest;
8 | import org.springframework.test.context.web.WebAppConfiguration;
9 | import org.testng.annotations.Test;
10 | import service.BaseTest;
11 |
12 | @EnableAutoConfiguration
13 | //@ImportXml("classpath:sbeans.xml")
14 | //@SpringApplicationConfiguration(classes = {HomeController.class, LoginController.class})
15 | @SpringApplicationConfiguration(classes = {SimpleController.class})
16 | @WebAppConfiguration
17 | @WebIntegrationTest
18 | @Test
19 | public class AppTest extends BaseTest {
20 |
21 | // /**
22 | // * 定制 EmbeddedServletContainerFactory
23 | // *
24 | // * @return
25 | // */
26 | // @Bean
27 | // public EmbeddedServletContainerFactory servletContainer() {
28 | // TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
29 | // factory.setPort(9000);
30 | // factory.setSessionTimeout(10, TimeUnit.MINUTES);
31 | //// factory.addErrorPages(new ErrorPage(HttpStatus.404, "/notfound.html"));
32 | // return factory;
33 | // }
34 |
35 | public static void main(String[] args) {
36 | // 必须是注解的类
37 | // Caused by: org.springframework.context.ApplicationContextException:
38 | // Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
39 | SpringApplication.run(AppTest.class, args);
40 | }
41 | }
--------------------------------------------------------------------------------
/sample-test/src/test/java/app/Application.java:
--------------------------------------------------------------------------------
1 | package app;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 |
7 | // same as @Configuration @EnableAutoConfiguration @ComponentScan
8 | @SpringBootApplication
9 | public class Application {
10 | public static void main(String[] args) {
11 | SpringApplication.run(Application.class, args);
12 | }
13 |
14 | }
--------------------------------------------------------------------------------
/sample-test/src/test/java/app/HomeController.java:
--------------------------------------------------------------------------------
1 | package app;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
5 | import org.springframework.boot.test.IntegrationTest;
6 | import org.springframework.stereotype.Controller;
7 | import org.springframework.web.bind.annotation.RequestMapping;
8 | import org.springframework.web.bind.annotation.ResponseBody;
9 |
10 | @EnableAutoConfiguration
11 | @IntegrationTest
12 | @Controller
13 | public class HomeController {
14 |
15 | @RequestMapping("/")
16 | @ResponseBody
17 | public String home() {
18 | return "s";
19 | }
20 |
21 | public static void main(String[] args) {
22 | SpringApplication.run(HomeController.class, args);
23 | }
24 | }
--------------------------------------------------------------------------------
/sample-test/src/test/java/app/JettryRun.java:
--------------------------------------------------------------------------------
1 | package app;
2 |
3 | import org.eclipse.jetty.server.Server;
4 | import org.mortbay.jetty.webapp.WebAppContext;
5 |
6 | public class JettryRun {
7 |
8 | public static void main(String[] args) throws Exception {
9 | Server server = new Server(8080);
10 | WebAppContext context = new WebAppContext();
11 | context.setContextPath("/myapp");
12 | context.setDescriptor("/WEB-INF/web.xml");
13 | context.setResourceBase("/");
14 | context.setParentLoaderPriority(true);
15 |
16 | server.start();
17 | server.join();
18 | }
19 | }
--------------------------------------------------------------------------------
/sample-test/src/test/java/app/TestApplicationContext.java:
--------------------------------------------------------------------------------
1 | package app;
2 |
3 | import org.junit.runner.RunWith;
4 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
5 | import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
6 | import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
7 | import org.springframework.boot.test.IntegrationTest;
8 | import org.springframework.boot.test.SpringApplicationConfiguration;
9 | import org.springframework.context.annotation.Configuration;
10 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
11 | import org.springframework.test.context.web.WebAppConfiguration;
12 |
13 | import java.util.concurrent.TimeUnit;
14 |
15 | @RunWith(SpringJUnit4ClassRunner.class)
16 | @SpringApplicationConfiguration(classes = {HomeController.class})
17 | @WebAppConfiguration
18 | @EnableAutoConfiguration
19 | @IntegrationTest
20 | @Configuration
21 | public class TestApplicationContext {
22 |
23 | // @Bean
24 | public EmbeddedServletContainerFactory servletContainer() {
25 | TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
26 | factory.setPort(9000);
27 | factory.setSessionTimeout(10, TimeUnit.MINUTES);
28 | //factory.addErrorPages(new ErrorPage(HttpStatus.404, "/notfound.html"));
29 | return factory;
30 | }
31 |
32 | }
--------------------------------------------------------------------------------
/sample-test/src/test/java/config/cache/CacheConfigDev.java:
--------------------------------------------------------------------------------
1 | package config.cache;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 | import org.springframework.cache.CacheManager;
6 | import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
7 | import org.springframework.context.annotation.Bean;
8 | import org.springframework.context.annotation.Configuration;
9 | import org.springframework.context.annotation.Profile;
10 |
11 | @Configuration
12 | @Profile("dev")
13 | public class CacheConfigDev {
14 |
15 | private static final Logger log = LoggerFactory.getLogger(CacheConfigDev.class);
16 |
17 | @Bean
18 | public CacheManager concurrentMapCacheManager() {
19 | log.debug("Cache manager is concurrentMapCacheManager");
20 | return new ConcurrentMapCacheManager("movieFindCache");
21 | }
22 |
23 | }
--------------------------------------------------------------------------------
/sample-test/src/test/java/config/cache/CacheManagerTest.java:
--------------------------------------------------------------------------------
1 | package config.cache;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.cache.Cache;
7 | import org.springframework.cache.CacheManager;
8 | import org.springframework.context.annotation.Configuration;
9 | import org.springframework.context.annotation.Import;
10 | import org.springframework.test.context.ActiveProfiles;
11 | import org.springframework.test.context.ContextConfiguration;
12 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
13 | import org.testng.Assert;
14 |
15 | @RunWith(SpringJUnit4ClassRunner.class)
16 | @ContextConfiguration()
17 | @ActiveProfiles("dev")
18 | public class CacheManagerTest {
19 |
20 | @Configuration
21 | // @EnableCaching
22 | @Import({CacheConfigDev.class, CacheConfig.class})
23 | public static class AppConfig {
24 | }
25 |
26 | @Autowired
27 | private CacheManager cacheManager;
28 |
29 | @Test
30 | public void test() {
31 | for (String cacheName : cacheManager.getCacheNames()) {
32 | System.out.println("cache Name:" + cacheName);
33 |
34 | }
35 |
36 | Cache cache = cacheManager.getCache("movieFindCache");
37 | cache.put("a", "1");
38 | Assert.assertEquals(cache.get("a").get(), "1");
39 | }
40 |
41 | }
--------------------------------------------------------------------------------
/sample-test/src/test/java/controller/BaseContorllerMockTest.java:
--------------------------------------------------------------------------------
1 | package controller;
2 |
3 | import org.springframework.mock.web.MockHttpServletRequest;
4 | import org.springframework.mock.web.MockHttpServletResponse;
5 | import org.springframework.mock.web.MockHttpSession;
6 | import org.springframework.test.context.ContextConfiguration;
7 | import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
8 | import org.testng.annotations.BeforeMethod;
9 |
10 | import java.util.Hashtable;
11 | import java.util.Map;
12 |
13 | @ContextConfiguration(locations = {
14 | "classpath:service/mockservice.xml",
15 | "classpath:dispatcher-servlet.xml",
16 | })
17 | public abstract class BaseContorllerMockTest extends AbstractTestNGSpringContextTests {
18 |
19 | protected MockHttpServletRequest request;
20 | protected MockHttpServletResponse response;
21 |
22 | protected Map