|
|
@@ -0,0 +1,131 @@
|
|
|
+package com.zksy.web.controller.cockpit;
|
|
|
+
|
|
|
+import com.zksy.base.domain.EquipmentBase;
|
|
|
+import com.zksy.base.domain.EquipmentType;
|
|
|
+import com.zksy.base.domain.MonitorPoint;
|
|
|
+import com.zksy.base.service.EquipmentBaseService;
|
|
|
+import com.zksy.base.service.EquipmentTypeService;
|
|
|
+import com.zksy.base.service.MonitorPointService;
|
|
|
+import com.zksy.cockpit.point.BusinessCockpitDeviceFactResolver;
|
|
|
+import com.zksy.cockpit.point.BusinessCockpitMonitoringPointDetailAdapter;
|
|
|
+import com.zksy.cockpit.point.CockpitMonitoringPointDetail;
|
|
|
+import com.zksy.cockpit.point.CockpitMonitoringPointDeviceSnapshot;
|
|
|
+import org.junit.jupiter.api.BeforeEach;
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.Collections;
|
|
|
+
|
|
|
+import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
+import static org.junit.jupiter.api.Assertions.assertFalse;
|
|
|
+import static org.junit.jupiter.api.Assertions.assertNull;
|
|
|
+import static org.mockito.ArgumentMatchers.any;
|
|
|
+import static org.mockito.ArgumentMatchers.anyString;
|
|
|
+import static org.mockito.Mockito.mock;
|
|
|
+import static org.mockito.Mockito.when;
|
|
|
+
|
|
|
+class BusinessCockpitMonitoringPointDetailAdapterTest {
|
|
|
+
|
|
|
+ private MonitorPointService monitorPointService;
|
|
|
+ private EquipmentBaseService equipmentBaseService;
|
|
|
+ private EquipmentTypeService equipmentTypeService;
|
|
|
+ private BusinessCockpitDeviceFactResolver deviceFactResolver;
|
|
|
+ private BusinessCockpitMonitoringPointDetailAdapter adapter;
|
|
|
+
|
|
|
+ @BeforeEach
|
|
|
+ void setUp() {
|
|
|
+ monitorPointService = mock(MonitorPointService.class);
|
|
|
+ equipmentBaseService = mock(EquipmentBaseService.class);
|
|
|
+ equipmentTypeService = mock(EquipmentTypeService.class);
|
|
|
+ deviceFactResolver = mock(BusinessCockpitDeviceFactResolver.class);
|
|
|
+ adapter = new BusinessCockpitMonitoringPointDetailAdapter(
|
|
|
+ monitorPointService, equipmentBaseService, equipmentTypeService, deviceFactResolver);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void loadsPointAndResolvesBoundDeviceTypeAndRuntimeFacts() {
|
|
|
+ MonitorPoint point = point("P-1", "MP-001", "供水干管监测点", "110.4024", "28.4499");
|
|
|
+ EquipmentBase device = device("D-1", "DEV-001", "压力计-001", 11);
|
|
|
+ EquipmentType type = type(11, "超声波流量计");
|
|
|
+ when(monitorPointService.list()).thenReturn(Collections.singletonList(point));
|
|
|
+ when(equipmentTypeService.list()).thenReturn(Collections.singletonList(type));
|
|
|
+ when(equipmentBaseService.getEquipmentByPoint("P-1"))
|
|
|
+ .thenReturn(Collections.singletonList(device));
|
|
|
+ when(deviceFactResolver.resolve(device, "超声波流量计"))
|
|
|
+ .thenReturn(fact("DEV-001"));
|
|
|
+
|
|
|
+ CockpitMonitoringPointDetail detail = adapter.load(" MP-001 ");
|
|
|
+
|
|
|
+ assertEquals("MP-001", detail.getMonitoringPointCode());
|
|
|
+ assertEquals("供水干管监测点", detail.getMonitoringPointName());
|
|
|
+ assertEquals(new BigDecimal("110.4024"), detail.getLongitude());
|
|
|
+ assertEquals(new BigDecimal("28.4499"), detail.getLatitude());
|
|
|
+ assertFalse(detail.isCoordinateVerified(), "现网没有可信坐标校核字段");
|
|
|
+ assertEquals(1, detail.getDevices().size());
|
|
|
+ assertEquals("DEV-001", detail.getDevices().get(0).getDeviceCode());
|
|
|
+ assertEquals("压力计", detail.getDevices().get(0).getDeviceTypeName());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void missingPointReturnsNullWithoutInventingAnEmptyDetail() {
|
|
|
+ when(monitorPointService.list()).thenReturn(Collections.singletonList(
|
|
|
+ point("P-1", "MP-001", "点位一", "110.4", "28.4")));
|
|
|
+
|
|
|
+ assertNull(adapter.load("MP-404"));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void nullRelationsAndUnknownTypeRemainSafeAndExplicit() {
|
|
|
+ MonitorPoint point = point("P-1", "MP-001", "点位一", null, null);
|
|
|
+ EquipmentBase device = device("D-1", "DEV-001", "未知设备", null);
|
|
|
+ when(monitorPointService.list()).thenReturn(Arrays.asList(point, null));
|
|
|
+ when(equipmentTypeService.list()).thenReturn(Collections.emptyList());
|
|
|
+ when(equipmentBaseService.getEquipmentByPoint("P-1"))
|
|
|
+ .thenReturn(Arrays.asList(device, null));
|
|
|
+ when(deviceFactResolver.resolve(device, null)).thenReturn(fact("DEV-001", null));
|
|
|
+
|
|
|
+ CockpitMonitoringPointDetail detail = adapter.load("MP-001");
|
|
|
+
|
|
|
+ assertEquals(1, detail.getDevices().size());
|
|
|
+ assertNull(detail.getDevices().get(0).getDeviceTypeName());
|
|
|
+ assertNull(detail.getLongitude());
|
|
|
+ assertNull(detail.getLatitude());
|
|
|
+ }
|
|
|
+
|
|
|
+ private static CockpitMonitoringPointDeviceSnapshot fact(String code) {
|
|
|
+ return fact(code, "压力计");
|
|
|
+ }
|
|
|
+
|
|
|
+ private static CockpitMonitoringPointDeviceSnapshot fact(String code, String typeName) {
|
|
|
+ return new CockpitMonitoringPointDeviceSnapshot(
|
|
|
+ code, code, typeName, true, false, false, false,
|
|
|
+ Collections.emptyList(), null);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static MonitorPoint point(String id, String code, String name, String longitude, String latitude) {
|
|
|
+ MonitorPoint point = new MonitorPoint();
|
|
|
+ point.setPointId(id);
|
|
|
+ point.setPointCode(code);
|
|
|
+ point.setPointName(name);
|
|
|
+ point.setLongitude(longitude == null ? null : new BigDecimal(longitude));
|
|
|
+ point.setLatitude(latitude == null ? null : new BigDecimal(latitude));
|
|
|
+ return point;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static EquipmentBase device(String id, String code, String name, Integer typeId) {
|
|
|
+ EquipmentBase device = new EquipmentBase();
|
|
|
+ device.setEquipmentId(id);
|
|
|
+ device.setEquipmentCode(code);
|
|
|
+ device.setEquipmentName(name);
|
|
|
+ device.setEquipmentTypeId(typeId);
|
|
|
+ return device;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static EquipmentType type(int id, String name) {
|
|
|
+ EquipmentType type = new EquipmentType();
|
|
|
+ type.setId(id);
|
|
|
+ type.setTypeName(name);
|
|
|
+ return type;
|
|
|
+ }
|
|
|
+}
|