|
|
|
@ -19,9 +19,7 @@ import com.datastax.oss.driver.api.core.uuid.Uuids; |
|
|
|
import org.junit.After; |
|
|
|
import org.junit.Assert; |
|
|
|
import org.junit.Before; |
|
|
|
import org.junit.Rule; |
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.rules.ExpectedException; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.thingsboard.common.util.JacksonUtil; |
|
|
|
import org.thingsboard.server.common.data.Device; |
|
|
|
@ -48,6 +46,7 @@ import java.util.Collections; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
import static org.assertj.core.api.Assertions.assertThatThrownBy; |
|
|
|
import static org.thingsboard.server.common.data.ota.OtaPackageType.FIRMWARE; |
|
|
|
|
|
|
|
public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest { |
|
|
|
@ -83,10 +82,6 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest { |
|
|
|
deviceProfileId = savedDeviceProfile.getId(); |
|
|
|
} |
|
|
|
|
|
|
|
@SuppressWarnings("deprecation") |
|
|
|
@Rule |
|
|
|
public ExpectedException thrown = ExpectedException.none(); |
|
|
|
|
|
|
|
@After |
|
|
|
public void after() { |
|
|
|
tenantService.deleteTenant(tenantId); |
|
|
|
@ -104,9 +99,9 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest { |
|
|
|
createAndSaveFirmware(tenantId, "1"); |
|
|
|
Assert.assertEquals(1, otaPackageService.sumDataSizeByTenantId(tenantId)); |
|
|
|
|
|
|
|
thrown.expect(DataValidationException.class); |
|
|
|
thrown.expectMessage(String.format("Failed to create the ota package, files size limit is exhausted %d bytes!", DATA_SIZE)); |
|
|
|
createAndSaveFirmware(tenantId, "2"); |
|
|
|
assertThatThrownBy(() -> createAndSaveFirmware(tenantId, "2")) |
|
|
|
.isInstanceOf(DataValidationException.class) |
|
|
|
.hasMessageContaining("Failed to create the ota package, files size limit is exhausted %d bytes!", DATA_SIZE); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@ -248,9 +243,9 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest { |
|
|
|
firmware.setChecksum(CHECKSUM); |
|
|
|
firmware.setData(DATA); |
|
|
|
|
|
|
|
thrown.expect(DataValidationException.class); |
|
|
|
thrown.expectMessage("OtaPackage should be assigned to tenant!"); |
|
|
|
otaPackageService.saveOtaPackage(firmware); |
|
|
|
assertThatThrownBy(() -> otaPackageService.saveOtaPackage(firmware)) |
|
|
|
.isInstanceOf(DataValidationException.class) |
|
|
|
.hasMessageContaining("OtaPackage should be assigned to tenant!"); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@ -266,9 +261,9 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest { |
|
|
|
firmware.setChecksum(CHECKSUM); |
|
|
|
firmware.setData(DATA); |
|
|
|
|
|
|
|
thrown.expect(DataValidationException.class); |
|
|
|
thrown.expectMessage("Type should be specified!"); |
|
|
|
otaPackageService.saveOtaPackage(firmware); |
|
|
|
assertThatThrownBy(() -> otaPackageService.saveOtaPackage(firmware)) |
|
|
|
.isInstanceOf(DataValidationException.class) |
|
|
|
.hasMessageContaining("Type should be specified!"); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@ -284,9 +279,9 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest { |
|
|
|
firmware.setChecksum(CHECKSUM); |
|
|
|
firmware.setData(DATA); |
|
|
|
|
|
|
|
thrown.expect(DataValidationException.class); |
|
|
|
thrown.expectMessage("OtaPackage title should be specified!"); |
|
|
|
otaPackageService.saveOtaPackage(firmware); |
|
|
|
assertThatThrownBy(() -> otaPackageService.saveOtaPackage(firmware)) |
|
|
|
.isInstanceOf(DataValidationException.class) |
|
|
|
.hasMessageContaining("OtaPackage title should be specified!"); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@ -302,9 +297,9 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest { |
|
|
|
firmware.setChecksum(CHECKSUM); |
|
|
|
firmware.setData(DATA); |
|
|
|
|
|
|
|
thrown.expect(DataValidationException.class); |
|
|
|
thrown.expectMessage("OtaPackage file name should be specified!"); |
|
|
|
otaPackageService.saveOtaPackage(firmware); |
|
|
|
assertThatThrownBy(() -> otaPackageService.saveOtaPackage(firmware)) |
|
|
|
.isInstanceOf(DataValidationException.class) |
|
|
|
.hasMessageContaining("OtaPackage file name should be specified!"); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@ -320,9 +315,9 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest { |
|
|
|
firmware.setChecksum(CHECKSUM); |
|
|
|
firmware.setData(DATA); |
|
|
|
|
|
|
|
thrown.expect(DataValidationException.class); |
|
|
|
thrown.expectMessage("OtaPackage content type should be specified!"); |
|
|
|
otaPackageService.saveOtaPackage(firmware); |
|
|
|
assertThatThrownBy(() -> otaPackageService.saveOtaPackage(firmware)) |
|
|
|
.isInstanceOf(DataValidationException.class) |
|
|
|
.hasMessageContaining("OtaPackage content type should be specified!"); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@ -338,9 +333,9 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest { |
|
|
|
firmware.setChecksumAlgorithm(CHECKSUM_ALGORITHM); |
|
|
|
firmware.setChecksum(CHECKSUM); |
|
|
|
|
|
|
|
thrown.expect(DataValidationException.class); |
|
|
|
thrown.expectMessage("OtaPackage data should be specified!"); |
|
|
|
otaPackageService.saveOtaPackage(firmware); |
|
|
|
assertThatThrownBy(() -> otaPackageService.saveOtaPackage(firmware)) |
|
|
|
.isInstanceOf(DataValidationException.class) |
|
|
|
.hasMessageContaining("OtaPackage data should be specified!"); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@ -357,9 +352,9 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest { |
|
|
|
firmware.setChecksum(CHECKSUM); |
|
|
|
firmware.setData(DATA); |
|
|
|
|
|
|
|
thrown.expect(DataValidationException.class); |
|
|
|
thrown.expectMessage("OtaPackage is referencing to non-existent tenant!"); |
|
|
|
otaPackageService.saveOtaPackage(firmware); |
|
|
|
assertThatThrownBy(() -> otaPackageService.saveOtaPackage(firmware)) |
|
|
|
.isInstanceOf(DataValidationException.class) |
|
|
|
.hasMessageContaining("OtaPackage is referencing to non-existent tenant!"); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@ -376,9 +371,9 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest { |
|
|
|
firmware.setChecksum(CHECKSUM); |
|
|
|
firmware.setData(DATA); |
|
|
|
|
|
|
|
thrown.expect(DataValidationException.class); |
|
|
|
thrown.expectMessage("OtaPackage is referencing to non-existent device profile!"); |
|
|
|
otaPackageService.saveOtaPackage(firmware); |
|
|
|
assertThatThrownBy(() -> otaPackageService.saveOtaPackage(firmware)) |
|
|
|
.isInstanceOf(DataValidationException.class) |
|
|
|
.hasMessageContaining("OtaPackage is referencing to non-existent device profile!"); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@ -394,9 +389,9 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest { |
|
|
|
firmware.setChecksumAlgorithm(CHECKSUM_ALGORITHM); |
|
|
|
firmware.setData(DATA); |
|
|
|
|
|
|
|
thrown.expect(DataValidationException.class); |
|
|
|
thrown.expectMessage("OtaPackage checksum should be specified!"); |
|
|
|
otaPackageService.saveOtaPackage(firmware); |
|
|
|
assertThatThrownBy(() -> otaPackageService.saveOtaPackage(firmware)) |
|
|
|
.isInstanceOf(DataValidationException.class) |
|
|
|
.hasMessageContaining("OtaPackage checksum should be specified!"); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@ -416,17 +411,17 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest { |
|
|
|
newFirmwareInfo.setTitle(TITLE); |
|
|
|
newFirmwareInfo.setVersion(VERSION); |
|
|
|
|
|
|
|
thrown.expect(DataValidationException.class); |
|
|
|
thrown.expectMessage("OtaPackage with such title and version already exists!"); |
|
|
|
otaPackageService.saveOtaPackageInfo(newFirmwareInfo, false); |
|
|
|
assertThatThrownBy(() -> otaPackageService.saveOtaPackageInfo(newFirmwareInfo, false)) |
|
|
|
.isInstanceOf(DataValidationException.class) |
|
|
|
.hasMessageContaining("OtaPackage with such title and version already exists!"); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testSaveFirmwareWithExistingTitleAndVersion() { |
|
|
|
createAndSaveFirmware(tenantId, VERSION); |
|
|
|
thrown.expect(DataValidationException.class); |
|
|
|
thrown.expectMessage("OtaPackage with such title and version already exists!"); |
|
|
|
createAndSaveFirmware(tenantId, VERSION); |
|
|
|
assertThatThrownBy(() -> createAndSaveFirmware(tenantId, VERSION)) |
|
|
|
.isInstanceOf(DataValidationException.class) |
|
|
|
.hasMessageContaining("OtaPackage with such title and version already exists!"); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@ -441,9 +436,9 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest { |
|
|
|
Device savedDevice = deviceService.saveDevice(device); |
|
|
|
|
|
|
|
try { |
|
|
|
thrown.expect(DataValidationException.class); |
|
|
|
thrown.expectMessage("The otaPackage referenced by the devices cannot be deleted!"); |
|
|
|
otaPackageService.deleteOtaPackage(tenantId, savedFirmware.getId()); |
|
|
|
assertThatThrownBy(() -> otaPackageService.deleteOtaPackage(tenantId, savedFirmware.getId())) |
|
|
|
.isInstanceOf(DataValidationException.class) |
|
|
|
.hasMessageContaining("The otaPackage referenced by the devices cannot be deleted!"); |
|
|
|
} finally { |
|
|
|
deviceService.deleteDevice(tenantId, savedDevice.getId()); |
|
|
|
otaPackageService.deleteOtaPackage(tenantId, savedFirmware.getId()); |
|
|
|
@ -453,12 +448,12 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest { |
|
|
|
@Test |
|
|
|
public void testUpdateDeviceProfileId() { |
|
|
|
OtaPackage savedFirmware = createAndSaveFirmware(tenantId, VERSION); |
|
|
|
savedFirmware.setDeviceProfileId(null); |
|
|
|
|
|
|
|
try { |
|
|
|
thrown.expect(DataValidationException.class); |
|
|
|
thrown.expectMessage("Updating otaPackage deviceProfile is prohibited!"); |
|
|
|
savedFirmware.setDeviceProfileId(null); |
|
|
|
otaPackageService.saveOtaPackage(savedFirmware); |
|
|
|
assertThatThrownBy(() -> otaPackageService.saveOtaPackage(savedFirmware)) |
|
|
|
.isInstanceOf(DataValidationException.class) |
|
|
|
.hasMessageContaining("Updating otaPackage deviceProfile is prohibited!"); |
|
|
|
} finally { |
|
|
|
otaPackageService.deleteOtaPackage(tenantId, savedFirmware.getId()); |
|
|
|
} |
|
|
|
@ -487,9 +482,9 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest { |
|
|
|
deviceProfileService.saveDeviceProfile(savedDeviceProfile); |
|
|
|
|
|
|
|
try { |
|
|
|
thrown.expect(DataValidationException.class); |
|
|
|
thrown.expectMessage("The otaPackage referenced by the device profile cannot be deleted!"); |
|
|
|
otaPackageService.deleteOtaPackage(tenantId, savedFirmware.getId()); |
|
|
|
assertThatThrownBy(() -> otaPackageService.deleteOtaPackage(tenantId, savedFirmware.getId())) |
|
|
|
.isInstanceOf(DataValidationException.class) |
|
|
|
.hasMessageContaining("The otaPackage referenced by the device profile cannot be deleted!"); |
|
|
|
} finally { |
|
|
|
deviceProfileService.deleteDeviceProfile(tenantId, savedDeviceProfile.getId()); |
|
|
|
} |
|
|
|
@ -641,12 +636,18 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest { |
|
|
|
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); |
|
|
|
assertThatThrownBy(() -> otaPackageService.saveOtaPackageInfo(firmwareInfo, true)) |
|
|
|
.as("firmwareInfo url set whitespaces") |
|
|
|
.isInstanceOf(DataValidationException.class) |
|
|
|
.hasMessageContaining("Ota package URL should be specified!"); |
|
|
|
|
|
|
|
firmwareInfo.setUrl(""); |
|
|
|
otaPackageService.saveOtaPackageInfo(firmwareInfo, true); |
|
|
|
assertThatThrownBy(() -> otaPackageService.saveOtaPackageInfo(firmwareInfo, true)) |
|
|
|
.as("firmwareInfo url is empty") |
|
|
|
.isInstanceOf(DataValidationException.class) |
|
|
|
.hasMessageContaining("Ota package URL should be specified!"); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@ -660,12 +661,10 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest { |
|
|
|
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); |
|
|
|
assertThatThrownBy(() -> otaPackageService.saveOtaPackageInfo(savedFirmwareInfo, true)) |
|
|
|
.isInstanceOf(DataValidationException.class) |
|
|
|
.hasMessageContaining("Updating otaPackage URL is prohibited!"); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@ -678,10 +677,9 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest { |
|
|
|
firmwareInfo.setUrl(URL); |
|
|
|
firmwareInfo.setTenantId(tenantId); |
|
|
|
|
|
|
|
thrown.expect(DataValidationException.class); |
|
|
|
thrown.expectMessage("title length must be equal or less than 255"); |
|
|
|
|
|
|
|
otaPackageService.saveOtaPackageInfo(firmwareInfo, true); |
|
|
|
assertThatThrownBy(() -> otaPackageService.saveOtaPackageInfo(firmwareInfo, true)) |
|
|
|
.isInstanceOf(DataValidationException.class) |
|
|
|
.hasMessageContaining("title length must be equal or less than 255"); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@ -692,11 +690,11 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest { |
|
|
|
firmwareInfo.setUrl(URL); |
|
|
|
firmwareInfo.setTenantId(tenantId); |
|
|
|
firmwareInfo.setTitle(TITLE); |
|
|
|
|
|
|
|
firmwareInfo.setVersion(StringUtils.random(257)); |
|
|
|
thrown.expectMessage("version length must be equal or less than 255"); |
|
|
|
|
|
|
|
otaPackageService.saveOtaPackageInfo(firmwareInfo, true); |
|
|
|
assertThatThrownBy(() -> otaPackageService.saveOtaPackageInfo(firmwareInfo, true)) |
|
|
|
.isInstanceOf(DataValidationException.class) |
|
|
|
.hasMessageContaining("version length must be equal or less than 255"); |
|
|
|
} |
|
|
|
|
|
|
|
private OtaPackage createAndSaveFirmware(TenantId tenantId, String version) { |
|
|
|
|