use of org.thingsboard.server.common.data.id.TenantId in project thingsboard by thingsboard.
the class JpaUserDaoTest method saveUser.
private void saveUser(UUID tenantId, UUID customerId) {
User user = new User();
UUID id = UUIDs.timeBased();
user.setId(new UserId(id));
user.setTenantId(new TenantId(tenantId));
user.setCustomerId(new CustomerId(customerId));
if (customerId == NULL_UUID) {
user.setAuthority(Authority.TENANT_ADMIN);
} else {
user.setAuthority(Authority.CUSTOMER_USER);
}
String idString = id.toString();
String email = idString.substring(0, idString.indexOf('-')) + "@thingsboard.org";
user.setEmail(email);
userDao.save(user);
}
use of org.thingsboard.server.common.data.id.TenantId in project thingsboard by thingsboard.
the class BasePluginServiceTest method findPluginByTenantIdAndApiToken.
@Test
public void findPluginByTenantIdAndApiToken() throws Exception {
String token = UUID.randomUUID().toString();
TenantId tenantId = new TenantId(UUIDs.timeBased());
pluginService.savePlugin(generatePlugin(null, null));
pluginService.savePlugin(generatePlugin(tenantId, null));
pluginService.savePlugin(generatePlugin(tenantId, null));
pluginService.savePlugin(generatePlugin(tenantId, null));
PluginMetaData expected = pluginService.savePlugin(generatePlugin(tenantId, token));
Assert.assertNotNull(expected.getId());
PluginMetaData found = pluginService.findPluginByApiToken(token);
Assert.assertEquals(expected, found);
}
use of org.thingsboard.server.common.data.id.TenantId 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());
}
use of org.thingsboard.server.common.data.id.TenantId in project thingsboard by thingsboard.
the class BaseRuleServiceTest method findTenantRules.
@Test
public void findTenantRules() throws Exception {
TenantId tenantIdA = new TenantId(UUIDs.timeBased());
TenantId tenantIdB = new TenantId(UUIDs.timeBased());
PluginMetaData pluginA = generatePlugin(tenantIdA, "testPluginToken" + ThreadLocalRandom.current().nextInt());
PluginMetaData pluginB = generatePlugin(tenantIdB, "testPluginToken" + ThreadLocalRandom.current().nextInt());
pluginService.savePlugin(pluginA);
pluginService.savePlugin(pluginB);
ruleService.saveRule(generateRule(tenantIdA, null, pluginA.getApiToken()));
ruleService.saveRule(generateRule(tenantIdA, null, pluginA.getApiToken()));
ruleService.saveRule(generateRule(tenantIdA, null, pluginA.getApiToken()));
ruleService.saveRule(generateRule(tenantIdB, null, pluginB.getApiToken()));
ruleService.saveRule(generateRule(tenantIdB, null, pluginB.getApiToken()));
TextPageData<RuleMetaData> foundA = ruleService.findTenantRules(tenantIdA, new TextPageLink(100));
Assert.assertEquals(3, foundA.getData().size());
TextPageData<RuleMetaData> foundB = ruleService.findTenantRules(tenantIdB, new TextPageLink(100));
Assert.assertEquals(2, foundB.getData().size());
}
use of org.thingsboard.server.common.data.id.TenantId in project thingsboard by thingsboard.
the class BaseRuleServiceTest method deleteRulesByTenantId.
@Test
public void deleteRulesByTenantId() throws Exception {
TenantId tenantIdA = new TenantId(UUIDs.timeBased());
TenantId tenantIdB = new TenantId(UUIDs.timeBased());
PluginMetaData pluginA = generatePlugin(tenantIdA, "testPluginToken" + ThreadLocalRandom.current().nextInt());
PluginMetaData pluginB = generatePlugin(tenantIdB, "testPluginToken" + ThreadLocalRandom.current().nextInt());
pluginService.savePlugin(pluginA);
pluginService.savePlugin(pluginB);
ruleService.saveRule(generateRule(tenantIdA, null, pluginA.getApiToken()));
ruleService.saveRule(generateRule(tenantIdA, null, pluginA.getApiToken()));
ruleService.saveRule(generateRule(tenantIdA, null, pluginA.getApiToken()));
ruleService.saveRule(generateRule(tenantIdB, null, pluginB.getApiToken()));
ruleService.saveRule(generateRule(tenantIdB, null, pluginB.getApiToken()));
TextPageData<RuleMetaData> foundA = ruleService.findTenantRules(tenantIdA, new TextPageLink(100));
Assert.assertEquals(3, foundA.getData().size());
TextPageData<RuleMetaData> foundB = ruleService.findTenantRules(tenantIdB, new TextPageLink(100));
Assert.assertEquals(2, foundB.getData().size());
ruleService.deleteRulesByTenantId(tenantIdA);
foundA = ruleService.findTenantRules(tenantIdA, new TextPageLink(100));
Assert.assertEquals(0, foundA.getData().size());
foundB = ruleService.findTenantRules(tenantIdB, new TextPageLink(100));
Assert.assertEquals(2, foundB.getData().size());
}
Aggregations