From a7830379c1e7df68bbfdccffd6996fb8d78e3b80 Mon Sep 17 00:00:00 2001 From: Avgustin Marinov Date: Fri, 20 Dec 2024 12:21:47 +0200 Subject: [PATCH] Hibernate versioning made to start from 1 to be EclipseLink compatible (#2156) Signed-off-by: Avgustin Marinov --- .../AbstractManagementApiIntegrationTest.java | 9 ------- .../MgmtDistributionSetTypeResourceTest.java | 6 ++--- .../resource/MgmtTargetTypeResourceTest.java | 10 ++++---- .../jpa/model/AbstractJpaBaseEntity.java | 2 +- .../jpa/AbstractJpaIntegrationTest.java | 8 ------- .../DistributionSetManagementTest.java | 6 ++--- .../SoftwareModuleManagementTest.java | 10 ++++---- .../jpa/management/TargetManagementTest.java | 24 +++++++++---------- .../management/TargetTagManagementTest.java | 2 +- 9 files changed, 30 insertions(+), 47 deletions(-) diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/AbstractManagementApiIntegrationTest.java b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/AbstractManagementApiIntegrationTest.java index c23ae29e90..afd5840bca 100644 --- a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/AbstractManagementApiIntegrationTest.java +++ b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/AbstractManagementApiIntegrationTest.java @@ -15,7 +15,6 @@ import lombok.SneakyThrows; import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtActionType; -import org.eclipse.hawkbit.repository.jpa.Jpa; import org.eclipse.hawkbit.repository.jpa.RepositoryApplicationConfiguration; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; import org.eclipse.hawkbit.repository.model.BaseEntity; @@ -205,12 +204,4 @@ static void implicitLock(final DistributionSet set) { ((JpaDistributionSet) set).lock(); } } - - // version is 1, 2 ... based - protected int version(final int version) { - return switch (Jpa.JPA_VENDOR) { - case ECLIPSELINK -> version; - case HIBERNATE -> version - 1; - }; - } } \ No newline at end of file diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResourceTest.java b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResourceTest.java index c5328b3cde..a152027dcb 100644 --- a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResourceTest.java +++ b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResourceTest.java @@ -214,7 +214,7 @@ void assignModuleTypesToDistributionSetTypeUntilQuotaExceeded() throws Exception final DistributionSetType testType = distributionSetTypeManagement.create(entityFactory.distributionSetType() .create().key("testType").name("testType").description("testType").colour("col12")); - assertThat(testType.getOptLockRevision()).isEqualTo(version(1)); + assertThat(testType.getOptLockRevision()).isEqualTo(1); for (int i = 0; i < moduleTypeIds.size() - 1; ++i) { mvc.perform(post("/rest/v1/distributionsettypes/{dstID}/optionalmoduletypes", testType.getId()) @@ -235,7 +235,7 @@ void assignModuleTypesToDistributionSetTypeUntilQuotaExceeded() throws Exception final DistributionSetType testType2 = distributionSetTypeManagement.create(entityFactory.distributionSetType() .create().key("testType2").name("testType2").description("testType2").colour("col12")); - assertThat(testType2.getOptLockRevision()).isEqualTo(version(1)); + assertThat(testType2.getOptLockRevision()).isEqualTo(1); for (int i = 0; i < moduleTypeIds.size() - 1; ++i) { mvc.perform(post("/rest/v1/distributionsettypes/{dstID}/mandatorymoduletypes", testType2.getId()) @@ -741,7 +741,7 @@ private DistributionSetType generateTestType() { final DistributionSetType testType = distributionSetTypeManagement.create(entityFactory.distributionSetType() .create().key("test123").name("TestName123").description("Desc123").colour("col") .mandatory(Collections.singletonList(osType.getId())).optional(Collections.singletonList(appType.getId()))); - assertThat(testType.getOptLockRevision()).isEqualTo(version(1)); + assertThat(testType.getOptLockRevision()).isEqualTo(1); assertThat(testType.getOptionalModuleTypes()).containsExactly(appType); assertThat(testType.getMandatoryModuleTypes()).containsExactly(osType); return testType; diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTypeResourceTest.java b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTypeResourceTest.java index e3016b9e79..3b5999b68a 100644 --- a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTypeResourceTest.java +++ b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTypeResourceTest.java @@ -321,7 +321,7 @@ void createTargetTypes() throws Exception { void addDistributionSetTypeToTargetType() throws Exception { String typeName = "TestTypeAddDs"; TargetType testType = createTestTargetTypeInDB(typeName); - assertThat(testType.getOptLockRevision()).isEqualTo(version(1)); + assertThat(testType.getOptLockRevision()).isEqualTo(1); mvc.perform(post(TARGETTYPE_DSTYPES_ENDPOINT, testType.getId()) .content("[{\"id\":" + standardDsType.getId() + "}]").contentType(MediaType.APPLICATION_JSON)) @@ -330,7 +330,7 @@ void addDistributionSetTypeToTargetType() throws Exception { testType = targetTypeManagement.get(testType.getId()).get(); assertThat(testType.getLastModifiedBy()).isEqualTo(TEST_USER); - assertThat(testType.getOptLockRevision()).isEqualTo(version(2)); + assertThat(testType.getOptLockRevision()).isEqualTo(2); assertThat(testType.getCompatibleDistributionSetTypes()).containsExactly(standardDsType); } @@ -380,7 +380,7 @@ void removeDsTypeFromTargetType() throws Exception { testType = targetTypeManagement.get(testType.getId()).get(); assertThat(testType.getLastModifiedBy()).isEqualTo(TEST_USER); - assertThat(testType.getOptLockRevision()).isEqualTo(version(2)); + assertThat(testType.getOptLockRevision()).isEqualTo(2); assertThat(testType.getCompatibleDistributionSetTypes()).isEmpty(); } @@ -398,7 +398,7 @@ void deletingDsTypeRemovesAssignmentFromTargetType() throws Exception { testType = targetTypeManagement.get(testType.getId()).get(); assertThat(testType.getLastModifiedBy()).isEqualTo(TEST_USER); - assertThat(testType.getOptLockRevision()).isEqualTo(version(2)); + assertThat(testType.getOptLockRevision()).isEqualTo(2); assertThat(testType.getCompatibleDistributionSetTypes()).isEmpty(); assertThat(distributionSetTypeManagement.getByKey(standardDsType.getKey())).isEmpty(); } @@ -641,7 +641,7 @@ private TargetType createTestTargetTypeInDB(String name) { @Step private TargetType createTestTargetTypeInDB(String name, List dsTypes) { TargetType targetType = testdataFactory.createTargetType(name, dsTypes); - assertThat(targetType.getOptLockRevision()).isEqualTo(version(1)); + assertThat(targetType.getOptLockRevision()).isEqualTo(1); return targetType; } diff --git a/hawkbit-repository/hawkbit-repository-jpa-hibernate/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaBaseEntity.java b/hawkbit-repository/hawkbit-repository-jpa-hibernate/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaBaseEntity.java index d358430678..7d0d673457 100644 --- a/hawkbit-repository/hawkbit-repository-jpa-hibernate/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaBaseEntity.java +++ b/hawkbit-repository/hawkbit-repository-jpa-hibernate/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaBaseEntity.java @@ -54,7 +54,7 @@ public abstract class AbstractJpaBaseEntity extends AbstractBaseEntity { @Getter @Version @Column(name = "optlock_revision") - private int optLockRevision; + private int optLockRevision = 1; // Audit fields. use property access to ensure that setters will be called and checked for modification // (touch implementation depends on setLastModifiedAt(1). diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTest.java index b59f26fc89..9a33414869 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTest.java @@ -244,14 +244,6 @@ protected JpaRolloutGroup refresh(final RolloutGroup group) { return rolloutGroupRepository.findById(group.getId()).get(); } - // version is 1, 2 ... based - protected int version(final int version) { - return switch (Jpa.JPA_VENDOR) { - case ECLIPSELINK -> version; - case HIBERNATE -> version - 1; - }; - } - private JpaRollout refresh(final Rollout rollout) { return rolloutRepository.findById(rollout.getId()).get(); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/DistributionSetManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/DistributionSetManagementTest.java index d9f15f9677..7912b7eba7 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/DistributionSetManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/DistributionSetManagementTest.java @@ -505,13 +505,13 @@ void updateDistributionSetMetadata() { // create a DS final DistributionSet ds = testdataFactory.createDistributionSet("testDs"); // initial opt lock revision must be zero - assertThat(ds.getOptLockRevision()).isEqualTo(version(1)); + assertThat(ds.getOptLockRevision()).isEqualTo(1); // create an DS meta data entry createDistributionSetMetadata(ds.getId(), new JpaDistributionSetMetadata(knownKey, ds, knownValue)); final DistributionSet changedLockRevisionDS = getOrThrow(distributionSetManagement.get(ds.getId())); - assertThat(changedLockRevisionDS.getOptLockRevision()).isEqualTo(version(2)); + assertThat(changedLockRevisionDS.getOptLockRevision()).isEqualTo(2); // update the DS metadata final JpaDistributionSetMetadata updated = (JpaDistributionSetMetadata) distributionSetManagement @@ -519,7 +519,7 @@ void updateDistributionSetMetadata() { // we are updating the sw metadata so also modifying the base software // module so opt lock revision must be three final DistributionSet reloadedDS = getOrThrow(distributionSetManagement.get(ds.getId())); - assertThat(reloadedDS.getOptLockRevision()).isEqualTo(version(3)); + assertThat(reloadedDS.getOptLockRevision()).isEqualTo(3); assertThat(reloadedDS.getLastModifiedAt()).isPositive(); // verify updated meta data contains the updated value diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/SoftwareModuleManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/SoftwareModuleManagementTest.java index 20e7a367ab..4034da51da 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/SoftwareModuleManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/SoftwareModuleManagementTest.java @@ -499,7 +499,7 @@ void createSoftwareModuleMetadata() { final SoftwareModule ah = testdataFactory.createSoftwareModuleApp(); - assertThat(ah.getOptLockRevision()).isEqualTo(version(1)); + assertThat(ah.getOptLockRevision()).isEqualTo(1); final SoftwareModuleMetadataCreate swMetadata1 = entityFactory.softwareModuleMetadata().create(ah.getId()) .key(knownKey1).value(knownValue1); @@ -511,7 +511,7 @@ void createSoftwareModuleMetadata() { .createMetaData(Arrays.asList(swMetadata1, swMetadata2)); final SoftwareModule changedLockRevisionModule = softwareModuleManagement.get(ah.getId()).get(); - assertThat(changedLockRevisionModule.getOptLockRevision()).isEqualTo(version(2)); + assertThat(changedLockRevisionModule.getOptLockRevision()).isEqualTo(2); assertThat(softwareModuleMetadata).hasSize(2); assertThat(softwareModuleMetadata.get(0)).isNotNull(); @@ -604,7 +604,7 @@ void updateSoftwareModuleMetadata() { // create a base software module final SoftwareModule ah = testdataFactory.createSoftwareModuleApp(); // initial opt lock revision must be 1 - assertThat(ah.getOptLockRevision()).isEqualTo(version(1)); + assertThat(ah.getOptLockRevision()).isEqualTo(1); // create an software module meta data entry final SoftwareModuleMetadata softwareModuleMetadata = softwareModuleManagement.createMetaData( @@ -615,7 +615,7 @@ void updateSoftwareModuleMetadata() { // base software module should have now the opt lock revision one // because we are modifying the base software module SoftwareModule changedLockRevisionModule = softwareModuleManagement.get(ah.getId()).get(); - assertThat(changedLockRevisionModule.getOptLockRevision()).isEqualTo(version(2)); + assertThat(changedLockRevisionModule.getOptLockRevision()).isEqualTo(2); // update the software module metadata final SoftwareModuleMetadata updated = softwareModuleManagement.updateMetaData(entityFactory @@ -624,7 +624,7 @@ void updateSoftwareModuleMetadata() { // we are updating the sw metadata so also modifying the base software // module so opt lock revision must be two changedLockRevisionModule = softwareModuleManagement.get(ah.getId()).get(); - assertThat(changedLockRevisionModule.getOptLockRevision()).isEqualTo(version(3)); + assertThat(changedLockRevisionModule.getOptLockRevision()).isEqualTo(3); // verify updated meta data contains the updated value assertThat(updated).isNotNull(); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/TargetManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/TargetManagementTest.java index 3dfea5da92..662916bcd5 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/TargetManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/TargetManagementTest.java @@ -840,14 +840,14 @@ void updateTargetMetadata() throws InterruptedException { // create a target final Target target = testdataFactory.createTarget("target1"); // initial opt lock revision must be zero - assertThat(target.getOptLockRevision()).isEqualTo(version(1)); + assertThat(target.getOptLockRevision()).isEqualTo(1); // create target meta data entry insertTargetMetadata(knownKey, knownValue, target); Target changedLockRevisionTarget = targetManagement.get(target.getId()) .orElseThrow(NoSuchElementException::new); - assertThat(changedLockRevisionTarget.getOptLockRevision()).isEqualTo(version(2)); + assertThat(changedLockRevisionTarget.getOptLockRevision()).isEqualTo(2); // Unsure if needed maybe to wait for a db flush? // Thread.sleep(100); @@ -858,7 +858,7 @@ void updateTargetMetadata() throws InterruptedException { // we are updating the target meta data so also modifying the base // software module so opt lock revision must be three changedLockRevisionTarget = targetManagement.get(target.getId()).orElseThrow(NoSuchElementException::new); - assertThat(changedLockRevisionTarget.getOptLockRevision()).isEqualTo(version(3)); + assertThat(changedLockRevisionTarget.getOptLockRevision()).isEqualTo(3); assertThat(changedLockRevisionTarget.getLastModifiedAt()).isPositive(); // verify updated meta data contains the updated value @@ -881,7 +881,7 @@ void createAndUpdateTargetTypeInTarget() { // initial opt lock revision must be one final Optional targetFound = targetRepository.findById(target.getId()); assertThat(targetFound).isPresent(); - assertThat(targetFound.get().getOptLockRevision()).isEqualTo(version(1)); + assertThat(targetFound.get().getOptLockRevision()).isEqualTo(1); assertThat(targetFound.get().getTargetType().getId()).isEqualTo(targetTypes.get(0).getId()); // update the target type @@ -892,7 +892,7 @@ void createAndUpdateTargetTypeInTarget() { // opt lock revision must be changed final Optional targetFound1 = targetRepository.findById(target.getId()); assertThat(targetFound1).isPresent(); - assertThat(targetFound1.get().getOptLockRevision()).isEqualTo(version(2)); + assertThat(targetFound1.get().getOptLockRevision()).isEqualTo(2); assertThat(targetFound1.get().getTargetType().getId()).isEqualTo(targetTypes.get(1).getId()); // unassign the target type @@ -901,7 +901,7 @@ void createAndUpdateTargetTypeInTarget() { // opt lock revision must be changed final Optional targetFound2 = targetRepository.findById(target.getId()); assertThat(targetFound2).isPresent(); - assertThat(targetFound2.get().getOptLockRevision()).isEqualTo(version(3)); + assertThat(targetFound2.get().getOptLockRevision()).isEqualTo(3); assertThat(targetFound2.get().getTargetType()).isNull(); } @@ -914,7 +914,7 @@ void assignTargetTypeInTarget() { // initial opt lock revision must be one final Optional targetFound = targetRepository.findById(target.getId()); assertThat(targetFound).isPresent(); - assertThat(targetFound.get().getOptLockRevision()).isEqualTo(version(1)); + assertThat(targetFound.get().getOptLockRevision()).isEqualTo(1); assertThat(targetFound.get().getTargetType()).isNull(); // create a target type @@ -927,7 +927,7 @@ void assignTargetTypeInTarget() { // opt lock revision must be changed final Optional targetFound1 = targetRepository.findById(target.getId()); assertThat(targetFound1).isPresent(); - assertThat(targetFound1.get().getOptLockRevision()).isEqualTo(version(2)); + assertThat(targetFound1.get().getOptLockRevision()).isEqualTo(2); assertThat(targetFound1.get().getTargetType().getId()).isEqualTo(targetType.getId()); } @@ -1003,7 +1003,7 @@ void assignInvalidTargetTypeToTarget() { // initial opt lock revision must be one final Optional targetFound = targetRepository.findById(target.getId()); assertThat(targetFound).isPresent(); - assertThat(targetFound.get().getOptLockRevision()).isEqualTo(version(1)); + assertThat(targetFound.get().getOptLockRevision()).isEqualTo(1); assertThat(targetFound.get().getTargetType()).isNull(); // assign target type to target @@ -1017,7 +1017,7 @@ void assignInvalidTargetTypeToTarget() { // opt lock revision is not changed final Optional targetFound1 = targetRepository.findById(target.getId()); assertThat(targetFound1).isPresent(); - assertThat(targetFound1.get().getOptLockRevision()).isEqualTo(version(1)); + assertThat(targetFound1.get().getOptLockRevision()).isEqualTo(1); } @Test @@ -1032,7 +1032,7 @@ void unAssignTargetTypeFromTarget() { // initial opt lock revision must be one final Optional targetFound = targetRepository.findById(target.getId()); assertThat(targetFound).isPresent(); - assertThat(targetFound.get().getOptLockRevision()).isEqualTo(version(1)); + assertThat(targetFound.get().getOptLockRevision()).isEqualTo(1); assertThat(targetFound.get().getTargetType().getName()).isEqualTo(targetType.getName()); // un-assign target type from target @@ -1041,7 +1041,7 @@ void unAssignTargetTypeFromTarget() { // opt lock revision must be changed final Optional targetFound1 = targetRepository.findById(target.getId()); assertThat(targetFound1).isPresent(); - assertThat(targetFound1.get().getOptLockRevision()).isEqualTo(version(2)); + assertThat(targetFound1.get().getOptLockRevision()).isEqualTo(2); assertThat(targetFound1.get().getTargetType()).isNull(); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/TargetTagManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/TargetTagManagementTest.java index 716ab0b2b8..9d3c3725dd 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/TargetTagManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/TargetTagManagementTest.java @@ -215,7 +215,7 @@ void updateTargetTag() { .isEqualTo("test123"); assertThat(targetTagRepository.findById(savedAssigned.getId()).get().getOptLockRevision()) .as("wrong target tag is saved") - .isEqualTo(version(2)); + .isEqualTo(2); } @Test