Search in sources :

Example 56 with TextPageLink

use of org.thingsboard.server.common.data.page.TextPageLink in project thingsboard by thingsboard.

the class BaseDeviceServiceTest method testFindDevicesByTenantId.

@Test
public void testFindDevicesByTenantId() {
    Tenant tenant = new Tenant();
    tenant.setTitle("Test tenant");
    tenant = tenantService.saveTenant(tenant);
    TenantId tenantId = tenant.getId();
    List<Device> devices = new ArrayList<>();
    for (int i = 0; i < 178; i++) {
        Device device = new Device();
        device.setTenantId(tenantId);
        device.setName("Device" + i);
        device.setType("default");
        devices.add(deviceService.saveDevice(device));
    }
    List<Device> loadedDevices = new ArrayList<>();
    TextPageLink pageLink = new TextPageLink(23);
    TextPageData<Device> pageData = null;
    do {
        pageData = deviceService.findDevicesByTenantId(tenantId, pageLink);
        loadedDevices.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(devices, idComparator);
    Collections.sort(loadedDevices, idComparator);
    Assert.assertEquals(devices, loadedDevices);
    deviceService.deleteDevicesByTenantId(tenantId);
    pageLink = new TextPageLink(33);
    pageData = deviceService.findDevicesByTenantId(tenantId, 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) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) Device(org.thingsboard.server.common.data.Device) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 57 with TextPageLink

use of org.thingsboard.server.common.data.page.TextPageLink in project thingsboard by thingsboard.

the class BaseTenantServiceTest method testFindTenants.

@Test
public void testFindTenants() {
    List<Tenant> tenants = new ArrayList<>();
    TextPageLink pageLink = new TextPageLink(17);
    TextPageData<Tenant> pageData = tenantService.findTenants(pageLink);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertTrue(pageData.getData().isEmpty());
    tenants.addAll(pageData.getData());
    for (int i = 0; i < 156; i++) {
        Tenant tenant = new Tenant();
        tenant.setTitle("Tenant" + i);
        tenants.add(tenantService.saveTenant(tenant));
    }
    List<Tenant> loadedTenants = new ArrayList<>();
    pageLink = new TextPageLink(17);
    do {
        pageData = tenantService.findTenants(pageLink);
        loadedTenants.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(tenants, idComparator);
    Collections.sort(loadedTenants, idComparator);
    Assert.assertEquals(tenants, loadedTenants);
    for (Tenant tenant : loadedTenants) {
        if (!tenant.getTitle().equals("Tenant")) {
            tenantService.deleteTenant(tenant.getId());
        }
    }
    pageLink = new TextPageLink(17);
    pageData = tenantService.findTenants(pageLink);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertTrue(pageData.getData().isEmpty());
}
Also used : Tenant(org.thingsboard.server.common.data.Tenant) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 58 with TextPageLink

use of org.thingsboard.server.common.data.page.TextPageLink in project thingsboard by thingsboard.

the class BaseUserServiceTest method testFindCustomerUsersByEmail.

@Test
public void testFindCustomerUsersByEmail() {
    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();
    String email1 = "testEmail1";
    List<User> customerUsersEmail1 = new ArrayList<>();
    for (int i = 0; i < 124; i++) {
        User user = new User();
        user.setAuthority(Authority.CUSTOMER_USER);
        user.setTenantId(tenantId);
        user.setCustomerId(customerId);
        String suffix = RandomStringUtils.randomAlphanumeric((int) (5 + Math.random() * 10));
        String email = email1 + suffix + "@thingsboard.org";
        email = i % 2 == 0 ? email.toLowerCase() : email.toUpperCase();
        user.setEmail(email);
        customerUsersEmail1.add(userService.saveUser(user));
    }
    String email2 = "testEmail2";
    List<User> customerUsersEmail2 = new ArrayList<>();
    for (int i = 0; i < 132; i++) {
        User user = new User();
        user.setAuthority(Authority.CUSTOMER_USER);
        user.setTenantId(tenantId);
        user.setCustomerId(customerId);
        String suffix = RandomStringUtils.randomAlphanumeric((int) (5 + Math.random() * 10));
        String email = email2 + suffix + "@thingsboard.org";
        email = i % 2 == 0 ? email.toLowerCase() : email.toUpperCase();
        user.setEmail(email);
        customerUsersEmail2.add(userService.saveUser(user));
    }
    List<User> loadedCustomerUsersEmail1 = new ArrayList<>();
    TextPageLink pageLink = new TextPageLink(33, email1);
    TextPageData<User> pageData = null;
    do {
        pageData = userService.findCustomerUsers(tenantId, customerId, pageLink);
        loadedCustomerUsersEmail1.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(customerUsersEmail1, idComparator);
    Collections.sort(loadedCustomerUsersEmail1, idComparator);
    Assert.assertEquals(customerUsersEmail1, loadedCustomerUsersEmail1);
    List<User> loadedCustomerUsersEmail2 = new ArrayList<>();
    pageLink = new TextPageLink(16, email2);
    do {
        pageData = userService.findCustomerUsers(tenantId, customerId, pageLink);
        loadedCustomerUsersEmail2.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(customerUsersEmail2, idComparator);
    Collections.sort(loadedCustomerUsersEmail2, idComparator);
    Assert.assertEquals(customerUsersEmail2, loadedCustomerUsersEmail2);
    for (User user : loadedCustomerUsersEmail1) {
        userService.deleteUser(user.getId());
    }
    pageLink = new TextPageLink(4, email1);
    pageData = userService.findCustomerUsers(tenantId, customerId, pageLink);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertEquals(0, pageData.getData().size());
    for (User user : loadedCustomerUsersEmail2) {
        userService.deleteUser(user.getId());
    }
    pageLink = new TextPageLink(4, email2);
    pageData = userService.findCustomerUsers(tenantId, customerId, pageLink);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertEquals(0, pageData.getData().size());
    tenantService.deleteTenant(tenantId);
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) Tenant(org.thingsboard.server.common.data.Tenant) User(org.thingsboard.server.common.data.User) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) Customer(org.thingsboard.server.common.data.Customer) ArrayList(java.util.ArrayList) CustomerId(org.thingsboard.server.common.data.id.CustomerId) Test(org.junit.Test)

Example 59 with TextPageLink

use of org.thingsboard.server.common.data.page.TextPageLink in project thingsboard by thingsboard.

the class BaseUserServiceTest method testFindTenantAdmins.

@Test
public void testFindTenantAdmins() {
    User tenantAdminUser = userService.findUserByEmail("tenant@thingsboard.org");
    TextPageData<User> pageData = userService.findTenantAdmins(tenantAdminUser.getTenantId(), new TextPageLink(10));
    Assert.assertFalse(pageData.hasNext());
    List<User> users = pageData.getData();
    Assert.assertEquals(1, users.size());
    Assert.assertEquals(tenantAdminUser, users.get(0));
    Tenant tenant = new Tenant();
    tenant.setTitle("Test tenant");
    tenant = tenantService.saveTenant(tenant);
    TenantId tenantId = tenant.getId();
    List<User> tenantAdmins = new ArrayList<>();
    for (int i = 0; i < 124; i++) {
        User user = new User();
        user.setAuthority(Authority.TENANT_ADMIN);
        user.setTenantId(tenantId);
        user.setEmail("testTenant" + i + "@thingsboard.org");
        tenantAdmins.add(userService.saveUser(user));
    }
    List<User> loadedTenantAdmins = new ArrayList<>();
    TextPageLink pageLink = new TextPageLink(33);
    do {
        pageData = userService.findTenantAdmins(tenantId, pageLink);
        loadedTenantAdmins.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(tenantAdmins, idComparator);
    Collections.sort(loadedTenantAdmins, idComparator);
    Assert.assertEquals(tenantAdmins, loadedTenantAdmins);
    tenantService.deleteTenant(tenantId);
    pageLink = new TextPageLink(33);
    pageData = userService.findTenantAdmins(tenantId, 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) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 60 with TextPageLink

use of org.thingsboard.server.common.data.page.TextPageLink in project thingsboard by thingsboard.

the class BaseUserServiceTest method testFindTenantAdminsByEmail.

@Test
public void testFindTenantAdminsByEmail() {
    Tenant tenant = new Tenant();
    tenant.setTitle("Test tenant");
    tenant = tenantService.saveTenant(tenant);
    TenantId tenantId = tenant.getId();
    String email1 = "testEmail1";
    List<User> tenantAdminsEmail1 = new ArrayList<>();
    for (int i = 0; i < 94; i++) {
        User user = new User();
        user.setAuthority(Authority.TENANT_ADMIN);
        user.setTenantId(tenantId);
        String suffix = RandomStringUtils.randomAlphanumeric((int) (5 + Math.random() * 10));
        String email = email1 + suffix + "@thingsboard.org";
        email = i % 2 == 0 ? email.toLowerCase() : email.toUpperCase();
        user.setEmail(email);
        tenantAdminsEmail1.add(userService.saveUser(user));
    }
    String email2 = "testEmail2";
    List<User> tenantAdminsEmail2 = new ArrayList<>();
    for (int i = 0; i < 132; i++) {
        User user = new User();
        user.setAuthority(Authority.TENANT_ADMIN);
        user.setTenantId(tenantId);
        String suffix = RandomStringUtils.randomAlphanumeric((int) (5 + Math.random() * 10));
        String email = email2 + suffix + "@thingsboard.org";
        email = i % 2 == 0 ? email.toLowerCase() : email.toUpperCase();
        user.setEmail(email);
        tenantAdminsEmail2.add(userService.saveUser(user));
    }
    List<User> loadedTenantAdminsEmail1 = new ArrayList<>();
    TextPageLink pageLink = new TextPageLink(33, email1);
    TextPageData<User> pageData = null;
    do {
        pageData = userService.findTenantAdmins(tenantId, pageLink);
        loadedTenantAdminsEmail1.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(tenantAdminsEmail1, idComparator);
    Collections.sort(loadedTenantAdminsEmail1, idComparator);
    Assert.assertEquals(tenantAdminsEmail1, loadedTenantAdminsEmail1);
    List<User> loadedTenantAdminsEmail2 = new ArrayList<>();
    pageLink = new TextPageLink(16, email2);
    do {
        pageData = userService.findTenantAdmins(tenantId, pageLink);
        loadedTenantAdminsEmail2.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(tenantAdminsEmail2, idComparator);
    Collections.sort(loadedTenantAdminsEmail2, idComparator);
    Assert.assertEquals(tenantAdminsEmail2, loadedTenantAdminsEmail2);
    for (User user : loadedTenantAdminsEmail1) {
        userService.deleteUser(user.getId());
    }
    pageLink = new TextPageLink(4, email1);
    pageData = userService.findTenantAdmins(tenantId, pageLink);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertEquals(0, pageData.getData().size());
    for (User user : loadedTenantAdminsEmail2) {
        userService.deleteUser(user.getId());
    }
    pageLink = new TextPageLink(4, email2);
    pageData = userService.findTenantAdmins(tenantId, pageLink);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertEquals(0, pageData.getData().size());
    tenantService.deleteTenant(tenantId);
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) Tenant(org.thingsboard.server.common.data.Tenant) User(org.thingsboard.server.common.data.User) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) ArrayList(java.util.ArrayList) 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