refactor(系统设置): 系统日志功能测试用例

This commit is contained in:
WangXu10 2023-07-17 18:07:32 +08:00 committed by 刘瑞斌
parent 0e88e52214
commit 58707ad414
7 changed files with 87 additions and 15 deletions

View File

@ -101,7 +101,7 @@ public class OperationLogService {
}
List<OperationLogResponse> list = baseOperationLogMapper.list(request);
if (CollectionUtils.isNotEmpty(list) && !"system".equals(request.getLevel())) {
if (CollectionUtils.isNotEmpty(list)) {
List<String> userIds = list.stream().map(OperationLogResponse::getCreateUser).collect(Collectors.toList());
List<String> projectIds = list.stream().map(OperationLogResponse::getProjectId).collect(Collectors.toList());
List<String> organizationIds = list.stream().map(OperationLogResponse::getOrganizationId).collect(Collectors.toList());

View File

@ -2,13 +2,14 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="io.metersphere.sdk.mapper.BaseOperationLogMapper">
<select id="list" resultType="io.metersphere.sdk.log.vo.OperationLogResponse">
<select id="list" parameterType="io.metersphere.sdk.log.vo.OperationLogRequest" resultType="io.metersphere.sdk.log.vo.OperationLogResponse">
SELECT
t.id,
t.project_id,
t.organization_id,
t.create_time,
t.create_user,
t.module,
t.type,
t.content
FROM
@ -23,6 +24,9 @@
<if test="request.level != null and request.level != 'system'">
AND t.project_id != 'system'
</if>
<if test="request.level != null and request.level == 'project'">
AND t.project_id <![CDATA[<>]]> ''
</if>
<if test="request.projectIds != null and request.projectIds.size > 0 ">
AND t.project_id IN
<foreach collection="request.projectIds" item="projectId" separator="," open="(" close=")">
@ -36,13 +40,13 @@
</foreach>
</if>
<if test="request.type != null and request.type != ''">
AND t.type = #{request.type, jdbcType=VARCHAR}
AND t.type = #{request.type}
</if>
<if test="request.module != null and request.module != ''">
AND t.module = #{module, jdbcType=VARCHAR}
AND t.module = #{request.module}
</if>
<if test="request.content != null and request.content != ''">
AND t.content like #{request.content, jdbcType=VARCHAR}
AND t.content like CONCAT('%', #{request.content},'%')
</if>
</where>
ORDER BY t.oper_time DESC

View File

@ -221,7 +221,7 @@ public class SystemParameterService {
"system-parameter",
null,
OperationLogType.ADD.name(),
OperationLogModule.SYSTEM_USER_ROLE_RELATION,
OperationLogModule.SYSTEM_PARAMETER_SETTING,
"系统参数");
dto.setPath("/system/parameter/save/base-info");
@ -237,7 +237,7 @@ public class SystemParameterService {
"system-parameter",
null,
OperationLogType.ADD.name(),
OperationLogModule.SYSTEM_USER_ROLE_RELATION,
OperationLogModule.SYSTEM_PARAMETER_SETTING,
"编辑邮件信息");
dto.setPath("/system/parameter/edit/email-info");

View File

@ -25,7 +25,7 @@ import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/operating/log")
@RequestMapping("/operation/log")
public class OperationLogController {
@Resource

View File

@ -80,7 +80,7 @@ public class SystemProjectController {
@GetMapping("/revoke/{id}")
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ_RECOVER)
@Log(type = OperationLogType.UPDATE, expression = "#msClass.updateLog(#project)", msClass = SystemProjectLogService.class)
@Log(type = OperationLogType.UPDATE, expression = "#msClass.updateLog(#id)", msClass = SystemProjectLogService.class)
public int revokeProject(@PathVariable String id) {
return systemProjectService.revoke(id);
}

View File

@ -12,27 +12,32 @@ import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMock
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.jdbc.SqlConfig;
import org.springframework.test.web.servlet.ResultActions;
import java.util.Arrays;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@SpringBootTest
@AutoConfigureMockMvc
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class OperationLogControllerTests extends BaseTest {
public static final String OPERATION_LOG_LIST = "/operating/log/list";
public static final String OPERATION_LOG_LIST = "/operation/log/list";
public static final String OPTIONS_LIST = "/operating/log/get/options";
public static final String OPTIONS_LIST = "/operation/log/get/options";
public static final String USER_LIST = "/system/user/list";
public static final String SYSTEM = "system";
public static final String ORGANIZATION = "organization";
public static final String PROJECT = "project";
/**
* 系统级别 查询 用例
*
* @throws Exception
*/
@Test
@ -45,6 +50,13 @@ public class OperationLogControllerTests extends BaseTest {
OperationLogRequest request = buildParam(SYSTEM);
this.requestPostWithOkAndReturn(OPERATION_LOG_LIST, request);
//其他查询条件
request.setOperUser("admin");
request.setType("add");
request.setModule("SYSTEM_PARAMETER_SETTING");
request.setContent("认证配置");
this.requestPostWithOkAndReturn(OPERATION_LOG_LIST, request);
// @@异常参数校验
updatedGroupParamValidateTest(OperationLogRequestDefinition.class, OPERATION_LOG_LIST);
// @@校验权限
@ -55,17 +67,26 @@ public class OperationLogControllerTests extends BaseTest {
/**
* 组织级别 查询 用例
*
* @throws Exception
*/
@Test
@Order(3)
@Order(4)
public void testOrganizationOperationLogList() throws Exception {
OperationLogRequest request = buildParam(ORGANIZATION);
//组织级别 全部
this.requestPostWithOkAndReturn(OPERATION_LOG_LIST, request);
//其他查询条件
request.setOperUser("admin");
request.setType("add");
request.setModule("SYSTEM_PARAMETER_SETTING");
request.setContent("认证配置");
this.requestPostWithOkAndReturn(OPERATION_LOG_LIST, request);
//组织级别 指定组织查询
request.setOrganizationIds(Arrays.asList("organization_id_001","organization_id_002"));
request.setOrganizationIds(Arrays.asList("organization_id_001", "organization_id_002"));
this.requestPostWithOkAndReturn(OPERATION_LOG_LIST, request);
// @@异常参数校验
@ -75,7 +96,35 @@ public class OperationLogControllerTests extends BaseTest {
}
//TODO 项目级别 查询 用例
/**
* 项目级别 查询 用例
*
* @throws Exception
*/
@Test
@Order(5)
public void testProjectOperationLogList() throws Exception {
OperationLogRequest request = buildParam(PROJECT);
//项目级别 全部
this.requestPostWithOkAndReturn(OPERATION_LOG_LIST, request);
//其他查询条件
request.setOperUser("admin");
request.setType("add");
request.setModule("SYSTEM_PARAMETER_SETTING");
request.setContent("认证配置");
this.requestPostWithOkAndReturn(OPERATION_LOG_LIST, request);
//项目级别 指定项目查询
request.setProjectIds(Arrays.asList("project_id_001", "project_id_002"));
this.requestPostWithOkAndReturn(OPERATION_LOG_LIST, request);
// @@异常参数校验
updatedGroupParamValidateTest(OperationLogRequestDefinition.class, OPERATION_LOG_LIST);
// @@校验权限
requestPostPermissionTest(PermissionConstants.SYSTEM_OPERATING_LOG_READ, OPERATION_LOG_LIST, request);
}
@Test
@Order(2)
@ -95,7 +144,15 @@ public class OperationLogControllerTests extends BaseTest {
requestGetPermissionTest(PermissionConstants.SYSTEM_OPERATING_LOG_READ, OPTIONS_LIST);
}
//TODO 异常用例补充
@Test
@Order(6)
public void testGetOperationLogParamsError() throws Exception {
OperationLogRequest request = buildParam(SYSTEM);
request.setStartTime(1689149059000l);
request.setEndTime(1689131059000l);
ResultActions resultActions = this.requestPost(OPERATION_LOG_LIST, request);
resultActions.andExpect(status().is5xxServerError());
}
private OperationLogRequest buildParam(String level) {

View File

@ -1,11 +1,22 @@
-- 模拟数据
INSERT INTO organization (id, num, name, description, create_user, update_user, create_time, update_time) VALUES ('organization_id_001', 100010, '测试日志组织', '测试日志的组织', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000);
INSERT INTO organization (id, num, name, description, create_user, update_user, create_time, update_time) VALUES ('organization_id_002', 100011, '测试日志组织2', '测试日志的组织2', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000);
INSERT INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time) VALUES ('project_id_001', 100010, 'organization_id_001', '测试日志项目', '测试日志的项目', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000);
INSERT INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time) VALUES ('project_id_002', 100011, 'organization_id_002', '测试日志项目2', '测试日志的项目2', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000);
-- 初始化日志记录
INSERT INTO operation_log(`id`, `project_id`, `organization_id`, `create_time`, `create_user`, `source_id`, `method`, `type`, `module`, `content`, `path`) VALUES (uuid(), 'system', '', 1689141859000, 'admin', '1', 'post', 'add', 'SYSTEM_PARAMETER_SETTING', '认证配置', '/system/authsource/add');
INSERT INTO operation_log(`id`, `project_id`, `organization_id`, `create_time`, `create_user`, `source_id`, `method`, `type`, `module`, `content`, `path`) VALUES (uuid(), 'system', '', 1689141859000, 'admin', '1', 'post', 'update', 'SYSTEM_PARAMETER_SETTING', '认证配置', '/system/authsource/update');
INSERT INTO operation_log(`id`, `project_id`, `organization_id`, `create_time`, `create_user`, `source_id`, `method`, `type`, `module`, `content`, `path`) VALUES (uuid(), '', 'organization_id_001', 1689141859000, 'admin', '1', 'post', 'add', 'SYSTEM_PARAMETER_SETTING', '认证配置', '/system/authsource/add');
INSERT INTO operation_log(`id`, `project_id`, `organization_id`, `create_time`, `create_user`, `source_id`, `method`, `type`, `module`, `content`, `path`) VALUES (uuid(), '', 'organization_id_002', 1689141859000, 'admin', '1', 'post', 'update', 'SYSTEM_PARAMETER_SETTING', '认证配置', '/system/authsource/update');
INSERT INTO operation_log(`id`, `project_id`, `organization_id`, `create_time`, `create_user`, `source_id`, `method`, `type`, `module`, `content`, `path`) VALUES (uuid(), 'project_id_001', 'organization_id_001', 1689141859000, 'admin', '1', 'post', 'add', 'SYSTEM_PARAMETER_SETTING', '认证配置', '/system/authsource/add');
INSERT INTO operation_log(`id`, `project_id`, `organization_id`, `create_time`, `create_user`, `source_id`, `method`, `type`, `module`, `content`, `path`) VALUES (uuid(), 'project_id_001', 'organization_id_001', 1689141859000, 'admin', '1', 'post', 'update', 'SYSTEM_PARAMETER_SETTING', '认证配置', '/system/authsource/update');
INSERT INTO operation_log(`id`, `project_id`, `organization_id`, `create_time`, `create_user`, `source_id`, `method`, `type`, `module`, `content`, `path`) VALUES (uuid(), 'project_id_002', 'organization_id_001', 1689141859000, 'admin', '1', 'post', 'add', 'SYSTEM_PARAMETER_SETTING', '认证配置', '/system/authsource/add');
INSERT INTO operation_log(`id`, `project_id`, `organization_id`, `create_time`, `create_user`, `source_id`, `method`, `type`, `module`, `content`, `path`) VALUES (uuid(), 'project_id_002', 'organization_id_001', 1689141859000, 'admin', '1', 'post', 'update', 'SYSTEM_PARAMETER_SETTING', '认证配置', '/system/authsource/update');
INSERT INTO operation_log(`id`, `project_id`, `organization_id`, `create_time`, `create_user`, `source_id`, `method`, `type`, `module`, `content`, `path`) VALUES (uuid(), 'project_id_001', 'organization_id_002', 1689141859000, 'admin', '1', 'post', 'add', 'SYSTEM_PARAMETER_SETTING', '认证配置', '/system/authsource/add');
INSERT INTO operation_log(`id`, `project_id`, `organization_id`, `create_time`, `create_user`, `source_id`, `method`, `type`, `module`, `content`, `path`) VALUES (uuid(), 'project_id_001', 'organization_id_002', 1689141859000, 'admin', '1', 'post', 'update', 'SYSTEM_PARAMETER_SETTING', '认证配置', '/system/authsource/update');
INSERT INTO operation_log(`id`, `project_id`, `organization_id`, `create_time`, `create_user`, `source_id`, `method`, `type`, `module`, `content`, `path`) VALUES (uuid(), 'project_id_002', 'organization_id_002', 1689141859000, 'admin', '1', 'post', 'add', 'SYSTEM_PARAMETER_SETTING', '认证配置', '/system/authsource/add');
INSERT INTO operation_log(`id`, `project_id`, `organization_id`, `create_time`, `create_user`, `source_id`, `method`, `type`, `module`, `content`, `path`) VALUES (uuid(), 'project_id_002', 'organization_id_002', 1689141859000, 'admin', '1', 'post', 'update', 'SYSTEM_PARAMETER_SETTING', '认证配置', '/system/authsource/update');