Search in sources :

Example 21 with TenantId

use of org.thingsboard.server.common.data.id.TenantId in project thingsboard by thingsboard.

the class JpaBasePluginDaoTest method createPlugin.

private void createPlugin(UUID tenantId, String namePrefix, int i) {
    PluginMetaData plugin = new PluginMetaData();
    plugin.setId(new PluginId(UUIDs.timeBased()));
    plugin.setTenantId(new TenantId(tenantId));
    plugin.setName(namePrefix + i);
    pluginDao.save(plugin);
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData) PluginId(org.thingsboard.server.common.data.id.PluginId)

Example 22 with TenantId

use of org.thingsboard.server.common.data.id.TenantId in project thingsboard by thingsboard.

the class JpaBaseRuleDaoTest method testFindByTenantIdAndPageLink.

@Test
@DatabaseSetup("classpath:dbunit/empty_dataset.xml")
public void testFindByTenantIdAndPageLink() {
    UUID tenantId1 = UUIDs.timeBased();
    UUID tenantId2 = UUIDs.timeBased();
    createRulesTwoTenants(tenantId1, tenantId2, "name_", "token");
    List<RuleMetaData> rules1 = ruleDao.findByTenantIdAndPageLink(new TenantId(tenantId1), new TextPageLink(20, "name_"));
    assertEquals(20, rules1.size());
    List<RuleMetaData> rules2 = ruleDao.findByTenantIdAndPageLink(new TenantId(tenantId1), new TextPageLink(20, "name_", rules1.get(19).getId().getId(), null));
    assertEquals(10, rules2.size());
    List<RuleMetaData> rules3 = ruleDao.findByTenantIdAndPageLink(new TenantId(tenantId1), new TextPageLink(20, "name_", rules2.get(9).getId().getId(), null));
    assertEquals(0, rules3.size());
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) 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 23 with TenantId

use of org.thingsboard.server.common.data.id.TenantId in project thingsboard by thingsboard.

the class JpaBaseRuleDaoTest method createRule.

private void createRule(UUID tenantId, String namePrefix, String pluginToken, int i) {
    RuleMetaData ruleMetaData = new RuleMetaData();
    ruleMetaData.setId(new RuleId(UUIDs.timeBased()));
    ruleMetaData.setTenantId(new TenantId(tenantId));
    ruleMetaData.setName(namePrefix + i);
    ruleMetaData.setPluginToken(pluginToken);
    ruleDao.save(ruleMetaData);
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) RuleId(org.thingsboard.server.common.data.id.RuleId) RuleMetaData(org.thingsboard.server.common.data.rule.RuleMetaData)

Example 24 with TenantId

use of org.thingsboard.server.common.data.id.TenantId in project thingsboard by thingsboard.

the class JpaTenantDaoTest method createTenant.

private void createTenant(String region, String title, int index) {
    Tenant tenant = new Tenant();
    tenant.setId(new TenantId(UUIDs.timeBased()));
    tenant.setRegion(region);
    tenant.setTitle(title + "_" + index);
    tenantDao.save(tenant);
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) Tenant(org.thingsboard.server.common.data.Tenant)

Example 25 with TenantId

use of org.thingsboard.server.common.data.id.TenantId in project thingsboard by thingsboard.

the class BaseUserServiceTest method testFindCustomerUsers.

@Test
public void testFindCustomerUsers() {
    User customerUser = userService.findUserByEmail("customer@thingsboard.org");
    TextPageData<User> pageData = userService.findCustomerUsers(customerUser.getTenantId(), customerUser.getCustomerId(), new TextPageLink(10));
    Assert.assertFalse(pageData.hasNext());
    List<User> users = pageData.getData();
    Assert.assertEquals(1, users.size());
    Assert.assertEquals(customerUser, users.get(0));
    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();
    List<User> customerUsers = new ArrayList<>();
    for (int i = 0; i < 156; i++) {
        User user = new User();
        user.setAuthority(Authority.CUSTOMER_USER);
        user.setTenantId(tenantId);
        user.setCustomerId(customerId);
        user.setEmail("testCustomer" + i + "@thingsboard.org");
        customerUsers.add(userService.saveUser(user));
    }
    List<User> loadedCustomerUsers = new ArrayList<>();
    TextPageLink pageLink = new TextPageLink(33);
    do {
        pageData = userService.findCustomerUsers(tenantId, customerId, pageLink);
        loadedCustomerUsers.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(customerUsers, idComparator);
    Collections.sort(loadedCustomerUsers, idComparator);
    Assert.assertEquals(customerUsers, loadedCustomerUsers);
    tenantService.deleteTenant(tenantId);
    pageData = userService.findCustomerUsers(tenantId, customerId, 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) Customer(org.thingsboard.server.common.data.Customer) ArrayList(java.util.ArrayList) CustomerId(org.thingsboard.server.common.data.id.CustomerId) Test(org.junit.Test)

Aggregations

TenantId (org.thingsboard.server.common.data.id.TenantId)119 Test (org.junit.Test)44 TextPageLink (org.thingsboard.server.common.data.page.TextPageLink)38 CustomerId (org.thingsboard.server.common.data.id.CustomerId)30 ArrayList (java.util.ArrayList)26 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)24 Tenant (org.thingsboard.server.common.data.Tenant)23 ThingsboardException (org.thingsboard.server.exception.ThingsboardException)23 PluginMetaData (org.thingsboard.server.common.data.plugin.PluginMetaData)16 Customer (org.thingsboard.server.common.data.Customer)14 User (org.thingsboard.server.common.data.User)14 WidgetsBundle (org.thingsboard.server.common.data.widget.WidgetsBundle)13 DeviceId (org.thingsboard.server.common.data.id.DeviceId)10 RuleMetaData (org.thingsboard.server.common.data.rule.RuleMetaData)10 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)10 AbstractServiceTest (org.thingsboard.server.dao.service.AbstractServiceTest)10 UserId (org.thingsboard.server.common.data.id.UserId)8 TimePageLink (org.thingsboard.server.common.data.page.TimePageLink)8 IOException (java.io.IOException)7 PluginId (org.thingsboard.server.common.data.id.PluginId)7