Skip to content

Commit

Permalink
Merge pull request #3216 from KouShenhai/dev
Browse files Browse the repository at this point in the history
feat: 提交测试用例【认证】【应用层】【完成】
  • Loading branch information
KouShenhai authored Dec 28, 2024
2 parents c48eb77 + 5702f87 commit e1a4507
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,22 @@
import org.junit.jupiter.api.Test;
import org.laokou.auth.factory.DomainFactory;
import org.laokou.auth.model.AuthA;
import org.laokou.auth.model.CaptchaE;
import org.laokou.auth.service.extensionpoint.AuthParamValidatorExtPt;
import org.laokou.auth.service.extensionpoint.extension.UsernamePasswordAuthParamValidator;
import org.laokou.auth.service.extensionpoint.CaptchaParamValidatorExtPt;
import org.laokou.auth.service.extensionpoint.extension.*;
import org.laokou.common.extension.BizScenario;
import org.laokou.common.extension.ExtensionExecutor;
import org.laokou.common.extension.ExtensionPointI;
import org.laokou.common.extension.ExtensionRepository;
import org.laokou.common.extension.register.ExtensionRegister;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestConstructor;

import static org.laokou.auth.common.constant.MqConstant.MAIL_TAG;
import static org.laokou.auth.common.constant.MqConstant.MOBILE_TAG;
import static org.laokou.auth.dto.clientobject.CaptchaCO.USE_CASE_CAPTCHA;
import static org.laokou.auth.model.AuthA.USE_CASE_AUTH;
import static org.laokou.common.i18n.common.constant.Constant.SCENARIO;

Expand All @@ -52,21 +58,120 @@ class ExtensionExecutorTest {

@Test
void testUsernamePasswordAuthParamValidateExecutor() {
Assertions.assertNotNull(extensionExecutor);
Assertions.assertNotNull(extensionRegister);
// 校验参数
validate();

AuthA auth = DomainFactory.getUsernamePasswordAuth(1L, "admin", "123", "laokou", "1", "1234");
Assertions.assertNotNull(auth);

// 注入【用户名密码登录】校验器
AuthParamValidatorExtPt authParamValidatorExtPt = new UsernamePasswordAuthParamValidator();
Assertions.assertNotNull(authParamValidatorExtPt);
extensionRegister.doRegistration(authParamValidatorExtPt);
// 注册【用户名密码登录】校验器
doRegistration(new UsernamePasswordAuthParamValidator());

// 执行参数校验【用户名密码登录】
execute(auth);
}

@Test
void testMailAuthParamValidateExecutor() {
// 校验参数
validate();

AuthA auth = DomainFactory.getMailAuth(1L, "[email protected]", "123456", "laokou");
Assertions.assertNotNull(auth);

// 注册【邮箱登录】校验器
doRegistration(new MailAuthParamValidator());

// 执行参数校验【邮箱登录】
execute(auth);
}

@Test
void testMobileAuthParamValidateExecutor() {
// 校验参数
validate();

AuthA auth = DomainFactory.getMobileAuth(1L, "18888888888", "123456", "laokou");
Assertions.assertNotNull(auth);

// 注册【手机号登录】校验器
doRegistration(new MobileAuthParamValidator());

// 执行参数校验【手机号登录】
execute(auth);
}

@Test
void testAuthorizationCodeAuthParamValidateExecutor() {
// 校验参数
validate();

AuthA auth = DomainFactory.getAuthorizationCodeAuth(1L, "admin", "123", "laokou");
Assertions.assertNotNull(auth);

// 注册【授权码登录】校验器
doRegistration(new AuthorizationCodeAuthParamValidator());

// 执行参数校验【授权码登录】
execute(auth);
}

@Test
void testMailCaptchaParamValidateExecutor() {
// 校验参数
validate();

CaptchaE captcha = DomainFactory.getCaptcha();
Assertions.assertNotNull(captcha);

// 注册【邮箱验证码】校验器
doRegistration(new MailCaptchaParamValidator());

// 执行参数校验【邮箱验证码】
captcha.setTag(MAIL_TAG);
captcha.setUuid("[email protected]");
captcha.setTenantCode("laokou");
execute(captcha);
}

@Test
void testCaptchaParamValidateExecutor() {
// 校验参数
validate();

CaptchaE captcha = DomainFactory.getCaptcha();
Assertions.assertNotNull(captcha);

// 注册【手机号验证码】校验器
doRegistration(new MobileCaptchaParamValidator());

// 执行参数校验【手机号验证码】
captcha.setTag(MOBILE_TAG);
captcha.setUuid("18888888888");
captcha.setTenantCode("laokou");
execute(captcha);
}

private void doRegistration(ExtensionPointI extensionPointI) {
Assertions.assertNotNull(extensionPointI);
extensionRegister.doRegistration(extensionPointI);
}

private void validate() {
Assertions.assertNotNull(extensionExecutor);
Assertions.assertNotNull(extensionRegister);
}

private void execute(AuthA auth) {
extensionExecutor.executeVoid(AuthParamValidatorExtPt.class,
BizScenario.valueOf(auth.getGrantType().getCode(), USE_CASE_AUTH, SCENARIO),
extension -> extension.validate(auth));
}

private void execute(CaptchaE captcha) {
extensionExecutor.executeVoid(CaptchaParamValidatorExtPt.class,
BizScenario.valueOf(captcha.getTag(), USE_CASE_CAPTCHA, SCENARIO),
extension -> extension.validate(captcha));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ server:
spring:
application:
name: laokou-auth-app
profiles:
active: test

0 comments on commit e1a4507

Please sign in to comment.