Search in sources :

Example 6 with DeviceProfileInfo

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

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

the class BaseDeviceProfileServiceTest method testFindDefaultDeviceProfileInfo.

@Test
public void testFindDefaultDeviceProfileInfo() {
    DeviceProfileInfo foundDefaultDeviceProfileInfo = deviceProfileService.findDefaultDeviceProfileInfo(tenantId);
    Assert.assertNotNull(foundDefaultDeviceProfileInfo);
    Assert.assertNotNull(foundDefaultDeviceProfileInfo.getId());
    Assert.assertNotNull(foundDefaultDeviceProfileInfo.getName());
    Assert.assertNotNull(foundDefaultDeviceProfileInfo.getType());
}
Also used : DeviceProfileInfo(org.thingsboard.server.common.data.DeviceProfileInfo) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)7 DeviceProfileInfo (org.thingsboard.server.common.data.DeviceProfileInfo)7 DeviceProfile (org.thingsboard.server.common.data.DeviceProfile)5 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 After (org.junit.After)2 Assert (org.junit.Assert)2 Before (org.junit.Before)2 Ignore (org.junit.Ignore)2 Device (org.thingsboard.server.common.data.Device)2 DeviceTransportType (org.thingsboard.server.common.data.DeviceTransportType)2 Tenant (org.thingsboard.server.common.data.Tenant)2 PageData (org.thingsboard.server.common.data.page.PageData)2 PageLink (org.thingsboard.server.common.data.page.PageLink)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 DynamicSchema (com.github.os72.protobuf.dynamic.DynamicSchema)1 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1