UrlBuilderTest.java 1.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
package me.zhyd.oauth.utils;

import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.request.AuthWeChatRequest;
import org.junit.Assert;
import org.junit.Test;

/**
 * <p>
 * UrlBuilder测试类
 * </p>
 *
不合群的混子's avatar
不合群的混子 已提交
14
 * @author yangkai.shen (https://xkcoding.com)
15 16 17 18 19 20 21 22 23 24 25
 * @date Created in 2019-07-18 16:36
 */
public class UrlBuilderTest {
    @Test
    public void testUrlBuilder() {
        AuthConfig config = new AuthConfig();
        config.setClientId("appid-110110110");
        config.setClientSecret("secret-110110110");
        config.setRedirectUri("https://xkcoding.com");
        config.setState(AuthState.create(AuthSource.WECHAT));
        String build = UrlBuilder.fromBaseUrl(AuthSource.WECHAT.authorize())
不合群的混子's avatar
不合群的混子 已提交
26 27 28 29 30 31
            .queryParam("appid", config.getClientId())
            .queryParam("redirect_uri", config.getRedirectUri())
            .queryParam("response_type", "code")
            .queryParam("scope", "snsapi_login")
            .queryParam("state", config.getState().concat("#wechat_redirect"))
            .build(false);
32 33 34 35 36 37
        AuthWeChatRequest request = new AuthWeChatRequest(config);
        String authorize = request.authorize();
        Assert.assertEquals(build, authorize);
        AuthState.delete(AuthSource.WECHAT);
    }
}