Search in sources :

Example 1 with ProtoTransportPayloadConfiguration

use of org.thingsboard.server.common.data.device.profile.ProtoTransportPayloadConfiguration in project thingsboard by thingsboard.

the class BaseDeviceProfileControllerTest method testSaveDeviceProfileWithInvalidRpcRequestProtoSchema.

private void testSaveDeviceProfileWithInvalidRpcRequestProtoSchema(String schema, String errorMsg) throws Exception {
    ProtoTransportPayloadConfiguration protoTransportPayloadConfiguration = this.createProtoTransportPayloadConfiguration(schema, schema, schema, null);
    MqttDeviceProfileTransportConfiguration mqttDeviceProfileTransportConfiguration = this.createMqttDeviceProfileTransportConfiguration(protoTransportPayloadConfiguration);
    DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile", mqttDeviceProfileTransportConfiguration);
    doPost("/api/deviceProfile", deviceProfile).andExpect(status().isBadRequest()).andExpect(statusReason(containsString(errorMsg)));
}
Also used : DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) MqttDeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.MqttDeviceProfileTransportConfiguration) ProtoTransportPayloadConfiguration(org.thingsboard.server.common.data.device.profile.ProtoTransportPayloadConfiguration)

Example 2 with ProtoTransportPayloadConfiguration

use of org.thingsboard.server.common.data.device.profile.ProtoTransportPayloadConfiguration in project thingsboard by thingsboard.

the class BaseDeviceProfileControllerTest method testSaveDeviceProfileWithProtoPayloadType.

private DeviceProfile testSaveDeviceProfileWithProtoPayloadType(String schema) throws Exception {
    ProtoTransportPayloadConfiguration protoTransportPayloadConfiguration = this.createProtoTransportPayloadConfiguration(schema, schema, null, null);
    MqttDeviceProfileTransportConfiguration mqttDeviceProfileTransportConfiguration = this.createMqttDeviceProfileTransportConfiguration(protoTransportPayloadConfiguration);
    DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile", mqttDeviceProfileTransportConfiguration);
    DeviceProfile savedDeviceProfile = doPost("/api/deviceProfile", deviceProfile, DeviceProfile.class);
    DeviceProfile foundDeviceProfile = doGet("/api/deviceProfile/" + savedDeviceProfile.getId().getId().toString(), DeviceProfile.class);
    Assert.assertEquals(savedDeviceProfile.getName(), foundDeviceProfile.getName());
    return savedDeviceProfile;
}
Also used : DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) MqttDeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.MqttDeviceProfileTransportConfiguration) ProtoTransportPayloadConfiguration(org.thingsboard.server.common.data.device.profile.ProtoTransportPayloadConfiguration)

Example 3 with ProtoTransportPayloadConfiguration

use of org.thingsboard.server.common.data.device.profile.ProtoTransportPayloadConfiguration in project thingsboard by thingsboard.

the class BaseDeviceProfileControllerTest method testSaveDeviceProfileWithInvalidProtoSchema.

private void testSaveDeviceProfileWithInvalidProtoSchema(String schema, String errorMsg) throws Exception {
    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)));
}
Also used : DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) MqttDeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.MqttDeviceProfileTransportConfiguration) ProtoTransportPayloadConfiguration(org.thingsboard.server.common.data.device.profile.ProtoTransportPayloadConfiguration)

Example 4 with ProtoTransportPayloadConfiguration

use of org.thingsboard.server.common.data.device.profile.ProtoTransportPayloadConfiguration in project thingsboard by thingsboard.

the class AbstractCoapAttributesProtoIntegrationTest method testPushAttributesWithExplicitPresenceProtoKeys.

