|
@@ -0,0 +1,53 @@
|
|
|
|
|
+package com.zksy.web.controller.WaterSupply.WaterSupplyGisMap;
|
|
|
|
|
+
|
|
|
|
|
+import com.zksy.WaterSupply.WaterSupplyGisMap.service.WaterSupplyGisMapService;
|
|
|
|
|
+import com.zksy.common.core.domain.AjaxResult;
|
|
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
|
|
+import org.springframework.test.util.ReflectionTestUtils;
|
|
|
|
|
+
|
|
|
|
|
+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;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+
|
|
|
|
|
+class WaterSupplyGisMapControllerTest {
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void missingFacilityDetailUsesTheExistingFacilitySpecificWarning() {
|
|
|
|
|
+ WaterSupplyGisMapService service = mock(WaterSupplyGisMapService.class);
|
|
|
|
|
+ WaterSupplyGisMapController controller = controllerWith(service);
|
|
|
|
|
+
|
|
|
|
|
+ for (Map.Entry<String, String> expected : Map.of(
|
|
|
|
|
+ "source", "未找到该水源地信息",
|
|
|
|
|
+ "plant", "未找到该水厂信息",
|
|
|
|
|
+ "pumpStation", "未找到该泵站信息",
|
|
|
|
|
+ "pipe", "未找到该管网信息",
|
|
|
|
|
+ "user", "未找到该用水户信息").entrySet()) {
|
|
|
|
|
+ when(service.getDetail(expected.getKey(), 1L)).thenReturn(null);
|
|
|
|
|
+ AjaxResult result = controller.detail(expected.getKey(), 1L);
|
|
|
|
|
+
|
|
|
|
|
+ assertEquals(601, result.get(AjaxResult.CODE_TAG));
|
|
|
|
|
+ assertTrue(result.get(AjaxResult.MSG_TAG).toString().contains(expected.getValue()));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void detailQueryFailureUsesTheExistingExplainableError() {
|
|
|
|
|
+ WaterSupplyGisMapService service = mock(WaterSupplyGisMapService.class);
|
|
|
|
|
+ when(service.getDetail("plant", 2L)).thenThrow(new IllegalStateException("数据库暂不可用"));
|
|
|
|
|
+ WaterSupplyGisMapController controller = controllerWith(service);
|
|
|
|
|
+
|
|
|
|
|
+ AjaxResult result = controller.detail("plant", 2L);
|
|
|
|
|
+
|
|
|
|
|
+ assertEquals(500, result.get(AjaxResult.CODE_TAG));
|
|
|
|
|
+ assertEquals("查询失败:数据库暂不可用", result.get(AjaxResult.MSG_TAG));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static WaterSupplyGisMapController controllerWith(WaterSupplyGisMapService service) {
|
|
|
|
|
+ WaterSupplyGisMapController controller = new WaterSupplyGisMapController();
|
|
|
|
|
+ ReflectionTestUtils.setField(controller, "gisMapService", service);
|
|
|
|
|
+ return controller;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|