Commit 3db187091c7e510b651b4e6452a866008a02b4b4
1 parent
a28a1529
feat(iot):【协议改造】优化 coap 单测类的实现
Showing
14 changed files
with
32 additions
and
48 deletions
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/coap/IotCoapProtocol.java
| ... | ... | @@ -7,14 +7,14 @@ import cn.iocoder.yudao.module.iot.core.util.IotDeviceMessageUtils; |
| 7 | 7 | import cn.iocoder.yudao.module.iot.gateway.config.IotGatewayProperties.ProtocolInstanceProperties; |
| 8 | 8 | import cn.iocoder.yudao.module.iot.gateway.protocol.IotProtocol; |
| 9 | 9 | import cn.iocoder.yudao.module.iot.gateway.protocol.coap.handler.downstream.IotCoapDownstreamSubscriber; |
| 10 | -import cn.iocoder.yudao.module.iot.gateway.protocol.coap.handler.upstrem.IotCoapAuthHandler; | |
| 11 | -import cn.iocoder.yudao.module.iot.gateway.protocol.coap.handler.upstrem.IotCoapAuthResource; | |
| 12 | -import cn.iocoder.yudao.module.iot.gateway.protocol.coap.handler.upstrem.IotCoapRegisterHandler; | |
| 13 | -import cn.iocoder.yudao.module.iot.gateway.protocol.coap.handler.upstrem.IotCoapRegisterResource; | |
| 14 | -import cn.iocoder.yudao.module.iot.gateway.protocol.coap.handler.upstrem.IotCoapRegisterSubHandler; | |
| 15 | -import cn.iocoder.yudao.module.iot.gateway.protocol.coap.handler.upstrem.IotCoapRegisterSubResource; | |
| 16 | -import cn.iocoder.yudao.module.iot.gateway.protocol.coap.handler.upstrem.IotCoapUpstreamHandler; | |
| 17 | -import cn.iocoder.yudao.module.iot.gateway.protocol.coap.handler.upstrem.IotCoapUpstreamTopicResource; | |
| 10 | +import cn.iocoder.yudao.module.iot.gateway.protocol.coap.handler.upstream.IotCoapAuthHandler; | |
| 11 | +import cn.iocoder.yudao.module.iot.gateway.protocol.coap.handler.upstream.IotCoapAuthResource; | |
| 12 | +import cn.iocoder.yudao.module.iot.gateway.protocol.coap.handler.upstream.IotCoapRegisterHandler; | |
| 13 | +import cn.iocoder.yudao.module.iot.gateway.protocol.coap.handler.upstream.IotCoapRegisterResource; | |
| 14 | +import cn.iocoder.yudao.module.iot.gateway.protocol.coap.handler.upstream.IotCoapRegisterSubHandler; | |
| 15 | +import cn.iocoder.yudao.module.iot.gateway.protocol.coap.handler.upstream.IotCoapRegisterSubResource; | |
| 16 | +import cn.iocoder.yudao.module.iot.gateway.protocol.coap.handler.upstream.IotCoapUpstreamHandler; | |
| 17 | +import cn.iocoder.yudao.module.iot.gateway.protocol.coap.handler.upstream.IotCoapUpstreamTopicResource; | |
| 18 | 18 | import lombok.Getter; |
| 19 | 19 | import lombok.extern.slf4j.Slf4j; |
| 20 | 20 | import org.eclipse.californium.core.CoapResource; | ... | ... |
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/coap/handler/upstrem/IotCoapAbstractHandler.java renamed to yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/coap/handler/upstream/IotCoapAbstractHandler.java
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/coap/handler/upstrem/IotCoapAuthHandler.java renamed to yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/coap/handler/upstream/IotCoapAuthHandler.java
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/coap/handler/upstrem/IotCoapAuthResource.java renamed to yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/coap/handler/upstream/IotCoapAuthResource.java
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/coap/handler/upstrem/IotCoapRegisterHandler.java renamed to yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/coap/handler/upstream/IotCoapRegisterHandler.java
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/coap/handler/upstrem/IotCoapRegisterResource.java renamed to yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/coap/handler/upstream/IotCoapRegisterResource.java
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/coap/handler/upstrem/IotCoapRegisterSubHandler.java renamed to yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/coap/handler/upstream/IotCoapRegisterSubHandler.java
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/coap/handler/upstrem/IotCoapRegisterSubResource.java renamed to yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/coap/handler/upstream/IotCoapRegisterSubResource.java
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/coap/handler/upstrem/IotCoapUpstreamHandler.java renamed to yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/coap/handler/upstream/IotCoapUpstreamHandler.java
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/coap/handler/upstrem/IotCoapUpstreamTopicResource.java renamed to yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/coap/handler/upstream/IotCoapUpstreamTopicResource.java
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/coap/util/IotCoapUtils.java deleted
| 1 | -package cn.iocoder.yudao.module.iot.gateway.protocol.coap.util; | |
| 2 | - | |
| 3 | -import cn.iocoder.yudao.module.iot.gateway.protocol.coap.handler.upstrem.IotCoapAbstractHandler; | |
| 4 | - | |
| 5 | -/** | |
| 6 | - * IoT CoAP 协议工具类 | |
| 7 | - * | |
| 8 | - * @author 芋道源码 | |
| 9 | - */ | |
| 10 | -public class IotCoapUtils { | |
| 11 | - | |
| 12 | - /** | |
| 13 | - * 自定义 CoAP Option 编号,用于携带 Token | |
| 14 | - * <p> | |
| 15 | - * CoAP Option 范围 2048-65535 属于实验/自定义范围 | |
| 16 | - */ | |
| 17 | - public static final int OPTION_TOKEN = IotCoapAbstractHandler.OPTION_TOKEN; | |
| 18 | - | |
| 19 | -} |
yudao-module-iot/yudao-module-iot-gateway/src/test/java/cn/iocoder/yudao/module/iot/gateway/protocol/coap/IotDirectDeviceCoapProtocolIntegrationTest.java
| ... | ... | @@ -9,7 +9,6 @@ import cn.iocoder.yudao.module.iot.core.topic.auth.IotDeviceRegisterReqDTO; |
| 9 | 9 | import cn.iocoder.yudao.module.iot.core.topic.event.IotDeviceEventPostReqDTO; |
| 10 | 10 | import cn.iocoder.yudao.module.iot.core.topic.property.IotDevicePropertyPostReqDTO; |
| 11 | 11 | import cn.iocoder.yudao.module.iot.core.util.IotDeviceAuthUtils; |
| 12 | -import cn.iocoder.yudao.module.iot.gateway.protocol.coap.util.IotCoapUtils; | |
| 13 | 12 | import lombok.extern.slf4j.Slf4j; |
| 14 | 13 | import org.eclipse.californium.core.CoapClient; |
| 15 | 14 | import org.eclipse.californium.core.CoapResponse; |
| ... | ... | @@ -23,6 +22,8 @@ import org.junit.jupiter.api.BeforeAll; |
| 23 | 22 | import org.junit.jupiter.api.Disabled; |
| 24 | 23 | import org.junit.jupiter.api.Test; |
| 25 | 24 | |
| 25 | +import static cn.iocoder.yudao.module.iot.gateway.protocol.coap.handler.upstream.IotCoapAbstractHandler.OPTION_TOKEN; | |
| 26 | + | |
| 26 | 27 | /** |
| 27 | 28 | * IoT 直连设备 CoAP 协议集成测试(手动测试) |
| 28 | 29 | * |
| ... | ... | @@ -134,7 +135,7 @@ public class IotDirectDeviceCoapProtocolIntegrationTest { |
| 134 | 135 | request.setURI(uri); |
| 135 | 136 | request.setPayload(payload); |
| 136 | 137 | request.getOptions().setContentFormat(MediaTypeRegistry.APPLICATION_JSON); |
| 137 | - request.getOptions().addOption(new Option(IotCoapUtils.OPTION_TOKEN, TOKEN)); | |
| 138 | + request.getOptions().addOption(new Option(OPTION_TOKEN, TOKEN)); | |
| 138 | 139 | |
| 139 | 140 | CoapResponse response = client.advanced(request); |
| 140 | 141 | // 2.2 输出结果 |
| ... | ... | @@ -177,7 +178,7 @@ public class IotDirectDeviceCoapProtocolIntegrationTest { |
| 177 | 178 | request.setURI(uri); |
| 178 | 179 | request.setPayload(payload); |
| 179 | 180 | request.getOptions().setContentFormat(MediaTypeRegistry.APPLICATION_JSON); |
| 180 | - request.getOptions().addOption(new Option(IotCoapUtils.OPTION_TOKEN, TOKEN)); | |
| 181 | + request.getOptions().addOption(new Option(OPTION_TOKEN, TOKEN)); | |
| 181 | 182 | |
| 182 | 183 | CoapResponse response = client.advanced(request); |
| 183 | 184 | // 2.2 输出结果 | ... | ... |
yudao-module-iot/yudao-module-iot-gateway/src/test/java/cn/iocoder/yudao/module/iot/gateway/protocol/coap/IotGatewayDeviceCoapProtocolIntegrationTest.java
| ... | ... | @@ -13,7 +13,6 @@ import cn.iocoder.yudao.module.iot.core.topic.topo.IotDeviceTopoAddReqDTO; |
| 13 | 13 | import cn.iocoder.yudao.module.iot.core.topic.topo.IotDeviceTopoDeleteReqDTO; |
| 14 | 14 | import cn.iocoder.yudao.module.iot.core.topic.topo.IotDeviceTopoGetReqDTO; |
| 15 | 15 | import cn.iocoder.yudao.module.iot.core.util.IotDeviceAuthUtils; |
| 16 | -import cn.iocoder.yudao.module.iot.gateway.protocol.coap.util.IotCoapUtils; | |
| 17 | 16 | import lombok.extern.slf4j.Slf4j; |
| 18 | 17 | import org.eclipse.californium.core.CoapClient; |
| 19 | 18 | import org.eclipse.californium.core.CoapResponse; |
| ... | ... | @@ -30,6 +29,8 @@ import org.junit.jupiter.api.Test; |
| 30 | 29 | import java.util.Collections; |
| 31 | 30 | import java.util.Map; |
| 32 | 31 | |
| 32 | +import static cn.iocoder.yudao.module.iot.gateway.protocol.coap.handler.upstream.IotCoapAbstractHandler.OPTION_TOKEN; | |
| 33 | + | |
| 33 | 34 | /** |
| 34 | 35 | * IoT 网关设备 CoAP 协议集成测试(手动测试) |
| 35 | 36 | * |
| ... | ... | @@ -158,7 +159,7 @@ public class IotGatewayDeviceCoapProtocolIntegrationTest { |
| 158 | 159 | request.setURI(uri); |
| 159 | 160 | request.setPayload(payload); |
| 160 | 161 | request.getOptions().setContentFormat(MediaTypeRegistry.APPLICATION_JSON); |
| 161 | - request.getOptions().addOption(new Option(IotCoapUtils.OPTION_TOKEN, GATEWAY_TOKEN)); | |
| 162 | + request.getOptions().addOption(new Option(OPTION_TOKEN, GATEWAY_TOKEN)); | |
| 162 | 163 | |
| 163 | 164 | CoapResponse response = client.advanced(request); |
| 164 | 165 | // 2.2 输出结果 |
| ... | ... | @@ -201,7 +202,7 @@ public class IotGatewayDeviceCoapProtocolIntegrationTest { |
| 201 | 202 | request.setURI(uri); |
| 202 | 203 | request.setPayload(payload); |
| 203 | 204 | request.getOptions().setContentFormat(MediaTypeRegistry.APPLICATION_JSON); |
| 204 | - request.getOptions().addOption(new Option(IotCoapUtils.OPTION_TOKEN, GATEWAY_TOKEN)); | |
| 205 | + request.getOptions().addOption(new Option(OPTION_TOKEN, GATEWAY_TOKEN)); | |
| 205 | 206 | |
| 206 | 207 | CoapResponse response = client.advanced(request); |
| 207 | 208 | // 2.2 输出结果 |
| ... | ... | @@ -242,7 +243,7 @@ public class IotGatewayDeviceCoapProtocolIntegrationTest { |
| 242 | 243 | request.setURI(uri); |
| 243 | 244 | request.setPayload(payload); |
| 244 | 245 | request.getOptions().setContentFormat(MediaTypeRegistry.APPLICATION_JSON); |
| 245 | - request.getOptions().addOption(new Option(IotCoapUtils.OPTION_TOKEN, GATEWAY_TOKEN)); | |
| 246 | + request.getOptions().addOption(new Option(OPTION_TOKEN, GATEWAY_TOKEN)); | |
| 246 | 247 | |
| 247 | 248 | CoapResponse response = client.advanced(request); |
| 248 | 249 | // 2.2 输出结果 |
| ... | ... | @@ -289,7 +290,7 @@ public class IotGatewayDeviceCoapProtocolIntegrationTest { |
| 289 | 290 | request.setURI(uri); |
| 290 | 291 | request.setPayload(payload); |
| 291 | 292 | request.getOptions().setContentFormat(MediaTypeRegistry.APPLICATION_JSON); |
| 292 | - request.getOptions().addOption(new Option(IotCoapUtils.OPTION_TOKEN, GATEWAY_TOKEN)); | |
| 293 | + request.getOptions().addOption(new Option(OPTION_TOKEN, GATEWAY_TOKEN)); | |
| 293 | 294 | |
| 294 | 295 | CoapResponse response = client.advanced(request); |
| 295 | 296 | // 2.2 输出结果 |
| ... | ... | @@ -362,7 +363,7 @@ public class IotGatewayDeviceCoapProtocolIntegrationTest { |
| 362 | 363 | request.setURI(uri); |
| 363 | 364 | request.setPayload(payload); |
| 364 | 365 | request.getOptions().setContentFormat(MediaTypeRegistry.APPLICATION_JSON); |
| 365 | - request.getOptions().addOption(new Option(IotCoapUtils.OPTION_TOKEN, GATEWAY_TOKEN)); | |
| 366 | + request.getOptions().addOption(new Option(OPTION_TOKEN, GATEWAY_TOKEN)); | |
| 366 | 367 | |
| 367 | 368 | CoapResponse response = client.advanced(request); |
| 368 | 369 | // 2.2 输出结果 | ... | ... |
yudao-module-iot/yudao-module-iot-gateway/src/test/java/cn/iocoder/yudao/module/iot/gateway/protocol/coap/IotGatewaySubDeviceCoapProtocolIntegrationTest.java
| ... | ... | @@ -8,7 +8,6 @@ import cn.iocoder.yudao.module.iot.core.enums.IotDeviceMessageMethodEnum; |
| 8 | 8 | import cn.iocoder.yudao.module.iot.core.topic.event.IotDeviceEventPostReqDTO; |
| 9 | 9 | import cn.iocoder.yudao.module.iot.core.topic.property.IotDevicePropertyPostReqDTO; |
| 10 | 10 | import cn.iocoder.yudao.module.iot.core.util.IotDeviceAuthUtils; |
| 11 | -import cn.iocoder.yudao.module.iot.gateway.protocol.coap.util.IotCoapUtils; | |
| 12 | 11 | import lombok.extern.slf4j.Slf4j; |
| 13 | 12 | import org.eclipse.californium.core.CoapClient; |
| 14 | 13 | import org.eclipse.californium.core.CoapResponse; |
| ... | ... | @@ -22,6 +21,8 @@ import org.junit.jupiter.api.BeforeAll; |
| 22 | 21 | import org.junit.jupiter.api.Disabled; |
| 23 | 22 | import org.junit.jupiter.api.Test; |
| 24 | 23 | |
| 24 | +import static cn.iocoder.yudao.module.iot.gateway.protocol.coap.handler.upstream.IotCoapAbstractHandler.OPTION_TOKEN; | |
| 25 | + | |
| 25 | 26 | /** |
| 26 | 27 | * IoT 网关子设备 CoAP 协议集成测试(手动测试) |
| 27 | 28 | * |
| ... | ... | @@ -137,7 +138,7 @@ public class IotGatewaySubDeviceCoapProtocolIntegrationTest { |
| 137 | 138 | request.setURI(uri); |
| 138 | 139 | request.setPayload(payload); |
| 139 | 140 | request.getOptions().setContentFormat(MediaTypeRegistry.APPLICATION_JSON); |
| 140 | - request.getOptions().addOption(new Option(IotCoapUtils.OPTION_TOKEN, TOKEN)); | |
| 141 | + request.getOptions().addOption(new Option(OPTION_TOKEN, TOKEN)); | |
| 141 | 142 | |
| 142 | 143 | CoapResponse response = client.advanced(request); |
| 143 | 144 | // 2.2 输出结果 |
| ... | ... | @@ -185,7 +186,7 @@ public class IotGatewaySubDeviceCoapProtocolIntegrationTest { |
| 185 | 186 | request.setURI(uri); |
| 186 | 187 | request.setPayload(payload); |
| 187 | 188 | request.getOptions().setContentFormat(MediaTypeRegistry.APPLICATION_JSON); |
| 188 | - request.getOptions().addOption(new Option(IotCoapUtils.OPTION_TOKEN, TOKEN)); | |
| 189 | + request.getOptions().addOption(new Option(OPTION_TOKEN, TOKEN)); | |
| 189 | 190 | |
| 190 | 191 | CoapResponse response = client.advanced(request); |
| 191 | 192 | // 2.2 输出结果 | ... | ... |