@Test
public void testPushAttributesWithExplicitPresenceProtoKeys() throws Exception {
    DeviceProfileTransportConfiguration transportConfiguration = deviceProfile.getProfileData().getTransportConfiguration();
    assertTrue(transportConfiguration instanceof CoapDeviceProfileTransportConfiguration);
    CoapDeviceProfileTransportConfiguration coapTransportConfiguration = (CoapDeviceProfileTransportConfiguration) transportConfiguration;
    CoapDeviceTypeConfiguration coapDeviceTypeConfiguration = coapTransportConfiguration.getCoapDeviceTypeConfiguration();
    assertTrue(coapDeviceTypeConfiguration instanceof DefaultCoapDeviceTypeConfiguration);
    DefaultCoapDeviceTypeConfiguration defaultCoapDeviceTypeConfiguration = (DefaultCoapDeviceTypeConfiguration) coapDeviceTypeConfiguration;
    TransportPayloadTypeConfiguration transportPayloadTypeConfiguration = defaultCoapDeviceTypeConfiguration.getTransportPayloadTypeConfiguration();
    assertTrue(transportPayloadTypeConfiguration instanceof ProtoTransportPayloadConfiguration);
    ProtoTransportPayloadConfiguration protoTransportPayloadConfiguration = (ProtoTransportPayloadConfiguration) transportPayloadTypeConfiguration;
    ProtoFileElement transportProtoSchemaFile = protoTransportPayloadConfiguration.getTransportProtoSchema(DEVICE_ATTRIBUTES_PROTO_SCHEMA);
    DynamicSchema attributesSchema = protoTransportPayloadConfiguration.getDynamicSchema(transportProtoSchemaFile, ProtoTransportPayloadConfiguration.ATTRIBUTES_PROTO_SCHEMA);
    DynamicMessage.Builder nestedJsonObjectBuilder = attributesSchema.newMessageBuilder("PostAttributes.JsonObject.NestedJsonObject");
    Descriptors.Descriptor nestedJsonObjectBuilderDescriptor = nestedJsonObjectBuilder.getDescriptorForType();
    assertNotNull(nestedJsonObjectBuilderDescriptor);
    DynamicMessage nestedJsonObject = nestedJsonObjectBuilder.setField(nestedJsonObjectBuilderDescriptor.findFieldByName("key"), "value").build();
    DynamicMessage.Builder jsonObjectBuilder = attributesSchema.newMessageBuilder("PostAttributes.JsonObject");
    Descriptors.Descriptor jsonObjectBuilderDescriptor = jsonObjectBuilder.getDescriptorForType();
    assertNotNull(jsonObjectBuilderDescriptor);
    DynamicMessage jsonObject = jsonObjectBuilder.addRepeatedField(jsonObjectBuilderDescriptor.findFieldByName("someArray"), 1).addRepeatedField(jsonObjectBuilderDescriptor.findFieldByName("someArray"), 2).addRepeatedField(jsonObjectBuilderDescriptor.findFieldByName("someArray"), 3).setField(jsonObjectBuilderDescriptor.findFieldByName("someNestedObject"), nestedJsonObject).build();
    DynamicMessage.Builder postAttributesBuilder = attributesSchema.newMessageBuilder("PostAttributes");
    Descriptors.Descriptor postAttributesMsgDescriptor = postAttributesBuilder.getDescriptorForType();
    assertNotNull(postAttributesMsgDescriptor);
    DynamicMessage postAttributesMsg = postAttributesBuilder.setField(postAttributesMsgDescriptor.findFieldByName("key1"), "").setField(postAttributesMsgDescriptor.findFieldByName("key5"), jsonObject).build();
    processAttributesTest(Arrays.asList("key1", "key5"), postAttributesMsg.toByteArray(), true);
}
Also used : CoapDeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.CoapDeviceProfileTransportConfiguration) DeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.DeviceProfileTransportConfiguration) ProtoTransportPayloadConfiguration(org.thingsboard.server.common.data.device.profile.ProtoTransportPayloadConfiguration) DefaultCoapDeviceTypeConfiguration(org.thingsboard.server.common.data.device.profile.DefaultCoapDeviceTypeConfiguration) TransportPayloadTypeConfiguration(org.thingsboard.server.common.data.device.profile.TransportPayloadTypeConfiguration) DefaultCoapDeviceTypeConfiguration(org.thingsboard.server.common.data.device.profile.DefaultCoapDeviceTypeConfiguration) CoapDeviceTypeConfiguration(org.thingsboard.server.common.data.device.profile.CoapDeviceTypeConfiguration) DynamicSchema(com.github.os72.protobuf.dynamic.DynamicSchema) DynamicMessage(com.google.protobuf.DynamicMessage) Descriptors(com.google.protobuf.Descriptors) ProtoFileElement(com.squareup.wire.schema.internal.parser.ProtoFileElement) CoapDeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.CoapDeviceProfileTransportConfiguration) Test(org.junit.Test)

