Authored by zhaoyue

Add qrcode testcases

1 git pull 1 git pull
2 -#git add --all src/* 2 +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 "Add health exam doc" 6 +git commit -m "Add qrcode testcases"
7 git push origin master 7 git push origin master
8 git status 8 git status
9 git pull 9 git pull
@@ -4,16 +4,29 @@ package com.xkl; @@ -4,16 +4,29 @@ package com.xkl;
4 * Created by win7 on 2016/12/25. 4 * Created by win7 on 2016/12/25.
5 */ 5 */
6 public interface Constants { 6 public interface Constants {
7 -  
8 - // String URL_PREFIX = "http://127.0.0.1:8090";  
9 - //String URL_PREFIX = "http://139.129.166.85:8090"; 7 + /**
  8 + * 服务地址
  9 + */
  10 +// String URL_PREFIX = "http://127.0.0.1:8090";
10 String URL_PREFIX = "https://www.hanhezy.com:8090/"; 11 String URL_PREFIX = "https://www.hanhezy.com:8090/";
11 -  
12 - 12 + // String URL_PREFIX = "http://139.129.166.85:8090";
  13 + /**
  14 + * 测试用 用户名、密码、openid、openidtype
  15 + */
  16 + String USR_ACC = "user1";
  17 + String USR_PWD = "pass1";
  18 + String USR_OPENID = "abcdefghijklmnopqrstuvwxyz123456";
  19 + String USR_OPENID_TYPE = "0";
  20 + /**
  21 + * 密钥
  22 + */
13 // 加密密钥 23 // 加密密钥
14 String KEY = "weixin"; 24 String KEY = "weixin";
15 // 密钥ID 25 // 密钥ID
16 String KEY_ID = "1"; 26 String KEY_ID = "1";
  27 + /**
  28 + * 性别
  29 + */
17 String MALE = "0"; 30 String MALE = "0";
18 String FEMALE = "1"; 31 String FEMALE = "1";
19 32
@@ -25,8 +25,8 @@ public class OpenIdTest { @@ -25,8 +25,8 @@ public class OpenIdTest {
25 Map<String,String> params = new HashMap<String, String>(); 25 Map<String,String> params = new HashMap<String, String>();
26 params.put("username","user1"); 26 params.put("username","user1");
27 params.put("password",EncodeTools.encode("MD5","pass1")); 27 params.put("password",EncodeTools.encode("MD5","pass1"));
28 - params.put("openId","abcdefghijklmnopqrstuvwxyz123456");  
29 - params.put("openIdType","0"); 28 + params.put("openId",Constants.USR_OPENID);
  29 + params.put("openIdType",Constants.USR_OPENID_TYPE);
30 params.put("t",HttpTools.getNow()); 30 params.put("t",HttpTools.getNow());
31 params.put("type",Constants.KEY_ID); 31 params.put("type",Constants.KEY_ID);
32 params.put("sign",HttpTools.getSign(params)); 32 params.put("sign",HttpTools.getSign(params));
@@ -50,6 +50,8 @@ public class OpenIdTest { @@ -50,6 +50,8 @@ public class OpenIdTest {
50 params.put("sign",HttpTools.getSign(params)); 50 params.put("sign",HttpTools.getSign(params));
51 String response = HttpTools.requestByMap(URL_OPEN_ID,"DELETE",params); 51 String response = HttpTools.requestByMap(URL_OPEN_ID,"DELETE",params);
52 System.out.println(response); 52 System.out.println(response);
  53 + // 解除绑定后,又重新绑定好以便下次测试
  54 + testBind();
53 } 55 }
54 56
55 /** 57 /**
  1 +package com.xkl;
  2 +
  3 +import org.json.JSONObject;
  4 +import org.junit.Assert;
  5 +import org.junit.Test;
  6 +
  7 +import java.util.HashMap;
  8 +import java.util.Map;
  9 +
  10 +/**
  11 + * Created by zhaoyue on 2017/3/11.
  12 + */
  13 +public class QrCodeTest {
  14 + private static final String URL_USER = Constants.URL_PREFIX + "/userInfo";
  15 +
  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";
  19 + 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 +
  25 + /**
  26 + * 使用token得到qrcode
  27 + */
  28 + @Test
  29 + public void testGetQrWithToken() {
  30 + String token = TokenTest.loginAndGetToken(Constants.USR_ACC, Constants.USR_PWD);
  31 + Map<String, String> params = new HashMap<String, String>();
  32 + params.put("t", HttpTools.getNow());
  33 + params.put("type", Constants.KEY_ID);
  34 + params.put("sign", HttpTools.getSign(params));
  35 + String response = HttpTools.requestByMapWithToken(URL_GETQR_WITHTOKEN, "GET", params, token);
  36 + System.out.println(response);
  37 + Assert.assertTrue(hasQrCode(response));
  38 + }
  39 +
  40 + /**
  41 + * 使用openid得到qrcode
  42 + */
  43 + @Test
  44 + public void testGetQrWithOpenid() {
  45 + String token = TokenTest.loginAndGetToken(Constants.USR_ACC, Constants.USR_PWD);
  46 + 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());
  50 + params.put("type", Constants.KEY_ID);
  51 + params.put("sign", HttpTools.getSign(params));
  52 + String response = HttpTools.requestByMap(URL_GETQR_WITHOPNEID, "GET", params);
  53 + System.out.println(response);
  54 + Assert.assertTrue(hasQrCode(response));
  55 + }
  56 +
  57 +
  58 +
  59 + private boolean hasQrCode(String responseStr) {
  60 + try {
  61 + JSONObject res = new JSONObject(responseStr);
  62 + String qrcode = res.getJSONObject("content").getString("qrcode");
  63 + Assert.assertNotEquals("qrcode", "");
  64 + Assert.assertNotEquals("qrcode", null);
  65 + } catch (Exception e) {
  66 + return false;
  67 + }
  68 + return true;
  69 + }
  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 +
  98 +}
  1 +package com.xkl.inneruse.qrcode;
  2 +
  3 +import com.xkl.Constants;
  4 +import com.xkl.EncodeTools;
  5 +import com.xkl.HttpTools;
  6 +import com.xkl.TokenTest;
  7 +import org.json.JSONObject;
  8 +import org.junit.Assert;
  9 +import org.junit.Test;
  10 +
  11 +import java.util.HashMap;
  12 +import java.util.Map;
  13 +
  14 +/**
  15 + * Created by zhaoyue on 2017/3/11.
  16 + */
  17 +public class QrCodeTest {
  18 + private static final String URL_USER = Constants.URL_PREFIX + "/userInfo";
  19 +
  20 +
  21 + public static final String URL_GETQR_WITHACCPWD = Constants.URL_PREFIX + "/qrcode/getQrWithAccPwd";
  22 + public static final String URL_GETQR_WITHTOKEN = Constants.URL_PREFIX + "/qrcode/getQrWithToken";
  23 + public static final String URL_GETQR_WITHOPNEID = Constants.URL_PREFIX + "/qrcode/getQrWithOpenId";
  24 + public static final String URL_GETUSRINFO_WITHQR = Constants.URL_PREFIX + "/qrcode/getUsrInfoWithQr";
  25 +
  26 +
  27 + /**
  28 + * 1 .使用用户名密码得到qrcode
  29 + */
  30 + @Test
  31 + public void testGetQrWithAccPwd() {
  32 + Map<String, String> params = new HashMap<String, String>();
  33 + params.put("username", Constants.USR_ACC);
  34 + params.put("password", EncodeTools.encode("MD5", Constants.USR_PWD));
  35 + params.put("t", HttpTools.getNow());
  36 + String response = HttpTools.requestByMap(URL_GETQR_WITHACCPWD, "GET", params);
  37 + System.out.println(response);
  38 + Assert.assertTrue(hasQrCode(response));
  39 + }
  40 +
  41 + /**
  42 + * 2 .使用openid得到qrcode
  43 + */
  44 + @Test
  45 + public void testGetQrWithOpenid() {
  46 + 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());
  50 + params.put("type", Constants.KEY_ID);
  51 + params.put("sign", HttpTools.getSign(params));
  52 + String response = HttpTools.requestByMap(URL_GETQR_WITHOPNEID, "GET", params);
  53 + System.out.println(response);
  54 + Assert.assertTrue(hasQrCode(response));
  55 + }
  56 +
  57 + /**
  58 + * 3 .使用token得到qrcode
  59 + */
  60 + @Test
  61 + public void testGetQrWithToken() {
  62 + String token = TokenTest.loginAndGetToken(Constants.USR_ACC, Constants.USR_PWD);
  63 + Map<String, String> params = new HashMap<String, String>();
  64 + params.put("t", HttpTools.getNow());
  65 + params.put("type", Constants.KEY_ID);
  66 + params.put("sign", HttpTools.getSign(params));
  67 + String response = HttpTools.requestByMapWithToken(URL_GETQR_WITHTOKEN, "GET", params, token);
  68 + System.out.println(response);
  69 + Assert.assertTrue(hasQrCode(response));
  70 + }
  71 +
  72 +
  73 + /**
  74 + * 4 .使用qrcode查询个人信息
  75 + */
  76 + @Test
  77 + public void testGetUsrInfoWithQr() {
  78 + String qrcode = getQrCode();
  79 + Map<String, String> params = new HashMap<String, String>();
  80 + params.put("qrcode", qrcode);
  81 + params.put("t", HttpTools.getNow());
  82 + String response = HttpTools.requestByMap(URL_GETUSRINFO_WITHQR, "GET", params);
  83 + System.out.println(response);
  84 + Assert.assertTrue(hasSuccCode(response));
  85 + }
  86 +
  87 +
  88 + private boolean hasQrCode(String responseStr) {
  89 + try {
  90 + JSONObject res = new JSONObject(responseStr);
  91 + String qrcode = res.getJSONObject("content").getString("qrcode");
  92 + Assert.assertNotEquals("qrcode", "");
  93 + Assert.assertNotEquals("qrcode", null);
  94 + } catch (Exception e) {
  95 + return false;
  96 + }
  97 + return true;
  98 + }
  99 +
  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 +
  112 + private String getQrCode() {
  113 + Map<String, String> params = new HashMap<String, String>();
  114 + params.put("username", Constants.USR_ACC);
  115 + params.put("password", EncodeTools.encode("MD5", Constants.USR_PWD));
  116 + params.put("t", HttpTools.getNow());
  117 + String response = HttpTools.requestByMap(URL_GETQR_WITHACCPWD, "GET", params);
  118 + String qrcode = null;
  119 + try {
  120 + JSONObject res = new JSONObject(response);
  121 + qrcode = res.getJSONObject("content").getString("qrcode");
  122 + } catch (Exception e) {
  123 + return null;
  124 + }
  125 + return qrcode;
  126 + }
  127 +
  128 +
  129 +}
@@ -37,9 +37,9 @@ public class ReportTest { @@ -37,9 +37,9 @@ public class ReportTest {
37 String token = loginAndGetToken(Data.ADMIN_ACCOUNT, Data.ADMIN_PWD); 37 String token = loginAndGetToken(Data.ADMIN_ACCOUNT, Data.ADMIN_PWD);
38 Map<String, String> params = new HashMap<String, String>(); 38 Map<String, String> params = new HashMap<String, String>();
39 // 程序自动生成json报告。 39 // 程序自动生成json报告。
40 -// String report =Data.AMP_REPORT; 40 + String report = Data.AMP_REPORT;
41 // 从本地加载json报告。 41 // 从本地加载json报告。
42 - String report = Data.readTxtFile("C:\\Users\\zhaoyue\\Desktop\\report.txt"); 42 +// String report = Data.readTxtFile("C:\\Users\\zhaoyue\\Desktop\\report.txt");
43 params.put("json_report", report); 43 params.put("json_report", report);
44 String response = HttpTools.requestByMapWithToken(URL_REPORT, "POST", params, token); 44 String response = HttpTools.requestByMapWithToken(URL_REPORT, "POST", params, token);
45 System.out.println("add report success:" + response); 45 System.out.println("add report success:" + response);