Authored by zhaoyue

Add assert verify

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