From 8ba28ba5fbee0582f742f6eb1e824544869abc05 Mon Sep 17 00:00:00 2001
From: yeg <1347747024@qq.com>
Date: 星期六, 29 八月 2026 18:32:58 +0800
Subject: [PATCH] 修正共享字段快照模块边界
---
ruoyi-admin/src/test/java/com/ruoyi/system/service/impl/TTestServiceImplTest.java | 64 +++++++++++++++++++++-----------
1 files changed, 42 insertions(+), 22 deletions(-)
diff --git a/ruoyi-admin/src/test/java/com/ruoyi/system/service/impl/TTestServiceImplTest.java b/ruoyi-admin/src/test/java/com/ruoyi/system/service/impl/TTestServiceImplTest.java
index 5793f3e..291e569 100644
--- a/ruoyi-admin/src/test/java/com/ruoyi/system/service/impl/TTestServiceImplTest.java
+++ b/ruoyi-admin/src/test/java/com/ruoyi/system/service/impl/TTestServiceImplTest.java
@@ -22,8 +22,6 @@
import org.mockito.junit.jupiter.MockitoExtension;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.system.domain.TTest;
-import com.ruoyi.system.domain.TBatteryGroup;
-import com.ruoyi.system.domain.TBatteryGroupRelationField;
import com.ruoyi.system.domain.TTestBattery;
import com.ruoyi.system.domain.TTestChannelBinding;
import com.ruoyi.system.domain.TTestCollectorChannel;
@@ -31,7 +29,7 @@
import com.ruoyi.system.domain.TTestPlanStep;
import com.ruoyi.system.domain.TTestWarningThreshold;
import com.ruoyi.system.mapper.TTestMapper;
-import com.ruoyi.system.service.ITBatteryGroupService;
+import com.ruoyi.system.service.ISharedFieldSnapshotService;
/** 测试配置服务的业务契约测试。 */
@ExtendWith(MockitoExtension.class)
@@ -41,7 +39,7 @@
private TTestMapper testMapper;
@Mock
- private ITBatteryGroupService batteryGroupService;
+ private ISharedFieldSnapshotService sharedFieldSnapshotService;
@InjectMocks
private TTestServiceImpl testService;
@@ -68,9 +66,32 @@
verify(testMapper).insertTestPlanStep(any(TTestPlanStep.class));
verify(testMapper).insertTestChannelBinding(any(TTestChannelBinding.class));
verify(testMapper, times(3)).insertTestCollectorChannel(any(TTestCollectorChannel.class));
- verify(testMapper).insertTestFieldSnapshot(any());
+ verify(sharedFieldSnapshotService).saveForTest(eq(10L), any());
verify(testMapper).insertTestThreshold(any(TTestWarningThreshold.class));
verify(testMapper).insertTestAudit(anyLong(), any(), anyLong(), any(), isNull(), any());
+ }
+
+ @Test
+ void listShouldAggregateBatteryNumbersOutsideDatabaseQuery()
+ {
+ TTest first = new TTest();
+ first.setTestId(10L);
+ TTest second = new TTest();
+ second.setTestId(11L);
+ TTestBattery firstBattery = new TTestBattery();
+ firstBattery.setTestId(10L);
+ firstBattery.setBatteryNo("BAT-001");
+ TTestBattery secondBattery = new TTestBattery();
+ secondBattery.setTestId(10L);
+ secondBattery.setBatteryNo("BAT-002");
+ when(testMapper.selectTestList(any(TTest.class))).thenReturn(java.util.List.of(first, second));
+ when(testMapper.selectBatteryNosByTestIds(java.util.List.of(10L, 11L)))
+ .thenReturn(java.util.List.of(firstBattery, secondBattery));
+
+ java.util.List<TTest> result = testService.selectTestList(new TTest());
+
+ assertEquals("BAT-001、BAT-002", result.get(0).getBatteryNo());
+ assertEquals("", result.get(1).getBatteryNo());
}
@Test
@@ -263,8 +284,11 @@
current.setReceptionStatus("NOT_STARTED");
current.setMonitorTimeoutMinutes(30);
when(testMapper.selectTestByIdForUpdate(10L)).thenReturn(current);
+ when(testMapper.selectTestBatteries(10L)).thenReturn(current.getBatteries());
+ when(sharedFieldSnapshotService.selectByTestId(10L)).thenReturn(java.util.List.of());
+ when(sharedFieldSnapshotService.resolveForUpdate(1L, 1L, java.util.List.of()))
+ .thenReturn(java.util.List.of());
mockEnabledOptions();
- mockGroupSnapshot();
when(testMapper.updateTest(request)).thenReturn(1);
doAnswer(invocation -> {
invocation.<TTestBattery>getArgument(0).setRelationId(21L);
@@ -295,7 +319,9 @@
when(testMapper.selectTestByIdForUpdate(10L)).thenReturn(current);
when(testMapper.selectTestBatteries(10L)).thenReturn(current.getBatteries());
- when(testMapper.selectTestFieldSnapshots(10L)).thenReturn(java.util.List.of(originalSnapshot));
+ when(sharedFieldSnapshotService.selectByTestId(10L)).thenReturn(java.util.List.of(originalSnapshot));
+ when(sharedFieldSnapshotService.resolveForUpdate(1L, 1L, java.util.List.of(originalSnapshot)))
+ .thenReturn(java.util.List.of(originalSnapshot));
mockEnabledOptions();
when(testMapper.updateTest(request)).thenReturn(1);
doAnswer(invocation -> {
@@ -305,12 +331,9 @@
assertEquals(1, testService.updateTest(request));
- verify(testMapper).insertTestFieldSnapshot(org.mockito.ArgumentMatchers.argThat(snapshot ->
- Long.valueOf(11L).equals(snapshot.getFieldDefinitionId())
- && "额定容量".equals(snapshot.getFieldName())
- && "number".equals(snapshot.getFieldType())
- && "72".equals(snapshot.getFieldValue())));
- verify(batteryGroupService, never()).selectBatteryGroupById(anyLong());
+ verify(sharedFieldSnapshotService).resolveForUpdate(1L, 1L, java.util.List.of(originalSnapshot));
+ verify(sharedFieldSnapshotService).saveForTest(eq(10L), org.mockito.ArgumentMatchers.argThat(snapshots ->
+ snapshots.size() == 1 && "72".equals(snapshots.get(0).getFieldValue())));
}
@Test
@@ -345,15 +368,12 @@
private void mockGroupSnapshot()
{
- TBatteryGroupRelationField field = new TBatteryGroupRelationField();
- field.setBatteryGroupFieldId(11L);
- field.setFieldName("额定容量");
- field.setFieldType("number");
- field.setFieldValue("72");
- TBatteryGroup group = new TBatteryGroup();
- group.setGroupId(1L);
- group.setTemplateFields(java.util.List.of(field));
- when(batteryGroupService.selectBatteryGroupById(1L)).thenReturn(group);
+ TTestFieldSnapshot snapshot = new TTestFieldSnapshot();
+ snapshot.setFieldDefinitionId(11L);
+ snapshot.setFieldName("额定容量");
+ snapshot.setFieldType("number");
+ snapshot.setFieldValue("72");
+ when(sharedFieldSnapshotService.createForBatteryGroup(1L)).thenReturn(java.util.List.of(snapshot));
}
private TTest validTest()
--
Gitblit v1.7.1