Search in sources :

Example 71 with TextPageLink

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

the class JpaBaseRuleDaoTest method testFindAllTenantRulesByTenantId.

@Test
@DatabaseSetup("classpath:dbunit/empty_dataset.xml")
public void testFindAllTenantRulesByTenantId() {
    UUID tenantId1 = UUIDs.timeBased();
    UUID tenantId2 = UUIDs.timeBased();
    createTenantsAndSystemRules(tenantId1, tenantId2, "name_", "token");
    List<RuleMetaData> rules1 = ruleDao.findAllTenantRulesByTenantId(tenantId1, new TextPageLink(40, "name_"));
    assertEquals(40, rules1.size());
    List<RuleMetaData> rules2 = ruleDao.findAllTenantRulesByTenantId(tenantId1, new TextPageLink(40, "name_", rules1.get(19).getId().getId(), null));
    assertEquals(20, rules2.size());
    List<RuleMetaData> rules3 = ruleDao.findAllTenantRulesByTenantId(tenantId1, new TextPageLink(40, "name_", rules2.get(19).getId().getId(), null));
    assertEquals(0, rules3.size());
}
Also used : 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 72 with TextPageLink

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

the class JpaUserDaoTest method testFindTenantAdmins.

@Test
@DatabaseSetup("classpath:dbunit/empty_dataset.xml")
public void testFindTenantAdmins() {
    UUID tenantId = UUIDs.timeBased();
    UUID customerId = UUIDs.timeBased();
    create30Adminsand60Users(tenantId, customerId);
    List<User> tenantAdmins1 = userDao.findTenantAdmins(tenantId, new TextPageLink(20));
    assertEquals(20, tenantAdmins1.size());
    List<User> tenantAdmins2 = userDao.findTenantAdmins(tenantId, new TextPageLink(20, null, tenantAdmins1.get(19).getId().getId(), null));
    assertEquals(10, tenantAdmins2.size());
    List<User> tenantAdmins3 = userDao.findTenantAdmins(tenantId, new TextPageLink(20, null, tenantAdmins2.get(9).getId().getId(), null));
    assertEquals(0, tenantAdmins3.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 73 with TextPageLink

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

the class JpaWidgetsBundleDaoTest method testFindWidgetsBundlesByTenantId.

@Test
@DatabaseSetup(value = "classpath:dbunit/widgets_bundle.xml", type = DatabaseOperation.DELETE_ALL)
public void testFindWidgetsBundlesByTenantId() {
    UUID tenantId1 = UUIDs.timeBased();
    UUID tenantId2 = UUIDs.timeBased();
    // Create a bunch of widgetBundles
    for (int i = 0; i < 10; i++) {
        createWidgetBundles(3, tenantId1, "WB1_");
        createWidgetBundles(5, tenantId2, "WB2_");
        createSystemWidgetBundles(10, "WB_SYS_");
    }
    assertEquals(180, widgetsBundleDao.find().size());
    TextPageLink textPageLink1 = new TextPageLink(40, "WB");
    List<WidgetsBundle> widgetsBundles1 = widgetsBundleDao.findTenantWidgetsBundlesByTenantId(tenantId1, textPageLink1);
    assertEquals(30, widgetsBundles1.size());
    TextPageLink textPageLink2 = new TextPageLink(40, "WB");
    List<WidgetsBundle> widgetsBundles2 = widgetsBundleDao.findTenantWidgetsBundlesByTenantId(tenantId2, textPageLink2);
    assertEquals(40, widgetsBundles2.size());
    TextPageLink textPageLink3 = new TextPageLink(40, "WB", widgetsBundles2.get(39).getId().getId(), null);
    List<WidgetsBundle> widgetsBundles3 = widgetsBundleDao.findTenantWidgetsBundlesByTenantId(tenantId2, textPageLink3);
    assertEquals(10, widgetsBundles3.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 74 with TextPageLink

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

the class JpaWidgetsBundleDaoTest method testFindSystemWidgetsBundles.

@Test
@DatabaseSetup(value = "classpath:dbunit/widgets_bundle.xml", type = DatabaseOperation.DELETE_ALL)
public void testFindSystemWidgetsBundles() {
    createSystemWidgetBundles(30, "WB_");
    assertEquals(30, widgetsBundleDao.find().size());
    // Get first page
    TextPageLink textPageLink1 = new TextPageLink(10, "WB");
    List<WidgetsBundle> widgetsBundles1 = widgetsBundleDao.findSystemWidgetsBundles(textPageLink1);
    assertEquals(10, widgetsBundles1.size());
    // Get next page
    TextPageLink textPageLink2 = new TextPageLink(10, "WB", widgetsBundles1.get(9).getId().getId(), null);
    List<WidgetsBundle> widgetsBundles2 = widgetsBundleDao.findSystemWidgetsBundles(textPageLink2);
    assertEquals(10, widgetsBundles2.size());
}
Also used : TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) 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 75 with TextPageLink

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

the class BasePluginServiceTest method findTenantPlugins.

@Test
public void findTenantPlugins() throws Exception {
    TenantId tenantId = new TenantId(UUIDs.timeBased());
    pluginService.savePlugin(generatePlugin(null, null));
    pluginService.savePlugin(generatePlugin(null, null));
    pluginService.savePlugin(generatePlugin(tenantId, null));
    pluginService.savePlugin(generatePlugin(tenantId, null));
    pluginService.savePlugin(generatePlugin(tenantId, null));
    TextPageData<PluginMetaData> found = pluginService.findTenantPlugins(tenantId, new TextPageLink(100));
    Assert.assertEquals(3, found.getData().size());
}
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