From 2ee6c21aaab3cc88b5644b3ef9a6575f46baea81 Mon Sep 17 00:00:00 2001
From: yeg <1347747024@qq.com>
Date: 星期六, 05 九月 2026 01:40:34 +0800
Subject: [PATCH] 更新测试配置基线断言

---
 ruoyi-admin/src/test/java/com/ruoyi/system/service/impl/TTestServiceImplTest.java |   91 +++++++++++++++++++++------------------------
 1 files changed, 42 insertions(+), 49 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 0dd6a09..d15dd2d 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
@@ -10,6 +10,7 @@
 import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoInteractions;
 import static org.mockito.Mockito.when;
 import static org.mockito.Mockito.times;
 
@@ -23,7 +24,6 @@
 import org.mockito.InjectMocks;
 import org.mockito.Mock;
 import org.mockito.junit.jupiter.MockitoExtension;
-import org.springframework.dao.DuplicateKeyException;
 import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.system.domain.TTest;
 import com.ruoyi.system.domain.TTestBattery;
@@ -54,7 +54,6 @@
     {
         TTest test = validTest();
         mockEnabledOptions();
-        mockGroupSnapshot();
         when(testMapper.insertTest(any(TTest.class))).thenAnswer(invocation -> {
             invocation.<TTest>getArgument(0).setTestId(10L);
             return 1;
@@ -68,12 +67,12 @@
         assertEquals("WAITING", test.getTestStatus());
         assertEquals("NOT_STARTED", test.getReceptionStatus());
         assertEquals(7L, test.getCreatorId());
-        verify(testMapper).insertTestPlanStep(any(TTestPlanStep.class));
+        verify(testMapper, never()).insertTestPlanStep(any(TTestPlanStep.class));
         verify(testMapper).insertTestChannelBinding(any(TTestChannelBinding.class));
         verify(testMapper, times(3)).insertTestCollectorChannel(any(TTestCollectorChannel.class));
-        verify(sharedFieldSnapshotService).saveForTest(eq(10L), any());
+        verify(sharedFieldSnapshotService, never()).saveForTest(anyLong(), any());
         verify(testMapper).insertTestThreshold(any(TTestWarningThreshold.class));
-        verify(testMapper).insertTestAudit(anyLong(), any(), anyLong(), any(), isNull(), any());
+        verify(testMapper, never()).insertTestAudit(anyLong(), any(), anyLong(), any(), isNull(), any());
     }
 
     @Test
@@ -133,7 +132,6 @@
         TTest test = validTest();
         test.setPlanSteps(Collections.emptyList());
         mockEnabledOptions();
-        mockGroupSnapshot();
         when(testMapper.insertTest(any(TTest.class))).thenAnswer(invocation -> {
             invocation.<TTest>getArgument(0).setTestId(10L);
             return 1;
@@ -304,9 +302,6 @@
         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();
         when(testMapper.updateTest(request)).thenReturn(1);
         doAnswer(invocation -> {
@@ -317,8 +312,8 @@
         assertEquals(1, testService.updateTest(request));
         assertEquals(45, request.getMonitorTimeoutMinutes());
         verify(testMapper).deleteTestBindingsByTestId(10L);
-        verify(testMapper).deleteTestPlanStepsByTestId(10L);
-        verify(testMapper).insertTestAudit(anyLong(), any(), anyLong(), any(), any(), any());
+        verify(testMapper, never()).deleteTestPlanStepsByTestId(10L);
+        verify(testMapper, never()).insertTestAudit(anyLong(), any(), anyLong(), any(), any(), any());
     }
 
     @Test
@@ -338,9 +333,6 @@
 
         when(testMapper.selectTestByIdForUpdate(10L)).thenReturn(current);
         when(testMapper.selectTestBatteries(10L)).thenReturn(current.getBatteries());
-        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 -> {
@@ -350,9 +342,7 @@
 
         assertEquals(1, testService.updateTest(request));
 
-        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())));
+        verifyNoInteractions(sharedFieldSnapshotService);
     }
 
     @Test
@@ -366,11 +356,11 @@
 
         assertEquals(1, testService.deleteTestByIds(new Long[] { 10L }, 7L, "operator"));
 
-        verify(testMapper).insertTestAudit(eq(10L), eq("TEST_DELETED"), eq(7L), eq("operator"), any(), isNull());
+        verify(testMapper, never()).insertTestAudit(anyLong(), any(), anyLong(), any(), any(), any());
     }
 
     @Test
-    void startReceptionShouldOpenAllSourceIntervalsAtomically()
+    void startReceptionShouldPersistReceptionWithoutLegacyIntervals()
     {
         TTest current = validTest();
         current.setTestId(10L);
@@ -384,14 +374,9 @@
         when(testMapper.selectReceptionChannelForUpdate(100L)).thenReturn(channel);
         when(testMapper.countCollectorEnabled(8L)).thenReturn(1);
         when(testMapper.selectCollectorChannelCount(8L)).thenReturn(4);
-        when(testMapper.collectorOnline(8L)).thenReturn(true);
         when(testMapper.updateReceptionStarted(eq(10L), any(), anyBoolean(), eq("operator"))).thenReturn(1);
 
         assertEquals(1, testService.startReception(10L, 7L, "operator"));
-        verify(testMapper).insertChannelLease(eq(100L), eq(10L), eq(30L), eq(7L), any());
-        verify(testMapper).insertReceptionInterval(eq(10L), eq(30L), eq("CABINET_CHANNEL"), eq(100L), isNull(), any(), eq("RECEPTION_STARTED"));
-        verify(testMapper, times(3)).insertCollectorChannelLease(eq(8L), any(), eq(10L), eq(30L), eq(7L), any());
-        verify(testMapper, times(3)).insertReceptionInterval(eq(10L), eq(30L), eq("COLLECTOR_CHANNEL"), eq(8L), any(), any(), eq("RECEPTION_STARTED"));
         verify(testMapper).insertTestAudit(eq(10L), eq("RECEPTION_STARTED"), eq(7L), eq("operator"), isNull(), any());
     }
 
@@ -411,7 +396,6 @@
         when(testMapper.selectReceptionChannelForUpdate(100L)).thenReturn(channel);
         when(testMapper.countCollectorEnabled(8L)).thenReturn(1);
         when(testMapper.selectCollectorChannelCount(8L)).thenReturn(4);
-        when(testMapper.collectorOnline(8L)).thenReturn(true);
         when(testMapper.updateReceptionStarted(eq(10L), any(), anyBoolean(), eq("operator"))).thenReturn(1);
 
         assertEquals(1, testService.startReception(10L, 7L, "operator"));
@@ -421,7 +405,7 @@
     }
 
     @Test
