use of org.thingsboard.server.common.data.page.PageLink in project thingsboard by thingsboard.
the class BaseRuleChainServiceTest method testGetDefaultEdgeRuleChains.
@Test
public void testGetDefaultEdgeRuleChains() throws Exception {
RuleChainId ruleChainId = saveRuleChainAndSetAutoAssignToEdge("Default Edge Rule Chain 1");
saveRuleChainAndSetAutoAssignToEdge("Default Edge Rule Chain 2");
PageData<RuleChain> result = ruleChainService.findAutoAssignToEdgeRuleChainsByTenantId(tenantId, new PageLink(100));
Assert.assertEquals(2, result.getData().size());
ruleChainService.unsetAutoAssignToEdgeRuleChain(tenantId, ruleChainId);
result = ruleChainService.findAutoAssignToEdgeRuleChainsByTenantId(tenantId, new PageLink(100));
Assert.assertEquals(1, result.getData().size());
}
use of org.thingsboard.server.common.data.page.PageLink in project thingsboard by thingsboard.
the class BaseRuleChainServiceTest method testFindRuleChainsByTenantId.
@Test
public void testFindRuleChainsByTenantId() {
Tenant tenant = new Tenant();
tenant.setTitle("Test tenant");
tenant = tenantService.saveTenant(tenant);
TenantId tenantId = tenant.getId();
List<RuleChain> ruleChains = new ArrayList<>();
for (int i = 0; i < 165; i++) {
RuleChain ruleChain = new RuleChain();
ruleChain.setTenantId(tenantId);
ruleChain.setName("RuleChain" + i);
ruleChains.add(ruleChainService.saveRuleChain(ruleChain));
}
List<RuleChain> loadedRuleChains = new ArrayList<>();
PageLink pageLink = new PageLink(16);
PageData<RuleChain> pageData = null;
do {
pageData = ruleChainService.findTenantRuleChainsByType(tenantId, RuleChainType.CORE, pageLink);
loadedRuleChains.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageLink.nextPageLink();
}
} while (pageData.hasNext());
Collections.sort(ruleChains, idComparator);
Collections.sort(loadedRuleChains, idComparator);
Assert.assertEquals(ruleChains, loadedRuleChains);
ruleChainService.deleteRuleChainsByTenantId(tenantId);
pageLink = new PageLink(31);
pageData = ruleChainService.findTenantRuleChainsByType(tenantId, RuleChainType.CORE, 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 BaseTenantProfileServiceTest method testFindTenantProfiles.
@Test
public void testFindTenantProfiles() {
List<TenantProfile> tenantProfiles = new ArrayList<>();
PageLink pageLink = new PageLink(17);
PageData<TenantProfile> pageData = tenantProfileService.findTenantProfiles(TenantId.SYS_TENANT_ID, pageLink);
Assert.assertFalse(pageData.hasNext());
Assert.assertTrue(pageData.getData().isEmpty());
tenantProfiles.addAll(pageData.getData());
for (int i = 0; i < 28; i++) {
TenantProfile tenantProfile = this.createTenantProfile("Tenant Profile" + i);
tenantProfiles.add(tenantProfileService.saveTenantProfile(TenantId.SYS_TENANT_ID, tenantProfile));
}
List<TenantProfile> loadedTenantProfiles = new ArrayList<>();
pageLink = new PageLink(17);
do {
pageData = tenantProfileService.findTenantProfiles(TenantId.SYS_TENANT_ID, pageLink);
loadedTenantProfiles.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageLink.nextPageLink();
}
} while (pageData.hasNext());
Collections.sort(tenantProfiles, idComparator);
Collections.sort(loadedTenantProfiles, idComparator);
Assert.assertEquals(tenantProfiles, loadedTenantProfiles);
for (TenantProfile tenantProfile : loadedTenantProfiles) {
tenantProfileService.deleteTenantProfile(TenantId.SYS_TENANT_ID, tenantProfile.getId());
}
pageLink = new PageLink(17);
pageData = tenantProfileService.findTenantProfiles(TenantId.SYS_TENANT_ID, pageLink);
Assert.assertFalse(pageData.hasNext());
Assert.assertTrue(pageData.getData().isEmpty());
}
use of org.thingsboard.server.common.data.page.PageLink in project thingsboard by thingsboard.
the class BaseTenantProfileServiceTest method testFindTenantProfileInfos.
@Test
public void testFindTenantProfileInfos() {
List<TenantProfile> tenantProfiles = new ArrayList<>();
for (int i = 0; i < 28; i++) {
TenantProfile tenantProfile = this.createTenantProfile("Tenant Profile" + i);
tenantProfiles.add(tenantProfileService.saveTenantProfile(TenantId.SYS_TENANT_ID, tenantProfile));
}
List<EntityInfo> loadedTenantProfileInfos = new ArrayList<>();
PageLink pageLink = new PageLink(17);
PageData<EntityInfo> pageData;
do {
pageData = tenantProfileService.findTenantProfileInfos(TenantId.SYS_TENANT_ID, pageLink);
loadedTenantProfileInfos.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageLink.nextPageLink();
}
} while (pageData.hasNext());
Collections.sort(tenantProfiles, idComparator);
Collections.sort(loadedTenantProfileInfos, tenantProfileInfoIdComparator);
List<EntityInfo> tenantProfileInfos = tenantProfiles.stream().map(tenantProfile -> new EntityInfo(tenantProfile.getId(), tenantProfile.getName())).collect(Collectors.toList());
Assert.assertEquals(tenantProfileInfos, loadedTenantProfileInfos);
for (EntityInfo tenantProfile : loadedTenantProfileInfos) {
tenantProfileService.deleteTenantProfile(TenantId.SYS_TENANT_ID, new TenantProfileId(tenantProfile.getId().getId()));
}
pageLink = new PageLink(17);
pageData = tenantProfileService.findTenantProfileInfos(TenantId.SYS_TENANT_ID, pageLink);
Assert.assertFalse(pageData.hasNext());
Assert.assertTrue(pageData.getData().isEmpty());
}
use of org.thingsboard.server.common.data.page.PageLink in project thingsboard by thingsboard.
the class BaseUserServiceTest method testFindCustomerUsers.
@Test
public void testFindCustomerUsers() {
User customerUser = userService.findUserByEmail(tenantId, "customer@thingsboard.org");
PageData<User> pageData = userService.findCustomerUsers(customerUser.getTenantId(), customerUser.getCustomerId(), new PageLink(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<>();
PageLink pageLink = new PageLink(33);
do {
pageData = userService.findCustomerUsers(tenantId, customerId, 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);
tenantService.deleteTenant(tenantId);
pageData = userService.findCustomerUsers(tenantId, customerId, pageLink);
Assert.assertFalse(pageData.hasNext());
Assert.assertTrue(pageData.getData().isEmpty());
}
Aggregations