Search in sources :

Example 21 with TextPageLink

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

the class BaseWidgetsBundleControllerTest method testFindSystemWidgetsBundlesByPageLink.

@Test
public void testFindSystemWidgetsBundlesByPageLink() throws Exception {
    loginSysAdmin();
    List<WidgetsBundle> sysWidgetsBundles = doGetTyped("/api/widgetsBundles?", new TypeReference<List<WidgetsBundle>>() {
    });
    List<WidgetsBundle> createdWidgetsBundles = new ArrayList<>();
    for (int i = 0; i < 120; i++) {
        WidgetsBundle widgetsBundle = new WidgetsBundle();
        widgetsBundle.setTitle("Widgets bundle" + i);
        createdWidgetsBundles.add(doPost("/api/widgetsBundle", widgetsBundle, WidgetsBundle.class));
    }
    List<WidgetsBundle> widgetsBundles = new ArrayList<>(createdWidgetsBundles);
    widgetsBundles.addAll(sysWidgetsBundles);
    List<WidgetsBundle> loadedWidgetsBundles = new ArrayList<>();
    TextPageLink pageLink = new TextPageLink(14);
    TextPageData<WidgetsBundle> pageData;
    do {
        pageData = doGetTypedWithPageLink("/api/widgetsBundles?", new TypeReference<TextPageData<WidgetsBundle>>() {
        }, pageLink);
        loadedWidgetsBundles.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(widgetsBundles, idComparator);
    Collections.sort(loadedWidgetsBundles, idComparator);
    Assert.assertEquals(widgetsBundles, loadedWidgetsBundles);
    for (WidgetsBundle widgetsBundle : createdWidgetsBundles) {
        doDelete("/api/widgetsBundle/" + widgetsBundle.getId().getId().toString()).andExpect(status().isOk());
    }
    pageLink = new TextPageLink(17);
    loadedWidgetsBundles.clear();
    do {
        pageData = doGetTypedWithPageLink("/api/widgetsBundles?", new TypeReference<TextPageData<WidgetsBundle>>() {
        }, pageLink);
        loadedWidgetsBundles.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(sysWidgetsBundles, idComparator);
    Collections.sort(loadedWidgetsBundles, idComparator);
    Assert.assertEquals(sysWidgetsBundles, loadedWidgetsBundles);
}
Also used : TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TypeReference(com.fasterxml.jackson.core.type.TypeReference) WidgetsBundle(org.thingsboard.server.common.data.widget.WidgetsBundle) Test(org.junit.Test)

Example 22 with TextPageLink

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

the class JpaBaseComponentDescriptorDaoTest method findByTypeAndSocpe.

@Test
public void findByTypeAndSocpe() {
    for (int i = 0; i < 20; i++) {
        createComponentDescriptor(ComponentType.PLUGIN, ComponentScope.SYSTEM, i);
        createComponentDescriptor(ComponentType.ACTION, ComponentScope.TENANT, i + 20);
        createComponentDescriptor(ComponentType.FILTER, ComponentScope.SYSTEM, i + 40);
    }
    TextPageLink pageLink1 = new TextPageLink(15, "COMPONENT_");
    List<ComponentDescriptor> components1 = componentDescriptorDao.findByScopeAndTypeAndPageLink(ComponentScope.SYSTEM, ComponentType.FILTER, pageLink1);
    assertEquals(15, components1.size());
    TextPageLink pageLink2 = new TextPageLink(15, "COMPONENT_", components1.get(14).getId().getId(), null);
    List<ComponentDescriptor> components2 = componentDescriptorDao.findByScopeAndTypeAndPageLink(ComponentScope.SYSTEM, ComponentType.FILTER, pageLink2);
    assertEquals(5, components2.size());
}
Also used : TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) ComponentDescriptor(org.thingsboard.server.common.data.plugin.ComponentDescriptor) AbstractJpaDaoTest(org.thingsboard.server.dao.AbstractJpaDaoTest) Test(org.junit.Test)

Example 23 with TextPageLink

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

the class JpaBaseComponentDescriptorDaoTest method findByType.

@Test
public void findByType() {
    for (int i = 0; i < 20; i++) {
        createComponentDescriptor(ComponentType.PLUGIN, ComponentScope.SYSTEM, i);
        createComponentDescriptor(ComponentType.ACTION, ComponentScope.TENANT, i + 20);
    }
    TextPageLink pageLink1 = new TextPageLink(15, "COMPONENT_");
    List<ComponentDescriptor> components1 = componentDescriptorDao.findByTypeAndPageLink(ComponentType.PLUGIN, pageLink1);
    assertEquals(15, components1.size());
    TextPageLink pageLink2 = new TextPageLink(15, "COMPONENT_", components1.get(14).getId().getId(), null);
    List<ComponentDescriptor> components2 = componentDescriptorDao.findByTypeAndPageLink(ComponentType.PLUGIN, pageLink2);
    assertEquals(5, components2.size());
}
Also used : TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) ComponentDescriptor(org.thingsboard.server.common.data.plugin.ComponentDescriptor) AbstractJpaDaoTest(org.thingsboard.server.dao.AbstractJpaDaoTest) Test(org.junit.Test)

Example 24 with TextPageLink

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

the class JpaCustomerDaoTest method testFindByTenantId.

@Test
public void testFindByTenantId() {
    UUID tenantId1 = UUIDs.timeBased();
    UUID tenantId2 = UUIDs.timeBased();
    for (int i = 0; i < 20; i++) {
        createCustomer(tenantId1, i);
        createCustomer(tenantId2, i * 2);
    }
    TextPageLink pageLink1 = new TextPageLink(15, "CUSTOMER");
    List<Customer> customers1 = customerDao.findCustomersByTenantId(tenantId1, pageLink1);
    assertEquals(15, customers1.size());
    TextPageLink pageLink2 = new TextPageLink(15, "CUSTOMER", customers1.get(14).getId().getId(), null);
    List<Customer> customers2 = customerDao.findCustomersByTenantId(tenantId1, pageLink2);
    assertEquals(5, customers2.size());
}
Also used : TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) Customer(org.thingsboard.server.common.data.Customer) UUID(java.util.UUID) AbstractJpaDaoTest(org.thingsboard.server.dao.AbstractJpaDaoTest) Test(org.junit.Test)

Example 25 with TextPageLink

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

the class JpaDashboardInfoDaoTest method testFindDashboardsByTenantId.

@Test
public void testFindDashboardsByTenantId() {
    UUID tenantId1 = UUIDs.timeBased();
    UUID tenantId2 = UUIDs.timeBased();
    for (int i = 0; i < 20; i++) {
        createDashboard(tenantId1, i);
        createDashboard(tenantId2, i * 2);
    }
    TextPageLink pageLink1 = new TextPageLink(15, "DASHBOARD");
    List<DashboardInfo> dashboardInfos1 = dashboardInfoDao.findDashboardsByTenantId(tenantId1, pageLink1);
    Assert.assertEquals(15, dashboardInfos1.size());
    TextPageLink pageLink2 = new TextPageLink(15, "DASHBOARD", dashboardInfos1.get(14).getId().getId(), null);
    List<DashboardInfo> dashboardInfos2 = dashboardInfoDao.findDashboardsByTenantId(tenantId1, pageLink2);
    Assert.assertEquals(5, dashboardInfos2.size());
}
Also used : TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) UUID(java.util.UUID) DashboardInfo(org.thingsboard.server.common.data.DashboardInfo) 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