package tech.easyflow.system.config;

import org.junit.Assert;
import org.junit.Test;
import tech.easyflow.common.web.exceptions.BusinessException;

/**
 * {@link AccountSecurityProperties} 测试。
 */
public class AccountSecurityPropertiesTest {

    /**
     * 验证默认重置密码符合强密码策略。
     */
    @Test
    public void shouldAcceptDefaultStrongResetPassword() {
        AccountSecurityProperties properties = new AccountSecurityProperties();

        properties.afterPropertiesSet();

        Assert.assertEquals("!QAZ2wsx", properties.getDefaultResetPassword());
        Assert.assertFalse(properties.isMultiLogin());
    }

    /**
     * 验证账号多端登录配置可以开启。
     */
    @Test
    public void shouldEnableAccountMultiLogin() {
        AccountSecurityProperties properties = new AccountSecurityProperties();

        properties.setMultiLogin(true);

        Assert.assertTrue(properties.isMultiLogin());
    }

    /**
     * 验证弱默认密码会阻止应用启动。
     */
    @Test(expected = BusinessException.class)
    public void shouldRejectWeakResetPassword() {
        AccountSecurityProperties properties = new AccountSecurityProperties();
        properties.setDefaultResetPassword("123456");

        properties.afterPropertiesSet();
    }

    /**
     * 验证空默认密码会阻止应用启动。
     */
    @Test(expected = BusinessException.class)
    public void shouldRejectBlankResetPassword() {
        AccountSecurityProperties properties = new AccountSecurityProperties();
        properties.setDefaultResetPassword(" ");

        properties.afterPropertiesSet();
    }
}
