Search in sources :

Example 6 with DeviceInfo

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

the class BaseDeviceServiceTest method testFindDeviceInfoByTenantIdAndDeviceProfileId.

@Test
public void testFindDeviceInfoByTenantIdAndDeviceProfileId() {
    Customer customer = new Customer();
    customer.setTitle("Customer X");
    customer.setTenantId(tenantId);
    Customer savedCustomer = customerService.saveCustomer(customer);
    Device device = new Device();
    device.setTenantId(tenantId);
    device.setName("default");
    device.setLabel("label");
    device.setCustomerId(savedCustomer.getId());
    Device savedDevice = deviceService.saveDevice(device);
    PageLink pageLinkWithLabel = new PageLink(100, 0, "label");
    List<DeviceInfo> deviceInfosWithLabel = deviceService.findDeviceInfosByTenantIdAndDeviceProfileId(tenantId, savedDevice.getDeviceProfileId(), pageLinkWithLabel).getData();
    Assert.assertFalse(deviceInfosWithLabel.isEmpty());
    Assert.assertTrue(deviceInfosWithLabel.stream().anyMatch(d -> d.getId().equals(savedDevice.getId()) && d.getTenantId().equals(tenantId) && d.getDeviceProfileId().equals(savedDevice.getDeviceProfileId()) && d.getLabel().equals(savedDevice.getLabel())));
    PageLink pageLinkWithCustomer = new PageLink(100, 0, savedCustomer.getSearchText());
    List<DeviceInfo> deviceInfosWithCustomer = deviceService.findDeviceInfosByTenantIdAndDeviceProfileId(tenantId, savedDevice.getDeviceProfileId(), pageLinkWithCustomer).getData();
    Assert.assertFalse(deviceInfosWithCustomer.isEmpty());
    Assert.assertTrue(deviceInfosWithCustomer.stream().anyMatch(d -> d.getId().equals(savedDevice.getId()) && d.getTenantId().equals(tenantId) && d.getDeviceProfileId().equals(savedDevice.getDeviceProfileId()) && d.getCustomerId().equals(savedCustomer.getId()) && d.getCustomerTitle().equals(savedCustomer.getTitle())));
}
Also used : DeviceInfo(org.thingsboard.server.common.data.DeviceInfo) Device(org.thingsboard.server.common.data.Device) FIRMWARE(org.thingsboard.server.common.data.ota.OtaPackageType.FIRMWARE) Customer(org.thingsboard.server.common.data.Customer) Tenant(org.thingsboard.server.common.data.Tenant) DefaultTenantProfileConfiguration(org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileConfiguration) TenantId(org.thingsboard.server.common.data.id.TenantId) ByteBuffer(java.nio.ByteBuffer) ArrayList(java.util.ArrayList) ChecksumAlgorithm(org.thingsboard.server.common.data.ota.ChecksumAlgorithm) TenantProfile(org.thingsboard.server.common.data.TenantProfile) Uuids(com.datastax.oss.driver.api.core.uuid.Uuids) After(org.junit.After) ExpectedException(org.junit.rules.ExpectedException) Before(org.junit.Before) DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) PageLink(org.thingsboard.server.common.data.page.PageLink) OtaPackage(org.thingsboard.server.common.data.OtaPackage) DeviceCredentialsType(org.thingsboard.server.common.data.security.DeviceCredentialsType) NULL_UUID(org.thingsboard.server.dao.model.ModelConstants.NULL_UUID) DeviceCredentials(org.thingsboard.server.common.data.security.DeviceCredentials) Test(org.junit.Test) DataValidationException(org.thingsboard.server.dao.exception.DataValidationException) List(java.util.List) Rule(org.junit.Rule) PageData(org.thingsboard.server.common.data.page.PageData) RandomStringUtils(org.apache.commons.lang3.RandomStringUtils) EntitySubtype(org.thingsboard.server.common.data.EntitySubtype) Assert(org.junit.Assert) Collections(java.util.Collections) CustomerId(org.thingsboard.server.common.data.id.CustomerId) Customer(org.thingsboard.server.common.data.Customer) Device(org.thingsboard.server.common.data.Device) PageLink(org.thingsboard.server.common.data.page.PageLink) DeviceInfo(org.thingsboard.server.common.data.DeviceInfo) Test(org.junit.Test)

Aggregations

DeviceInfo (org.thingsboard.server.common.data.DeviceInfo)6 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)5 Device (org.thingsboard.server.common.data.Device)5 PageLink (org.thingsboard.server.common.data.page.PageLink)5 Customer (org.thingsboard.server.common.data.Customer)4 Tenant (org.thingsboard.server.common.data.Tenant)4 CustomerId (org.thingsboard.server.common.data.id.CustomerId)4 TenantId (org.thingsboard.server.common.data.id.TenantId)4 DataValidationException (org.thingsboard.server.dao.exception.DataValidationException)4 Uuids (com.datastax.oss.driver.api.core.uuid.Uuids)3 ByteBuffer (java.nio.ByteBuffer)3 Collections (java.util.Collections)3 List (java.util.List)3 RandomStringUtils (org.apache.commons.lang3.RandomStringUtils)3 After (org.junit.After)3 Assert (org.junit.Assert)3 Before (org.junit.Before)3 Rule (org.junit.Rule)3 ExpectedException (org.junit.rules.ExpectedException)3