| | |
| | | import static org.junit.jupiter.api.Assertions.assertEquals; |
| | | import static org.junit.jupiter.api.Assertions.assertThrows; |
| | | import static org.mockito.ArgumentMatchers.any; |
| | | import static org.mockito.ArgumentMatchers.anyBoolean; |
| | | import static org.mockito.ArgumentMatchers.anyLong; |
| | | import static org.mockito.ArgumentMatchers.eq; |
| | | import static org.mockito.ArgumentMatchers.isNull; |
| | |
| | | import java.math.BigDecimal; |
| | | import java.util.Collections; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.time.Instant; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.junit.jupiter.api.extension.ExtendWith; |
| | |
| | | } |
| | | |
| | | @Test |
| | | void createShouldRejectCaseInsensitiveDuplicateCollectorMeasurement() |
| | | { |
| | | TTest test = validTest(); |
| | | test.getBatteries().get(0).getCollectorChannels() |
| | | .add(collectorChannel("primary_temperature", "主温度重复", "S-04")); |
| | | mockEnabledOptions(); |
| | | |
| | | ServiceException exception = assertThrows(ServiceException.class, () -> testService.createTest(test)); |
| | | |
| | | assertEquals("同一电池号的采集器测量项不可重复", exception.getMessage()); |
| | | verify(testMapper, never()).insertTest(any(TTest.class)); |
| | | } |
| | | |
| | | @Test |
| | | void createShouldRejectBatteriesFromDifferentGroups() |
| | | { |
| | | TTest test = validTest(); |
| | |
| | | when(testMapper.countCollectorEnabled(8L)).thenReturn(1); |
| | | when(testMapper.selectCollectorChannelCount(8L)).thenReturn(4); |
| | | when(testMapper.collectorOnline(8L)).thenReturn(true); |
| | | when(testMapper.updateReceptionStarted(eq(10L), any(), eq("operator"))).thenReturn(1); |
| | | 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(4)).insertReceptionInterval(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()); |
| | | } |
| | | |
| | |
| | | when(testMapper.countCollectorEnabled(8L)).thenReturn(1); |
| | | when(testMapper.selectCollectorChannelCount(8L)).thenReturn(4); |
| | | when(testMapper.collectorOnline(8L)).thenReturn(true); |
| | | when(testMapper.updateReceptionStarted(eq(10L), any(), eq("operator"))).thenReturn(1); |
| | | when(testMapper.updateReceptionStarted(eq(10L), any(), anyBoolean(), eq("operator"))).thenReturn(1); |
| | | |
| | | assertEquals(1, testService.startReception(10L, 7L, "operator")); |
| | | verify(testMapper).insertTestAudit(eq(10L), eq("RECEPTION_STARTED"), eq(7L), eq("operator"), isNull(), |
| | | org.mockito.ArgumentMatchers.argThat(value -> value != null && value.contains("runtimeAttach") |
| | | && value.contains("运行中接入"))); |
| | | && value.contains("true"))); |
| | | } |
| | | |
| | | @Test |
| | |
| | | () -> testService.startReception(10L, 7L, "operator")); |
| | | |
| | | assertEquals("数据来源已被其他测试占用,请刷新后重试", exception.getMessage()); |
| | | verify(testMapper, never()).insertReceptionInterval(any()); |
| | | verify(testMapper, never()).updateReceptionStarted(any(), any(), any()); |
| | | verify(testMapper, never()).updateReceptionStarted(any(), any(), anyBoolean(), any()); |
| | | verify(testMapper, never()).insertTestAudit(anyLong(), any(), anyLong(), any(), any(), any()); |
| | | } |
| | | |
| | |
| | | |
| | | assertEquals("检测柜通道 100 当前离线或不可观测", exception.getMessage()); |
| | | verify(testMapper, never()).insertChannelLease(any(), any(), any(), any(), any()); |
| | | verify(testMapper, never()).insertReceptionInterval(any()); |
| | | verify(testMapper, never()).updateReceptionStarted(any(), any(), any()); |
| | | verify(testMapper, never()).updateReceptionStarted(any(), any(), anyBoolean(), any()); |
| | | } |
| | | |
| | | @Test |
| | |
| | | |
| | | assertEquals("每个电池号必须绑定主温度、正电位主通道和负电位主通道", exception.getMessage()); |
| | | verify(testMapper, never()).insertChannelLease(any(), any(), any(), any(), any()); |
| | | verify(testMapper, never()).updateReceptionStarted(any(), any(), any()); |
| | | verify(testMapper, never()).updateReceptionStarted(any(), any(), anyBoolean(), any()); |
| | | } |
| | | |
| | | @Test |
| | |
| | | verify(testMapper, never()).selectTestByIdForUpdate(anyLong()); |
| | | } |
| | | |
| | | @Test |
| | | void pauseReceptionShouldStopPollingAndAppendAudit() |
| | | { |
| | | TTest current = validTest(); |
| | | current.setTestId(10L); |
| | | current.setReceptionStatus("RECEIVING"); |
| | | when(testMapper.selectTestByIdForUpdate(10L)).thenReturn(current); |
| | | when(testMapper.updateReceptionPaused(eq(10L), eq("operator"), any())).thenReturn(1); |
| | | |
| | | assertEquals(1, testService.pauseReception(10L, 7L, "operator")); |
| | | verify(testMapper).updateReceptionPaused(eq(10L), eq("operator"), any()); |
| | | verify(testMapper).insertTestAudit(eq(10L), eq("RECEPTION_PAUSED"), eq(7L), eq("operator"), isNull(), |
| | | org.mockito.ArgumentMatchers.argThat(value -> value != null && value.contains("STOPPED"))); |
| | | } |
| | | |
| | | @Test |
| | | void resumeReceptionShouldRestartPollingAndAppendAudit() |
| | | { |
| | | TTest current = validTest(); |
| | | current.setTestId(10L); |
| | | current.setReceptionStatus("PAUSED"); |
| | | when(testMapper.selectTestByIdForUpdate(10L)).thenReturn(current); |
| | | when(testMapper.updateReceptionResumed(eq(10L), eq("operator"), any())).thenReturn(1); |
| | | |
| | | assertEquals(1, testService.resumeReception(10L, 7L, "operator")); |
| | | verify(testMapper).updateReceptionResumed(eq(10L), eq("operator"), any()); |
| | | verify(testMapper).insertTestAudit(eq(10L), eq("RECEPTION_RESUMED"), eq(7L), eq("operator"), isNull(), |
| | | org.mockito.ArgumentMatchers.argThat(value -> value != null && value.contains("RESUMED"))); |
| | | } |
| | | |
| | | @Test |
| | | void stopTestShouldCompleteAndReleaseLeases() |
| | | { |
| | | TTest current = validTest(); |
| | | current.setTestId(10L); |
| | | current.setReceptionStatus("PAUSED"); |
| | | when(testMapper.selectTestByIdForUpdate(10L)).thenReturn(current); |
| | | when(testMapper.updateReceptionStopped(eq(10L), eq("operator"), any())).thenReturn(1); |
| | | |
| | | 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() |
| | | { |
| | | 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"))); |
| | | } |
| | | |
| | | private void mockEnabledOptions() |
| | | { |
| | | mockEnabledPeopleAndType(); |