From acfb83068486766f63284b479d30f78e3ec17dca Mon Sep 17 00:00:00 2001
From: yeg <1347747024@qq.com>
Date: 星期六, 05 九月 2026 02:24:48 +0800
Subject: [PATCH] 完成测试生命周期与接收边界
---
ruoyi-admin/src/test/java/com/ruoyi/system/service/impl/TTestServiceImplTest.java | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 60 insertions(+), 0 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 d15dd2d..268740a 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
@@ -360,10 +360,27 @@
}
@Test
+ void deleteShouldRejectMismatchedTestAndReceptionStates()
+ {
+ TTest current = validTest();
+ current.setTestId(10L);
+ current.setTestStatus("RUNNING");
+ current.setReceptionStatus("NOT_STARTED");
+ when(testMapper.selectTestByIdForUpdate(10L)).thenReturn(current);
+
+ ServiceException exception = assertThrows(ServiceException.class,
+ () -> testService.deleteTestByIds(new Long[] { 10L }, 7L, "operator"));
+
+ assertEquals("开始接收后不能删除测试", exception.getMessage());
+ verify(testMapper, never()).deleteTestById(anyLong(), any(String.class));
+ }
+
+ @Test
void startReceptionShouldPersistReceptionWithoutLegacyIntervals()
{
TTest current = validTest();
current.setTestId(10L);
+ current.setTestStatus("WAITING");
current.setReceptionStatus("NOT_STARTED");
current.getBatteries().get(0).getBinding().setBindingId(30L);
when(testMapper.selectTestByIdForUpdate(10L)).thenReturn(current);
@@ -385,6 +402,7 @@
{
TTest current = validTest();
current.setTestId(10L);
+ current.setTestStatus("WAITING");
current.setReceptionStatus("NOT_STARTED");
current.getBatteries().get(0).getBinding().setBindingId(30L);
when(testMapper.selectTestByIdForUpdate(10L)).thenReturn(current);
@@ -409,6 +427,7 @@
{
TTest current = validTest();
current.setTestId(10L);
+ current.setTestStatus("WAITING");
current.setReceptionStatus("NOT_STARTED");
current.getBatteries().get(0).getBinding().setBindingId(30L);
when(testMapper.selectTestByIdForUpdate(10L)).thenReturn(current);
@@ -430,6 +449,7 @@
{
TTest current = validTest();
current.setTestId(10L);
+ current.setTestStatus("WAITING");
current.setReceptionStatus("NOT_STARTED");
current.getBatteries().get(0).getBinding().setBindingId(30L);
when(testMapper.selectTestByIdForUpdate(10L)).thenReturn(current);
@@ -449,6 +469,7 @@
{
TTest current = validTest();
current.setTestId(10L);
+ current.setTestStatus("WAITING");
current.setReceptionStatus("NOT_STARTED");
current.getBatteries().get(0).getBinding().setBindingId(30L);
when(testMapper.selectTestByIdForUpdate(10L)).thenReturn(current);
@@ -468,6 +489,7 @@
{
TTest current = validTest();
current.setTestId(10L);
+ current.setTestStatus("WAITING");
current.setReceptionStatus("NOT_STARTED");
current.getBatteries().get(0).getBinding().setBindingId(30L);
current.getBatteries().get(0).setCollectorChannels(Collections.emptyList());
@@ -498,10 +520,43 @@
}
@Test
+ void startReceptionShouldRejectMismatchedTestAndReceptionStates()
+ {
+ TTest current = validTest();
+ current.setTestId(10L);
+ current.setTestStatus("COMPLETED");
+ current.setReceptionStatus("NOT_STARTED");
+ when(testMapper.selectTestByIdForUpdate(10L)).thenReturn(current);
+
+ ServiceException exception = assertThrows(ServiceException.class,
+ () -> testService.startReception(10L, 7L, "operator"));
+
+ assertEquals("当前测试不是未开始接收状态", exception.getMessage());
+ verify(testMapper, never()).updateReceptionStarted(any(), any(), anyBoolean(), any());
+ }
+
+ @Test
+ void pauseReceptionShouldRejectMismatchedTestAndReceptionStates()
+ {
+ TTest current = validTest();
+ current.setTestId(10L);
+ current.setTestStatus("PAUSED");
+ current.setReceptionStatus("RECEIVING");
+ when(testMapper.selectTestByIdForUpdate(10L)).thenReturn(current);
+
+ ServiceException exception = assertThrows(ServiceException.class,
+ () -> testService.pauseReception(10L, 7L, "operator"));
+
+ assertEquals("当前测试不是接收中状态", exception.getMessage());
+ verify(testMapper, never()).updateReceptionPaused(any(), any(), any());
+ }
+
+ @Test
void pauseReceptionShouldStopPollingAndAppendAudit()
{
TTest current = validTest();
current.setTestId(10L);
+ current.setTestStatus("RUNNING");
current.setReceptionStatus("RECEIVING");
when(testMapper.selectTestByIdForUpdate(10L)).thenReturn(current);
when(testMapper.updateReceptionPaused(eq(10L), eq("operator"), any())).thenReturn(1);
@@ -517,6 +572,7 @@
{
TTest current = validTest();
current.setTestId(10L);
+ current.setTestStatus("PAUSED");
current.setReceptionStatus("PAUSED");
List<TTestBattery> configuredBatteries = current.getBatteries();
current.setBatteries(null);
@@ -535,6 +591,7 @@
{
TTest current = validTest();
current.setTestId(10L);
+ current.setTestStatus("PAUSED");
current.setReceptionStatus("PAUSED");
when(testMapper.selectTestByIdForUpdate(10L)).thenReturn(current);
when(testMapper.updateReceptionStopped(eq(10L), eq("operator"), any())).thenReturn(1);
@@ -550,6 +607,7 @@
{
TTest current = validTest();
current.setTestId(10L);
+ current.setTestStatus("RUNNING");
current.setReceptionStatus("RECEIVING");
when(testMapper.selectTestByIdForUpdate(10L)).thenReturn(current);
when(testMapper.updateReceptionStopped(eq(10L), eq("operator"), any())).thenReturn(1);
@@ -615,6 +673,8 @@
test.setPrincipalId(9L);
test.setTestTypeId(3L);
test.setTestPurpose("验证低温循环性能");
+ test.setTestStatus("WAITING");
+ test.setReceptionStatus("NOT_STARTED");
test.setMonitorTimeoutMinutes(30);
test.setBatteries(Collections.singletonList(validBattery("BAT-001", 1L, 100L)));
test.setPlanSteps(Collections.singletonList(step));
--
Gitblit v1.7.1