use of org.thingsboard.server.common.data.id.TenantId in project thingsboard by thingsboard.
the class BaseDeviceServiceTest method testFindDevicesByTenantId.
@Test
public void testFindDevicesByTenantId() {
Tenant tenant = new Tenant();
tenant.setTitle("Test tenant");
tenant = tenantService.saveTenant(tenant);
TenantId tenantId = tenant.getId();
List<Device> devices = new ArrayList<>();
for (int i = 0; i < 178; i++) {
Device device = new Device();
device.setTenantId(tenantId);
device.setName("Device" + i);
device.setType("default");
devices.add(deviceService.saveDevice(device));
}
List<Device> loadedDevices = new ArrayList<>();
TextPageLink pageLink = new TextPageLink(23);
TextPageData<Device> pageData = null;
do {
pageData = deviceService.findDevicesByTenantId(tenantId, pageLink);
loadedDevices.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageData.getNextPageLink();
}
} while (pageData.hasNext());
Collections.sort(devices, idComparator);
Collections.sort(loadedDevices, idComparator);
Assert.assertEquals(devices, loadedDevices);
deviceService.deleteDevicesByTenantId(tenantId);
pageLink = new TextPageLink(33);
pageData = deviceService.findDevicesByTenantId(tenantId, pageLink);
Assert.assertFalse(pageData.hasNext());
Assert.assertTrue(pageData.getData().isEmpty());
tenantService.deleteTenant(tenantId);
}
use of org.thingsboard.server.common.data.id.TenantId in project thingsboard by thingsboard.
the class BaseUserServiceTest method testFindCustomerUsersByEmail.
@Test
public void testFindCustomerUsersByEmail() {
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();
String email1 = "testEmail1";
List<User> customerUsersEmail1 = new ArrayList<>();
for (int i = 0; i < 124; i++) {
User user = new User();
user.setAuthority(Authority.CUSTOMER_USER);
user.setTenantId(tenantId);
user.setCustomerId(customerId);
String suffix = RandomStringUtils.randomAlphanumeric((int) (5 + Math.random() * 10));
String email = email1 + suffix + "@thingsboard.org";
email = i % 2 == 0 ? email.toLowerCase() : email.toUpperCase();
user.setEmail(email);
customerUsersEmail1.add(userService.saveUser(user));
}
String email2 = "testEmail2";
List<User> customerUsersEmail2 = new ArrayList<>();
for (int i = 0; i < 132; i++) {
User user = new User();
user.setAuthority(Authority.CUSTOMER_USER);
user.setTenantId(tenantId);
user.setCustomerId(customerId);
String suffix = RandomStringUtils.randomAlphanumeric((int) (5 + Math.random() * 10));
String email = email2 + suffix + "@thingsboard.org";
email = i % 2 == 0 ? email.toLowerCase() : email.toUpperCase();
user.setEmail(email);
customerUsersEmail2.add(userService.saveUser(user));
}
List<User> loadedCustomerUsersEmail1 = new ArrayList<>();
TextPageLink pageLink = new TextPageLink(33, email1);
TextPageData<User> pageData = null;
do {
pageData = userService.findCustomerUsers(tenantId, customerId, pageLink);
loadedCustomerUsersEmail1.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageData.getNextPageLink();
}
} while (pageData.hasNext());
Collections.sort(customerUsersEmail1, idComparator);
Collections.sort(loadedCustomerUsersEmail1, idComparator);
Assert.assertEquals(customerUsersEmail1, loadedCustomerUsersEmail1);
List<User> loadedCustomerUsersEmail2 = new ArrayList<>();
pageLink = new TextPageLink(16, email2);
do {
pageData = userService.findCustomerUsers(tenantId, customerId, pageLink);
loadedCustomerUsersEmail2.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageData.getNextPageLink();
}
} while (pageData.hasNext());
Collections.sort(customerUsersEmail2, idComparator);
Collections.sort(loadedCustomerUsersEmail2, idComparator);
Assert.assertEquals(customerUsersEmail2, loadedCustomerUsersEmail2);
for (User user : loadedCustomerUsersEmail1) {
userService.deleteUser(user.getId());
}
pageLink = new TextPageLink(4, email1);
pageData = userService.findCustomerUsers(tenantId, customerId, pageLink);
Assert.assertFalse(pageData.hasNext());
Assert.assertEquals(0, pageData.getData().size());
for (User user : loadedCustomerUsersEmail2) {
userService.deleteUser(user.getId());
}
pageLink = new TextPageLink(4, email2);
pageData = userService.findCustomerUsers(tenantId, customerId, pageLink);
Assert.assertFalse(pageData.hasNext());
Assert.assertEquals(0, pageData.getData().size());
tenantService.deleteTenant(tenantId);
}
use of org.thingsboard.server.common.data.id.TenantId in project thingsboard by thingsboard.
the class BaseUserServiceTest method testFindTenantAdmins.
@Test
public void testFindTenantAdmins() {
User tenantAdminUser = userService.findUserByEmail("tenant@thingsboard.org");
TextPageData<User> pageData = userService.findTenantAdmins(tenantAdminUser.getTenantId(), new TextPageLink(10));
Assert.assertFalse(pageData.hasNext());
List<User> users = pageData.getData();
Assert.assertEquals(1, users.size());
Assert.assertEquals(tenantAdminUser, users.get(0));
Tenant tenant = new Tenant();
tenant.setTitle("Test tenant");
tenant = tenantService.saveTenant(tenant);
TenantId tenantId = tenant.getId();
List<User> tenantAdmins = new ArrayList<>();
for (int i = 0; i < 124; i++) {
User user = new User();
user.setAuthority(Authority.TENANT_ADMIN);
user.setTenantId(tenantId);
user.setEmail("testTenant" + i + "@thingsboard.org");
tenantAdmins.add(userService.saveUser(user));
}
List<User> loadedTenantAdmins = new ArrayList<>();
TextPageLink pageLink = new TextPageLink(33);
do {
pageData = userService.findTenantAdmins(tenantId, pageLink);
loadedTenantAdmins.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageData.getNextPageLink();
}
} while (pageData.hasNext());
Collections.sort(tenantAdmins, idComparator);
Collections.sort(loadedTenantAdmins, idComparator);
Assert.assertEquals(tenantAdmins, loadedTenantAdmins);
tenantService.deleteTenant(tenantId);
pageLink = new TextPageLink(33);
pageData = userService.findTenantAdmins(tenantId, pageLink);
Assert.assertFalse(pageData.hasNext());
Assert.assertTrue(pageData.getData().isEmpty());
}
use of org.thingsboard.server.common.data.id.TenantId in project thingsboard by thingsboard.
the class BaseUserServiceTest method testFindTenantAdminsByEmail.
@Test
public void testFindTenantAdminsByEmail() {
Tenant tenant = new Tenant();
tenant.setTitle("Test tenant");
tenant = tenantService.saveTenant(tenant);
TenantId tenantId = tenant.getId();
String email1 = "testEmail1";
List<User> tenantAdminsEmail1 = new ArrayList<>();
for (int i = 0; i < 94; i++) {
User user = new User();
user.setAuthority(Authority.TENANT_ADMIN);
user.setTenantId(tenantId);
String suffix = RandomStringUtils.randomAlphanumeric((int) (5 + Math.random() * 10));
String email = email1 + suffix + "@thingsboard.org";
email = i % 2 == 0 ? email.toLowerCase() : email.toUpperCase();
user.setEmail(email);
tenantAdminsEmail1.add(userService.saveUser(user));
}
String email2 = "testEmail2";
List<User> tenantAdminsEmail2 = new ArrayList<>();
for (int i = 0; i < 132; i++) {
User user = new User();
user.setAuthority(Authority.TENANT_ADMIN);
user.setTenantId(tenantId);
String suffix = RandomStringUtils.randomAlphanumeric((int) (5 + Math.random() * 10));
String email = email2 + suffix + "@thingsboard.org";
email = i % 2 == 0 ? email.toLowerCase() : email.toUpperCase();
user.setEmail(email);
tenantAdminsEmail2.add(userService.saveUser(user));
}
List<User> loadedTenantAdminsEmail1 = new ArrayList<>();
TextPageLink pageLink = new TextPageLink(33, email1);
TextPageData<User> pageData = null;
do {
pageData = userService.findTenantAdmins(tenantId, pageLink);
loadedTenantAdminsEmail1.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageData.getNextPageLink();
}
} while (pageData.hasNext());
Collections.sort(tenantAdminsEmail1, idComparator);
Collections.sort(loadedTenantAdminsEmail1, idComparator);
Assert.assertEquals(tenantAdminsEmail1, loadedTenantAdminsEmail1);
List<User> loadedTenantAdminsEmail2 = new ArrayList<>();
pageLink = new TextPageLink(16, email2);
do {
pageData = userService.findTenantAdmins(tenantId, pageLink);
loadedTenantAdminsEmail2.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageData.getNextPageLink();
}
} while (pageData.hasNext());
Collections.sort(tenantAdminsEmail2, idComparator);
Collections.sort(loadedTenantAdminsEmail2, idComparator);
Assert.assertEquals(tenantAdminsEmail2, loadedTenantAdminsEmail2);
for (User user : loadedTenantAdminsEmail1) {
userService.deleteUser(user.getId());
}
pageLink = new TextPageLink(4, email1);
pageData = userService.findTenantAdmins(tenantId, pageLink);
Assert.assertFalse(pageData.hasNext());
Assert.assertEquals(0, pageData.getData().size());
for (User user : loadedTenantAdminsEmail2) {
userService.deleteUser(user.getId());
}
pageLink = new TextPageLink(4, email2);
pageData = userService.findTenantAdmins(tenantId, pageLink);
Assert.assertFalse(pageData.hasNext());
Assert.assertEquals(0, pageData.getData().size());
tenantService.deleteTenant(tenantId);
}
use of org.thingsboard.server.common.data.id.TenantId in project thingsboard by thingsboard.
the class BaseWidgetTypeServiceTest method testSaveWidgetTypeWithInvalidTenant.
@Test(expected = DataValidationException.class)
public void testSaveWidgetTypeWithInvalidTenant() throws IOException {
WidgetsBundle widgetsBundle = new WidgetsBundle();
widgetsBundle.setTenantId(tenantId);
widgetsBundle.setTitle("Widgets bundle");
WidgetsBundle savedWidgetsBundle = widgetsBundleService.saveWidgetsBundle(widgetsBundle);
WidgetType widgetType = new WidgetType();
widgetType.setTenantId(new TenantId(UUIDs.timeBased()));
widgetType.setBundleAlias(savedWidgetsBundle.getAlias());
widgetType.setName("Widget Type");
widgetType.setDescriptor(new ObjectMapper().readValue("{ \"someKey\": \"someValue\" }", JsonNode.class));
try {
widgetTypeService.saveWidgetType(widgetType);
} finally {
widgetsBundleService.deleteWidgetsBundle(savedWidgetsBundle.getId());
}
}
Aggregations