use of org.thingsboard.server.common.data.security.DeviceCredentials in project thingsboard by thingsboard.
the class BaseDeviceCredentialsCacheTest method createDummyDeviceCredentials.
private DeviceCredentials createDummyDeviceCredentials(UUID id, String deviceCredentialsId, UUID deviceId) {
DeviceCredentials result = new DeviceCredentials();
result.setId(new DeviceCredentialsId(id));
result.setDeviceId(new DeviceId(deviceId));
result.setCredentialsId(deviceCredentialsId);
result.setCredentialsType(DeviceCredentialsType.ACCESS_TOKEN);
return result;
}
use of org.thingsboard.server.common.data.security.DeviceCredentials in project thingsboard by thingsboard.
the class BaseDeviceCredentialsServiceTest method testFindDeviceCredentialsByDeviceId.
@Test
public void testFindDeviceCredentialsByDeviceId() {
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());
deviceService.deleteDevice(savedDevice.getId());
deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(savedDevice.getId());
Assert.assertNull(deviceCredentials);
}
use of org.thingsboard.server.common.data.security.DeviceCredentials 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());
}
}
use of org.thingsboard.server.common.data.security.DeviceCredentials 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);
}
use of org.thingsboard.server.common.data.security.DeviceCredentials 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());
}
}
Aggregations