Search in sources :

Example 36 with WidgetsBundle

use of org.thingsboard.server.common.data.widget.WidgetsBundle 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)

Example 37 with WidgetsBundle

use of org.thingsboard.server.common.data.widget.WidgetsBundle in project thingsboard by thingsboard.

the class BaseWidgetsBundleServiceTest method testDeleteWidgetsBundle.

@Test
public void testDeleteWidgetsBundle() {
    WidgetsBundle widgetsBundle = new WidgetsBundle();
    widgetsBundle.setTenantId(tenantId);
    widgetsBundle.setTitle("My widgets bundle");
    WidgetsBundle savedWidgetsBundle = widgetsBundleService.saveWidgetsBundle(widgetsBundle);
    WidgetsBundle foundWidgetsBundle = widgetsBundleService.findWidgetsBundleById(savedWidgetsBundle.getId());
    Assert.assertNotNull(foundWidgetsBundle);
    widgetsBundleService.deleteWidgetsBundle(savedWidgetsBundle.getId());
    foundWidgetsBundle = widgetsBundleService.findWidgetsBundleById(savedWidgetsBundle.getId());
    Assert.assertNull(foundWidgetsBundle);
}
Also used : WidgetsBundle(org.thingsboard.server.common.data.widget.WidgetsBundle) Test(org.junit.Test)

Example 38 with WidgetsBundle

use of org.thingsboard.server.common.data.widget.WidgetsBundle 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 39 with WidgetsBundle

use of org.thingsboard.server.common.data.widget.WidgetsBundle 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 40 with WidgetsBundle

use of org.thingsboard.server.common.data.widget.WidgetsBundle in project thingsboard by thingsboard.

the class JpaWidgetsBundleDaoTest method testFindWidgetsBundleByTenantIdAndAlias.

@Test
@DatabaseSetup(value = "classpath:dbunit/widgets_bundle.xml", type = DatabaseOperation.CLEAN_INSERT)
@DatabaseTearDown(value = "classpath:dbunit/widgets_bundle.xml", type = DatabaseOperation.DELETE_ALL)
public void testFindWidgetsBundleByTenantIdAndAlias() {
    WidgetsBundle widgetsBundle = widgetsBundleDao.findWidgetsBundleByTenantIdAndAlias(UUID.fromString("250aca8e-2825-11e7-93ae-92361f002671"), "WB3");
    assertEquals("44e6af4e-2825-11e7-93ae-92361f002671", widgetsBundle.getId().toString());
}
Also used : WidgetsBundle(org.thingsboard.server.common.data.widget.WidgetsBundle) AbstractJpaDaoTest(org.thingsboard.server.dao.AbstractJpaDaoTest) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup) DatabaseTearDown(com.github.springtestdbunit.annotation.DatabaseTearDown)

Aggregations

WidgetsBundle (org.thingsboard.server.common.data.widget.WidgetsBundle)48 Test (org.junit.Test)38 TenantId (org.thingsboard.server.common.data.id.TenantId)13 JsonNode (com.fasterxml.jackson.databind.JsonNode)12 ArrayList (java.util.ArrayList)12 WidgetType (org.thingsboard.server.common.data.widget.WidgetType)12 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)11 TextPageLink (org.thingsboard.server.common.data.page.TextPageLink)11 DatabaseSetup (com.github.springtestdbunit.annotation.DatabaseSetup)5 AbstractJpaDaoTest (org.thingsboard.server.dao.AbstractJpaDaoTest)5 List (java.util.List)4 Tenant (org.thingsboard.server.common.data.Tenant)4 WidgetsBundleId (org.thingsboard.server.common.data.id.WidgetsBundleId)4 TypeReference (com.fasterxml.jackson.core.type.TypeReference)3 UUID (java.util.UUID)3 NULL_UUID (org.thingsboard.server.dao.model.ModelConstants.NULL_UUID)3 DatabaseTearDown (com.github.springtestdbunit.annotation.DatabaseTearDown)2 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1