use of org.thingsboard.server.common.data.security.DeviceCredentials in project thingsboard by thingsboard.
the class BaseDeviceServiceTest method testSaveDevice.
@Test
public void testSaveDevice() {
Device device = new Device();
device.setTenantId(tenantId);
device.setName("My device");
device.setType("default");
Device savedDevice = deviceService.saveDevice(device);
Assert.assertNotNull(savedDevice);
Assert.assertNotNull(savedDevice.getId());
Assert.assertTrue(savedDevice.getCreatedTime() > 0);
Assert.assertEquals(device.getTenantId(), savedDevice.getTenantId());
Assert.assertNotNull(savedDevice.getCustomerId());
Assert.assertEquals(NULL_UUID, savedDevice.getCustomerId().getId());
Assert.assertEquals(device.getName(), savedDevice.getName());
DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(savedDevice.getId());
Assert.assertNotNull(deviceCredentials);
Assert.assertNotNull(deviceCredentials.getId());
Assert.assertEquals(savedDevice.getId(), deviceCredentials.getDeviceId());
Assert.assertEquals(DeviceCredentialsType.ACCESS_TOKEN, deviceCredentials.getCredentialsType());
Assert.assertNotNull(deviceCredentials.getCredentialsId());
Assert.assertEquals(20, deviceCredentials.getCredentialsId().length());
savedDevice.setName("My new device");
deviceService.saveDevice(savedDevice);
Device foundDevice = deviceService.findDeviceById(savedDevice.getId());
Assert.assertEquals(foundDevice.getName(), savedDevice.getName());
deviceService.deleteDevice(savedDevice.getId());
}
use of org.thingsboard.server.common.data.security.DeviceCredentials in project thingsboard by thingsboard.
the class PreviousDeviceCredentialsIdKeyGenerator method generate.
@Override
public Object generate(Object o, Method method, Object... objects) {
DeviceCredentialsService deviceCredentialsService = (DeviceCredentialsService) o;
DeviceCredentials deviceCredentials = (DeviceCredentials) objects[0];
if (deviceCredentials.getDeviceId() != null) {
DeviceCredentials oldDeviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(deviceCredentials.getDeviceId());
if (oldDeviceCredentials != null) {
return oldDeviceCredentials.getCredentialsId();
}
}
return NOT_VALID_DEVICE;
}
use of org.thingsboard.server.common.data.security.DeviceCredentials in project thingsboard by thingsboard.
the class DeviceCredentialsEntity method toData.
@Override
public DeviceCredentials toData() {
DeviceCredentials deviceCredentials = new DeviceCredentials(new DeviceCredentialsId(getId()));
deviceCredentials.setCreatedTime(UUIDs.unixTimestamp(getId()));
if (deviceId != null) {
deviceCredentials.setDeviceId(new DeviceId(toUUID(deviceId)));
}
deviceCredentials.setCredentialsType(credentialsType);
deviceCredentials.setCredentialsId(credentialsId);
deviceCredentials.setCredentialsValue(credentialsValue);
return deviceCredentials;
}
use of org.thingsboard.server.common.data.security.DeviceCredentials in project thingsboard by thingsboard.
the class DeviceCredentialsEntity method toData.
@Override
public DeviceCredentials toData() {
DeviceCredentials deviceCredentials = new DeviceCredentials(new DeviceCredentialsId(id));
deviceCredentials.setCreatedTime(UUIDs.unixTimestamp(id));
if (deviceId != null) {
deviceCredentials.setDeviceId(new DeviceId(deviceId));
}
deviceCredentials.setCredentialsType(credentialsType);
deviceCredentials.setCredentialsId(credentialsId);
deviceCredentials.setCredentialsValue(credentialsValue);
return deviceCredentials;
}
use of org.thingsboard.server.common.data.security.DeviceCredentials in project thingsboard by thingsboard.
the class BaseDeviceControllerTest method testSaveDeviceCredentialsWithNonExistentDevice.
@Test
public void testSaveDeviceCredentialsWithNonExistentDevice() throws Exception {
Device device = new Device();
device.setName("My device");
device.setType("default");
Device savedDevice = doPost("/api/device", device, Device.class);
DeviceCredentials deviceCredentials = doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class);
deviceCredentials.setDeviceId(new DeviceId(UUIDs.timeBased()));
doPost("/api/device/credentials", deviceCredentials).andExpect(status().isNotFound());
}
Aggregations