|
@@ -61,6 +61,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
|
|
import static org.mockito.ArgumentMatchers.any;
|
|
import static org.mockito.ArgumentMatchers.any;
|
|
|
import static org.mockito.ArgumentMatchers.anyString;
|
|
import static org.mockito.ArgumentMatchers.anyString;
|
|
|
|
|
+import static org.mockito.ArgumentMatchers.eq;
|
|
|
import static org.mockito.Mockito.*;
|
|
import static org.mockito.Mockito.*;
|
|
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
|
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
|
@@ -139,6 +140,74 @@ class CockpitVideoControllerTest {
|
|
|
SecurityContextHolder.clearContext();
|
|
SecurityContextHolder.clearContext();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private static final String RECORD_QUERY = "/api/gb_record/query";
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void anonymousHistoryListsOnlyRealReturnedRecordingsForTheRequestedWindow() throws Exception {
|
|
|
|
|
+ when(collector.get(RECORD_QUERY, Map.of("deviceId", GB, "channelId", CHANNEL,
|
|
|
|
|
+ "startTime", "2026-11-10 00:00:00", "endTime", "2026-11-10 12:00:00", "type", "all")))
|
|
|
|
|
+ .thenReturn(Map.of("recordList", List.of(Map.of("name", "通道01", "startTime", "2026-11-10 01:00:00",
|
|
|
|
|
+ "endTime", "2026-11-10 02:00:00", "type", "time"))));
|
|
|
|
|
+ mvc.perform(get(ROOT + "/records").param("deviceCode", CODE)
|
|
|
|
|
+ .param("startTime", "2026-11-10 00:00:00").param("endTime", "2026-11-10 12:00:00"))
|
|
|
|
|
+ .andExpect(status().isOk()).andExpect(jsonPath("$.code").value(200))
|
|
|
|
|
+ .andExpect(jsonPath("$.data.deviceCode").value(CODE))
|
|
|
|
|
+ .andExpect(jsonPath("$.data.empty").value(false))
|
|
|
|
|
+ .andExpect(jsonPath("$.data.records[0].name").value("通道01"))
|
|
|
|
|
+ .andExpect(jsonPath("$.data.records[0].startTime").value("2026-11-10 01:00:00"))
|
|
|
|
|
+ .andExpect(jsonPath("$.data.records[0].endTime").value("2026-11-10 02:00:00"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void emptyRecordingWindowIsAnAnswerNotAFailure() throws Exception {
|
|
|
|
|
+ when(collector.get(RECORD_QUERY, Map.of("deviceId", GB, "channelId", CHANNEL,
|
|
|
|
|
+ "startTime", "2026-11-10 00:00:00", "endTime", "2026-11-10 12:00:00", "type", "all")))
|
|
|
|
|
+ .thenReturn(Map.of("recordList", List.of()));
|
|
|
|
|
+ mvc.perform(get(ROOT + "/records").param("deviceCode", CODE)
|
|
|
|
|
+ .param("startTime", "2026-11-10 00:00:00").param("endTime", "2026-11-10 12:00:00"))
|
|
|
|
|
+ .andExpect(status().isOk())
|
|
|
|
|
+ .andExpect(jsonPath("$.data.empty").value(true))
|
|
|
|
|
+ .andExpect(jsonPath("$.data.records").isEmpty());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void recordingRangeOverSevenDaysIsRejectedBeforeTouchingTheDevice() throws Exception {
|
|
|
|
|
+ mvc.perform(get(ROOT + "/records").param("deviceCode", CODE)
|
|
|
|
|
+ .param("startTime", "2026-11-01 00:00:00").param("endTime", "2026-11-10 00:00:00"))
|
|
|
|
|
+ .andExpect(status().isBadRequest())
|
|
|
|
|
+ .andExpect(jsonPath("$.data.category").value("INVALID_REQUEST"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void playbackReusesTheAnonymousSeamAndPublishesOnlyTheReturnedMedia() throws Exception {
|
|
|
|
|
+ when(collector.get(eq("/api/playback/start"), any())).thenReturn(Map.of("stream", "stream_pb", "native", true,
|
|
|
|
|
+ "rtcs", "https://media.invalid/index/api/webrtc?app=rtp&stream=stream_pb&type=play",
|
|
|
|
|
+ "flv", "https://media.invalid/pb.flv", "secret", "internal-secret", "proxyKey", "internal-key"));
|
|
|
|
|
+ mvc.perform(post(ROOT + "/playback").contentType(MediaType.APPLICATION_JSON)
|
|
|
|
|
+ .content(JSON.toJSONString(Map.of("deviceCode", CODE,
|
|
|
|
|
+ "startTime", "2026-11-10 01:00:00", "endTime", "2026-11-10 02:00:00"))))
|
|
|
|
|
+ .andExpect(status().isOk())
|
|
|
|
|
+ .andExpect(jsonPath("$.data.mode").value("PLAYBACK"))
|
|
|
|
|
+ .andExpect(jsonPath("$.data.startTime").value("2026-11-10 01:00:00"))
|
|
|
|
|
+ .andExpect(jsonPath("$.data.sessionToken").isNotEmpty())
|
|
|
|
|
+ .andExpect(jsonPath("$.data.media.webrtc").exists())
|
|
|
|
|
+ .andExpect(content().string(org.hamcrest.Matchers.not(org.hamcrest.Matchers.containsString("internal-key"))));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void aBusyChannelReportsOccupancyInsteadOfStoppingTheExistingPlayback() throws Exception {
|
|
|
|
|
+ // The single-active-playback rule is enforced by the reused session store, not by the media adapter.
|
|
|
|
|
+ when(sessions.selectCount(any())).thenReturn(1L);
|
|
|
|
|
+ mvc.perform(post(ROOT + "/playback").contentType(MediaType.APPLICATION_JSON)
|
|
|
|
|
+ .content(JSON.toJSONString(Map.of("deviceCode", CODE,
|
|
|
|
|
+ "startTime", "2026-11-10 01:00:00", "endTime", "2026-11-10 02:00:00"))))
|
|
|
|
|
+ .andExpect(status().isConflict())
|
|
|
|
|
+ .andExpect(jsonPath("$.data.category").value("PLAYBACK_OCCUPIED"));
|
|
|
|
|
+ // Never stop somebody else's playback just because this request lost the race.
|
|
|
|
|
+ verify(collector, never()).get(STOP, Map.of());
|
|
|
|
|
+ verify(collector, never()).get(eq("/api/playback/start"), any());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Test
|
|
@Test
|
|
|
void anonymousDeviceLookupKeepsExactBusinessCodeAndPublishesOnlyConfirmedLiveCapability() throws Exception {
|
|
void anonymousDeviceLookupKeepsExactBusinessCodeAndPublishesOnlyConfirmedLiveCapability() throws Exception {
|
|
|
mvc.perform(get(ROOT + "/device").param("deviceCode", CODE).header("X-Request-Id", "video-lookup-1"))
|
|
mvc.perform(get(ROOT + "/device").param("deviceCode", CODE).header("X-Request-Id", "video-lookup-1"))
|
|
@@ -148,8 +217,9 @@ class CockpitVideoControllerTest {
|
|
|
.andExpect(jsonPath("$.data.typeCode").value("20"))
|
|
.andExpect(jsonPath("$.data.typeCode").value("20"))
|
|
|
.andExpect(jsonPath("$.data.bound").value(true))
|
|
.andExpect(jsonPath("$.data.bound").value(true))
|
|
|
.andExpect(jsonPath("$.data.capabilities.live").value(true))
|
|
.andExpect(jsonPath("$.data.capabilities.live").value(true))
|
|
|
- .andExpect(jsonPath("$.data.capabilities.records").value(false))
|
|
|
|
|
- .andExpect(jsonPath("$.data.capabilities.playback").value(false))
|
|
|
|
|
|
|
+ // Records and playback follow the GB28181 binding; control stays grey until a real device confirms it.
|
|
|
|
|
+ .andExpect(jsonPath("$.data.capabilities.records").value(true))
|
|
|
|
|
+ .andExpect(jsonPath("$.data.capabilities.playback").value(true))
|
|
|
.andExpect(jsonPath("$.data.capabilities.playbackControl").value(false))
|
|
.andExpect(jsonPath("$.data.capabilities.playbackControl").value(false))
|
|
|
.andExpect(jsonPath("$.data.capabilities.ptz").value(false))
|
|
.andExpect(jsonPath("$.data.capabilities.ptz").value(false))
|
|
|
.andExpect(jsonPath("$.data.capabilities.ptzStopGuaranteed").value(false))
|
|
.andExpect(jsonPath("$.data.capabilities.ptzStopGuaranteed").value(false))
|
|
@@ -197,10 +267,10 @@ class CockpitVideoControllerTest {
|
|
|
|
|
|
|
|
@ParameterizedTest
|
|
@ParameterizedTest
|
|
|
@CsvSource({"GET,/live", "GET,/sessions/example/stop", "GET,/sessions/example/heartbeat",
|
|
@CsvSource({"GET,/live", "GET,/sessions/example/stop", "GET,/sessions/example/heartbeat",
|
|
|
- "GET,/devices/remove", "GET,/records", "POST,/device", "PUT,/live", "DELETE,/live",
|
|
|
|
|
- "POST,/sessions/example/control", "POST,/ptz", "POST,/playback", "POST,/devices",
|
|
|
|
|
|
|
+ "GET,/devices/remove", "GET,/record", "POST,/device", "PUT,/live", "DELETE,/live",
|
|
|
|
|
+ "POST,/sessions/example/control", "POST,/ptz", "POST,/playback/control", "POST,/devices",
|
|
|
"POST,/sessions/example/nested/stop", "POST,/live/nested"})
|
|
"POST,/sessions/example/nested/stop", "POST,/live/nested"})
|
|
|
- void onlyTheFourPublishedMethodAndPathPairsAreAnonymous(String method, String path) throws Exception {
|
|
|
|
|
|
|
+ void onlyTheSixPublishedMethodAndPathPairsAreAnonymous(String method, String path) throws Exception {
|
|
|
mvc.perform(request(org.springframework.http.HttpMethod.valueOf(method), ROOT + path))
|
|
mvc.perform(request(org.springframework.http.HttpMethod.valueOf(method), ROOT + path))
|
|
|
.andExpect(status().isUnauthorized()).andExpect(jsonPath("$.code").value(401));
|
|
.andExpect(status().isUnauthorized()).andExpect(jsonPath("$.code").value(401));
|
|
|
verifyNoInteractions(devices, bindings, sessions, collector);
|
|
verifyNoInteractions(devices, bindings, sessions, collector);
|