@ -16,6 +16,7 @@
package org.thingsboard.server.controller ;
import com.fasterxml.jackson.core.type.TypeReference ;
import org.awaitility.Awaitility ;
import org.junit.After ;
import org.junit.Assert ;
import org.junit.Before ;
@ -52,8 +53,8 @@ import org.thingsboard.server.common.data.page.PageLink;
import org.thingsboard.server.common.data.rule.RuleChain ;
import org.thingsboard.server.common.data.security.Authority ;
import org.thingsboard.server.dao.device.DeviceProfileDao ;
import org.thingsboard.server.exception.DataValidationException ;
import org.thingsboard.server.dao.service.DaoSqlTest ;
import org.thingsboard.server.exception.DataValidationException ;
import java.util.ArrayList ;
import java.util.Arrays ;
@ -62,6 +63,7 @@ import java.util.Comparator;
import java.util.List ;
import java.util.Map ;
import java.util.UUID ;
import java.util.concurrent.TimeUnit ;
import java.util.function.Function ;
import java.util.stream.Collectors ;
@ -93,6 +95,7 @@ public class DeviceProfileControllerTest extends AbstractControllerTest {
public DeviceProfileDao deviceProfileDao ( DeviceProfileDao deviceProfileDao ) {
return Mockito . mock ( DeviceProfileDao . class , AdditionalAnswers . delegatesTo ( deviceProfileDao ) ) ;
}
}
@Before
@ -640,364 +643,364 @@ public class DeviceProfileControllerTest extends AbstractControllerTest {
@Test
public void testSaveProtoDeviceProfileWithInvalidProtoFile ( ) throws Exception {
testSaveDeviceProfileWithInvalidProtoSchema ( "syntax = \"proto3\";\n" +
"\n" +
"package schemavalidation;\n" +
"\n" +
"message SchemaValidationTest {\n" +
" required int32 parameter = 1;\n" +
"}" , "[Transport Configuration] failed to parse attributes proto schema due to: Syntax error in :6:4: 'required' label forbidden in proto3 field declarations" ) ;
"\n" +
"package schemavalidation;\n" +
"\n" +
"message SchemaValidationTest {\n" +
" required int32 parameter = 1;\n" +
"}" , "[Transport Configuration] failed to parse attributes proto schema due to: Syntax error in :6:4: 'required' label forbidden in proto3 field declarations" ) ;
}
@Test
public void testSaveProtoDeviceProfileWithInvalidProtoSyntax ( ) throws Exception {
testSaveDeviceProfileWithInvalidProtoSchema ( "syntax = \"proto2\";\n" +
"\n" +
"package schemavalidation;\n" +
"\n" +
"message SchemaValidationTest {\n" +
" required int32 parameter = 1;\n" +
"}" , "[Transport Configuration] invalid schema syntax: proto2 for attributes proto schema provided! Only proto3 allowed!" ) ;
"\n" +
"package schemavalidation;\n" +
"\n" +
"message SchemaValidationTest {\n" +
" required int32 parameter = 1;\n" +
"}" , "[Transport Configuration] invalid schema syntax: proto2 for attributes proto schema provided! Only proto3 allowed!" ) ;
}
@Test
public void testSaveProtoDeviceProfileOptionsNotSupported ( ) throws Exception {
testSaveDeviceProfileWithInvalidProtoSchema ( "syntax = \"proto3\";\n" +
"\n" +
"option java_package = \"com.test.schemavalidation\";\n" +
"option java_multiple_files = true;\n" +
"\n" +
"package schemavalidation;\n" +
"\n" +
"message SchemaValidationTest {\n" +
" optional int32 parameter = 1;\n" +
"}" , "[Transport Configuration] invalid attributes proto schema provided! Schema options don't support!" ) ;
"\n" +
"option java_package = \"com.test.schemavalidation\";\n" +
"option java_multiple_files = true;\n" +
"\n" +
"package schemavalidation;\n" +
"\n" +
"message SchemaValidationTest {\n" +
" optional int32 parameter = 1;\n" +
"}" , "[Transport Configuration] invalid attributes proto schema provided! Schema options don't support!" ) ;
}
@Test
public void testSaveProtoDeviceProfilePublicImportsNotSupported ( ) throws Exception {
testSaveDeviceProfileWithInvalidProtoSchema ( "syntax = \"proto3\";\n" +
"\n" +
"import public \"oldschema.proto\";\n" +
"\n" +
"package schemavalidation;\n" +
"\n" +
"message SchemaValidationTest {\n" +
" optional int32 parameter = 1;\n" +
"}" , "[Transport Configuration] invalid attributes proto schema provided! Schema public imports don't support!" ) ;
"\n" +
"import public \"oldschema.proto\";\n" +
"\n" +
"package schemavalidation;\n" +
"\n" +
"message SchemaValidationTest {\n" +
" optional int32 parameter = 1;\n" +
"}" , "[Transport Configuration] invalid attributes proto schema provided! Schema public imports don't support!" ) ;
}
@Test
public void testSaveProtoDeviceProfileImportsNotSupported ( ) throws Exception {
testSaveDeviceProfileWithInvalidProtoSchema ( "syntax = \"proto3\";\n" +
"\n" +
"import \"oldschema.proto\";\n" +
"\n" +
"package schemavalidation;\n" +
"\n" +
"message SchemaValidationTest {\n" +
" optional int32 parameter = 1;\n" +
"}" , "[Transport Configuration] invalid attributes proto schema provided! Schema imports don't support!" ) ;
"\n" +
"import \"oldschema.proto\";\n" +
"\n" +
"package schemavalidation;\n" +
"\n" +
"message SchemaValidationTest {\n" +
" optional int32 parameter = 1;\n" +
"}" , "[Transport Configuration] invalid attributes proto schema provided! Schema imports don't support!" ) ;
}
@Test
public void testSaveProtoDeviceProfileExtendDeclarationsNotSupported ( ) throws Exception {
testSaveDeviceProfileWithInvalidProtoSchema ( "syntax = \"proto3\";\n" +
"\n" +
"package schemavalidation;\n" +
"\n" +
"extend google.protobuf.MethodOptions {\n" +
" MyMessage my_method_option = 50007;\n" +
"}" , "[Transport Configuration] invalid attributes proto schema provided! Schema extend declarations don't support!" ) ;
"\n" +
"package schemavalidation;\n" +
"\n" +
"extend google.protobuf.MethodOptions {\n" +
" MyMessage my_method_option = 50007;\n" +
"}" , "[Transport Configuration] invalid attributes proto schema provided! Schema extend declarations don't support!" ) ;
}
@Test
public void testSaveProtoDeviceProfileEnumOptionsNotSupported ( ) throws Exception {
testSaveDeviceProfileWithInvalidProtoSchema ( "syntax = \"proto3\";\n" +
"\n" +
"package schemavalidation;\n" +
"\n" +
"enum testEnum {\n" +
" option allow_alias = true;\n" +
" DEFAULT = 0;\n" +
" STARTED = 1;\n" +
" RUNNING = 2;\n" +
"}\n" +
"\n" +
"message testMessage {\n" +
" optional int32 parameter = 1;\n" +
"}" , "[Transport Configuration] invalid attributes proto schema provided! Enum definitions options are not supported!" ) ;
"\n" +
"package schemavalidation;\n" +
"\n" +
"enum testEnum {\n" +
" option allow_alias = true;\n" +
" DEFAULT = 0;\n" +
" STARTED = 1;\n" +
" RUNNING = 2;\n" +
"}\n" +
"\n" +
"message testMessage {\n" +
" optional int32 parameter = 1;\n" +
"}" , "[Transport Configuration] invalid attributes proto schema provided! Enum definitions options are not supported!" ) ;
}
@Test
public void testSaveProtoDeviceProfileNoOneMessageTypeExists ( ) throws Exception {
testSaveDeviceProfileWithInvalidProtoSchema ( "syntax = \"proto3\";\n" +
"\n" +
"package schemavalidation;\n" +
"\n" +
"enum testEnum {\n" +
" DEFAULT = 0;\n" +
" STARTED = 1;\n" +
" RUNNING = 2;\n" +
"}" , "[Transport Configuration] invalid attributes proto schema provided! At least one Message definition should exists!" ) ;
"\n" +
"package schemavalidation;\n" +
"\n" +
"enum testEnum {\n" +
" DEFAULT = 0;\n" +
" STARTED = 1;\n" +
" RUNNING = 2;\n" +
"}" , "[Transport Configuration] invalid attributes proto schema provided! At least one Message definition should exists!" ) ;
}
@Test
public void testSaveProtoDeviceProfileMessageTypeOptionsNotSupported ( ) throws Exception {
testSaveDeviceProfileWithInvalidProtoSchema ( "syntax = \"proto3\";\n" +
"\n" +
"package schemavalidation;\n" +
"\n" +
"message testMessage {\n" +
" option allow_alias = true;\n" +
" optional int32 parameter = 1;\n" +
"}" , "[Transport Configuration] invalid attributes proto schema provided! Message definition options don't support!" ) ;
"\n" +
"package schemavalidation;\n" +
"\n" +
"message testMessage {\n" +
" option allow_alias = true;\n" +
" optional int32 parameter = 1;\n" +
"}" , "[Transport Configuration] invalid attributes proto schema provided! Message definition options don't support!" ) ;
}
@Test
public void testSaveProtoDeviceProfileMessageTypeExtensionsNotSupported ( ) throws Exception {
testSaveDeviceProfileWithInvalidProtoSchema ( "syntax = \"proto3\";\n" +
"\n" +
"package schemavalidation;\n" +
"\n" +
"message TestMessage {\n" +
" extensions 100 to 199;\n" +
"}" , "[Transport Configuration] invalid attributes proto schema provided! Message definition extensions don't support!" ) ;
"\n" +
"package schemavalidation;\n" +
"\n" +
"message TestMessage {\n" +
" extensions 100 to 199;\n" +
"}" , "[Transport Configuration] invalid attributes proto schema provided! Message definition extensions don't support!" ) ;
}
@Test
public void testSaveProtoDeviceProfileMessageTypeReservedElementsNotSupported ( ) throws Exception {
testSaveDeviceProfileWithInvalidProtoSchema ( "syntax = \"proto3\";\n" +
"\n" +
"package schemavalidation;\n" +
"\n" +
"message Foo {\n" +
" reserved 2, 15, 9 to 11;\n" +
" reserved \"foo\", \"bar\";\n" +
"}" , "[Transport Configuration] invalid attributes proto schema provided! Message definition reserved elements don't support!" ) ;
"\n" +
"package schemavalidation;\n" +
"\n" +
"message Foo {\n" +
" reserved 2, 15, 9 to 11;\n" +
" reserved \"foo\", \"bar\";\n" +
"}" , "[Transport Configuration] invalid attributes proto schema provided! Message definition reserved elements don't support!" ) ;
}
@Test
public void testSaveProtoDeviceProfileMessageTypeGroupsElementsNotSupported ( ) throws Exception {
testSaveDeviceProfileWithInvalidProtoSchema ( "syntax = \"proto3\";\n" +
"\n" +
"package schemavalidation;\n" +
"\n" +
"message TestMessage {\n" +
" repeated group Result = 1 {\n" +
" optional string url = 2;\n" +
" optional string title = 3;\n" +
" repeated string snippets = 4;\n" +
" }\n" +
"}" , "[Transport Configuration] invalid attributes proto schema provided! Message definition groups don't support!" ) ;
"\n" +
"package schemavalidation;\n" +
"\n" +
"message TestMessage {\n" +
" repeated group Result = 1 {\n" +
" optional string url = 2;\n" +
" optional string title = 3;\n" +
" repeated string snippets = 4;\n" +
" }\n" +
"}" , "[Transport Configuration] invalid attributes proto schema provided! Message definition groups don't support!" ) ;
}
@Test
public void testSaveProtoDeviceProfileOneOfsGroupsElementsNotSupported ( ) throws Exception {
testSaveDeviceProfileWithInvalidProtoSchema ( "syntax = \"proto3\";\n" +
"\n" +
"package schemavalidation;\n" +
"\n" +
"message SampleMessage {\n" +
" oneof test_oneof {\n" +
" string name = 1;\n" +
" group Result = 2 {\n" +
" \tstring url = 3;\n" +
" \tstring title = 4;\n" +
" \trepeated string snippets = 5;\n" +
" }\n" +
" }" +
"}" , "[Transport Configuration] invalid attributes proto schema provided! OneOf definition groups don't support!" ) ;
"\n" +
"package schemavalidation;\n" +
"\n" +
"message SampleMessage {\n" +
" oneof test_oneof {\n" +
" string name = 1;\n" +
" group Result = 2 {\n" +
" \tstring url = 3;\n" +
" \tstring title = 4;\n" +
" \trepeated string snippets = 5;\n" +
" }\n" +
" }" +
"}" , "[Transport Configuration] invalid attributes proto schema provided! OneOf definition groups don't support!" ) ;
}
@Test
public void testSaveProtoDeviceProfileWithInvalidTelemetrySchemaTsField ( ) throws Exception {
testSaveDeviceProfileWithInvalidProtoSchema ( "syntax =\"proto3\";\n" +
"\n" +
"package schemavalidation;\n" +
"\n" +
"message PostTelemetry {\n" +
" int64 ts = 1;\n" +
" Values values = 2;\n" +
" \n" +
" message Values {\n" +
" string key1 = 3;\n" +
" bool key2 = 4;\n" +
" double key3 = 5;\n" +
" int32 key4 = 6;\n" +
" JsonObject key5 = 7;\n" +
" }\n" +
" \n" +
" message JsonObject {\n" +
" optional int32 someNumber = 8;\n" +
" repeated int32 someArray = 9;\n" +
" NestedJsonObject someNestedObject = 10;\n" +
" message NestedJsonObject {\n" +
" optional string key = 11;\n" +
" }\n" +
" }\n" +
"}" , "[Transport Configuration] invalid telemetry proto schema provided! Field 'ts' has invalid label. Field 'ts' should have optional keyword!" ) ;
"\n" +
"package schemavalidation;\n" +
"\n" +
"message PostTelemetry {\n" +
" int64 ts = 1;\n" +
" Values values = 2;\n" +
" \n" +
" message Values {\n" +
" string key1 = 3;\n" +
" bool key2 = 4;\n" +
" double key3 = 5;\n" +
" int32 key4 = 6;\n" +
" JsonObject key5 = 7;\n" +
" }\n" +
" \n" +
" message JsonObject {\n" +
" optional int32 someNumber = 8;\n" +
" repeated int32 someArray = 9;\n" +
" NestedJsonObject someNestedObject = 10;\n" +
" message NestedJsonObject {\n" +
" optional string key = 11;\n" +
" }\n" +
" }\n" +
"}" , "[Transport Configuration] invalid telemetry proto schema provided! Field 'ts' has invalid label. Field 'ts' should have optional keyword!" ) ;
}
@Test
public void testSaveProtoDeviceProfileWithInvalidTelemetrySchemaTsDateType ( ) throws Exception {
testSaveDeviceProfileWithInvalidProtoSchema ( "syntax =\"proto3\";\n" +
"\n" +
"package schemavalidation;\n" +
"\n" +
"message PostTelemetry {\n" +
" optional int32 ts = 1;\n" +
" Values values = 2;\n" +
" \n" +
" message Values {\n" +
" string key1 = 3;\n" +
" bool key2 = 4;\n" +
" double key3 = 5;\n" +
" int32 key4 = 6;\n" +
" JsonObject key5 = 7;\n" +
" }\n" +
" \n" +
" message JsonObject {\n" +
" optional int32 someNumber = 8;\n" +
" }\n" +
"}" , "[Transport Configuration] invalid telemetry proto schema provided! Field 'ts' has invalid data type. Only int64 type is supported!" ) ;
"\n" +
"package schemavalidation;\n" +
"\n" +
"message PostTelemetry {\n" +
" optional int32 ts = 1;\n" +
" Values values = 2;\n" +
" \n" +
" message Values {\n" +
" string key1 = 3;\n" +
" bool key2 = 4;\n" +
" double key3 = 5;\n" +
" int32 key4 = 6;\n" +
" JsonObject key5 = 7;\n" +
" }\n" +
" \n" +
" message JsonObject {\n" +
" optional int32 someNumber = 8;\n" +
" }\n" +
"}" , "[Transport Configuration] invalid telemetry proto schema provided! Field 'ts' has invalid data type. Only int64 type is supported!" ) ;
}
@Test
public void testSaveProtoDeviceProfileWithInvalidTelemetrySchemaValuesDateType ( ) throws Exception {
testSaveDeviceProfileWithInvalidProtoSchema ( "syntax =\"proto3\";\n" +
"\n" +
"package schemavalidation;\n" +
"\n" +
"message PostTelemetry {\n" +
" optional int64 ts = 1;\n" +
" string values = 2;\n" +
" \n" +
"}" , "[Transport Configuration] invalid telemetry proto schema provided! Field 'values' has invalid data type. Only message type is supported!" ) ;
"\n" +
"package schemavalidation;\n" +
"\n" +
"message PostTelemetry {\n" +
" optional int64 ts = 1;\n" +
" string values = 2;\n" +
" \n" +
"}" , "[Transport Configuration] invalid telemetry proto schema provided! Field 'values' has invalid data type. Only message type is supported!" ) ;
}
@Test
public void testSaveProtoDeviceProfileWithInvalidRpcRequestSchemaMethodDateType ( ) throws Exception {
testSaveDeviceProfileWithInvalidRpcRequestProtoSchema ( "syntax =\"proto3\";\n" +
"\n" +
"package schemavalidation;\n" +
"\n" +
"message RpcRequestMsg {\n" +
" optional int32 method = 1;\n" +
" optional int32 requestId = 2;\n" +
" optional string params = 3;\n" +
" \n" +
"}" , "[Transport Configuration] invalid rpc request proto schema provided! Field 'method' has invalid data type. Only string type is supported!" ) ;
"\n" +
"package schemavalidation;\n" +
"\n" +
"message RpcRequestMsg {\n" +
" optional int32 method = 1;\n" +
" optional int32 requestId = 2;\n" +
" optional string params = 3;\n" +
" \n" +
"}" , "[Transport Configuration] invalid rpc request proto schema provided! Field 'method' has invalid data type. Only string type is supported!" ) ;
}
@Test
public void testSaveProtoDeviceProfileWithInvalidRpcRequestSchemaRequestIdDateType ( ) throws Exception {
testSaveDeviceProfileWithInvalidRpcRequestProtoSchema ( "syntax =\"proto3\";\n" +
"\n" +
"package schemavalidation;\n" +
"\n" +
"message RpcRequestMsg {\n" +
" optional string method = 1;\n" +
" optional int64 requestId = 2;\n" +
" optional string params = 3;\n" +
" \n" +
"}" , "[Transport Configuration] invalid rpc request proto schema provided! Field 'requestId' has invalid data type. Only int32 type is supported!" ) ;
"\n" +
"package schemavalidation;\n" +
"\n" +
"message RpcRequestMsg {\n" +
" optional string method = 1;\n" +
" optional int64 requestId = 2;\n" +
" optional string params = 3;\n" +
" \n" +
"}" , "[Transport Configuration] invalid rpc request proto schema provided! Field 'requestId' has invalid data type. Only int32 type is supported!" ) ;
}
@Test
public void testSaveProtoDeviceProfileWithInvalidRpcRequestSchemaMethodLabel ( ) throws Exception {
testSaveDeviceProfileWithInvalidRpcRequestProtoSchema ( "syntax =\"proto3\";\n" +
"\n" +
"package schemavalidation;\n" +
"\n" +
"message RpcRequestMsg {\n" +
" repeated string method = 1;\n" +
" optional int32 requestId = 2;\n" +
" optional string params = 3;\n" +
" \n" +
"}" , "[Transport Configuration] invalid rpc request proto schema provided! Field 'method' has invalid label!" ) ;
"\n" +
"package schemavalidation;\n" +
"\n" +
"message RpcRequestMsg {\n" +
" repeated string method = 1;\n" +
" optional int32 requestId = 2;\n" +
" optional string params = 3;\n" +
" \n" +
"}" , "[Transport Configuration] invalid rpc request proto schema provided! Field 'method' has invalid label!" ) ;
}
@Test
public void testSaveProtoDeviceProfileWithInvalidRpcRequestSchemaRequestIdLabel ( ) throws Exception {
testSaveDeviceProfileWithInvalidRpcRequestProtoSchema ( "syntax =\"proto3\";\n" +
"\n" +
"package schemavalidation;\n" +
"\n" +
"message RpcRequestMsg {\n" +
" optional string method = 1;\n" +
" repeated int32 requestId = 2;\n" +
" optional string params = 3;\n" +
" \n" +
"}" , "[Transport Configuration] invalid rpc request proto schema provided! Field 'requestId' has invalid label!" ) ;
"\n" +
"package schemavalidation;\n" +
"\n" +
"message RpcRequestMsg {\n" +
" optional string method = 1;\n" +
" repeated int32 requestId = 2;\n" +
" optional string params = 3;\n" +
" \n" +
"}" , "[Transport Configuration] invalid rpc request proto schema provided! Field 'requestId' has invalid label!" ) ;
}
@Test
public void testSaveProtoDeviceProfileWithInvalidRpcRequestSchemaParamsLabel ( ) throws Exception {
testSaveDeviceProfileWithInvalidRpcRequestProtoSchema ( "syntax =\"proto3\";\n" +
"\n" +
"package schemavalidation;\n" +
"\n" +
"message RpcRequestMsg {\n" +
" optional string method = 1;\n" +
" optional int32 requestId = 2;\n" +
" repeated string params = 3;\n" +
" \n" +
"}" , "[Transport Configuration] invalid rpc request proto schema provided! Field 'params' has invalid label!" ) ;
"\n" +
"package schemavalidation;\n" +
"\n" +
"message RpcRequestMsg {\n" +
" optional string method = 1;\n" +
" optional int32 requestId = 2;\n" +
" repeated string params = 3;\n" +
" \n" +
"}" , "[Transport Configuration] invalid rpc request proto schema provided! Field 'params' has invalid label!" ) ;
}
@Test
public void testSaveProtoDeviceProfileWithInvalidRpcRequestSchemaFieldsCount ( ) throws Exception {
testSaveDeviceProfileWithInvalidRpcRequestProtoSchema ( "syntax =\"proto3\";\n" +
"\n" +
"package schemavalidation;\n" +
"\n" +
"message RpcRequestMsg {\n" +
" optional int32 requestId = 2;\n" +
" optional string params = 3;\n" +
" \n" +
"}" , "[Transport Configuration] invalid rpc request proto schema provided! RpcRequestMsg message should always contains 3 fields: method, requestId and params!" ) ;
"\n" +
"package schemavalidation;\n" +
"\n" +
"message RpcRequestMsg {\n" +
" optional int32 requestId = 2;\n" +
" optional string params = 3;\n" +
" \n" +
"}" , "[Transport Configuration] invalid rpc request proto schema provided! RpcRequestMsg message should always contains 3 fields: method, requestId and params!" ) ;
}
@Test
public void testSaveProtoDeviceProfileWithInvalidRpcRequestSchemaFieldMethodIsNoSet ( ) throws Exception {
testSaveDeviceProfileWithInvalidRpcRequestProtoSchema ( "syntax =\"proto3\";\n" +
"\n" +
"package schemavalidation;\n" +
"\n" +
"message RpcRequestMsg {\n" +
" optional string methodName = 1;\n" +
" optional int32 requestId = 2;\n" +
" optional string params = 3;\n" +
" \n" +
"}" , "[Transport Configuration] invalid rpc request proto schema provided! Failed to get field descriptor for field: method!" ) ;
"\n" +
"package schemavalidation;\n" +
"\n" +
"message RpcRequestMsg {\n" +
" optional string methodName = 1;\n" +
" optional int32 requestId = 2;\n" +
" optional string params = 3;\n" +
" \n" +
"}" , "[Transport Configuration] invalid rpc request proto schema provided! Failed to get field descriptor for field: method!" ) ;
}
@Test
public void testSaveProtoDeviceProfileWithInvalidRpcRequestSchemaFieldRequestIdIsNotSet ( ) throws Exception {
testSaveDeviceProfileWithInvalidRpcRequestProtoSchema ( "syntax =\"proto3\";\n" +
"\n" +
"package schemavalidation;\n" +
"\n" +
"message RpcRequestMsg {\n" +
" optional string method = 1;\n" +
" optional int32 requestIdentifier = 2;\n" +
" optional string params = 3;\n" +
" \n" +
"}" , "[Transport Configuration] invalid rpc request proto schema provided! Failed to get field descriptor for field: requestId!" ) ;
"\n" +
"package schemavalidation;\n" +
"\n" +
"message RpcRequestMsg {\n" +
" optional string method = 1;\n" +
" optional int32 requestIdentifier = 2;\n" +
" optional string params = 3;\n" +
" \n" +
"}" , "[Transport Configuration] invalid rpc request proto schema provided! Failed to get field descriptor for field: requestId!" ) ;
}
@Test
public void testSaveProtoDeviceProfileWithInvalidRpcRequestSchemaFieldParamsIsNotSet ( ) throws Exception {
testSaveDeviceProfileWithInvalidRpcRequestProtoSchema ( "syntax =\"proto3\";\n" +
"\n" +
"package schemavalidation;\n" +
"\n" +
"message RpcRequestMsg {\n" +
" optional string method = 1;\n" +
" optional int32 requestId = 2;\n" +
" optional string parameters = 3;\n" +
" \n" +
"}" , "[Transport Configuration] invalid rpc request proto schema provided! Failed to get field descriptor for field: params!" ) ;
"\n" +
"package schemavalidation;\n" +
"\n" +
"message RpcRequestMsg {\n" +
" optional string method = 1;\n" +
" optional int32 requestId = 2;\n" +
" optional string parameters = 3;\n" +
" \n" +
"}" , "[Transport Configuration] invalid rpc request proto schema provided! Failed to get field descriptor for field: params!" ) ;
}
@Test
@ -1068,11 +1071,17 @@ public class DeviceProfileControllerTest extends AbstractControllerTest {
MqttDeviceProfileTransportConfiguration mqttDeviceProfileTransportConfiguration = this . createMqttDeviceProfileTransportConfiguration ( protoTransportPayloadConfiguration , false ) ;
DeviceProfile deviceProfile = this . createDeviceProfile ( "Device Profile" , mqttDeviceProfileTransportConfiguration ) ;
Mockito . reset ( tbClusterService , auditLogService ) ;
doPost ( "/api/deviceProfile" , deviceProfile )
. andExpect ( status ( ) . isBadRequest ( ) )
. andExpect ( statusReason ( containsString ( errorMsg ) ) ) ;
// The request may hit a transient TenantNotFoundException right after the @Before tenant creation
// if the tenant profile cache is not yet warmed up for the newly created tenant. Retry until the
// request returns the expected 400 Bad Request for the invalid schema. Mockito.reset is inside the
// retry loop so the subsequent verify* assertions see only the invocations from the last attempt.
Awaitility . await ( ) . atMost ( 10 , TimeUnit . SECONDS ) . pollInterval ( 500 , TimeUnit . MILLISECONDS )
. ignoreExceptions ( ) . untilAsserted ( ( ) - > {
Mockito . reset ( tbClusterService , auditLogService ) ;
doPost ( "/api/deviceProfile" , deviceProfile )
. andExpect ( status ( ) . isBadRequest ( ) )
. andExpect ( statusReason ( containsString ( errorMsg ) ) ) ;
} ) ;
testNotifyEntityEqualsOneTimeServiceNeverError ( deviceProfile , savedTenant . getId ( ) ,
tenantAdmin . getId ( ) , tenantAdmin . getEmail ( ) , ActionType . ADDED , new DataValidationException ( errorMsg ) ) ;