|
@@ -146,7 +146,59 @@ class BusinessCockpitMapSnapshotAdapterTest {
|
|
|
"窨井根映射为 MANHOLE 传值,交由服务层判非正式行业,而非在适配器吞掉");
|
|
"窨井根映射为 MANHOLE 传值,交由服务层判非正式行业,而非在适配器吞掉");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // ---- stubbing helpers ----
|
|
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void sameSnapshotAtReusesTheFirstSourceSnapshotAfterRelationsChange() {
|
|
|
|
|
+ String snapshotAt = "2026-09-02T10:00:00+08:00";
|
|
|
|
|
+ MonitorPoint point = point("P-1", "POINT-1", "点位一", new BigDecimal("110.4"), new BigDecimal("28.4"));
|
|
|
|
|
+ EquipmentType equipmentType = type(11, "pressure", "压力计", "1");
|
|
|
|
|
+ EquipmentBase firstDevice = device("D-1", "DEVICE-1", "设备一", "11",
|
|
|
|
|
+ new BigDecimal("110.401"), new BigDecimal("28.401"));
|
|
|
|
|
+ EquipmentBase secondDevice = device("D-2", "DEVICE-2", "设备二", "11",
|
|
|
|
|
+ new BigDecimal("110.402"), new BigDecimal("28.402"));
|
|
|
|
|
+ stubPoints(Collections.singletonList(point));
|
|
|
|
|
+ stubTypes(Collections.singletonList(equipmentType));
|
|
|
|
|
+ stubDevices(Collections.singletonList(firstDevice), Collections.singletonList(firstDevice));
|
|
|
|
|
+ when(deviceFactResolver.resolve(any(), anyString())).thenAnswer(invocation -> {
|
|
|
|
|
+ EquipmentBase device = invocation.getArgument(0);
|
|
|
|
|
+ return fact(device.getEquipmentCode());
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ CockpitMapSnapshot first = adapter.load(snapshotAt);
|
|
|
|
|
+
|
|
|
|
|
+ stubDevices(Collections.singletonList(secondDevice), Collections.singletonList(secondDevice));
|
|
|
|
|
+ CockpitMapSnapshot second = adapter.load(snapshotAt);
|
|
|
|
|
+
|
|
|
|
|
+ assertEquals(Collections.singletonList("DEVICE-1"),
|
|
|
|
|
+ first.getMonitoringPoints().get(0).getDevices().stream()
|
|
|
|
|
+ .map(CockpitMonitoringPointDeviceSnapshot::getDeviceCode)
|
|
|
|
|
+ .collect(java.util.stream.Collectors.toList()));
|
|
|
|
|
+ assertEquals(Collections.singletonList("DEVICE-1"),
|
|
|
|
|
+ second.getMonitoringPoints().get(0).getDevices().stream()
|
|
|
|
|
+ .map(CockpitMonitoringPointDeviceSnapshot::getDeviceCode)
|
|
|
|
|
+ .collect(java.util.stream.Collectors.toList()),
|
|
|
|
|
+ "同一 snapshotAt 必须复用首次读取的点位设备关系");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void differentSnapshotAtReadsASeparateSourceSnapshot() {
|
|
|
|
|
+ String firstSnapshotAt = "2026-09-02T10:00:00+08:00";
|
|
|
|
|
+ String secondSnapshotAt = "2026-09-02T10:01:00+08:00";
|
|
|
|
|
+ MonitorPoint point = point("P-1", "POINT-1", "点位一", new BigDecimal("110.4"), new BigDecimal("28.4"));
|
|
|
|
|
+ stubPoints(Collections.singletonList(point));
|
|
|
|
|
+ stubTypes(Collections.singletonList(type(11, "pressure", "压力计", "1")));
|
|
|
|
|
+ EquipmentBase firstDevice = device("D-1", "DEVICE-1", "设备一", "11", null, null);
|
|
|
|
|
+ EquipmentBase secondDevice = device("D-2", "DEVICE-2", "设备二", "11", null, null);
|
|
|
|
|
+ stubDevices(Collections.singletonList(firstDevice), Collections.singletonList(firstDevice));
|
|
|
|
|
+ when(deviceFactResolver.resolve(any(), anyString())).thenAnswer(invocation ->
|
|
|
|
|
+ fact(invocation.<EquipmentBase>getArgument(0).getEquipmentCode()));
|
|
|
|
|
+
|
|
|
|
|
+ CockpitMapSnapshot first = adapter.load(firstSnapshotAt);
|
|
|
|
|
+ stubDevices(Collections.singletonList(secondDevice), Collections.singletonList(secondDevice));
|
|
|
|
|
+ CockpitMapSnapshot second = adapter.load(secondSnapshotAt);
|
|
|
|
|
+
|
|
|
|
|
+ assertEquals("DEVICE-1", first.getMonitoringPoints().get(0).getDevices().get(0).getDeviceCode());
|
|
|
|
|
+ assertEquals("DEVICE-2", second.getMonitoringPoints().get(0).getDevices().get(0).getDeviceCode());
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
private void stubPoints(List<MonitorPoint> points) {
|
|
private void stubPoints(List<MonitorPoint> points) {
|
|
|
when(monitorPointService.list()).thenReturn(points);
|
|
when(monitorPointService.list()).thenReturn(points);
|