Commit dea8883f8243b5bd2d67c5213c9b9ac76a24d9dc

Authored by YunaiV
1 parent 555310de

【代码评审】IoT:插件管理相关的逻辑

Showing 12 changed files with 39 additions and 354 deletions
yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/plugin/IotPluginDeployTypeEnum.java
@@ -13,7 +13,7 @@ import java.util.Arrays; @@ -13,7 +13,7 @@ import java.util.Arrays;
13 @Getter 13 @Getter
14 public enum IotPluginDeployTypeEnum implements IntArrayValuable { 14 public enum IotPluginDeployTypeEnum implements IntArrayValuable {
15 15
16 - UPLOAD(0, "上传jar"), 16 + UPLOAD(0, "上传 jar"), // TODO @haohao:UPLOAD 和 ALONE 感觉有点冲突,前者是部署方式,后者是运行方式。这个后续再讨论下哈
17 ALONE(1, "独立运行"); 17 ALONE(1, "独立运行");
18 18
19 public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(IotPluginDeployTypeEnum::getDeployType).toArray(); 19 public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(IotPluginDeployTypeEnum::getDeployType).toArray();
yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/plugin/IotPluginStatusEnum.java
@@ -42,6 +42,11 @@ public enum IotPluginStatusEnum implements IntArrayValuable { @@ -42,6 +42,11 @@ public enum IotPluginStatusEnum implements IntArrayValuable {
42 return null; 42 return null;
43 } 43 }
44 44
  45 + @Override
  46 + public int[] array() {
  47 + return ARRAYS;
  48 + }
  49 +
45 public static boolean isValidState(Integer state) { 50 public static boolean isValidState(Integer state) {
46 return fromState(state) != null; 51 return fromState(state) != null;
47 } 52 }
@@ -50,8 +55,4 @@ public enum IotPluginStatusEnum implements IntArrayValuable { @@ -50,8 +55,4 @@ public enum IotPluginStatusEnum implements IntArrayValuable {
50 return Arrays.stream(values()).anyMatch(e -> e.getStatus().equals(status)); 55 return Arrays.stream(values()).anyMatch(e -> e.getStatus().equals(status));
51 } 56 }
52 57
53 - @Override  
54 - public int[] array() {  
55 - return new int[0];  
56 - }  
57 } 58 }
yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/plugin/IotPluginTypeEnum.java
1 package cn.iocoder.yudao.module.iot.enums.plugin; 1 package cn.iocoder.yudao.module.iot.enums.plugin;
2 2
3 import cn.iocoder.yudao.framework.common.core.IntArrayValuable; 3 import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
  4 +import lombok.AllArgsConstructor;
4 import lombok.Getter; 5 import lombok.Getter;
5 6
6 import java.util.Arrays; 7 import java.util.Arrays;
@@ -10,6 +11,7 @@ import java.util.Arrays; @@ -10,6 +11,7 @@ import java.util.Arrays;
10 * 11 *
11 * @author haohao 12 * @author haohao
12 */ 13 */
  14 +@AllArgsConstructor
