use of org.thingsboard.server.common.data.page.PageLink in project thingsboard by thingsboard.
the class BaseUserControllerTest method testFindCustomerUsers.
@Test
public void testFindCustomerUsers() throws Exception {
loginSysAdmin();
User tenantAdmin = new User();
tenantAdmin.setAuthority(Authority.TENANT_ADMIN);
tenantAdmin.setTenantId(tenantId);
tenantAdmin.setEmail("tenant2@thingsboard.org");
tenantAdmin.setFirstName("Joe");
tenantAdmin.setLastName("Downs");
tenantAdmin = createUserAndLogin(tenantAdmin, "testPassword1");
Customer customer = new Customer();
customer.setTitle("My customer");
Customer savedCustomer = doPost("/api/customer", customer, Customer.class);
CustomerId customerId = savedCustomer.getId();
List<User> customerUsers = new ArrayList<>();
for (int i = 0; i < 56; i++) {
User user = new User();
user.setAuthority(Authority.CUSTOMER_USER);
user.setCustomerId(customerId);
user.setEmail("testCustomer" + i + "@thingsboard.org");
customerUsers.add(doPost("/api/user", user, User.class));
}
List<User> loadedCustomerUsers = new ArrayList<>();
PageLink pageLink = new PageLink(33);
PageData<User> pageData = null;
do {
pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/users?", new TypeReference<PageData<User>>() {
}, pageLink);
loadedCustomerUsers.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageLink.nextPageLink();
}
} while (pageData.hasNext());
Collections.sort(customerUsers, idComparator);
Collections.sort(loadedCustomerUsers, idComparator);
Assert.assertEquals(customerUsers, loadedCustomerUsers);
doDelete("/api/customer/" + customerId.getId().toString()).andExpect(status().isOk());
}
use of org.thingsboard.server.common.data.page.PageLink in project thingsboard by thingsboard.
the class BaseWidgetsBundleControllerTest method testFindSystemWidgetsBundlesByPageLink.
@Test
public void testFindSystemWidgetsBundlesByPageLink() throws Exception {
loginSysAdmin();
List<WidgetsBundle> sysWidgetsBundles = doGetTyped("/api/widgetsBundles?", new TypeReference<List<WidgetsBundle>>() {
});
List<WidgetsBundle> createdWidgetsBundles = new ArrayList<>();
for (int i = 0; i < 120; i++) {
WidgetsBundle widgetsBundle = new WidgetsBundle();
widgetsBundle.setTitle("Widgets bundle" + i);
createdWidgetsBundles.add(doPost("/api/widgetsBundle", widgetsBundle, WidgetsBundle.class));
}
List<WidgetsBundle> widgetsBundles = new ArrayList<>(createdWidgetsBundles);
widgetsBundles.addAll(sysWidgetsBundles);
List<WidgetsBundle> loadedWidgetsBundles = new ArrayList<>();
PageLink pageLink = new PageLink(14);
PageData<WidgetsBundle> pageData;
do {
pageData = doGetTypedWithPageLink("/api/widgetsBundles?", new TypeReference<PageData<WidgetsBundle>>() {
}, pageLink);
loadedWidgetsBundles.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageLink.nextPageLink();
}
} while (pageData.hasNext());
Collections.sort(widgetsBundles, idComparator);
Collections.sort(loadedWidgetsBundles, idComparator);
Assert.assertEquals(widgetsBundles, loadedWidgetsBundles);
for (WidgetsBundle widgetsBundle : createdWidgetsBundles) {
doDelete("/api/widgetsBundle/" + widgetsBundle.getId().getId().toString()).andExpect(status().isOk());
}
pageLink = new PageLink(17);
loadedWidgetsBundles.clear();
do {
pageData = doGetTypedWithPageLink("/api/widgetsBundles?", new TypeReference<PageData<WidgetsBundle>>() {
}, pageLink);
loadedWidgetsBundles.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageLink.nextPageLink();
}
} while (pageData.hasNext());
Collections.sort(sysWidgetsBundles, idComparator);
Collections.sort(loadedWidgetsBundles, idComparator);
Assert.assertEquals(sysWidgetsBundles, loadedWidgetsBundles);
}
use of org.thingsboard.server.common.data.page.PageLink in project thingsboard by thingsboard.
the class BaseDeviceServiceTest method testFindDevicesByTenantIdAndCustomerId.
@Test
public void testFindDevicesByTenantIdAndCustomerId() {
Tenant tenant = new Tenant();
tenant.setTitle("Test tenant");
tenant = tenantService.saveTenant(tenant);
TenantId tenantId = tenant.getId();
Customer customer = new Customer();
customer.setTitle("Test customer");
customer.setTenantId(tenantId);
customer = customerService.saveCustomer(customer);
CustomerId customerId = customer.getId();
List<DeviceInfo> devices = new ArrayList<>();
for (int i = 0; i < 278; i++) {
Device device = new Device();
device.setTenantId(tenantId);
device.setName("Device" + i);
device.setType("default");
device = deviceService.saveDevice(device);
devices.add(new DeviceInfo(deviceService.assignDeviceToCustomer(tenantId, device.getId(), customerId), customer.getTitle(), customer.isPublic(), "default"));
}
List<DeviceInfo> loadedDevices = new ArrayList<>();
PageLink pageLink = new PageLink(23);
PageData<DeviceInfo> pageData = null;
do {
pageData = deviceService.findDeviceInfosByTenantIdAndCustomerId(tenantId, customerId, pageLink);
loadedDevices.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageLink.nextPageLink();
}
} while (pageData.hasNext());
Collections.sort(devices, idComparator);
Collections.sort(loadedDevices, idComparator);
Assert.assertEquals(devices, loadedDevices);
deviceService.unassignCustomerDevices(tenantId, customerId);
pageLink = new PageLink(33);
pageData = deviceService.findDeviceInfosByTenantIdAndCustomerId(tenantId, customerId, pageLink);
Assert.assertFalse(pageData.hasNext());
Assert.assertTrue(pageData.getData().isEmpty());
tenantService.deleteTenant(tenantId);
}
use of org.thingsboard.server.common.data.page.PageLink in project thingsboard by thingsboard.
the class BaseDeviceServiceTest method testFindDevicesByTenantIdCustomerIdAndType.
@Test
public void testFindDevicesByTenantIdCustomerIdAndType() {
Customer customer = new Customer();
customer.setTitle("Test customer");
customer.setTenantId(tenantId);
customer = customerService.saveCustomer(customer);
CustomerId customerId = customer.getId();
String title1 = "Device title 1";
String type1 = "typeC";
List<Device> devicesType1 = new ArrayList<>();
for (int i = 0; i < 175; i++) {
Device device = new Device();
device.setTenantId(tenantId);
String suffix = RandomStringUtils.randomAlphanumeric(15);
String name = title1 + suffix;
name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
device.setName(name);
device.setType(type1);
device = deviceService.saveDevice(device);
devicesType1.add(deviceService.assignDeviceToCustomer(tenantId, device.getId(), customerId));
}
String title2 = "Device title 2";
String type2 = "typeD";
List<Device> devicesType2 = new ArrayList<>();
for (int i = 0; i < 143; i++) {
Device device = new Device();
device.setTenantId(tenantId);
String suffix = RandomStringUtils.randomAlphanumeric(15);
String name = title2 + suffix;
name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
device.setName(name);
device.setType(type2);
device = deviceService.saveDevice(device);
devicesType2.add(deviceService.assignDeviceToCustomer(tenantId, device.getId(), customerId));
}
List<Device> loadedDevicesType1 = new ArrayList<>();
PageLink pageLink = new PageLink(15);
PageData<Device> pageData = null;
do {
pageData = deviceService.findDevicesByTenantIdAndCustomerIdAndType(tenantId, customerId, type1, pageLink);
loadedDevicesType1.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageLink.nextPageLink();
}
} while (pageData.hasNext());
Collections.sort(devicesType1, idComparator);
Collections.sort(loadedDevicesType1, idComparator);
Assert.assertEquals(devicesType1, loadedDevicesType1);
List<Device> loadedDevicesType2 = new ArrayList<>();
pageLink = new PageLink(4);
do {
pageData = deviceService.findDevicesByTenantIdAndCustomerIdAndType(tenantId, customerId, type2, pageLink);
loadedDevicesType2.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageLink.nextPageLink();
}
} while (pageData.hasNext());
Collections.sort(devicesType2, idComparator);
Collections.sort(loadedDevicesType2, idComparator);
Assert.assertEquals(devicesType2, loadedDevicesType2);
for (Device device : loadedDevicesType1) {
deviceService.deleteDevice(tenantId, device.getId());
}
pageLink = new PageLink(4);
pageData = deviceService.findDevicesByTenantIdAndCustomerIdAndType(tenantId, customerId, type1, pageLink);
Assert.assertFalse(pageData.hasNext());
Assert.assertEquals(0, pageData.getData().size());
for (Device device : loadedDevicesType2) {
deviceService.deleteDevice(tenantId, device.getId());
}
pageLink = new PageLink(4);
pageData = deviceService.findDevicesByTenantIdAndCustomerIdAndType(tenantId, customerId, type2, pageLink);
Assert.assertFalse(pageData.hasNext());
Assert.assertEquals(0, pageData.getData().size());
customerService.deleteCustomer(tenantId, customerId);
}
use of org.thingsboard.server.common.data.page.PageLink in project thingsboard by thingsboard.
the class BaseDeviceServiceTest method testFindDeviceInfoByTenantId.
@Test
public void testFindDeviceInfoByTenantId() {
Customer customer = new Customer();
customer.setTitle("Customer X");
customer.setTenantId(tenantId);
Customer savedCustomer = customerService.saveCustomer(customer);
Device device = new Device();
device.setTenantId(tenantId);
device.setName("default");
device.setType("default");
device.setLabel("label");
device.setCustomerId(savedCustomer.getId());
Device savedDevice = deviceService.saveDevice(device);
PageLink pageLinkWithLabel = new PageLink(100, 0, "label");
List<DeviceInfo> deviceInfosWithLabel = deviceService.findDeviceInfosByTenantId(tenantId, pageLinkWithLabel).getData();
Assert.assertFalse(deviceInfosWithLabel.isEmpty());
Assert.assertTrue(deviceInfosWithLabel.stream().anyMatch(d -> d.getId().equals(savedDevice.getId()) && d.getTenantId().equals(tenantId) && d.getLabel().equals(savedDevice.getLabel())));
PageLink pageLinkWithCustomer = new PageLink(100, 0, savedCustomer.getSearchText());
List<DeviceInfo> deviceInfosWithCustomer = deviceService.findDeviceInfosByTenantId(tenantId, pageLinkWithCustomer).getData();
Assert.assertFalse(deviceInfosWithCustomer.isEmpty());
Assert.assertTrue(deviceInfosWithCustomer.stream().anyMatch(d -> d.getId().equals(savedDevice.getId()) && d.getTenantId().equals(tenantId) && d.getCustomerId().equals(savedCustomer.getId()) && d.getCustomerTitle().equals(savedCustomer.getTitle())));
PageLink pageLinkWithType = new PageLink(100, 0, device.getType());
List<DeviceInfo> deviceInfosWithType = deviceService.findDeviceInfosByTenantId(tenantId, pageLinkWithType).getData();
Assert.assertFalse(deviceInfosWithType.isEmpty());
Assert.assertTrue(deviceInfosWithType.stream().anyMatch(d -> d.getId().equals(savedDevice.getId()) && d.getTenantId().equals(tenantId) && d.getType().equals(device.getType())));
}
Aggregations