【代码评审】IoT:插件管理相关的逻辑
This commit is contained in:
parent
555310de66
commit
dea8883f82
|
@ -13,7 +13,7 @@ import java.util.Arrays;
|
|||
@Getter
|
||||
public enum IotPluginDeployTypeEnum implements IntArrayValuable {
|
||||
|
||||
UPLOAD(0, "上传jar"),
|
||||
UPLOAD(0, "上传 jar"), // TODO @haohao:UPLOAD 和 ALONE 感觉有点冲突,前者是部署方式,后者是运行方式。这个后续再讨论下哈
|
||||
ALONE(1, "独立运行");
|
||||
|
||||
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(IotPluginDeployTypeEnum::getDeployType).toArray();
|
||||
|
|
|
@ -42,6 +42,11 @@ public enum IotPluginStatusEnum implements IntArrayValuable {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] array() {
|
||||
return ARRAYS;
|
||||
}
|
||||
|
||||
public static boolean isValidState(Integer state) {
|
||||
return fromState(state) != null;
|
||||
}
|
||||
|
@ -50,8 +55,4 @@ public enum IotPluginStatusEnum implements IntArrayValuable {
|
|||
return Arrays.stream(values()).anyMatch(e -> e.getStatus().equals(status));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] array() {
|
||||
return new int[0];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package cn.iocoder.yudao.module.iot.enums.plugin;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
@ -10,6 +11,7 @@ import java.util.Arrays;
|
|||
*
|
||||
* @author haohao
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum IotPluginTypeEnum implements IntArrayValuable {
|
||||
|
||||
|
@ -28,11 +30,12 @@ public enum IotPluginTypeEnum implements IntArrayValuable {
|
|||
*/
|
||||
private final String name;
|
||||
|
||||
IotPluginTypeEnum(Integer type, String name) {
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
@Override
|
||||
public int[] array() {
|
||||
return ARRAYS;
|
||||
}
|
||||
|
||||
// TODO @haohao:可以使用 hutool 简化
|
||||
public static IotPluginTypeEnum fromType(Integer type) {
|
||||
for (IotPluginTypeEnum value : values()) {
|
||||
if (value.getType().equals(type)) {
|
||||
|
@ -46,8 +49,4 @@ public enum IotPluginTypeEnum implements IntArrayValuable {
|
|||
return fromType(type) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] array() {
|
||||
return ARRAYS;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ import org.springframework.web.multipart.MultipartFile;
|
|||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||
import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.FILE_IS_EMPTY;
|
||||
|
||||
@Tag(name = "管理后台 - IoT 插件信息")
|
||||
|
@ -86,7 +85,6 @@ public class PluginInfoController {
|
|||
return success(true);
|
||||
}
|
||||
|
||||
// 修改插件状态
|
||||
@PutMapping("/update-status")
|
||||
@Operation(summary = "修改插件状态")
|
||||
@PreAuthorize("@ss.hasPermission('iot:plugin-info:update')")
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package cn.iocoder.yudao.module.iot.controller.admin.plugininfo.vo;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.validation.InEnum;
|
||||
import cn.iocoder.yudao.module.iot.enums.plugin.IotPluginTypeEnum;
|
||||
import lombok.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
|
@ -8,13 +10,12 @@ import java.time.LocalDateTime;
|
|||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
// TODO @haohao:只查询必要字段哈
|
||||
@Schema(description = "管理后台 - IoT 插件信息分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class PluginInfoPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "插件包id", example = "24627")
|
||||
@Schema(description = "插件包 ID ", example = "24627")
|
||||
private String pluginId;
|
||||
|
||||
@Schema(description = "插件名称", example = "赵六")
|
||||
|
@ -33,6 +34,7 @@ public class PluginInfoPageReqVO extends PageParam {
|
|||
private String version;
|
||||
|
||||
@Schema(description = "插件类型", example = "2")
|
||||
@InEnum(IotPluginTypeEnum.class)
|
||||
private Integer type;
|
||||
|
||||
@Schema(description = "设备插件协议类型")
|
||||
|
|
|
@ -1,22 +1,23 @@
|
|||
package cn.iocoder.yudao.module.iot.controller.admin.plugininfo.vo;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import com.alibaba.excel.annotation.*;
|
||||
|
||||
@Schema(description = "管理后台 - IoT 插件信息 Response VO")
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class PluginInfoRespVO {
|
||||
|
||||
@Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "11546")
|
||||
@ExcelProperty("主键ID")
|
||||
@Schema(description = "主键 ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "11546")
|
||||
@ExcelProperty("主键 ID")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "插件包id", requiredMode = Schema.RequiredMode.REQUIRED, example = "24627")
|
||||
@ExcelProperty("插件包id")
|
||||
@Schema(description = "插件包 ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "24627")
|
||||
@ExcelProperty("插件包 ID")
|
||||
private String pluginId;
|
||||
|
||||
@Schema(description = "插件名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
|
||||
|
|
|
@ -8,6 +8,7 @@ import java.time.LocalDateTime;
|
|||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
// TODO @haohao:建议搞个 plugin,然后里面分 info 和 instance。另外,是不是 info => config 会好点,插件配置?
|
||||
@Schema(description = "管理后台 - IoT 插件实例分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
|
|
|
@ -22,12 +22,13 @@ import lombok.*;
|
|||
public class PluginInfoDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
* 主键 ID
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
// TODO @haohao:这个是不是改成类似 key 之类的字段哈?
|
||||
/**
|
||||
* 插件包id
|
||||
* 插件包 ID
|
||||
*/
|
||||
private String pluginId;
|
||||
/**
|
||||
|
@ -41,10 +42,12 @@ public class PluginInfoDO extends BaseDO {
|
|||
/**
|
||||
* 部署方式
|
||||
*/
|
||||
// TODO @haohao:枚举
|
||||
private Integer deployType;
|
||||
/**
|
||||
* 插件包文件名
|
||||
*/
|
||||
// TODO @haohao:是不是叫 fileName 哈?避免后续有别的字段,类似 fileUrl?
|
||||
private String file;
|
||||
/**
|
||||
* 插件版本
|
||||
|
@ -53,6 +56,7 @@ public class PluginInfoDO extends BaseDO {
|
|||
/**
|
||||
* 插件类型
|
||||
*/
|
||||
// TODO @haohao:枚举
|
||||
private Integer type;
|
||||
/**
|
||||
* 设备插件协议类型
|
||||
|
@ -61,6 +65,7 @@ public class PluginInfoDO extends BaseDO {
|
|||
/**
|
||||
* 状态
|
||||
*/
|
||||
// TODO @haohao:枚举
|
||||
private Integer status;
|
||||
/**
|
||||
* 插件配置项描述信息
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package cn.iocoder.yudao.module.iot.dal.dataobject.plugininstance;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalDateTime;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.*;
|
||||
|
||||
// TODO @haohao:一些必要的关联、枚举
|
||||
/**
|
||||
* IoT 插件实例 DO
|
||||
*
|
||||
|
@ -28,7 +28,7 @@ public class PluginInstanceDO extends BaseDO {
|
|||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 插件主程序id
|
||||
* 插件主程序 ID
|
||||
*/
|
||||
private String mainId;
|
||||
/**
|
||||
|
@ -44,7 +44,7 @@ public class PluginInstanceDO extends BaseDO {
|
|||
*/
|
||||
private Integer port;
|
||||
/**
|
||||
* 心跳时间,心路时间超过30秒需要剔除
|
||||
* 心跳时间,心路时间超过 30 秒需要剔除
|
||||
*/
|
||||
private Long heartbeatAt;
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@ import java.util.Map;
|
|||
*/
|
||||
public interface IotDeviceDataService {
|
||||
|
||||
|
||||
/**
|
||||
* 保存设备数据
|
||||
*
|
||||
|
|
|
@ -1,171 +0,0 @@
|
|||
package cn.iocoder.yudao.module.iot.service.plugininfo;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
|
||||
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
||||
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.plugininfo.vo.*;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.plugininfo.PluginInfoDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.mysql.plugininfo.PluginInfoMapper;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* {@link PluginInfoServiceImpl} 的单元测试类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Import(PluginInfoServiceImpl.class)
|
||||
public class PluginInfoServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private PluginInfoServiceImpl pluginInfoService;
|
||||
|
||||
@Resource
|
||||
private PluginInfoMapper pluginInfoMapper;
|
||||
|
||||
@Test
|
||||
public void testCreatePluginInfo_success() {
|
||||
// 准备参数
|
||||
PluginInfoSaveReqVO createReqVO = randomPojo(PluginInfoSaveReqVO.class).setId(null);
|
||||
|
||||
// 调用
|
||||
Long pluginInfoId = pluginInfoService.createPluginInfo(createReqVO);
|
||||
// 断言
|
||||
assertNotNull(pluginInfoId);
|
||||
// 校验记录的属性是否正确
|
||||
PluginInfoDO pluginInfo = pluginInfoMapper.selectById(pluginInfoId);
|
||||
assertPojoEquals(createReqVO, pluginInfo, "id");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdatePluginInfo_success() {
|
||||
// mock 数据
|
||||
PluginInfoDO dbPluginInfo = randomPojo(PluginInfoDO.class);
|
||||
pluginInfoMapper.insert(dbPluginInfo);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
PluginInfoSaveReqVO updateReqVO = randomPojo(PluginInfoSaveReqVO.class, o -> {
|
||||
o.setId(dbPluginInfo.getId()); // 设置更新的 ID
|
||||
});
|
||||
|
||||
// 调用
|
||||
pluginInfoService.updatePluginInfo(updateReqVO);
|
||||
// 校验是否更新正确
|
||||
PluginInfoDO pluginInfo = pluginInfoMapper.selectById(updateReqVO.getId()); // 获取最新的
|
||||
assertPojoEquals(updateReqVO, pluginInfo);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdatePluginInfo_notExists() {
|
||||
// 准备参数
|
||||
PluginInfoSaveReqVO updateReqVO = randomPojo(PluginInfoSaveReqVO.class);
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> pluginInfoService.updatePluginInfo(updateReqVO), PLUGIN_INFO_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeletePluginInfo_success() {
|
||||
// mock 数据
|
||||
PluginInfoDO dbPluginInfo = randomPojo(PluginInfoDO.class);
|
||||
pluginInfoMapper.insert(dbPluginInfo);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Long id = dbPluginInfo.getId();
|
||||
|
||||
// 调用
|
||||
pluginInfoService.deletePluginInfo(id);
|
||||
// 校验数据不存在了
|
||||
assertNull(pluginInfoMapper.selectById(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeletePluginInfo_notExists() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> pluginInfoService.deletePluginInfo(id), PLUGIN_INFO_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||
public void testGetPluginInfoPage() {
|
||||
// mock 数据
|
||||
PluginInfoDO dbPluginInfo = randomPojo(PluginInfoDO.class, o -> { // 等会查询到
|
||||
o.setPluginId(null);
|
||||
o.setName(null);
|
||||
o.setDescription(null);
|
||||
o.setDeployType(null);
|
||||
o.setFile(null);
|
||||
o.setVersion(null);
|
||||
o.setType(null);
|
||||
o.setProtocol(null);
|
||||
o.setStatus(null);
|
||||
o.setConfigSchema(null);
|
||||
o.setConfig(null);
|
||||
o.setScript(null);
|
||||
o.setCreateTime(null);
|
||||
});
|
||||
pluginInfoMapper.insert(dbPluginInfo);
|
||||
// 测试 pluginId 不匹配
|
||||
pluginInfoMapper.insert(cloneIgnoreId(dbPluginInfo, o -> o.setPluginId(null)));
|
||||
// 测试 name 不匹配
|
||||
pluginInfoMapper.insert(cloneIgnoreId(dbPluginInfo, o -> o.setName(null)));
|
||||
// 测试 description 不匹配
|
||||
pluginInfoMapper.insert(cloneIgnoreId(dbPluginInfo, o -> o.setDescription(null)));
|
||||
// 测试 deployType 不匹配
|
||||
pluginInfoMapper.insert(cloneIgnoreId(dbPluginInfo, o -> o.setDeployType(null)));
|
||||
// 测试 file 不匹配
|
||||
pluginInfoMapper.insert(cloneIgnoreId(dbPluginInfo, o -> o.setFile(null)));
|
||||
// 测试 version 不匹配
|
||||
pluginInfoMapper.insert(cloneIgnoreId(dbPluginInfo, o -> o.setVersion(null)));
|
||||
// 测试 type 不匹配
|
||||
pluginInfoMapper.insert(cloneIgnoreId(dbPluginInfo, o -> o.setType(null)));
|
||||
// 测试 protocol 不匹配
|
||||
pluginInfoMapper.insert(cloneIgnoreId(dbPluginInfo, o -> o.setProtocol(null)));
|
||||
// 测试 state 不匹配
|
||||
pluginInfoMapper.insert(cloneIgnoreId(dbPluginInfo, o -> o.setStatus(null)));
|
||||
// 测试 configSchema 不匹配
|
||||
pluginInfoMapper.insert(cloneIgnoreId(dbPluginInfo, o -> o.setConfigSchema(null)));
|
||||
// 测试 config 不匹配
|
||||
pluginInfoMapper.insert(cloneIgnoreId(dbPluginInfo, o -> o.setConfig(null)));
|
||||
// 测试 script 不匹配
|
||||
pluginInfoMapper.insert(cloneIgnoreId(dbPluginInfo, o -> o.setScript(null)));
|
||||
// 测试 createTime 不匹配
|
||||
pluginInfoMapper.insert(cloneIgnoreId(dbPluginInfo, o -> o.setCreateTime(null)));
|
||||
// 准备参数
|
||||
PluginInfoPageReqVO reqVO = new PluginInfoPageReqVO();
|
||||
reqVO.setPluginId(null);
|
||||
reqVO.setName(null);
|
||||
reqVO.setDescription(null);
|
||||
reqVO.setDeployType(null);
|
||||
reqVO.setFile(null);
|
||||
reqVO.setVersion(null);
|
||||
reqVO.setType(null);
|
||||
reqVO.setProtocol(null);
|
||||
reqVO.setStatus(null);
|
||||
reqVO.setConfigSchema(null);
|
||||
reqVO.setConfig(null);
|
||||
reqVO.setScript(null);
|
||||
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
|
||||
// 调用
|
||||
PageResult<PluginInfoDO> pageResult = pluginInfoService.getPluginInfoPage(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbPluginInfo, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,150 +0,0 @@
|
|||
package cn.iocoder.yudao.module.iot.service.plugininstance;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
|
||||
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
||||
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.plugininstance.vo.*;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.plugininstance.PluginInstanceDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.mysql.plugininstance.PluginInstanceMapper;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.hutool.core.util.RandomUtil.*;
|
||||
import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* {@link PluginInstanceServiceImpl} 的单元测试类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Import(PluginInstanceServiceImpl.class)
|
||||
public class PluginInstanceServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private PluginInstanceServiceImpl pluginInstanceService;
|
||||
|
||||
@Resource
|
||||
private PluginInstanceMapper pluginInstanceMapper;
|
||||
|
||||
@Test
|
||||
public void testCreatePluginInstance_success() {
|
||||
// 准备参数
|
||||
PluginInstanceSaveReqVO createReqVO = randomPojo(PluginInstanceSaveReqVO.class).setId(null);
|
||||
|
||||
// 调用
|
||||
Long pluginInstanceId = pluginInstanceService.createPluginInstance(createReqVO);
|
||||
// 断言
|
||||
assertNotNull(pluginInstanceId);
|
||||
// 校验记录的属性是否正确
|
||||
PluginInstanceDO pluginInstance = pluginInstanceMapper.selectById(pluginInstanceId);
|
||||
assertPojoEquals(createReqVO, pluginInstance, "id");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdatePluginInstance_success() {
|
||||
// mock 数据
|
||||
PluginInstanceDO dbPluginInstance = randomPojo(PluginInstanceDO.class);
|
||||
pluginInstanceMapper.insert(dbPluginInstance);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
PluginInstanceSaveReqVO updateReqVO = randomPojo(PluginInstanceSaveReqVO.class, o -> {
|
||||
o.setId(dbPluginInstance.getId()); // 设置更新的 ID
|
||||
});
|
||||
|
||||
// 调用
|
||||
pluginInstanceService.updatePluginInstance(updateReqVO);
|
||||
// 校验是否更新正确
|
||||
PluginInstanceDO pluginInstance = pluginInstanceMapper.selectById(updateReqVO.getId()); // 获取最新的
|
||||
assertPojoEquals(updateReqVO, pluginInstance);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdatePluginInstance_notExists() {
|
||||
// 准备参数
|
||||
PluginInstanceSaveReqVO updateReqVO = randomPojo(PluginInstanceSaveReqVO.class);
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> pluginInstanceService.updatePluginInstance(updateReqVO), PLUGIN_INSTANCE_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeletePluginInstance_success() {
|
||||
// mock 数据
|
||||
PluginInstanceDO dbPluginInstance = randomPojo(PluginInstanceDO.class);
|
||||
pluginInstanceMapper.insert(dbPluginInstance);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Long id = dbPluginInstance.getId();
|
||||
|
||||
// 调用
|
||||
pluginInstanceService.deletePluginInstance(id);
|
||||
// 校验数据不存在了
|
||||
assertNull(pluginInstanceMapper.selectById(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeletePluginInstance_notExists() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> pluginInstanceService.deletePluginInstance(id), PLUGIN_INSTANCE_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||
public void testGetPluginInstancePage() {
|
||||
// mock 数据
|
||||
PluginInstanceDO dbPluginInstance = randomPojo(PluginInstanceDO.class, o -> { // 等会查询到
|
||||
o.setMainId(null);
|
||||
o.setPluginId(null);
|
||||
o.setIp(null);
|
||||
o.setPort(null);
|
||||
o.setHeartbeatAt(null);
|
||||
o.setCreateTime(null);
|
||||
});
|
||||
pluginInstanceMapper.insert(dbPluginInstance);
|
||||
// 测试 mainId 不匹配
|
||||
pluginInstanceMapper.insert(cloneIgnoreId(dbPluginInstance, o -> o.setMainId(null)));
|
||||
// 测试 pluginId 不匹配
|
||||
pluginInstanceMapper.insert(cloneIgnoreId(dbPluginInstance, o -> o.setPluginId(null)));
|
||||
// 测试 ip 不匹配
|
||||
pluginInstanceMapper.insert(cloneIgnoreId(dbPluginInstance, o -> o.setIp(null)));
|
||||
// 测试 port 不匹配
|
||||
pluginInstanceMapper.insert(cloneIgnoreId(dbPluginInstance, o -> o.setPort(null)));
|
||||
// 测试 heartbeatAt 不匹配
|
||||
pluginInstanceMapper.insert(cloneIgnoreId(dbPluginInstance, o -> o.setHeartbeatAt(null)));
|
||||
// 测试 createTime 不匹配
|
||||
pluginInstanceMapper.insert(cloneIgnoreId(dbPluginInstance, o -> o.setCreateTime(null)));
|
||||
// 准备参数
|
||||
PluginInstancePageReqVO reqVO = new PluginInstancePageReqVO();
|
||||
reqVO.setMainId(null);
|
||||
reqVO.setPluginId(null);
|
||||
reqVO.setIp(null);
|
||||
reqVO.setPort(null);
|
||||
reqVO.setHeartbeatAt(null);
|
||||
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
|
||||
// 调用
|
||||
PageResult<PluginInstanceDO> pageResult = pluginInstanceService.getPluginInstancePage(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbPluginInstance, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue