mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-27 17:43:55 +08:00
test: 修复 manager-api 国际化测试配置
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
package xiaozhi.modules.device;
|
package xiaozhi.modules.device;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.DisplayName;
|
import org.junit.jupiter.api.DisplayName;
|
||||||
@@ -11,6 +10,8 @@ import org.springframework.boot.test.context.SpringBootTest;
|
|||||||
import org.springframework.test.context.ActiveProfiles;
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import xiaozhi.common.exception.ErrorCode;
|
||||||
|
import xiaozhi.common.exception.RenException;
|
||||||
import xiaozhi.common.redis.RedisUtils;
|
import xiaozhi.common.redis.RedisUtils;
|
||||||
import xiaozhi.modules.sys.dto.SysUserDTO;
|
import xiaozhi.modules.sys.dto.SysUserDTO;
|
||||||
import xiaozhi.modules.sys.service.SysUserService;
|
import xiaozhi.modules.sys.service.SysUserService;
|
||||||
@@ -27,11 +28,13 @@ public class DeviceTest {
|
|||||||
private SysUserService sysUserService;
|
private SysUserService sysUserService;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSaveUser() {
|
public void testRejectWeakPassword() {
|
||||||
SysUserDTO userDTO = new SysUserDTO();
|
SysUserDTO userDTO = new SysUserDTO();
|
||||||
userDTO.setUsername("test");
|
userDTO.setUsername("test");
|
||||||
userDTO.setPassword(UUID.randomUUID().toString());
|
userDTO.setPassword("weak-password-123");
|
||||||
sysUserService.save(userDTO);
|
|
||||||
|
RenException exception = Assertions.assertThrows(RenException.class, () -> sysUserService.save(userDTO));
|
||||||
|
Assertions.assertEquals(ErrorCode.PASSWORD_WEAK_ERROR, exception.getCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -70,4 +73,4 @@ public class DeviceTest {
|
|||||||
|
|
||||||
log.info("测试完成");
|
log.info("测试完成");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,23 @@
|
|||||||
package xiaozhi.modules.sys;
|
package xiaozhi.modules.sys;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.test.context.ActiveProfiles;
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
|
import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import xiaozhi.common.exception.ErrorCode;
|
||||||
|
import xiaozhi.common.exception.RenException;
|
||||||
import xiaozhi.modules.security.controller.LoginController;
|
import xiaozhi.modules.security.controller.LoginController;
|
||||||
import xiaozhi.modules.security.dto.LoginDTO;
|
import xiaozhi.modules.security.dto.LoginDTO;
|
||||||
import xiaozhi.modules.security.dto.SmsVerificationDTO;
|
import xiaozhi.modules.security.dto.SmsVerificationDTO;
|
||||||
import xiaozhi.modules.sys.dto.RetrievePasswordDTO;
|
import xiaozhi.modules.sys.dto.RetrievePasswordDTO;
|
||||||
|
import xiaozhi.modules.sys.service.SysUserService;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@@ -19,12 +27,19 @@ class loginControllerTest {
|
|||||||
@Autowired
|
@Autowired
|
||||||
LoginController loginController;
|
LoginController loginController;
|
||||||
|
|
||||||
|
@MockitoBean
|
||||||
|
SysUserService sysUserService;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRegister() {
|
public void testRegister() {
|
||||||
|
when(sysUserService.getAllowUserRegister()).thenReturn(false);
|
||||||
|
|
||||||
LoginDTO loginDTO = new LoginDTO();
|
LoginDTO loginDTO = new LoginDTO();
|
||||||
loginDTO.setUsername("手机号码");
|
loginDTO.setUsername("手机号码");
|
||||||
loginDTO.setPassword("密码");
|
loginDTO.setPassword("密码");
|
||||||
loginController.register(loginDTO);
|
|
||||||
|
RenException exception = assertThrows(RenException.class, () -> loginController.register(loginDTO));
|
||||||
|
assertEquals(ErrorCode.USER_REGISTER_DISABLED, exception.getCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -54,4 +69,4 @@ class loginControllerTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
spring:
|
spring:
|
||||||
|
messages:
|
||||||
|
encoding: UTF-8
|
||||||
|
basename: i18n/messages
|
||||||
data:
|
data:
|
||||||
redis:
|
redis:
|
||||||
host: localhost
|
host: localhost
|
||||||
@@ -19,4 +22,4 @@ renren:
|
|||||||
logging:
|
logging:
|
||||||
level:
|
level:
|
||||||
xiaozhi.modules.device: DEBUG
|
xiaozhi.modules.device: DEBUG
|
||||||
org.springframework.data.redis: DEBUG
|
org.springframework.data.redis: DEBUG
|
||||||
|
|||||||
Reference in New Issue
Block a user