Authored by zhaoyue

Add admin info test

1 git add --all src/* 1 git add --all src/*
2 git add push.sh 2 git add push.sh
3 git add pom.xml 3 git add pom.xml
4 -git commit -m "Modify to make better" 4 +git commit -m "Add admin info test"
5 git push origin master 5 git push origin master
6 git status 6 git status
7 git pull 7 git pull
@@ -5,7 +5,7 @@ package com.xkl; @@ -5,7 +5,7 @@ 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"; 8 +// String URL_PREFIX = "http://127.0.0.1:8090";
9 // String URL_PREFIX = "http://139.129.166.85: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
  1 +package com.xkl.upsoft;
  2 +
  3 +import com.xkl.Constants;
  4 +import com.xkl.EncodeTools;
  5 +import com.xkl.HttpTools;
  6 +import org.json.JSONObject;
  7 +import org.junit.Test;
  8 +
  9 +import java.util.HashMap;
  10 +import java.util.Map;
  11 +
  12 +/**
  13 + * 获取admin个人信息
  14 + */
  15 +
  16 +public class AdminInfoTest {
  17 + private static final String URL_ADMININFO = Constants.URL_PREFIX + "/adminInfo";
  18 + private static final String URL_LOGIN = Constants.URL_PREFIX + "/upsoft/account";
  19 +
  20 + public static String loginAndGetToken(String user, String pass) {
  21 + Map<String, String> params = new HashMap<String, String>();
  22 + params.put("account", user);
  23 + params.put("password", EncodeTools.encode("MD5", pass));
  24 + params.put("t", HttpTools.getNow());
  25 + String response = HttpTools.requestByMap(URL_LOGIN, "POST", params);
  26 + System.out.println("login success:" + response);
  27 + JSONObject jsonObject = new JSONObject(response);
  28 + JSONObject content = jsonObject.getJSONObject("content");
  29 + return content.getString("userId") + "_" + content.getString("token");
  30 + }
  31 + @Test
  32 + public void testGetAdminInfo() {
  33 + String token = loginAndGetToken(Data.ADMIN_ACCOUNT, Data.ADMIN_PWD);
  34 + Map<String, String> params = new HashMap<String, String>();
  35 + params.put("t", HttpTools.getNow());
  36 + String response = HttpTools.requestByMapWithToken(URL_ADMININFO, "GET", params, token);
  37 + System.out.println("admin info get success:" + response);
  38 + }
  39 +}