Search in sources :

Example 46 with PageLink

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

the class BaseTbResourceControllerTest method testFindSystemTbResources.

@Test
public void testFindSystemTbResources() throws Exception {
    loginSysAdmin();
    List<TbResourceInfo> resources = new ArrayList<>();
    for (int i = 0; i < 173; i++) {
        TbResource resource = new TbResource();
        resource.setTitle("Resource" + i);
        resource.setResourceType(ResourceType.JKS);
        resource.setFileName(i + DEFAULT_FILE_NAME);
        resource.setData("Test Data");
        resources.add(new TbResourceInfo(save(resource)));
    }
    List<TbResourceInfo> loadedResources = new ArrayList<>();
    PageLink pageLink = new PageLink(24);
    PageData<TbResourceInfo> pageData;
    do {
        pageData = doGetTypedWithPageLink("/api/resource?", new TypeReference<PageData<TbResourceInfo>>() {
        }, pageLink);
        loadedResources.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageLink.nextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(resources, idComparator);
    Collections.sort(loadedResources, idComparator);
    Assert.assertEquals(resources, loadedResources);
    for (TbResourceInfo resource : resources) {
        doDelete("/api/resource/" + resource.getId().getId().toString()).andExpect(status().isOk());
    }
    pageLink = new PageLink(27);
    loadedResources.clear();
    do {
        pageData = doGetTypedWithPageLink("/api/resource?", new TypeReference<PageData<TbResourceInfo>>() {
        }, pageLink);
        loadedResources.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageLink.nextPageLink();
        }
    } while (pageData.hasNext());
    Assert.assertTrue(loadedResources.isEmpty());
}
Also used : TbResourceInfo(org.thingsboard.server.common.data.TbResourceInfo) ArrayList(java.util.ArrayList) PageLink(org.thingsboard.server.common.data.page.PageLink) TypeReference(com.fasterxml.jackson.core.type.TypeReference) TbResource(org.thingsboard.server.common.data.TbResource) Test(org.junit.Test)

Example 47 with PageLink

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

the class BaseTbResourceControllerTest method testFindSystemAndTenantTbResources.

