Authored by zhaoyue

Add qrcode testcases

git pull
#git add --all src/*
git add --all src/*
git add --all lib/*
git add push.sh
git add pom.xml
git commit -m "Add health exam doc"
git commit -m "Add qrcode testcases"
git push origin master
git status
git pull
... ...
... ... @@ -4,16 +4,29 @@ package com.xkl;
* Created by win7 on 2016/12/25.
*/
public interface Constants {
// String URL_PREFIX = "http://127.0.0.1:8090";
//String URL_PREFIX = "http://139.129.166.85:8090";
/**
* 服务地址
*/
// String URL_PREFIX = "http://127.0.0.1:8090";
String URL_PREFIX = "https://www.hanhezy.com:8090/";
// String URL_PREFIX = "http://139.129.166.85:8090";
/**
* 测试用 用户名、密码、openid、openidtype
*/
String USR_ACC = "user1";
String USR_PWD = "pass1";
String USR_OPENID = "abcdefghijklmnopqrstuvwxyz123456";
String USR_OPENID_TYPE = "0";
/**
* 密钥
*/
// 加密密钥
String KEY = "weixin";
// 密钥ID
String KEY_ID = "1";
/**
* 性别
*/
String MALE = "0";
String FEMALE = "1";
... ...
... ... @@ -25,8 +25,8 @@ public class OpenIdTest {
Map<String,String> params = new HashMap<String, String>();
params.put("username","user1");
params.put("password",EncodeTools.encode("MD5","pass1"));
params.put("openId","abcdefghijklmnopqrstuvwxyz123456");
params.put("openIdType","0");
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));
... ... @@ -50,6 +50,8 @@ public class OpenIdTest {
params.put("sign",HttpTools.getSign(params));
String response = HttpTools.requestByMap(URL_OPEN_ID,"DELETE",params);
System.out.println(response);
// 解除绑定后,又重新绑定好以便下次测试
testBind();
}
/**
... ...
package com.xkl;
import org.json.JSONObject;
import org.junit.Assert;
import org.junit.Test;
import java.util.HashMap;
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
*/
@Test
public void testGetQrWithToken() {
String token = TokenTest.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_GETQR_WITHTOKEN, "GET", params, token);
System.out.println(response);
Assert.assertTrue(hasQrCode(response));
}
/**
* 使用openid得到qrcode
*/
@Test
public void testGetQrWithOpenid() {
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);
System.out.println(response);
Assert.assertTrue(hasQrCode(response));
}
private boolean hasQrCode(String responseStr) {
try {
JSONObject res = new JSONObject(responseStr);
String qrcode = res.getJSONObject("content").getString("qrcode");
Assert.assertNotEquals("qrcode", "");
Assert.assertNotEquals("qrcode", null);
} catch (Exception e) {
return false;
}
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.inneruse.qrcode;
import com.xkl.Constants;
import com.xkl.EncodeTools;
import com.xkl.HttpTools;
import com.xkl.TokenTest;
import org.json.JSONObject;
import org.junit.Assert;
import org.junit.Test;
import java.util.HashMap;
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";
/**
* 1 .使用用户名密码得到qrcode
*/
@Test
public void testGetQrWithAccPwd() {
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);
System.out.println(response);
Assert.assertTrue(hasQrCode(response));
}
/**
* 2 .使用openid得到qrcode
*/
@Test
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.requestByMap(URL_GETQR_WITHOPNEID, "GET", params);
System.out.println(response);
Assert.assertTrue(hasQrCode(response));
}
/**
* 3 .使用token得到qrcode
*/
@Test
public void testGetQrWithToken() {
String token = TokenTest.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_GETQR_WITHTOKEN, "GET", params, token);
System.out.println(response);
Assert.assertTrue(hasQrCode(response));
}
/**
* 4 .使用qrcode查询个人信息
*/
@Test
public void testGetUsrInfoWithQr() {
String qrcode = getQrCode();
Map<String, String> params = new HashMap<String, String>();
params.put("qrcode", qrcode);
params.put("t", HttpTools.getNow());
String response = HttpTools.requestByMap(URL_GETUSRINFO_WITHQR, "GET", params);
System.out.println(response);
Assert.assertTrue(hasSuccCode(response));
}
private boolean hasQrCode(String responseStr) {
try {
JSONObject res = new JSONObject(responseStr);
String qrcode = res.getJSONObject("content").getString("qrcode");
Assert.assertNotEquals("qrcode", "");
Assert.assertNotEquals("qrcode", null);
} catch (Exception e) {
return false;
}
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;
}
}
... ...
... ... @@ -37,9 +37,9 @@ public class ReportTest {
String token = loginAndGetToken(Data.ADMIN_ACCOUNT, Data.ADMIN_PWD);
Map<String, String> params = new HashMap<String, String>();
// 程序自动生成json报告。
// String report =Data.AMP_REPORT;
String report = Data.AMP_REPORT;
// 从本地加载json报告。
String report = Data.readTxtFile("C:\\Users\\zhaoyue\\Desktop\\report.txt");
// String report = Data.readTxtFile("C:\\Users\\zhaoyue\\Desktop\\report.txt");
params.put("json_report", report);
String response = HttpTools.requestByMapWithToken(URL_REPORT, "POST", params, token);
System.out.println("add report success:" + response);
... ...