Search in sources :

Example 81 with DeviceProfile

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

the class BaseDeviceProfileServiceTest method testDeleteDeviceProfile.

@Test
public void testDeleteDeviceProfile() {
    DeviceProfile deviceProfile = this.createDeviceProfile(tenantId, "Device Profile");
    DeviceProfile savedDeviceProfile = deviceProfileService.saveDeviceProfile(deviceProfile);
    deviceProfileService.deleteDeviceProfile(tenantId, savedDeviceProfile.getId());
    DeviceProfile foundDeviceProfile = deviceProfileService.findDeviceProfileById(tenantId, savedDeviceProfile.getId());
    Assert.assertNull(foundDeviceProfile);
}
Also used : DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) Test(org.junit.Test)

Example 82 with DeviceProfile

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

the class BaseDeviceProfileServiceTest method testChangeDeviceProfileTypeWithExistingDevices.

@Ignore
@Test(expected = DataValidationException.class)
public void testChangeDeviceProfileTypeWithExistingDevices() {
    DeviceProfile deviceProfile = this.createDeviceProfile(tenantId, "Device Profile");
    DeviceProfile savedDeviceProfile = deviceProfileService.saveDeviceProfile(deviceProfile);
    Device device = new Device();
    device.setTenantId(tenantId);
    device.setName("Test device");
    device.setType("default");
    device.setDeviceProfileId(savedDeviceProfile.getId());
    deviceService.saveDevice(device);
    // TODO: once we have more profile types, we should test that we can not change profile type in runtime and uncomment the @Ignore.
    // savedDeviceProfile.setType(DeviceProfileType.LWM2M);
    deviceProfileService.saveDeviceProfile(savedDeviceProfile);
}
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 83 with DeviceProfile

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

the class BaseDeviceProfileServiceTest method testFindDeviceProfiles.

@Test
public void testFindDeviceProfiles() {
    List<DeviceProfile> deviceProfiles = new ArrayList<>();
    PageLink pageLink = new PageLink(17);
    PageData<DeviceProfile> pageData = deviceProfileService.findDeviceProfiles(tenantId, 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(tenantId, "Device Profile" + i);
        deviceProfiles.add(deviceProfileService.saveDeviceProfile(deviceProfile));
    }
    List<DeviceProfile> loadedDeviceProfiles = new ArrayList<>();
    pageLink = new PageLink(17);
    do {
        pageData = deviceProfileService.findDeviceProfiles(tenantId, 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()) {
            deviceProfileService.deleteDeviceProfile(tenantId, deviceProfile.getId());
        }
    }
    pageLink = new PageLink(17);
    pageData = deviceProfileService.findDeviceProfiles(tenantId, pageLink);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertEquals(1, pageData.getTotalElements());
}
Also used : DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) ArrayList(java.util.ArrayList) PageLink(org.thingsboard.server.common.data.page.PageLink) Test(org.junit.Test)

Example 84 with DeviceProfile

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

the class BaseDeviceProfileServiceTest method testFindDeviceProfileInfos.

