Search in sources :

Example 6 with DeviceProfile

use of org.thingsboard.server.common.data.DeviceProfile 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 7 with DeviceProfile

use of org.thingsboard.server.common.data.DeviceProfile in project thingsboard by thingsboard.

the class BaseDeviceProfileControllerTest method testSaveDeviceProfileWithEmptyName.

@Test
public void testSaveDeviceProfileWithEmptyName() throws Exception {
    DeviceProfile deviceProfile = new DeviceProfile();
    doPost("/api/deviceProfile", deviceProfile).andExpect(status().isBadRequest()).andExpect(statusReason(containsString("Device profile name should be specified")));
}
Also used : DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) Test(org.junit.Test)

Example 8 with DeviceProfile

use of org.thingsboard.server.common.data.DeviceProfile in project thingsboard by thingsboard.

the class BaseDeviceProfileControllerTest method testChangeDeviceProfileTypeWithExistingDevices.

@Ignore
@Test
public void testChangeDeviceProfileTypeWithExistingDevices() throws Exception {
    DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile", null);
    DeviceProfile savedDeviceProfile = doPost("/api/deviceProfile", deviceProfile, DeviceProfile.class);
    Device device = new Device();
    device.setName("Test device");
    device.setType("default");
    device.setDeviceProfileId(savedDeviceProfile.getId());
    doPost("/api/device", device, Device.class);
    // TODO uncomment once we have other device types;
    // savedDeviceProfile.setType(DeviceProfileType.LWM2M);
    doPost("/api/deviceProfile", savedDeviceProfile).andExpect(status().isBadRequest()).andExpect(statusReason(containsString("Can't change device profile type because devices referenced it")));
}
Also used : DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) Device(org.thingsboard.server.common.data.Device) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 9 with DeviceProfile

use of org.thingsboard.server.common.data.DeviceProfile in project thingsboard by thingsboard.

the class BaseDeviceProfileControllerTest method testFindDeviceProfiles.

@Test
public void testFindDeviceProfiles() throws Exception {
    List<DeviceProfile> deviceProfiles = new ArrayList<>();
    PageLink pageLink = new PageLink(17);
    PageData<DeviceProfile> pageData = doGetTypedWithPageLink("/api/deviceProfiles?", new TypeReference<PageData<DeviceProfile>>() {
    }, pageLink);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertEquals(1, pageData.getTotalElements());
    deviceProfiles.addAll(pageData.getData());
    for (int i = 0; i < 28; i++) {
        DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile" + i, null);
        deviceProfiles.add(doPost("/api/deviceProfile", deviceProfile, DeviceProfile.class));
    }
    List<DeviceProfile> loadedDeviceProfiles = new ArrayList<>();
    pageLink = new PageLink(17);
    do {
        pageData = doGetTypedWithPageLink("/api/deviceProfiles?", new TypeReference<PageData<DeviceProfile>>() {
        }, pageLink);
        loadedDeviceProfiles.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageLink.nextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(deviceProfiles, idComparator);
    Collections.sort(loadedDeviceProfiles, idComparator);
    Assert.assertEquals(deviceProfiles, loadedDeviceProfiles);
    for (DeviceProfile deviceProfile : loadedDeviceProfiles) {
        if (!deviceProfile.isDefault()) {
            doDelete("/api/deviceProfile/" + deviceProfile.getId().getId().toString()).andExpect(status().isOk());
        }
    }
    pageLink = new PageLink(17);
    pageData = doGetTypedWithPageLink("/api/deviceProfiles?", new TypeReference<PageData<DeviceProfile>>() {
    }, pageLink);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertEquals(1, pageData.getTotalElements());
}
Also used : DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) PageData(org.thingsboard.server.common.data.page.PageData) ArrayList(java.util.ArrayList) PageLink(org.thingsboard.server.common.data.page.PageLink) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Test(org.junit.Test)

Example 10 with DeviceProfile

use of org.thingsboard.server.common.data.DeviceProfile in project thingsboard by thingsboard.

the class BaseDeviceProfileControllerTest method testDeleteDeviceProfileWithExistingDevice.

@Test
public void testDeleteDeviceProfileWithExistingDevice() throws Exception {
    DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile", null);
    DeviceProfile savedDeviceProfile = doPost("/api/deviceProfile", deviceProfile, DeviceProfile.class);
    Device device = new Device();
    device.setName("Test device");
    device.setType("default");
    device.setDeviceProfileId(savedDeviceProfile.getId());
    Device savedDevice = doPost("/api/device", device, Device.class);
    doDelete("/api/deviceProfile/" + savedDeviceProfile.getId().getId().toString()).andExpect(status().isBadRequest()).andExpect(statusReason(containsString("The device profile referenced by the devices cannot be deleted")));
}
Also used : DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) Device(org.thingsboard.server.common.data.Device) Test(org.junit.Test)

Aggregations

DeviceProfile (org.thingsboard.server.common.data.DeviceProfile)110 Test (org.junit.Test)48 Device (org.thingsboard.server.common.data.Device)30 DeviceProfileData (org.thingsboard.server.common.data.device.profile.DeviceProfileData)26 List (java.util.List)20 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)19 TbMsg (org.thingsboard.server.common.msg.TbMsg)19 DeviceProfileAlarm (org.thingsboard.server.common.data.device.profile.DeviceProfileAlarm)18 TbMsgMetaData (org.thingsboard.server.common.msg.TbMsgMetaData)18 AlarmConditionFilterKey (org.thingsboard.server.common.data.device.profile.AlarmConditionFilterKey)17 AlarmRule (org.thingsboard.server.common.data.device.profile.AlarmRule)17 AlarmCondition (org.thingsboard.server.common.data.device.profile.AlarmCondition)16 AlarmConditionFilter (org.thingsboard.server.common.data.device.profile.AlarmConditionFilter)16 NumericFilterPredicate (org.thingsboard.server.common.data.query.NumericFilterPredicate)16 DynamicValue (org.thingsboard.server.common.data.query.DynamicValue)14 DeviceProfileId (org.thingsboard.server.common.data.id.DeviceProfileId)13 AttributeKvEntry (org.thingsboard.server.common.data.kv.AttributeKvEntry)13 AttributeKvCompositeKey (org.thingsboard.server.dao.model.sql.AttributeKvCompositeKey)13 AttributeKvEntity (org.thingsboard.server.dao.model.sql.AttributeKvEntity)13 UUID (java.util.UUID)12