|
|
@@ -0,0 +1,133 @@
|
|
|
+package com.zksy.WaterSupply.WaterSupplyGisMap;
|
|
|
+
|
|
|
+import com.zksy.WaterSupply.WaterPlantInfo.domain.WaterPlantInfo;
|
|
|
+import com.zksy.WaterSupply.WaterPlantInfo.service.IWaterPlantInfoService;
|
|
|
+import com.zksy.WaterSupply.WaterSupplyGisMap.dto.GisOverviewItemDTO;
|
|
|
+import com.zksy.WaterSupply.WaterSupplyGisMap.dto.GisFeatureCollectionDTO;
|
|
|
+import com.zksy.WaterSupply.WaterSupplyGisMap.mapper.WaterSupplyGisMapMapper;
|
|
|
+import com.zksy.WaterSupply.WaterSupplyGisMap.service.impl.WaterSupplyGisMapServiceImpl;
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
+import org.junit.jupiter.api.extension.ExtendWith;
|
|
|
+import org.mockito.InjectMocks;
|
|
|
+import org.mockito.Mock;
|
|
|
+import org.mockito.junit.jupiter.MockitoExtension;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
+import static org.junit.jupiter.api.Assertions.assertSame;
|
|
|
+import static org.mockito.Mockito.never;
|
|
|
+import static org.mockito.Mockito.verify;
|
|
|
+import static org.mockito.Mockito.when;
|
|
|
+
|
|
|
+@ExtendWith(MockitoExtension.class)
|
|
|
+class WaterSupplyGisMapServiceTest {
|
|
|
+
|
|
|
+ @Mock
|
|
|
+ private WaterSupplyGisMapMapper mapper;
|
|
|
+
|
|
|
+ @Mock
|
|
|
+ private IWaterPlantInfoService plantService;
|
|
|
+
|
|
|
+ @InjectMocks
|
|
|
+ private WaterSupplyGisMapServiceImpl service;
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void overviewStillDescribesAllFacilityTypesWhenNoCoordinatesHaveBeenLoaded() {
|
|
|
+ when(mapper.selectOverview()).thenReturn(Collections.emptyList());
|
|
|
+
|
|
|
+ List<GisOverviewItemDTO> overview = service.getOverview();
|
|
|
+
|
|
|
+ assertEquals(List.of("source", "plant", "pumpStation", "pipe", "user", "total"),
|
|
|
+ overview.stream().map(GisOverviewItemDTO::getFacilityType).collect(Collectors.toList()));
|
|
|
+ overview.forEach(item -> {
|
|
|
+ assertEquals(0L, item.getTotalCount());
|
|
|
+ assertEquals(0L, item.getGeoCompleteCount());
|
|
|
+ assertEquals(0L, item.getGeoMissingCount());
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void pointLayerOmitsRowsWithoutBothCoordinatesAndKeepsLongitudeFirst() {
|
|
|
+ Map<String, Object> complete = pointRow(1L, "完整水厂");
|
|
|
+ Map<String, Object> missingLatitude = pointRow(2L, "缺纬度水厂");
|
|
|
+ missingLatitude.put("latitude", null);
|
|
|
+ when(mapper.selectPlantFeatures()).thenReturn(List.of(complete, missingLatitude));
|
|
|
+
|
|
|
+ GisFeatureCollectionDTO features = service.getFeatures(Set.of("plant"));
|
|
|
+
|
|
|
+ assertEquals(1, features.getFeatures().size());
|
|
|
+ assertEquals("Point", features.getFeatures().get(0).getGeometry().get("type"));
|
|
|
+ assertEquals(List.of(new BigDecimal("113.12345678"), new BigDecimal("23.12345678")),
|
|
|
+ features.getFeatures().get(0).getGeometry().get("coordinates"));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void pipeLayerOmitsRowsWithoutFourCoordinatesAndKeepsEndpointOrder() {
|
|
|
+ Map<String, Object> complete = pipeRow(1L, "完整管线");
|
|
|
+ Map<String, Object> missingEndpoint = pipeRow(2L, "缺终点纬度管线");
|
|
|
+ missingEndpoint.put("end_latitude", null);
|
|
|
+ when(mapper.selectPipeFeatures()).thenReturn(List.of(complete, missingEndpoint));
|
|
|
+
|
|
|
+ GisFeatureCollectionDTO features = service.getFeatures(Set.of("pipe"));
|
|
|
+
|
|
|
+ assertEquals(1, features.getFeatures().size());
|
|
|
+ assertEquals("LineString", features.getFeatures().get(0).getGeometry().get("type"));
|
|
|
+ assertEquals(List.of(
|
|
|
+ List.of(new BigDecimal("113.10000000"), new BigDecimal("23.10000000")),
|
|
|
+ List.of(new BigDecimal("113.20000000"), new BigDecimal("23.20000000"))),
|
|
|
+ features.getFeatures().get(0).getGeometry().get("coordinates"));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void requestedFacilityTypesDoNotLoadUnselectedLayers() {
|
|
|
+ when(mapper.selectPlantFeatures()).thenReturn(Collections.emptyList());
|
|
|
+
|
|
|
+ service.getFeatures(Set.of("plant"));
|
|
|
+
|
|
|
+ verify(mapper).selectPlantFeatures();
|
|
|
+ verify(mapper, never()).selectSourceFeatures();
|
|
|
+ verify(mapper, never()).selectPumpStationFeatures();
|
|
|
+ verify(mapper, never()).selectPipeFeatures();
|
|
|
+ verify(mapper, never()).selectUserFeatures();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void detailReturnsTheExistingFacilityEvenWhenItHasNoCoordinates() {
|
|
|
+ WaterPlantInfo plant = new WaterPlantInfo();
|
|
|
+ plant.setId(9L);
|
|
|
+ plant.setPlantName("待补坐标水厂");
|
|
|
+ when(plantService.getById(9L)).thenReturn(plant);
|
|
|
+
|
|
|
+ Object detail = service.getDetail("plant", 9L);
|
|
|
+
|
|
|
+ assertSame(plant, detail);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, Object> pointRow(Long id, String name) {
|
|
|
+ Map<String, Object> row = new HashMap<>();
|
|
|
+ row.put("id", id);
|
|
|
+ row.put("code", "WP" + id);
|
|
|
+ row.put("name", name);
|
|
|
+ row.put("status", "0");
|
|
|
+ row.put("location", "测试地址");
|
|
|
+ row.put("longitude", new BigDecimal("113.12345678"));
|
|
|
+ row.put("latitude", new BigDecimal("23.12345678"));
|
|
|
+ return row;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, Object> pipeRow(Long id, String name) {
|
|
|
+ Map<String, Object> row = pointRow(id, name);
|
|
|
+ row.put("start_longitude", new BigDecimal("113.10000000"));
|
|
|
+ row.put("start_latitude", new BigDecimal("23.10000000"));
|
|
|
+ row.put("end_longitude", new BigDecimal("113.20000000"));
|
|
|
+ row.put("end_latitude", new BigDecimal("23.20000000"));
|
|
|
+ return row;
|
|
|
+ }
|
|
|
+}
|