Search in sources :

Example 26 with TextPageLink

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());
}
Also used : TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) Device(org.thingsboard.server.common.data.Device) UUID(java.util.UUID) AbstractJpaDaoTest(org.thingsboard.server.dao.AbstractJpaDaoTest) Test(org.junit.Test)

Example 27 with TextPageLink

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());
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) RuleMetaData(org.thingsboard.server.common.data.rule.RuleMetaData) UUID(java.util.UUID) AbstractJpaDaoTest(org.thingsboard.server.dao.AbstractJpaDaoTest) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup)

Example 28 with TextPageLink

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());
}
Also used : Tenant(org.thingsboard.server.common.data.Tenant) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) AbstractJpaDaoTest(org.thingsboard.server.dao.AbstractJpaDaoTest) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup)

Example 29 with TextPageLink

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

Example 30 with TextPageLink

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());
}
Also used : TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) Asset(org.thingsboard.server.common.data.asset.Asset) UUID(java.util.UUID) AbstractJpaDaoTest(org.thingsboard.server.dao.AbstractJpaDaoTest) Test(org.junit.Test)

Aggregations

TextPageLink (org.thingsboard.server.common.data.page.TextPageLink)93 Test (org.junit.Test)75 ArrayList (java.util.ArrayList)58 TenantId (org.thingsboard.server.common.data.id.TenantId)37 TypeReference (com.fasterxml.jackson.core.type.TypeReference)27 Tenant (org.thingsboard.server.common.data.Tenant)24 CustomerId (org.thingsboard.server.common.data.id.CustomerId)19 Customer (org.thingsboard.server.common.data.Customer)18 AbstractJpaDaoTest (org.thingsboard.server.dao.AbstractJpaDaoTest)18 UUID (java.util.UUID)15 Asset (org.thingsboard.server.common.data.asset.Asset)14 Matchers.containsString (org.hamcrest.Matchers.containsString)13 User (org.thingsboard.server.common.data.User)13 DatabaseSetup (com.github.springtestdbunit.annotation.DatabaseSetup)11 PluginMetaData (org.thingsboard.server.common.data.plugin.PluginMetaData)11 WidgetsBundle (org.thingsboard.server.common.data.widget.WidgetsBundle)11 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)10 RuleMetaData (org.thingsboard.server.common.data.rule.RuleMetaData)10 ThingsboardException (org.thingsboard.server.exception.ThingsboardException)10 Device (org.thingsboard.server.common.data.Device)7