|
|
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);
|
|
|
}
|
|
|
|
...
|
...
|
|