-    void startReceptionShouldRollbackWhenDatabaseLeaseIsTaken()
+    void startReceptionShouldNotDependOnDatabaseLease()
     {
         TTest current = validTest();
         current.setTestId(10L);
@@ -435,36 +419,48 @@
         when(testMapper.selectReceptionChannelForUpdate(100L)).thenReturn(channel);
         when(testMapper.countCollectorEnabled(8L)).thenReturn(1);
         when(testMapper.selectCollectorChannelCount(8L)).thenReturn(4);
-        when(testMapper.collectorOnline(8L)).thenReturn(true);
-        when(testMapper.insertChannelLease(any(), any(), any(), any(), any()))
-                .thenThrow(new DuplicateKeyException("lease already exists"));
+        when(testMapper.updateReceptionStarted(eq(10L), any(), anyBoolean(), eq("operator"))).thenReturn(1);
 
-        ServiceException exception = assertThrows(ServiceException.class,
-                () -> testService.startReception(10L, 7L, "operator"));
+        assertEquals(1, testService.startReception(10L, 7L, "operator"));
 
-        assertEquals("数据来源已被其他测试占用,请刷新后重试", exception.getMessage());
-        verify(testMapper, never()).updateReceptionStarted(any(), any(), anyBoolean(), any());
-        verify(testMapper, never()).insertTestAudit(anyLong(), any(), anyLong(), any(), any(), any());
     }
 
     @Test
-    void startReceptionShouldRejectOfflineSourceWithoutWritingAnything()
+    void startReceptionShouldAllowOfflineSourcesWithoutBlockingReception()
     {
         TTest current = validTest();
         current.setTestId(10L);
         current.setReceptionStatus("NOT_STARTED");
+        current.getBatteries().get(0).getBinding().setBindingId(30L);
         when(testMapper.selectTestByIdForUpdate(10L)).thenReturn(current);
         TDetectionChannel channel = new TDetectionChannel();
         channel.setChannelId(100L);
         channel.setOnlineStatus("OFFLINE");
         when(testMapper.selectReceptionChannelForUpdate(100L)).thenReturn(channel);
+        when(testMapper.countCollectorEnabled(8L)).thenReturn(1);
+        when(testMapper.selectCollectorChannelCount(8L)).thenReturn(4);
+        when(testMapper.updateReceptionStarted(eq(10L), any(), anyBoolean(), eq("operator"))).thenReturn(1);
 
-        ServiceException exception = assertThrows(ServiceException.class,
-                () -> testService.startReception(10L, 7L, "operator"));
+        assertEquals(1, testService.startReception(10L, 7L, "operator"));
+    }
 
