From 71ec0a588a402faa0a644cd5a7e5c617b354c56f Mon Sep 17 00:00:00 2001 From: Andrii Landiak Date: Wed, 25 Jun 2025 11:34:17 +0300 Subject: [PATCH] Fix test to use profile with ota on import --- .../service/sync/vc/VersionControlTest.java | 25 +++++++++++-------- .../data/sync/ie/OtaPackageExportData.java | 4 +++ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/application/src/test/java/org/thingsboard/server/service/sync/vc/VersionControlTest.java b/application/src/test/java/org/thingsboard/server/service/sync/vc/VersionControlTest.java index 5c5b7bb107..461ca5a2ec 100644 --- a/application/src/test/java/org/thingsboard/server/service/sync/vc/VersionControlTest.java +++ b/application/src/test/java/org/thingsboard/server/service/sync/vc/VersionControlTest.java @@ -685,23 +685,28 @@ public class VersionControlTest extends AbstractControllerTest { } @Test - public void testOtaPackageVc_betweenTenants() throws Exception { + public void testOtaPackageVcWithProfile_betweenTenants() throws Exception { DeviceProfile deviceProfile = createDeviceProfile(null, null, "Device profile v1.0"); OtaPackage firmware = createOtaPackage(tenantId1, deviceProfile.getId(), OtaPackageType.FIRMWARE); OtaPackage software = createOtaPackage(tenantId1, deviceProfile.getId(), OtaPackageType.SOFTWARE); + deviceProfile.setFirmwareId(firmware.getId()); + deviceProfile.setSoftwareId(software.getId()); + deviceProfile = doPost("/api/deviceProfile", deviceProfile, DeviceProfile.class); String versionId = createVersion("ota packages", EntityType.DEVICE_PROFILE, EntityType.OTA_PACKAGE); - OtaPackage firmwareOta = findOtaPackage(firmware.getTitle()); - OtaPackage softwareOta = findOtaPackage(software.getTitle()); - loginTenant2(); loadVersion(versionId, EntityType.DEVICE_PROFILE, EntityType.OTA_PACKAGE); - OtaPackage importedFirmwareOta = findOtaPackage(firmwareOta.getTitle()); - OtaPackage importedSoftwareOta = findOtaPackage(softwareOta.getTitle()); - checkImportedEntity(tenantId1, firmwareOta, tenantId2, importedFirmwareOta); - checkImportedOtaPackageData(firmwareOta, importedFirmwareOta); - checkImportedEntity(tenantId1, softwareOta, tenantId2, importedSoftwareOta); - checkImportedOtaPackageData(softwareOta, importedSoftwareOta); + DeviceProfile importedProfile = findDeviceProfile(deviceProfile.getName()); + OtaPackage importedFirmwareOta = findOtaPackage(firmware.getTitle()); + OtaPackage importedSoftwareOta = findOtaPackage(software.getTitle()); + checkImportedEntity(tenantId1, deviceProfile, tenantId2, importedProfile); + checkImportedDeviceProfileData(deviceProfile, importedProfile); + checkImportedEntity(tenantId1, firmware, tenantId2, importedFirmwareOta); + checkImportedOtaPackageData(firmware, importedFirmwareOta); + checkImportedEntity(tenantId1, software, tenantId2, importedSoftwareOta); + checkImportedOtaPackageData(software, importedSoftwareOta); + assertThat(importedProfile.getFirmwareId()).isEqualTo(importedFirmwareOta.getId()); + assertThat(importedProfile.getSoftwareId()).isEqualTo(importedSoftwareOta.getId()); } protected void checkImportedOtaPackageData(OtaPackage otaPackage, OtaPackage importedOtaPackage) { diff --git a/common/data/src/main/java/org/thingsboard/server/common/data/sync/ie/OtaPackageExportData.java b/common/data/src/main/java/org/thingsboard/server/common/data/sync/ie/OtaPackageExportData.java index df12bb5b08..44e2f7857c 100644 --- a/common/data/src/main/java/org/thingsboard/server/common/data/sync/ie/OtaPackageExportData.java +++ b/common/data/src/main/java/org/thingsboard/server/common/data/sync/ie/OtaPackageExportData.java @@ -22,6 +22,10 @@ import org.thingsboard.server.common.data.OtaPackage; @EqualsAndHashCode(callSuper = true) public class OtaPackageExportData extends EntityExportData { + /* + * OtaPackage is not a versioned entity; its 'version' field is part of the domain model (not used for optimistic locking) + * We override both methods to ensure 'version' is not ignored during (de)serialization. + */ @JsonIgnoreProperties(value = {"tenantId", "createdTime"}, ignoreUnknown = true) @Override public OtaPackage getEntity() {