|
|
|
@ -20,16 +20,25 @@ import org.junit.Assert; |
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.jupiter.api.Assertions; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.transaction.PlatformTransactionManager; |
|
|
|
import org.springframework.transaction.TransactionStatus; |
|
|
|
import org.springframework.transaction.support.DefaultTransactionDefinition; |
|
|
|
import org.springframework.transaction.support.TransactionCallbackWithoutResult; |
|
|
|
import org.springframework.transaction.support.TransactionTemplate; |
|
|
|
import org.thingsboard.server.common.data.Customer; |
|
|
|
import org.thingsboard.server.common.data.EntitySubtype; |
|
|
|
import org.thingsboard.server.common.data.StringUtils; |
|
|
|
import org.thingsboard.server.common.data.Tenant; |
|
|
|
import org.thingsboard.server.common.data.asset.Asset; |
|
|
|
import org.thingsboard.server.common.data.asset.AssetInfo; |
|
|
|
import org.thingsboard.server.common.data.asset.AssetProfile; |
|
|
|
import org.thingsboard.server.common.data.id.AssetProfileId; |
|
|
|
import org.thingsboard.server.common.data.id.CustomerId; |
|
|
|
import org.thingsboard.server.common.data.id.TenantId; |
|
|
|
import org.thingsboard.server.common.data.page.PageData; |
|
|
|
import org.thingsboard.server.common.data.page.PageLink; |
|
|
|
import org.thingsboard.server.dao.asset.AssetDao; |
|
|
|
import org.thingsboard.server.dao.asset.AssetProfileService; |
|
|
|
import org.thingsboard.server.dao.asset.AssetService; |
|
|
|
import org.thingsboard.server.dao.customer.CustomerService; |
|
|
|
import org.thingsboard.server.dao.exception.DataValidationException; |
|
|
|
@ -37,6 +46,7 @@ import org.thingsboard.server.dao.exception.DataValidationException; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.List; |
|
|
|
import java.util.UUID; |
|
|
|
|
|
|
|
import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID; |
|
|
|
|
|
|
|
@ -46,7 +56,13 @@ public class AssetServiceTest extends AbstractServiceTest { |
|
|
|
@Autowired |
|
|
|
AssetService assetService; |
|
|
|
@Autowired |
|
|
|
AssetDao assetDao; |
|
|
|
@Autowired |
|
|
|
CustomerService customerService; |
|
|
|
@Autowired |
|
|
|
private AssetProfileService assetProfileService; |
|
|
|
@Autowired |
|
|
|
private PlatformTransactionManager platformTransactionManager; |
|
|
|
|
|
|
|
private IdComparator<Asset> idComparator = new IdComparator<>(); |
|
|
|
|
|
|
|
@ -75,6 +91,29 @@ public class AssetServiceTest extends AbstractServiceTest { |
|
|
|
assetService.deleteAsset(tenantId, savedAsset.getId()); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testShouldNotPutInCacheRolledbackAssetProfile() { |
|
|
|
AssetProfile assetProfile = new AssetProfile(); |
|
|
|
assetProfile.setName(StringUtils.randomAlphabetic(10)); |
|
|
|
assetProfile.setTenantId(tenantId); |
|
|
|
|
|
|
|
Asset asset = new Asset(); |
|
|
|
asset.setName("My asset" + StringUtils.randomAlphabetic(15)); |
|
|
|
asset.setType(assetProfile.getName()); |
|
|
|
asset.setTenantId(tenantId); |
|
|
|
|
|
|
|
DefaultTransactionDefinition def = new DefaultTransactionDefinition(); |
|
|
|
TransactionStatus status = platformTransactionManager.getTransaction(def); |
|
|
|
try { |
|
|
|
assetProfileService.saveAssetProfile(assetProfile); |
|
|
|
assetService.saveAsset(asset); |
|
|
|
} finally { |
|
|
|
platformTransactionManager.rollback(status); |
|
|
|
} |
|
|
|
AssetProfile assetProfileByName = assetProfileService.findAssetProfileByName(tenantId, assetProfile.getName()); |
|
|
|
Assert.assertNull(assetProfileByName); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testSaveAssetWithEmptyName() { |
|
|
|
Asset asset = new Asset(); |
|
|
|
|