updated deviceProfile proto transport configuration validation tests
This commit is contained in:
parent
c4133fa41a
commit
d769f6749c
@ -352,10 +352,12 @@ public abstract class AbstractWebTest {
|
|||||||
return mqttDeviceProfileTransportConfiguration;
|
return mqttDeviceProfileTransportConfiguration;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ProtoTransportPayloadConfiguration createProtoTransportPayloadConfiguration(String deviceAttributesProtoSchema, String deviceTelemetryProtoSchema) {
|
protected ProtoTransportPayloadConfiguration createProtoTransportPayloadConfiguration(String attributesProtoSchema, String telemetryProtoSchema, String rpcRequestProtoSchema, String rpcResponseProtoSchema) {
|
||||||
ProtoTransportPayloadConfiguration protoTransportPayloadConfiguration = new ProtoTransportPayloadConfiguration();
|
ProtoTransportPayloadConfiguration protoTransportPayloadConfiguration = new ProtoTransportPayloadConfiguration();
|
||||||
protoTransportPayloadConfiguration.setDeviceAttributesProtoSchema(deviceAttributesProtoSchema);
|
protoTransportPayloadConfiguration.setDeviceAttributesProtoSchema(attributesProtoSchema);
|
||||||
protoTransportPayloadConfiguration.setDeviceTelemetryProtoSchema(deviceTelemetryProtoSchema);
|
protoTransportPayloadConfiguration.setDeviceTelemetryProtoSchema(telemetryProtoSchema);
|
||||||
|
protoTransportPayloadConfiguration.setDeviceRpcRequestProtoSchema(rpcRequestProtoSchema);
|
||||||
|
protoTransportPayloadConfiguration.setDeviceRpcResponseProtoSchema(rpcResponseProtoSchema);
|
||||||
return protoTransportPayloadConfiguration;
|
return protoTransportPayloadConfiguration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -364,7 +364,7 @@ public abstract class BaseDeviceProfileControllerTest extends AbstractController
|
|||||||
"package schemavalidation;\n" +
|
"package schemavalidation;\n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
"message SchemaValidationTest {\n" +
|
"message SchemaValidationTest {\n" +
|
||||||
" int32 parameter = 1;\n" +
|
" optional int32 parameter = 1;\n" +
|
||||||
"}", "[Transport Configuration] invalid attributes proto schema provided! Schema options don't support!");
|
"}", "[Transport Configuration] invalid attributes proto schema provided! Schema options don't support!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -377,7 +377,7 @@ public abstract class BaseDeviceProfileControllerTest extends AbstractController
|
|||||||
"package schemavalidation;\n" +
|
"package schemavalidation;\n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
"message SchemaValidationTest {\n" +
|
"message SchemaValidationTest {\n" +
|
||||||
" int32 parameter = 1;\n" +
|
" optional int32 parameter = 1;\n" +
|
||||||
"}", "[Transport Configuration] invalid attributes proto schema provided! Schema public imports don't support!");
|
"}", "[Transport Configuration] invalid attributes proto schema provided! Schema public imports don't support!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -390,7 +390,7 @@ public abstract class BaseDeviceProfileControllerTest extends AbstractController
|
|||||||
"package schemavalidation;\n" +
|
"package schemavalidation;\n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
"message SchemaValidationTest {\n" +
|
"message SchemaValidationTest {\n" +
|
||||||
" int32 parameter = 1;\n" +
|
" optional int32 parameter = 1;\n" +
|
||||||
"}", "[Transport Configuration] invalid attributes proto schema provided! Schema imports don't support!");
|
"}", "[Transport Configuration] invalid attributes proto schema provided! Schema imports don't support!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -419,7 +419,7 @@ public abstract class BaseDeviceProfileControllerTest extends AbstractController
|
|||||||
"}\n" +
|
"}\n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
"message testMessage {\n" +
|
"message testMessage {\n" +
|
||||||
" int32 parameter = 1;\n" +
|
" optional int32 parameter = 1;\n" +
|
||||||
"}", "[Transport Configuration] invalid attributes proto schema provided! Enum definitions options are not supported!");
|
"}", "[Transport Configuration] invalid attributes proto schema provided! Enum definitions options are not supported!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -444,7 +444,7 @@ public abstract class BaseDeviceProfileControllerTest extends AbstractController
|
|||||||
"\n" +
|
"\n" +
|
||||||
"message testMessage {\n" +
|
"message testMessage {\n" +
|
||||||
" option allow_alias = true;\n" +
|
" option allow_alias = true;\n" +
|
||||||
" int32 parameter = 1;\n" +
|
" optional int32 parameter = 1;\n" +
|
||||||
"}", "[Transport Configuration] invalid attributes proto schema provided! Message definition options don't support!");
|
"}", "[Transport Configuration] invalid attributes proto schema provided! Message definition options don't support!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -479,8 +479,8 @@ public abstract class BaseDeviceProfileControllerTest extends AbstractController
|
|||||||
"\n" +
|
"\n" +
|
||||||
"message TestMessage {\n" +
|
"message TestMessage {\n" +
|
||||||
" repeated group Result = 1 {\n" +
|
" repeated group Result = 1 {\n" +
|
||||||
" string url = 2;\n" +
|
" optional string url = 2;\n" +
|
||||||
" string title = 3;\n" +
|
" optional string title = 3;\n" +
|
||||||
" repeated string snippets = 4;\n" +
|
" repeated string snippets = 4;\n" +
|
||||||
" }\n" +
|
" }\n" +
|
||||||
"}", "[Transport Configuration] invalid attributes proto schema provided! Message definition groups don't support!");
|
"}", "[Transport Configuration] invalid attributes proto schema provided! Message definition groups don't support!");
|
||||||
@ -513,15 +513,15 @@ public abstract class BaseDeviceProfileControllerTest extends AbstractController
|
|||||||
"message Outer {\n" +
|
"message Outer {\n" +
|
||||||
" message MiddleAA {\n" +
|
" message MiddleAA {\n" +
|
||||||
" message Inner {\n" +
|
" message Inner {\n" +
|
||||||
" int64 ival = 1;\n" +
|
" optional int64 ival = 1;\n" +
|
||||||
" bool booly = 2;\n" +
|
" optional bool booly = 2;\n" +
|
||||||
" }\n" +
|
" }\n" +
|
||||||
" Inner inner = 1;\n" +
|
" Inner inner = 1;\n" +
|
||||||
" }\n" +
|
" }\n" +
|
||||||
" message MiddleBB {\n" +
|
" message MiddleBB {\n" +
|
||||||
" message Inner {\n" +
|
" message Inner {\n" +
|
||||||
" int32 ival = 1;\n" +
|
" optional int32 ival = 1;\n" +
|
||||||
" bool booly = 2;\n" +
|
" optional bool booly = 2;\n" +
|
||||||
" }\n" +
|
" }\n" +
|
||||||
" Inner inner = 1;\n" +
|
" Inner inner = 1;\n" +
|
||||||
" }\n" +
|
" }\n" +
|
||||||
@ -599,6 +599,7 @@ public abstract class BaseDeviceProfileControllerTest extends AbstractController
|
|||||||
"}\n" +
|
"}\n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
"message SampleMessage {\n" +
|
"message SampleMessage {\n" +
|
||||||
|
" optional int32 id = 1;\n" +
|
||||||
" oneof testOneOf {\n" +
|
" oneof testOneOf {\n" +
|
||||||
" string name = 4;\n" +
|
" string name = 4;\n" +
|
||||||
" SubMessage subMessage = 9;\n" +
|
" SubMessage subMessage = 9;\n" +
|
||||||
@ -616,7 +617,7 @@ public abstract class BaseDeviceProfileControllerTest extends AbstractController
|
|||||||
assertNotNull(sampleMsgDescriptor);
|
assertNotNull(sampleMsgDescriptor);
|
||||||
|
|
||||||
List<Descriptors.FieldDescriptor> fields = sampleMsgDescriptor.getFields();
|
List<Descriptors.FieldDescriptor> fields = sampleMsgDescriptor.getFields();
|
||||||
assertEquals(2, fields.size());
|
assertEquals(3, fields.size());
|
||||||
DynamicMessage sampleMsg = sampleMsgBuilder
|
DynamicMessage sampleMsg = sampleMsgBuilder
|
||||||
.setField(sampleMsgDescriptor.findFieldByName("name"), "Bob")
|
.setField(sampleMsgDescriptor.findFieldByName("name"), "Bob")
|
||||||
.build();
|
.build();
|
||||||
@ -700,8 +701,133 @@ public abstract class BaseDeviceProfileControllerTest extends AbstractController
|
|||||||
"}", "[Transport Configuration] invalid telemetry proto schema provided! Field 'values' has invalid data type. Only message type is supported!");
|
"}", "[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!");
|
||||||
|
}
|
||||||
|
|
||||||
|
@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!");
|
||||||
|
}
|
||||||
|
|
||||||
|
@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!");
|
||||||
|
}
|
||||||
|
|
||||||
|
@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!");
|
||||||
|
}
|
||||||
|
|
||||||
|
@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!");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSaveProtoDeviceProfileWithInvalidRpcRequestSchemaFieldsCount() throws Exception {
|
||||||
|
testSaveDeviceProfileWithInvalidRpcRequestProtoSchema("syntax =\"proto3\";\n" +
|
||||||
|
"\n" +
|
||||||
|
"package schemavalidation;\n" +
|
||||||
|
"\n" +
|
||||||
|
"message RpcRequestMsg {\n" +
|
||||||
|
" optional int32 requestId = 2;\n" +
|
||||||
|
" repeated 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" +
|
||||||
|
" repeated 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" +
|
||||||
|
" repeated 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" +
|
||||||
|
" repeated string parameters = 3;\n" +
|
||||||
|
" \n" +
|
||||||
|
"}", "[Transport Configuration] invalid rpc request proto schema provided! Failed to get field descriptor for field: params!");
|
||||||
|
}
|
||||||
|
|
||||||
private DeviceProfile testSaveDeviceProfileWithProtoPayloadType(String schema) throws Exception {
|
private DeviceProfile testSaveDeviceProfileWithProtoPayloadType(String schema) throws Exception {
|
||||||
ProtoTransportPayloadConfiguration protoTransportPayloadConfiguration = this.createProtoTransportPayloadConfiguration(schema, schema);
|
ProtoTransportPayloadConfiguration protoTransportPayloadConfiguration = this.createProtoTransportPayloadConfiguration(schema, schema, null, null);
|
||||||
MqttDeviceProfileTransportConfiguration mqttDeviceProfileTransportConfiguration = this.createMqttDeviceProfileTransportConfiguration(protoTransportPayloadConfiguration);
|
MqttDeviceProfileTransportConfiguration mqttDeviceProfileTransportConfiguration = this.createMqttDeviceProfileTransportConfiguration(protoTransportPayloadConfiguration);
|
||||||
DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile", mqttDeviceProfileTransportConfiguration);
|
DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile", mqttDeviceProfileTransportConfiguration);
|
||||||
DeviceProfile savedDeviceProfile = doPost("/api/deviceProfile", deviceProfile, DeviceProfile.class);
|
DeviceProfile savedDeviceProfile = doPost("/api/deviceProfile", deviceProfile, DeviceProfile.class);
|
||||||
@ -711,7 +837,15 @@ public abstract class BaseDeviceProfileControllerTest extends AbstractController
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void testSaveDeviceProfileWithInvalidProtoSchema(String schema, String errorMsg) throws Exception {
|
private void testSaveDeviceProfileWithInvalidProtoSchema(String schema, String errorMsg) throws Exception {
|
||||||
ProtoTransportPayloadConfiguration protoTransportPayloadConfiguration = this.createProtoTransportPayloadConfiguration(schema, schema);
|
ProtoTransportPayloadConfiguration protoTransportPayloadConfiguration = this.createProtoTransportPayloadConfiguration(schema, schema, null, null);
|
||||||
|
MqttDeviceProfileTransportConfiguration mqttDeviceProfileTransportConfiguration = this.createMqttDeviceProfileTransportConfiguration(protoTransportPayloadConfiguration);
|
||||||
|
DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile", mqttDeviceProfileTransportConfiguration);
|
||||||
|
doPost("/api/deviceProfile", deviceProfile).andExpect(status().isBadRequest())
|
||||||
|
.andExpect(statusReason(containsString(errorMsg)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void testSaveDeviceProfileWithInvalidRpcRequestProtoSchema(String schema, String errorMsg) throws Exception {
|
||||||
|
ProtoTransportPayloadConfiguration protoTransportPayloadConfiguration = this.createProtoTransportPayloadConfiguration(schema, schema, schema, null);
|
||||||
MqttDeviceProfileTransportConfiguration mqttDeviceProfileTransportConfiguration = this.createMqttDeviceProfileTransportConfiguration(protoTransportPayloadConfiguration);
|
MqttDeviceProfileTransportConfiguration mqttDeviceProfileTransportConfiguration = this.createMqttDeviceProfileTransportConfiguration(protoTransportPayloadConfiguration);
|
||||||
DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile", mqttDeviceProfileTransportConfiguration);
|
DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile", mqttDeviceProfileTransportConfiguration);
|
||||||
doPost("/api/deviceProfile", deviceProfile).andExpect(status().isBadRequest())
|
doPost("/api/deviceProfile", deviceProfile).andExpect(status().isBadRequest())
|
||||||
|
|||||||
@ -29,6 +29,7 @@ import java.util.Arrays;
|
|||||||
// "org.thingsboard.server.controller.sql.WebsocketApiSqlTest",
|
// "org.thingsboard.server.controller.sql.WebsocketApiSqlTest",
|
||||||
// "org.thingsboard.server.controller.sql.EntityQueryControllerSqlTest",
|
// "org.thingsboard.server.controller.sql.EntityQueryControllerSqlTest",
|
||||||
// "org.thingsboard.server.controller.sql.TbResourceControllerSqlTest",
|
// "org.thingsboard.server.controller.sql.TbResourceControllerSqlTest",
|
||||||
|
// "org.thingsboard.server.controller.sql.DeviceProfileControllerSqlTest",
|
||||||
"org.thingsboard.server.controller.sql.*Test",
|
"org.thingsboard.server.controller.sql.*Test",
|
||||||
})
|
})
|
||||||
public class ControllerSqlTestSuite {
|
public class ControllerSqlTestSuite {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user