Authored by fangyeqing

ADD:register test

@@ -5,11 +5,13 @@ package com.xkl; @@ -5,11 +5,13 @@ package com.xkl;
5 */ 5 */
6 public interface Constants { 6 public interface Constants {
7 7
8 - // String URL_PREFIX = "http://127.0.0.1:8090";  
9 -// String URL_PREFIX = "http://139.129.166.85:8090"; 8 + //String URL_PREFIX = "http://127.0.0.1:8090";
  9 + //String URL_PREFIX = "http://139.129.166.85:8090";
10 String URL_PREFIX = "https://www.hanhezy.com:8090/"; 10 String URL_PREFIX = "https://www.hanhezy.com:8090/";
11 11
12 String KEY = "weixin"; 12 String KEY = "weixin";
13 String KEY_ID = "1"; 13 String KEY_ID = "1";
  14 + String MALE = "0";
  15 + String FEMALE = "1";
14 16
15 } 17 }
@@ -12,6 +12,7 @@ import java.util.Map; @@ -12,6 +12,7 @@ import java.util.Map;
12 */ 12 */
13 public class TokenTest { 13 public class TokenTest {
14 private static final String URL_LOGIN = Constants.URL_PREFIX + "/token"; 14 private static final String URL_LOGIN = Constants.URL_PREFIX + "/token";
  15 + private static final String ADMIN_URL_LOGIN = Constants.URL_PREFIX + "/token/admin";
15 16
16 public static String loginAndGetToken(String user,String pass){ 17 public static String loginAndGetToken(String user,String pass){
17 Map<String,String> params = new HashMap<String, String>(); 18 Map<String,String> params = new HashMap<String, String>();
@@ -48,4 +49,41 @@ public class TokenTest { @@ -48,4 +49,41 @@ public class TokenTest {
48 String response = HttpTools.requestByMapWithToken(URL_LOGIN,"DELETE",params,token); 49 String response = HttpTools.requestByMapWithToken(URL_LOGIN,"DELETE",params,token);
49 System.out.println(response); 50 System.out.println(response);
50 } 51 }
  52 +
  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);
  62 + JSONObject jsonObject = new JSONObject(response);
  63 + JSONObject content = jsonObject.getJSONObject("content");
  64 + return content.getString("userId") + "_" + content.getString("token");
  65 + }
  66 +
  67 + /**
  68 + * 管理员登录接口
  69 + */
  70 + @Test
  71 + public void adminTestLogin(){
  72 + System.out.println(adminLoginAndGetToken("user1","pass1"));
  73 + }
  74 +
  75 + /**
  76 + * 管理员退出登录接口
  77 + */
  78 + @Test
  79 + public void adminLogout(){
  80 + String token = loginAndGetToken("user1","pass1");
  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);
  86 + System.out.println(response);
  87 + }
  88 +
51 } 89 }
@@ -15,11 +15,50 @@ public class UserInfoTest { @@ -15,11 +15,50 @@ public class UserInfoTest {
15 private static final String URL_USER = Constants.URL_PREFIX + "/userInfo"; 15 private static final String URL_USER = Constants.URL_PREFIX + "/userInfo";
16 16
17 /** 17 /**
18 - * 用户注册 18 + * 用户注册:
  19 + * register(String adminUser,String adminPass,
  20 + String user,String pass,String name,String sex,String birthDate,String phone,String idcard)
19 */ 21 */
20 @Test 22 @Test
21 public void testRegister(){ 23 public void testRegister(){
22 - register("15211112222","pass152"); 24 + String adminUser = "user1";
  25 + String adminPass = "pass1";
  26 + String user = "15211112222";
  27 + String pass = "pass152";
  28 + String name = "usernameTest";
  29 + String sex = Constants.MALE;
  30 + String birthDate= "1966-06-12";
  31 + String phone = "13011112222";
  32 + String idcard = "130105196606125555";
  33 + register(adminUser,adminPass,user,pass,name,sex,birthDate,phone,idcard);
  34 + }
  35 +
  36 + @Test
  37 + public void testRegisterWithDiffId(){
  38 + String adminUser = "user1";
  39 + String adminPass = "pass1";
  40 + String user = "15233334444";
  41 + String pass = "pass152";
  42 + String name = "usernameTest1";
  43 + String sex = Constants.MALE;
  44 + String birthDate= "1966-06-12";
  45 + String phone = "13011112222";
  46 + String idcard = "110000196606125555";
  47 + register(adminUser,adminPass,user,pass,name,sex,birthDate,phone,idcard);
  48 + }
  49 +
  50 + @Test
  51 + public void testRegisterWithOutIdCard(){
  52 + String adminUser = "user1";
  53 + String adminPass = "pass1";
  54 + String user = "15222223333";
  55 + String pass = "pass152";
  56 + String name = "usernameTest2";
  57 + String sex = Constants.FEMALE;
  58 + String birthDate= "1999-12-22";
  59 + String phone = "13011112222";
  60 + String idcard = null;
  61 + register(adminUser,adminPass,user,pass,name,sex,birthDate,phone,idcard);
23 } 62 }
24 63
25 /** 64 /**
@@ -27,7 +66,7 @@ public class UserInfoTest { @@ -27,7 +66,7 @@ public class UserInfoTest {
27 */ 66 */
28 @Test 67 @Test
29 public void testModPass(){ 68 public void testModPass(){
30 - register("15211112222","pass152"); 69 + register("user1","pass1","15211112222","pass152","usernameTest","1","1966-06-12","13011112222","130105196606125555");
31 70
32 Map<String,String> params = new HashMap<String, String>(); 71 Map<String,String> params = new HashMap<String, String>();
33 params.put("password",EncodeTools.encode("MD5","pass152_new")); 72 params.put("password",EncodeTools.encode("MD5","pass152_new"));
@@ -57,14 +96,22 @@ public class UserInfoTest { @@ -57,14 +96,22 @@ public class UserInfoTest {
57 System.out.println(response); 96 System.out.println(response);
58 } 97 }
59 98
60 - public void register(String user,String pass){ 99 + public void register(String adminUser,String adminPass,
  100 + String user,String pass,String name,String sex,String birthDate,String phone,String idcard){
61 Map<String,String> params = new HashMap<String, String>(); 101 Map<String,String> params = new HashMap<String, String>();
62 params.put("username",user); 102 params.put("username",user);
63 params.put("password",EncodeTools.encode("MD5",pass)); 103 params.put("password",EncodeTools.encode("MD5",pass));
  104 + params.put("name",name);
  105 + params.put("sex",sex);
  106 + params.put("birthDate",birthDate);
  107 + params.put("phone",phone);
  108 + if(idcard!=null&&idcard!="")
  109 + params.put("idcard",idcard);
64 params.put("t",HttpTools.getNow()); 110 params.put("t",HttpTools.getNow());
65 params.put("type",Constants.KEY_ID); 111 params.put("type",Constants.KEY_ID);
66 params.put("sign",HttpTools.getSign(params)); 112 params.put("sign",HttpTools.getSign(params));
67 - String response = HttpTools.requestByMap(URL_USER,"POST",params); 113 + String token = TokenTest.adminLoginAndGetToken(adminUser,adminPass);
  114 + String response = HttpTools.requestByMapWithToken(URL_USER,"POST",params,token);
68 System.out.println(response); 115 System.out.println(response);
69 } 116 }
70 117
@@ -73,13 +120,29 @@ public class UserInfoTest { @@ -73,13 +120,29 @@ public class UserInfoTest {
73 */ 120 */
74 @Test 121 @Test
75 public void testRegisterNoSign(){ 122 public void testRegisterNoSign(){
  123 + String adminUser = "user1";
  124 + String adminPass = "pass1";
  125 + String user = "15211112222";
  126 + String pass = "pass152";
  127 + String name = "usernameTest";
  128 + String sex = Constants.MALE;
  129 + String birthDate= "1966-06-12";
  130 + String phone = "13011112222";
  131 + String idcard = "130105196606125555";
76 Map<String,String> params = new HashMap<String, String>(); 132 Map<String,String> params = new HashMap<String, String>();
77 - params.put("username","15211112222");  
78 - params.put("password",EncodeTools.encode("MD5","pass152")); 133 + params.put("username",user);
  134 + params.put("password",EncodeTools.encode("MD5",pass));
  135 + params.put("name",name);
  136 + params.put("sex",sex);
  137 + params.put("birthDate",birthDate);
  138 + params.put("phone",phone);
  139 + if(idcard!=null&&idcard!="")
  140 + params.put("idcard",idcard);
79 params.put("t",HttpTools.getNow()); 141 params.put("t",HttpTools.getNow());
80 params.put("type",Constants.KEY_ID); 142 params.put("type",Constants.KEY_ID);
81 params.put("sign","nosign"); 143 params.put("sign","nosign");
82 - String response = HttpTools.requestByMap(URL_USER,"POST",params); 144 + String token = TokenTest.adminLoginAndGetToken(adminUser,adminPass);
  145 + String response = HttpTools.requestByMapWithToken(URL_USER,"POST",params,token);
83 System.out.println(response); 146 System.out.println(response);
84 } 147 }
85 148
@@ -88,13 +151,30 @@ public class UserInfoTest { @@ -88,13 +151,30 @@ public class UserInfoTest {
88 */ 151 */
89 @Test 152 @Test
90 public void testRegisterWrongTime(){ 153 public void testRegisterWrongTime(){
  154 + String adminUser = "user1";
  155 + String adminPass = "pass1";
  156 + String user = "15211112222";
  157 + String pass = "pass152";
  158 + String name = "usernameTest";
  159 + String sex = Constants.MALE;
  160 + String birthDate= "1966-06-12";
  161 + String phone = "13011112222";
  162 + String idcard = "130105196606125555";
91 Map<String,String> params = new HashMap<String, String>(); 163 Map<String,String> params = new HashMap<String, String>();
92 - params.put("username","15211112222");  
93 - params.put("password",EncodeTools.encode("MD5","pass152"));  
94 - params.put("t",HttpTools.getNow()+100000); 164 + params.put("username",user);
  165 + params.put("password",EncodeTools.encode("MD5",pass));
  166 + params.put("name",name);
  167 + params.put("sex",sex);
  168 + params.put("birthDate",birthDate);
  169 + params.put("phone",phone);
  170 + if(idcard!=null&&idcard!="")
  171 + params.put("idcard",idcard);
  172 + params.put("t",HttpTools.getNow()+60*60*26);
95 params.put("type",Constants.KEY_ID); 173 params.put("type",Constants.KEY_ID);
96 - params.put("sign",HttpTools.getSign(params));  
97 - String response = HttpTools.requestByMap(URL_USER,"POST",params); 174 + params.put("sign","nosign");
  175 + String token = TokenTest.adminLoginAndGetToken(adminUser,adminPass);
  176 + String response = HttpTools.requestByMapWithToken(URL_USER,"POST",params,token);
  177 +
98 System.out.println(response); 178 System.out.println(response);
99 } 179 }
100 } 180 }