Authored by zhaoyue

Add assert verify

@@ -3,7 +3,7 @@ git add --all src/* @@ -3,7 +3,7 @@ git add --all src/*
3 git add --all lib/* 3 git add --all lib/*
4 git add push.sh 4 git add push.sh
5 git add pom.xml 5 git add pom.xml
6 -git commit -m "Mod some var names" 6 +git commit -m "Add assert verify "
7 git push origin master 7 git push origin master
8 git status 8 git status
9 git pull 9 git pull
@@ -39,4 +39,20 @@ public interface Constants { @@ -39,4 +39,20 @@ public interface Constants {
39 String MALE = "0"; 39 String MALE = "0";
40 String FEMALE = "1"; 40 String FEMALE = "1";
41 41
  42 + /**
  43 + * return code
  44 + */
  45 + int CODE_SUCC = 100;
  46 + int OPENID_BIND_SUCCESS = 2001; //OPENID绑定成功
  47 + int OPENID_UNBIND_SUCESS = 2002;//OPENID解除绑定成功
  48 + int USER_LOGOUT = 1001;//退出登录成功
  49 + int USER_REGISTER = 1000;//用户注册成功
  50 + int USER_IS_EXIT = -1005;//用户已注册
  51 + int SIGN_ERROR = -100;//签名错误或者客户端时间有误
  52 + int USERNAME_OR_PASSWORD_ERROR = -1001;//用户名或密码错误/Account or Password is wrong
  53 + int USER_MODPASS_LOGOUT = 1002;//修改密码成功,请重新登录
  54 + int REPORT_INVALID_ERROR = -11142;//报告在数据库中不存在/Report is not exist in the DB
  55 + int USER_NOT_FOUND = -1002;//用户不存在/User is not exist
  56 +
  57 +
42 } 58 }
  1 +package com.xkl;
  2 +
  3 +import org.json.JSONObject;
  4 +import org.junit.Assert;
  5 +
  6 +/**
  7 + * Created by zhaoyue on 2017/3/11.
  8 + */
  9 +public class RtnCodeTools {
  10 + public static boolean verifyCode(String response, int expectCode) {
  11 + try {
  12 + JSONObject res = new JSONObject(response);
  13 + int code = res.getInt("code");
  14 + Assert.assertEquals(code, expectCode);
  15 + } catch (Exception e) {
  16 + e.printStackTrace();
  17 + return false;
  18 + }
  19 + return true;
  20 + }
  21 +}
1 package com.xkl; 1 package com.xkl;
2 2
3 import org.json.JSONObject; 3 import org.json.JSONObject;
  4 +import org.junit.Assert;
