Commit 152dbccd1425e42cbb075c5f2edc6ea7eab88db4
1 parent
ed1ca6ee
注释掉 单元测试类
Showing
1 changed file
with
179 additions
and
179 deletions
jeecg-boot/jeecg-boot-module-system/src/test/java/org/jeecg/modules/system/test/SysUserTest.java
1 | -//package org.jeecg.modules.system.test; | ||
2 | -// | ||
3 | -//import org.jeecg.JeecgSystemApplication; | ||
4 | -//import org.jeecg.common.constant.CommonConstant; | ||
5 | -//import org.jeecg.common.system.util.JwtUtil; | ||
6 | -//import org.jeecg.common.util.RedisUtil; | ||
7 | -//import org.jeecg.common.util.RestUtil; | ||
8 | -//import org.junit.Test; | ||
9 | -//import org.junit.runner.RunWith; | ||
10 | -//import org.springframework.beans.factory.annotation.Autowired; | ||
11 | -//import org.springframework.boot.test.context.SpringBootTest; | ||
12 | -//import org.springframework.test.context.ActiveProfiles; | ||
13 | -//import org.springframework.test.context.junit4.SpringRunner; | ||
14 | -//import org.springframework.http.HttpHeaders; | ||
15 | -//import org.springframework.http.HttpMethod; | ||
16 | -//import org.springframework.http.MediaType; | ||
17 | -//import com.alibaba.fastjson.JSONObject; | ||
18 | -//import org.springframework.http.ResponseEntity; | ||
19 | -// | ||
20 | -///** | ||
21 | -// * 系统用户单元测试 | ||
22 | -// */ | ||
23 | -//@RunWith(SpringRunner.class) | ||
24 | -//@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,classes = JeecgSystemApplication.class) | ||
25 | -//@SuppressWarnings({"FieldCanBeLocal", "SpringJavaAutowiredMembersInspection"}) | ||
26 | -//public class SysUserTest { | ||
27 | -// /** | ||
28 | -// * 测试地址:实际使用时替换成你自己的地址 | ||
29 | -// */ | ||
30 | -// private final String BASE_URL = "http://localhost:8080/jeecg-boot/sys/user/"; | ||
31 | -// //测试:用户名和密码 | ||
32 | -// private final String USERNAME = "admin"; | ||
33 | -// private final String PASSWORD = "123456"; | ||
34 | -// @Autowired | ||
35 | -// private RedisUtil redisUtil; | ||
36 | -// | ||
37 | -// /** | ||
38 | -// * 测试用例:查询记录 | ||
39 | -// */ | ||
40 | -// @Test | ||
41 | -// public void testQuery() { | ||
42 | -// // 请求地址 | ||
43 | -// String url = BASE_URL + "list"; | ||
44 | -// // 请求 Header (用于传递Token) | ||
45 | -// HttpHeaders headers = this.getHeaders(); | ||
46 | -// // 请求方式是 GET 代表获取数据 | ||
47 | -// HttpMethod method = HttpMethod.GET; | ||
48 | -// | ||
49 | -// System.out.println("请求地址:" + url); | ||
50 | -// System.out.println("请求方式:" + method); | ||
51 | -// | ||
52 | -// // 利用 RestUtil 请求该url | ||
53 | -// ResponseEntity<JSONObject> result = RestUtil.request(url, method, headers, null, null, JSONObject.class); | ||
54 | -// if (result != null && result.getBody() != null) { | ||
55 | -// System.out.println("返回结果:" + result.getBody().toJSONString()); | ||
56 | -// } else { | ||
57 | -// System.out.println("查询失败"); | ||
58 | -// } | ||
59 | -// } | ||
60 | -// | ||
61 | -// /** | ||
62 | -// * 测试用例:新增 | ||
63 | -// */ | ||
64 | -// @Test | ||
65 | -// public void testAdd() { | ||
66 | -// // 请求地址 | ||
67 | -// String url = BASE_URL + "add" ; | ||
68 | -// // 请求 Header (用于传递Token) | ||
69 | -// HttpHeaders headers = this.getHeaders(); | ||
70 | -// // 请求方式是 POST 代表提交新增数据 | ||
71 | -// HttpMethod method = HttpMethod.POST; | ||
72 | -// | ||
73 | -// System.out.println("请求地址:" + url); | ||
74 | -// System.out.println("请求方式:" + method); | ||
75 | -// | ||
76 | -// JSONObject params = new JSONObject(); | ||
77 | -// params.put("username", "wangwuTest"); | ||
78 | -// params.put("password", "123456"); | ||
79 | -// params.put("confirmpassword","123456"); | ||
80 | -// params.put("realname", "单元测试"); | ||
81 | -// params.put("activitiSync", "1"); | ||
82 | -// params.put("userIdentity","1"); | ||
83 | -// params.put("workNo","0025"); | ||
84 | -// | ||
85 | -// System.out.println("请求参数:" + params.toJSONString()); | ||
86 | -// | ||
87 | -// // 利用 RestUtil 请求该url | ||
88 | -// ResponseEntity<JSONObject> result = RestUtil.request(url, method, headers, null, params, JSONObject.class); | ||
89 | -// if (result != null && result.getBody() != null) { | ||
90 | -// System.out.println("返回结果:" + result.getBody().toJSONString()); | ||
91 | -// } else { | ||
92 | -// System.out.println("查询失败"); | ||
93 | -// } | ||
94 | -// } | ||
95 | -// | ||
96 | -// | ||
97 | -// /** | ||
98 | -// * 测试用例:修改 | ||
99 | -// */ | ||
100 | -// @Test | ||
101 | -// public void testEdit() { | ||
102 | -// // 数据Id | ||
103 | -// String dataId = "1331795062924374018"; | ||
104 | -// // 请求地址 | ||
105 | -// String url = BASE_URL + "edit"; | ||
106 | -// // 请求 Header (用于传递Token) | ||
107 | -// HttpHeaders headers = this.getHeaders(); | ||
108 | -// // 请求方式是 PUT 代表提交修改数据 | ||
109 | -// HttpMethod method = HttpMethod.PUT; | ||
110 | -// | ||
111 | -// System.out.println("请求地址:" + url); | ||
112 | -// System.out.println("请求方式:" + method); | ||
113 | -// | ||
114 | -// JSONObject params = new JSONObject(); | ||
115 | -// params.put("username", "wangwuTest"); | ||
116 | -// params.put("realname", "单元测试1111"); | ||
117 | -// params.put("activitiSync", "1"); | ||
118 | -// params.put("userIdentity","1"); | ||
119 | -// params.put("workNo","0025"); | ||
120 | -// params.put("id",dataId); | ||
121 | -// | ||
122 | -// System.out.println("请求参数:" + params.toJSONString()); | ||
123 | -// | ||
124 | -// // 利用 RestUtil 请求该url | ||
125 | -// ResponseEntity<JSONObject> result = RestUtil.request(url, method, headers, null, params, JSONObject.class); | ||
126 | -// if (result != null && result.getBody() != null) { | ||
127 | -// System.out.println("返回结果:" + result.getBody().toJSONString()); | ||
128 | -// } else { | ||
129 | -// System.out.println("查询失败"); | ||
130 | -// } | ||
131 | -// } | ||
132 | -// | ||
133 | -// | ||
134 | -// /** | ||
135 | -// * 测试用例:删除 | ||
136 | -// */ | ||
137 | -// @Test | ||
138 | -// public void testDelete() { | ||
139 | -// // 数据Id | ||
140 | -// String dataId = "1331795062924374018"; | ||
141 | -// // 请求地址 | ||
142 | -// String url = BASE_URL + "delete" + "?id=" + dataId; | ||
143 | -// // 请求 Header (用于传递Token) | ||
144 | -// HttpHeaders headers = this.getHeaders(); | ||
145 | -// // 请求方式是 DELETE 代表删除数据 | ||
146 | -// HttpMethod method = HttpMethod.DELETE; | ||
147 | -// | ||
148 | -// System.out.println("请求地址:" + url); | ||
149 | -// System.out.println("请求方式:" + method); | ||
150 | -// | ||
151 | -// // 利用 RestUtil 请求该url | ||
152 | -// ResponseEntity<JSONObject> result = RestUtil.request(url, method, headers, null, null, JSONObject.class); | ||
153 | -// if (result != null && result.getBody() != null) { | ||
154 | -// System.out.println("返回结果:" + result.getBody().toJSONString()); | ||
155 | -// } else { | ||
156 | -// System.out.println("查询失败"); | ||
157 | -// } | ||
158 | -// } | ||
159 | -// | ||
160 | -// | ||
161 | -// private String getToken() { | ||
162 | -// String token = JwtUtil.sign(USERNAME, PASSWORD); | ||
163 | -// redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token); | ||
164 | -// redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, 60); | ||
165 | -// return token; | ||
166 | -// } | ||
167 | -// | ||
168 | -// private HttpHeaders getHeaders() { | ||
169 | -// String token = this.getToken(); | ||
170 | -// System.out.println("请求Token:" + token); | ||
171 | -// | ||
172 | -// HttpHeaders headers = new HttpHeaders(); | ||
173 | -// String mediaType = MediaType.APPLICATION_JSON_VALUE; | ||
174 | -// headers.setContentType(MediaType.parseMediaType(mediaType)); | ||
175 | -// headers.set("Accept", mediaType); | ||
176 | -// headers.set("X-Access-Token", token); | ||
177 | -// return headers; | ||
178 | -// } | ||
179 | -//} | 1 | +package org.jeecg.modules.system.test; |
2 | + | ||
3 | +import org.jeecg.JeecgSystemApplication; | ||
4 | +import org.jeecg.common.constant.CommonConstant; | ||
5 | +import org.jeecg.common.system.util.JwtUtil; | ||
6 | +import org.jeecg.common.util.RedisUtil; | ||
7 | +import org.jeecg.common.util.RestUtil; | ||
8 | +import org.junit.Test; | ||
9 | +import org.junit.runner.RunWith; | ||
10 | +import org.springframework.beans.factory.annotation.Autowired; | ||
11 | +import org.springframework.boot.test.context.SpringBootTest; | ||
12 | +import org.springframework.test.context.ActiveProfiles; | ||
13 | +import org.springframework.test.context.junit4.SpringRunner; | ||
14 | +import org.springframework.http.HttpHeaders; | ||
15 | +import org.springframework.http.HttpMethod; | ||
16 | +import org.springframework.http.MediaType; | ||
17 | +import com.alibaba.fastjson.JSONObject; | ||
18 | +import org.springframework.http.ResponseEntity; | ||
19 | + | ||
20 | +/** | ||
21 | + * 系统用户单元测试 | ||
22 | + */ | ||
23 | +@RunWith(SpringRunner.class) | ||
24 | +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,classes = JeecgSystemApplication.class) | ||
25 | +@SuppressWarnings({"FieldCanBeLocal", "SpringJavaAutowiredMembersInspection"}) | ||
26 | +public class SysUserTest { | ||
27 | + /** | ||
28 | + * 测试地址:实际使用时替换成你自己的地址 | ||
29 | + */ | ||
30 | + private final String BASE_URL = "http://localhost:8080/jeecg-boot/sys/user/"; | ||
31 | + //测试:用户名和密码 | ||
32 | + private final String USERNAME = "admin"; | ||
33 | + private final String PASSWORD = "123456"; | ||
34 | + @Autowired | ||
35 | + private RedisUtil redisUtil; | ||
36 | + | ||
37 | + /** | ||
38 | + * 测试用例:查询记录 | ||
39 | + */ | ||
40 | + @Test | ||
41 | + public void testQuery() { | ||
42 | + // 请求地址 | ||
43 | + String url = BASE_URL + "list"; | ||
44 | + // 请求 Header (用于传递Token) | ||
45 | + HttpHeaders headers = this.getHeaders(); | ||
46 | + // 请求方式是 GET 代表获取数据 | ||
47 | + HttpMethod method = HttpMethod.GET; | ||
48 | + | ||
49 | + System.out.println("请求地址:" + url); | ||
50 | + System.out.println("请求方式:" + method); | ||
51 | + | ||
52 | + // 利用 RestUtil 请求该url | ||
53 | + ResponseEntity<JSONObject> result = RestUtil.request(url, method, headers, null, null, JSONObject.class); | ||
54 | + if (result != null && result.getBody() != null) { | ||
55 | + System.out.println("返回结果:" + result.getBody().toJSONString()); | ||
56 | + } else { | ||
57 | + System.out.println("查询失败"); | ||
58 | + } | ||
59 | + } | ||
60 | + | ||
61 | + /** | ||
62 | + * 测试用例:新增 | ||
63 | + */ | ||
64 | + @Test | ||
65 | + public void testAdd() { | ||
66 | + // 请求地址 | ||
67 | + String url = BASE_URL + "add" ; | ||
68 | + // 请求 Header (用于传递Token) | ||
69 | + HttpHeaders headers = this.getHeaders(); | ||
70 | + // 请求方式是 POST 代表提交新增数据 | ||
71 | + HttpMethod method = HttpMethod.POST; | ||
72 | + | ||
73 | + System.out.println("请求地址:" + url); | ||
74 | + System.out.println("请求方式:" + method); | ||
75 | + | ||
76 | + JSONObject params = new JSONObject(); | ||
77 | + params.put("username", "wangwuTest"); | ||
78 | + params.put("password", "123456"); | ||
79 | + params.put("confirmpassword","123456"); | ||
80 | + params.put("realname", "单元测试"); | ||
81 | + params.put("activitiSync", "1"); | ||
82 | + params.put("userIdentity","1"); | ||
83 | + params.put("workNo","0025"); | ||
84 | + | ||
85 | + System.out.println("请求参数:" + params.toJSONString()); | ||
86 | + | ||
87 | + // 利用 RestUtil 请求该url | ||
88 | + ResponseEntity<JSONObject> result = RestUtil.request(url, method, headers, null, params, JSONObject.class); | ||
89 | + if (result != null && result.getBody() != null) { | ||
90 | + System.out.println("返回结果:" + result.getBody().toJSONString()); | ||
91 | + } else { | ||
92 | + System.out.println("查询失败"); | ||
93 | + } | ||
94 | + } | ||
95 | + | ||
96 | + | ||
97 | + /** | ||
98 | + * 测试用例:修改 | ||
99 | + */ | ||
100 | + @Test | ||
101 | + public void testEdit() { | ||
102 | + // 数据Id | ||
103 | + String dataId = "1331795062924374018"; | ||
104 | + // 请求地址 | ||
105 | + String url = BASE_URL + "edit"; | ||
106 | + // 请求 Header (用于传递Token) | ||
107 | + HttpHeaders headers = this.getHeaders(); | ||
108 | + // 请求方式是 PUT 代表提交修改数据 | ||
109 | + HttpMethod method = HttpMethod.PUT; | ||
110 | + | ||
111 | + System.out.println("请求地址:" + url); | ||
112 | + System.out.println("请求方式:" + method); | ||
113 | + | ||
114 | + JSONObject params = new JSONObject(); | ||
115 | + params.put("username", "wangwuTest"); | ||
116 | + params.put("realname", "单元测试1111"); | ||
117 | + params.put("activitiSync", "1"); | ||
118 | + params.put("userIdentity","1"); | ||
119 | + params.put("workNo","0025"); | ||
120 | + params.put("id",dataId); | ||
121 | + | ||
122 | + System.out.println("请求参数:" + params.toJSONString()); | ||
123 | + | ||
124 | + // 利用 RestUtil 请求该url | ||
125 | + ResponseEntity<JSONObject> result = RestUtil.request(url, method, headers, null, params, JSONObject.class); | ||
126 | + if (result != null && result.getBody() != null) { | ||
127 | + System.out.println("返回结果:" + result.getBody().toJSONString()); | ||
128 | + } else { | ||
129 | + System.out.println("查询失败"); | ||
130 | + } | ||
131 | + } | ||
132 | + | ||
133 | + | ||
134 | + /** | ||
135 | + * 测试用例:删除 | ||
136 | + */ | ||
137 | + @Test | ||
138 | + public void testDelete() { | ||
139 | + // 数据Id | ||
140 | + String dataId = "1331795062924374018"; | ||
141 | + // 请求地址 | ||
142 | + String url = BASE_URL + "delete" + "?id=" + dataId; | ||
143 | + // 请求 Header (用于传递Token) | ||
144 | + HttpHeaders headers = this.getHeaders(); | ||
145 | + // 请求方式是 DELETE 代表删除数据 | ||
146 | + HttpMethod method = HttpMethod.DELETE; | ||
147 | + | ||
148 | + System.out.println("请求地址:" + url); | ||
149 | + System.out.println("请求方式:" + method); | ||
150 | + | ||
151 | + // 利用 RestUtil 请求该url | ||
152 | + ResponseEntity<JSONObject> result = RestUtil.request(url, method, headers, null, null, JSONObject.class); | ||
153 | + if (result != null && result.getBody() != null) { | ||
154 | + System.out.println("返回结果:" + result.getBody().toJSONString()); | ||
155 | + } else { | ||
156 | + System.out.println("查询失败"); | ||
157 | + } | ||
158 | + } | ||
159 | + | ||
160 | + | ||
161 | + private String getToken() { | ||
162 | + String token = JwtUtil.sign(USERNAME, PASSWORD); | ||
163 | + redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token); | ||
164 | + redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, 60); | ||
165 | + return token; | ||
166 | + } | ||
167 | + | ||
168 | + private HttpHeaders getHeaders() { | ||
169 | + String token = this.getToken(); | ||
170 | + System.out.println("请求Token:" + token); | ||
171 | + | ||
172 | + HttpHeaders headers = new HttpHeaders(); | ||
173 | + String mediaType = MediaType.APPLICATION_JSON_VALUE; | ||
174 | + headers.setContentType(MediaType.parseMediaType(mediaType)); | ||
175 | + headers.set("Accept", mediaType); | ||
176 | + headers.set("X-Access-Token", token); | ||
177 | + return headers; | ||
178 | + } | ||
179 | +} |