Search in sources :

Example 96 with TenantId

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

the class BaseWidgetsBundleServiceTest method testUpdateWidgetsBundleTenant.

@Test(expected = DataValidationException.class)
public void testUpdateWidgetsBundleTenant() {
    WidgetsBundle widgetsBundle = new WidgetsBundle();
    widgetsBundle.setTitle("My widgets bundle");
    widgetsBundle.setTenantId(tenantId);
    WidgetsBundle savedWidgetsBundle = widgetsBundleService.saveWidgetsBundle(widgetsBundle);
    savedWidgetsBundle.setTenantId(new TenantId(ModelConstants.NULL_UUID));
    try {
        widgetsBundleService.saveWidgetsBundle(savedWidgetsBundle);
    } finally {
        widgetsBundleService.deleteWidgetsBundle(savedWidgetsBundle.getId());
    }
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) WidgetsBundle(org.thingsboard.server.common.data.widget.WidgetsBundle) Test(org.junit.Test)

Example 97 with TenantId

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

the class BaseWidgetsBundleServiceTest method testFindAllWidgetsBundlesByTenantIdAndPageLink.

@Test
public void testFindAllWidgetsBundlesByTenantIdAndPageLink() {
    List<WidgetsBundle> systemWidgetsBundles = widgetsBundleService.findSystemWidgetsBundles();
    Tenant tenant = new Tenant();
    tenant.setTitle("Test tenant");
    tenant = tenantService.saveTenant(tenant);
    TenantId tenantId = tenant.getId();
    TenantId systemTenantId = new TenantId(ModelConstants.NULL_UUID);
    List<WidgetsBundle> createdWidgetsBundles = new ArrayList<>();
    List<WidgetsBundle> createdSystemWidgetsBundles = new ArrayList<>();
    for (int i = 0; i < 177; i++) {
        WidgetsBundle widgetsBundle = new WidgetsBundle();
        widgetsBundle.setTenantId(i % 2 == 0 ? tenantId : systemTenantId);
        widgetsBundle.setTitle((i % 2 == 0 ? "Widgets bundle " : "System widget bundle ") + i);
        WidgetsBundle savedWidgetsBundle = widgetsBundleService.saveWidgetsBundle(widgetsBundle);
        createdWidgetsBundles.add(savedWidgetsBundle);
        if (i % 2 == 1) {
            createdSystemWidgetsBundles.add(savedWidgetsBundle);
        }
    }
    List<WidgetsBundle> widgetsBundles = new ArrayList<>(createdWidgetsBundles);
    widgetsBundles.addAll(systemWidgetsBundles);
    List<WidgetsBundle> loadedWidgetsBundles = new ArrayList<>();
    TextPageLink pageLink = new TextPageLink(17);
    TextPageData<WidgetsBundle> pageData = null;
    do {
        pageData = widgetsBundleService.findAllTenantWidgetsBundlesByTenantIdAndPageLink(tenantId, pageLink);
        loadedWidgetsBundles.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(widgetsBundles, idComparator);
    Collections.sort(loadedWidgetsBundles, idComparator);
    Assert.assertEquals(widgetsBundles, loadedWidgetsBundles);
    widgetsBundleService.deleteWidgetsBundlesByTenantId(tenantId);
    loadedWidgetsBundles.clear();
    pageLink = new TextPageLink(14);
    do {
        pageData = widgetsBundleService.findAllTenantWidgetsBundlesByTenantIdAndPageLink(tenantId, pageLink);
        loadedWidgetsBundles.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    List<WidgetsBundle> allSystemWidgetsBundles = new ArrayList<>(systemWidgetsBundles);
    allSystemWidgetsBundles.addAll(createdSystemWidgetsBundles);
    Collections.sort(allSystemWidgetsBundles, idComparator);
    Collections.sort(loadedWidgetsBundles, idComparator);
    Assert.assertEquals(allSystemWidgetsBundles, loadedWidgetsBundles);
    for (WidgetsBundle widgetsBundle : createdSystemWidgetsBundles) {
        widgetsBundleService.deleteWidgetsBundle(widgetsBundle.getId());
    }
    loadedWidgetsBundles.clear();
    pageLink = new TextPageLink(18);
    do {
        pageData = widgetsBundleService.findAllTenantWidgetsBundlesByTenantIdAndPageLink(tenantId, pageLink);
        loadedWidgetsBundles.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(systemWidgetsBundles, idComparator);
    Collections.sort(loadedWidgetsBundles, idComparator);
    Assert.assertEquals(systemWidgetsBundles, loadedWidgetsBundles);
    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) ArrayList(java.util.ArrayList) WidgetsBundle(org.thingsboard.server.common.data.widget.WidgetsBundle) Test(org.junit.Test)

Example 98 with TenantId

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

the class BaseEventServiceTest method findEventsByTypeAndTimeAscOrder.

@Test
public void findEventsByTypeAndTimeAscOrder() throws Exception {
    long timeBeforeStartTime = LocalDateTime.of(2016, Month.NOVEMBER, 1, 11, 30).toEpochSecond(ZoneOffset.UTC);
    long startTime = LocalDateTime.of(2016, Month.NOVEMBER, 1, 12, 0).toEpochSecond(ZoneOffset.UTC);
    long eventTime = LocalDateTime.of(2016, Month.NOVEMBER, 1, 12, 30).toEpochSecond(ZoneOffset.UTC);
    long endTime = LocalDateTime.of(2016, Month.NOVEMBER, 1, 13, 0).toEpochSecond(ZoneOffset.UTC);
    long timeAfterEndTime = LocalDateTime.of(2016, Month.NOVEMBER, 1, 13, 30).toEpochSecond(ZoneOffset.UTC);
    RuleId ruleId = new RuleId(UUIDs.timeBased());
    TenantId tenantId = new TenantId(UUIDs.timeBased());
    saveEventWithProvidedTime(timeBeforeStartTime, ruleId, tenantId);
    Event savedEvent = saveEventWithProvidedTime(eventTime, ruleId, tenantId);
    Event savedEvent2 = saveEventWithProvidedTime(eventTime + 1, ruleId, tenantId);
    Event savedEvent3 = saveEventWithProvidedTime(eventTime + 2, ruleId, tenantId);
    saveEventWithProvidedTime(timeAfterEndTime, ruleId, tenantId);
    TimePageData<Event> events = eventService.findEvents(tenantId, ruleId, DataConstants.STATS, new TimePageLink(2, startTime, endTime, true));
    Assert.assertNotNull(events.getData());
    Assert.assertTrue(events.getData().size() == 2);
    Assert.assertTrue(events.getData().get(0).getUuidId().equals(savedEvent.getUuidId()));
    Assert.assertTrue(events.getData().get(1).getUuidId().equals(savedEvent2.getUuidId()));
    Assert.assertTrue(events.hasNext());
    Assert.assertNotNull(events.getNextPageLink());
    events = eventService.findEvents(tenantId, ruleId, DataConstants.STATS, events.getNextPageLink());
    Assert.assertNotNull(events.getData());
    Assert.assertTrue(events.getData().size() == 1);
    Assert.assertTrue(events.getData().get(0).getUuidId().equals(savedEvent3.getUuidId()));
    Assert.assertFalse(events.hasNext());
    Assert.assertNull(events.getNextPageLink());
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) RuleId(org.thingsboard.server.common.data.id.RuleId) Event(org.thingsboard.server.common.data.Event) TimePageLink(org.thingsboard.server.common.data.page.TimePageLink) Test(org.junit.Test) AbstractServiceTest(org.thingsboard.server.dao.service.AbstractServiceTest)

Example 99 with TenantId

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

the class BaseAssetServiceTest method testFindAssetsByTenantId.

@Test
public void testFindAssetsByTenantId() {
    Tenant tenant = new Tenant();
    tenant.setTitle("Test tenant");
    tenant = tenantService.saveTenant(tenant);
    TenantId tenantId = tenant.getId();
    List<Asset> assets = new ArrayList<>();
    for (int i = 0; i < 178; i++) {
        Asset asset = new Asset();
        asset.setTenantId(tenantId);
        asset.setName("Asset" + i);
        asset.setType("default");
        assets.add(assetService.saveAsset(asset));
    }
    List<Asset> loadedAssets = new ArrayList<>();
    TextPageLink pageLink = new TextPageLink(23);
    TextPageData<Asset> pageData = null;
    do {
        pageData = assetService.findAssetsByTenantId(tenantId, pageLink);
        loadedAssets.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(assets, idComparator);
    Collections.sort(loadedAssets, idComparator);
    Assert.assertEquals(assets, loadedAssets);
    assetService.deleteAssetsByTenantId(tenantId);
    pageLink = new TextPageLink(33);
    pageData = assetService.findAssetsByTenantId(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) ArrayList(java.util.ArrayList) Asset(org.thingsboard.server.common.data.asset.Asset) Test(org.junit.Test)

Example 100 with TenantId

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

the class BaseAssetServiceTest method testFindAssetsByTenantIdAndCustomerId.

@Test
public void testFindAssetsByTenantIdAndCustomerId() {
    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<Asset> assets = new ArrayList<>();
    for (int i = 0; i < 278; i++) {
        Asset asset = new Asset();
        asset.setTenantId(tenantId);
        asset.setName("Asset" + i);
        asset.setType("default");
        asset = assetService.saveAsset(asset);
        assets.add(assetService.assignAssetToCustomer(asset.getId(), customerId));
    }
    List<Asset> loadedAssets = new ArrayList<>();
    TextPageLink pageLink = new TextPageLink(23);
    TextPageData<Asset> pageData = null;
    do {
        pageData = assetService.findAssetsByTenantIdAndCustomerId(tenantId, customerId, pageLink);
        loadedAssets.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(assets, idComparator);
    Collections.sort(loadedAssets, idComparator);
    Assert.assertEquals(assets, loadedAssets);
    assetService.unassignCustomerAssets(tenantId, customerId);
    pageLink = new TextPageLink(33);
    pageData = assetService.findAssetsByTenantIdAndCustomerId(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) ArrayList(java.util.ArrayList) Asset(org.thingsboard.server.common.data.asset.Asset) 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