From 3070392ecd5548632d774287b19ba9df1d6b3b8c Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 4 Feb 2023 07:50:36 +0800 Subject: [PATCH] =?UTF-8?q?infra=EF=BC=9A=E5=AE=8C=E5=96=84=20file=20?= =?UTF-8?q?=E7=9A=84=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../infra/service/file/FileConfigService.java | 10 -------- .../service/file/FileConfigServiceImpl.java | 14 +++-------- .../infra/service/file/FileServiceImpl.java | 2 +- .../infra/service/job/JobServiceImpl.java | 8 +++--- ...ceTest.java => ConfigServiceImplTest.java} | 2 +- .../file/FileConfigServiceImplTest.java | 25 +++++++++++++++++++ ...viceTest.java => FileServiceImplTest.java} | 2 +- 7 files changed, 36 insertions(+), 27 deletions(-) rename yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/config/{ConfigServiceTest.java => ConfigServiceImplTest.java} (99%) rename yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/file/{FileServiceTest.java => FileServiceImplTest.java} (98%) diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileConfigService.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileConfigService.java index b3fc6bad2..43ab5bc68 100755 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileConfigService.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileConfigService.java @@ -8,8 +8,6 @@ import cn.iocoder.yudao.module.infra.controller.admin.file.vo.config.FileConfigU import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileConfigDO; import javax.validation.Valid; -import java.util.Collection; -import java.util.List; /** * 文件配置 Service 接口 @@ -60,14 +58,6 @@ public interface FileConfigService { */ FileConfigDO getFileConfig(Long id); - /** - * 获得文件配置列表 - * - * @param ids 编号 - * @return 文件配置列表 - */ - List getFileConfigList(Collection ids); - /** * 获得文件配置分页 * diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileConfigServiceImpl.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileConfigServiceImpl.java index 590ff8116..6236df6ff 100755 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileConfigServiceImpl.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileConfigServiceImpl.java @@ -27,7 +27,6 @@ import org.springframework.validation.annotation.Validated; import javax.annotation.PostConstruct; import javax.annotation.Resource; import javax.validation.Validator; -import java.util.Collection; import java.util.List; import java.util.Map; @@ -95,7 +94,7 @@ public class FileConfigServiceImpl implements FileConfigService { @Override public void updateFileConfig(FileConfigUpdateReqVO updateReqVO) { // 校验存在 - FileConfigDO config = this.validateFileConfigExists(updateReqVO.getId()); + FileConfigDO config = validateFileConfigExists(updateReqVO.getId()); // 更新 FileConfigDO updateObj = FileConfigConvert.INSTANCE.convert(updateReqVO) .setConfig(parseClientConfig(config.getStorage(), updateReqVO.getConfig())); @@ -108,7 +107,7 @@ public class FileConfigServiceImpl implements FileConfigService { @Transactional(rollbackFor = Exception.class) public void updateFileConfigMaster(Long id) { // 校验存在 - this.validateFileConfigExists(id); + validateFileConfigExists(id); // 更新其它为非 master fileConfigMapper.updateBatch(new FileConfigDO().setMaster(false)); // 更新 @@ -138,7 +137,7 @@ public class FileConfigServiceImpl implements FileConfigService { @Override public void deleteFileConfig(Long id) { // 校验存在 - FileConfigDO config = this.validateFileConfigExists(id); + FileConfigDO config = validateFileConfigExists(id); if (Boolean.TRUE.equals(config.getMaster())) { throw exception(FILE_CONFIG_DELETE_FAIL_MASTER); } @@ -161,11 +160,6 @@ public class FileConfigServiceImpl implements FileConfigService { return fileConfigMapper.selectById(id); } - @Override - public List getFileConfigList(Collection ids) { - return fileConfigMapper.selectBatchIds(ids); - } - @Override public PageResult getFileConfigPage(FileConfigPageReqVO pageReqVO) { return fileConfigMapper.selectPage(pageReqVO); @@ -174,7 +168,7 @@ public class FileConfigServiceImpl implements FileConfigService { @Override public String testFileConfig(Long id) throws Exception { // 校验存在 - this.validateFileConfigExists(id); + validateFileConfigExists(id); // 上传文件 byte[] content = ResourceUtil.readBytes("file/erweima.jpg"); return fileClientFactory.getFileClient(id).upload(content, IdUtil.fastSimpleUUID() + ".jpg", "image/jpeg"); diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileServiceImpl.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileServiceImpl.java index 2226e7bae..0732765d8 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileServiceImpl.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileServiceImpl.java @@ -69,7 +69,7 @@ public class FileServiceImpl implements FileService { @Override public void deleteFile(Long id) throws Exception { // 校验存在 - FileDO file = this.validateFileExists(id); + FileDO file = validateFileExists(id); // 从文件存储器中删除 FileClient client = fileConfigService.getFileClient(file.getConfigId()); diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobServiceImpl.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobServiceImpl.java index e0a245750..498d816b8 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobServiceImpl.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobServiceImpl.java @@ -69,7 +69,7 @@ public class JobServiceImpl implements JobService { public void updateJob(JobUpdateReqVO updateReqVO) throws SchedulerException { validateCronExpression(updateReqVO.getCronExpression()); // 校验存在 - JobDO job = this.validateJobExists(updateReqVO.getId()); + JobDO job = validateJobExists(updateReqVO.getId()); // 只有开启状态,才可以修改.原因是,如果出暂停状态,修改 Quartz Job 时,会导致任务又开始执行 if (!job.getStatus().equals(JobStatusEnum.NORMAL.getStatus())) { throw exception(JOB_UPDATE_ONLY_NORMAL_STATUS); @@ -92,7 +92,7 @@ public class JobServiceImpl implements JobService { throw exception(JOB_CHANGE_STATUS_INVALID); } // 校验存在 - JobDO job = this.validateJobExists(id); + JobDO job = validateJobExists(id); // 校验是否已经为当前状态 if (job.getStatus().equals(status)) { throw exception(JOB_CHANGE_STATUS_EQUALS); @@ -112,7 +112,7 @@ public class JobServiceImpl implements JobService { @Override public void triggerJob(Long id) throws SchedulerException { // 校验存在 - JobDO job = this.validateJobExists(id); + JobDO job = validateJobExists(id); // 触发 Quartz 中的 Job schedulerManager.triggerJob(job.getId(), job.getHandlerName(), job.getHandlerParam()); @@ -122,7 +122,7 @@ public class JobServiceImpl implements JobService { @Transactional(rollbackFor = Exception.class) public void deleteJob(Long id) throws SchedulerException { // 校验存在 - JobDO job = this.validateJobExists(id); + JobDO job = validateJobExists(id); // 更新 jobMapper.deleteById(id); diff --git a/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/config/ConfigServiceTest.java b/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/config/ConfigServiceImplTest.java similarity index 99% rename from yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/config/ConfigServiceTest.java rename to yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/config/ConfigServiceImplTest.java index 00ebae9f9..428b20522 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/config/ConfigServiceTest.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/config/ConfigServiceImplTest.java @@ -29,7 +29,7 @@ import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*; import static org.junit.jupiter.api.Assertions.*; @Import(ConfigServiceImpl.class) -public class ConfigServiceTest extends BaseDbUnitTest { +public class ConfigServiceImplTest extends BaseDbUnitTest { @Resource private ConfigServiceImpl configService; diff --git a/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/file/FileConfigServiceImplTest.java b/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/file/FileConfigServiceImplTest.java index 61c9827f6..656955194 100755 --- a/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/file/FileConfigServiceImplTest.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/file/FileConfigServiceImplTest.java @@ -7,6 +7,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.file.core.client.FileClient; import cn.iocoder.yudao.framework.file.core.client.FileClientConfig; import cn.iocoder.yudao.framework.file.core.client.FileClientFactory; +import cn.iocoder.yudao.framework.file.core.client.local.LocalFileClient; import cn.iocoder.yudao.framework.file.core.client.local.LocalFileClientConfig; import cn.iocoder.yudao.framework.file.core.enums.FileStorageEnum; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; @@ -242,6 +243,30 @@ public class FileConfigServiceImplTest extends BaseDbUnitTest { assertEquals("https://www.iocoder.cn", fileConfigService.testFileConfig(id)); } + @Test + public void testGetFileConfig() { + // mock 数据 + FileConfigDO dbFileConfig = randomFileConfigDO().setMaster(false); + fileConfigMapper.insert(dbFileConfig);// @Sql: 先插入出一条存在的数据 + // 准备参数 + Long id = dbFileConfig.getId(); + + // 调用,并断言 + assertPojoEquals(dbFileConfig, fileConfigService.getFileConfig(id)); + } + + @Test + public void testGetFileClient() { + // 准备参数 + Long id = randomLongId(); + // mock 获得 Client + FileClient fileClient = new LocalFileClient(id, new LocalFileClientConfig()); + when(fileClientFactory.getFileClient(eq(id))).thenReturn(fileClient); + + // 调用,并断言 + assertSame(fileClient, fileConfigService.getFileClient(id)); + } + private FileConfigDO randomFileConfigDO() { return randomPojo(FileConfigDO.class).setStorage(randomEle(FileStorageEnum.values()).getStorage()) .setConfig(new EmptyFileClientConfig()); diff --git a/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/file/FileServiceTest.java b/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/file/FileServiceImplTest.java similarity index 98% rename from yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/file/FileServiceTest.java rename to yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/file/FileServiceImplTest.java index 90bde8f4e..57cc4c476 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/file/FileServiceTest.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/file/FileServiceImplTest.java @@ -26,7 +26,7 @@ import static org.mockito.ArgumentMatchers.same; import static org.mockito.Mockito.*; @Import({FileServiceImpl.class}) -public class FileServiceTest extends BaseDbUnitTest { +public class FileServiceImplTest extends BaseDbUnitTest { @Resource private FileService fileService;