|
|
@@ -0,0 +1,46 @@
|
|
|
+package com.zksy.web.controller.WaterSupply.MonitorAlarm;
|
|
|
+
|
|
|
+import com.zksy.WaterSupply.MonitorAlarm.service.IWaterSupplyThresholdService;
|
|
|
+import com.zksy.base.domain.EquipmentBase;
|
|
|
+import org.junit.jupiter.api.BeforeEach;
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
+import org.springframework.test.util.ReflectionTestUtils;
|
|
|
+import org.springframework.test.web.servlet.MockMvc;
|
|
|
+import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
|
|
+
|
|
|
+import java.util.Arrays;
|
|
|
+
|
|
|
+import static org.mockito.Mockito.mock;
|
|
|
+import static org.mockito.Mockito.when;
|
|
|
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
|
|
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
|
|
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
|
|
+
|
|
|
+class WaterSupplyThresholdControllerTest {
|
|
|
+
|
|
|
+ private IWaterSupplyThresholdService thresholdService;
|
|
|
+ private MockMvc mockMvc;
|
|
|
+
|
|
|
+ @BeforeEach
|
|
|
+ void setUp() {
|
|
|
+ thresholdService = mock(IWaterSupplyThresholdService.class);
|
|
|
+ WaterSupplyThresholdController controller = new WaterSupplyThresholdController();
|
|
|
+ ReflectionTestUtils.setField(controller, "waterSupplyThresholdService", thresholdService);
|
|
|
+ mockMvc = MockMvcBuilders.standaloneSetup(controller).build();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void thresholdDeviceEndpointReturnsOnlyWaterDevices() throws Exception {
|
|
|
+ EquipmentBase flow = new EquipmentBase();
|
|
|
+ flow.setEquipmentCode("CN-GS-202609020001");
|
|
|
+ EquipmentBase pressure = new EquipmentBase();
|
|
|
+ pressure.setEquipmentCode("CB-GS-202609020001");
|
|
|
+ when(thresholdService.findThresholdDevices()).thenReturn(Arrays.asList(flow, pressure));
|
|
|
+
|
|
|
+ mockMvc.perform(get("/waterSupply/alarm/threshold/devices"))
|
|
|
+ .andExpect(status().isOk())
|
|
|
+ .andExpect(jsonPath("$.code").value(200))
|
|
|
+ .andExpect(jsonPath("$.data[0].equipmentCode").value("CN-GS-202609020001"))
|
|
|
+ .andExpect(jsonPath("$.data[1].equipmentCode").value("CB-GS-202609020001"));
|
|
|
+ }
|
|
|
+}
|