Commit 0d21170b7a62b64120ccff39838db8055de74ea3
Committed by
Andrew Shvayka
1 parent
d769f674
updated device profile validation tests & convertToRpcRequest method in ProtoConverter
Showing
6 changed files
with
17 additions
and
18 deletions
... | ... | @@ -779,7 +779,7 @@ public abstract class BaseDeviceProfileControllerTest extends AbstractController |
779 | 779 | "\n" + |
780 | 780 | "message RpcRequestMsg {\n" + |
781 | 781 | " optional int32 requestId = 2;\n" + |
782 | - " repeated string params = 3;\n" + | |
782 | + " optional string params = 3;\n" + | |
783 | 783 | " \n" + |
784 | 784 | "}", "[Transport Configuration] invalid rpc request proto schema provided! RpcRequestMsg message should always contains 3 fields: method, requestId and params!"); |
785 | 785 | } |
... | ... | @@ -793,7 +793,7 @@ public abstract class BaseDeviceProfileControllerTest extends AbstractController |
793 | 793 | "message RpcRequestMsg {\n" + |
794 | 794 | " optional string methodName = 1;\n" + |
795 | 795 | " optional int32 requestId = 2;\n" + |
796 | - " repeated string params = 3;\n" + | |
796 | + " optional string params = 3;\n" + | |
797 | 797 | " \n" + |
798 | 798 | "}", "[Transport Configuration] invalid rpc request proto schema provided! Failed to get field descriptor for field: method!"); |
799 | 799 | } |
... | ... | @@ -807,7 +807,7 @@ public abstract class BaseDeviceProfileControllerTest extends AbstractController |
807 | 807 | "message RpcRequestMsg {\n" + |
808 | 808 | " optional string method = 1;\n" + |
809 | 809 | " optional int32 requestIdentifier = 2;\n" + |
810 | - " repeated string params = 3;\n" + | |
810 | + " optional string params = 3;\n" + | |
811 | 811 | " \n" + |
812 | 812 | "}", "[Transport Configuration] invalid rpc request proto schema provided! Failed to get field descriptor for field: requestId!"); |
813 | 813 | } |
... | ... | @@ -821,7 +821,7 @@ public abstract class BaseDeviceProfileControllerTest extends AbstractController |
821 | 821 | "message RpcRequestMsg {\n" + |
822 | 822 | " optional string method = 1;\n" + |
823 | 823 | " optional int32 requestId = 2;\n" + |
824 | - " repeated string parameters = 3;\n" + | |
824 | + " optional string parameters = 3;\n" + | |
825 | 825 | " \n" + |
826 | 826 | "}", "[Transport Configuration] invalid rpc request proto schema provided! Failed to get field descriptor for field: params!"); |
827 | 827 | } | ... | ... |
... | ... | @@ -58,13 +58,13 @@ public abstract class AbstractCoapServerSideRpcProtoIntegrationTest extends Abst |
58 | 58 | "package rpc;\n" + |
59 | 59 | "\n" + |
60 | 60 | "message RpcRequestMsg {\n" + |
61 | - " string method = 1;\n" + | |
62 | - " int32 requestId = 2;\n" + | |
61 | + " optional string method = 1;\n" + | |
62 | + " optional int32 requestId = 2;\n" + | |
63 | 63 | " Params params = 3;\n" + |
64 | 64 | "\n" + |
65 | 65 | " message Params {\n" + |
66 | - " string pin = 1;\n" + | |
67 | - " int32 value = 2;\n" + | |
66 | + " optional string pin = 1;\n" + | |
67 | + " optional int32 value = 2;\n" + | |
68 | 68 | " }\n" + |
69 | 69 | "}"; |
70 | 70 | ... | ... |
... | ... | @@ -56,13 +56,13 @@ public abstract class AbstractMqttServerSideRpcProtoIntegrationTest extends Abst |
56 | 56 | "package rpc;\n" + |
57 | 57 | "\n" + |
58 | 58 | "message RpcRequestMsg {\n" + |
59 | - " string method = 1;\n" + | |
60 | - " int32 requestId = 2;\n" + | |
59 | + " optional string method = 1;\n" + | |
60 | + " optional int32 requestId = 2;\n" + | |
61 | 61 | " Params params = 3;\n" + |
62 | 62 | "\n" + |
63 | 63 | " message Params {\n" + |
64 | - " string pin = 1;\n" + | |
65 | - " int32 value = 2;\n" + | |
64 | + " optional string pin = 1;\n" + | |
65 | + " optional int32 value = 2;\n" + | |
66 | 66 | " }\n" + |
67 | 67 | "}"; |
68 | 68 | ... | ... |
... | ... | @@ -83,7 +83,7 @@ public class ProtoTransportPayloadConfiguration implements TransportPayloadTypeC |
83 | 83 | "package rpc;\n" + |
84 | 84 | "\n" + |
85 | 85 | "message RpcResponseMsg {\n" + |
86 | - " string payload = 1;\n" + | |
86 | + " optional string payload = 1;\n" + | |
87 | 87 | "}"; |
88 | 88 | } |
89 | 89 | } |
... | ... | @@ -96,9 +96,9 @@ public class ProtoTransportPayloadConfiguration implements TransportPayloadTypeC |
96 | 96 | "package rpc;\n" + |
97 | 97 | "\n" + |
98 | 98 | "message RpcRequestMsg {\n" + |
99 | - " string method = 1;\n" + | |
100 | - " int32 requestId = 2;\n" + | |
101 | - " string params = 3;\n" + | |
99 | + " optional string method = 1;\n" + | |
100 | + " optional int32 requestId = 2;\n" + | |
101 | + " optional string params = 3;\n" + | |
102 | 102 | "}"; |
103 | 103 | } |
104 | 104 | } | ... | ... |
... | ... | @@ -16,7 +16,6 @@ |
16 | 16 | package org.thingsboard.server.transport.coap.adaptors; |
17 | 17 | |
18 | 18 | import com.google.gson.JsonElement; |
19 | -import com.google.gson.JsonObject; | |
20 | 19 | import com.google.gson.JsonParser; |
21 | 20 | import com.google.protobuf.Descriptors; |
22 | 21 | import com.google.protobuf.DynamicMessage; | ... | ... |
... | ... | @@ -175,7 +175,7 @@ public class ProtoConverter { |
175 | 175 | } |
176 | 176 | |
177 | 177 | public static byte[] convertToRpcRequest(TransportProtos.ToDeviceRpcRequestMsg toDeviceRpcRequestMsg, DynamicMessage.Builder rpcRequestDynamicMessageBuilder) throws AdaptorException { |
178 | - rpcRequestDynamicMessageBuilder.clear(); | |
178 | + rpcRequestDynamicMessageBuilder = rpcRequestDynamicMessageBuilder.getDefaultInstanceForType().newBuilderForType(); | |
179 | 179 | JsonObject rpcRequestJson = new JsonObject(); |
180 | 180 | rpcRequestJson.addProperty("method", toDeviceRpcRequestMsg.getMethodName()); |
181 | 181 | rpcRequestJson.addProperty("requestId", toDeviceRpcRequestMsg.getRequestId()); | ... | ... |