use of org.thingsboard.server.common.data.asset.Asset in project thingsboard by thingsboard.
the class BaseAssetServiceTest method testAssignAssetToNonExistentCustomer.
@Test(expected = DataValidationException.class)
public void testAssignAssetToNonExistentCustomer() {
Asset asset = new Asset();
asset.setName("My asset");
asset.setType("default");
asset.setTenantId(tenantId);
asset = assetService.saveAsset(asset);
try {
assetService.assignAssetToCustomer(asset.getId(), new CustomerId(UUIDs.timeBased()));
} finally {
assetService.deleteAsset(asset.getId());
}
}
use of org.thingsboard.server.common.data.asset.Asset in project thingsboard by thingsboard.
the class BaseAssetServiceTest method testSaveAsset.
@Test
public void testSaveAsset() {
Asset asset = new Asset();
asset.setTenantId(tenantId);
asset.setName("My asset");
asset.setType("default");
Asset savedAsset = assetService.saveAsset(asset);
Assert.assertNotNull(savedAsset);
Assert.assertNotNull(savedAsset.getId());
Assert.assertTrue(savedAsset.getCreatedTime() > 0);
Assert.assertEquals(asset.getTenantId(), savedAsset.getTenantId());
Assert.assertNotNull(savedAsset.getCustomerId());
Assert.assertEquals(NULL_UUID, savedAsset.getCustomerId().getId());
Assert.assertEquals(asset.getName(), savedAsset.getName());
savedAsset.setName("My new asset");
assetService.saveAsset(savedAsset);
Asset foundAsset = assetService.findAssetById(savedAsset.getId());
Assert.assertEquals(foundAsset.getName(), savedAsset.getName());
assetService.deleteAsset(savedAsset.getId());
}
use of org.thingsboard.server.common.data.asset.Asset in project thingsboard by thingsboard.
the class BaseAssetServiceTest method testSaveAssetWithEmptyName.
@Test(expected = DataValidationException.class)
public void testSaveAssetWithEmptyName() {
Asset asset = new Asset();
asset.setTenantId(tenantId);
asset.setType("default");
assetService.saveAsset(asset);
}
use of org.thingsboard.server.common.data.asset.Asset in project thingsboard by thingsboard.
the class BaseAssetServiceTest method testSaveAssetWithEmptyTenant.
@Test(expected = DataValidationException.class)
public void testSaveAssetWithEmptyTenant() {
Asset asset = new Asset();
asset.setName("My asset");
asset.setType("default");
assetService.saveAsset(asset);
}
use of org.thingsboard.server.common.data.asset.Asset in project thingsboard by thingsboard.
the class BaseAssetServiceTest method testFindAssetsByTenantIdCustomerIdAndType.
@Test
public void testFindAssetsByTenantIdCustomerIdAndType() {
Customer customer = new Customer();
customer.setTitle("Test customer");
customer.setTenantId(tenantId);
customer = customerService.saveCustomer(customer);
CustomerId customerId = customer.getId();
String title1 = "Asset title 1";
String type1 = "typeC";
List<Asset> assetsType1 = new ArrayList<>();
for (int i = 0; i < 175; i++) {
Asset asset = new Asset();
asset.setTenantId(tenantId);
String suffix = RandomStringUtils.randomAlphanumeric(15);
String name = title1 + suffix;
name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
asset.setName(name);
asset.setType(type1);
asset = assetService.saveAsset(asset);
assetsType1.add(assetService.assignAssetToCustomer(asset.getId(), customerId));
}
String title2 = "Asset title 2";
String type2 = "typeD";
List<Asset> assetsType2 = new ArrayList<>();
for (int i = 0; i < 143; i++) {
Asset asset = new Asset();
asset.setTenantId(tenantId);
String suffix = RandomStringUtils.randomAlphanumeric(15);
String name = title2 + suffix;
name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
asset.setName(name);
asset.setType(type2);
asset = assetService.saveAsset(asset);
assetsType2.add(assetService.assignAssetToCustomer(asset.getId(), customerId));
}
List<Asset> loadedAssetsType1 = new ArrayList<>();
TextPageLink pageLink = new TextPageLink(15);
TextPageData<Asset> pageData = null;
do {
pageData = assetService.findAssetsByTenantIdAndCustomerIdAndType(tenantId, customerId, type1, pageLink);
loadedAssetsType1.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageData.getNextPageLink();
}
} while (pageData.hasNext());
Collections.sort(assetsType1, idComparator);
Collections.sort(loadedAssetsType1, idComparator);
Assert.assertEquals(assetsType1, loadedAssetsType1);
List<Asset> loadedAssetsType2 = new ArrayList<>();
pageLink = new TextPageLink(4);
do {
pageData = assetService.findAssetsByTenantIdAndCustomerIdAndType(tenantId, customerId, type2, pageLink);
loadedAssetsType2.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageData.getNextPageLink();
}
} while (pageData.hasNext());
Collections.sort(assetsType2, idComparator);
Collections.sort(loadedAssetsType2, idComparator);
Assert.assertEquals(assetsType2, loadedAssetsType2);
for (Asset asset : loadedAssetsType1) {
assetService.deleteAsset(asset.getId());
}
pageLink = new TextPageLink(4);
pageData = assetService.findAssetsByTenantIdAndCustomerIdAndType(tenantId, customerId, type1, pageLink);
Assert.assertFalse(pageData.hasNext());
Assert.assertEquals(0, pageData.getData().size());
for (Asset asset : loadedAssetsType2) {
assetService.deleteAsset(asset.getId());
}
pageLink = new TextPageLink(4);
pageData = assetService.findAssetsByTenantIdAndCustomerIdAndType(tenantId, customerId, type2, pageLink);
Assert.assertFalse(pageData.hasNext());
Assert.assertEquals(0, pageData.getData().size());
customerService.deleteCustomer(customerId);
}
Aggregations