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