|
@@ -0,0 +1,127 @@
|
|
|
|
|
+package com.zksy.web.controller.cockpit;
|
|
|
|
|
+
|
|
|
|
|
+import com.zksy.base.domain.EquipmentBase;
|
|
|
|
|
+import com.zksy.base.domain.EquipmentType;
|
|
|
|
|
+import com.zksy.base.domain.PipeNetworkBase;
|
|
|
|
|
+import com.zksy.base.service.EquipmentBaseService;
|
|
|
|
|
+import com.zksy.base.service.EquipmentTypeService;
|
|
|
|
|
+import com.zksy.base.service.PipeNetworkBaseService;
|
|
|
|
|
+import com.zksy.cockpit.device.BusinessCockpitDeviceBoundaryAdapter;
|
|
|
|
|
+import com.zksy.cockpit.device.CockpitDeviceBoundaryResponse;
|
|
|
|
|
+import com.zksy.cockpit.device.CockpitDeviceBoundaryService;
|
|
|
|
|
+import com.zksy.cockpit.device.CockpitFacilityBoundary;
|
|
|
|
|
+import org.junit.jupiter.api.BeforeEach;
|
|
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
|
|
+
|
|
|
|
|
+import java.time.Clock;
|
|
|
|
|
+import java.time.Instant;
|
|
|
|
|
+import java.time.ZoneOffset;
|
|
|
|
|
+import java.util.Arrays;
|
|
|
|
|
+import java.util.Collections;
|
|
|
|
|
+
|
|
|
|
|
+import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
|
+import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
|
|
+import static org.mockito.Mockito.mock;
|
|
|
|
|
+import static org.mockito.Mockito.when;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 设备边界「适配器 → 服务 → 响应」贯通契约(执行票 20 现象 2 的验收防线)。
|
|
|
|
|
+ *
|
|
|
|
|
+ * <p>回归背景:真实库里 {@code network_type=1} 是<b>排水</b>设施(3735 条),
|
|
|
|
|
+ * 旧实现把它透传去查 {@code equipment_type} 字典,命中 id=1「供水设备」,于是响应里
|
|
|
|
|
+ * 排水设施的类型名与行业都是「供水 / WATER_SUPPLY」。控制器测试用 mock 适配器,测不到
|
|
|
|
|
+ * 这一段;本测试用真实适配器 + 真实服务,只 mock 数据源。</p>
|
|
|
|
|
+ */
|
|
|
|
|
+class CockpitDeviceBoundaryPipeIndustryTest {
|
|
|
|
|
+
|
|
|
|
|
+ private CockpitDeviceBoundaryService service;
|
|
|
|
|
+
|
|
|
|
|
+ @BeforeEach
|
|
|
|
|
+ void setUp() {
|
|
|
|
|
+ EquipmentTypeService equipmentTypeService = mock(EquipmentTypeService.class);
|
|
|
|
|
+ EquipmentBaseService equipmentBaseService = mock(EquipmentBaseService.class);
|
|
|
|
|
+ PipeNetworkBaseService pipeNetworkBaseService = mock(PipeNetworkBaseService.class);
|
|
|
|
|
+ // 设备类型命名空间:id=1「供水设备」、id=2「排水设备」——与 network_type 数值域重叠。
|
|
|
|
|
+ when(equipmentTypeService.list()).thenReturn(Arrays.asList(
|
|
|
|
|
+ type(1, "供水设备", 0), type(2, "排水设备", 0)));
|
|
|
|
|
+ when(equipmentBaseService.list()).thenReturn(Collections.emptyList());
|
|
|
|
|
+ when(pipeNetworkBaseService.list()).thenReturn(Arrays.asList(
|
|
|
|
|
+ pipe("P-GAS", "燃气管线", "0"),
|
|
|
|
|
+ pipe("P-DRAIN", "排水管线", "1"),
|
|
|
|
|
+ pipe("P-WATER", "供水管线", "2")));
|
|
|
|
|
+
|
|
|
|
|
+ service = new CockpitDeviceBoundaryService(
|
|
|
|
|
+ new BusinessCockpitDeviceBoundaryAdapter(
|
|
|
|
|
+ equipmentTypeService, equipmentBaseService, pipeNetworkBaseService),
|
|
|
|
|
+ Clock.fixed(Instant.parse("2026-10-10T02:00:00Z"), ZoneOffset.UTC));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void drainagePipeIsReportedAsDrainageNotWaterSupply() {
|
|
|
|
|
+ CockpitDeviceBoundaryResponse response = service.load("req-1");
|
|
|
|
|
+
|
|
|
|
|
+ CockpitFacilityBoundary drainage = facility(response, "P-DRAIN");
|
|
|
|
|
+ assertEquals("排水管线", drainage.getFacilityType().getName(),
|
|
|
|
|
+ "排水设施不得被标成「供水设备」");
|
|
|
|
|
+ assertEquals("DRAINAGE_PIPE", drainage.getFacilityType().getCode());
|
|
|
|
|
+ assertEquals("DRAINAGE", drainage.getIndustry());
|
|
|
|
|
+ assertTrue(drainage.isFormalScope());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void waterPipeIsReportedAsWaterSupplyNotDrainage() {
|
|
|
|
|
+ CockpitDeviceBoundaryResponse response = service.load("req-2");
|
|
|
|
|
+
|
|
|
|
|
+ CockpitFacilityBoundary water = facility(response, "P-WATER");
|
|
|
|
|
+ assertEquals("供水管线", water.getFacilityType().getName(),
|
|
|
|
|
+ "供水设施不得被标成「排水设备」");
|
|
|
|
|
+ assertEquals("WATER_SUPPLY", water.getIndustry());
|
|
|
|
|
+ assertTrue(water.isFormalScope());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void gasPipeIsReportedAsGasAndNoLongerCountedAsUnknownType() {
|
|
|
|
|
+ CockpitDeviceBoundaryResponse response = service.load("req-3");
|
|
|
|
|
+
|
|
|
|
|
+ CockpitFacilityBoundary gas = facility(response, "P-GAS");
|
|
|
|
|
+ assertEquals("燃气管线", gas.getFacilityType().getName());
|
|
|
|
|
+ assertEquals("GAS", gas.getIndustry());
|
|
|
|
|
+
|
|
|
|
|
+ // 旧实现下 network_type=0 查不到 equipment_type.id=0,会被计入 unknownTypeCount
|
|
|
|
|
+ assertEquals(0, response.getStatistics().getUnknownTypeCount(),
|
|
|
|
|
+ "0/1/2 三类管网都应解析成功,不该有未知类型");
|
|
|
|
|
+ assertEquals(3, response.getStatistics().getFacilityCount());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void pipeFacilitiesFlowIntoFormalIndustryStatistics() {
|
|
|
|
|
+ CockpitDeviceBoundaryResponse response = service.load("req-4");
|
|
|
|
|
+
|
|
|
|
|
+ assertEquals(1, response.getStatistics().getIndustries().get("gas").getFacilityCount());
|
|
|
|
|
+ assertEquals(1, response.getStatistics().getIndustries().get("drainage").getFacilityCount());
|
|
|
|
|
+ assertEquals(1, response.getStatistics().getIndustries().get("waterSupply").getFacilityCount());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static CockpitFacilityBoundary facility(
|
|
|
|
|
+ CockpitDeviceBoundaryResponse response, String code) {
|
|
|
|
|
+ return response.getFacilities().stream()
|
|
|
|
|
+ .filter(item -> code.equals(item.getFacilityCode()))
|
|
|
|
|
+ .findFirst().orElseThrow(AssertionError::new);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static EquipmentType type(Integer id, String name, Integer parentId) {
|
|
|
|
|
+ EquipmentType type = new EquipmentType();
|
|
|
|
|
+ type.setId(id);
|
|
|
|
|
+ type.setTypeName(name);
|
|
|
|
|
+ type.setParentId(parentId);
|
|
|
|
|
+ return type;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static PipeNetworkBase pipe(String code, String name, String networkType) {
|
|
|
|
|
+ PipeNetworkBase facility = new PipeNetworkBase();
|
|
|
|
|
+ facility.setNetworkCode(code);
|
|
|
|
|
+ facility.setNetworkName(name);
|
|
|
|
|
+ facility.setNetworkType(networkType);
|
|
|
|
|
+ return facility;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|