use of org.thingsboard.server.common.data.page.TextPageLink in project thingsboard by thingsboard.
the class BaseDeviceServiceTest method testFindDevicesByTenantIdAndType.
@Test
public void testFindDevicesByTenantIdAndType() {
String title1 = "Device title 1";
String type1 = "typeA";
List<Device> devicesType1 = new ArrayList<>();
for (int i = 0; i < 143; 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);
devicesType1.add(deviceService.saveDevice(device));
}
String title2 = "Device title 2";
String type2 = "typeB";
List<Device> devicesType2 = new ArrayList<>();
for (int i = 0; i < 175; 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);
devicesType2.add(deviceService.saveDevice(device));
}
List<Device> loadedDevicesType1 = new ArrayList<>();
TextPageLink pageLink = new TextPageLink(15);
TextPageData<Device> pageData = null;
do {
pageData = deviceService.findDevicesByTenantIdAndType(tenantId, type1, pageLink);
loadedDevicesType1.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageData.getNextPageLink();
}
} while (pageData.hasNext());
Collections.sort(devicesType1, idComparator);
Collections.sort(loadedDevicesType1, idComparator);
Assert.assertEquals(devicesType1, loadedDevicesType1);
List<Device> loadedDevicesType2 = new ArrayList<>();
pageLink = new TextPageLink(4);
do {
pageData = deviceService.findDevicesByTenantIdAndType(tenantId, type2, pageLink);
loadedDevicesType2.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageData.getNextPageLink();
}
} while (pageData.hasNext());
Collections.sort(devicesType2, idComparator);
Collections.sort(loadedDevicesType2, idComparator);
Assert.assertEquals(devicesType2, loadedDevicesType2);
for (Device device : loadedDevicesType1) {
deviceService.deleteDevice(device.getId());
}
pageLink = new TextPageLink(4);
pageData = deviceService.findDevicesByTenantIdAndType(tenantId, type1, pageLink);
Assert.assertFalse(pageData.hasNext());
Assert.assertEquals(0, pageData.getData().size());
for (Device device : loadedDevicesType2) {
deviceService.deleteDevice(device.getId());
}
pageLink = new TextPageLink(4);
pageData = deviceService.findDevicesByTenantIdAndType(tenantId, type2, pageLink);
Assert.assertFalse(pageData.hasNext());
Assert.assertEquals(0, pageData.getData().size());
}
use of org.thingsboard.server.common.data.page.TextPageLink in project thingsboard by thingsboard.
the class BaseTenantServiceTest method testFindTenantsByTitle.
@Test
public void testFindTenantsByTitle() {
String title1 = "Tenant title 1";
List<Tenant> tenantsTitle1 = new ArrayList<>();
for (int i = 0; i < 134; i++) {
Tenant tenant = new Tenant();
String suffix = RandomStringUtils.randomAlphanumeric((int) (Math.random() * 15));
String title = title1 + suffix;
title = i % 2 == 0 ? title.toLowerCase() : title.toUpperCase();
tenant.setTitle(title);
tenantsTitle1.add(tenantService.saveTenant(tenant));
}
String title2 = "Tenant title 2";
List<Tenant> tenantsTitle2 = new ArrayList<>();
for (int i = 0; i < 127; i++) {
Tenant tenant = new Tenant();
String suffix = RandomStringUtils.randomAlphanumeric((int) (Math.random() * 15));
String title = title2 + suffix;
title = i % 2 == 0 ? title.toLowerCase() : title.toUpperCase();
tenant.setTitle(title);
tenantsTitle2.add(tenantService.saveTenant(tenant));
}
List<Tenant> loadedTenantsTitle1 = new ArrayList<>();
TextPageLink pageLink = new TextPageLink(15, title1);
TextPageData<Tenant> pageData = null;
do {
pageData = tenantService.findTenants(pageLink);
loadedTenantsTitle1.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageData.getNextPageLink();
}
} while (pageData.hasNext());
Collections.sort(tenantsTitle1, idComparator);
Collections.sort(loadedTenantsTitle1, idComparator);
Assert.assertEquals(tenantsTitle1, loadedTenantsTitle1);
List<Tenant> loadedTenantsTitle2 = new ArrayList<>();
pageLink = new TextPageLink(4, title2);
do {
pageData = tenantService.findTenants(pageLink);
loadedTenantsTitle2.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageData.getNextPageLink();
}
} while (pageData.hasNext());
Collections.sort(tenantsTitle2, idComparator);
Collections.sort(loadedTenantsTitle2, idComparator);
Assert.assertEquals(tenantsTitle2, loadedTenantsTitle2);
for (Tenant tenant : loadedTenantsTitle1) {
tenantService.deleteTenant(tenant.getId());
}
pageLink = new TextPageLink(4, title1);
pageData = tenantService.findTenants(pageLink);
Assert.assertFalse(pageData.hasNext());
Assert.assertEquals(0, pageData.getData().size());
for (Tenant tenant : loadedTenantsTitle2) {
tenantService.deleteTenant(tenant.getId());
}
pageLink = new TextPageLink(4, title2);
pageData = tenantService.findTenants(pageLink);
Assert.assertFalse(pageData.hasNext());
Assert.assertEquals(0, pageData.getData().size());
}
use of org.thingsboard.server.common.data.page.TextPageLink in project thingsboard by thingsboard.
the class BaseAssetServiceTest method testFindAssetsByTenantIdCustomerIdAndType.
@Test
public void testFindAssetsByTenantIdCustomerIdAndType() {
Customer customer = new Customer();
customer.setTitle("Test customer");
customer.setTenantId(tenantId);
customer = customerService.saveCustomer(customer);
CustomerId customerId = customer.getId();
String title1 = "Asset title 1";
String type1 = "typeC";
List<Asset> assetsType1 = new ArrayList<>();
for (int i = 0; i < 175; i++) {
Asset asset = new Asset();
asset.setTenantId(tenantId);
String suffix = RandomStringUtils.randomAlphanumeric(15);
String name = title1 + suffix;
name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
asset.setName(name);
asset.setType(type1);
asset = assetService.saveAsset(asset);
assetsType1.add(assetService.assignAssetToCustomer(asset.getId(), customerId));
}
String title2 = "Asset title 2";
String type2 = "typeD";
List<Asset> assetsType2 = new ArrayList<>();
for (int i = 0; i < 143; i++) {
Asset asset = new Asset();
asset.setTenantId(tenantId);
String suffix = RandomStringUtils.randomAlphanumeric(15);
String name = title2 + suffix;
name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
asset.setName(name);
asset.setType(type2);
asset = assetService.saveAsset(asset);
assetsType2.add(assetService.assignAssetToCustomer(asset.getId(), customerId));
}
List<Asset> loadedAssetsType1 = new ArrayList<>();
TextPageLink pageLink = new TextPageLink(15);
TextPageData<Asset> pageData = null;
do {
pageData = assetService.findAssetsByTenantIdAndCustomerIdAndType(tenantId, customerId, type1, pageLink);
loadedAssetsType1.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageData.getNextPageLink();
}
} while (pageData.hasNext());
Collections.sort(assetsType1, idComparator);
Collections.sort(loadedAssetsType1, idComparator);
Assert.assertEquals(assetsType1, loadedAssetsType1);
List<Asset> loadedAssetsType2 = new ArrayList<>();
pageLink = new TextPageLink(4);
do {
pageData = assetService.findAssetsByTenantIdAndCustomerIdAndType(tenantId, customerId, type2, pageLink);
loadedAssetsType2.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageData.getNextPageLink();
}
} while (pageData.hasNext());
Collections.sort(assetsType2, idComparator);
Collections.sort(loadedAssetsType2, idComparator);
Assert.assertEquals(assetsType2, loadedAssetsType2);
for (Asset asset : loadedAssetsType1) {
assetService.deleteAsset(asset.getId());
}
pageLink = new TextPageLink(4);
pageData = assetService.findAssetsByTenantIdAndCustomerIdAndType(tenantId, customerId, type1, pageLink);
Assert.assertFalse(pageData.hasNext());
Assert.assertEquals(0, pageData.getData().size());
for (Asset asset : loadedAssetsType2) {
assetService.deleteAsset(asset.getId());
}
pageLink = new TextPageLink(4);
pageData = assetService.findAssetsByTenantIdAndCustomerIdAndType(tenantId, customerId, type2, pageLink);
Assert.assertFalse(pageData.hasNext());
Assert.assertEquals(0, pageData.getData().size());
customerService.deleteCustomer(customerId);
}
use of org.thingsboard.server.common.data.page.TextPageLink in project thingsboard by thingsboard.
the class BaseRuleService method findSystemRules.
@Override
public List<RuleMetaData> findSystemRules() {
log.trace("Executing findSystemRules");
List<RuleMetaData> rules = new ArrayList<>();
TextPageLink pageLink = new TextPageLink(300);
TextPageData<RuleMetaData> pageData = null;
do {
pageData = findSystemRules(pageLink);
rules.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageData.getNextPageLink();
}
} while (pageData.hasNext());
return rules;
}
use of org.thingsboard.server.common.data.page.TextPageLink in project thingsboard by thingsboard.
the class BaseAssetControllerTest method testFindCustomerAssetsByType.
@Test
public void testFindCustomerAssetsByType() throws Exception {
Customer customer = new Customer();
customer.setTitle("Test customer");
customer = doPost("/api/customer", customer, Customer.class);
CustomerId customerId = customer.getId();
String title1 = "Asset title 1";
String type1 = "typeC";
List<Asset> assetsType1 = new ArrayList<>();
for (int i = 0; i < 125; i++) {
Asset asset = new Asset();
String suffix = RandomStringUtils.randomAlphanumeric(15);
String name = title1 + suffix;
name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
asset.setName(name);
asset.setType(type1);
asset = doPost("/api/asset", asset, Asset.class);
assetsType1.add(doPost("/api/customer/" + customerId.getId().toString() + "/asset/" + asset.getId().getId().toString(), Asset.class));
}
String title2 = "Asset title 2";
String type2 = "typeD";
List<Asset> assetsType2 = new ArrayList<>();
for (int i = 0; i < 143; i++) {
Asset asset = new Asset();
String suffix = RandomStringUtils.randomAlphanumeric(15);
String name = title2 + suffix;
name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
asset.setName(name);
asset.setType(type2);
asset = doPost("/api/asset", asset, Asset.class);
assetsType2.add(doPost("/api/customer/" + customerId.getId().toString() + "/asset/" + asset.getId().getId().toString(), Asset.class));
}
List<Asset> loadedAssetsType1 = new ArrayList<>();
TextPageLink pageLink = new TextPageLink(15);
TextPageData<Asset> pageData = null;
do {
pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/assets?type={type}&", new TypeReference<TextPageData<Asset>>() {
}, pageLink, type1);
loadedAssetsType1.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageData.getNextPageLink();
}
} while (pageData.hasNext());
Collections.sort(assetsType1, idComparator);
Collections.sort(loadedAssetsType1, idComparator);
Assert.assertEquals(assetsType1, loadedAssetsType1);
List<Asset> loadedAssetsType2 = new ArrayList<>();
pageLink = new TextPageLink(4);
do {
pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/assets?type={type}&", new TypeReference<TextPageData<Asset>>() {
}, pageLink, type2);
loadedAssetsType2.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageData.getNextPageLink();
}
} while (pageData.hasNext());
Collections.sort(assetsType2, idComparator);
Collections.sort(loadedAssetsType2, idComparator);
Assert.assertEquals(assetsType2, loadedAssetsType2);
for (Asset asset : loadedAssetsType1) {
doDelete("/api/customer/asset/" + asset.getId().getId().toString()).andExpect(status().isOk());
}
pageLink = new TextPageLink(4);
pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/assets?type={type}&", new TypeReference<TextPageData<Asset>>() {
}, pageLink, type1);
Assert.assertFalse(pageData.hasNext());
Assert.assertEquals(0, pageData.getData().size());
for (Asset asset : loadedAssetsType2) {
doDelete("/api/customer/asset/" + asset.getId().getId().toString()).andExpect(status().isOk());
}
pageLink = new TextPageLink(4);
pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/assets?type={type}&", new TypeReference<TextPageData<Asset>>() {
}, pageLink, type2);
Assert.assertFalse(pageData.hasNext());
Assert.assertEquals(0, pageData.getData().size());
}
Aggregations