|
|
@@ -1,9 +1,7 @@
|
|
|
package com.zksy.web.controller.cockpit;
|
|
|
|
|
|
-import com.zksy.base.domain.GasPipePoint;
|
|
|
import com.zksy.base.domain.ManholeBase;
|
|
|
import com.zksy.base.domain.PipeNetworkBase;
|
|
|
-import com.zksy.base.service.GasPipePointService;
|
|
|
import com.zksy.base.service.ManholeBaseService;
|
|
|
import com.zksy.base.service.PipeNetworkBaseService;
|
|
|
import com.zksy.cockpit.foundation.CockpitReadException;
|
|
|
@@ -30,19 +28,16 @@ import static org.mockito.Mockito.*;
|
|
|
|
|
|
class CockpitFacilityGeometryServiceTest {
|
|
|
private PipeNetworkBaseService networks;
|
|
|
- private GasPipePointService points;
|
|
|
private ManholeBaseService manholes;
|
|
|
private CockpitFacilityGeometryService service;
|
|
|
|
|
|
@BeforeEach
|
|
|
void setUp() {
|
|
|
networks = mock(PipeNetworkBaseService.class);
|
|
|
- points = mock(GasPipePointService.class);
|
|
|
manholes = mock(ManholeBaseService.class);
|
|
|
when(networks.list()).thenReturn(Collections.emptyList());
|
|
|
- when(points.list()).thenReturn(Collections.emptyList());
|
|
|
when(manholes.list()).thenReturn(Collections.emptyList());
|
|
|
- service = new CockpitFacilityGeometryService(networks, points, manholes,
|
|
|
+ service = new CockpitFacilityGeometryService(networks, manholes,
|
|
|
Clock.fixed(Instant.parse("2026-10-12T02:00:00Z"), ZoneOffset.UTC));
|
|
|
}
|
|
|
|
|
|
@@ -50,9 +45,6 @@ class CockpitFacilityGeometryServiceTest {
|
|
|
void readsAllThreeIndustriesAsActualTwoEndpointLinesWithoutInventingTopology() {
|
|
|
when(networks.list()).thenReturn(Arrays.asList(network("same-id", "0"), network("water", "2"),
|
|
|
network("drain", "1"), network("unknown", "3")));
|
|
|
- GasPipePoint point = point(1L, "三通");
|
|
|
- point.setNetworkId("same-id");
|
|
|
- when(points.list()).thenReturn(Collections.singletonList(point));
|
|
|
ManholeBase manhole = new ManholeBase();
|
|
|
manhole.setManholeId("same-id");
|
|
|
manhole.setLongitude(new BigDecimal("110.440"));
|
|
|
@@ -62,9 +54,10 @@ class CockpitFacilityGeometryServiceTest {
|
|
|
CockpitFacilityGeometryResponse response = service.load();
|
|
|
assertEquals("FeatureCollection", response.getType());
|
|
|
assertEquals("2026-10-12T10:00:00+08:00", response.getGeneratedAt());
|
|
|
- assertEquals(6, response.getFeatures().size());
|
|
|
- assertEquals(6, response.getFeatures().stream().map(Feature::getId).distinct().count());
|
|
|
- assertEquals(Arrays.asList("GAS", "WATER_SUPPLY", "DRAINAGE", "UNKNOWN", "GAS", "MANHOLE"),
|
|
|
+ // 4 条管网线 + 1 个窨井点(燃气管点来源已移除,不再有第 6 个要素)
|
|
|
+ assertEquals(5, response.getFeatures().size());
|
|
|
+ assertEquals(5, response.getFeatures().stream().map(Feature::getId).distinct().count());
|
|
|
+ assertEquals(Arrays.asList("GAS", "WATER_SUPPLY", "DRAINAGE", "UNKNOWN", "MANHOLE"),
|
|
|
response.getFeatures().stream().map(item -> item.getProperties().getIndustry()).collect(Collectors.toList()));
|
|
|
Feature gas = response.getFeatures().get(0);
|
|
|
assertEquals("LineString", gas.getGeometry().getType());
|
|
|
@@ -73,15 +66,12 @@ class CockpitFacilityGeometryServiceTest {
|
|
|
assertEquals("GAS_PIPE", gas.getProperties().getTypeCode());
|
|
|
assertEquals("PIPE_UNCLASSIFIED", response.getFeatures().get(3).getProperties().getTypeCode());
|
|
|
assertEquals("3", response.getFeatures().get(3).getProperties().getNetworkType());
|
|
|
- Feature component = response.getFeatures().get(4);
|
|
|
- assertEquals("Point", component.getGeometry().getType());
|
|
|
- assertEquals("三通", component.getProperties().getPointType());
|
|
|
- assertEquals(gas.getProperties().getNetworkId(), component.getProperties().getNetworkId());
|
|
|
+ // 燃气管点已移除:GAS 的点要素覆盖必须如实标为 UNAVAILABLE(不冒充"这里没有管线")
|
|
|
+ assertEquals("UNAVAILABLE", coverage(response, "GAS", "Point").getState());
|
|
|
assertEquals(1, coverage(response, "UNKNOWN", "LineString").getRecordCount());
|
|
|
verify(networks).list();
|
|
|
- verify(points).list();
|
|
|
verify(manholes).list();
|
|
|
- verifyNoMoreInteractions(networks, points, manholes);
|
|
|
+ verifyNoMoreInteractions(networks, manholes);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
@@ -91,14 +81,11 @@ class CockpitFacilityGeometryServiceTest {
|
|
|
PipeNetworkBase missing = network("missing-diameter", "0");
|
|
|
PipeNetworkBase zero = network("zero-diameter", "0");
|
|
|
zero.setDiameter(BigDecimal.ZERO);
|
|
|
- GasPipePoint point = point(7L, "阀门");
|
|
|
- point.setDiameter(new BigDecimal("125.25"));
|
|
|
ManholeBase well = new ManholeBase();
|
|
|
well.setManholeId("well");
|
|
|
well.setLongitude(new BigDecimal("110.440"));
|
|
|
well.setLatitude(new BigDecimal("28.450"));
|
|
|
when(networks.list()).thenReturn(Arrays.asList(known, missing, zero));
|
|
|
- when(points.list()).thenReturn(Collections.singletonList(point));
|
|
|
when(manholes.list()).thenReturn(Collections.singletonList(well));
|
|
|
com.fasterxml.jackson.databind.JsonNode json = new com.fasterxml.jackson.databind.ObjectMapper()
|
|
|
.valueToTree(service.load());
|
|
|
@@ -108,8 +95,8 @@ class CockpitFacilityGeometryServiceTest {
|
|
|
assertTrue(json.get("features").get(1).get("properties").has("diameter"));
|
|
|
assertTrue(json.get("features").get(1).get("properties").get("diameter").isNull());
|
|
|
assertEquals(0, json.get("features").get(2).get("properties").get("diameter").asInt());
|
|
|
- assertEquals(125.25, json.get("features").get(3).get("properties").get("diameter").asDouble());
|
|
|
- assertTrue(json.get("features").get(4).get("properties").get("diameter").isNull());
|
|
|
+ // 窨井没有管径语义 → 如实为 null(曾经的管点直径来源已移除)
|
|
|
+ assertTrue(json.get("features").get(3).get("properties").get("diameter").isNull());
|
|
|
assertEquals(new BigDecimal("400.50"), known.getDiameter());
|
|
|
assertNull(missing.getDiameter());
|
|
|
verify(networks).list();
|
|
|
@@ -158,19 +145,21 @@ class CockpitFacilityGeometryServiceTest {
|
|
|
verifyNoMoreInteractions(networks);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 燃气管点来源移除后,GAS 的**点**要素不再产出任何构件(维护者 2026-11-16)。
|
|
|
+ *
|
|
|
+ * <p>原用例逐个校验 阀门/调压/三通… 等 pointType 原样透传;来源删掉后这些断言
|
|
|
+ * 已无生产对象可测。保留的契约是:不产要素、且覆盖统计如实说「没有这个来源」。</p>
|
|
|
+ */
|
|
|
@Test
|
|
|
- void preservesEveryComponentTypeIncludingUnknownAndMissingTypesWithoutFabricatingNodes() {
|
|
|
- List<String> types = Arrays.asList("阀门", "调压", "计量", "阴极保护", "弯头", "三通", "其它", "未知原始值", null);
|
|
|
- List<GasPipePoint> records = new java.util.ArrayList<>();
|
|
|
- for (int i = 0; i < types.size(); i++) {
|
|
|
- records.add(point((long) i, types.get(i)));
|
|
|
- }
|
|
|
- when(points.list()).thenReturn(records);
|
|
|
+ void gasPointComponentsAreNotProducedAnymore() {
|
|
|
+ when(networks.list()).thenReturn(Collections.singletonList(network("gas-line", "0")));
|
|
|
CockpitFacilityGeometryResponse response = service.load();
|
|
|
- assertEquals(types, response.getFeatures().stream()
|
|
|
- .map(item -> item.getProperties().getPointType()).collect(Collectors.toList()));
|
|
|
- assertEquals(types.size(), response.getFeatures().size());
|
|
|
- assertTrue(response.getFeatures().stream().allMatch(item -> item.getProperties().getNetworkId() == null));
|
|
|
+ assertTrue(response.getFeatures().stream().noneMatch(item -> "Point".equals(item.getGeometry() == null
|
|
|
+ ? null : item.getGeometry().getType())),
|
|
|
+ "不再产出点要素");
|
|
|
+ assertEquals("UNAVAILABLE", coverage(response, "GAS", "Point").getState());
|
|
|
+ assertEquals("NO_COMPONENT_SOURCE", coverage(response, "GAS", "Point").getReason());
|
|
|
}
|
|
|
|
|
|
@ParameterizedTest
|
|
|
@@ -179,10 +168,11 @@ class CockpitFacilityGeometryServiceTest {
|
|
|
"110.4,-91,LATITUDE_OUT_OF_RANGE", "0,0,ZERO_COORDINATE"})
|
|
|
void invalidPointsStayInTheCollectionWithNullGeometryAndSpecificReason(String longitude, String latitude,
|
|
|
String reason) {
|
|
|
- GasPipePoint point = point(1L, "阀门");
|
|
|
- point.setLongitude(decimal(longitude));
|
|
|
- point.setLatitude(decimal(latitude));
|
|
|
- when(points.list()).thenReturn(Collections.singletonList(point));
|
|
|
+ ManholeBase manhole = new ManholeBase();
|
|
|
+ manhole.setManholeId("invalid-point");
|
|
|
+ manhole.setLongitude(decimal(longitude));
|
|
|
+ manhole.setLatitude(decimal(latitude));
|
|
|
+ when(manholes.list()).thenReturn(Collections.singletonList(manhole));
|
|
|
Feature feature = service.load().getFeatures().get(0);
|
|
|
assertNull(feature.getGeometry());
|
|
|
assertEquals("INVALID", feature.getProperties().getCoordinateValidation().getState());
|
|
|
@@ -216,12 +206,15 @@ class CockpitFacilityGeometryServiceTest {
|
|
|
@Test
|
|
|
void outsidePrimaryAreaIsRejectedWhileInAreaCoordinatesRender() {
|
|
|
when(networks.list()).thenReturn(Collections.singletonList(network("line", "0")));
|
|
|
- when(points.list()).thenReturn(Collections.singletonList(point(1L, "阀门")));
|
|
|
- ManholeBase manhole = new ManholeBase();
|
|
|
- manhole.setManholeId("well");
|
|
|
- manhole.setLongitude(new BigDecimal("-180"));
|
|
|
- manhole.setLatitude(new BigDecimal("90"));
|
|
|
- when(manholes.list()).thenReturn(Collections.singletonList(manhole));
|
|
|
+ ManholeBase inside = new ManholeBase();
|
|
|
+ inside.setManholeId("inside-well");
|
|
|
+ inside.setLongitude(new BigDecimal("110.440"));
|
|
|
+ inside.setLatitude(new BigDecimal("28.450"));
|
|
|
+ ManholeBase outsideWell = new ManholeBase();
|
|
|
+ outsideWell.setManholeId("outside-well");
|
|
|
+ outsideWell.setLongitude(new BigDecimal("-180"));
|
|
|
+ outsideWell.setLatitude(new BigDecimal("90"));
|
|
|
+ when(manholes.list()).thenReturn(Arrays.asList(inside, outsideWell));
|
|
|
|
|
|
CockpitFacilityGeometryResponse response = service.load();
|
|
|
|
|
|
@@ -248,8 +241,8 @@ class CockpitFacilityGeometryServiceTest {
|
|
|
assertTrue(coverage(response, "GAS", "LineString").getRenderableCount() > 0,
|
|
|
"区内线段必须计入可渲染统计");
|
|
|
assertEquals(1, coverage(response, "GAS", "LineString").getRenderableCount());
|
|
|
- assertEquals(1, coverage(response, "GAS", "Point").getRenderableCount());
|
|
|
- assertEquals(0, coverage(response, "MANHOLE", "Point").getRenderableCount());
|
|
|
+ assertEquals(1, coverage(response, "MANHOLE", "Point").getRenderableCount());
|
|
|
+ assertEquals("UNAVAILABLE", coverage(response, "GAS", "Point").getState());
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
@@ -269,10 +262,9 @@ class CockpitFacilityGeometryServiceTest {
|
|
|
@Test
|
|
|
void aFailedSourceNeverProducesAnEmptyOrPartialSuccess() {
|
|
|
when(networks.list()).thenReturn(Collections.singletonList(network("line", "0")));
|
|
|
- when(points.list()).thenThrow(new IllegalStateException("private database detail"));
|
|
|
+ when(manholes.list()).thenThrow(new IllegalStateException("private database detail"));
|
|
|
CockpitReadException failure = assertThrows(CockpitReadException.class, service::load);
|
|
|
assertEquals("facility geometry source unavailable", failure.getMessage());
|
|
|
- verifyNoInteractions(manholes);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
@@ -298,15 +290,6 @@ class CockpitFacilityGeometryServiceTest {
|
|
|
return network;
|
|
|
}
|
|
|
|
|
|
- private static GasPipePoint point(Long id, String type) {
|
|
|
- GasPipePoint point = new GasPipePoint();
|
|
|
- point.setPointId(id);
|
|
|
- point.setPointType(type);
|
|
|
- point.setLongitude(new BigDecimal("110.360"));
|
|
|
- point.setLatitude(new BigDecimal("28.420"));
|
|
|
- return point;
|
|
|
- }
|
|
|
-
|
|
|
private static BigDecimal decimal(String value) {
|
|
|
return value == null ? null : new BigDecimal(value);
|
|
|
}
|