Search in sources :

Example 91 with TenantId

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

the class BaseWidgetTypeServiceTest method testUpdateWidgetTypeTenant.

@Test(expected = DataValidationException.class)
public void testUpdateWidgetTypeTenant() throws IOException {
    WidgetsBundle widgetsBundle = new WidgetsBundle();
    widgetsBundle.setTenantId(tenantId);
    widgetsBundle.setTitle("Widgets bundle");
    WidgetsBundle savedWidgetsBundle = widgetsBundleService.saveWidgetsBundle(widgetsBundle);
    WidgetType widgetType = new WidgetType();
    widgetType.setTenantId(tenantId);
    widgetType.setBundleAlias(savedWidgetsBundle.getAlias());
    widgetType.setName("Widget Type");
    widgetType.setDescriptor(new ObjectMapper().readValue("{ \"someKey\": \"someValue\" }", JsonNode.class));
    WidgetType savedWidgetType = widgetTypeService.saveWidgetType(widgetType);
    savedWidgetType.setTenantId(new TenantId(ModelConstants.NULL_UUID));
    try {
        widgetTypeService.saveWidgetType(savedWidgetType);
    } finally {
        widgetsBundleService.deleteWidgetsBundle(savedWidgetsBundle.getId());
    }
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) JsonNode(com.fasterxml.jackson.databind.JsonNode) WidgetType(org.thingsboard.server.common.data.widget.WidgetType) WidgetsBundle(org.thingsboard.server.common.data.widget.WidgetsBundle) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 92 with TenantId

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

the class BaseWidgetsBundleServiceTest method testSaveWidgetsBundleWithInvalidTenant.

@Test(expected = DataValidationException.class)
public void testSaveWidgetsBundleWithInvalidTenant() {
    WidgetsBundle widgetsBundle = new WidgetsBundle();
    widgetsBundle.setTitle("My widgets bundle");
    widgetsBundle.setTenantId(new TenantId(UUIDs.timeBased()));
    widgetsBundleService.saveWidgetsBundle(widgetsBundle);
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) WidgetsBundle(org.thingsboard.server.common.data.widget.WidgetsBundle) Test(org.junit.Test)

Example 93 with TenantId

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

the class BaseWidgetsBundleServiceTest method testFindSystemWidgetsBundles.

@Test
public void testFindSystemWidgetsBundles() {
    TenantId tenantId = new TenantId(ModelConstants.NULL_UUID);
    List<WidgetsBundle> systemWidgetsBundles = widgetsBundleService.findSystemWidgetsBundles();
    List<WidgetsBundle> createdWidgetsBundles = new ArrayList<>();
    for (int i = 0; i < 135; i++) {
        WidgetsBundle widgetsBundle = new WidgetsBundle();
        widgetsBundle.setTenantId(tenantId);
        widgetsBundle.setTitle("Widgets bundle " + i);
        createdWidgetsBundles.add(widgetsBundleService.saveWidgetsBundle(widgetsBundle));
    }
    List<WidgetsBundle> widgetsBundles = new ArrayList<>(createdWidgetsBundles);
    widgetsBundles.addAll(systemWidgetsBundles);
    List<WidgetsBundle> loadedWidgetsBundles = widgetsBundleService.findSystemWidgetsBundles();
    Collections.sort(widgetsBundles, idComparator);
    Collections.sort(loadedWidgetsBundles, idComparator);
    Assert.assertEquals(widgetsBundles, loadedWidgetsBundles);
    for (WidgetsBundle widgetsBundle : createdWidgetsBundles) {
        widgetsBundleService.deleteWidgetsBundle(widgetsBundle.getId());
    }
    loadedWidgetsBundles = widgetsBundleService.findSystemWidgetsBundles();
    Collections.sort(systemWidgetsBundles, idComparator);
    Collections.sort(loadedWidgetsBundles, idComparator);
    Assert.assertEquals(systemWidgetsBundles, loadedWidgetsBundles);
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) ArrayList(java.util.ArrayList) WidgetsBundle(org.thingsboard.server.common.data.widget.WidgetsBundle) Test(org.junit.Test)

Example 94 with TenantId

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

the class BaseWidgetsBundleServiceTest method testFindTenantWidgetsBundlesByTenantId.

@Test
public void testFindTenantWidgetsBundlesByTenantId() {
    Tenant tenant = new Tenant();
    tenant.setTitle("Test tenant");
    tenant = tenantService.saveTenant(tenant);
    TenantId tenantId = tenant.getId();
    List<WidgetsBundle> widgetsBundles = new ArrayList<>();
    for (int i = 0; i < 127; i++) {
        WidgetsBundle widgetsBundle = new WidgetsBundle();
        widgetsBundle.setTenantId(tenantId);
        widgetsBundle.setTitle("Widgets bundle " + i);
        widgetsBundles.add(widgetsBundleService.saveWidgetsBundle(widgetsBundle));
    }
    List<WidgetsBundle> loadedWidgetsBundles = new ArrayList<>();
    TextPageLink pageLink = new TextPageLink(11);
    TextPageData<WidgetsBundle> pageData = null;
    do {
        pageData = widgetsBundleService.findTenantWidgetsBundlesByTenantId(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);
    pageLink = new TextPageLink(15);
    pageData = widgetsBundleService.findTenantWidgetsBundlesByTenantId(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) WidgetsBundle(org.thingsboard.server.common.data.widget.WidgetsBundle) Test(org.junit.Test)

Example 95 with TenantId

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

the class BaseWidgetsBundleServiceTest method testFindSystemWidgetsBundlesByPageLink.

@Test
public void testFindSystemWidgetsBundlesByPageLink() {
    TenantId tenantId = new TenantId(ModelConstants.NULL_UUID);
    List<WidgetsBundle> systemWidgetsBundles = widgetsBundleService.findSystemWidgetsBundles();
    List<WidgetsBundle> createdWidgetsBundles = new ArrayList<>();
    for (int i = 0; i < 235; i++) {
        WidgetsBundle widgetsBundle = new WidgetsBundle();
        widgetsBundle.setTenantId(tenantId);
        widgetsBundle.setTitle("Widgets bundle " + i);
        createdWidgetsBundles.add(widgetsBundleService.saveWidgetsBundle(widgetsBundle));
    }
    List<WidgetsBundle> widgetsBundles = new ArrayList<>(createdWidgetsBundles);
    widgetsBundles.addAll(systemWidgetsBundles);
    List<WidgetsBundle> loadedWidgetsBundles = new ArrayList<>();
    TextPageLink pageLink = new TextPageLink(19);
    TextPageData<WidgetsBundle> pageData = null;
    do {
        pageData = widgetsBundleService.findSystemWidgetsBundlesByPageLink(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);
    for (WidgetsBundle widgetsBundle : createdWidgetsBundles) {
        widgetsBundleService.deleteWidgetsBundle(widgetsBundle.getId());
    }
    loadedWidgetsBundles = widgetsBundleService.findSystemWidgetsBundles();
    Collections.sort(systemWidgetsBundles, idComparator);
    Collections.sort(loadedWidgetsBundles, idComparator);
    Assert.assertEquals(systemWidgetsBundles, loadedWidgetsBundles);
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) ArrayList(java.util.ArrayList) WidgetsBundle(org.thingsboard.server.common.data.widget.WidgetsBundle) 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