Example 5 with ProtoTransportPayloadConfiguration

use of org.thingsboard.server.common.data.device.profile.ProtoTransportPayloadConfiguration in project thingsboard by thingsboard.

the class AbstractCoapTimeseriesProtoIntegrationTest method testPushTelemetryWithExplicitPresenceProtoKeys.

@Test
public void testPushTelemetryWithExplicitPresenceProtoKeys() throws Exception {
    processBeforeTest("Test Post Telemetry device proto payload", CoapDeviceType.DEFAULT, TransportPayloadType.PROTOBUF);
    DeviceProfileTransportConfiguration transportConfiguration = deviceProfile.getProfileData().getTransportConfiguration();
    assertTrue(transportConfiguration instanceof CoapDeviceProfileTransportConfiguration);
    CoapDeviceProfileTransportConfiguration coapDeviceProfileTransportConfiguration = (CoapDeviceProfileTransportConfiguration) transportConfiguration;
    CoapDeviceTypeConfiguration coapDeviceTypeConfiguration = coapDeviceProfileTransportConfiguration.getCoapDeviceTypeConfiguration();
    assertTrue(coapDeviceTypeConfiguration instanceof DefaultCoapDeviceTypeConfiguration);
    DefaultCoapDeviceTypeConfiguration defaultCoapDeviceTypeConfiguration = (DefaultCoapDeviceTypeConfiguration) coapDeviceTypeConfiguration;
    TransportPayloadTypeConfiguration transportPayloadTypeConfiguration = defaultCoapDeviceTypeConfiguration.getTransportPayloadTypeConfiguration();
    assertTrue(transportPayloadTypeConfiguration instanceof ProtoTransportPayloadConfiguration);
    ProtoTransportPayloadConfiguration protoTransportPayloadConfiguration = (ProtoTransportPayloadConfiguration) transportPayloadTypeConfiguration;
    ProtoFileElement transportProtoSchema = protoTransportPayloadConfiguration.getTransportProtoSchema(DEVICE_TELEMETRY_PROTO_SCHEMA);
    DynamicSchema telemetrySchema = protoTransportPayloadConfiguration.getDynamicSchema(transportProtoSchema, "telemetrySchema");
    DynamicMessage.Builder nestedJsonObjectBuilder = telemetrySchema.newMessageBuilder("PostTelemetry.JsonObject.NestedJsonObject");
    Descriptors.Descriptor nestedJsonObjectBuilderDescriptor = nestedJsonObjectBuilder.getDescriptorForType();
    assertNotNull(nestedJsonObjectBuilderDescriptor);
    DynamicMessage nestedJsonObject = nestedJsonObjectBuilder.setField(nestedJsonObjectBuilderDescriptor.findFieldByName("key"), "value").build();
    DynamicMessage.Builder jsonObjectBuilder = telemetrySchema.newMessageBuilder("PostTelemetry.JsonObject");
    Descriptors.Descriptor jsonObjectBuilderDescriptor = jsonObjectBuilder.getDescriptorForType();
    assertNotNull(jsonObjectBuilderDescriptor);
    DynamicMessage jsonObject = jsonObjectBuilder.addRepeatedField(jsonObjectBuilderDescriptor.findFieldByName("someArray"), 1).addRepeatedField(jsonObjectBuilderDescriptor.findFieldByName("someArray"), 2).addRepeatedField(jsonObjectBuilderDescriptor.findFieldByName("someArray"), 3).setField(jsonObjectBuilderDescriptor.findFieldByName("someNestedObject"), nestedJsonObject).build();
    DynamicMessage.Builder postTelemetryBuilder = telemetrySchema.newMessageBuilder("PostTelemetry");
    Descriptors.Descriptor postTelemetryMsgDescriptor = postTelemetryBuilder.getDescriptorForType();
    assertNotNull(postTelemetryMsgDescriptor);
    DynamicMessage postTelemetryMsg = postTelemetryBuilder.setField(postTelemetryMsgDescriptor.findFieldByName("key1"), "").setField(postTelemetryMsgDescriptor.findFieldByName("key2"), false).setField(postTelemetryMsgDescriptor.findFieldByName("key3"), 0.0).setField(postTelemetryMsgDescriptor.findFieldByName("key5"), jsonObject).build();
    processTestPostTelemetry(postTelemetryMsg.toByteArray(), Arrays.asList("key1", "key2", "key3", "key5"), false, true);
}
Also used : CoapDeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.CoapDeviceProfileTransportConfiguration) DeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.DeviceProfileTransportConfiguration) ProtoTransportPayloadConfiguration(org.thingsboard.server.common.data.device.profile.ProtoTransportPayloadConfiguration) DefaultCoapDeviceTypeConfiguration(org.thingsboard.server.common.data.device.profile.DefaultCoapDeviceTypeConfiguration) TransportPayloadTypeConfiguration(org.thingsboard.server.common.data.device.profile.TransportPayloadTypeConfiguration) DefaultCoapDeviceTypeConfiguration(org.thingsboard.server.common.data.device.profile.DefaultCoapDeviceTypeConfiguration) CoapDeviceTypeConfiguration(org.thingsboard.server.common.data.device.profile.CoapDeviceTypeConfiguration) DynamicSchema(com.github.os72.protobuf.dynamic.DynamicSchema) DynamicMessage(com.google.protobuf.DynamicMessage) Descriptors(com.google.protobuf.Descriptors) ProtoFileElement(com.squareup.wire.schema.internal.parser.ProtoFileElement) CoapDeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.CoapDeviceProfileTransportConfiguration) Test(org.junit.Test)

