OCT REM: 1. 修正测试用例错误

This commit is contained in:
HuangXin 2025-04-17 11:46:47 +08:00
parent 819c112d41
commit 2cbacee29e
1 changed files with 11 additions and 0 deletions

View File

@ -341,6 +341,7 @@ public class HostAgentManagerServiceImplTest {
public void downloadScriptFiles_OssUrl_Success() {
RemoteShellContext ctx = new RemoteShellContext(workDir, "http://oss/file.sh", "file.sh", null, null);
when(commonConfigure.getDataRootDirectory()).thenReturn(workDir);
helperUtils.when(() -> HelperUtils.stringNotEmptyOrNull(anyString())).thenReturn(true);
when(ossFactory.getOssService()).thenReturn(ossService);
doNothing().when(ossService).download(any(URL.class), any(File.class));
@ -354,6 +355,7 @@ public class HostAgentManagerServiceImplTest {
public void downloadScriptFiles_NonOssUrl_Success() {
RemoteShellContext ctx = new RemoteShellContext(workDir, "http://non-oss/file.sh", "file.sh", null, null);
when(commonConfigure.getDataRootDirectory()).thenReturn(workDir);
helperUtils.when(() -> HelperUtils.stringNotEmptyOrNull(anyString())).thenReturn(true);
try (MockedConstruction<FileDownloader> mocked = mockConstruction(FileDownloader.class,
(mock, context) -> doNothing().when(mock).downloadFile())
@ -368,6 +370,7 @@ public class HostAgentManagerServiceImplTest {
public void downloadScriptFiles_WithChecksum_Success() {
RemoteShellContext ctx = new RemoteShellContext(workDir, "http://oss/file.sh", "file.sh", "checksum", null);
when(commonConfigure.getDataRootDirectory()).thenReturn(workDir);
helperUtils.when(() -> HelperUtils.stringNotEmptyOrNull(anyString())).thenReturn(true);
when(ossFactory.getOssService()).thenReturn(ossService);
doNothing().when(ossService).download(any(URL.class), any(File.class));
@ -382,6 +385,7 @@ public class HostAgentManagerServiceImplTest {
public void downloadScriptFiles_WithChecksum_Failure() {
RemoteShellContext ctx = new RemoteShellContext(workDir, "http://oss/file.sh", "file.sh", "checksum", null);
when(commonConfigure.getDataRootDirectory()).thenReturn(workDir);
helperUtils.when(() -> HelperUtils.stringNotEmptyOrNull(anyString())).thenReturn(true);
when(ossFactory.getOssService()).thenReturn(ossService);
doNothing().when(ossService).download(any(URL.class), any(File.class));
@ -396,6 +400,7 @@ public class HostAgentManagerServiceImplTest {
public void downloadScriptFiles_IOException() {
RemoteShellContext ctx = new RemoteShellContext(workDir, "http://oss/file.sh", "file.sh", null, null);
when(commonConfigure.getDataRootDirectory()).thenReturn(workDir);
when(ossFactory.getOssService()).thenReturn(ossService);
doThrow(new SdkClientException("file.sh")).when(ossService).download(any(URL.class), any(File.class));
@ -408,6 +413,7 @@ public class HostAgentManagerServiceImplTest {
public void downloadScriptFiles_OtherException() {
RemoteShellContext ctx = new RemoteShellContext(workDir, "http://oss/file.sh", "file.sh", null, null);
when(commonConfigure.getDataRootDirectory()).thenReturn(workDir);
when(ossFactory.getOssService()).thenReturn(ossService);
doThrow(new RuntimeException()).when(ossService).download(any(URL.class), any(File.class));
@ -420,6 +426,7 @@ public class HostAgentManagerServiceImplTest {
public void downloadRemoteFile_OssUrl_Success() {
RemoteFileContext context = new RemoteFileContext(workDir, "http://oss/file.txt", "file.txt", null);
when(commonConfigure.getDataRootDirectory()).thenReturn(workDir);
helperUtils.when(() -> HelperUtils.stringNotEmptyOrNull(anyString())).thenReturn(true);
when(ossFactory.getOssService()).thenReturn(ossService);
doNothing().when(ossService).download(any(URL.class), any(File.class));
@ -433,6 +440,7 @@ public class HostAgentManagerServiceImplTest {
public void downloadRemoteFile_NonOssUrl_Success() {
RemoteFileContext ctx = new RemoteFileContext(workDir, "http://non-oss/file.txt", "file.txt", null);
when(commonConfigure.getDataRootDirectory()).thenReturn(workDir);
helperUtils.when(() -> HelperUtils.stringNotEmptyOrNull(anyString())).thenReturn(true);
try (MockedConstruction<FileDownloader> mocked = mockConstruction(FileDownloader.class,
(mock, context) -> doNothing().when(mock).downloadFile())
@ -447,6 +455,7 @@ public class HostAgentManagerServiceImplTest {
public void downloadRemoteFile_ChecksumMatch_Success() {
RemoteFileContext context = new RemoteFileContext(workDir, "http://oss/file.txt", "file.txt", "checksum");
when(commonConfigure.getDataRootDirectory()).thenReturn(workDir);
when(ossFactory.getOssService()).thenReturn(ossService);
doNothing().when(ossService).download(any(URL.class), any(File.class));
cryptoHelper.when(() -> CryptoHelper.md5FileEncryption(anyString())).thenReturn("checksum");
@ -461,6 +470,7 @@ public class HostAgentManagerServiceImplTest {
public void downloadRemoteFile_ChecksumMismatch_Failure() {
RemoteFileContext context = new RemoteFileContext(workDir, "http://oss/file.txt", "file.txt", "checksum");
when(commonConfigure.getDataRootDirectory()).thenReturn(workDir);
when(ossFactory.getOssService()).thenReturn(ossService);
helperUtils.when(() -> HelperUtils.stringNotEmptyOrNull(anyString())).thenReturn(true);
doNothing().when(ossService).download(any(URL.class), any(File.class));
@ -476,6 +486,7 @@ public class HostAgentManagerServiceImplTest {
public void downloadRemoteFile_OtherException_Failure() {
RemoteFileContext context = new RemoteFileContext(workDir, "http://oss/file.txt", "file.txt", null);
when(commonConfigure.getDataRootDirectory()).thenReturn(workDir);
when(ossFactory.getOssService()).thenReturn(ossService);
doThrow(new RuntimeException("Unexpected error")).when(ossService).download(any(URL.class), any(File.class));