Authored by zhaoyue

Add admin info test

  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 +}