From 352d7d023f4d770d184221b2b1046554211540f3 Mon Sep 17 00:00:00 2001 From: luqingjie <544309509@qq.com> Date: Wed, 21 Oct 2026 09:41:41 -0400 Subject: [PATCH] =?UTF-8?q?=E5=BD=92=E9=9B=86=E4=BB=BB=E5=8A=A1=E5=88=A0?= =?UTF-8?q?=E9=99=A4=EF=BC=8C=E5=8F=AA=E5=85=81=E8=AE=B8=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E8=A2=AB=E6=8B=92=E7=BB=9D=E7=8A=B6=E6=80=81=E7=9A=84=E5=BD=92?= =?UTF-8?q?=E9=9B=86=E4=BB=BB=E5=8A=A1=EF=BC=8C=E5=88=A0=E9=99=A4=E5=BD=92?= =?UTF-8?q?=E9=9B=86=E4=BB=BB=E5=8A=A1=EF=BC=8C=E8=A6=81=E5=90=8C=E6=97=B6?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=BD=92=E9=9B=86=E4=BB=BB=E5=8A=A1=E4=B8=8B?= =?UTF-8?q?=E7=9A=84=E6=98=8E=E7=BB=86=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/AggregationTaskDeletionTest.java | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 ruoyi-admin/src/test/java/com/ruoyi/web/controller/system/AggregationTaskDeletionTest.java diff --git a/ruoyi-admin/src/test/java/com/ruoyi/web/controller/system/AggregationTaskDeletionTest.java b/ruoyi-admin/src/test/java/com/ruoyi/web/controller/system/AggregationTaskDeletionTest.java new file mode 100644 index 0000000..f790391 --- /dev/null +++ b/ruoyi-admin/src/test/java/com/ruoyi/web/controller/system/AggregationTaskDeletionTest.java @@ -0,0 +1,66 @@ +package com.ruoyi.web.controller.system; + +import com.ruoyi.common.exception.CustomException; +import com.ruoyi.system.domain.UsdtAggregationTask; +import com.ruoyi.system.mapper.UsdtAggregationTaskMapper; +import com.ruoyi.system.service.IUsdtAggregationTaskItemService; +import com.ruoyi.system.service.UsdtAggregationWorkflowService; +import org.junit.Test; +import static org.mockito.Mockito.*; +import static org.mockito.ArgumentMatchers.*; +import static org.junit.Assert.*; + +/** 隔离验证:仅拒绝任务可删,主表失败不能继续删除明细。 */ +public class AggregationTaskDeletionTest { + @org.junit.BeforeClass + public static void initializeMybatisMetadata() { + // 隔离测试不启动 Spring,手动初始化 LambdaUpdateWrapper 所需实体列缓存。 + com.baomidou.mybatisplus.core.metadata.TableInfoHelper.initTableInfo( + new org.apache.ibatis.builder.MapperBuilderAssistant( + new com.baomidou.mybatisplus.core.MybatisConfiguration(), "test"), + com.ruoyi.system.domain.UsdtAggregationTaskItemPlus.class); + } + + @Test + public void onlyRejectedUnexecutedTasksCanBeDeleted() { + UsdtAggregationTaskMapper mapper = mock(UsdtAggregationTaskMapper.class); + IUsdtAggregationTaskItemService items = mock(IUsdtAggregationTaskItemService.class); + UsdtAggregationWorkflowService service = new UsdtAggregationWorkflowService( + null, null, null, items, null, mapper, null, null, null, null, null); + UsdtAggregationTask task = new UsdtAggregationTask(); + task.setStatus(0); + when(mapper.selectUsdtAggregationTaskByIdForUpdate(1L)).thenReturn(task); + for (Integer status : new Integer[] {null, 0, 1}) { + task.setVerifyStatus(status); + reject(() -> service.deleteTask(1L, false)); + } + verify(mapper, never()).updateUsdtAggregationTask(any()); + task.setVerifyStatus(2); + task.setStatus(1); + reject(() -> service.deleteTask(1L, false)); + task.setStatus(0); + when(mapper.updateUsdtAggregationTask(task)).thenReturn(1); + service.deleteTask(1L, false); + assertNotNull(task.getDeletedAt()); + verify(items).update(any(com.baomidou.mybatisplus.core.conditions.Wrapper.class)); + } + + @Test + public void doesNotDeleteItemsWhenTaskUpdateFails() { + UsdtAggregationTaskMapper mapper = mock(UsdtAggregationTaskMapper.class); + IUsdtAggregationTaskItemService items = mock(IUsdtAggregationTaskItemService.class); + UsdtAggregationWorkflowService service = new UsdtAggregationWorkflowService( + null, null, null, items, null, mapper, null, null, null, null, null); + UsdtAggregationTask task = new UsdtAggregationTask(); + task.setStatus(0); + task.setVerifyStatus(2); + when(mapper.selectUsdtAggregationTaskByIdForUpdate(1L)).thenReturn(task); + reject(() -> service.deleteTask(1L, false)); + verify(items, never()).update(any(com.baomidou.mybatisplus.core.conditions.Wrapper.class)); + } + + private void reject(Runnable action) { + try { action.run(); fail("应拒绝删除"); } + catch (CustomException expected) { assertNotNull(expected.getMessage()); } + } +}