feat: 实现登录日志和操作日志的分页查询功能
refactor: 重构日志服务层代码,将分页逻辑移至Repository层 test: 添加日志分页查询的单元测试和组件测试 docs: 更新README文档,记录API响应格式修复过程 chore: 清理无用文件,更新.gitignore配置 build: 添加Jacoco代码覆盖率插件配置 ci: 添加测试环境配置文件application-h2-test.yml style: 统一日志服务代码格式,添加必要的日志输出
This commit is contained in:
+88
@@ -72,6 +72,50 @@ class SysLogHandlerTest {
|
||||
verify(loginLogService).findAll();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetAllLoginLogs_WithPagination() {
|
||||
PageResponse<SysLoginLog> pageResponse = new PageResponse<>();
|
||||
pageResponse.setContent(java.util.Collections.singletonList(testLoginLog));
|
||||
pageResponse.setTotalElements(1L);
|
||||
pageResponse.setTotalPages(1);
|
||||
|
||||
when(loginLogService.findLoginLogsByPage(any())).thenReturn(Mono.just(pageResponse));
|
||||
|
||||
ServerRequest request = MockServerRequest.builder()
|
||||
.queryParam("page", "0")
|
||||
.queryParam("size", "10")
|
||||
.build();
|
||||
Mono<ServerResponse> response = logHandler.getAllLoginLogs(request);
|
||||
|
||||
StepVerifier.create(response)
|
||||
.expectNextMatches(serverResponse ->
|
||||
serverResponse.statusCode() == HttpStatus.OK)
|
||||
.verifyComplete();
|
||||
|
||||
verify(loginLogService).findLoginLogsByPage(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetAllLoginLogs_WithOnlyPageParam() {
|
||||
PageResponse<SysLoginLog> pageResponse = new PageResponse<>();
|
||||
pageResponse.setContent(java.util.Collections.singletonList(testLoginLog));
|
||||
pageResponse.setTotalElements(1L);
|
||||
|
||||
when(loginLogService.findLoginLogsByPage(any())).thenReturn(Mono.just(pageResponse));
|
||||
|
||||
ServerRequest request = MockServerRequest.builder()
|
||||
.queryParam("page", "0")
|
||||
.build();
|
||||
Mono<ServerResponse> response = logHandler.getAllLoginLogs(request);
|
||||
|
||||
StepVerifier.create(response)
|
||||
.expectNextMatches(serverResponse ->
|
||||
serverResponse.statusCode() == HttpStatus.OK)
|
||||
.verifyComplete();
|
||||
|
||||
verify(loginLogService).findLoginLogsByPage(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetLoginLogById() {
|
||||
when(loginLogService.findById(1L)).thenReturn(Mono.just(testLoginLog));
|
||||
@@ -203,6 +247,50 @@ class SysLogHandlerTest {
|
||||
verify(exceptionLogService).findAll();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetAllExceptionLogs_WithPagination() {
|
||||
PageResponse<SysExceptionLog> pageResponse = new PageResponse<>();
|
||||
pageResponse.setContent(java.util.Collections.singletonList(testExceptionLog));
|
||||
pageResponse.setTotalElements(1L);
|
||||
pageResponse.setTotalPages(1);
|
||||
|
||||
when(exceptionLogService.findExceptionLogsByPage(any())).thenReturn(Mono.just(pageResponse));
|
||||
|
||||
ServerRequest request = MockServerRequest.builder()
|
||||
.queryParam("page", "0")
|
||||
.queryParam("size", "10")
|
||||
.build();
|
||||
Mono<ServerResponse> response = logHandler.getAllExceptionLogs(request);
|
||||
|
||||
StepVerifier.create(response)
|
||||
.expectNextMatches(serverResponse ->
|
||||
serverResponse.statusCode() == HttpStatus.OK)
|
||||
.verifyComplete();
|
||||
|
||||
verify(exceptionLogService).findExceptionLogsByPage(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetAllExceptionLogs_WithOnlySizeParam() {
|
||||
PageResponse<SysExceptionLog> pageResponse = new PageResponse<>();
|
||||
pageResponse.setContent(java.util.Collections.singletonList(testExceptionLog));
|
||||
pageResponse.setTotalElements(1L);
|
||||
|
||||
when(exceptionLogService.findExceptionLogsByPage(any())).thenReturn(Mono.just(pageResponse));
|
||||
|
||||
ServerRequest request = MockServerRequest.builder()
|
||||
.queryParam("size", "10")
|
||||
.build();
|
||||
Mono<ServerResponse> response = logHandler.getAllExceptionLogs(request);
|
||||
|
||||
StepVerifier.create(response)
|
||||
.expectNextMatches(serverResponse ->
|
||||
serverResponse.statusCode() == HttpStatus.OK)
|
||||
.verifyComplete();
|
||||
|
||||
verify(exceptionLogService).findExceptionLogsByPage(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetExceptionLogById() {
|
||||
when(exceptionLogService.findById(1L)).thenReturn(Mono.just(testExceptionLog));
|
||||
|
||||
+45
@@ -7,6 +7,7 @@ import cn.novalon.manage.sys.dto.request.UserRegisterRequest;
|
||||
import cn.novalon.manage.sys.dto.request.UserUpdateRequest;
|
||||
import cn.novalon.manage.sys.core.command.CreateUserCommand;
|
||||
import cn.novalon.manage.sys.core.command.UpdateUserCommand;
|
||||
import cn.novalon.manage.common.dto.PageResponse;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
@@ -74,6 +75,50 @@ class SysUserHandlerTest {
|
||||
verify(userService).findAll(anyBoolean());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetAllUsers_WithPagination() {
|
||||
PageResponse<SysUser> pageResponse = new PageResponse<>();
|
||||
pageResponse.setContent(java.util.Collections.singletonList(testUser));
|
||||
pageResponse.setTotalElements(1L);
|
||||
pageResponse.setTotalPages(1);
|
||||
|
||||
when(userService.findUsersByPage(any())).thenReturn(Mono.just(pageResponse));
|
||||
|
||||
ServerRequest request = MockServerRequest.builder()
|
||||
.queryParam("page", "0")
|
||||
.queryParam("size", "10")
|
||||
.build();
|
||||
Mono<ServerResponse> response = userHandler.getAllUsers(request);
|
||||
|
||||
StepVerifier.create(response)
|
||||
.expectNextMatches(serverResponse ->
|
||||
serverResponse.statusCode() == HttpStatus.OK)
|
||||
.verifyComplete();
|
||||
|
||||
verify(userService).findUsersByPage(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetAllUsers_WithOnlyPageParam() {
|
||||
PageResponse<SysUser> pageResponse = new PageResponse<>();
|
||||
pageResponse.setContent(java.util.Collections.singletonList(testUser));
|
||||
pageResponse.setTotalElements(1L);
|
||||
|
||||
when(userService.findUsersByPage(any())).thenReturn(Mono.just(pageResponse));
|
||||
|
||||
ServerRequest request = MockServerRequest.builder()
|
||||
.queryParam("page", "0")
|
||||
.build();
|
||||
Mono<ServerResponse> response = userHandler.getAllUsers(request);
|
||||
|
||||
StepVerifier.create(response)
|
||||
.expectNextMatches(serverResponse ->
|
||||
serverResponse.statusCode() == HttpStatus.OK)
|
||||
.verifyComplete();
|
||||
|
||||
verify(userService).findUsersByPage(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetUserCount() {
|
||||
when(userService.count()).thenReturn(Mono.just(10L));
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package cn.novalon.manage.sys.util;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
|
||||
public class PasswordHashGenerator {
|
||||
|
||||
@Test
|
||||
public void generatePasswordHash() {
|
||||
PasswordEncoder passwordEncoder = new BCryptPasswordEncoder(12);
|
||||
|
||||
String password = "Test@123";
|
||||
String hash = passwordEncoder.encode(password);
|
||||
|
||||
System.out.println("========================================");
|
||||
System.out.println("密码: " + password);
|
||||
System.out.println("哈希: " + hash);
|
||||
System.out.println("========================================");
|
||||
|
||||
boolean matches = passwordEncoder.matches(password, hash);
|
||||
System.out.println("验证结果: " + matches);
|
||||
|
||||
String hash2b = "$2b$12$LQv3c1yqBWVHxkd0LHAkCOYz6TtxMQJqhN8/X4.VTtYA/7.J6LlZy";
|
||||
boolean matches2b = passwordEncoder.matches(password, hash2b);
|
||||
System.out.println("验证$2b$哈希结果: " + matches2b);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user