-        assertEquals("检测柜通道 100 当前离线或不可观测", exception.getMessage());
-        verify(testMapper, never()).insertChannelLease(any(), any(), any(), any(), any());
-        verify(testMapper, never()).updateReceptionStarted(any(), any(), anyBoolean(), any());
+    @Test
+    void startReceptionShouldAllowOfflineCollectorWithoutBlockingReception()
+    {
+        TTest current = validTest();
+        current.setTestId(10L);
+        current.setReceptionStatus("NOT_STARTED");
+        current.getBatteries().get(0).getBinding().setBindingId(30L);
+        when(testMapper.selectTestByIdForUpdate(10L)).thenReturn(current);
+        TDetectionChannel channel = new TDetectionChannel();
+        channel.setChannelId(100L);
+        channel.setOnlineStatus("ONLINE");
+        when(testMapper.selectReceptionChannelForUpdate(100L)).thenReturn(channel);
+        when(testMapper.countCollectorEnabled(8L)).thenReturn(1);
+        when(testMapper.selectCollectorChannelCount(8L)).thenReturn(4);
+        when(testMapper.updateReceptionStarted(eq(10L), any(), anyBoolean(), eq("operator"))).thenReturn(1);
+
+        assertEquals(1, testService.startReception(10L, 7L, "operator"));
     }
 
     @Test
@@ -482,14 +478,12 @@
         channel.setLastSeenAtUtc(Instant.parse("2026-08-29T12:00:00Z"));
         when(testMapper.selectReceptionChannelForUpdate(100L)).thenReturn(channel);
         when(testMapper.countCollectorEnabled(8L)).thenReturn(1);
-        when(testMapper.collectorOnline(8L)).thenReturn(true);
         when(testMapper.selectCollectorChannelCount(8L)).thenReturn(4);
 
         ServiceException exception = assertThrows(ServiceException.class,
                 () -> testService.startReception(10L, 7L, "operator"));
 
         assertEquals("每个电池号必须绑定主温度、正电位主通道和负电位主通道", exception.getMessage());
-        verify(testMapper, never()).insertChannelLease(any(), any(), any(), any(), any());
         verify(testMapper, never()).updateReceptionStarted(any(), any(), anyBoolean(), any());
     }
 
@@ -524,7 +518,10 @@
         TTest current = validTest();
         current.setTestId(10L);
         current.setReceptionStatus("PAUSED");
+        List<TTestBattery> configuredBatteries = current.getBatteries();
+        current.setBatteries(null);
         when(testMapper.selectTestByIdForUpdate(10L)).thenReturn(current);
+        when(testMapper.selectTestBatteries(10L)).thenReturn(configuredBatteries);
         when(testMapper.updateReceptionResumed(eq(10L), eq("operator"), any())).thenReturn(1);
 
         assertEquals(1, testService.resumeReception(10L, 7L, "operator"));
@@ -534,7 +531,7 @@
     }
 
     @Test
-    void stopTestShouldCompleteAndReleaseLeases()
+    void stopTestShouldCompleteWithoutLegacyLeaseCleanup()
     {
         TTest current = validTest();
         current.setTestId(10L);
@@ -544,28 +541,24 @@
 
         assertEquals(1, testService.stopTest(10L, 7L, "operator"));
         verify(testMapper).updateReceptionStopped(eq(10L), eq("operator"), any());
-        verify(testMapper).closeOpenReceptionIntervals(eq(10L), any(), eq("MANUAL_END"));
-        verify(testMapper).deleteChannelLeasesByTestId(10L);
-        verify(testMapper).deleteCollectorChannelLeasesByTestId(10L);
         verify(testMapper).insertTestAudit(eq(10L), eq("TEST_STOPPED"), eq(7L), eq("operator"), isNull(),
                 org.mockito.ArgumentMatchers.argThat(value -> value != null && value.contains("COMPLETED")));
     }
 
     @Test
-    void stopTestShouldAuditImmediateReleaseAndClosedIntervals()
+    void stopTestShouldAuditImmediateStop()
     {
         TTest current = validTest();
         current.setTestId(10L);
         current.setReceptionStatus("RECEIVING");
         when(testMapper.selectTestByIdForUpdate(10L)).thenReturn(current);
         when(testMapper.updateReceptionStopped(eq(10L), eq("operator"), any())).thenReturn(1);
-        when(testMapper.closeOpenReceptionIntervals(eq(10L), any(), eq("MANUAL_END"))).thenReturn(4);
 
         testService.stopTest(10L, 7L, "operator");
 
         verify(testMapper).insertTestAudit(eq(10L), eq("TEST_STOPPED"), eq(7L), eq("operator"), isNull(),
                 org.mockito.ArgumentMatchers.argThat(value -> value != null
-                        && value.contains("closedIntervals") && value.contains("IMMEDIATE")));
+                        && value.contains("IMMEDIATE")));
     }
 
     private void mockEnabledOptions()

--
Gitblit v1.7.1