Commit 0d21170b7a62b64120ccff39838db8055de74ea3

Authored by ShvaykaD
Committed by Andrew Shvayka
1 parent d769f674

updated device profile validation tests & convertToRpcRequest method in ProtoConverter

@@ -779,7 +779,7 @@ public abstract class BaseDeviceProfileControllerTest extends AbstractController @@ -779,7 +779,7 @@ public abstract class BaseDeviceProfileControllerTest extends AbstractController
779 "\n" + 779 "\n" +
780 "message RpcRequestMsg {\n" + 780 "message RpcRequestMsg {\n" +
781 " optional int32 requestId = 2;\n" + 781 " optional int32 requestId = 2;\n" +
782 - " repeated string params = 3;\n" + 782 + " optional string params = 3;\n" +
783 " \n" + 783 " \n" +
784 "}", "[Transport Configuration] invalid rpc request proto schema provided! RpcRequestMsg message should always contains 3 fields: method, requestId and params!"); 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,7 +793,7 @@ public abstract class BaseDeviceProfileControllerTest extends AbstractController
793 "message RpcRequestMsg {\n" + 793 "message RpcRequestMsg {\n" +
794 " optional string methodName = 1;\n" + 794 " optional string methodName = 1;\n" +
795 " optional int32 requestId = 2;\n" + 795 " optional int32 requestId = 2;\n" +
796 - " repeated string params = 3;\n" + 796 + " optional string params = 3;\n" +
797 " \n" + 797 " \n" +
798 "}", "[Transport Configuration] invalid rpc request proto schema provided! Failed to get field descriptor for field: method!"); 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,7 +807,7 @@ public abstract class BaseDeviceProfileControllerTest extends AbstractController
807 "message RpcRequestMsg {\n" + 807 "message RpcRequestMsg {\n" +
808 " optional string method = 1;\n" + 808 " optional string method = 1;\n" +
809 " optional int32 requestIdentifier = 2;\n" + 809 " optional int32 requestIdentifier = 2;\n" +
810 - " repeated string params = 3;\n" + 810 + " optional string params = 3;\n" +
811 " \n" + 811 " \n" +
812 "}", "[Transport Configuration] invalid rpc request proto schema provided! Failed to get field descriptor for field: requestId!"); 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,7 +821,7 @@ public abstract class BaseDeviceProfileControllerTest extends AbstractController
821 "message RpcRequestMsg {\n" + 821 "message RpcRequestMsg {\n" +
822 " optional string method = 1;\n" + 822 " optional string method = 1;\n" +
823 " optional int32 requestId = 2;\n" + 823 " optional int32 requestId = 2;\n" +
824 - " repeated string parameters = 3;\n" + 824 + " optional string parameters = 3;\n" +
825 " \n" + 825 " \n" +
826 "}", "[Transport Configuration] invalid rpc request proto schema provided! Failed to get field descriptor for field: params!"); 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,13 +58,13 @@ public abstract class AbstractCoapServerSideRpcProtoIntegrationTest extends Abst
58 "package rpc;\n" + 58 "package rpc;\n" +
59 "\n" + 59 "\n" +
60 "message RpcRequestMsg {\n" + 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 " Params params = 3;\n" + 63 " Params params = 3;\n" +
64 "\n" + 64 "\n" +
65 " message Params {\n" + 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 " }\n" + 68 " }\n" +
69 "}"; 69 "}";
70 70
@@ -56,13 +56,13 @@ public abstract class AbstractMqttServerSideRpcProtoIntegrationTest extends Abst @@ -56,13 +56,13 @@ public abstract class AbstractMqttServerSideRpcProtoIntegrationTest extends Abst
56 "package rpc;\n" + 56 "package rpc;\n" +
57 "\n" + 57 "\n" +
58 "message RpcRequestMsg {\n" + 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 " Params params = 3;\n" + 61 " Params params = 3;\n" +
62 "\n" + 62 "\n" +
63 " message Params {\n" + 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 " }\n" + 66 " }\n" +
67 "}"; 67 "}";
68 68
@@ -83,7 +83,7 @@ public class ProtoTransportPayloadConfiguration implements TransportPayloadTypeC @@ -83,7 +83,7 @@ public class ProtoTransportPayloadConfiguration implements TransportPayloadTypeC
83 "package rpc;\n" + 83 "package rpc;\n" +
84 "\n" + 84 "\n" +
85 "message RpcResponseMsg {\n" + 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,9 +96,9 @@ public class ProtoTransportPayloadConfiguration implements TransportPayloadTypeC
96 "package rpc;\n" + 96 "package rpc;\n" +
97 "\n" + 97 "\n" +
98 "message RpcRequestMsg {\n" + 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,7 +16,6 @@
16 package org.thingsboard.server.transport.coap.adaptors; 16 package org.thingsboard.server.transport.coap.adaptors;
17 17
18 import com.google.gson.JsonElement; 18 import com.google.gson.JsonElement;
19 -import com.google.gson.JsonObject;  
20 import com.google.gson.JsonParser; 19 import com.google.gson.JsonParser;
21 import com.google.protobuf.Descriptors; 20 import com.google.protobuf.Descriptors;
22 import com.google.protobuf.DynamicMessage; 21 import com.google.protobuf.DynamicMessage;
@@ -175,7 +175,7 @@ public class ProtoConverter { @@ -175,7 +175,7 @@ public class ProtoConverter {
175 } 175 }
176 176
177 public static byte[] convertToRpcRequest(TransportProtos.ToDeviceRpcRequestMsg toDeviceRpcRequestMsg, DynamicMessage.Builder rpcRequestDynamicMessageBuilder) throws AdaptorException { 177 public static byte[] convertToRpcRequest(TransportProtos.ToDeviceRpcRequestMsg toDeviceRpcRequestMsg, DynamicMessage.Builder rpcRequestDynamicMessageBuilder) throws AdaptorException {
178 - rpcRequestDynamicMessageBuilder.clear(); 178 + rpcRequestDynamicMessageBuilder = rpcRequestDynamicMessageBuilder.getDefaultInstanceForType().newBuilderForType();
179 JsonObject rpcRequestJson = new JsonObject(); 179 JsonObject rpcRequestJson = new JsonObject();
180 rpcRequestJson.addProperty("method", toDeviceRpcRequestMsg.getMethodName()); 180 rpcRequestJson.addProperty("method", toDeviceRpcRequestMsg.getMethodName());
181 rpcRequestJson.addProperty("requestId", toDeviceRpcRequestMsg.getRequestId()); 181 rpcRequestJson.addProperty("requestId", toDeviceRpcRequestMsg.getRequestId());