Search in sources :

Example 31 with TextPageLink

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

the class JpaAssetDaoTest method testFindAssetsByTenantIdAndCustomerId.

@Test
public void testFindAssetsByTenantIdAndCustomerId() {
    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");
    }
    TextPageLink pageLink1 = new TextPageLink(20, "ASSET_");
    List<Asset> assets1 = assetDao.findAssetsByTenantIdAndCustomerId(tenantId1, customerId1, pageLink1);
    assertEquals(20, assets1.size());
    TextPageLink pageLink2 = new TextPageLink(20, "ASSET_", assets1.get(19).getId().getId(), null);
    List<Asset> assets2 = assetDao.findAssetsByTenantIdAndCustomerId(tenantId1, customerId1, pageLink2);
    assertEquals(10, assets2.size());
    TextPageLink pageLink3 = new TextPageLink(20, "ASSET_", assets2.get(9).getId().getId(), null);
    List<Asset> assets3 = assetDao.findAssetsByTenantIdAndCustomerId(tenantId1, customerId1, 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)

Example 32 with TextPageLink

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

the class JpaUserDaoTest method testFindCustomerUsers.

@Test
@DatabaseSetup("classpath:dbunit/empty_dataset.xml")
public void testFindCustomerUsers() {
    UUID tenantId = UUIDs.timeBased();
    UUID customerId = UUIDs.timeBased();
    create30Adminsand60Users(tenantId, customerId);
    List<User> customerUsers1 = userDao.findCustomerUsers(tenantId, customerId, new TextPageLink(40));
    assertEquals(40, customerUsers1.size());
    List<User> customerUsers2 = userDao.findCustomerUsers(tenantId, customerId, new TextPageLink(20, null, customerUsers1.get(39).getId().getId(), null));
    assertEquals(20, customerUsers2.size());
    List<User> customerUsers3 = userDao.findCustomerUsers(tenantId, customerId, new TextPageLink(20, null, customerUsers2.get(19).getId().getId(), null));
    assertEquals(0, customerUsers3.size());
}
Also used : User(org.thingsboard.server.common.data.User) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) NULL_UUID(org.thingsboard.server.dao.model.ModelConstants.NULL_UUID) UUID(java.util.UUID) AbstractJpaDaoTest(org.thingsboard.server.dao.AbstractJpaDaoTest) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup)

Example 33 with TextPageLink

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

the class JpaWidgetsBundleDaoTest method testSearchTextNotFound.

@Test
@DatabaseSetup("classpath:dbunit/empty_dataset.xml")
@DatabaseTearDown(value = "classpath:dbunit/empty_dataset.xml", type = DatabaseOperation.DELETE_ALL)
public void testSearchTextNotFound() {
    UUID tenantId = UUIDs.timeBased();
    createWidgetBundles(5, tenantId, "ABC_");
    createSystemWidgetBundles(5, "SYS_");
    TextPageLink textPageLink = new TextPageLink(30, "TEXT_NOT_FOUND");
    List<WidgetsBundle> widgetsBundles4 = widgetsBundleDao.findAllTenantWidgetsBundlesByTenantId(tenantId, textPageLink);
    assertEquals(0, widgetsBundles4.size());
}
Also used : TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) NULL_UUID(org.thingsboard.server.dao.model.ModelConstants.NULL_UUID) UUID(java.util.UUID) WidgetsBundle(org.thingsboard.server.common.data.widget.WidgetsBundle) AbstractJpaDaoTest(org.thingsboard.server.dao.AbstractJpaDaoTest) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup) DatabaseTearDown(com.github.springtestdbunit.annotation.DatabaseTearDown)

Example 34 with TextPageLink

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

the class JpaWidgetsBundleDaoTest method testFindAllWidgetsBundlesByTenantId.

@Test
@DatabaseSetup(value = "classpath:dbunit/widgets_bundle.xml", type = DatabaseOperation.DELETE_ALL)
public void testFindAllWidgetsBundlesByTenantId() {
    UUID tenantId1 = UUIDs.timeBased();
    UUID tenantId2 = UUIDs.timeBased();
    // Create a bunch of widgetBundles
    for (int i = 0; i < 10; i++) {
        createWidgetBundles(5, tenantId1, "WB1_");
        createWidgetBundles(3, tenantId2, "WB2_");
        createSystemWidgetBundles(2, "WB_SYS_");
    }
    TextPageLink textPageLink1 = new TextPageLink(30, "WB");
    List<WidgetsBundle> widgetsBundles1 = widgetsBundleDao.findAllTenantWidgetsBundlesByTenantId(tenantId1, textPageLink1);
    assertEquals(30, widgetsBundles1.size());
    TextPageLink textPageLink2 = new TextPageLink(30, "WB", widgetsBundles1.get(29).getId().getId(), null);
    List<WidgetsBundle> widgetsBundles2 = widgetsBundleDao.findAllTenantWidgetsBundlesByTenantId(tenantId1, textPageLink2);
    assertEquals(30, widgetsBundles2.size());
    TextPageLink textPageLink3 = new TextPageLink(30, "WB", widgetsBundles2.get(29).getId().getId(), null);
    List<WidgetsBundle> widgetsBundles3 = widgetsBundleDao.findAllTenantWidgetsBundlesByTenantId(tenantId1, textPageLink3);
    assertEquals(10, widgetsBundles3.size());
    TextPageLink textPageLink4 = new TextPageLink(30, "WB", widgetsBundles3.get(9).getId().getId(), null);
    List<WidgetsBundle> widgetsBundles4 = widgetsBundleDao.findAllTenantWidgetsBundlesByTenantId(tenantId1, textPageLink4);
    assertEquals(0, widgetsBundles4.size());
}
Also used : TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) NULL_UUID(org.thingsboard.server.dao.model.ModelConstants.NULL_UUID) UUID(java.util.UUID) WidgetsBundle(org.thingsboard.server.common.data.widget.WidgetsBundle) AbstractJpaDaoTest(org.thingsboard.server.dao.AbstractJpaDaoTest) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup)

Example 35 with TextPageLink

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

the class BasePluginServiceTest method findSystemPlugins.

@Test
public void findSystemPlugins() throws Exception {
    // system tenant id
    TenantId systemTenant = new TenantId(ModelConstants.NULL_UUID);
    pluginService.savePlugin(generatePlugin(null, null));
    pluginService.savePlugin(generatePlugin(null, null));
    pluginService.savePlugin(generatePlugin(systemTenant, null));
    pluginService.savePlugin(generatePlugin(systemTenant, null));
    TextPageData<PluginMetaData> found = pluginService.findSystemPlugins(new TextPageLink(100));
    Assert.assertEquals(2, found.getData().size());
    Assert.assertFalse(found.hasNext());
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData) AbstractServiceTest(org.thingsboard.server.dao.service.AbstractServiceTest) 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