Commit 3b85adc754d5817d138daf2fc00f99e4938a124a
1 parent
3191d1bd
【代码评审】IoT:数据桥梁的接入
Showing
4 changed files
with
27 additions
and
27 deletions
yudao-module-iot/yudao-module-iot-biz/pom.xml
| ... | ... | @@ -112,6 +112,21 @@ |
| 112 | 112 | <version>24.1.2</version> |
| 113 | 113 | </dependency> |
| 114 | 114 | |
| 115 | + <!-- TODO @芋艿:合理注释 --> | |
| 116 | + <!-- IoT 数据桥梁的执行器所需消息队列。如果您只需要使用 rocketmq 那么则注释掉其它消息队列即可 --> | |
| 117 | + <!-- <dependency>--> | |
| 118 | + <!-- <groupId>org.apache.rocketmq</groupId>--> | |
| 119 | + <!-- <artifactId>rocketmq-spring-boot-starter</artifactId>--> | |
| 120 | + <!-- </dependency>--> | |
| 121 | + <!-- <dependency>--> | |
| 122 | + <!-- <groupId>org.springframework.kafka</groupId>--> | |
| 123 | + <!-- <artifactId>spring-kafka</artifactId>--> | |
| 124 | + <!-- </dependency>--> | |
| 125 | + <!-- <dependency>--> | |
| 126 | + <!-- <groupId>org.springframework.boot</groupId>--> | |
| 127 | + <!-- <artifactId>spring-boot-starter-amqp</artifactId>--> | |
| 128 | + <!-- </dependency>--> | |
| 129 | + | |
| 115 | 130 | </dependencies> |
| 116 | 131 | |
| 117 | 132 | </project> | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/config/IotDataBridgeAbstractConfig.java
| 1 | 1 | package cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.config; |
| 2 | 2 | |
| 3 | +import cn.iocoder.yudao.module.iot.enums.rule.IotDataBridgeTypeEnum; | |
| 3 | 4 | import com.fasterxml.jackson.annotation.JsonSubTypes; |
| 4 | 5 | import com.fasterxml.jackson.annotation.JsonTypeInfo; |
| 5 | 6 | import lombok.Data; |
| ... | ... | @@ -7,7 +8,7 @@ import lombok.Data; |
| 7 | 8 | /** |
| 8 | 9 | * 抽象类 IotDataBridgeConfig |
| 9 | 10 | * |
| 10 | - * 用于表示数据桥梁配置数据的通用类型,根据具体的 "type" 字段动态映射到对应的子类。 | |
| 11 | + * 用于表示数据桥梁配置数据的通用类型,根据具体的 "type" 字段动态映射到对应的子类 | |
| 11 | 12 | * 提供多态支持,适用于不同类型的数据结构序列化和反序列化场景。 |
| 12 | 13 | * |
| 13 | 14 | * @author HUIHUI |
| ... | ... | @@ -26,6 +27,8 @@ public abstract class IotDataBridgeAbstractConfig { |
| 26 | 27 | |
| 27 | 28 | /** |
| 28 | 29 | * 配置类型 |
| 30 | + * | |
| 31 | + * 枚举 {@link IotDataBridgeTypeEnum#getType()} | |
| 29 | 32 | */ |
| 30 | 33 | private String type; |
| 31 | 34 | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/test/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/IotDataBridgeExecuteTest.java
| ... | ... | @@ -10,7 +10,6 @@ import org.junit.jupiter.api.Disabled; |
| 10 | 10 | import org.junit.jupiter.api.Test; |
| 11 | 11 | import org.mockito.InjectMocks; |
| 12 | 12 | import org.mockito.Mock; |
| 13 | -import org.mockito.Mockito; | |
| 14 | 13 | import org.springframework.http.HttpMethod; |
| 15 | 14 | import org.springframework.http.HttpStatus; |
| 16 | 15 | import org.springframework.http.ResponseEntity; |
| ... | ... | @@ -20,6 +19,7 @@ import java.time.LocalDateTime; |
| 20 | 19 | |
| 21 | 20 | import static org.mockito.ArgumentMatchers.any; |
| 22 | 21 | import static org.mockito.ArgumentMatchers.anyString; |
| 22 | +import static org.mockito.Mockito.when; | |
| 23 | 23 | |
| 24 | 24 | /** |
| 25 | 25 | * {@link IotDataBridgeExecute} 实现类的测试 |
| ... | ... | @@ -41,20 +41,14 @@ public class IotDataBridgeExecuteTest extends BaseMockitoUnitTest { |
| 41 | 41 | @BeforeEach |
| 42 | 42 | public void setUp() { |
| 43 | 43 | // 创建共享的测试消息 |
| 44 | - message = IotDeviceMessage.builder() | |
| 45 | - .requestId("TEST-001") | |
| 46 | - .productKey("testProduct") | |
| 47 | - .deviceName("testDevice") | |
| 48 | - .deviceKey("testDeviceKey") | |
| 49 | - .type("property") | |
| 50 | - .identifier("temperature") | |
| 51 | - .data("{\"value\": 60}") | |
| 52 | - .reportTime(LocalDateTime.now()) | |
| 53 | - .tenantId(1L) | |
| 44 | + message = IotDeviceMessage.builder().requestId("TEST-001").reportTime(LocalDateTime.now()).tenantId(1L) | |
| 45 | + .productKey("testProduct").deviceName("testDevice").deviceKey("testDeviceKey") | |
| 46 | + .type("property").identifier("temperature").data("{\"value\": 60}") | |
| 54 | 47 | .build(); |
| 55 | 48 | |
| 56 | 49 | // 配置 RestTemplate mock 返回成功响应 |
| 57 | - Mockito.when(restTemplate.exchange(anyString(), any(HttpMethod.class), any(), any(Class.class))) | |
| 50 | + // TODO @puhui999:这个应该放到 testHttpDataBridge 里 | |
| 51 | + when(restTemplate.exchange(anyString(), any(HttpMethod.class), any(), any(Class.class))) | |
| 58 | 52 | .thenReturn(new ResponseEntity<>("Success", HttpStatus.OK)); |
| 59 | 53 | } |
| 60 | 54 | |
| ... | ... | @@ -64,6 +58,7 @@ public class IotDataBridgeExecuteTest extends BaseMockitoUnitTest { |
| 64 | 58 | IotKafkaMQDataBridgeExecute action = new IotKafkaMQDataBridgeExecute(); |
| 65 | 59 | |
| 66 | 60 | // 2. 创建配置 |
| 61 | + // TODO @puhui999:可以改成链式哈。 | |
| 67 | 62 | IotDataBridgeKafkaMQConfig config = new IotDataBridgeKafkaMQConfig(); |
| 68 | 63 | config.setBootstrapServers("127.0.0.1:9092"); |
| 69 | 64 | config.setTopic("test-topic"); |
| ... | ... | @@ -156,4 +151,4 @@ public class IotDataBridgeExecuteTest extends BaseMockitoUnitTest { |
| 156 | 151 | httpDataBridgeExecute.execute(message, new IotDataBridgeDO().setType(httpDataBridgeExecute.getType()).setConfig(config)); |
| 157 | 152 | } |
| 158 | 153 | |
| 159 | -} | |
| 154 | +} | ... | ... |
yudao-server/pom.xml
| ... | ... | @@ -114,19 +114,6 @@ |
| 114 | 114 | <artifactId>yudao-module-iot-biz</artifactId> |
| 115 | 115 | <version>${revision}</version> |
| 116 | 116 | </dependency> |
| 117 | - <!-- IoT 数据桥梁的执行器所需消息队列。如果您只需要使用 rocketmq 那么则注释掉其它消息队列即可 --> | |
| 118 | - <!-- <dependency>--> | |
| 119 | - <!-- <groupId>org.apache.rocketmq</groupId>--> | |
| 120 | - <!-- <artifactId>rocketmq-spring-boot-starter</artifactId>--> | |
| 121 | - <!-- </dependency>--> | |
| 122 | - <!-- <dependency>--> | |
| 123 | - <!-- <groupId>org.springframework.kafka</groupId>--> | |
| 124 | - <!-- <artifactId>spring-kafka</artifactId>--> | |
| 125 | - <!-- </dependency>--> | |
| 126 | - <!-- <dependency>--> | |
| 127 | - <!-- <groupId>org.springframework.boot</groupId>--> | |
| 128 | - <!-- <artifactId>spring-boot-starter-amqp</artifactId>--> | |
| 129 | - <!-- </dependency>--> | |
| 130 | 117 | |
| 131 | 118 | <!-- spring boot 配置所需依赖 --> |
| 132 | 119 | <dependency> | ... | ... |