Authored by fangyeqing

ADD:register test

... ... @@ -5,11 +5,13 @@ package com.xkl;
*/
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 = "http://139.129.166.85:8090";
String URL_PREFIX = "https://www.hanhezy.com:8090/";
String KEY = "weixin";
String KEY_ID = "1";
String MALE = "0";
String FEMALE = "1";
}
... ...
... ... @@ -12,6 +12,7 @@ import java.util.Map;
*/
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>();
... ... @@ -48,4 +49,41 @@ public class TokenTest {
String response = HttpTools.requestByMapWithToken(URL_LOGIN,"DELETE",params,token);
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);
JSONObject jsonObject = new JSONObject(response);
JSONObject content = jsonObject.getJSONObject("content");
return content.getString("userId") + "_" + content.getString("token");
}
/**
* 管理员登录接口
*/
@Test
public void adminTestLogin(){
System.out.println(adminLoginAndGetToken("user1","pass1"));
}
/**
* 管理员退出登录接口
*/
@Test
public void adminLogout(){
String token = loginAndGetToken("user1","pass1");
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);
System.out.println(response);
}
}
... ...
... ... @@ -15,11 +15,50 @@ public class UserInfoTest {
private static final String URL_USER = Constants.URL_PREFIX + "/userInfo";
/**
* 用户注册
* 用户注册:
* register(String adminUser,String adminPass,
String user,String pass,String name,String sex,String birthDate,String phone,String idcard)
*/
@Test
public void testRegister(){
register("15211112222","pass152");
String adminUser = "user1";
String adminPass = "pass1";
String user = "15211112222";
String pass = "pass152";
String name = "usernameTest";
String sex = Constants.MALE;
String birthDate= "1966-06-12";
String phone = "13011112222";
String idcard = "130105196606125555";
register(adminUser,adminPass,user,pass,name,sex,birthDate,phone,idcard);
}
@Test
public void testRegisterWithDiffId(){
String adminUser = "user1";
String adminPass = "pass1";
String user = "15233334444";
String pass = "pass152";
String name = "usernameTest1";
String sex = Constants.MALE;
String birthDate= "1966-06-12";
String phone = "13011112222";
String idcard = "110000196606125555";
register(adminUser,adminPass,user,pass,name,sex,birthDate,phone,idcard);
}
@Test
public void testRegisterWithOutIdCard(){
String adminUser = "user1";
String adminPass = "pass1";
String user = "15222223333";
String pass = "pass152";
String name = "usernameTest2";
String sex = Constants.FEMALE;
String birthDate= "1999-12-22";
String phone = "13011112222";
String idcard = null;
register(adminUser,adminPass,user,pass,name,sex,birthDate,phone,idcard);
}
/**
... ... @@ -27,7 +66,7 @@ public class UserInfoTest {
*/
@Test
public void testModPass(){
register("15211112222","pass152");
register("user1","pass1","15211112222","pass152","usernameTest","1","1966-06-12","13011112222","130105196606125555");
Map<String,String> params = new HashMap<String, String>();
params.put("password",EncodeTools.encode("MD5","pass152_new"));
... ... @@ -57,14 +96,22 @@ public class UserInfoTest {
System.out.println(response);
}
public void register(String user,String pass){
public void 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));
params.put("name",name);
params.put("sex",sex);
params.put("birthDate",birthDate);
params.put("phone",phone);
if(idcard!=null&&idcard!="")
params.put("idcard",idcard);
params.put("t",HttpTools.getNow());
params.put("type",Constants.KEY_ID);
params.put("sign",HttpTools.getSign(params));
String response = HttpTools.requestByMap(URL_USER,"POST",params);
String token = TokenTest.adminLoginAndGetToken(adminUser,adminPass);
String response = HttpTools.requestByMapWithToken(URL_USER,"POST",params,token);
System.out.println(response);
}
... ... @@ -73,13 +120,29 @@ public class UserInfoTest {
*/
@Test
public void testRegisterNoSign(){
String adminUser = "user1";
String adminPass = "pass1";
String user = "15211112222";
String pass = "pass152";
String name = "usernameTest";
String sex = Constants.MALE;
String birthDate= "1966-06-12";
String phone = "13011112222";
String idcard = "130105196606125555";
Map<String,String> params = new HashMap<String, String>();
params.put("username","15211112222");
params.put("password",EncodeTools.encode("MD5","pass152"));
params.put("username",user);
params.put("password",EncodeTools.encode("MD5",pass));
params.put("name",name);
params.put("sex",sex);
params.put("birthDate",birthDate);
params.put("phone",phone);
if(idcard!=null&&idcard!="")
params.put("idcard",idcard);
params.put("t",HttpTools.getNow());
params.put("type",Constants.KEY_ID);
params.put("sign","nosign");
String response = HttpTools.requestByMap(URL_USER,"POST",params);
String token = TokenTest.adminLoginAndGetToken(adminUser,adminPass);
String response = HttpTools.requestByMapWithToken(URL_USER,"POST",params,token);
System.out.println(response);
}
... ... @@ -88,13 +151,30 @@ public class UserInfoTest {
*/
@Test
public void testRegisterWrongTime(){
String adminUser = "user1";
String adminPass = "pass1";
String user = "15211112222";
String pass = "pass152";
String name = "usernameTest";
String sex = Constants.MALE;
String birthDate= "1966-06-12";
String phone = "13011112222";
String idcard = "130105196606125555";
Map<String,String> params = new HashMap<String, String>();
params.put("username","15211112222");
params.put("password",EncodeTools.encode("MD5","pass152"));
params.put("t",HttpTools.getNow()+100000);
params.put("username",user);
params.put("password",EncodeTools.encode("MD5",pass));
params.put("name",name);
params.put("sex",sex);
params.put("birthDate",birthDate);
params.put("phone",phone);
if(idcard!=null&&idcard!="")
params.put("idcard",idcard);
params.put("t",HttpTools.getNow()+60*60*26);
params.put("type",Constants.KEY_ID);
params.put("sign",HttpTools.getSign(params));
String response = HttpTools.requestByMap(URL_USER,"POST",params);
params.put("sign","nosign");
String token = TokenTest.adminLoginAndGetToken(adminUser,adminPass);
String response = HttpTools.requestByMapWithToken(URL_USER,"POST",params,token);
System.out.println(response);
}
}
... ...