use of org.thingsboard.server.common.data.id.TenantId 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.id.TenantId 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.id.TenantId in project thingsboard by thingsboard.
the class BaseEventServiceTest method findEventsByTypeAndTimeAscOrder.
@Test
public void findEventsByTypeAndTimeAscOrder() throws Exception {
long timeBeforeStartTime = LocalDateTime.of(2016, Month.NOVEMBER, 1, 11, 30).toEpochSecond(ZoneOffset.UTC);
long startTime = LocalDateTime.of(2016, Month.NOVEMBER, 1, 12, 0).toEpochSecond(ZoneOffset.UTC);
long eventTime = LocalDateTime.of(2016, Month.NOVEMBER, 1, 12, 30).toEpochSecond(ZoneOffset.UTC);
long endTime = LocalDateTime.of(2016, Month.NOVEMBER, 1, 13, 0).toEpochSecond(ZoneOffset.UTC);
long timeAfterEndTime = LocalDateTime.of(2016, Month.NOVEMBER, 1, 13, 30).toEpochSecond(ZoneOffset.UTC);
RuleId ruleId = new RuleId(UUIDs.timeBased());
TenantId tenantId = new TenantId(UUIDs.timeBased());
saveEventWithProvidedTime(timeBeforeStartTime, ruleId, tenantId);
Event savedEvent = saveEventWithProvidedTime(eventTime, ruleId, tenantId);
Event savedEvent2 = saveEventWithProvidedTime(eventTime + 1, ruleId, tenantId);
Event savedEvent3 = saveEventWithProvidedTime(eventTime + 2, ruleId, tenantId);
saveEventWithProvidedTime(timeAfterEndTime, ruleId, tenantId);
TimePageData<Event> events = eventService.findEvents(tenantId, ruleId, DataConstants.STATS, new TimePageLink(2, startTime, endTime, true));
Assert.assertNotNull(events.getData());
Assert.assertTrue(events.getData().size() == 2);
Assert.assertTrue(events.getData().get(0).getUuidId().equals(savedEvent.getUuidId()));
Assert.assertTrue(events.getData().get(1).getUuidId().equals(savedEvent2.getUuidId()));
Assert.assertTrue(events.hasNext());
Assert.assertNotNull(events.getNextPageLink());
events = eventService.findEvents(tenantId, ruleId, DataConstants.STATS, events.getNextPageLink());
Assert.assertNotNull(events.getData());
Assert.assertTrue(events.getData().size() == 1);
Assert.assertTrue(events.getData().get(0).getUuidId().equals(savedEvent3.getUuidId()));
Assert.assertFalse(events.hasNext());
Assert.assertNull(events.getNextPageLink());
}
use of org.thingsboard.server.common.data.id.TenantId in project thingsboard by thingsboard.
the class BaseAssetServiceTest method testFindAssetsByTenantId.
@Test
public void testFindAssetsByTenantId() {
Tenant tenant = new Tenant();
tenant.setTitle("Test tenant");
tenant = tenantService.saveTenant(tenant);
TenantId tenantId = tenant.getId();
List<Asset> assets = new ArrayList<>();
for (int i = 0; i < 178; i++) {
Asset asset = new Asset();
asset.setTenantId(tenantId);
asset.setName("Asset" + i);
asset.setType("default");
assets.add(assetService.saveAsset(asset));
}
List<Asset> loadedAssets = new ArrayList<>();
TextPageLink pageLink = new TextPageLink(23);
TextPageData<Asset> pageData = null;
do {
pageData = assetService.findAssetsByTenantId(tenantId, pageLink);
loadedAssets.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageData.getNextPageLink();
}
} while (pageData.hasNext());
Collections.sort(assets, idComparator);
Collections.sort(loadedAssets, idComparator);
Assert.assertEquals(assets, loadedAssets);
assetService.deleteAssetsByTenantId(tenantId);
pageLink = new TextPageLink(33);
pageData = assetService.findAssetsByTenantId(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 BaseAssetServiceTest method testFindAssetsByTenantIdAndCustomerId.
@Test
public void testFindAssetsByTenantIdAndCustomerId() {
Tenant tenant = new Tenant();
tenant.setTitle("Test tenant");
tenant = tenantService.saveTenant(tenant);
TenantId tenantId = tenant.getId();
Customer customer = new Customer();
customer.setTitle("Test customer");
customer.setTenantId(tenantId);
customer = customerService.saveCustomer(customer);
CustomerId customerId = customer.getId();
List<Asset> assets = new ArrayList<>();
for (int i = 0; i < 278; i++) {
Asset asset = new Asset();
asset.setTenantId(tenantId);
asset.setName("Asset" + i);
asset.setType("default");
asset = assetService.saveAsset(asset);
assets.add(assetService.assignAssetToCustomer(asset.getId(), customerId));
}
List<Asset> loadedAssets = new ArrayList<>();
TextPageLink pageLink = new TextPageLink(23);
TextPageData<Asset> pageData = null;
do {
pageData = assetService.findAssetsByTenantIdAndCustomerId(tenantId, customerId, pageLink);
loadedAssets.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageData.getNextPageLink();
}
} while (pageData.hasNext());
Collections.sort(assets, idComparator);
Collections.sort(loadedAssets, idComparator);
Assert.assertEquals(assets, loadedAssets);
assetService.unassignCustomerAssets(tenantId, customerId);
pageLink = new TextPageLink(33);
pageData = assetService.findAssetsByTenantIdAndCustomerId(tenantId, customerId, pageLink);
Assert.assertFalse(pageData.hasNext());
Assert.assertTrue(pageData.getData().isEmpty());
tenantService.deleteTenant(tenantId);
}
Aggregations