|
|
@@ -120,6 +120,27 @@ class CockpitTypeMetricsControllerTest {
|
|
|
.andExpect(jsonPath("$.data.metrics[0].points[0].freshness").value("HISTORICAL"));
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ void historyResponseUsesAdapterTotalForPartialPage() throws Exception {
|
|
|
+ when(adapter.loadHistory(
|
|
|
+ DEVICE_CODE,
|
|
|
+ java.time.OffsetDateTime.parse("2026-09-01T10:00:00+08:00"),
|
|
|
+ java.time.OffsetDateTime.parse("2026-09-02T10:00:00+08:00"),
|
|
|
+ 2,
|
|
|
+ 1)).thenReturn(partialSewageHistoryFixture());
|
|
|
+
|
|
|
+ mockMvc.perform(get("/api/cockpit/v1/equipments/" + DEVICE_CODE + "/metrics/history")
|
|
|
+ .param("startTime", "2026-09-01T10:00:00+08:00")
|
|
|
+ .param("endTime", "2026-09-02T10:00:00+08:00")
|
|
|
+ .param("page", "2")
|
|
|
+ .param("pageSize", "1"))
|
|
|
+ .andExpect(status().isOk())
|
|
|
+ .andExpect(jsonPath("$.data.page").value(2))
|
|
|
+ .andExpect(jsonPath("$.data.total").value(7))
|
|
|
+ .andExpect(jsonPath("$.data.metrics", org.hamcrest.Matchers.hasSize(1)))
|
|
|
+ .andExpect(jsonPath("$.data.metrics[0].points", org.hamcrest.Matchers.hasSize(1)));
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
void historyRejectsInvertedRange() throws Exception {
|
|
|
mockMvc.perform(get("/api/cockpit/v1/equipments/" + DEVICE_CODE + "/metrics/history")
|
|
|
@@ -232,4 +253,20 @@ class CockpitTypeMetricsControllerTest {
|
|
|
sampledAt,
|
|
|
points);
|
|
|
}
|
|
|
+ private CockpitTypeMetricsSnapshot partialSewageHistoryFixture() {
|
|
|
+ return new CockpitTypeMetricsSnapshot(
|
|
|
+ DEVICE_CODE,
|
|
|
+ "ws_sewage_environment",
|
|
|
+ "污水环境监测设备",
|
|
|
+ Collections.singletonList(new CockpitMetricSnapshot(
|
|
|
+ "PH",
|
|
|
+ "pH",
|
|
|
+ null,
|
|
|
+ "",
|
|
|
+ null,
|
|
|
+ null,
|
|
|
+ Collections.singletonList(new CockpitMetricSnapshot.PointSnapshot(
|
|
|
+ new BigDecimal("7.2"), "NORMAL", "2026-09-02T09:59:00+08:00")))),
|
|
|
+ 7);
|
|
|
+ }
|
|
|
}
|