Validation of version and title
This commit is contained in:
parent
f1216c9720
commit
f6c720513d
@ -341,6 +341,7 @@ public class BaseOtaPackageService implements OtaPackageService {
|
||||
if (otaPackageOld.getDataSize() != null && !otaPackageOld.getDataSize().equals(otaPackage.getDataSize())) {
|
||||
throw new DataValidationException("Updating otaPackage data size is prohibited!");
|
||||
}
|
||||
|
||||
if(otaPackageOld.getUrl() != null && !otaPackageOld.getUrl().equals(otaPackage.getUrl())) {
|
||||
throw new DataValidationException("Updating otaPackage URL is prohibited!");
|
||||
}
|
||||
@ -374,6 +375,15 @@ public class BaseOtaPackageService implements OtaPackageService {
|
||||
if (StringUtils.isEmpty(otaPackageInfo.getVersion())) {
|
||||
throw new DataValidationException("OtaPackage version should be specified!");
|
||||
}
|
||||
|
||||
if(otaPackageInfo.getTitle().length() > 255) {
|
||||
throw new DataValidationException("The length of title should be equal or shorter than 255");
|
||||
}
|
||||
|
||||
if(otaPackageInfo.getVersion().length() > 255) {
|
||||
throw new DataValidationException("The length of version should be equal or shorter than 255");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private PaginatedRemover<TenantId, OtaPackageInfo> tenantOtaPackageRemover =
|
||||
|
||||
@ -661,6 +661,38 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest {
|
||||
otaPackageService.saveOtaPackageInfo(savedFirmwareInfo, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveOtaPackageCantViolateSizeOfTitleAndVersion() {
|
||||
OtaPackageInfo firmwareInfo = new OtaPackageInfo();
|
||||
firmwareInfo.setDeviceProfileId(deviceProfileId);
|
||||
firmwareInfo.setType(FIRMWARE);
|
||||
firmwareInfo.setTitle("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
|
||||
"aaaaaaaaaa");
|
||||
firmwareInfo.setVersion(VERSION);
|
||||
firmwareInfo.setUrl(URL);
|
||||
firmwareInfo.setTenantId(tenantId);
|
||||
|
||||
thrown.expect(DataValidationException.class);
|
||||
thrown.expectMessage("The length of title should be equal or shorter than 255");
|
||||
|
||||
otaPackageService.saveOtaPackageInfo(firmwareInfo, true);
|
||||
|
||||
firmwareInfo.setTitle(TITLE);
|
||||
firmwareInfo.setVersion("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
|
||||
"aaaaaaaaaa");
|
||||
thrown.expectMessage("The length of version should be equal or shorter than 255");
|
||||
|
||||
otaPackageService.saveOtaPackageInfo(firmwareInfo, true);
|
||||
}
|
||||
|
||||
private OtaPackage createFirmware(TenantId tenantId, String version) {
|
||||
OtaPackage firmware = new OtaPackage();
|
||||
firmware.setTenantId(tenantId);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user