use of org.thingsboard.server.common.data.widget.WidgetsBundle 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);
}
use of org.thingsboard.server.common.data.widget.WidgetsBundle 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);
}
use of org.thingsboard.server.common.data.widget.WidgetsBundle in project thingsboard by thingsboard.
the class BaseWidgetsBundleServiceTest method testSaveWidgetsBundle.
@Test
public void testSaveWidgetsBundle() throws IOException {
WidgetsBundle widgetsBundle = new WidgetsBundle();
widgetsBundle.setTenantId(tenantId);
widgetsBundle.setTitle("My first widgets bundle");
WidgetsBundle savedWidgetsBundle = widgetsBundleService.saveWidgetsBundle(widgetsBundle);
Assert.assertNotNull(savedWidgetsBundle);
Assert.assertNotNull(savedWidgetsBundle.getId());
Assert.assertNotNull(savedWidgetsBundle.getAlias());
Assert.assertTrue(savedWidgetsBundle.getCreatedTime() > 0);
Assert.assertEquals(widgetsBundle.getTenantId(), savedWidgetsBundle.getTenantId());
Assert.assertEquals(widgetsBundle.getTitle(), savedWidgetsBundle.getTitle());
savedWidgetsBundle.setTitle("My new widgets bundle");
widgetsBundleService.saveWidgetsBundle(savedWidgetsBundle);
WidgetsBundle foundWidgetsBundle = widgetsBundleService.findWidgetsBundleById(savedWidgetsBundle.getId());
Assert.assertEquals(foundWidgetsBundle.getTitle(), savedWidgetsBundle.getTitle());
widgetsBundleService.deleteWidgetsBundle(savedWidgetsBundle.getId());
}
use of org.thingsboard.server.common.data.widget.WidgetsBundle in project thingsboard by thingsboard.
the class BaseWidgetsBundleServiceTest method testSaveWidgetsBundleWithEmptyTitle.
@Test(expected = DataValidationException.class)
public void testSaveWidgetsBundleWithEmptyTitle() {
WidgetsBundle widgetsBundle = new WidgetsBundle();
widgetsBundle.setTenantId(tenantId);
widgetsBundleService.saveWidgetsBundle(widgetsBundle);
}
use of org.thingsboard.server.common.data.widget.WidgetsBundle in project thingsboard by thingsboard.
the class BaseWidgetsBundleServiceTest method testFindWidgetsBundleById.
@Test
public void testFindWidgetsBundleById() {
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);
Assert.assertEquals(savedWidgetsBundle, foundWidgetsBundle);
widgetsBundleService.deleteWidgetsBundle(savedWidgetsBundle.getId());
}
Aggregations