use of org.thingsboard.server.common.data.id.TenantId in project thingsboard by thingsboard.
the class BaseCustomerServiceTest method testFindCustomersByTenantId.
@Test
public void testFindCustomersByTenantId() {
Tenant tenant = new Tenant();
tenant.setTitle("Test tenant");
tenant = tenantService.saveTenant(tenant);
TenantId tenantId = tenant.getId();
List<Customer> customers = new ArrayList<>();
for (int i = 0; i < 135; i++) {
Customer customer = new Customer();
customer.setTenantId(tenantId);
customer.setTitle("Customer" + i);
customers.add(customerService.saveCustomer(customer));
}
List<Customer> loadedCustomers = new ArrayList<>();
TextPageLink pageLink = new TextPageLink(23);
TextPageData<Customer> pageData = null;
do {
pageData = customerService.findCustomersByTenantId(tenantId, pageLink);
loadedCustomers.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageData.getNextPageLink();
}
} while (pageData.hasNext());
Collections.sort(customers, idComparator);
Collections.sort(loadedCustomers, idComparator);
Assert.assertEquals(customers, loadedCustomers);
customerService.deleteCustomersByTenantId(tenantId);
pageLink = new TextPageLink(33);
pageData = customerService.findCustomersByTenantId(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 BaseDashboardServiceTest method testFindDashboardsByTenantIdAndCustomerId.
@Test
public void testFindDashboardsByTenantIdAndCustomerId() throws ExecutionException, InterruptedException {
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<DashboardInfo> dashboards = new ArrayList<>();
for (int i = 0; i < 223; i++) {
Dashboard dashboard = new Dashboard();
dashboard.setTenantId(tenantId);
dashboard.setTitle("Dashboard" + i);
dashboard = dashboardService.saveDashboard(dashboard);
dashboards.add(new DashboardInfo(dashboardService.assignDashboardToCustomer(dashboard.getId(), customerId)));
}
List<DashboardInfo> loadedDashboards = new ArrayList<>();
TimePageLink pageLink = new TimePageLink(23);
TimePageData<DashboardInfo> pageData = null;
do {
pageData = dashboardService.findDashboardsByTenantIdAndCustomerId(tenantId, customerId, pageLink).get();
loadedDashboards.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageData.getNextPageLink();
}
} while (pageData.hasNext());
Collections.sort(dashboards, idComparator);
Collections.sort(loadedDashboards, idComparator);
Assert.assertEquals(dashboards, loadedDashboards);
dashboardService.unassignCustomerDashboards(customerId);
pageLink = new TimePageLink(42);
pageData = dashboardService.findDashboardsByTenantIdAndCustomerId(tenantId, customerId, pageLink).get();
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 BaseDeviceServiceTest method testFindDevicesByTenantIdAndCustomerId.
@Test
public void testFindDevicesByTenantIdAndCustomerId() {
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<Device> devices = new ArrayList<>();
for (int i = 0; i < 278; i++) {
Device device = new Device();
device.setTenantId(tenantId);
device.setName("Device" + i);
device.setType("default");
device = deviceService.saveDevice(device);
devices.add(deviceService.assignDeviceToCustomer(device.getId(), customerId));
}
List<Device> loadedDevices = new ArrayList<>();
TextPageLink pageLink = new TextPageLink(23);
TextPageData<Device> pageData = null;
do {
pageData = deviceService.findDevicesByTenantIdAndCustomerId(tenantId, customerId, 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.unassignCustomerDevices(tenantId, customerId);
pageLink = new TextPageLink(33);
pageData = deviceService.findDevicesByTenantIdAndCustomerId(tenantId, customerId, 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 AbstractServiceTest method generatePlugin.
protected PluginMetaData generatePlugin(TenantId tenantId, String token, String clazz, String actions, String configurationDescriptorResource, String dataResource) throws IOException {
if (tenantId == null) {
tenantId = new TenantId(UUIDs.timeBased());
}
if (token == null) {
token = UUID.randomUUID().toString();
}
getOrCreateDescriptor(ComponentScope.TENANT, ComponentType.PLUGIN, clazz, configurationDescriptorResource, actions);
PluginMetaData pluginMetaData = new PluginMetaData();
pluginMetaData.setName("Testing");
pluginMetaData.setClazz(clazz);
pluginMetaData.setTenantId(tenantId);
pluginMetaData.setApiToken(token);
pluginMetaData.setAdditionalInfo(mapper.readTree("{\"test\":\"test\"}"));
try {
pluginMetaData.setConfiguration(readFromResource(dataResource));
} catch (IOException e) {
throw new RuntimeException(e);
}
return pluginMetaData;
}
use of org.thingsboard.server.common.data.id.TenantId in project thingsboard by thingsboard.
the class AbstractServiceTest method generateRule.
protected RuleMetaData generateRule(TenantId tenantId, Integer weight, String pluginToken) throws IOException {
if (tenantId == null) {
tenantId = new TenantId(UUIDs.timeBased());
}
if (weight == null) {
weight = ThreadLocalRandom.current().nextInt();
}
RuleMetaData ruleMetaData = new RuleMetaData();
ruleMetaData.setName("Testing");
ruleMetaData.setTenantId(tenantId);
ruleMetaData.setWeight(weight);
ruleMetaData.setPluginToken(pluginToken);
ruleMetaData.setAction(createNode(ComponentScope.TENANT, ComponentType.ACTION, "org.thingsboard.component.ActionTest", "TestJsonDescriptor.json", "TestJsonData.json"));
ruleMetaData.setProcessor(createNode(ComponentScope.TENANT, ComponentType.PROCESSOR, "org.thingsboard.component.ProcessorTest", "TestJsonDescriptor.json", "TestJsonData.json"));
ruleMetaData.setFilters(mapper.createArrayNode().add(createNode(ComponentScope.TENANT, ComponentType.FILTER, "org.thingsboard.component.FilterTest", "TestJsonDescriptor.json", "TestJsonData.json")));
ruleMetaData.setAdditionalInfo(mapper.readTree("{}"));
return ruleMetaData;
}
Aggregations