13 @Getter 15 @Getter
14 public enum IotPluginTypeEnum implements IntArrayValuable { 16 public enum IotPluginTypeEnum implements IntArrayValuable {
15 17
@@ -28,11 +30,12 @@ public enum IotPluginTypeEnum implements IntArrayValuable { @@ -28,11 +30,12 @@ public enum IotPluginTypeEnum implements IntArrayValuable {
28 */ 30 */
29 private final String name; 31 private final String name;
30 32
31 - IotPluginTypeEnum(Integer type, String name) {  
32 - this.type = type;  
33 - this.name = name; 33 + @Override
  34 + public int[] array() {
  35 + return ARRAYS;
34 } 36 }
35 37
  38 + // TODO @haohao:可以使用 hutool 简化
36 public static IotPluginTypeEnum fromType(Integer type) { 39 public static IotPluginTypeEnum fromType(Integer type) {
37 for (IotPluginTypeEnum value : values()) { 40 for (IotPluginTypeEnum value : values()) {
38 if (value.getType().equals(type)) { 41 if (value.getType().equals(type)) {
@@ -46,8 +49,4 @@ public enum IotPluginTypeEnum implements IntArrayValuable { @@ -46,8 +49,4 @@ public enum IotPluginTypeEnum implements IntArrayValuable {
46 return fromType(type) != null; 49 return fromType(type) != null;
47 } 50 }
48 51
49 - @Override  
50 - public int[] array() {  
51 - return ARRAYS;  
52 - }  
53 } 52 }
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugininfo/PluginInfoController.java
@@ -20,7 +20,6 @@ import org.springframework.web.multipart.MultipartFile; @@ -20,7 +20,6 @@ import org.springframework.web.multipart.MultipartFile;
20 20
21 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; 21 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
22 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; 22 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
23 -import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;  
24 import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.FILE_IS_EMPTY; 23 import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.FILE_IS_EMPTY;
25 24
26 @Tag(name = "管理后台 - IoT 插件信息") 25 @Tag(name = "管理后台 - IoT 插件信息")
@@ -86,7 +85,6 @@ public class PluginInfoController { @@ -86,7 +85,6 @@ public class PluginInfoController {
86 return success(true); 85 return success(true);
87 } 86 }
88 87
89 - // 修改插件状态  
90 @PutMapping("/update-status") 88 @PutMapping("/update-status")
91 @Operation(summary = "修改插件状态") 89 @Operation(summary = "修改插件状态")
92 @PreAuthorize("@ss.hasPermission('iot:plugin-info:update')") 90 @PreAuthorize("@ss.hasPermission('iot:plugin-info:update')")
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugininfo/vo/PluginInfoPageReqVO.java
1 package cn.iocoder.yudao.module.iot.controller.admin.plugininfo.vo; 1 package cn.iocoder.yudao.module.iot.controller.admin.plugininfo.vo;
2 2
  3 +import cn.iocoder.yudao.framework.common.validation.InEnum;
  4 +import cn.iocoder.yudao.module.iot.enums.plugin.IotPluginTypeEnum;
3 import lombok.*; 5 import lombok.*;
4 import io.swagger.v3.oas.annotations.media.Schema; 6 import io.swagger.v3.oas.annotations.media.Schema;
5 import cn.iocoder.yudao.framework.common.pojo.PageParam; 7 import cn.iocoder.yudao.framework.common.pojo.PageParam;
@@ -8,13 +10,12 @@ import java.time.LocalDateTime; @@ -8,13 +10,12 @@ import java.time.LocalDateTime;
8 10
9 import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; 11 import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
10 12
  13 +// TODO @haohao:只查询必要字段哈
11 @Schema(description = "管理后台 - IoT 插件信息分页 Request VO") 14 @Schema(description = "管理后台 - IoT 插件信息分页 Request VO")
12 @Data 15 @Data
13 -@EqualsAndHashCode(callSuper = true)  
14 -@ToString(callSuper = true)  
15 public class PluginInfoPageReqVO extends PageParam { 16 public class PluginInfoPageReqVO extends PageParam {
16 17
17 - @Schema(description = "插件包id", example = "24627") 18 + @Schema(description = "插件包 ID ", example = "24627")
18 private String pluginId; 19 private String pluginId;
19 20
20 @Schema(description = "插件名称", example = "赵六") 21 @Schema(description = "插件名称", example = "赵六")
@@ -33,6 +34,7 @@ public class PluginInfoPageReqVO extends PageParam { @@ -33,6 +34,7 @@ public class PluginInfoPageReqVO extends PageParam {
33 private String version; 34 private String version;
34 35
35 @Schema(description = "插件类型", example = "2") 36 @Schema(description = "插件类型", example = "2")
  37 + @InEnum(IotPluginTypeEnum.class)
36 private Integer type; 38 private Integer type;
37 39
38 @Schema(description = "设备插件协议类型") 40 @Schema(description = "设备插件协议类型")
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugininfo/vo/PluginInfoRespVO.java
1 package cn.iocoder.yudao.module.iot.controller.admin.plugininfo.vo; 1 package cn.iocoder.yudao.module.iot.controller.admin.plugininfo.vo;
2 2
  3 +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
  4 +import com.alibaba.excel.annotation.ExcelProperty;
3 import io.swagger.v3.oas.annotations.media.Schema; 5 import io.swagger.v3.oas.annotations.media.Schema;
4 -import lombok.*; 6 +import lombok.Data;
5 7
6 import java.time.LocalDateTime; 8 import java.time.LocalDateTime;
7 -import com.alibaba.excel.annotation.*;  
8 9
9 @Schema(description = "管理后台 - IoT 插件信息 Response VO") 10 @Schema(description = "管理后台 - IoT 插件信息 Response VO")
10 @Data 11 @Data
11 @ExcelIgnoreUnannotated 12 @ExcelIgnoreUnannotated
12 public class PluginInfoRespVO { 13 public class PluginInfoRespVO {
13 14
14 - @Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "11546")  
15 - @ExcelProperty("主键ID") 15 + @Schema(description = "主键 ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "11546")
  16 + @ExcelProperty("主键 ID")
16 private Long id; 17 private Long id;
17 18
18 - @Schema(description = "插件包id", requiredMode = Schema.RequiredMode.REQUIRED, example = "24627")  
19 - @ExcelProperty("插件包id") 19 + @Schema(description = "插件包 ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "24627")
  20 + @ExcelProperty("插件包 ID")
20 private String pluginId; 21 private String pluginId;
21 22
22 @Schema(description = "插件名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六") 23 @Schema(description = "插件名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugininstance/vo/PluginInstancePageReqVO.java
@@ -8,6 +8,7 @@ import java.time.LocalDateTime; @@ -8,6 +8,7 @@ import java.time.LocalDateTime;
8 8
9 import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; 9 import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
10 10
  11 +// TODO @haohao:建议搞个 plugin,然后里面分 info 和 instance。另外,是不是 info => config 会好点,插件配置?
11 @Schema(description = "管理后台 - IoT 插件实例分页 Request VO") 12 @Schema(description = "管理后台 - IoT 插件实例分页 Request VO")
12 @Data 13 @Data
13 @EqualsAndHashCode(callSuper = true) 14 @EqualsAndHashCode(callSuper = true)
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/plugininfo/PluginInfoDO.java
@@ -22,12 +22,13 @@ import lombok.*; @@ -22,12 +22,13 @@ import lombok.*;
22 public class PluginInfoDO extends BaseDO { 22 public class PluginInfoDO extends BaseDO {
23 23
24 /** 24 /**
25 - * 主键ID 25 + * 主键 ID
26 */ 26 */
27 @TableId 27 @TableId
28 private Long id; 28 private Long id;
  29 + // TODO @haohao:这个是不是改成类似 key 之类的字段哈?
29 /** 30 /**
30 - * 插件包id 31 + * 插件包 ID
31 */ 32 */
32 private String pluginId; 33 private String pluginId;
33 /** 34 /**
@@ -41,10 +42,12 @@ public class PluginInfoDO extends BaseDO { @@ -41,10 +42,12 @@ public class PluginInfoDO extends BaseDO {
41 /** 42 /**
42 * 部署方式 43 * 部署方式
43 */ 44 */
  45 + // TODO @haohao:枚举
44 private Integer deployType; 46 private Integer deployType;
45 /** 47 /**
46 * 插件包文件名 48 * 插件包文件名
47 */ 49 */
  50 + // TODO @haohao:是不是叫 fileName 哈?避免后续有别的字段,类似 fileUrl?
48 private String file; 51 private String file;
49 /** 52 /**
50 * 插件版本 53 * 插件版本
@@ -53,6 +56,7 @@ public class PluginInfoDO extends BaseDO { @@ -53,6 +56,7 @@ public class PluginInfoDO extends BaseDO {
53 /** 56 /**
54 * 插件类型 57 * 插件类型
55 */ 58 */
  59 + // TODO @haohao:枚举
56 private Integer type; 60 private Integer type;
57 /** 61 /**
58 * 设备插件协议类型 62 * 设备插件协议类型
@@ -61,6 +65,7 @@ public class PluginInfoDO extends BaseDO { @@ -61,6 +65,7 @@ public class PluginInfoDO extends BaseDO {
61 /** 65 /**
62 * 状态 66 * 状态
63 */ 67 */
  68 + // TODO @haohao:枚举
64 private Integer status; 69 private Integer status;
65 /** 70 /**
66 * 插件配置项描述信息 71 * 插件配置项描述信息
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/plugininstance/PluginInstanceDO.java
1 package cn.iocoder.yudao.module.iot.dal.dataobject.plugininstance; 1 package cn.iocoder.yudao.module.iot.dal.dataobject.plugininstance;
2 2
3 -import lombok.*;  
4 -import java.util.*;  
5 -import java.time.LocalDateTime;  
6 -import java.time.LocalDateTime;  
7 -import com.baomidou.mybatisplus.annotation.*;  
8 import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; 3 import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
  4 +import com.baomidou.mybatisplus.annotation.KeySequence;
  5 +import com.baomidou.mybatisplus.annotation.TableId;
  6 +import com.baomidou.mybatisplus.annotation.TableName;
  7 +import lombok.*;
9 8
  9 +// TODO @haohao:一些必要的关联、枚举
10 /** 10 /**
11 * IoT 插件实例 DO 11 * IoT 插件实例 DO
12 * 12 *
@@ -28,7 +28,7 @@ public class PluginInstanceDO extends BaseDO { @@ -28,7 +28,7 @@ public class PluginInstanceDO extends BaseDO {
28 @TableId 28 @TableId
29 private Long id; 29 private Long id;
30 /** 30 /**
31 - * 插件主程序id 31 + * 插件主程序 ID
32 */ 32 */
33 private String mainId; 33 private String mainId;
34 /** 34 /**
@@ -44,7 +44,7 @@ public class PluginInstanceDO extends BaseDO { @@ -44,7 +44,7 @@ public class PluginInstanceDO extends BaseDO {
44 */ 44 */
45 private Integer port; 45 private Integer port;
46 /** 46 /**
47 - * 心跳时间,心路时间超过30秒需要剔除 47 + * 心跳时间,心路时间超过 30 秒需要剔除
48 */ 48 */
49 private Long heartbeatAt; 49 private Long heartbeatAt;
50 50
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceDataService.java
@@ -15,7 +15,6 @@ import java.util.Map; @@ -15,7 +15,6 @@ import java.util.Map;
15 */ 15 */
16 public interface IotDeviceDataService { 16 public interface IotDeviceDataService {
17 17
18 -  
19 /** 18 /**
20 * 保存设备数据 19 * 保存设备数据
21 * 20 *
yudao-module-iot/yudao-module-iot-biz/src/test/java/cn/iocoder/yudao/module/iot/service/plugininfo/PluginInfoServiceImplTest.java deleted
1 -package cn.iocoder.yudao.module.iot.service.plugininfo;  
2 -  
3 -import org.junit.jupiter.api.Disabled;  
4 -import org.junit.jupiter.api.Test;  
5 -  
6 -import jakarta.annotation.Resource;  
7 -  
8 -import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;  
9 -  
10 -import cn.iocoder.yudao.module.iot.controller.admin.plugininfo.vo.*;  
11 -import cn.iocoder.yudao.module.iot.dal.dataobject.plugininfo.PluginInfoDO;  
12 -import cn.iocoder.yudao.module.iot.dal.mysql.plugininfo.PluginInfoMapper;  
13 -import cn.iocoder.yudao.framework.common.pojo.PageResult;  
14 -  
15 -import org.springframework.context.annotation.Import;  
16 -  
17 -import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*;  
18 -import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;  
19 -import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;  
20 -import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*;  
21 -import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;  
22 -import static org.junit.jupiter.api.Assertions.*;  
23 -  
24 -/**  
25 - * {@link PluginInfoServiceImpl} 的单元测试类  
26 - *  
27 - * @author 芋道源码  
28 - */  
29 -@Import(PluginInfoServiceImpl.class)  
30 -public class PluginInfoServiceImplTest extends BaseDbUnitTest {  
31 -  
32 - @Resource  
33 - private PluginInfoServiceImpl pluginInfoService;  
34 -  
35 - @Resource  
36 - private PluginInfoMapper pluginInfoMapper;  
37 -  
38 - @Test  
39 - public void testCreatePluginInfo_success() {  
40 - // 准备参数  
41 - PluginInfoSaveReqVO createReqVO = randomPojo(PluginInfoSaveReqVO.class).setId(null);  
42 -  
43 - // 调用  
44 - Long pluginInfoId = pluginInfoService.createPluginInfo(createReqVO);  
45 - // 断言  
46 - assertNotNull(pluginInfoId);  
47 - // 校验记录的属性是否正确  
48 - PluginInfoDO pluginInfo = pluginInfoMapper.selectById(pluginInfoId);  
49 - assertPojoEquals(createReqVO, pluginInfo, "id");  
50 - }  
51 -  
52 - @Test  
53 - public void testUpdatePluginInfo_success() {  
54 - // mock 数据  
55 - PluginInfoDO dbPluginInfo = randomPojo(PluginInfoDO.class);  
56 - pluginInfoMapper.insert(dbPluginInfo);// @Sql: 先插入出一条存在的数据  
57 - // 准备参数  
58 - PluginInfoSaveReqVO updateReqVO = randomPojo(PluginInfoSaveReqVO.class, o -> {  
59 - o.setId(dbPluginInfo.getId()); // 设置更新的 ID  
60 - });  
61 -  
62 - // 调用  
63 - pluginInfoService.updatePluginInfo(updateReqVO);  
64 - // 校验是否更新正确  
65 - PluginInfoDO pluginInfo = pluginInfoMapper.selectById(updateReqVO.getId()); // 获取最新的  
66 - assertPojoEquals(updateReqVO, pluginInfo);  
67 - }  
68 -  
69 - @Test  
70 - public void testUpdatePluginInfo_notExists() {  
71 - // 准备参数  
72 - PluginInfoSaveReqVO updateReqVO = randomPojo(PluginInfoSaveReqVO.class);  
73 -  
74 - // 调用, 并断言异常  
75 - assertServiceException(() -> pluginInfoService.updatePluginInfo(updateReqVO), PLUGIN_INFO_NOT_EXISTS);  
76 - }  
77 -  
78 - @Test  
79 - public void testDeletePluginInfo_success() {  
80 - // mock 数据  
81 - PluginInfoDO dbPluginInfo = randomPojo(PluginInfoDO.class);  
82 - pluginInfoMapper.insert(dbPluginInfo);// @Sql: 先插入出一条存在的数据  
83 - // 准备参数  
84 - Long id = dbPluginInfo.getId();  
85 -  
86 - // 调用  
87 - pluginInfoService.deletePluginInfo(id);  
88 - // 校验数据不存在了  
89 - assertNull(pluginInfoMapper.selectById(id));  
90 - }  
91 -  
92 - @Test  
93 - public void testDeletePluginInfo_notExists() {  
94 - // 准备参数  
95 - Long id = randomLongId();  
96 -  
97 - // 调用, 并断言异常  
98 - assertServiceException(() -> pluginInfoService.deletePluginInfo(id), PLUGIN_INFO_NOT_EXISTS);  
99 - }  
100 -  
101 - @Test  
102 - @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解  
103 - public void testGetPluginInfoPage() {  
104 - // mock 数据  
105 - PluginInfoDO dbPluginInfo = randomPojo(PluginInfoDO.class, o -> { // 等会查询到  
106 - o.setPluginId(null);  
107 - o.setName(null);  
108 - o.setDescription(null);  
109 - o.setDeployType(null);  
110 - o.setFile(null);  
111 - o.setVersion(null);  
112 - o.setType(null);  
113 - o.setProtocol(null);  
114 - o.setStatus(null);  
115 - o.setConfigSchema(null);  
116 - o.setConfig(null);  
117 - o.setScript(null);  
118 - o.setCreateTime(null);  
119 - });  
120 - pluginInfoMapper.insert(dbPluginInfo);  
121 - // 测试 pluginId 不匹配  
122 - pluginInfoMapper.insert(cloneIgnoreId(dbPluginInfo, o -> o.setPluginId(null)));  
123 - // 测试 name 不匹配  
124 - pluginInfoMapper.insert(cloneIgnoreId(dbPluginInfo, o -> o.setName(null)));  
125 - // 测试 description 不匹配  
126 - pluginInfoMapper.insert(cloneIgnoreId(dbPluginInfo, o -> o.setDescription(null)));  
127 - // 测试 deployType 不匹配  
128 - pluginInfoMapper.insert(cloneIgnoreId(dbPluginInfo, o -> o.setDeployType(null)));  
129 - // 测试 file 不匹配  
130 - pluginInfoMapper.insert(cloneIgnoreId(dbPluginInfo, o -> o.setFile(null)));  
131 - // 测试 version 不匹配  
132 - pluginInfoMapper.insert(cloneIgnoreId(dbPluginInfo, o -> o.setVersion(null)));  
133 - // 测试 type 不匹配  
134 - pluginInfoMapper.insert(cloneIgnoreId(dbPluginInfo, o -> o.setType(null)));  
135 - // 测试 protocol 不匹配  
136 - pluginInfoMapper.insert(cloneIgnoreId(dbPluginInfo, o -> o.setProtocol(null)));  
137 - // 测试 state 不匹配  
138 - pluginInfoMapper.insert(cloneIgnoreId(dbPluginInfo, o -> o.setStatus(null)));  
139 - // 测试 configSchema 不匹配  
140 - pluginInfoMapper.insert(cloneIgnoreId(dbPluginInfo, o -> o.setConfigSchema(null)));  
141 - // 测试 config 不匹配  
142 - pluginInfoMapper.insert(cloneIgnoreId(dbPluginInfo, o -> o.setConfig(null)));  
143 - // 测试 script 不匹配  
144 - pluginInfoMapper.insert(cloneIgnoreId(dbPluginInfo, o -> o.setScript(null)));  
145 - // 测试 createTime 不匹配  
146 - pluginInfoMapper.insert(cloneIgnoreId(dbPluginInfo, o -> o.setCreateTime(null)));  
147 - // 准备参数  
148 - PluginInfoPageReqVO reqVO = new PluginInfoPageReqVO();  
149 - reqVO.setPluginId(null);  
150 - reqVO.setName(null);  
151 - reqVO.setDescription(null);  
152 - reqVO.setDeployType(null);  
153 - reqVO.setFile(null);  
154 - reqVO.setVersion(null);  
155 - reqVO.setType(null);  
156 - reqVO.setProtocol(null);  
157 - reqVO.setStatus(null);  
158 - reqVO.setConfigSchema(null);  
159 - reqVO.setConfig(null);  
160 - reqVO.setScript(null);  
161 - reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));  
162 -  
163 - // 调用  
164 - PageResult<PluginInfoDO> pageResult = pluginInfoService.getPluginInfoPage(reqVO);  
165 - // 断言  
166 - assertEquals(1, pageResult.getTotal());  
167 - assertEquals(1, pageResult.getList().size());  
168 - assertPojoEquals(dbPluginInfo, pageResult.getList().get(0));  
169 - }  
170 -  
171 -}  
172 \ No newline at end of file 0 \ No newline at end of file
yudao-module-iot/yudao-module-iot-biz/src/test/java/cn/iocoder/yudao/module/iot/service/plugininstance/PluginInstanceServiceImplTest.java deleted
1 -package cn.iocoder.yudao.module.iot.service.plugininstance;  
2 -  
3 -import org.junit.jupiter.api.Disabled;  
4 -import org.junit.jupiter.api.Test;  
5 -import org.springframework.boot.test.mock.mockito.MockBean;  
6 -  
7 -import jakarta.annotation.Resource;  
8 -  
9 -import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;  
10 -  
11 -import cn.iocoder.yudao.module.iot.controller.admin.plugininstance.vo.*;  
12 -import cn.iocoder.yudao.module.iot.dal.dataobject.plugininstance.PluginInstanceDO;  
13 -import cn.iocoder.yudao.module.iot.dal.mysql.plugininstance.PluginInstanceMapper;  
14 -import cn.iocoder.yudao.framework.common.pojo.PageResult;  
15 -  
16 -import jakarta.annotation.Resource;  
17 -import org.springframework.context.annotation.Import;  
18 -import java.util.*;  
19 -import java.time.LocalDateTime;  
20 -  
21 -import static cn.hutool.core.util.RandomUtil.*;  
22 -import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*;  
23 -import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;  
24 -import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;  
25 -import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*;  
26 -import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;  
27 -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*;  
28 -import static org.junit.jupiter.api.Assertions.*;  
29 -import static org.mockito.Mockito.*;  
30 -  
31 -/**  
32 - * {@link PluginInstanceServiceImpl} 的单元测试类  
33 - *  
34 - * @author 芋道源码  
35 - */  
36 -@Import(PluginInstanceServiceImpl.class)  
37 -public class PluginInstanceServiceImplTest extends BaseDbUnitTest {  
38 -  
39 - @Resource  
40 - private PluginInstanceServiceImpl pluginInstanceService;  
41 -  
42 - @Resource  
43 - private PluginInstanceMapper pluginInstanceMapper;  
44 -  
45 - @Test  
46 - public void testCreatePluginInstance_success() {  
47 - // 准备参数  
48 - PluginInstanceSaveReqVO createReqVO = randomPojo(PluginInstanceSaveReqVO.class).setId(null);  
49 -  
50 - // 调用  
51 - Long pluginInstanceId = pluginInstanceService.createPluginInstance(createReqVO);  
52 - // 断言  
53 - assertNotNull(pluginInstanceId);  
54 - // 校验记录的属性是否正确  
55 - PluginInstanceDO pluginInstance = pluginInstanceMapper.selectById(pluginInstanceId);  
56 - assertPojoEquals(createReqVO, pluginInstance, "id");  
57 - }  
58 -  
59 - @Test  
60 - public void testUpdatePluginInstance_success() {  
61 - // mock 数据  
62 - PluginInstanceDO dbPluginInstance = randomPojo(PluginInstanceDO.class);  
63 - pluginInstanceMapper.insert(dbPluginInstance);// @Sql: 先插入出一条存在的数据  
64 - // 准备参数  
65 - PluginInstanceSaveReqVO updateReqVO = randomPojo(PluginInstanceSaveReqVO.class, o -> {  
66 - o.setId(dbPluginInstance.getId()); // 设置更新的 ID  
67 - });  
68 -  
69 - // 调用  
70 - pluginInstanceService.updatePluginInstance(updateReqVO);  
71 - // 校验是否更新正确  
72 - PluginInstanceDO pluginInstance = pluginInstanceMapper.selectById(updateReqVO.getId()); // 获取最新的  
73 - assertPojoEquals(updateReqVO, pluginInstance);  
74 - }  
75 -  
76 - @Test  
77 - public void testUpdatePluginInstance_notExists() {  
78 - // 准备参数  
79 - PluginInstanceSaveReqVO updateReqVO = randomPojo(PluginInstanceSaveReqVO.class);  
80 -  
81 - // 调用, 并断言异常  
82 - assertServiceException(() -> pluginInstanceService.updatePluginInstance(updateReqVO), PLUGIN_INSTANCE_NOT_EXISTS);  
83 - }  
84 -  
85 - @Test  
86 - public void testDeletePluginInstance_success() {  
87 - // mock 数据  
88 - PluginInstanceDO dbPluginInstance = randomPojo(PluginInstanceDO.class);  
89 - pluginInstanceMapper.insert(dbPluginInstance);// @Sql: 先插入出一条存在的数据  
90 - // 准备参数  
91 - Long id = dbPluginInstance.getId();  
92 -  
93 - // 调用  
94 - pluginInstanceService.deletePluginInstance(id);  
95 - // 校验数据不存在了  
96 - assertNull(pluginInstanceMapper.selectById(id));  
97 - }  
98 -  
99 - @Test  
100 - public void testDeletePluginInstance_notExists() {  
101 - // 准备参数  
102 - Long id = randomLongId();  
103 -  
104 - // 调用, 并断言异常  
105 - assertServiceException(() -> pluginInstanceService.deletePluginInstance(id), PLUGIN_INSTANCE_NOT_EXISTS);  
106 - }  
107 -  
108 - @Test  
109 - @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解  
110 - public void testGetPluginInstancePage() {  
111 - // mock 数据  
112 - PluginInstanceDO dbPluginInstance = randomPojo(PluginInstanceDO.class, o -> { // 等会查询到  
113 - o.setMainId(null);  
114 - o.setPluginId(null);  
115 - o.setIp(null);  
116 - o.setPort(null);  
117 - o.setHeartbeatAt(null);  
118 - o.setCreateTime(null);  
119 - });  
120 - pluginInstanceMapper.insert(dbPluginInstance);  
121 - // 测试 mainId 不匹配  
122 - pluginInstanceMapper.insert(cloneIgnoreId(dbPluginInstance, o -> o.setMainId(null)));  
123 - // 测试 pluginId 不匹配  
124 - pluginInstanceMapper.insert(cloneIgnoreId(dbPluginInstance, o -> o.setPluginId(null)));  
125 - // 测试 ip 不匹配  
126 - pluginInstanceMapper.insert(cloneIgnoreId(dbPluginInstance, o -> o.setIp(null)));  
127 - // 测试 port 不匹配  
128 - pluginInstanceMapper.insert(cloneIgnoreId(dbPluginInstance, o -> o.setPort(null)));  
129 - // 测试 heartbeatAt 不匹配  
130 - pluginInstanceMapper.insert(cloneIgnoreId(dbPluginInstance, o -> o.setHeartbeatAt(null)));  
131 - // 测试 createTime 不匹配  
132 - pluginInstanceMapper.insert(cloneIgnoreId(dbPluginInstance, o -> o.setCreateTime(null)));  
133 - // 准备参数  
134 - PluginInstancePageReqVO reqVO = new PluginInstancePageReqVO();  
135 - reqVO.setMainId(null);  
136 - reqVO.setPluginId(null);  
137 - reqVO.setIp(null);  
138 - reqVO.setPort(null);  
139 - reqVO.setHeartbeatAt(null);  
140 - reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));  
141 -  
142 - // 调用  
143 - PageResult<PluginInstanceDO> pageResult = pluginInstanceService.getPluginInstancePage(reqVO);  
144 - // 断言  
145 - assertEquals(1, pageResult.getTotal());  
146 - assertEquals(1, pageResult.getList().size());  
147 - assertPojoEquals(dbPluginInstance, pageResult.getList().get(0));  
148 - }  
149 -  
150 -}  
151 \ No newline at end of file 0 \ No newline at end of file