yeg
2026-08-27 2651949754a60afae6152977a0f83a1b4704cba5
fix(test): address configuration review findings
4个文件已修改
34 ■■■■■ 已修改文件
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/TTestController.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/test/java/com/ruoyi/system/service/impl/TTestServiceImplTest.java 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/java/com/ruoyi/system/service/ITTestService.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TTestServiceImpl.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/TTestController.java
@@ -61,7 +61,8 @@
        test.setOperatorId(getUserId());
        test.setCreatorId(getUserId());
        test.setCreateBy(getUsername());
        return success(testService.createTest(test));
        Long testId = testService.createTest(test);
        return success(testService.selectTestById(testId));
    }
    @PreAuthorize("@ss.hasPermi('system:test:edit')")
@@ -71,7 +72,8 @@
    {
        test.setOperatorId(getUserId());
        test.setUpdateBy(getUsername());
        return toAjax(testService.updateTest(test));
        testService.updateTest(test);
        return success(testService.selectTestById(test.getTestId()));
    }
    @PreAuthorize("@ss.hasPermi('system:test:start')")
@@ -87,7 +89,7 @@
    @DeleteMapping("/{testIds}")
    public AjaxResult remove(@PathVariable Long[] testIds)
    {
        return toAjax(testService.deleteTestByIds(testIds, getUsername()));
        return toAjax(testService.deleteTestByIds(testIds, getUserId(), getUsername()));
    }
    @PreAuthorize("@ss.hasPermi('system:test:query')")
ruoyi-admin/src/test/java/com/ruoyi/system/service/impl/TTestServiceImplTest.java
@@ -4,6 +4,7 @@
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.never;
@@ -198,6 +199,20 @@
        verify(testMapper).insertTestAudit(anyLong(), any(), anyLong(), any(), any(), any());
    }
    @Test
    void deleteBeforeMonitoringShouldAppendAudit()
    {
        TTest current = validTest();
        current.setTestId(10L);
        current.setMonitoringStatus("NOT_MONITORED");
        when(testMapper.selectTestByIdForUpdate(10L)).thenReturn(current);
        when(testMapper.deleteTestById(10L, "operator")).thenReturn(1);
        assertEquals(1, testService.deleteTestByIds(new Long[] { 10L }, 7L, "operator"));
        verify(testMapper).insertTestAudit(eq(10L), eq("TEST_DELETED"), eq(7L), eq("operator"), any(), isNull());
    }
    private void mockEnabledOptions()
    {
        mockEnabledPeopleAndType();
ruoyi-system/src/main/java/com/ruoyi/system/service/ITTestService.java
@@ -23,6 +23,6 @@
    int updateTest(TTest test);
    int startTest(Long testId, String updateBy);
    int deleteTestByIds(Long[] testIds, String updateBy);
    int deleteTestByIds(Long[] testIds, Long operatorId, String updateBy);
    List<TTestResult> selectTestResults(TTestResult result);
}
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TTestServiceImpl.java
@@ -135,7 +135,7 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int deleteTestByIds(Long[] testIds, String updateBy)
    public int deleteTestByIds(Long[] testIds, Long operatorId, String updateBy)
    {
        if (testIds == null || testIds.length == 0) throw new ServiceException("请选择要删除的测试");
        int rows = 0;
@@ -144,7 +144,12 @@
            TTest current = testMapper.selectTestByIdForUpdate(testId);
            if (current == null) throw new ServiceException("测试不存在");
            if (!NOT_MONITORED.equals(current.getMonitoringStatus())) throw new ServiceException("开始监测后不能删除测试");
            rows += testMapper.deleteTestById(testId, updateBy);
            loadConfiguration(current);
            int deleted = testMapper.deleteTestById(testId, updateBy);
            if (deleted != 1) throw new ServiceException("测试配置已变更,请刷新后重试");
            testMapper.insertTestAudit(testId, "TEST_DELETED", operatorId, updateBy,
                    JSON.toJSONString(current), null);
            rows += deleted;
        }
        return rows;
    }