Search in sources :

Example 41 with Device

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

the class BaseDeviceCredentialsServiceTest method testSaveDeviceCredentialsWithEmptyCredentialsType.

@Test(expected = DataValidationException.class)
public void testSaveDeviceCredentialsWithEmptyCredentialsType() {
    Device device = new Device();
    device.setName("My device");
    device.setType("default");
    device.setTenantId(tenantId);
    device = deviceService.saveDevice(device);
    DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(device.getId());
    deviceCredentials.setCredentialsType(null);
    try {
        deviceCredentialsService.updateDeviceCredentials(deviceCredentials);
    } finally {
        deviceService.deleteDevice(device.getId());
    }
}
Also used : Device(org.thingsboard.server.common.data.Device) DeviceCredentials(org.thingsboard.server.common.data.security.DeviceCredentials) Test(org.junit.Test)

Example 42 with Device

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

the class BaseDeviceCredentialsServiceTest method testFindDeviceCredentialsByCredentialsId.

@Test
public void testFindDeviceCredentialsByCredentialsId() {
    Device device = new Device();
    device.setTenantId(tenantId);
    device.setName("My device");
    device.setType("default");
    Device savedDevice = deviceService.saveDevice(device);
    DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(savedDevice.getId());
    Assert.assertEquals(savedDevice.getId(), deviceCredentials.getDeviceId());
    DeviceCredentials foundDeviceCredentials = deviceCredentialsService.findDeviceCredentialsByCredentialsId(deviceCredentials.getCredentialsId());
    Assert.assertEquals(deviceCredentials, foundDeviceCredentials);
    deviceService.deleteDevice(savedDevice.getId());
    foundDeviceCredentials = deviceCredentialsService.findDeviceCredentialsByCredentialsId(deviceCredentials.getCredentialsId());
    Assert.assertNull(foundDeviceCredentials);
}
Also used : Device(org.thingsboard.server.common.data.Device) DeviceCredentials(org.thingsboard.server.common.data.security.DeviceCredentials) Test(org.junit.Test)

Example 43 with Device

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

the class BaseDeviceCredentialsServiceTest method testSaveDeviceCredentialsWithNonExistentDevice.

@Test(expected = DataValidationException.class)
public void testSaveDeviceCredentialsWithNonExistentDevice() {
    Device device = new Device();
    device.setName("My device");
    device.setType("default");
    device.setTenantId(tenantId);
    device = deviceService.saveDevice(device);
    DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(device.getId());
    deviceCredentials.setDeviceId(new DeviceId(UUIDs.timeBased()));
    try {
        deviceCredentialsService.updateDeviceCredentials(deviceCredentials);
    } finally {
        deviceService.deleteDevice(device.getId());
    }
}
Also used : Device(org.thingsboard.server.common.data.Device) DeviceId(org.thingsboard.server.common.data.id.DeviceId) DeviceCredentials(org.thingsboard.server.common.data.security.DeviceCredentials) Test(org.junit.Test)

Example 44 with Device

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

the class BaseDeviceCredentialsServiceTest method testSaveNonExistentDeviceCredentials.

@Test(expected = DataValidationException.class)
public void testSaveNonExistentDeviceCredentials() {
    Device device = new Device();
    device.setName("My device");
    device.setType("default");
    device.setTenantId(tenantId);
    device = deviceService.saveDevice(device);
    DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(device.getId());
    DeviceCredentials newDeviceCredentials = new DeviceCredentials(new DeviceCredentialsId(UUIDs.timeBased()));
    newDeviceCredentials.setCreatedTime(deviceCredentials.getCreatedTime());
    newDeviceCredentials.setDeviceId(deviceCredentials.getDeviceId());
    newDeviceCredentials.setCredentialsType(deviceCredentials.getCredentialsType());
    newDeviceCredentials.setCredentialsId(deviceCredentials.getCredentialsId());
    try {
        deviceCredentialsService.updateDeviceCredentials(newDeviceCredentials);
    } finally {
        deviceService.deleteDevice(device.getId());
    }
}
Also used : Device(org.thingsboard.server.common.data.Device) DeviceCredentialsId(org.thingsboard.server.common.data.id.DeviceCredentialsId) DeviceCredentials(org.thingsboard.server.common.data.security.DeviceCredentials) Test(org.junit.Test)

Example 45 with Device

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

the class BaseDeviceServiceTest method testSaveDeviceWithInvalidTenant.

@Test(expected = DataValidationException.class)
public void testSaveDeviceWithInvalidTenant() {
    Device device = new Device();
    device.setName("My device");
    device.setType("default");
    device.setTenantId(new TenantId(UUIDs.timeBased()));
    deviceService.saveDevice(device);
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) Device(org.thingsboard.server.common.data.Device) Test(org.junit.Test)

Aggregations

Device (org.thingsboard.server.common.data.Device)53 Test (org.junit.Test)31 DeviceCredentials (org.thingsboard.server.common.data.security.DeviceCredentials)18 ArrayList (java.util.ArrayList)11 DeviceId (org.thingsboard.server.common.data.id.DeviceId)11 CustomerId (org.thingsboard.server.common.data.id.CustomerId)8 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)7 Customer (org.thingsboard.server.common.data.Customer)7 TextPageLink (org.thingsboard.server.common.data.page.TextPageLink)7 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)7 ThingsboardException (org.thingsboard.server.exception.ThingsboardException)7 TenantId (org.thingsboard.server.common.data.id.TenantId)6 UUID (java.util.UUID)5 AbstractControllerTest (org.thingsboard.server.controller.AbstractControllerTest)4 AbstractJpaDaoTest (org.thingsboard.server.dao.AbstractJpaDaoTest)4 Tenant (org.thingsboard.server.common.data.Tenant)3 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 List (java.util.List)2 Before (org.junit.Before)2