UsrAccountTest.java 1.89 KB
package com.xkl.uspih;

import com.xkl.Constants;
import com.xkl.EncodeTools;
import com.xkl.HttpTools;
import org.json.JSONObject;
import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

/**
 * User Account Verify
 * zhaoyue
 * 2017-1-14
 */

public class UsrAccountTest {
    private static final String URL_LOGIN = Constants.URL_PREFIX + "/uspih/account";
    private static final String URL_USER = Constants.URL_PREFIX + "/uspihusr";


    public static String loginAndGetToken(String user, String pass) {
        Map<String, String> params = new HashMap<String, String>();
        params.put("account", user);
        params.put("password", EncodeTools.encode("MD5", pass));
        params.put("t", HttpTools.getNow());
        String response = HttpTools.requestByMap(URL_LOGIN, "POST", params);
        System.out.println("login success:" + response);
        JSONObject jsonObject = new JSONObject(response);
        JSONObject content = jsonObject.getJSONObject("content");
        return content.getString("userId") + "_" + content.getString("token");
    }


    @Test
    public void testAccountExistVerify() {
        String token = loginAndGetToken(Constants.ADMIN_ACCOUNT, Constants.ADMIN_PWD);
        Map<String, String> params = new HashMap<String, String>();
        params.put("usraccount", Constants.USR_ACC);
        String response = HttpTools.requestByMapWithToken(URL_USER, "GET", params, token);
        System.out.println("verify status:" + response);
    }


    @Test
    public void testAccountNotExist() {
        String token = loginAndGetToken(Constants.ADMIN_ACCOUNT, Constants.ADMIN_PWD);
        Map<String, String> params = new HashMap<String, String>();
        params.put("usraccount",Constants.USR_ACC + "not exist account");
        String response = HttpTools.requestByMapWithToken(URL_USER, "GET", params, token);
        System.out.println("verify status:" + response);
    }
}