diff --git a/laokou-service/laokou-auth/laokou-auth-app/src/test/java/org/laokou/auth/ExtensionExecutorTest.java b/laokou-service/laokou-auth/laokou-auth-app/src/test/java/org/laokou/auth/ExtensionExecutorTest.java index ef2054886..73e7e9abc 100644 --- a/laokou-service/laokou-auth/laokou-auth-app/src/test/java/org/laokou/auth/ExtensionExecutorTest.java +++ b/laokou-service/laokou-auth/laokou-auth-app/src/test/java/org/laokou/auth/ExtensionExecutorTest.java @@ -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; @@ -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, "2413176044@qq.com", "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("2413176044@qq.com"); + 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)); + } + } diff --git a/laokou-service/laokou-auth/laokou-auth-app/src/test/resources/application.yml b/laokou-service/laokou-auth/laokou-auth-app/src/test/resources/application.yml index 1495b569c..2e8ca3385 100644 --- a/laokou-service/laokou-auth/laokou-auth-app/src/test/resources/application.yml +++ b/laokou-service/laokou-auth/laokou-auth-app/src/test/resources/application.yml @@ -4,3 +4,5 @@ server: spring: application: name: laokou-auth-app + profiles: + active: test