updated device profile validation tests & convertToRpcRequest method in ProtoConverter

This commit is contained in:
ShvaykaD 2021-06-15 11:43:21 +03:00 committed by Andrew Shvayka
parent d769f6749c
commit 0d21170b7a
6 changed files with 17 additions and 18 deletions

View File

@ -779,7 +779,7 @@ public abstract class BaseDeviceProfileControllerTest extends AbstractController
"\n" + "\n" +
"message RpcRequestMsg {\n" + "message RpcRequestMsg {\n" +
" optional int32 requestId = 2;\n" + " optional int32 requestId = 2;\n" +
" repeated string params = 3;\n" + " optional string params = 3;\n" +
" \n" + " \n" +
"}", "[Transport Configuration] invalid rpc request proto schema provided! RpcRequestMsg message should always contains 3 fields: method, requestId and params!"); "}", "[Transport Configuration] invalid rpc request proto schema provided! RpcRequestMsg message should always contains 3 fields: method, requestId and params!");
} }
@ -793,7 +793,7 @@ public abstract class BaseDeviceProfileControllerTest extends AbstractController
"message RpcRequestMsg {\n" + "message RpcRequestMsg {\n" +
" optional string methodName = 1;\n" + " optional string methodName = 1;\n" +
" optional int32 requestId = 2;\n" + " optional int32 requestId = 2;\n" +
" repeated string params = 3;\n" + " optional string params = 3;\n" +
" \n" + " \n" +
"}", "[Transport Configuration] invalid rpc request proto schema provided! Failed to get field descriptor for field: method!"); "}", "[Transport Configuration] invalid rpc request proto schema provided! Failed to get field descriptor for field: method!");
} }
@ -807,7 +807,7 @@ public abstract class BaseDeviceProfileControllerTest extends AbstractController
"message RpcRequestMsg {\n" + "message RpcRequestMsg {\n" +
" optional string method = 1;\n" + " optional string method = 1;\n" +
" optional int32 requestIdentifier = 2;\n" + " optional int32 requestIdentifier = 2;\n" +
" repeated string params = 3;\n" + " optional string params = 3;\n" +
" \n" + " \n" +
"}", "[Transport Configuration] invalid rpc request proto schema provided! Failed to get field descriptor for field: requestId!"); "}", "[Transport Configuration] invalid rpc request proto schema provided! Failed to get field descriptor for field: requestId!");
} }
@ -821,7 +821,7 @@ public abstract class BaseDeviceProfileControllerTest extends AbstractController
"message RpcRequestMsg {\n" + "message RpcRequestMsg {\n" +
" optional string method = 1;\n" + " optional string method = 1;\n" +
" optional int32 requestId = 2;\n" + " optional int32 requestId = 2;\n" +
" repeated string parameters = 3;\n" + " optional string parameters = 3;\n" +
" \n" + " \n" +
"}", "[Transport Configuration] invalid rpc request proto schema provided! Failed to get field descriptor for field: params!"); "}", "[Transport Configuration] invalid rpc request proto schema provided! Failed to get field descriptor for field: params!");
} }

View File

@ -58,13 +58,13 @@ public abstract class AbstractCoapServerSideRpcProtoIntegrationTest extends Abst
"package rpc;\n" + "package rpc;\n" +
"\n" + "\n" +
"message RpcRequestMsg {\n" + "message RpcRequestMsg {\n" +
" string method = 1;\n" + " optional string method = 1;\n" +
" int32 requestId = 2;\n" + " optional int32 requestId = 2;\n" +
" Params params = 3;\n" + " Params params = 3;\n" +
"\n" + "\n" +
" message Params {\n" + " message Params {\n" +
" string pin = 1;\n" + " optional string pin = 1;\n" +
" int32 value = 2;\n" + " optional int32 value = 2;\n" +
" }\n" + " }\n" +
"}"; "}";

View File

@ -56,13 +56,13 @@ public abstract class AbstractMqttServerSideRpcProtoIntegrationTest extends Abst
"package rpc;\n" + "package rpc;\n" +
"\n" + "\n" +
"message RpcRequestMsg {\n" + "message RpcRequestMsg {\n" +
" string method = 1;\n" + " optional string method = 1;\n" +
" int32 requestId = 2;\n" + " optional int32 requestId = 2;\n" +
" Params params = 3;\n" + " Params params = 3;\n" +
"\n" + "\n" +
" message Params {\n" + " message Params {\n" +
" string pin = 1;\n" + " optional string pin = 1;\n" +
" int32 value = 2;\n" + " optional int32 value = 2;\n" +
" }\n" + " }\n" +
"}"; "}";

View File

@ -83,7 +83,7 @@ public class ProtoTransportPayloadConfiguration implements TransportPayloadTypeC
"package rpc;\n" + "package rpc;\n" +
"\n" + "\n" +
"message RpcResponseMsg {\n" + "message RpcResponseMsg {\n" +
" string payload = 1;\n" + " optional string payload = 1;\n" +
"}"; "}";
} }
} }
@ -96,9 +96,9 @@ public class ProtoTransportPayloadConfiguration implements TransportPayloadTypeC
"package rpc;\n" + "package rpc;\n" +
"\n" + "\n" +
"message RpcRequestMsg {\n" + "message RpcRequestMsg {\n" +
" string method = 1;\n" + " optional string method = 1;\n" +
" int32 requestId = 2;\n" + " optional int32 requestId = 2;\n" +
" string params = 3;\n" + " optional string params = 3;\n" +
"}"; "}";
} }
} }

View File

@ -16,7 +16,6 @@
package org.thingsboard.server.transport.coap.adaptors; package org.thingsboard.server.transport.coap.adaptors;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import com.google.protobuf.Descriptors; import com.google.protobuf.Descriptors;
import com.google.protobuf.DynamicMessage; import com.google.protobuf.DynamicMessage;

View File

@ -175,7 +175,7 @@ public class ProtoConverter {
} }
public static byte[] convertToRpcRequest(TransportProtos.ToDeviceRpcRequestMsg toDeviceRpcRequestMsg, DynamicMessage.Builder rpcRequestDynamicMessageBuilder) throws AdaptorException { public static byte[] convertToRpcRequest(TransportProtos.ToDeviceRpcRequestMsg toDeviceRpcRequestMsg, DynamicMessage.Builder rpcRequestDynamicMessageBuilder) throws AdaptorException {
rpcRequestDynamicMessageBuilder.clear(); rpcRequestDynamicMessageBuilder = rpcRequestDynamicMessageBuilder.getDefaultInstanceForType().newBuilderForType();
JsonObject rpcRequestJson = new JsonObject(); JsonObject rpcRequestJson = new JsonObject();
rpcRequestJson.addProperty("method", toDeviceRpcRequestMsg.getMethodName()); rpcRequestJson.addProperty("method", toDeviceRpcRequestMsg.getMethodName());
rpcRequestJson.addProperty("requestId", toDeviceRpcRequestMsg.getRequestId()); rpcRequestJson.addProperty("requestId", toDeviceRpcRequestMsg.getRequestId());