| | |
| | | import static org.junit.jupiter.api.Assertions.assertEquals; |
| | | import static org.junit.jupiter.api.Assertions.assertTrue; |
| | | import static org.mockito.Mockito.when; |
| | | import java.time.Instant; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | assertTrue(service.cycles(8L).get(0).containsKey("cycleNo")); |
| | | } |
| | | |
| | | @Test |
| | | void assignsCollectorObservationToCabinetStepByDeviceTime() |
| | | { |
| | | when(tests.selectTestById(9L)).thenReturn(new TTest()); |
| | | Map<String, Object> cabinet = row("sourceType", "CABINET", "batteryNo", "B-01", "cycleNo", 1, |
| | | "stepNo", 2, "stepName", "恒流充电", "deviceTime", Instant.parse("2026-09-02T00:00:00Z"), |
| | | "adapterId", 1L, "devtype", 22, "deviceId", 22L, "subdevid", 0, "channelId", 8L, "sequenceId", 1L); |
| | | Map<String, Object> collector = row("sourceType", "COLLECTOR", "batteryNo", "B-01", "metricCode", "temperature", |
| | | "deviceTime", Instant.parse("2026-09-02T00:00:01Z"), "collectorId", 3L, "channelCode", "S-01", "sequenceId", 2L); |
| | | when(mapper.selectPersistedRecords(9L)).thenReturn(List.of(cabinet)); |
| | | when(mapper.selectPersistedCollectorRecords(9L)).thenReturn(List.of(collector)); |
| | | when(mapper.selectDataOverrides(9L, "REALTIME")).thenReturn(List.of()); |
| | | |
| | | List<Map<String, Object>> result = new TestDataQueryServiceImpl(mapper, tests).records(9L); |
| | | |
| | | assertEquals(2, result.size()); |
| | | Map<String, Object> assigned = result.stream().filter(item -> "COLLECTOR".equals(item.get("sourceType"))).findFirst().orElseThrow(); |
| | | assertEquals("1", assigned.get("cycleNo")); |
| | | assertEquals("2", assigned.get("stepNo")); |
| | | assertEquals("恒流充电", assigned.get("stepName")); |
| | | } |
| | | |
| | | @Test |
| | | void doesNotAssignCollectorObservationToDeletedCabinetStep() |
| | | { |
| | | when(tests.selectTestById(10L)).thenReturn(new TTest()); |
| | | Map<String, Object> cabinet = row("sourceType", "CABINET", "batteryNo", "B-01", "cycleNo", 1, |
| | | "stepNo", 2, "stepName", "恒流充电", "deviceTime", Instant.parse("2026-09-02T00:00:00Z"), |
| | | "adapterId", 1L, "devtype", 22, "deviceId", 22L, "subdevid", 0, "channelId", 8L, "sequenceId", 1L); |
| | | Map<String, Object> collector = row("sourceType", "COLLECTOR", "batteryNo", "B-01", "metricCode", "temperature", |
| | | "deviceTime", Instant.parse("2026-09-02T00:00:01Z"), "collectorId", 3L, "channelCode", "S-01", "sequenceId", 2L); |
| | | when(mapper.selectPersistedRecords(10L)).thenReturn(List.of(cabinet)); |
| | | when(mapper.selectPersistedCollectorRecords(10L)).thenReturn(List.of(collector)); |
| | | when(mapper.selectDataOverrides(10L, "REALTIME")).thenReturn(List.of( |
| | | override("1:22:22:0:8:1", null, true))); |
| | | |
| | | List<Map<String, Object>> result = new TestDataQueryServiceImpl(mapper, tests).records(10L); |
| | | |
| | | Map<String, Object> assigned = result.stream().filter(item -> "COLLECTOR".equals(item.get("sourceType"))).findFirst().orElseThrow(); |
| | | assertTrue(!assigned.containsKey("stepNo")); |
| | | assertTrue(!assigned.containsKey("cycleNo")); |
| | | } |
| | | |
| | | private static TTestDataOverride override(String identity, String values, boolean deleted) |
| | | { |
| | | TTestDataOverride result = new TTestDataOverride(); |