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);
}
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);
}
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());
}
}
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);
}
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());
}
Aggregations