|
@@ -8,6 +8,7 @@ import org.springframework.test.web.servlet.MockMvc;
|
|
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
import java.util.Arrays;
|
|
|
|
|
+import java.util.Collections;
|
|
|
|
|
|
|
|
import static org.mockito.Mockito.*;
|
|
import static org.mockito.Mockito.*;
|
|
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
|
@@ -19,6 +20,14 @@ class CockpitDictControllerTest {
|
|
|
|
|
|
|
|
@BeforeEach void setup() { mvc = MockMvcBuilders.standaloneSetup(new CockpitDictController(dictTypeService)).setControllerAdvice(new CockpitExceptionAdvice()).build(); }
|
|
@BeforeEach void setup() { mvc = MockMvcBuilders.standaloneSetup(new CockpitDictController(dictTypeService)).setControllerAdvice(new CockpitExceptionAdvice()).build(); }
|
|
|
|
|
|
|
|
|
|
+ private void stubPublished(String dictType, String dictValue, String dictLabel) {
|
|
|
|
|
+ SysDictData row = new SysDictData();
|
|
|
|
|
+ row.setDictType(dictType);
|
|
|
|
|
+ row.setDictValue(dictValue);
|
|
|
|
|
+ row.setDictLabel(dictLabel);
|
|
|
|
|
+ when(dictTypeService.selectDictDataByType(dictType)).thenReturn(Collections.singletonList(row));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Test void exposesPumpStationTypeDictionaryUnderCockpitDomain() throws Exception {
|
|
@Test void exposesPumpStationTypeDictionaryUnderCockpitDomain() throws Exception {
|
|
|
SysDictData supply = new SysDictData(); supply.setDictType("pump_station_type"); supply.setDictValue("0"); supply.setDictLabel("供水泵站");
|
|
SysDictData supply = new SysDictData(); supply.setDictType("pump_station_type"); supply.setDictValue("0"); supply.setDictLabel("供水泵站");
|
|
|
SysDictData drainage = new SysDictData(); drainage.setDictType("pump_station_type"); drainage.setDictValue("1"); drainage.setDictLabel("排水泵站");
|
|
SysDictData drainage = new SysDictData(); drainage.setDictType("pump_station_type"); drainage.setDictValue("1"); drainage.setDictLabel("排水泵站");
|
|
@@ -32,6 +41,33 @@ class CockpitDictControllerTest {
|
|
|
verify(dictTypeService).selectDictDataByType("pump_station_type");
|
|
verify(dictTypeService).selectDictDataByType("pump_station_type");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Test void exposesRiskAndHazardDictionariesUsedByDetailPanels() throws Exception {
|
|
|
|
|
+ String[][] samples = {
|
|
|
|
|
+ {"risk_level", "0", "重大风险"},
|
|
|
|
|
+ {"risk_color", "0", "红"},
|
|
|
|
|
+ {"hazard_type", "0", "腐蚀"},
|
|
|
|
|
+ {"hazard_level", "1", "一级隐患"},
|
|
|
|
|
+ {"hazard_source", "0", "巡检"},
|
|
|
|
|
+ {"hazard_status", "0", "整改中"},
|
|
|
|
|
+ };
|
|
|
|
|
+ for (String[] sample : samples) {
|
|
|
|
|
+ stubPublished(sample[0], sample[1], sample[2]);
|
|
|
|
|
+ mvc.perform(get("/api/cockpit/v1/dict/" + sample[0]))
|
|
|
|
|
+ .andExpect(status().isOk())
|
|
|
|
|
+ .andExpect(jsonPath("$.code").value(200))
|
|
|
|
|
+ .andExpect(jsonPath("$.data.length()").value(1))
|
|
|
|
|
+ .andExpect(jsonPath("$.data[0].dictValue").value(sample[1]))
|
|
|
|
|
+ .andExpect(jsonPath("$.data[0].dictLabel").value(sample[2]));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test void dictionaryOutsideCockpitContractIsNotRead() throws Exception {
|
|
|
|
|
+ mvc.perform(get("/api/cockpit/v1/dict/equipment_type"))
|
|
|
|
|
+ .andExpect(status().isOk())
|
|
|
|
|
+ .andExpect(jsonPath("$.data.length()").value(0));
|
|
|
|
|
+ verifyNoInteractions(dictTypeService);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Test void missingDictionaryIsEmptyNotError() throws Exception {
|
|
@Test void missingDictionaryIsEmptyNotError() throws Exception {
|
|
|
when(dictTypeService.selectDictDataByType("unknown_type")).thenReturn(null);
|
|
when(dictTypeService.selectDictDataByType("unknown_type")).thenReturn(null);
|
|
|
mvc.perform(get("/api/cockpit/v1/dict/unknown_type"))
|
|
mvc.perform(get("/api/cockpit/v1/dict/unknown_type"))
|