usdt归集明细页面usdtTaskItem和USDTmanage/usdtTaskItem,添加取消归集明细任务功能。
This commit is contained in:
1 parent
2870c3fb6c
commit
62f43056e2
8 files changed
+161
-10
No files matched your search
+93
@@ -0,0 +1,93 @@
|
||||
package com.ruoyi.web.controller.system;
|
||||
|
||||
import com.ruoyi.common.exception.CustomException;
|
||||
import com.ruoyi.system.domain.UsdtAggregationTask;
|
||||
import com.ruoyi.system.domain.UsdtAggregationTaskItem;
|
||||
import com.ruoyi.system.domain.UsdtAggregationTaskItemPlus;
|
||||
import com.ruoyi.system.mapper.UsdtAggregationTaskMapper;
|
||||
import com.ruoyi.system.mapper.UsdtAggregationTaskItemMapper;
|
||||
import com.ruoyi.system.service.UsdtAggregationWorkflowService;
|
||||
import com.ruoyi.system.service.WalletSigningService;
|
||||
import org.junit.Test;
|
||||
import java.lang.reflect.Method;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/** 不依赖数据库和链上节点,验证取消边界及旧执行快照不会绕过数据库取消状态。 */
|
||||
public class AggregationItemCancellationTest {
|
||||
@Test
|
||||
public void cancelsOnlyWhenConditionalUpdateSucceeds() {
|
||||
UsdtAggregationTaskMapper tasks = mock(UsdtAggregationTaskMapper.class);
|
||||
UsdtAggregationTaskItemMapper items = mock(UsdtAggregationTaskItemMapper.class);
|
||||
UsdtAggregationWorkflowService service = service(tasks, items);
|
||||
UsdtAggregationTaskItem item = new UsdtAggregationTaskItem();
|
||||
item.setParentId(10L);
|
||||
when(items.selectUsdtAggregationTaskItemById(1L)).thenReturn(item);
|
||||
when(tasks.selectUsdtAggregationTaskByIdForUpdate(10L)).thenReturn(new UsdtAggregationTask());
|
||||
when(items.cancelPendingItem(1L)).thenReturn(1);
|
||||
service.cancelItem(1L, false);
|
||||
when(items.cancelPendingItem(1L)).thenReturn(0);
|
||||
try {
|
||||
service.cancelItem(1L, false);
|
||||
fail("执行中、成功、失败和已取消状态必须拒绝取消");
|
||||
} catch (CustomException expected) {
|
||||
assertTrue(expected.getMessage().contains("仅待执行"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = CustomException.class)
|
||||
public void missingItemCannotBeCancelled() {
|
||||
service(mock(UsdtAggregationTaskMapper.class), mock(UsdtAggregationTaskItemMapper.class))
|
||||
.cancelItem(1L, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void userCannotCancelAnotherUsersItem() {
|
||||
UsdtAggregationTaskMapper tasks = mock(UsdtAggregationTaskMapper.class);
|
||||
UsdtAggregationTaskItemMapper items = mock(UsdtAggregationTaskItemMapper.class);
|
||||
UsdtAggregationTaskItem item = new UsdtAggregationTaskItem();
|
||||
item.setParentId(10L);
|
||||
item.setUserId(2L);
|
||||
UsdtAggregationTask task = new UsdtAggregationTask();
|
||||
task.setUserId(2L);
|
||||
when(items.selectUsdtAggregationTaskItemById(1L)).thenReturn(item);
|
||||
when(tasks.selectUsdtAggregationTaskByIdForUpdate(10L)).thenReturn(task);
|
||||
com.ruoyi.common.core.domain.entity.SysUser user = new com.ruoyi.common.core.domain.entity.SysUser();
|
||||
user.setUserId(1L);
|
||||
com.ruoyi.common.core.domain.model.LoginUser login = new com.ruoyi.common.core.domain.model.LoginUser(
|
||||
user, java.util.Collections.emptySet());
|
||||
org.springframework.security.core.context.SecurityContextHolder.getContext().setAuthentication(
|
||||
new org.springframework.security.authentication.UsernamePasswordAuthenticationToken(login, null));
|
||||
try {
|
||||
service(tasks, items).cancelItem(1L, true);
|
||||
fail("不能取消其他用户的归集明细");
|
||||
} catch (CustomException expected) {
|
||||
verify(items, never()).cancelPendingItem(1L);
|
||||
} finally {
|
||||
org.springframework.security.core.context.SecurityContextHolder.clearContext();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cancelledSnapshotCannotReachSigningSession() throws Exception {
|
||||
UsdtAggregationTaskItemMapper items = mock(UsdtAggregationTaskItemMapper.class);
|
||||
UsdtAggregationWorkflowService service = service(null, items);
|
||||
UsdtAggregationTaskItemPlus snapshot = new UsdtAggregationTaskItemPlus();
|
||||
snapshot.setId(1L);
|
||||
snapshot.setStatus(0L);
|
||||
UsdtAggregationTaskItem current = new UsdtAggregationTaskItem();
|
||||
current.setStatus(3L);
|
||||
when(items.selectUsdtAggregationTaskItemById(1L)).thenReturn(current);
|
||||
Method execute = UsdtAggregationWorkflowService.class.getDeclaredMethod("executeItemInternal",
|
||||
UsdtAggregationTaskItemPlus.class, WalletSigningService.UnlockedWalletSession.class);
|
||||
execute.setAccessible(true);
|
||||
// 不提供钱包服务和签名会话:若取消检查后仍触达转账路径,调用会立即失败。
|
||||
assertEquals(Boolean.TRUE, execute.invoke(service, snapshot, null));
|
||||
}
|
||||
|
||||
private UsdtAggregationWorkflowService service(UsdtAggregationTaskMapper tasks,
|
||||
UsdtAggregationTaskItemMapper items) {
|
||||
return new UsdtAggregationWorkflowService(null, null, null, null, null,
|
||||
tasks, items, null, null, null, null);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user