|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+package com.ruoyi.web.modules.video.service;
|
|
|
2
|
+
|
|
|
3
|
+import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
4
|
+import static org.junit.jupiter.api.Assertions.assertNull;
|
|
|
5
|
+import static org.mockito.ArgumentMatchers.any;
|
|
|
6
|
+import static org.mockito.Mockito.verify;
|
|
|
7
|
+import static org.mockito.Mockito.when;
|
|
|
8
|
+
|
|
|
9
|
+import java.util.Date;
|
|
|
10
|
+import org.junit.jupiter.api.DisplayName;
|
|
|
11
|
+import org.junit.jupiter.api.Test;
|
|
|
12
|
+import org.junit.jupiter.api.extension.ExtendWith;
|
|
|
13
|
+import org.mockito.ArgumentCaptor;
|
|
|
14
|
+import org.mockito.InjectMocks;
|
|
|
15
|
+import org.mockito.Mock;
|
|
|
16
|
+import org.mockito.junit.jupiter.MockitoExtension;
|
|
|
17
|
+import com.ruoyi.web.modules.industryservice.domain.BizPasture;
|
|
|
18
|
+import com.ruoyi.web.modules.industryservice.mapper.BizPastureMapper;
|
|
|
19
|
+import com.ruoyi.web.modules.video.domain.BizLivestockMonitor;
|
|
|
20
|
+import com.ruoyi.web.modules.video.domain.dto.OpenCameraDto;
|
|
|
21
|
+import com.ruoyi.web.modules.video.mapper.BizLivestockMonitorMapper;
|
|
|
22
|
+import com.ruoyi.web.modules.video.support.LivestockMonitorRules;
|
|
|
23
|
+
|
|
|
24
|
+@ExtendWith(MockitoExtension.class)
|
|
|
25
|
+@DisplayName("畜牧监控同步落库")
|
|
|
26
|
+class LivestockMonitorSyncTxServiceTest
|
|
|
27
|
+{
|
|
|
28
|
+ @Mock
|
|
|
29
|
+ private BizLivestockMonitorMapper bizLivestockMonitorMapper;
|
|
|
30
|
+
|
|
|
31
|
+ @Mock
|
|
|
32
|
+ private BizPastureMapper bizPastureMapper;
|
|
|
33
|
+
|
|
|
34
|
+ @InjectMocks
|
|
|
35
|
+ private LivestockMonitorSyncTxService livestockMonitorSyncTxService;
|
|
|
36
|
+
|
|
|
37
|
+ @Test
|
|
|
38
|
+ @DisplayName("farmName 匹配牧场时写入 owner_type=1 与 owner_id")
|
|
|
39
|
+ void persistCameraResolvesPastureOwner()
|
|
|
40
|
+ {
|
|
|
41
|
+ OpenCameraDto dto = new OpenCameraDto();
|
|
|
42
|
+ dto.setCameraId(50001L);
|
|
|
43
|
+ dto.setDeviceName("1号圈舍监控");
|
|
|
44
|
+ dto.setFarmName("示范牧场");
|
|
|
45
|
+ dto.setVideoSource("wvp");
|
|
|
46
|
+ when(bizLivestockMonitorMapper.selectBizLivestockMonitorByMonitorId("50001")).thenReturn(null);
|
|
|
47
|
+ BizPasture pasture = new BizPasture();
|
|
|
48
|
+ pasture.setId(101L);
|
|
|
49
|
+ pasture.setPastureName("示范牧场");
|
|
|
50
|
+ when(bizPastureMapper.selectBizPastureByExactName("示范牧场")).thenReturn(pasture);
|
|
|
51
|
+ when(bizLivestockMonitorMapper.insertBizLivestockMonitor(any())).thenReturn(1);
|
|
|
52
|
+
|
|
|
53
|
+ boolean inserted = livestockMonitorSyncTxService.persistCamera(dto, new Date(), "admin");
|
|
|
54
|
+ assertEquals(true, inserted);
|
|
|
55
|
+
|
|
|
56
|
+ ArgumentCaptor<BizLivestockMonitor> captor = ArgumentCaptor.forClass(BizLivestockMonitor.class);
|
|
|
57
|
+ verify(bizLivestockMonitorMapper).insertBizLivestockMonitor(captor.capture());
|
|
|
58
|
+ BizLivestockMonitor row = captor.getValue();
|
|
|
59
|
+ assertEquals(LivestockMonitorRules.OWNER_TYPE_PASTURE, row.getOwnerType());
|
|
|
60
|
+ assertEquals(101L, row.getOwnerId());
|
|
|
61
|
+ assertEquals("示范牧场", row.getOwnerName());
|
|
|
62
|
+ }
|
|
|
63
|
+
|
|
|
64
|
+ @Test
|
|
|
65
|
+ @DisplayName("farmName 未匹配牧场时仅保留 owner_name 文本")
|
|
|
66
|
+ void persistCameraFarmNameWithoutPasture()
|
|
|
67
|
+ {
|
|
|
68
|
+ OpenCameraDto dto = new OpenCameraDto();
|
|
|
69
|
+ dto.setCameraId(50002L);
|
|
|
70
|
+ dto.setDeviceName("入口监控");
|
|
|
71
|
+ dto.setFarmName("未知牧场");
|
|
|
72
|
+ dto.setVideoSource("ys7");
|
|
|
73
|
+ when(bizLivestockMonitorMapper.selectBizLivestockMonitorByMonitorId("50002")).thenReturn(null);
|
|
|
74
|
+ when(bizPastureMapper.selectBizPastureByExactName("未知牧场")).thenReturn(null);
|
|
|
75
|
+ when(bizLivestockMonitorMapper.insertBizLivestockMonitor(any())).thenReturn(1);
|
|
|
76
|
+
|
|
|
77
|
+ livestockMonitorSyncTxService.persistCamera(dto, new Date(), "admin");
|
|
|
78
|
+
|
|
|
79
|
+ ArgumentCaptor<BizLivestockMonitor> captor = ArgumentCaptor.forClass(BizLivestockMonitor.class);
|
|
|
80
|
+ verify(bizLivestockMonitorMapper).insertBizLivestockMonitor(captor.capture());
|
|
|
81
|
+ BizLivestockMonitor row = captor.getValue();
|
|
|
82
|
+ assertNull(row.getOwnerType());
|
|
|
83
|
+ assertNull(row.getOwnerId());
|
|
|
84
|
+ assertEquals("未知牧场", row.getOwnerName());
|
|
|
85
|
+ }
|
|
|
86
|
+}
|