|
|
|
@ -16,6 +16,7 @@ |
|
|
|
package org.thingsboard.server.dao.service; |
|
|
|
|
|
|
|
import com.datastax.oss.driver.api.core.uuid.Uuids; |
|
|
|
import org.apache.commons.lang3.RandomStringUtils; |
|
|
|
import org.junit.After; |
|
|
|
import org.junit.Assert; |
|
|
|
import org.junit.Before; |
|
|
|
@ -163,7 +164,7 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest { |
|
|
|
firmware.setVersion(VERSION); |
|
|
|
firmware.setUrl(URL); |
|
|
|
firmware.setDataSize(0L); |
|
|
|
OtaPackageInfo savedFirmware = otaPackageService.saveOtaPackageInfo(firmware); |
|
|
|
OtaPackageInfo savedFirmware = otaPackageService.saveOtaPackageInfo(firmware, true); |
|
|
|
|
|
|
|
Assert.assertNotNull(savedFirmware); |
|
|
|
Assert.assertNotNull(savedFirmware.getId()); |
|
|
|
@ -174,7 +175,7 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest { |
|
|
|
Assert.assertEquals(firmware.getContentType(), savedFirmware.getContentType()); |
|
|
|
|
|
|
|
savedFirmware.setAdditionalInfo(JacksonUtil.newObjectNode()); |
|
|
|
otaPackageService.saveOtaPackageInfo(savedFirmware); |
|
|
|
otaPackageService.saveOtaPackageInfo(savedFirmware, true); |
|
|
|
|
|
|
|
OtaPackage foundFirmware = otaPackageService.findOtaPackageById(tenantId, savedFirmware.getId()); |
|
|
|
Assert.assertEquals(foundFirmware.getTitle(), savedFirmware.getTitle()); |
|
|
|
@ -190,7 +191,7 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest { |
|
|
|
firmwareInfo.setType(FIRMWARE); |
|
|
|
firmwareInfo.setTitle(TITLE); |
|
|
|
firmwareInfo.setVersion(VERSION); |
|
|
|
OtaPackageInfo savedFirmwareInfo = otaPackageService.saveOtaPackageInfo(firmwareInfo); |
|
|
|
OtaPackageInfo savedFirmwareInfo = otaPackageService.saveOtaPackageInfo(firmwareInfo, false); |
|
|
|
|
|
|
|
Assert.assertNotNull(savedFirmwareInfo); |
|
|
|
Assert.assertNotNull(savedFirmwareInfo.getId()); |
|
|
|
@ -216,7 +217,7 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest { |
|
|
|
|
|
|
|
savedFirmwareInfo = otaPackageService.findOtaPackageInfoById(tenantId, savedFirmwareInfo.getId()); |
|
|
|
savedFirmwareInfo.setAdditionalInfo(JacksonUtil.newObjectNode()); |
|
|
|
otaPackageService.saveOtaPackageInfo(savedFirmwareInfo); |
|
|
|
otaPackageService.saveOtaPackageInfo(savedFirmwareInfo, false); |
|
|
|
|
|
|
|
OtaPackage foundFirmware = otaPackageService.findOtaPackageById(tenantId, firmware.getId()); |
|
|
|
firmware.setAdditionalInfo(JacksonUtil.newObjectNode()); |
|
|
|
@ -399,7 +400,7 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest { |
|
|
|
firmwareInfo.setType(FIRMWARE); |
|
|
|
firmwareInfo.setTitle(TITLE); |
|
|
|
firmwareInfo.setVersion(VERSION); |
|
|
|
otaPackageService.saveOtaPackageInfo(firmwareInfo); |
|
|
|
otaPackageService.saveOtaPackageInfo(firmwareInfo, false); |
|
|
|
|
|
|
|
OtaPackageInfo newFirmwareInfo = new OtaPackageInfo(); |
|
|
|
newFirmwareInfo.setTenantId(tenantId); |
|
|
|
@ -410,7 +411,7 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest { |
|
|
|
|
|
|
|
thrown.expect(DataValidationException.class); |
|
|
|
thrown.expectMessage("OtaPackage with such title and version already exists!"); |
|
|
|
otaPackageService.saveOtaPackageInfo(newFirmwareInfo); |
|
|
|
otaPackageService.saveOtaPackageInfo(newFirmwareInfo, false); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@ -506,7 +507,7 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest { |
|
|
|
firmware.setType(FIRMWARE); |
|
|
|
firmware.setTitle(TITLE); |
|
|
|
firmware.setVersion(VERSION); |
|
|
|
OtaPackageInfo savedFirmware = otaPackageService.saveOtaPackageInfo(firmware); |
|
|
|
OtaPackageInfo savedFirmware = otaPackageService.saveOtaPackageInfo(firmware, false); |
|
|
|
|
|
|
|
OtaPackageInfo foundFirmware = otaPackageService.findOtaPackageInfoById(tenantId, savedFirmware.getId()); |
|
|
|
Assert.assertNotNull(foundFirmware); |
|
|
|
@ -543,7 +544,7 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest { |
|
|
|
firmwareWithUrl.setUrl(URL); |
|
|
|
firmwareWithUrl.setDataSize(0L); |
|
|
|
|
|
|
|
OtaPackageInfo savedFwWithUrl = otaPackageService.saveOtaPackageInfo(firmwareWithUrl); |
|
|
|
OtaPackageInfo savedFwWithUrl = otaPackageService.saveOtaPackageInfo(firmwareWithUrl, true); |
|
|
|
savedFwWithUrl.setHasData(true); |
|
|
|
|
|
|
|
firmwares.add(savedFwWithUrl); |
|
|
|
@ -588,7 +589,7 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest { |
|
|
|
firmwareWithUrl.setUrl(URL); |
|
|
|
firmwareWithUrl.setDataSize(0L); |
|
|
|
|
|
|
|
OtaPackageInfo savedFwWithUrl = otaPackageService.saveOtaPackageInfo(firmwareWithUrl); |
|
|
|
OtaPackageInfo savedFwWithUrl = otaPackageService.saveOtaPackageInfo(firmwareWithUrl, true); |
|
|
|
savedFwWithUrl.setHasData(true); |
|
|
|
|
|
|
|
firmwares.add(savedFwWithUrl); |
|
|
|
@ -627,6 +628,71 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest { |
|
|
|
Assert.assertTrue(pageData.getData().isEmpty()); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testSaveOtaPackageInfoWithBlankAndEmptyUrl() { |
|
|
|
OtaPackageInfo firmwareInfo = new OtaPackageInfo(); |
|
|
|
firmwareInfo.setDeviceProfileId(deviceProfileId); |
|
|
|
firmwareInfo.setType(FIRMWARE); |
|
|
|
firmwareInfo.setTitle(TITLE); |
|
|
|
firmwareInfo.setVersion(VERSION); |
|
|
|
firmwareInfo.setUrl(" "); |
|
|
|
thrown.expect(DataValidationException.class); |
|
|
|
thrown.expectMessage("Ota package URL should be specified!"); |
|
|
|
otaPackageService.saveOtaPackageInfo(firmwareInfo, true); |
|
|
|
firmwareInfo.setUrl(""); |
|
|
|
otaPackageService.saveOtaPackageInfo(firmwareInfo, true); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testSaveOtaPackageUrlCantBeUpdated() { |
|
|
|
OtaPackageInfo firmwareInfo = new OtaPackageInfo(); |
|
|
|
firmwareInfo.setDeviceProfileId(deviceProfileId); |
|
|
|
firmwareInfo.setType(FIRMWARE); |
|
|
|
firmwareInfo.setTitle(TITLE); |
|
|
|
firmwareInfo.setVersion(VERSION); |
|
|
|
firmwareInfo.setUrl(URL); |
|
|
|
firmwareInfo.setTenantId(tenantId); |
|
|
|
|
|
|
|
OtaPackageInfo savedFirmwareInfo = otaPackageService.saveOtaPackageInfo(firmwareInfo, true); |
|
|
|
|
|
|
|
thrown.expect(DataValidationException.class); |
|
|
|
thrown.expectMessage("Updating otaPackage URL is prohibited!"); |
|
|
|
|
|
|
|
savedFirmwareInfo.setUrl("https://newurl.com"); |
|
|
|
otaPackageService.saveOtaPackageInfo(savedFirmwareInfo, true); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testSaveOtaPackageCantViolateSizeOfTitle() { |
|
|
|
OtaPackageInfo firmwareInfo = new OtaPackageInfo(); |
|
|
|
firmwareInfo.setDeviceProfileId(deviceProfileId); |
|
|
|
firmwareInfo.setType(FIRMWARE); |
|
|
|
firmwareInfo.setTitle(RandomStringUtils.random(257)); |
|
|
|
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); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testSaveOtaPackageCantViolateSizeOfVersion() { |
|
|
|
OtaPackageInfo firmwareInfo = new OtaPackageInfo(); |
|
|
|
firmwareInfo.setDeviceProfileId(deviceProfileId); |
|
|
|
firmwareInfo.setType(FIRMWARE); |
|
|
|
firmwareInfo.setUrl(URL); |
|
|
|
firmwareInfo.setTenantId(tenantId); |
|
|
|
firmwareInfo.setTitle(TITLE); |
|
|
|
|
|
|
|
firmwareInfo.setVersion(RandomStringUtils.random(257)); |
|
|
|
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); |
|
|
|
@ -642,5 +708,4 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest { |
|
|
|
firmware.setDataSize(DATA_SIZE); |
|
|
|
return otaPackageService.saveOtaPackage(firmware); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|