|
@@ -24,8 +24,10 @@ import org.junit.jupiter.api.BeforeEach;
|
|
|
import org.junit.jupiter.api.Test;
|
|
import org.junit.jupiter.api.Test;
|
|
|
import org.apache.ibatis.builder.MapperBuilderAssistant;
|
|
import org.apache.ibatis.builder.MapperBuilderAssistant;
|
|
|
import org.springframework.test.util.ReflectionTestUtils;
|
|
import org.springframework.test.util.ReflectionTestUtils;
|
|
|
|
|
+import org.mockito.invocation.InvocationOnMock;
|
|
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
|
|
+import java.util.Objects;
|
|
|
import java.util.Collection;
|
|
import java.util.Collection;
|
|
|
import java.util.Arrays;
|
|
import java.util.Arrays;
|
|
|
import java.util.Collections;
|
|
import java.util.Collections;
|
|
@@ -114,6 +116,28 @@ class MonitoringServiceImplTest {
|
|
|
assertEquals(BASE_TIME.minusHours(1), row.getMonitorTime());
|
|
assertEquals(BASE_TIME.minusHours(1), row.getMonitorTime());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void flowPaginationUsesTheNewestQualifyingMeasurementAcrossDataSources() {
|
|
|
|
|
+ when(equipmentBaseMapper.selectList(any())).thenReturn(Collections.singletonList(
|
|
|
|
|
+ device("flow-1", "WS-FLOW-1", "流量监测点1", "flow-type", BASE_TIME)
|
|
|
|
|
+ ));
|
|
|
|
|
+ when(radarDataMapper.selectList(any())).thenReturn(Collections.singletonList(
|
|
|
|
|
+ radar("WS-FLOW-1", "30", BASE_TIME.minusHours(2))
|
|
|
|
|
+ ));
|
|
|
|
|
+ when(telemetryDataMapper.selectList(any())).thenReturn(Collections.singletonList(
|
|
|
|
|
+ telemetry("WS-FLOW-1", "35", BASE_TIME.minusHours(1))
|
|
|
|
|
+ ));
|
|
|
|
|
+
|
|
|
|
|
+ Page<FlowMonitoringVO> page = service.getFlowMonitorPage(
|
|
|
|
|
+ 1, 10, null, null, null, null, null, 20D, 40D);
|
|
|
|
|
+
|
|
|
|
|
+ assertEquals(1, page.getTotal());
|
|
|
|
|
+ FlowMonitoringVO row = page.getRecords().get(0);
|
|
|
|
|
+ assertEquals("遥测终端", row.getDataSource());
|
|
|
|
|
+ assertEquals("35", row.getInstantFlow());
|
|
|
|
|
+ assertEquals(BASE_TIME.minusHours(1), row.getMonitorTime());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Test
|
|
@Test
|
|
|
void pressurePaginationTotalsFollowMeasurementFiltering() {
|
|
void pressurePaginationTotalsFollowMeasurementFiltering() {
|
|
|
when(equipmentBaseMapper.selectList(any())).thenReturn(Arrays.asList(
|
|
when(equipmentBaseMapper.selectList(any())).thenReturn(Arrays.asList(
|
|
@@ -291,6 +315,27 @@ class MonitoringServiceImplTest {
|
|
|
assertEquals("20", trend.get(1).get("instantFlow"));
|
|
assertEquals("20", trend.get(1).get("instantFlow"));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void trendQueriesWithOnlyAnEndTimeDoNotBindNullStartTime() {
|
|
|
|
|
+ EquipmentBase flowDevice = device("flow-1", "WS-FLOW-1", "流量监测点1", "flow-type", BASE_TIME);
|
|
|
|
|
+ EquipmentBase pressureDevice = device("pressure-1", "WS-PR-1", "压力监测点1", "pressure-type", BASE_TIME);
|
|
|
|
|
+ EquipmentBase leakageDevice = device("leakage-1", "WS-LK-1", "漏失监测点1", "leakage-type", BASE_TIME);
|
|
|
|
|
+ when(equipmentBaseMapper.selectById("flow-1")).thenReturn(flowDevice);
|
|
|
|
|
+ when(equipmentBaseMapper.selectById("pressure-1")).thenReturn(pressureDevice);
|
|
|
|
|
+ when(equipmentBaseMapper.selectById("leakage-1")).thenReturn(leakageDevice);
|
|
|
|
|
+
|
|
|
|
|
+ when(radarDataMapper.selectList(any())).thenAnswer(invocation -> recordsWithoutNullBounds(
|
|
|
|
|
+ invocation, Collections.singletonList(radar("WS-FLOW-1", "10", BASE_TIME.minusDays(3)))));
|
|
|
|
|
+ when(pressureMapper.selectList(any())).thenAnswer(invocation -> recordsWithoutNullBounds(
|
|
|
|
|
+ invocation, Collections.singletonList(pressure("WS-PR-1", 0.2D, BASE_TIME.minusDays(3)))));
|
|
|
|
|
+ when(noiseMapper.selectList(any())).thenAnswer(invocation -> recordsWithoutNullBounds(
|
|
|
|
|
+ invocation, Collections.singletonList(noise("WS-LK-1", 2D, BASE_TIME.minusDays(3)))));
|
|
|
|
|
+
|
|
|
|
|
+ assertEquals(1, service.getFlowTrend("flow-1", null, BASE_TIME).size());
|
|
|
|
|
+ assertEquals(1, service.getPressureTrend("pressure-1", null, BASE_TIME).size());
|
|
|
|
|
+ assertEquals(1, service.getLeakageTrend("leakage-1", null, BASE_TIME).size());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Test
|
|
@Test
|
|
|
void requestedPageBeyondMeasurementResultsKeepsTheFilteredTotal() {
|
|
void requestedPageBeyondMeasurementResultsKeepsTheFilteredTotal() {
|
|
|
when(equipmentBaseMapper.selectList(any())).thenReturn(Collections.singletonList(
|
|
when(equipmentBaseMapper.selectList(any())).thenReturn(Collections.singletonList(
|
|
@@ -326,6 +371,14 @@ class MonitoringServiceImplTest {
|
|
|
return values;
|
|
return values;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private static <T> List<T> recordsWithoutNullBounds(InvocationOnMock invocation, List<T> records) {
|
|
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
|
|
+ LambdaQueryWrapper<T> wrapper = invocation.getArgument(0);
|
|
|
|
|
+ assertTrue(wrapper.getParamNameValuePairs().values().stream().noneMatch(Objects::isNull),
|
|
|
|
|
+ "trend query must not bind a null start time");
|
|
|
|
|
+ return records;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private static EquipmentType type(String id, String typeId, String name, String parentTypeId) {
|
|
private static EquipmentType type(String id, String typeId, String name, String parentTypeId) {
|
|
|
EquipmentType type = new EquipmentType();
|
|
EquipmentType type = new EquipmentType();
|
|
|
type.setId(id);
|
|
type.setId(id);
|
|
@@ -355,6 +408,15 @@ class MonitoringServiceImplTest {
|
|
|
return data;
|
|
return data;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private static TelemetryData telemetry(String code, String flow, LocalDateTime time) {
|
|
|
|
|
+ TelemetryData data = new TelemetryData();
|
|
|
|
|
+ data.setDeviceCode(code);
|
|
|
|
|
+ data.setMeter1InstantFlow(flow);
|
|
|
|
|
+ data.setFlowSpeed("1.1");
|
|
|
|
|
+ data.setCreateTime(time);
|
|
|
|
|
+ return data;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private static FirefightingPressure pressure(String code, Double value, LocalDateTime time) {
|
|
private static FirefightingPressure pressure(String code, Double value, LocalDateTime time) {
|
|
|
FirefightingPressure data = new FirefightingPressure();
|
|
FirefightingPressure data = new FirefightingPressure();
|
|
|
data.setTelemeteringStation(code);
|
|
data.setTelemeteringStation(code);
|