@Test
public void testFindDeviceProfileInfos() {
    List<DeviceProfile> deviceProfiles = new ArrayList<>();
    PageLink pageLink = new PageLink(17);
    PageData<DeviceProfile> deviceProfilePageData = deviceProfileService.findDeviceProfiles(tenantId, pageLink);
    Assert.assertFalse(deviceProfilePageData.hasNext());
    Assert.assertEquals(1, deviceProfilePageData.getTotalElements());
    deviceProfiles.addAll(deviceProfilePageData.getData());
    for (int i = 0; i < 28; i++) {
        DeviceProfile deviceProfile = this.createDeviceProfile(tenantId, "Device Profile" + i);
        deviceProfiles.add(deviceProfileService.saveDeviceProfile(deviceProfile));
    }
    List<DeviceProfileInfo> loadedDeviceProfileInfos = new ArrayList<>();
    pageLink = new PageLink(17);
    PageData<DeviceProfileInfo> pageData;
    do {
        pageData = deviceProfileService.findDeviceProfileInfos(tenantId, pageLink, null);
        loadedDeviceProfileInfos.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageLink.nextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(deviceProfiles, idComparator);
    Collections.sort(loadedDeviceProfileInfos, deviceProfileInfoIdComparator);
    List<DeviceProfileInfo> deviceProfileInfos = deviceProfiles.stream().map(deviceProfile -> new DeviceProfileInfo(deviceProfile.getId(), deviceProfile.getName(), deviceProfile.getImage(), deviceProfile.getDefaultDashboardId(), deviceProfile.getType(), deviceProfile.getTransportType())).collect(Collectors.toList());
    Assert.assertEquals(deviceProfileInfos, loadedDeviceProfileInfos);
    for (DeviceProfile deviceProfile : deviceProfiles) {
        if (!deviceProfile.isDefault()) {
            deviceProfileService.deleteDeviceProfile(tenantId, deviceProfile.getId());
        }
    }
    pageLink = new PageLink(17);
    pageData = deviceProfileService.findDeviceProfileInfos(tenantId, pageLink, null);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertEquals(1, pageData.getTotalElements());
}
Also used : MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Device(org.thingsboard.server.common.data.Device) FIRMWARE(org.thingsboard.server.common.data.ota.OtaPackageType.FIRMWARE) Tenant(org.thingsboard.server.common.data.Tenant) TenantId(org.thingsboard.server.common.data.id.TenantId) ByteBuffer(java.nio.ByteBuffer) ArrayList(java.util.ArrayList) ChecksumAlgorithm(org.thingsboard.server.common.data.ota.ChecksumAlgorithm) After(org.junit.After) DeviceTransportType(org.thingsboard.server.common.data.DeviceTransportType) Before(org.junit.Before) DeviceProfileInfo(org.thingsboard.server.common.data.DeviceProfileInfo) DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) PageLink(org.thingsboard.server.common.data.page.PageLink) OtaPackage(org.thingsboard.server.common.data.OtaPackage) Test(org.junit.Test) ThingsBoardThreadFactory(org.thingsboard.common.util.ThingsBoardThreadFactory) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) ExecutionException(java.util.concurrent.ExecutionException) DataValidationException(org.thingsboard.server.dao.exception.DataValidationException) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) Ignore(org.junit.Ignore) PageData(org.thingsboard.server.common.data.page.PageData) Assert(org.junit.Assert) Collections(java.util.Collections) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) DeviceProfileInfo(org.thingsboard.server.common.data.DeviceProfileInfo) ArrayList(java.util.ArrayList) PageLink(org.thingsboard.server.common.data.page.PageLink) Test(org.junit.Test)

Example 85 with DeviceProfile

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

the class BaseDeviceProfileServiceTest method testFindOrCreateDeviceProfile.

@Test
public void testFindOrCreateDeviceProfile() throws ExecutionException, InterruptedException {
    ListeningExecutorService testExecutor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(100, ThingsBoardThreadFactory.forName(getClass().getSimpleName() + "-test-scope")));
    try {
        List<ListenableFuture<DeviceProfile>> futures = new ArrayList<>();
        for (int i = 0; i < 50; i++) {
            futures.add(testExecutor.submit(() -> deviceProfileService.findOrCreateDeviceProfile(tenantId, "Device Profile 1")));
            futures.add(testExecutor.submit(() -> deviceProfileService.findOrCreateDeviceProfile(tenantId, "Device Profile 2")));
        }
        List<DeviceProfile> deviceProfiles = Futures.allAsList(futures).get();
        deviceProfiles.forEach(Assert::assertNotNull);
    } finally {
        testExecutor.shutdownNow();
    }
}
Also used : DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) Assert(org.junit.Assert) ArrayList(java.util.ArrayList) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) 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