Add test for deleting device profile referenced by OTA

This commit is contained in:
Viacheslav Klimov 2022-01-31 13:21:59 +02:00
parent d4784b3096
commit 35528e687a
2 changed files with 37 additions and 1 deletions

View File

@ -33,14 +33,18 @@ import org.thingsboard.server.common.data.DeviceProfileType;
import org.thingsboard.server.common.data.DeviceTransportType;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.Event;
import org.thingsboard.server.common.data.OtaPackage;
import org.thingsboard.server.common.data.Tenant;
import org.thingsboard.server.common.data.device.profile.DefaultDeviceProfileConfiguration;
import org.thingsboard.server.common.data.device.profile.DefaultDeviceProfileTransportConfiguration;
import org.thingsboard.server.common.data.device.profile.DeviceProfileData;
import org.thingsboard.server.common.data.edge.Edge;
import org.thingsboard.server.common.data.id.DeviceProfileId;
import org.thingsboard.server.common.data.id.EntityId;
import org.thingsboard.server.common.data.id.HasId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.ota.ChecksumAlgorithm;
import org.thingsboard.server.common.data.ota.OtaPackageType;
import org.thingsboard.server.dao.alarm.AlarmService;
import org.thingsboard.server.dao.asset.AssetService;
import org.thingsboard.server.dao.audit.AuditLogLevelFilter;
@ -70,6 +74,7 @@ import org.thingsboard.server.dao.widget.WidgetTypeService;
import org.thingsboard.server.dao.widget.WidgetsBundleService;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
@ -253,4 +258,21 @@ public abstract class AbstractServiceTest {
edge.setCloudEndpoint("http://localhost:8080");
return edge;
}
protected OtaPackage constructDefaultOtaPackage(TenantId tenantId, DeviceProfileId deviceProfileId) {
OtaPackage firmware = new OtaPackage();
firmware.setTenantId(tenantId);
firmware.setDeviceProfileId(deviceProfileId);
firmware.setType(OtaPackageType.FIRMWARE);
firmware.setTitle("My firmware");
firmware.setVersion("3.3.3");
firmware.setFileName("filename.txt");
firmware.setContentType("text/plain");
firmware.setChecksumAlgorithm(ChecksumAlgorithm.SHA256);
firmware.setChecksum("4bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459a");
firmware.setData(ByteBuffer.wrap(new byte[]{1}));
firmware.setDataSize(1L);
return firmware;
}
}

View File

@ -31,8 +31,8 @@ import org.thingsboard.server.common.data.DeviceProfileInfo;
import org.thingsboard.server.common.data.DeviceTransportType;
import org.thingsboard.server.common.data.OtaPackage;
import org.thingsboard.server.common.data.Tenant;
import org.thingsboard.server.common.data.ota.ChecksumAlgorithm;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.ota.ChecksumAlgorithm;
import org.thingsboard.server.common.data.page.PageData;
import org.thingsboard.server.common.data.page.PageLink;
import org.thingsboard.server.dao.exception.DataValidationException;
@ -45,6 +45,7 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;
import static org.junit.Assert.assertThrows;
import static org.thingsboard.server.common.data.ota.OtaPackageType.FIRMWARE;
public abstract class BaseDeviceProfileServiceTest extends AbstractServiceTest {
@ -252,6 +253,19 @@ public abstract class BaseDeviceProfileServiceTest extends AbstractServiceTest {
deviceProfileService.deleteDeviceProfile(tenantId, savedDeviceProfile.getId());
}
@Test
public void testDeleteDeviceProfileWithExistingOta() {
DeviceProfile deviceProfile = this.createDeviceProfile(tenantId, "Device Profile");
DeviceProfile savedDeviceProfile = deviceProfileService.saveDeviceProfile(deviceProfile);
OtaPackage otaPackage = constructDefaultOtaPackage(tenantId, savedDeviceProfile.getId());
otaPackageService.saveOtaPackage(otaPackage);
assertThrows("The device profile is referenced by OTA update package", DataValidationException.class, () -> {
deviceProfileService.deleteDeviceProfile(tenantId, savedDeviceProfile.getId());
});
}
@Test
public void testDeleteDeviceProfile() {
DeviceProfile deviceProfile = this.createDeviceProfile(tenantId, "Device Profile");