From 4eaa4be4d2cbd2aa49d36a313ce71ad3e743db4a Mon Sep 17 00:00:00 2001
From: yeg <1347747024@qq.com>
Date: 星期三, 02 九月 2026 12:22:53 +0800
Subject: [PATCH] 彻底清理补采完整性遗留依赖

---
 ruoyi-admin/src/test/java/com/ruoyi/system/service/impl/TTestServiceImplTest.java |   43 +++++++++++++++++++++++++------------------
 1 files changed, 25 insertions(+), 18 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 3538aec..561b2de 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
@@ -23,7 +23,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;
@@ -370,7 +369,7 @@
     }
 
     @Test
-    void startReceptionShouldOpenAllSourceIntervalsAtomically()
+    void startReceptionShouldPersistReceptionWithoutLegacyIntervals()
     {
         TTest current = validTest();
         current.setTestId(10L);
@@ -388,8 +387,6 @@
         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, times(3)).insertCollectorChannelLease(eq(8L), any(), eq(10L), eq(30L), eq(7L), any());
         verify(testMapper).insertTestAudit(eq(10L), eq("RECEPTION_STARTED"), eq(7L), eq("operator"), isNull(), any());
     }
 
@@ -419,7 +416,7 @@
     }
 
     @Test
-    void startReceptionShouldRollbackWhenDatabaseLeaseIsTaken()
+    void startReceptionShouldNotDependOnDatabaseLease()
     {
         TTest current = validTest();
         current.setTestId(10L);
@@ -434,15 +431,10 @@
         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
@@ -461,7 +453,6 @@
                 () -> 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());
     }
 
@@ -487,7 +478,6 @@
                 () -> 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());
     }
 
@@ -522,7 +512,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"));
@@ -532,7 +525,7 @@
     }
 
     @Test
-    void stopTestShouldTerminateAndReleaseLeases()
+    void stopTestShouldCompleteWithoutLegacyLeaseCleanup()
     {
         TTest current = validTest();
         current.setTestId(10L);
@@ -542,10 +535,24 @@
 
         assertEquals(1, testService.stopTest(10L, 7L, "operator"));
         verify(testMapper).updateReceptionStopped(eq(10L), eq("operator"), any());
-        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("TERMINATED")));
+                org.mockito.ArgumentMatchers.argThat(value -> value != null && value.contains("COMPLETED")));
+    }
+
+    @Test
+    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);
+
+        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("IMMEDIATE")));
     }
 
     private void mockEnabledOptions()

--
Gitblit v1.7.1