Search in sources :

Example 1 with DeviceCredentials

use of org.thingsboard.server.common.data.security.DeviceCredentials in project thingsboard by thingsboard.

the class BaseDeviceCredentialsCacheTest method createDummyDeviceCredentialsEntity.

private DeviceCredentials createDummyDeviceCredentialsEntity(String deviceCredentialsId) {
    DeviceCredentials result = new DeviceCredentials(new DeviceCredentialsId(UUID.randomUUID()));
    result.setCredentialsId(deviceCredentialsId);
    return result;
}
Also used : DeviceCredentialsId(org.thingsboard.server.common.data.id.DeviceCredentialsId) DeviceCredentials(org.thingsboard.server.common.data.security.DeviceCredentials)

Example 2 with DeviceCredentials

use of org.thingsboard.server.common.data.security.DeviceCredentials in project thingsboard by thingsboard.

the class BaseDeviceCredentialsServiceTest method testSaveDeviceCredentialsWithEmptyCredentialsId.

@Test(expected = DataValidationException.class)
public void testSaveDeviceCredentialsWithEmptyCredentialsId() {
    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.setCredentialsId(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 3 with DeviceCredentials

use of org.thingsboard.server.common.data.security.DeviceCredentials in project thingsboard by thingsboard.

the class BaseDeviceCredentialsServiceTest method testSaveDeviceCredentials.

@Test
public void testSaveDeviceCredentials() {
    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.setCredentialsType(DeviceCredentialsType.ACCESS_TOKEN);
    deviceCredentials.setCredentialsId("access_token");
    deviceCredentialsService.updateDeviceCredentials(deviceCredentials);
    DeviceCredentials foundDeviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(savedDevice.getId());
    Assert.assertEquals(deviceCredentials, foundDeviceCredentials);
    deviceService.deleteDevice(savedDevice.getId());
}
Also used : Device(org.thingsboard.server.common.data.Device) DeviceCredentials(org.thingsboard.server.common.data.security.DeviceCredentials) Test(org.junit.Test)

Example 4 with DeviceCredentials

use of org.thingsboard.server.common.data.security.DeviceCredentials in project thingsboard by thingsboard.

the class BaseDeviceCredentialsServiceTest method testCreateDeviceCredentials.

@Test(expected = DataValidationException.class)
public void testCreateDeviceCredentials() {
    DeviceCredentials deviceCredentials = new DeviceCredentials();
    deviceCredentialsService.updateDeviceCredentials(deviceCredentials);
}
Also used : DeviceCredentials(org.thingsboard.server.common.data.security.DeviceCredentials) Test(org.junit.Test)

Example 5 with DeviceCredentials

use of org.thingsboard.server.common.data.security.DeviceCredentials in project thingsboard by thingsboard.

the class BaseDeviceCredentialsServiceTest method testSaveDeviceCredentialsWithEmptyDevice.

@Test(expected = DataValidationException.class)
public void testSaveDeviceCredentialsWithEmptyDevice() {
    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(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)

Aggregations

DeviceCredentials (org.thingsboard.server.common.data.security.DeviceCredentials)39 Test (org.junit.Test)21 Device (org.thingsboard.server.common.data.Device)18 DeviceId (org.thingsboard.server.common.data.id.DeviceId)7 DeviceCredentialsId (org.thingsboard.server.common.data.id.DeviceCredentialsId)6 AbstractControllerTest (org.thingsboard.server.controller.AbstractControllerTest)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 DatabaseSetup (com.github.springtestdbunit.annotation.DatabaseSetup)2 Before (org.junit.Before)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 AbstractJpaDaoTest (org.thingsboard.server.dao.AbstractJpaDaoTest)2 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)2 ThingsboardException (org.thingsboard.server.exception.ThingsboardException)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 UUID (java.util.UUID)1 Cache (org.springframework.cache.Cache)1 CacheEvict (org.springframework.cache.annotation.CacheEvict)1 AttributeKvEntry (org.thingsboard.server.common.data.kv.AttributeKvEntry)1 DeviceCredentialsService (org.thingsboard.server.dao.device.DeviceCredentialsService)1