@Test
public void testFindSystemAndTenantTbResources() throws Exception {
    List<TbResourceInfo> systemResources = new ArrayList<>();
    List<TbResourceInfo> expectedResources = new ArrayList<>();
    for (int i = 0; i < 73; i++) {
        TbResource resource = new TbResource();
        resource.setTitle("Resource" + i);
        resource.setResourceType(ResourceType.JKS);
        resource.setFileName(i + DEFAULT_FILE_NAME);
        resource.setData("Test Data");
        expectedResources.add(new TbResourceInfo(save(resource)));
    }
    loginSysAdmin();
    for (int i = 0; i < 173; i++) {
        TbResource resource = new TbResource();
        resource.setTitle("Resource" + i);
        resource.setResourceType(ResourceType.JKS);
        resource.setFileName(i + DEFAULT_FILE_NAME);
        resource.setData("Test Data");
        TbResourceInfo savedResource = new TbResourceInfo(save(resource));
        systemResources.add(savedResource);
        if (i >= 73) {
            expectedResources.add(savedResource);
        }
    }
    login(tenantAdmin.getEmail(), "testPassword1");
    List<TbResourceInfo> loadedResources = new ArrayList<>();
    PageLink pageLink = new PageLink(24);
    PageData<TbResourceInfo> pageData;
    do {
        pageData = doGetTypedWithPageLink("/api/resource?", new TypeReference<PageData<TbResourceInfo>>() {
        }, pageLink);
        loadedResources.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageLink.nextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(expectedResources, idComparator);
    Collections.sort(loadedResources, idComparator);
    Assert.assertEquals(expectedResources, loadedResources);
    loginSysAdmin();
    for (TbResourceInfo resource : systemResources) {
        doDelete("/api/resource/" + resource.getId().getId().toString()).andExpect(status().isOk());
    }
}
Also used : TbResourceInfo(org.thingsboard.server.common.data.TbResourceInfo) ArrayList(java.util.ArrayList) PageLink(org.thingsboard.server.common.data.page.PageLink) TypeReference(com.fasterxml.jackson.core.type.TypeReference) TbResource(org.thingsboard.server.common.data.TbResource) Test(org.junit.Test)

Example 48 with PageLink

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

the class BaseUserControllerTest method testFindTenantAdminsByEmail.

@Test
public void testFindTenantAdminsByEmail() throws Exception {
    loginSysAdmin();
    String email1 = "testEmail1";
    List<User> tenantAdminsEmail1 = new ArrayList<>();
    for (int i = 0; i < 124; 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(doPost("/api/user", user, User.class));
    }
    String email2 = "testEmail2";
    List<User> tenantAdminsEmail2 = new ArrayList<>();
    for (int i = 0; i < 112; 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(doPost("/api/user", user, User.class));
    }
    List<User> loadedTenantAdminsEmail1 = new ArrayList<>();
    PageLink pageLink = new PageLink(33, 0, email1);
    PageData<User> pageData = null;
    do {
        pageData = doGetTypedWithPageLink("/api/tenant/" + tenantId.getId().toString() + "/users?", new TypeReference<PageData<User>>() {
        }, pageLink);
        loadedTenantAdminsEmail1.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageLink.nextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(tenantAdminsEmail1, idComparator);
    Collections.sort(loadedTenantAdminsEmail1, idComparator);
    Assert.assertEquals(tenantAdminsEmail1, loadedTenantAdminsEmail1);
    List<User> loadedTenantAdminsEmail2 = new ArrayList<>();
    pageLink = new PageLink(16, 0, email2);
    do {
        pageData = doGetTypedWithPageLink("/api/tenant/" + tenantId.getId().toString() + "/users?", new TypeReference<PageData<User>>() {
        }, pageLink);
        loadedTenantAdminsEmail2.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageLink.nextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(tenantAdminsEmail2, idComparator);
    Collections.sort(loadedTenantAdminsEmail2, idComparator);
    Assert.assertEquals(tenantAdminsEmail2, loadedTenantAdminsEmail2);
    for (User user : loadedTenantAdminsEmail1) {
        doDelete("/api/user/" + user.getId().getId().toString()).andExpect(status().isOk());
    }
    pageLink = new PageLink(4, 0, email1);
    pageData = doGetTypedWithPageLink("/api/tenant/" + tenantId.getId().toString() + "/users?", new TypeReference<PageData<User>>() {
    }, pageLink);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertEquals(0, pageData.getData().size());
    for (User user : loadedTenantAdminsEmail2) {
        doDelete("/api/user/" + user.getId().getId().toString()).andExpect(status().isOk());
    }
    pageLink = new PageLink(4, 0, email2);
    pageData = doGetTypedWithPageLink("/api/tenant/" + tenantId.getId().toString() + "/users?", new TypeReference<PageData<User>>() {
    }, pageLink);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertEquals(0, pageData.getData().size());
}
Also used : User(org.thingsboard.server.common.data.User) ArrayList(java.util.ArrayList) PageLink(org.thingsboard.server.common.data.page.PageLink) Matchers.containsString(org.hamcrest.Matchers.containsString) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Test(org.junit.Test)

Example 49 with PageLink

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

the class BaseEntityViewControllerTest method testGetTenantEntityViews.

@Test
public void testGetTenantEntityViews() throws Exception {
    List<EntityViewInfo> views = new ArrayList<>();
    for (int i = 0; i < 178; i++) {
        views.add(new EntityViewInfo(getNewSavedEntityView("Test entity view" + i), null, false));
    }
    List<EntityViewInfo> loadedViews = loadListOfInfo(new PageLink(23), "/api/tenant/entityViewInfos?");
    Collections.sort(views, idComparator);
    Collections.sort(loadedViews, idComparator);
    assertEquals(views, loadedViews);
}
Also used : ArrayList(java.util.ArrayList) PageLink(org.thingsboard.server.common.data.page.PageLink) EntityViewInfo(org.thingsboard.server.common.data.EntityViewInfo) Test(org.junit.Test)

Example 50 with PageLink

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

the class BaseEntityViewControllerTest method testGetCustomerEntityViews.

@Test
public void testGetCustomerEntityViews() throws Exception {
    Customer customer = doPost("/api/customer", getNewCustomer("Test customer"), Customer.class);
    CustomerId customerId = customer.getId();
    String urlTemplate = "/api/customer/" + customerId.getId().toString() + "/entityViewInfos?";
    List<EntityViewInfo> views = new ArrayList<>();
    for (int i = 0; i < 128; i++) {
        views.add(new EntityViewInfo(doPost("/api/customer/" + customerId.getId().toString() + "/entityView/" + getNewSavedEntityView("Test entity view " + i).getId().getId().toString(), EntityView.class), customer.getTitle(), customer.isPublic()));
    }
    List<EntityViewInfo> loadedViews = loadListOfInfo(new PageLink(23), urlTemplate);
    Collections.sort(views, idComparator);
    Collections.sort(loadedViews, idComparator);
    assertEquals(views, loadedViews);
}
Also used : Customer(org.thingsboard.server.common.data.Customer) ArrayList(java.util.ArrayList) PageLink(org.thingsboard.server.common.data.page.PageLink) EntityViewInfo(org.thingsboard.server.common.data.EntityViewInfo) CustomerId(org.thingsboard.server.common.data.id.CustomerId) Matchers.containsString(org.hamcrest.Matchers.containsString) 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