Search in sources :

Example 86 with PageLink

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());
}
Also used : RuleChain(org.thingsboard.server.common.data.rule.RuleChain) PageLink(org.thingsboard.server.common.data.page.PageLink) RuleChainId(org.thingsboard.server.common.data.id.RuleChainId) Test(org.junit.Test)

Example 87 with PageLink

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);
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) Tenant(org.thingsboard.server.common.data.Tenant) RuleChain(org.thingsboard.server.common.data.rule.RuleChain) ArrayList(java.util.ArrayList) PageLink(org.thingsboard.server.common.data.page.PageLink) Test(org.junit.Test)

Example 88 with PageLink

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());
}
Also used : ArrayList(java.util.ArrayList) PageLink(org.thingsboard.server.common.data.page.PageLink) TenantProfile(org.thingsboard.server.common.data.TenantProfile) Test(org.junit.Test)

Example 89 with PageLink

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());
}
Also used : EntityInfo(org.thingsboard.server.common.data.EntityInfo) PageLink(org.thingsboard.server.common.data.page.PageLink) TenantProfileData(org.thingsboard.server.common.data.tenant.profile.TenantProfileData) Tenant(org.thingsboard.server.common.data.Tenant) Test(org.junit.Test) DefaultTenantProfileConfiguration(org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileConfiguration) Collectors(java.util.stream.Collectors) TenantId(org.thingsboard.server.common.data.id.TenantId) ArrayList(java.util.ArrayList) DataValidationException(org.thingsboard.server.dao.exception.DataValidationException) List(java.util.List) TenantProfile(org.thingsboard.server.common.data.TenantProfile) After(org.junit.After) TenantProfileId(org.thingsboard.server.common.data.id.TenantProfileId) PageData(org.thingsboard.server.common.data.page.PageData) Assert(org.junit.Assert) Collections(java.util.Collections) EntityInfo(org.thingsboard.server.common.data.EntityInfo) TenantProfileId(org.thingsboard.server.common.data.id.TenantProfileId) ArrayList(java.util.ArrayList) PageLink(org.thingsboard.server.common.data.page.PageLink) TenantProfile(org.thingsboard.server.common.data.TenantProfile) Test(org.junit.Test)

Example 90 with PageLink

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());
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) User(org.thingsboard.server.common.data.User) Tenant(org.thingsboard.server.common.data.Tenant) Customer(org.thingsboard.server.common.data.Customer) PageLink(org.thingsboard.server.common.data.page.PageLink) ArrayList(java.util.ArrayList) CustomerId(org.thingsboard.server.common.data.id.CustomerId) Test(org.junit.Test)

Aggregations

PageLink (org.thingsboard.server.common.data.page.PageLink)187 Test (org.junit.Test)117 ArrayList (java.util.ArrayList)106 TenantId (org.thingsboard.server.common.data.id.TenantId)67 TypeReference (com.fasterxml.jackson.core.type.TypeReference)54 CustomerId (org.thingsboard.server.common.data.id.CustomerId)47 Tenant (org.thingsboard.server.common.data.Tenant)45 Customer (org.thingsboard.server.common.data.Customer)43 ThingsboardException (org.thingsboard.server.common.data.exception.ThingsboardException)34 ApiOperation (io.swagger.annotations.ApiOperation)33 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)33 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)33 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)33 Edge (org.thingsboard.server.common.data.edge.Edge)32 Device (org.thingsboard.server.common.data.Device)28 PageData (org.thingsboard.server.common.data.page.PageData)28 Matchers.containsString (org.hamcrest.Matchers.containsString)22 UUID (java.util.UUID)20 Asset (org.thingsboard.server.common.data.asset.Asset)20 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)20