Aggregations

ProtoTransportPayloadConfiguration (org.thingsboard.server.common.data.device.profile.ProtoTransportPayloadConfiguration)23 TransportPayloadTypeConfiguration (org.thingsboard.server.common.data.device.profile.TransportPayloadTypeConfiguration)17 DeviceProfileTransportConfiguration (org.thingsboard.server.common.data.device.profile.DeviceProfileTransportConfiguration)15 ProtoFileElement (com.squareup.wire.schema.internal.parser.ProtoFileElement)13 MqttDeviceProfileTransportConfiguration (org.thingsboard.server.common.data.device.profile.MqttDeviceProfileTransportConfiguration)11 DynamicSchema (com.github.os72.protobuf.dynamic.DynamicSchema)10 Descriptors (com.google.protobuf.Descriptors)10 DynamicMessage (com.google.protobuf.DynamicMessage)10 CoapDeviceProfileTransportConfiguration (org.thingsboard.server.common.data.device.profile.CoapDeviceProfileTransportConfiguration)10 CoapDeviceTypeConfiguration (org.thingsboard.server.common.data.device.profile.CoapDeviceTypeConfiguration)10 DefaultCoapDeviceTypeConfiguration (org.thingsboard.server.common.data.device.profile.DefaultCoapDeviceTypeConfiguration)10 DeviceProfile (org.thingsboard.server.common.data.DeviceProfile)7 Test (org.junit.Test)6 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)2 CoapResponse (org.eclipse.californium.core.CoapResponse)2 MqttMessage (org.eclipse.paho.client.mqttv3.MqttMessage)2 AllowCreateNewDevicesDeviceProfileProvisionConfiguration (org.thingsboard.server.common.data.device.profile.AllowCreateNewDevicesDeviceProfileProvisionConfiguration)2 CheckPreProvisionedDevicesDeviceProfileProvisionConfiguration (org.thingsboard.server.common.data.device.profile.CheckPreProvisionedDevicesDeviceProfileProvisionConfiguration)2 DefaultDeviceProfileConfiguration (org.thingsboard.server.common.data.device.profile.DefaultDeviceProfileConfiguration)2 DeviceProfileData (org.thingsboard.server.common.data.device.profile.DeviceProfileData)2