use of org.thingsboard.server.common.data.page.TextPageLink in project thingsboard by thingsboard.
the class JpaDeviceDaoTest method testFindDevicesByTenantId.
@Test
public void testFindDevicesByTenantId() {
UUID tenantId1 = UUIDs.timeBased();
UUID tenantId2 = UUIDs.timeBased();
UUID customerId1 = UUIDs.timeBased();
UUID customerId2 = UUIDs.timeBased();
createDevices(tenantId1, tenantId2, customerId1, customerId2, 40);
TextPageLink pageLink1 = new TextPageLink(15, "SEARCH_TEXT");
List<Device> devices1 = deviceDao.findDevicesByTenantId(tenantId1, pageLink1);
assertEquals(15, devices1.size());
TextPageLink pageLink2 = new TextPageLink(15, "SEARCH_TEXT", devices1.get(14).getId().getId(), null);
List<Device> devices2 = deviceDao.findDevicesByTenantId(tenantId1, pageLink2);
assertEquals(5, devices2.size());
}
use of org.thingsboard.server.common.data.page.TextPageLink in project thingsboard by thingsboard.
the class JpaBaseRuleDaoTest method testFindByTenantIdAndPageLink.
@Test
@DatabaseSetup("classpath:dbunit/empty_dataset.xml")
public void testFindByTenantIdAndPageLink() {
UUID tenantId1 = UUIDs.timeBased();
UUID tenantId2 = UUIDs.timeBased();
createRulesTwoTenants(tenantId1, tenantId2, "name_", "token");
List<RuleMetaData> rules1 = ruleDao.findByTenantIdAndPageLink(new TenantId(tenantId1), new TextPageLink(20, "name_"));
assertEquals(20, rules1.size());
List<RuleMetaData> rules2 = ruleDao.findByTenantIdAndPageLink(new TenantId(tenantId1), new TextPageLink(20, "name_", rules1.get(19).getId().getId(), null));
assertEquals(10, rules2.size());
List<RuleMetaData> rules3 = ruleDao.findByTenantIdAndPageLink(new TenantId(tenantId1), new TextPageLink(20, "name_", rules2.get(9).getId().getId(), null));
assertEquals(0, rules3.size());
}
use of org.thingsboard.server.common.data.page.TextPageLink in project thingsboard by thingsboard.
the class JpaTenantDaoTest method testFindTenantsByRegion.
@Test
@DatabaseSetup("classpath:dbunit/empty_dataset.xml")
public void testFindTenantsByRegion() {
createTenants();
assertEquals(60, tenantDao.find().size());
List<Tenant> tenants1 = tenantDao.findTenantsByRegion("REGION_1", new TextPageLink(20, "title"));
assertEquals(20, tenants1.size());
List<Tenant> tenants2 = tenantDao.findTenantsByRegion("REGION_1", new TextPageLink(20, "title", tenants1.get(19).getId().getId(), null));
assertEquals(10, tenants2.size());
List<Tenant> tenants3 = tenantDao.findTenantsByRegion("REGION_1", new TextPageLink(20, "title", tenants2.get(9).getId().getId(), null));
assertEquals(0, tenants3.size());
}
use of org.thingsboard.server.common.data.page.TextPageLink in project thingsboard by thingsboard.
the class BaseUserServiceTest method testFindCustomerUsers.
@Test
public void testFindCustomerUsers() {
User customerUser = userService.findUserByEmail("customer@thingsboard.org");
TextPageData<User> pageData = userService.findCustomerUsers(customerUser.getTenantId(), customerUser.getCustomerId(), new TextPageLink(10));
Assert.assertFalse(pageData.hasNext());
List<User> users = pageData.getData();
Assert.assertEquals(1, users.size());
Assert.assertEquals(customerUser, users.get(0));
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<User> customerUsers = new ArrayList<>();
for (int i = 0; i < 156; i++) {
User user = new User();
user.setAuthority(Authority.CUSTOMER_USER);
user.setTenantId(tenantId);
user.setCustomerId(customerId);
user.setEmail("testCustomer" + i + "@thingsboard.org");
customerUsers.add(userService.saveUser(user));
}
List<User> loadedCustomerUsers = new ArrayList<>();
TextPageLink pageLink = new TextPageLink(33);
do {
pageData = userService.findCustomerUsers(tenantId, customerId, pageLink);
loadedCustomerUsers.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageData.getNextPageLink();
}
} while (pageData.hasNext());
Collections.sort(customerUsers, idComparator);
Collections.sort(loadedCustomerUsers, idComparator);
Assert.assertEquals(customerUsers, loadedCustomerUsers);
tenantService.deleteTenant(tenantId);
pageData = userService.findCustomerUsers(tenantId, customerId, pageLink);
Assert.assertFalse(pageData.hasNext());
Assert.assertTrue(pageData.getData().isEmpty());
}
use of org.thingsboard.server.common.data.page.TextPageLink in project thingsboard by thingsboard.
the class JpaAssetDaoTest method testFindAssetsByTenantId.
@Test
public void testFindAssetsByTenantId() {
UUID tenantId1 = UUIDs.timeBased();
UUID tenantId2 = UUIDs.timeBased();
UUID customerId1 = UUIDs.timeBased();
UUID customerId2 = UUIDs.timeBased();
for (int i = 0; i < 60; i++) {
UUID assetId = UUIDs.timeBased();
UUID tenantId = i % 2 == 0 ? tenantId1 : tenantId2;
UUID customerId = i % 2 == 0 ? customerId1 : customerId2;
saveAsset(assetId, tenantId, customerId, "ASSET_" + i, "TYPE_1");
}
assertEquals(60, assetDao.find().size());
TextPageLink pageLink1 = new TextPageLink(20, "ASSET_");
List<Asset> assets1 = assetDao.findAssetsByTenantId(tenantId1, pageLink1);
assertEquals(20, assets1.size());
TextPageLink pageLink2 = new TextPageLink(20, "ASSET_", assets1.get(19).getId().getId(), null);
List<Asset> assets2 = assetDao.findAssetsByTenantId(tenantId1, pageLink2);
assertEquals(10, assets2.size());
TextPageLink pageLink3 = new TextPageLink(20, "ASSET_", assets2.get(9).getId().getId(), null);
List<Asset> assets3 = assetDao.findAssetsByTenantId(tenantId1, pageLink3);
assertEquals(0, assets3.size());
}
Aggregations