4 import org.junit.Test; 5 import org.junit.Test;
5 6
6 import java.util.HashMap; 7 import java.util.HashMap;
@@ -17,20 +18,21 @@ public class OpenIdTest { @@ -17,20 +18,21 @@ public class OpenIdTest {
17 * OpenId绑定接口 18 * OpenId绑定接口
18 */ 19 */
19 @Test 20 @Test
20 - public void testBind(){ 21 + public void testBind() {
21 System.out.println(bindWithOpenIdAndUser()); 22 System.out.println(bindWithOpenIdAndUser());
22 } 23 }
23 24
24 - public static String bindWithOpenIdAndUser(){  
25 - Map<String,String> params = new HashMap<String, String>();  
26 - params.put("username",Constants.USR_ACC);  
27 - params.put("password",EncodeTools.encode("MD5",Constants.USR_PWD));  
28 - params.put("openId",Constants.USR_OPENID);  
29 - params.put("openIdType",Constants.USR_OPENID_TYPE);  
30 - params.put("t",HttpTools.getNow());  
31 - params.put("type",Constants.KEY_ID);  
32 - params.put("sign",HttpTools.getSign(params));  
33 - String response = HttpTools.requestByMap(URL_OPEN_ID,"POST",params); 25 + public static String bindWithOpenIdAndUser() {
  26 + Map<String, String> params = new HashMap<String, String>();
  27 + params.put("username", Constants.USR_ACC);
  28 + params.put("password", EncodeTools.encode("MD5", Constants.USR_PWD));
  29 + params.put("openId", Constants.USR_OPENID);
  30 + params.put("openIdType", Constants.USR_OPENID_TYPE);
  31 + params.put("t", HttpTools.getNow());
  32 + params.put("type", Constants.KEY_ID);
  33 + params.put("sign", HttpTools.getSign(params));
  34 + String response = HttpTools.requestByMap(URL_OPEN_ID, "POST", params);
  35 + Assert.assertTrue(RtnCodeTools.verifyCode(response, Constants.OPENID_BIND_SUCCESS));
34 return response; 36 return response;
35 } 37 }
36 38
@@ -38,18 +40,20 @@ public class OpenIdTest { @@ -38,18 +40,20 @@ public class OpenIdTest {
38 * OpenId解除绑定接口 40 * OpenId解除绑定接口
39 */ 41 */
40 @Test 42 @Test
41 - public void testUnBind(){  
42 - Map<String,String> params = new HashMap<String, String>();  
43 - params.put("username",Constants.USR_ACC);  
44 - params.put("password",EncodeTools.encode("MD5",Constants.USR_PWD));  
45 - params.put("openId",Constants.USR_OPENID);  
46 - params.put("openIdType",Constants.USR_OPENID_TYPE); 43 + public void testUnBind() {
  44 + Map<String, String> params = new HashMap<String, String>();
  45 + params.put("username", Constants.USR_ACC);
  46 + params.put("password", EncodeTools.encode("MD5", Constants.USR_PWD));
  47 + params.put("openId", Constants.USR_OPENID);
  48 + params.put("openIdType", Constants.USR_OPENID_TYPE);
47 49
48 - params.put("t",HttpTools.getNow());  
49 - params.put("type",Constants.KEY_ID);  
50 - params.put("sign",HttpTools.getSign(params));  
51 - String response = HttpTools.requestByMap(URL_OPEN_ID,"DELETE",params); 50 + params.put("t", HttpTools.getNow());
  51 + params.put("type", Constants.KEY_ID);
  52 + params.put("sign", HttpTools.getSign(params));
  53 + String response = HttpTools.requestByMap(URL_OPEN_ID, "DELETE", params);
52 System.out.println(response); 54 System.out.println(response);
  55 + Assert.assertTrue(RtnCodeTools.verifyCode(response, Constants.OPENID_UNBIND_SUCESS));
  56 +
53 // 解除绑定后,又重新绑定好以便下次测试 57 // 解除绑定后,又重新绑定好以便下次测试
54 testBind(); 58 testBind();
55 } 59 }
@@ -58,22 +62,23 @@ public class OpenIdTest { @@ -58,22 +62,23 @@ public class OpenIdTest {
58 * OpenId登陆接口 62 * OpenId登陆接口
59 */ 63 */
60 @Test 64 @Test
61 - public void testLogin(){  
62 - System.out.println(bindWithOpenIdAndLoginAndGetToken(Constants.USR_OPENID,Constants.USR_OPENID_TYPE)); 65 + public void testLogin() {
  66 + System.out.println(bindWithOpenIdAndLoginAndGetToken(Constants.USR_OPENID, Constants.USR_OPENID_TYPE));
63 } 67 }
64 68
65 - public static String bindWithOpenIdAndLoginAndGetToken(String openId, String openIdType){ 69 + public static String bindWithOpenIdAndLoginAndGetToken(String openId, String openIdType) {
66 bindWithOpenIdAndUser(); 70 bindWithOpenIdAndUser();
67 - Map<String,String> params = new HashMap<String, String>();  
68 - params.put("openId",openId);  
69 - params.put("openIdType",openIdType); 71 + Map<String, String> params = new HashMap<String, String>();
  72 + params.put("openId", openId);
  73 + params.put("openIdType", openIdType);
70 74
71 - params.put("t",HttpTools.getNow());  
72 - params.put("type",Constants.KEY_ID);  
73 - params.put("sign",HttpTools.getSign(params));  
74 - String response = HttpTools.requestByMap(URL_LOGIN,"POST",params); 75 + params.put("t", HttpTools.getNow());
  76 + params.put("type", Constants.KEY_ID);
  77 + params.put("sign", HttpTools.getSign(params));
  78 + String response = HttpTools.requestByMap(URL_LOGIN, "POST", params);
  79 + Assert.assertTrue(RtnCodeTools.verifyCode(response, Constants.CODE_SUCC));
75 80
76 - System.out.println("response:"+ response); 81 + System.out.println("response:" + response);
77 JSONObject jsonObject = new JSONObject(response); 82 JSONObject jsonObject = new JSONObject(response);
78 JSONObject content = jsonObject.getJSONObject("content"); 83 JSONObject content = jsonObject.getJSONObject("content");
79 return content.getString("userId") + "_" + content.getString("token"); 84 return content.getString("userId") + "_" + content.getString("token");
@@ -11,51 +11,41 @@ import java.util.Map; @@ -11,51 +11,41 @@ import java.util.Map;
11 * Created by zhaoyue on 2017/3/11. 11 * Created by zhaoyue on 2017/3/11.
12 */ 12 */
13 public class QrCodeTest { 13 public class QrCodeTest {
14 - private static final String URL_USER = Constants.URL_PREFIX + "/userInfo";  
15 14
16 -  
17 - public static final String URL_GETQR_WITHACCPWD = Constants.URL_PREFIX + "/qrcode/getQrWithAccPwd";  
18 public static final String URL_GETQR_WITHTOKEN = Constants.URL_PREFIX + "/qrcode/getQrWithToken"; 15 public static final String URL_GETQR_WITHTOKEN = Constants.URL_PREFIX + "/qrcode/getQrWithToken";
19 public static final String URL_GETQR_WITHOPNEID = Constants.URL_PREFIX + "/qrcode/getQrWithOpenId"; 16 public static final String URL_GETQR_WITHOPNEID = Constants.URL_PREFIX + "/qrcode/getQrWithOpenId";
20 - public static final String URL_GETUSRINFO_WITHQR = Constants.URL_PREFIX + "/qrcode/getUsrInfoWithQr";  
21 -  
22 -  
23 -  
24 17
25 /** 18 /**
26 - * 使用token得到qrcode 19 + * 使用openid得到qrcode
27 */ 20 */
28 @Test 21 @Test
29 - public void testGetQrWithToken() {  
30 - String token = TokenTest.loginAndGetToken(Constants.USR_ACC, Constants.USR_PWD); 22 + public void testGetQrWithOpenid() {
31 Map<String, String> params = new HashMap<String, String>(); 23 Map<String, String> params = new HashMap<String, String>();
  24 + params.put("openId", Constants.USR_OPENID);
  25 + params.put("openIdType", Constants.USR_OPENID_TYPE);
32 params.put("t", HttpTools.getNow()); 26 params.put("t", HttpTools.getNow());
33 params.put("type", Constants.KEY_ID); 27 params.put("type", Constants.KEY_ID);
34 params.put("sign", HttpTools.getSign(params)); 28 params.put("sign", HttpTools.getSign(params));
35 - String response = HttpTools.requestByMapWithToken(URL_GETQR_WITHTOKEN, "GET", params, token); 29 + String response = HttpTools.requestByMap(URL_GETQR_WITHOPNEID, "GET", params);
36 System.out.println(response); 30 System.out.println(response);
37 Assert.assertTrue(hasQrCode(response)); 31 Assert.assertTrue(hasQrCode(response));
38 } 32 }
39 33
40 /** 34 /**
41 - * 使用openid得到qrcode 35 + * 使用token得到qrcode
42 */ 36 */
43 @Test 37 @Test
44 - public void testGetQrWithOpenid() { 38 + public void testGetQrWithToken() {
45 String token = TokenTest.loginAndGetToken(Constants.USR_ACC, Constants.USR_PWD); 39 String token = TokenTest.loginAndGetToken(Constants.USR_ACC, Constants.USR_PWD);
46 Map<String, String> params = new HashMap<String, String>(); 40 Map<String, String> params = new HashMap<String, String>();
47 - params.put("openId", Constants.USR_OPENID);  
48 - params.put("openIdType", Constants.USR_OPENID_TYPE);  
49 params.put("t", HttpTools.getNow()); 41 params.put("t", HttpTools.getNow());
50 params.put("type", Constants.KEY_ID); 42 params.put("type", Constants.KEY_ID);
51 params.put("sign", HttpTools.getSign(params)); 43 params.put("sign", HttpTools.getSign(params));
52 - String response = HttpTools.requestByMap(URL_GETQR_WITHOPNEID, "GET", params); 44 + String response = HttpTools.requestByMapWithToken(URL_GETQR_WITHTOKEN, "GET", params, token);
53 System.out.println(response); 45 System.out.println(response);
54 Assert.assertTrue(hasQrCode(response)); 46 Assert.assertTrue(hasQrCode(response));
55 } 47 }
56 48
57 -  
58 -  
59 private boolean hasQrCode(String responseStr) { 49 private boolean hasQrCode(String responseStr) {
60 try { 50 try {
61 JSONObject res = new JSONObject(responseStr); 51 JSONObject res = new JSONObject(responseStr);
@@ -67,32 +57,5 @@ public class QrCodeTest { @@ -67,32 +57,5 @@ public class QrCodeTest {
67 } 57 }
68 return true; 58 return true;
69 } 59 }
70 - private boolean hasSuccCode(String responseStr) {  
71 - try {  
72 - JSONObject res = new JSONObject(responseStr);  
73 - int code = res.getInt("code");  
74 - Assert.assertEquals(code, 100);  
75 - } catch (Exception e) {  
76 - e.printStackTrace();  
77 - return false;  
78 - }  
79 - return true;  
80 - }  
81 - private String getQrCode() {  
82 - Map<String, String> params = new HashMap<String, String>();  
83 - params.put("username", Constants.USR_ACC);  
84 - params.put("password", EncodeTools.encode("MD5", Constants.USR_PWD));  
85 - params.put("t", HttpTools.getNow());  
86 - String response = HttpTools.requestByMap(URL_GETQR_WITHACCPWD, "GET", params);  
87 - String qrcode = null;  
88 - try {  
89 - JSONObject res = new JSONObject(response);  
90 - qrcode = res.getJSONObject("content").getString("qrcode");  
91 - } catch (Exception e) {  
92 - return null;  
93 - }  
94 - return qrcode;  
95 - }  
96 -  
97 60
98 } 61 }
1 package com.xkl; 1 package com.xkl;
2 2
  3 +import org.junit.Assert;
3 import org.junit.BeforeClass; 4 import org.junit.BeforeClass;
4 import org.junit.Test; 5 import org.junit.Test;
5 6
@@ -39,6 +40,7 @@ public class ReportTest { @@ -39,6 +40,7 @@ public class ReportTest {
39 params.put("type", Constants.KEY_ID); 40 params.put("type", Constants.KEY_ID);
40 params.put("sign", HttpTools.getSign(params)); 41 params.put("sign", HttpTools.getSign(params));
41 String response = HttpTools.requestByMapWithToken(URL_REPORT_LIST, "GET", params, token); 42 String response = HttpTools.requestByMapWithToken(URL_REPORT_LIST, "GET", params, token);
  43 + Assert.assertTrue(RtnCodeTools.verifyCode(response, Constants.CODE_SUCC));
42 System.out.println(response); 44 System.out.println(response);
43 } 45 }
44 46
@@ -53,6 +55,7 @@ public class ReportTest { @@ -53,6 +55,7 @@ public class ReportTest {
53 params.put("type", Constants.KEY_ID); 55 params.put("type", Constants.KEY_ID);
54 params.put("sign", HttpTools.getSign(params)); 56 params.put("sign", HttpTools.getSign(params));
55 String response = HttpTools.requestByMapWithToken(URL_REPORT_DETAIL, "GET", params, token); 57 String response = HttpTools.requestByMapWithToken(URL_REPORT_DETAIL, "GET", params, token);
  58 + Assert.assertTrue(RtnCodeTools.verifyCode(response, Constants.CODE_SUCC));
56 System.out.println(response); 59 System.out.println(response);
57 } 60 }
58 61
@@ -69,6 +72,7 @@ public class ReportTest { @@ -69,6 +72,7 @@ public class ReportTest {
69 params.put("type", Constants.KEY_ID); 72 params.put("type", Constants.KEY_ID);
70 params.put("sign", HttpTools.getSign(params)); 73 params.put("sign", HttpTools.getSign(params));
71 String response = HttpTools.requestByMapWithToken(URL_ITEM_INFO, "GET", params, token); 74 String response = HttpTools.requestByMapWithToken(URL_ITEM_INFO, "GET", params, token);
  75 + Assert.assertTrue(RtnCodeTools.verifyCode(response, Constants.CODE_SUCC));
72 System.out.println(response); 76 System.out.println(response);
73 } 77 }
74 78
@@ -85,6 +89,7 @@ public class ReportTest { @@ -85,6 +89,7 @@ public class ReportTest {
85 params.put("type", Constants.KEY_ID); 89 params.put("type", Constants.KEY_ID);
86 params.put("sign", HttpTools.getSign(params)); 90 params.put("sign", HttpTools.getSign(params));
87 String response = HttpTools.requestByMapWithToken(URL_ITEM_INFO, "GET", params, token); 91 String response = HttpTools.requestByMapWithToken(URL_ITEM_INFO, "GET", params, token);
  92 + Assert.assertTrue(RtnCodeTools.verifyCode(response, Constants.CODE_SUCC));
88 System.out.println(response); 93 System.out.println(response);
89 } 94 }
90 95
@@ -101,6 +106,7 @@ public class ReportTest { @@ -101,6 +106,7 @@ public class ReportTest {
101 params.put("type", Constants.KEY_ID); 106 params.put("type", Constants.KEY_ID);
102 params.put("sign", HttpTools.getSign(params)); 107 params.put("sign", HttpTools.getSign(params));
103 String response = HttpTools.requestByMapWithToken(URL_ITEM_GRAPH, "GET", params, token); 108 String response = HttpTools.requestByMapWithToken(URL_ITEM_GRAPH, "GET", params, token);
  109 + Assert.assertTrue(RtnCodeTools.verifyCode(response, Constants.CODE_SUCC));
104 System.out.println(response); 110 System.out.println(response);
105 } 111 }
106 112
@@ -115,6 +121,7 @@ public class ReportTest { @@ -115,6 +121,7 @@ public class ReportTest {
115 params.put("type", Constants.KEY_ID); 121 params.put("type", Constants.KEY_ID);
116 params.put("sign", HttpTools.getSign(params)); 122 params.put("sign", HttpTools.getSign(params));
117 String response = HttpTools.requestByMapWithToken(URL_COMPARE, "POST", params, token); 123 String response = HttpTools.requestByMapWithToken(URL_COMPARE, "POST", params, token);
  124 + Assert.assertTrue(RtnCodeTools.verifyCode(response, Constants.CODE_SUCC));
118 System.out.println(response); 125 System.out.println(response);
119 } 126 }
120 } 127 }
1 package com.xkl; 1 package com.xkl;
2 2
3 import org.json.JSONObject; 3 import org.json.JSONObject;
  4 +import org.junit.Assert;
4 import org.junit.Test; 5 import org.junit.Test;
5 6
6 import java.util.HashMap; 7 import java.util.HashMap;
@@ -14,15 +15,15 @@ public class TokenTest { @@ -14,15 +15,15 @@ public class TokenTest {
14 private static final String URL_LOGIN = Constants.URL_PREFIX + "/token"; 15 private static final String URL_LOGIN = Constants.URL_PREFIX + "/token";
15 private static final String ADMIN_URL_LOGIN = Constants.URL_PREFIX + "/token/admin"; 16 private static final String ADMIN_URL_LOGIN = Constants.URL_PREFIX + "/token/admin";
16 17
17 - public static String loginAndGetToken(String user,String pass){  
18 - Map<String,String> params = new HashMap<String, String>();  
19 - params.put("username",user);  
20 - params.put("password",EncodeTools.encode("MD5",pass));  
21 - params.put("t",HttpTools.getNow());  
22 - params.put("type",Constants.KEY_ID);  
23 - params.put("sign",HttpTools.getSign(params));  
24 - String response = HttpTools.requestByMap(URL_LOGIN,"POST",params);  
25 - System.out.println("response:"+ response); 18 + public static String loginAndGetToken(String user, String pass) {
  19 + Map<String, String> params = new HashMap<String, String>();
  20 + params.put("username", user);
  21 + params.put("password", EncodeTools.encode("MD5", pass));
  22 + params.put("t", HttpTools.getNow());
  23 + params.put("type", Constants.KEY_ID);
  24 + params.put("sign", HttpTools.getSign(params));
  25 + String response = HttpTools.requestByMap(URL_LOGIN, "POST", params);
  26 + System.out.println("response:" + response);
26 JSONObject jsonObject = new JSONObject(response); 27 JSONObject jsonObject = new JSONObject(response);
27 JSONObject content = jsonObject.getJSONObject("content"); 28 JSONObject content = jsonObject.getJSONObject("content");
28 return content.getString("userId") + "_" + content.getString("token"); 29 return content.getString("userId") + "_" + content.getString("token");
@@ -32,33 +33,36 @@ public class TokenTest { @@ -32,33 +33,36 @@ public class TokenTest {
32 * 用户登录接口 33 * 用户登录接口
33 */ 34 */
34 @Test 35 @Test
35 - public void testLogin(){  
36 - System.out.println(loginAndGetToken(Constants.USR_ACC,Constants.USR_PWD)); 36 + public void testLogin() {
  37 + String response = loginAndGetToken(Constants.USR_ACC, Constants.USR_PWD);
  38 + Assert.assertTrue(response.contains("_"));
  39 + System.out.println(response);
37 } 40 }
38 41
39 /** 42 /**
40 * 用户退出登录接口 43 * 用户退出登录接口
41 */ 44 */
42 @Test 45 @Test
43 - public void logout(){  
44 - String token = loginAndGetToken(Constants.USR_ACC,Constants.USR_PWD);  
45 - Map<String,String> params = new HashMap<String, String>();  
46 - params.put("t",HttpTools.getNow());  
47 - params.put("type",Constants.KEY_ID);  
48 - params.put("sign",HttpTools.getSign(params));  
49 - String response = HttpTools.requestByMapWithToken(URL_LOGIN,"DELETE",params,token); 46 + public void logout() {
  47 + String token = loginAndGetToken(Constants.USR_ACC, Constants.USR_PWD);
  48 + Map<String, String> params = new HashMap<String, String>();
  49 + params.put("t", HttpTools.getNow());
  50 + params.put("type", Constants.KEY_ID);
  51 + params.put("sign", HttpTools.getSign(params));
  52 + String response = HttpTools.requestByMapWithToken(URL_LOGIN, "DELETE", params, token);
  53 + Assert.assertTrue(RtnCodeTools.verifyCode(response, Constants.USER_LOGOUT));
50 System.out.println(response); 54 System.out.println(response);
51 } 55 }
52 56
53 - public static String adminLoginAndGetToken(String user,String pass){  
54 - Map<String,String> params = new HashMap<String, String>();  
55 - params.put("username",user);  
56 - params.put("password",EncodeTools.encode("MD5",pass));  
57 - params.put("t",HttpTools.getNow());  
58 - params.put("type",Constants.KEY_ID);  
59 - params.put("sign",HttpTools.getSign(params));  
60 - String response = HttpTools.requestByMap(ADMIN_URL_LOGIN,"POST",params);  
61 - System.out.println("response:"+ response); 57 + public static String adminLoginAndGetToken(String user, String pass) {
  58 + Map<String, String> params = new HashMap<String, String>();
  59 + params.put("username", user);
  60 + params.put("password", EncodeTools.encode("MD5", pass));
  61 + params.put("t", HttpTools.getNow());
  62 + params.put("type", Constants.KEY_ID);
  63 + params.put("sign", HttpTools.getSign(params));
  64 + String response = HttpTools.requestByMap(ADMIN_URL_LOGIN, "POST", params);
  65 + System.out.println("response:" + response);
62 JSONObject jsonObject = new JSONObject(response); 66 JSONObject jsonObject = new JSONObject(response);
63 JSONObject content = jsonObject.getJSONObject("content"); 67 JSONObject content = jsonObject.getJSONObject("content");
64 return content.getString("userId") + "_" + content.getString("token"); 68 return content.getString("userId") + "_" + content.getString("token");
@@ -68,21 +72,24 @@ public class TokenTest { @@ -68,21 +72,24 @@ public class TokenTest {
68 * 管理员登录接口 72 * 管理员登录接口
69 */ 73 */
70 @Test 74 @Test
71 - public void adminTestLogin(){  
72 - System.out.println(adminLoginAndGetToken( Constants.ADMIN_ACCOUNT, Constants.ADMIN_PWD)); 75 + public void adminTestLogin() {
  76 + String response = adminLoginAndGetToken(Constants.ADMIN_ACCOUNT, Constants.ADMIN_PWD);
  77 + Assert.assertTrue(response.contains("_"));
  78 + System.out.println(response);
73 } 79 }
74 80
75 /** 81 /**
76 * 管理员退出登录接口 82 * 管理员退出登录接口
77 */ 83 */
78 @Test 84 @Test
79 - public void adminLogout(){  
80 - String token = loginAndGetToken( Constants.ADMIN_ACCOUNT, Constants.ADMIN_PWD);  
81 - Map<String,String> params = new HashMap<String, String>();  
82 - params.put("t",HttpTools.getNow());  
83 - params.put("type",Constants.KEY_ID);  
84 - params.put("sign",HttpTools.getSign(params));  
85 - String response = HttpTools.requestByMapWithToken(ADMIN_URL_LOGIN,"DELETE",params,token); 85 + public void adminLogout() {
  86 + String token = loginAndGetToken(Constants.ADMIN_ACCOUNT, Constants.ADMIN_PWD);
  87 + Map<String, String> params = new HashMap<String, String>();
  88 + params.put("t", HttpTools.getNow());
  89 + params.put("type", Constants.KEY_ID);
  90 + params.put("sign", HttpTools.getSign(params));
  91 + String response = HttpTools.requestByMapWithToken(ADMIN_URL_LOGIN, "DELETE", params, token);
  92 + Assert.assertTrue(RtnCodeTools.verifyCode(response, Constants.CODE_SUCC));
86 System.out.println(response); 93 System.out.println(response);
87 } 94 }
88 95
1 package com.xkl; 1 package com.xkl;
2 2
  3 +import org.junit.Assert;
3 import org.junit.Test; 4 import org.junit.Test;
4 5
5 import java.util.HashMap; 6 import java.util.HashMap;
@@ -30,7 +31,9 @@ public class UserInfoTest { @@ -30,7 +31,9 @@ public class UserInfoTest {
30 String birthDate = "1966-06-12"; 31 String birthDate = "1966-06-12";
31 String phone = "13011112222"; 32 String phone = "13011112222";
32 String idcard = "130105196606125555"; 33 String idcard = "130105196606125555";
33 - register(adminUser, adminPass, user, pass, name, sex, birthDate, phone, idcard); 34 + String response = register(adminUser, adminPass, user, pass, name, sex, birthDate, phone, idcard);
  35 + Assert.assertTrue(RtnCodeTools.verifyCode(response, Constants.USER_IS_EXIT));
  36 +
34 } 37 }
35 38
36 @Test 39 @Test
@@ -44,7 +47,9 @@ public class UserInfoTest { @@ -44,7 +47,9 @@ public class UserInfoTest {
44 String birthDate = "1966-06-12"; 47 String birthDate = "1966-06-12";
45 String phone = "13011112222"; 48 String phone = "13011112222";
46 String idcard = "110000196606125555"; 49 String idcard = "110000196606125555";
47 - register(adminUser, adminPass, user, pass, name, sex, birthDate, phone, idcard); 50 + String response = register(adminUser, adminPass, user, pass, name, sex, birthDate, phone, idcard);
  51 + Assert.assertTrue(RtnCodeTools.verifyCode(response, Constants.USER_IS_EXIT));
  52 +
48 } 53 }
49 54
50 @Test 55 @Test
@@ -74,9 +79,10 @@ public class UserInfoTest { @@ -74,9 +79,10 @@ public class UserInfoTest {
74 params.put("type", Constants.KEY_ID); 79 params.put("type", Constants.KEY_ID);
75 params.put("sign", HttpTools.getSign(params)); 80 params.put("sign", HttpTools.getSign(params));
76 //获取token 81 //获取token
77 - String token = loginAndGetToken("15211112222", "pass152"); 82 + String token = loginAndGetToken("15211112222", "pass152_new");
78 System.out.println(token); 83 System.out.println(token);
79 String response = HttpTools.requestByMapWithToken(URL_USER, "PUT", params, token); 84 String response = HttpTools.requestByMapWithToken(URL_USER, "PUT", params, token);
  85 + Assert.assertTrue(RtnCodeTools.verifyCode(response, Constants.USER_MODPASS_LOGOUT));
80 System.out.println(response); 86 System.out.println(response);
81 } 87 }
82 88
@@ -93,10 +99,11 @@ public class UserInfoTest { @@ -93,10 +99,11 @@ public class UserInfoTest {
93 String token = loginAndGetToken(Constants.USR_ACC, Constants.USR_PWD); 99 String token = loginAndGetToken(Constants.USR_ACC, Constants.USR_PWD);
94 System.out.println(token); 100 System.out.println(token);
95 String response = HttpTools.requestByMapWithToken(URL_USER, "GET", params, token); 101 String response = HttpTools.requestByMapWithToken(URL_USER, "GET", params, token);
  102 + Assert.assertTrue(RtnCodeTools.verifyCode(response, Constants.CODE_SUCC));
96 System.out.println(response); 103 System.out.println(response);
97 } 104 }
98 105
99 - public void register(String adminUser, String adminPass, 106 + public String register(String adminUser, String adminPass,
100 String user, String pass, String name, String sex, String birthDate, String phone, String idcard) { 107 String user, String pass, String name, String sex, String birthDate, String phone, String idcard) {
101 Map<String, String> params = new HashMap<String, String>(); 108 Map<String, String> params = new HashMap<String, String>();
102 params.put("username", user); 109 params.put("username", user);
@@ -113,6 +120,7 @@ public class UserInfoTest { @@ -113,6 +120,7 @@ public class UserInfoTest {
113 String token = TokenTest.adminLoginAndGetToken(adminUser, adminPass); 120 String token = TokenTest.adminLoginAndGetToken(adminUser, adminPass);
114 String response = HttpTools.requestByMapWithToken(URL_USER, "POST", params, token); 121 String response = HttpTools.requestByMapWithToken(URL_USER, "POST", params, token);
115 System.out.println(response); 122 System.out.println(response);
  123 + return response;
116 } 124 }
117 125
118 /** 126 /**
@@ -143,6 +151,7 @@ public class UserInfoTest { @@ -143,6 +151,7 @@ public class UserInfoTest {
143 params.put("sign", "nosign"); 151 params.put("sign", "nosign");
144 String token = TokenTest.adminLoginAndGetToken(adminUser, adminPass); 152 String token = TokenTest.adminLoginAndGetToken(adminUser, adminPass);
145 String response = HttpTools.requestByMapWithToken(URL_USER, "POST", params, token); 153 String response = HttpTools.requestByMapWithToken(URL_USER, "POST", params, token);
  154 + Assert.assertTrue(RtnCodeTools.verifyCode(response, Constants.SIGN_ERROR));
146 System.out.println(response); 155 System.out.println(response);
147 } 156 }
148 157
@@ -174,7 +183,7 @@ public class UserInfoTest { @@ -174,7 +183,7 @@ public class UserInfoTest {
174 params.put("sign", "nosign"); 183 params.put("sign", "nosign");
175 String token = TokenTest.adminLoginAndGetToken(adminUser, adminPass); 184 String token = TokenTest.adminLoginAndGetToken(adminUser, adminPass);
176 String response = HttpTools.requestByMapWithToken(URL_USER, "POST", params, token); 185 String response = HttpTools.requestByMapWithToken(URL_USER, "POST", params, token);
177 - 186 + Assert.assertTrue(RtnCodeTools.verifyCode(response, Constants.SIGN_ERROR));
178 System.out.println(response); 187 System.out.println(response);
179 } 188 }
180 } 189 }
@@ -2,6 +2,8 @@ package com.xkl.inneruse; @@ -2,6 +2,8 @@ package com.xkl.inneruse;
2 2
3 import com.xkl.Constants; 3 import com.xkl.Constants;
4 import com.xkl.HttpTools; 4 import com.xkl.HttpTools;
  5 +import com.xkl.RtnCodeTools;
  6 +import org.junit.Assert;
5 import org.junit.BeforeClass; 7 import org.junit.BeforeClass;
6 import org.junit.Test; 8 import org.junit.Test;
7 9
@@ -21,14 +23,15 @@ public class ReportTest { @@ -21,14 +23,15 @@ public class ReportTest {
21 * 健康评分接口 23 * 健康评分接口
22 */ 24 */
23 @Test 25 @Test
24 - public void testScore(){  
25 - Map<String,String> params = new HashMap<String, String>();  
26 - params.put("report_id","77");  
27 - params.put("t",HttpTools.getNow());  
28 - params.put("type",Constants.KEY_ID);  
29 - params.put("sign",HttpTools.getSign(params));  
30 - String response = HttpTools.requestByMap(URL_REPORT_SCORE,"GET",params); 26 + public void testScore() {
  27 + Map<String, String> params = new HashMap<String, String>();
  28 + params.put("report_id", "77");
  29 + params.put("t", HttpTools.getNow());
  30 + params.put("type", Constants.KEY_ID);
  31 + params.put("sign", HttpTools.getSign(params));
  32 + String response = HttpTools.requestByMap(URL_REPORT_SCORE, "GET", params);
31 System.out.println(response); 33 System.out.println(response);
  34 + Assert.assertTrue(RtnCodeTools.verifyCode(response, Constants.CODE_SUCC));
32 } 35 }
33 36
34 } 37 }
1 package com.xkl.inneruse.qrcode; 1 package com.xkl.inneruse.qrcode;
2 2
3 -import com.xkl.Constants;  
4 -import com.xkl.EncodeTools;  
5 -import com.xkl.HttpTools;  
6 -import com.xkl.TokenTest; 3 +import com.xkl.*;
7 import org.json.JSONObject; 4 import org.json.JSONObject;
8 import org.junit.Assert; 5 import org.junit.Assert;
9 import org.junit.Test; 6 import org.junit.Test;
@@ -81,7 +78,7 @@ public class QrCodeTest { @@ -81,7 +78,7 @@ public class QrCodeTest {
81 params.put("t", HttpTools.getNow()); 78 params.put("t", HttpTools.getNow());
82 String response = HttpTools.requestByMap(URL_GETUSRINFO_WITHQR, "GET", params); 79 String response = HttpTools.requestByMap(URL_GETUSRINFO_WITHQR, "GET", params);
83 System.out.println(response); 80 System.out.println(response);
84 - Assert.assertTrue(hasSuccCode(response)); 81 + Assert.assertTrue(RtnCodeTools.verifyCode(response, Constants.CODE_SUCC));
85 } 82 }
86 83
87 84
@@ -97,17 +94,6 @@ public class QrCodeTest { @@ -97,17 +94,6 @@ public class QrCodeTest {
97 return true; 94 return true;
98 } 95 }
99 96
100 - private boolean hasSuccCode(String responseStr) {  
101 - try {  
102 - JSONObject res = new JSONObject(responseStr);  
103 - int code = res.getInt("code");  
104 - Assert.assertEquals(code, 100);  
105 - } catch (Exception e) {  
106 - e.printStackTrace();  
107 - return false;  
108 - }  
109 - return true;  
110 - }  
111 97
112 private String getQrCode() { 98 private String getQrCode() {
113 Map<String, String> params = new HashMap<String, String>(); 99 Map<String, String> params = new HashMap<String, String>();
@@ -3,7 +3,9 @@ package com.xkl.upsoft; @@ -3,7 +3,9 @@ package com.xkl.upsoft;
3 import com.xkl.Constants; 3 import com.xkl.Constants;
4 import com.xkl.EncodeTools; 4 import com.xkl.EncodeTools;
5 import com.xkl.HttpTools; 5 import com.xkl.HttpTools;
  6 +import com.xkl.RtnCodeTools;
6 import org.json.JSONObject; 7 import org.json.JSONObject;
  8 +import org.junit.Assert;
7 import org.junit.Test; 9 import org.junit.Test;
8 10
9 import java.util.HashMap; 11 import java.util.HashMap;
@@ -32,7 +34,9 @@ public class AccountTest { @@ -32,7 +34,9 @@ public class AccountTest {
32 34
33 @Test 35 @Test
34 public void testLogin() { 36 public void testLogin() {
35 - System.out.println(loginAndGetToken(Constants.ADMIN_ACCOUNT, Constants.ADMIN_PWD)); 37 + String response = loginAndGetToken(Constants.ADMIN_ACCOUNT, Constants.ADMIN_PWD);
  38 + Assert.assertTrue(response.contains("_"));
  39 + System.out.println(response);
36 } 40 }
37 41
38 @Test 42 @Test
@@ -41,6 +45,7 @@ public class AccountTest { @@ -41,6 +45,7 @@ public class AccountTest {
41 Map<String, String> params = new HashMap<String, String>(); 45 Map<String, String> params = new HashMap<String, String>();
42 params.put("t", HttpTools.getNow()); 46 params.put("t", HttpTools.getNow());
43 String response = HttpTools.requestByMapWithToken(URL_LOGIN, "DELETE", params, token); 47 String response = HttpTools.requestByMapWithToken(URL_LOGIN, "DELETE", params, token);
  48 + Assert.assertTrue(RtnCodeTools.verifyCode(response, Constants.CODE_SUCC));
44 System.out.println("logout success:" + response); 49 System.out.println("logout success:" + response);
45 } 50 }
46 51
@@ -51,6 +56,7 @@ public class AccountTest { @@ -51,6 +56,7 @@ public class AccountTest {
51 String newPassWord = Constants.ADMIN_PWD; 56 String newPassWord = Constants.ADMIN_PWD;
52 params.put("newpwd", EncodeTools.encode("MD5", newPassWord)); 57 params.put("newpwd", EncodeTools.encode("MD5", newPassWord));
53 String response = HttpTools.requestByMapWithToken(URL_LOGIN, "PUT", params, token); 58 String response = HttpTools.requestByMapWithToken(URL_LOGIN, "PUT", params, token);
  59 + Assert.assertTrue(RtnCodeTools.verifyCode(response, Constants.CODE_SUCC));
54 System.out.println("modify password success:" + response); 60 System.out.println("modify password success:" + response);
55 } 61 }
56 } 62 }
@@ -3,7 +3,9 @@ package com.xkl.upsoft; @@ -3,7 +3,9 @@ package com.xkl.upsoft;
3 import com.xkl.Constants; 3 import com.xkl.Constants;
4 import com.xkl.EncodeTools; 4 import com.xkl.EncodeTools;
5 import com.xkl.HttpTools; 5 import com.xkl.HttpTools;
  6 +import com.xkl.RtnCodeTools;
6 import org.json.JSONObject; 7 import org.json.JSONObject;
  8 +import org.junit.Assert;
7 import org.junit.Test; 9 import org.junit.Test;
8 10
9 import java.util.HashMap; 11 import java.util.HashMap;
@@ -23,17 +25,20 @@ public class AdminInfoTest { @@ -23,17 +25,20 @@ public class AdminInfoTest {
23 params.put("password", EncodeTools.encode("MD5", pass)); 25 params.put("password", EncodeTools.encode("MD5", pass));
24 params.put("t", HttpTools.getNow()); 26 params.put("t", HttpTools.getNow());
25 String response = HttpTools.requestByMap(URL_LOGIN, "POST", params); 27 String response = HttpTools.requestByMap(URL_LOGIN, "POST", params);
  28 + Assert.assertTrue(RtnCodeTools.verifyCode(response, Constants.CODE_SUCC));
26 System.out.println("login success:" + response); 29 System.out.println("login success:" + response);
27 JSONObject jsonObject = new JSONObject(response); 30 JSONObject jsonObject = new JSONObject(response);
28 JSONObject content = jsonObject.getJSONObject("content"); 31 JSONObject content = jsonObject.getJSONObject("content");
29 return content.getString("userId") + "_" + content.getString("token"); 32 return content.getString("userId") + "_" + content.getString("token");
30 } 33 }
  34 +
31 @Test 35 @Test
32 public void testGetAdminInfo() { 36 public void testGetAdminInfo() {
33 String token = loginAndGetToken(Constants.ADMIN_ACCOUNT, Constants.ADMIN_PWD); 37 String token = loginAndGetToken(Constants.ADMIN_ACCOUNT, Constants.ADMIN_PWD);
34 Map<String, String> params = new HashMap<String, String>(); 38 Map<String, String> params = new HashMap<String, String>();
35 params.put("t", HttpTools.getNow()); 39 params.put("t", HttpTools.getNow());
36 String response = HttpTools.requestByMapWithToken(URL_ADMININFO, "GET", params, token); 40 String response = HttpTools.requestByMapWithToken(URL_ADMININFO, "GET", params, token);
  41 + Assert.assertTrue(RtnCodeTools.verifyCode(response, Constants.CODE_SUCC));
37 System.out.println("admin info get success:" + response); 42 System.out.println("admin info get success:" + response);
38 } 43 }
39 } 44 }
@@ -3,7 +3,9 @@ package com.xkl.upsoft; @@ -3,7 +3,9 @@ package com.xkl.upsoft;
3 import com.xkl.Constants; 3 import com.xkl.Constants;
4 import com.xkl.EncodeTools; 4 import com.xkl.EncodeTools;
5 import com.xkl.HttpTools; 5 import com.xkl.HttpTools;
  6 +import com.xkl.RtnCodeTools;
6 import org.json.JSONObject; 7 import org.json.JSONObject;
  8 +import org.junit.Assert;
7 import org.junit.Test; 9 import org.junit.Test;
8 10
9 import java.util.HashMap; 11 import java.util.HashMap;
@@ -42,6 +44,7 @@ public class ReportTest { @@ -42,6 +44,7 @@ public class ReportTest {
42 // String report = Data.readTxtFile("C:\\Users\\zhaoyue\\Desktop\\report.txt"); 44 // String report = Data.readTxtFile("C:\\Users\\zhaoyue\\Desktop\\report.txt");
43 params.put("json_report", report); 45 params.put("json_report", report);
44 String response = HttpTools.requestByMapWithToken(URL_REPORT, "POST", params, token); 46 String response = HttpTools.requestByMapWithToken(URL_REPORT, "POST", params, token);
  47 + Assert.assertTrue(RtnCodeTools.verifyCode(response, Constants.CODE_SUCC));
45 System.out.println("add report success:" + response); 48 System.out.println("add report success:" + response);
46 } 49 }
47 50
@@ -52,5 +55,6 @@ public class ReportTest { @@ -52,5 +55,6 @@ public class ReportTest {
52 params.put("report_id", "143"); 55 params.put("report_id", "143");
53 String response = HttpTools.requestByMapWithToken(URL_REPORT, "DELETE", params, token); 56 String response = HttpTools.requestByMapWithToken(URL_REPORT, "DELETE", params, token);
54 System.out.println("delete report:" + response); 57 System.out.println("delete report:" + response);
  58 + Assert.assertTrue(response.contains("message"));
55 } 59 }
56 } 60 }
@@ -2,6 +2,8 @@ package com.xkl.upsoft; @@ -2,6 +2,8 @@ package com.xkl.upsoft;
2 2
3 import com.xkl.Constants; 3 import com.xkl.Constants;
4 import com.xkl.HttpTools; 4 import com.xkl.HttpTools;
  5 +import com.xkl.RtnCodeTools;
  6 +import org.junit.Assert;
5 import org.junit.Test; 7 import org.junit.Test;
6 8
7 import java.util.HashMap; 9 import java.util.HashMap;
@@ -21,6 +23,7 @@ public class SoftVersionTest { @@ -21,6 +23,7 @@ public class SoftVersionTest {
21 Map<String, String> params = new HashMap<String, String>(); 23 Map<String, String> params = new HashMap<String, String>();
22 params.put("t", HttpTools.getNow()); 24 params.put("t", HttpTools.getNow());
23 String response = HttpTools.requestByMap(URL_VERSION, "GET", params); 25 String response = HttpTools.requestByMap(URL_VERSION, "GET", params);
  26 + Assert.assertTrue(RtnCodeTools.verifyCode(response, Constants.CODE_SUCC));
24 System.out.println("version info get success:" + response); 27 System.out.println("version info get success:" + response);
25 } 28 }
26 } 29 }
@@ -3,7 +3,9 @@ package com.xkl.uspih; @@ -3,7 +3,9 @@ package com.xkl.uspih;
3 import com.xkl.Constants; 3 import com.xkl.Constants;
4 import com.xkl.EncodeTools; 4 import com.xkl.EncodeTools;
5 import com.xkl.HttpTools; 5 import com.xkl.HttpTools;
  6 +import com.xkl.RtnCodeTools;
6 import org.json.JSONObject; 7 import org.json.JSONObject;
  8 +import org.junit.Assert;
7 import org.junit.Test; 9 import org.junit.Test;
8 10
9 import java.util.HashMap; 11 import java.util.HashMap;
@@ -29,10 +31,16 @@ public class AccountTest { @@ -29,10 +31,16 @@ public class AccountTest {
29 params.put("password", EncodeTools.encode("MD5", pass)); // encode password with MD5 algorithm 31 params.put("password", EncodeTools.encode("MD5", pass)); // encode password with MD5 algorithm
30 params.put("t", HttpTools.getNow()); 32 params.put("t", HttpTools.getNow());
31 String response = HttpTools.requestByMap(URL_LOGIN, "POST", params); 33 String response = HttpTools.requestByMap(URL_LOGIN, "POST", params);
  34 + try {
32 System.out.println("login success:" + response); 35 System.out.println("login success:" + response);
33 JSONObject jsonObject = new JSONObject(response); 36 JSONObject jsonObject = new JSONObject(response);
34 JSONObject content = jsonObject.getJSONObject("content"); 37 JSONObject content = jsonObject.getJSONObject("content");
35 return content.getString("userId") + "_" + content.getString("token"); 38 return content.getString("userId") + "_" + content.getString("token");
  39 + } catch (Exception e) {
  40 + e.printStackTrace();
  41 + return null;
  42 + }
  43 +
36 } 44 }
37 45
38 /** 46 /**
@@ -48,10 +56,16 @@ public class AccountTest { @@ -48,10 +56,16 @@ public class AccountTest {
48 params.put("newpwd", EncodeTools.encode("MD5", newpwd)); // encode password with MD5 algorithm 56 params.put("newpwd", EncodeTools.encode("MD5", newpwd)); // encode password with MD5 algorithm
49 params.put("t", HttpTools.getNow()); 57 params.put("t", HttpTools.getNow());
50 String response = HttpTools.requestByMap(URL_LOGIN, "PUT", params); 58 String response = HttpTools.requestByMap(URL_LOGIN, "PUT", params);
  59 + try {
51 System.out.println("login success:" + response); 60 System.out.println("login success:" + response);
52 JSONObject jsonObject = new JSONObject(response); 61 JSONObject jsonObject = new JSONObject(response);
53 JSONObject content = jsonObject.getJSONObject("content"); 62 JSONObject content = jsonObject.getJSONObject("content");
54 return content.getString("userId") + "_" + content.getString("token"); 63 return content.getString("userId") + "_" + content.getString("token");
  64 + } catch (Exception e) {
  65 + e.printStackTrace();
  66 + return null;
  67 + }
  68 +
55 } 69 }
56 70
57 /** 71 /**
@@ -59,7 +73,8 @@ public class AccountTest { @@ -59,7 +73,8 @@ public class AccountTest {
59 */ 73 */
60 @Test 74 @Test
61 public void testLoginSuccess() { 75 public void testLoginSuccess() {
62 - System.out.println(loginAndGetToken(Constants.ADMIN_ACCOUNT, Constants.ADMIN_PWD)); 76 + String response = loginAndGetToken(Constants.ADMIN_ACCOUNT, Constants.ADMIN_PWD);
  77 + System.out.println(response);
63 } 78 }
64 79
65 /** 80 /**
@@ -67,7 +82,9 @@ public class AccountTest { @@ -67,7 +82,9 @@ public class AccountTest {
67 */ 82 */
68 @Test 83 @Test
69 public void testLoginFail() { 84 public void testLoginFail() {
70 - System.out.println(loginAndGetToken(Constants.ADMIN_ACCOUNT + "ppppp", Constants.ADMIN_PWD)); 85 + String response = loginAndGetToken(Constants.ADMIN_ACCOUNT + "ppppp", Constants.ADMIN_PWD);
  86 + Assert.assertTrue(response == null);
  87 + System.out.println(response);
71 } 88 }
72 89
73 /** 90 /**
@@ -75,7 +92,9 @@ public class AccountTest { @@ -75,7 +92,9 @@ public class AccountTest {
75 */ 92 */
76 @Test 93 @Test
77 public void testLoginModPwdSuccess() { 94 public void testLoginModPwdSuccess() {
78 - System.out.println(loginModPwdAndGetToken(Constants.ADMIN_ACCOUNT, Constants.ADMIN_PWD, Constants.ADMIN_PWD)); 95 + String response = loginModPwdAndGetToken(Constants.ADMIN_ACCOUNT, Constants.ADMIN_PWD, Constants.ADMIN_PWD);
  96 + Assert.assertTrue(response.contains("_"));
  97 + System.out.println(response);
79 } 98 }
80 99
81 /** 100 /**
@@ -83,7 +102,9 @@ public class AccountTest { @@ -83,7 +102,9 @@ public class AccountTest {
83 */ 102 */
84 @Test 103 @Test
85 public void testLoginModPwdFail() { 104 public void testLoginModPwdFail() {
86 - System.out.println(loginModPwdAndGetToken(Constants.ADMIN_ACCOUNT, Constants.ADMIN_PWD + "pppppp", Constants.ADMIN_PWD)); 105 + String response = loginModPwdAndGetToken(Constants.ADMIN_ACCOUNT, Constants.ADMIN_PWD + "pppppp", Constants.ADMIN_PWD);
  106 + Assert.assertTrue(response == null);
  107 + System.out.println(response);
87 } 108 }
88 109
89 110
@@ -94,6 +115,7 @@ public class AccountTest { @@ -94,6 +115,7 @@ public class AccountTest {
94 params.put("t", HttpTools.getNow()); 115 params.put("t", HttpTools.getNow());
95 String response = HttpTools.requestByMapWithToken(URL_LOGIN, "DELETE", params, token); 116 String response = HttpTools.requestByMapWithToken(URL_LOGIN, "DELETE", params, token);
96 System.out.println("logout success:" + response); 117 System.out.println("logout success:" + response);
  118 + Assert.assertTrue(RtnCodeTools.verifyCode(response, Constants.CODE_SUCC));
97 } 119 }
98 120
99 @Test 121 @Test
@@ -103,5 +125,6 @@ public class AccountTest { @@ -103,5 +125,6 @@ public class AccountTest {
103 params.put("t", HttpTools.getNow()); 125 params.put("t", HttpTools.getNow());
104 String response = HttpTools.requestByMapWithToken(URL_LOGIN, "DELETE", params, token + "PPPPPP"); 126 String response = HttpTools.requestByMapWithToken(URL_LOGIN, "DELETE", params, token + "PPPPPP");
105 System.out.println("logout success:" + response); 127 System.out.println("logout success:" + response);
  128 + Assert.assertTrue(response == null);
106 } 129 }
107 } 130 }
@@ -3,7 +3,9 @@ package com.xkl.uspih; @@ -3,7 +3,9 @@ package com.xkl.uspih;
3 import com.xkl.Constants; 3 import com.xkl.Constants;
4 import com.xkl.EncodeTools; 4 import com.xkl.EncodeTools;
5 import com.xkl.HttpTools; 5 import com.xkl.HttpTools;
  6 +import com.xkl.RtnCodeTools;
6 import org.json.JSONObject; 7 import org.json.JSONObject;
  8 +import org.junit.Assert;
7 import org.junit.Test; 9 import org.junit.Test;
8 10
9 import java.util.HashMap; 11 import java.util.HashMap;
@@ -39,6 +41,7 @@ public class ReportTest { @@ -39,6 +41,7 @@ public class ReportTest {
39 Map<String, String> params = new HashMap<String, String>(); 41 Map<String, String> params = new HashMap<String, String>();
40 params.put("json_report", Data.AMP_REPORT); 42 params.put("json_report", Data.AMP_REPORT);
41 String response = HttpTools.requestByMapWithToken(URL_REPORT, "POST", params, token); 43 String response = HttpTools.requestByMapWithToken(URL_REPORT, "POST", params, token);
  44 + Assert.assertTrue(RtnCodeTools.verifyCode(response, Constants.CODE_SUCC));
42 System.out.println("add report success:" + response); 45 System.out.println("add report success:" + response);
43 } 46 }
44 47
@@ -48,6 +51,7 @@ public class ReportTest { @@ -48,6 +51,7 @@ public class ReportTest {
48 Map<String, String> params = new HashMap<String, String>(); 51 Map<String, String> params = new HashMap<String, String>();
49 params.put("report_id", "133"); 52 params.put("report_id", "133");
50 String response = HttpTools.requestByMapWithToken(URL_REPORT, "DELETE", params, token); 53 String response = HttpTools.requestByMapWithToken(URL_REPORT, "DELETE", params, token);
  54 + Assert.assertTrue(RtnCodeTools.verifyCode(response, Constants.REPORT_INVALID_ERROR) || RtnCodeTools.verifyCode(response, Constants.CODE_SUCC));
51 System.out.println("delete report:" + response); 55 System.out.println("delete report:" + response);
52 } 56 }
53 } 57 }
@@ -3,7 +3,9 @@ package com.xkl.uspih; @@ -3,7 +3,9 @@ package com.xkl.uspih;
3 import com.xkl.Constants; 3 import com.xkl.Constants;
4 import com.xkl.EncodeTools; 4 import com.xkl.EncodeTools;
5 import com.xkl.HttpTools; 5 import com.xkl.HttpTools;
  6 +import com.xkl.RtnCodeTools;
6 import org.json.JSONObject; 7 import org.json.JSONObject;
  8 +import org.junit.Assert;
7 import org.junit.Test; 9 import org.junit.Test;
8 10
9 import java.util.HashMap; 11 import java.util.HashMap;
@@ -39,6 +41,7 @@ public class UsrAccountTest { @@ -39,6 +41,7 @@ public class UsrAccountTest {
39 Map<String, String> params = new HashMap<String, String>(); 41 Map<String, String> params = new HashMap<String, String>();
40 params.put("usraccount", Constants.USR_ACC); 42 params.put("usraccount", Constants.USR_ACC);
41 String response = HttpTools.requestByMapWithToken(URL_USER, "GET", params, token); 43 String response = HttpTools.requestByMapWithToken(URL_USER, "GET", params, token);
  44 + Assert.assertTrue(RtnCodeTools.verifyCode(response, Constants.CODE_SUCC));
42 System.out.println("verify status:" + response); 45 System.out.println("verify status:" + response);
43 } 46 }
44 47
@@ -49,6 +52,7 @@ public class UsrAccountTest { @@ -49,6 +52,7 @@ public class UsrAccountTest {
49 Map<String, String> params = new HashMap<String, String>(); 52 Map<String, String> params = new HashMap<String, String>();
50 params.put("usraccount",Constants.USR_ACC + "not exist account"); 53 params.put("usraccount",Constants.USR_ACC + "not exist account");
51 String response = HttpTools.requestByMapWithToken(URL_USER, "GET", params, token); 54 String response = HttpTools.requestByMapWithToken(URL_USER, "GET", params, token);
  55 + Assert.assertTrue(RtnCodeTools.verifyCode(response, Constants.USER_NOT_FOUND));
52 System.out.println("verify status:" + response); 56 System.out.println("verify status:" + response);
53 } 57 }
54 } 58 }