Search in sources :

Example 1 with TenantId

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);
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) Tenant(org.thingsboard.server.common.data.Tenant) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) Customer(org.thingsboard.server.common.data.Customer) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 2 with 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);
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) Tenant(org.thingsboard.server.common.data.Tenant) Customer(org.thingsboard.server.common.data.Customer) ArrayList(java.util.ArrayList) Dashboard(org.thingsboard.server.common.data.Dashboard) CustomerId(org.thingsboard.server.common.data.id.CustomerId) TimePageLink(org.thingsboard.server.common.data.page.TimePageLink) DashboardInfo(org.thingsboard.server.common.data.DashboardInfo) Test(org.junit.Test)

Example 3 with 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);
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) Tenant(org.thingsboard.server.common.data.Tenant) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) Customer(org.thingsboard.server.common.data.Customer) Device(org.thingsboard.server.common.data.Device) ArrayList(java.util.ArrayList) CustomerId(org.thingsboard.server.common.data.id.CustomerId) Test(org.junit.Test)

Example 4 with 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;
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData) IOException(java.io.IOException)

Example 5 with TenantId

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;
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) RuleMetaData(org.thingsboard.server.common.data.rule.RuleMetaData)

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