Blame view

src/test/java/com/xkl/UserInfoTest.java 2.88 KB
fangyeqing authored
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
package com.xkl;

import org.junit.Test;

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

import static com.xkl.TokenTest.loginAndGetToken;

/**
 * Created by win7 on 2016/12/25.
 * 用户注册、修改密码、获取个人信息
 */
public class UserInfoTest {
    private static final String URL_USER = Constants.URL_PREFIX + "/userInfo";

    @Test
    public void testRegister(){
       register("15211112222","pass152");
    }

    @Test
    public void testModPass(){
        register("15211112222","pass152");

        Map<String,String> params = new HashMap<String, String>();
        params.put("password",EncodeTools.encode("MD5","pass152_new"));
        params.put("t",HttpTools.getNow());
        params.put("type","1");
        params.put("sign",HttpTools.getSign(params));
        //获取token
        String token = loginAndGetToken("15211112222","pass152");
        System.out.println(token);
        String response = HttpTools.requestByMapWithToken(URL_USER,"PUT",params,token);
        System.out.println(response);
    }

    @Test
    public void testGetUserInfo(){
        Map<String,String> params = new HashMap<String, String>();
        params.put("t",HttpTools.getNow());
        params.put("type","1");
        params.put("sign",HttpTools.getSign(params));
        //获取token
        String token = loginAndGetToken("user1","pass1");
        System.out.println(token);
        String response = HttpTools.requestByMapWithToken(URL_USER,"GET",params,token);
        System.out.println(response);
    }

    public void register(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","1");
        params.put("sign",HttpTools.getSign(params));
        String response = HttpTools.requestByMap(URL_USER,"POST",params);
        System.out.println(response);
    }

    @Test
    public void testRegisterNoSign(){
        Map<String,String> params = new HashMap<String, String>();
        params.put("username","15211112222");
        params.put("password",EncodeTools.encode("MD5","pass152"));
        params.put("t",HttpTools.getNow());
        params.put("type","1");
        params.put("sign","nosign");
        String response = HttpTools.requestByMap(URL_USER,"POST",params);
        System.out.println(response);
    }

    @Test
    public void testRegisterWrongTime(){
        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("type","1");
        params.put("sign",HttpTools.getSign(params));
        String response = HttpTools.requestByMap(URL_USER,"POST",params);
        System.out.println(response);
    }
}