|
|
@@ -38,7 +38,7 @@ class LivestockMonitorSyncServiceTest
|
|
38
|
38
|
void syncDisabled()
|
|
39
|
39
|
{
|
|
40
|
40
|
when(thirdPartyCameraClient.fetchAllCameras()).thenThrow(new ServiceException("第三方监控同步未启用"));
|
|
41
|
|
- assertThrows(ServiceException.class, () -> livestockMonitorSyncService.syncFromThirdParty());
|
|
|
41
|
+ assertThrows(ServiceException.class, () -> livestockMonitorSyncService.syncFromThirdParty("tester"));
|
|
42
|
42
|
}
|
|
43
|
43
|
|
|
44
|
44
|
@Test
|
|
|
@@ -46,7 +46,7 @@ class LivestockMonitorSyncServiceTest
|
|
46
|
46
|
void syncEmpty()
|
|
47
|
47
|
{
|
|
48
|
48
|
when(thirdPartyCameraClient.fetchAllCameras()).thenReturn(Collections.emptyList());
|
|
49
|
|
- YakAssetSyncResultVo result = livestockMonitorSyncService.syncFromThirdParty();
|
|
|
49
|
+ YakAssetSyncResultVo result = livestockMonitorSyncService.syncFromThirdParty("tester");
|
|
50
|
50
|
assertNotNull(result.getSyncTime());
|
|
51
|
51
|
assertEquals(0, result.getInsertCount());
|
|
52
|
52
|
}
|
|
|
@@ -64,8 +64,8 @@ class LivestockMonitorSyncServiceTest
|
|
64
|
64
|
camera2.setDeviceName("监控2");
|
|
65
|
65
|
camera2.setVideoSource("ys7");
|
|
66
|
66
|
when(thirdPartyCameraClient.fetchAllCameras()).thenReturn(Arrays.asList(camera1, camera2));
|
|
67
|
|
- when(livestockMonitorSyncTxService.persistCamera(any(), any())).thenReturn(true, false);
|
|
68
|
|
- YakAssetSyncResultVo result = livestockMonitorSyncService.syncFromThirdParty();
|
|
|
67
|
+ when(livestockMonitorSyncTxService.persistCamera(any(), any(), any())).thenReturn(true, false);
|
|
|
68
|
+ YakAssetSyncResultVo result = livestockMonitorSyncService.syncFromThirdParty("tester");
|
|
69
|
69
|
assertEquals(1, result.getInsertCount());
|
|
70
|
70
|
assertEquals(1, result.getUpdateCount());
|
|
71
|
71
|
assertEquals(0, result.getFailCount());
|
|
|
@@ -80,9 +80,9 @@ class LivestockMonitorSyncServiceTest
|
|
80
|
80
|
camera.setDeviceName("监控1");
|
|
81
|
81
|
camera.setVideoSource("wvp");
|
|
82
|
82
|
when(thirdPartyCameraClient.fetchAllCameras()).thenReturn(Collections.singletonList(camera));
|
|
83
|
|
- when(livestockMonitorSyncTxService.persistCamera(any(), any()))
|
|
|
83
|
+ when(livestockMonitorSyncTxService.persistCamera(any(), any(), any()))
|
|
84
|
84
|
.thenThrow(new ServiceException("视频来源不能为空"));
|
|
85
|
|
- YakAssetSyncResultVo result = livestockMonitorSyncService.syncFromThirdParty();
|
|
|
85
|
+ YakAssetSyncResultVo result = livestockMonitorSyncService.syncFromThirdParty("tester");
|
|
86
|
86
|
assertEquals(1, result.getFailCount());
|
|
87
|
87
|
assertEquals(1, result.getFailMessages().size());
|
|
88
|
88
|
}
|
|
|
@@ -96,14 +96,14 @@ class LivestockMonitorSyncServiceTest
|
|
96
|
96
|
camera.setDeviceName("监控1");
|
|
97
|
97
|
camera.setVideoSource("wvp");
|
|
98
|
98
|
when(thirdPartyCameraClient.fetchAllCameras()).thenReturn(Collections.singletonList(camera));
|
|
99
|
|
- when(livestockMonitorSyncTxService.persistCamera(any(), any())).thenAnswer(invocation -> {
|
|
|
99
|
+ when(livestockMonitorSyncTxService.persistCamera(any(), any(), any())).thenAnswer(invocation -> {
|
|
100
|
100
|
Thread.sleep(200);
|
|
101
|
101
|
return true;
|
|
102
|
102
|
});
|
|
103
|
|
- Thread t1 = new Thread(() -> livestockMonitorSyncService.syncFromThirdParty());
|
|
|
103
|
+ Thread t1 = new Thread(() -> livestockMonitorSyncService.syncFromThirdParty("tester"));
|
|
104
|
104
|
t1.start();
|
|
105
|
105
|
Thread.sleep(50);
|
|
106
|
|
- ServiceException ex = assertThrows(ServiceException.class, () -> livestockMonitorSyncService.syncFromThirdParty());
|
|
|
106
|
+ ServiceException ex = assertThrows(ServiceException.class, () -> livestockMonitorSyncService.syncFromThirdParty("tester2"));
|
|
107
|
107
|
assertEquals(LivestockMonitorSyncRules.MSG_SYNC_IN_PROGRESS, ex.getMessage());
|
|
108
|
108
|
t1.join();
|
|
109
|
109
|
}
|