归集任务删除,只允许删除被拒绝状态的归集任务,删除归集任务,要同时删除归集任务下的明细数据

This commit is contained in:
lu7213 committed 2026-10-21 09:41:41 -04:00
1 parent 33481ab6eb
commit 352d7d023f
1 file changed
+66
@@ -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()); }
}
}