use of org.thingsboard.server.common.data.Device in project thingsboard by thingsboard.
the class BaseDeviceServiceTest method testFindDeviceById.
@Test
public void testFindDeviceById() {
Device device = new Device();
device.setTenantId(tenantId);
device.setName("My device");
device.setType("default");
Device savedDevice = deviceService.saveDevice(device);
Device foundDevice = deviceService.findDeviceById(savedDevice.getId());
Assert.assertNotNull(foundDevice);
Assert.assertEquals(savedDevice, foundDevice);
deviceService.deleteDevice(savedDevice.getId());
}
use of org.thingsboard.server.common.data.Device in project thingsboard by thingsboard.
the class BaseDeviceServiceTest method testDeleteDevice.
@Test
public void testDeleteDevice() {
Device device = new Device();
device.setTenantId(tenantId);
device.setName("My device");
device.setType("default");
Device savedDevice = deviceService.saveDevice(device);
Device foundDevice = deviceService.findDeviceById(savedDevice.getId());
Assert.assertNotNull(foundDevice);
deviceService.deleteDevice(savedDevice.getId());
foundDevice = deviceService.findDeviceById(savedDevice.getId());
Assert.assertNull(foundDevice);
DeviceCredentials foundDeviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(savedDevice.getId());
Assert.assertNull(foundDeviceCredentials);
}
use of org.thingsboard.server.common.data.Device in project thingsboard by thingsboard.
the class BaseDeviceServiceTest method testFindDevicesByTenantId.
@Test
public void testFindDevicesByTenantId() {
Tenant tenant = new Tenant();
tenant.setTitle("Test tenant");
tenant = tenantService.saveTenant(tenant);
TenantId tenantId = tenant.getId();
List<Device> devices = new ArrayList<>();
for (int i = 0; i < 178; i++) {
Device device = new Device();
device.setTenantId(tenantId);
device.setName("Device" + i);
device.setType("default");
devices.add(deviceService.saveDevice(device));
}
List<Device> loadedDevices = new ArrayList<>();
TextPageLink pageLink = new TextPageLink(23);
TextPageData<Device> pageData = null;
do {
pageData = deviceService.findDevicesByTenantId(tenantId, pageLink);
loadedDevices.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageData.getNextPageLink();
}
} while (pageData.hasNext());
Collections.sort(devices, idComparator);
Collections.sort(loadedDevices, idComparator);
Assert.assertEquals(devices, loadedDevices);
deviceService.deleteDevicesByTenantId(tenantId);
pageLink = new TextPageLink(33);
pageData = deviceService.findDevicesByTenantId(tenantId, pageLink);
Assert.assertFalse(pageData.hasNext());
Assert.assertTrue(pageData.getData().isEmpty());
tenantService.deleteTenant(tenantId);
}
use of org.thingsboard.server.common.data.Device in project thingsboard by thingsboard.
the class BaseDeviceServiceTest method testSaveDeviceWithEmptyName.
@Test(expected = DataValidationException.class)
public void testSaveDeviceWithEmptyName() {
Device device = new Device();
device.setType("default");
device.setTenantId(tenantId);
deviceService.saveDevice(device);
}
use of org.thingsboard.server.common.data.Device in project thingsboard by thingsboard.
the class BaseAuditLogControllerTest method testAuditLogs.
@Test
public void testAuditLogs() throws Exception {
for (int i = 0; i < 178; i++) {
Device device = new Device();
device.setName("Device" + i);
device.setType("default");
doPost("/api/device", device, Device.class);
}
List<AuditLog> loadedAuditLogs = new ArrayList<>();
TimePageLink pageLink = new TimePageLink(23);
TimePageData<AuditLog> pageData;
do {
pageData = doGetTypedWithTimePageLink("/api/audit/logs?", new TypeReference<TimePageData<AuditLog>>() {
}, pageLink);
loadedAuditLogs.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageData.getNextPageLink();
}
} while (pageData.hasNext());
Assert.assertEquals(178, loadedAuditLogs.size());
loadedAuditLogs = new ArrayList<>();
pageLink = new TimePageLink(23);
do {
pageData = doGetTypedWithTimePageLink("/api/audit/logs/customer/" + ModelConstants.NULL_UUID + "?", new TypeReference<TimePageData<AuditLog>>() {
}, pageLink);
loadedAuditLogs.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageData.getNextPageLink();
}
} while (pageData.hasNext());
Assert.assertEquals(178, loadedAuditLogs.size());
loadedAuditLogs = new ArrayList<>();
pageLink = new TimePageLink(23);
do {
pageData = doGetTypedWithTimePageLink("/api/audit/logs/user/" + tenantAdmin.getId().getId().toString() + "?", new TypeReference<TimePageData<AuditLog>>() {
}, pageLink);
loadedAuditLogs.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageData.getNextPageLink();
}
} while (pageData.hasNext());
Assert.assertEquals(178, loadedAuditLogs.size());
}
Aggregations