From 127728b89a3e4dde8bb983344617a3f9afde9862 Mon Sep 17 00:00:00 2001 From: Avgustin Marinov Date: Thu, 19 Dec 2024 11:19:20 +0200 Subject: [PATCH] Upgrades spring to 3.4.0 Signed-off-by: Avgustin Marinov --- ...uestOnHawkbitDefaultPortPostProcessor.java | 2 - .../AbstractManagementApiIntegrationTest.java | 3 + .../resource/MgmtBasicAuthResourceTest.java | 5 +- .../hawkbit/repository/EntityFactory.java | 3 +- .../hawkbit/repository/model/Artifact.java | 3 +- .../repository/jpa/JpaEntityFactory.java | 12 +--- .../jpa/management/JpaArtifactManagement.java | 2 +- .../OnlineDsAssignmentStrategy.java | 3 +- .../repository/jpa/model/JpaAction.java | 8 ++- .../repository/jpa/model/JpaArtifact.java | 7 ++- .../jpa/model/JpaAutoConfirmationStatus.java | 5 +- .../repository/jpa/model/JpaTarget.java | 22 +++++-- .../jpa/repository/ActionRepository.java | 2 +- .../repository/LocalArtifactRepository.java | 2 +- .../jpa/repository/TargetRepository.java | 15 ++--- .../autocleanup/AutoActionCleanupTest.java | 8 +-- .../management/ControllerManagementTest.java | 2 +- .../management/DeploymentManagementTest.java | 4 +- .../jpa/rsql/RSQLActionFieldsTest.java | 3 +- .../repository/jpa/rsql/RSQLUtilityTest.java | 63 ++++++++++--------- .../jpa/rsql/VirtualPropertyResolverTest.java | 23 +++---- pom.xml | 8 +-- 22 files changed, 109 insertions(+), 96 deletions(-) diff --git a/hawkbit-ddi/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/RequestOnHawkbitDefaultPortPostProcessor.java b/hawkbit-ddi/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/RequestOnHawkbitDefaultPortPostProcessor.java index 2c495902e0..dfd50e781e 100644 --- a/hawkbit-ddi/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/RequestOnHawkbitDefaultPortPostProcessor.java +++ b/hawkbit-ddi/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/RequestOnHawkbitDefaultPortPostProcessor.java @@ -11,13 +11,11 @@ import static org.eclipse.hawkbit.ddi.rest.resource.AbstractDDiApiIntegrationTest.HTTP_PORT; -import org.jetbrains.annotations.NotNull; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.test.web.servlet.request.RequestPostProcessor; public class RequestOnHawkbitDefaultPortPostProcessor implements RequestPostProcessor { - @NotNull @Override public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) { request.setRemotePort(HTTP_PORT); 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 fc56227f73..c23ae29e90 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 @@ -13,6 +13,7 @@ import static org.hamcrest.Matchers.equalTo; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +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; @@ -184,6 +185,7 @@ protected static ResultMatcher applySelfLinkMatcherOnSingleResult(final String l return mvcResult -> jsonPath("_links.self.href", equalTo(link)).match(mvcResult); } + @SneakyThrows protected static JSONObject getAssignmentObject(final Object id, final MgmtActionType type) { final JSONObject obj = new JSONObject(); obj.put("id", id); @@ -191,6 +193,7 @@ protected static JSONObject getAssignmentObject(final Object id, final MgmtActio return obj; } + @SneakyThrows protected static JSONObject getAssignmentObject(final Object id, final MgmtActionType type, final int weight) { return getAssignmentObject(id, type).put("weight", weight); } diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtBasicAuthResourceTest.java b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtBasicAuthResourceTest.java index 87876627ef..0a7d7602cd 100644 --- a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtBasicAuthResourceTest.java +++ b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtBasicAuthResourceTest.java @@ -15,6 +15,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import java.util.Base64; + import io.qameta.allure.Description; import io.qameta.allure.Feature; import io.qameta.allure.Story; @@ -46,7 +48,6 @@ import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder; import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import org.springframework.util.Base64Utils; import org.springframework.web.context.WebApplicationContext; /** @@ -105,7 +106,7 @@ public void validateBasicAuthFailsWithInvalidCredentials() throws Exception { } private String getBasicAuth(final String username, final String password) { - return "Basic " + Base64Utils.encodeToString((username + ":" + password).getBytes()); + return "Basic " + Base64.getEncoder().encodeToString((username + ":" + password).getBytes()); } private MockMvc withSecurityMock() throws Exception { diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/EntityFactory.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/EntityFactory.java index ac770392a7..1d94cb1374 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/EntityFactory.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/EntityFactory.java @@ -113,5 +113,4 @@ MetaData generateTargetMetadata(@Size(min = 1, max = MetaData.KEY_MAX_SIZE) @Not * @return {@link TargetFilterQueryBuilder} object */ TargetFilterQueryBuilder targetFilterQuery(); - -} +} \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Artifact.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Artifact.java index 1dc2b6fd28..91c40ec816 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Artifact.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Artifact.java @@ -48,5 +48,4 @@ public interface Artifact extends TenantAwareBaseEntity { * @return size of the artifact in bytes. */ long getSize(); - -} +} \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaEntityFactory.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaEntityFactory.java index 04f6bcf048..cdd8e125d3 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaEntityFactory.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaEntityFactory.java @@ -41,28 +41,21 @@ public class JpaEntityFactory implements EntityFactory { @Autowired private DistributionSetBuilder distributionSetBuilder; - @Autowired private TargetBuilder targetBuilder; - @Autowired private DistributionSetTypeBuilder distributionSetTypeBuilder; - @Autowired private SoftwareModuleBuilder softwareModuleBuilder; - @Autowired private RolloutBuilder rolloutBuilder; - @Autowired private TargetFilterQueryBuilder targetFilterQueryBuilder; - @Autowired private SoftwareModuleMetadataBuilder softwareModuleMetadataBuilder; - @Autowired private TargetTypeBuilder targetTypeBuilder; - + @Override public ActionStatusBuilder actionStatus() { return new JpaActionStatusBuilder(); @@ -132,5 +125,4 @@ public TargetTypeBuilder targetType() { public TargetFilterQueryBuilder targetFilterQuery() { return targetFilterQueryBuilder; } - -} +} \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaArtifactManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaArtifactManagement.java index c4c7f3653f..ba8fd54942 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaArtifactManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaArtifactManagement.java @@ -317,7 +317,7 @@ private Artifact storeArtifactMetadata(final SoftwareModule softwareModule, fina } artifact.setMd5Hash(result.getHashes().getMd5()); artifact.setSha256Hash(result.getHashes().getSha256()); - artifact.setSize(result.getSize()); + artifact.setFileSize(result.getSize()); log.debug("storing new artifact into repository {}", artifact); return localArtifactRepository.save(AccessController.Operation.CREATE, artifact); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/OnlineDsAssignmentStrategy.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/OnlineDsAssignmentStrategy.java index 81d87cac43..bf89264826 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/OnlineDsAssignmentStrategy.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/OnlineDsAssignmentStrategy.java @@ -132,8 +132,7 @@ public void setAssignedDistributionSetAndTargetStatus(final JpaDistributionSet s targetRepository.byIdsSpec(targetIdsChunk)) != targetIdsChunk.size()) { throw new InsufficientPermissionException("No update access to all targets!"); } - targetRepository.setAssignedDistributionSetAndUpdateStatus(TargetUpdateStatus.PENDING, - set, now, currentUser, targetIdsChunk); + targetRepository.setAssignedDistributionSetAndUpdateStatus(set, now, currentUser, TargetUpdateStatus.PENDING, targetIdsChunk); // TODO AC - current problem with this approach is that the caller detach the targets and seems doesn't save them // targetRepository.saveAll( // targetRepository diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaAction.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaAction.java index e1e75585d3..cfb9f605dd 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaAction.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaAction.java @@ -67,9 +67,11 @@ @NamedEntityGraphs({ @NamedEntityGraph(name = "Action.ds", attributeNodes = { @NamedAttributeNode("distributionSet") }), @NamedEntityGraph(name = "Action.all", attributeNodes = { - @NamedAttributeNode("distributionSet"), - @NamedAttributeNode(value = "target", subgraph = "target.ds") }, - subgraphs = @NamedSubgraph(name = "target.ds", attributeNodes = @NamedAttributeNode("assignedDistributionSet"))) + @NamedAttributeNode(value = "target", subgraph = "target.ds"), + @NamedAttributeNode("distributionSet") }, + subgraphs = @NamedSubgraph( + name = "target.ds", + attributeNodes = @NamedAttributeNode("assignedDistributionSet"))) }) @Entity // exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for sub entities diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaArtifact.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaArtifact.java index 33df233d5b..2854560c97 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaArtifact.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaArtifact.java @@ -75,7 +75,7 @@ public class JpaArtifact extends AbstractJpaTenantAwareBaseEntity implements Art private String sha256Hash; @Column(name = "file_size", updatable = false) - private long size; + private long fileSize; /** * Constructs artifact. @@ -90,4 +90,9 @@ public JpaArtifact(@NotEmpty final String sha1Hash, @NotNull final String filena this.softwareModule = (JpaSoftwareModule) softwareModule; this.softwareModule.addArtifact(this); } + + @Override + public long getSize() { + return getFileSize(); + } } \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaAutoConfirmationStatus.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaAutoConfirmationStatus.java index d20457173e..41fd1a051a 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaAutoConfirmationStatus.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaAutoConfirmationStatus.java @@ -15,7 +15,7 @@ import jakarta.persistence.FetchType; import jakarta.persistence.ForeignKey; import jakarta.persistence.JoinColumn; -import jakarta.persistence.OneToOne; +import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; import jakarta.validation.constraints.Size; @@ -33,7 +33,8 @@ @Table(name = "sp_target_conf_status") public class JpaAutoConfirmationStatus extends AbstractJpaTenantAwareBaseEntity implements AutoConfirmationStatus { - @OneToOne(optional = false, fetch = FetchType.LAZY) + // actually it is OneToOne - but lazy loading is not supported for OneToOne (at least for hibernate 6.6.2) + @ManyToOne(optional = false, fetch = FetchType.LAZY) @JoinColumn(name = "target_id", nullable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_target_auto_conf")) private JpaTarget target; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTarget.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTarget.java index eb155fdd48..80a6facad7 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTarget.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTarget.java @@ -35,7 +35,6 @@ import jakarta.persistence.ManyToOne; import jakarta.persistence.MapKeyColumn; import jakarta.persistence.OneToMany; -import jakarta.persistence.OneToOne; import jakarta.persistence.PrimaryKeyJoinColumn; import jakarta.persistence.Table; import jakarta.persistence.UniqueConstraint; @@ -65,6 +64,7 @@ import org.eclipse.hawkbit.repository.model.helper.SystemSecurityContextHolder; import org.eclipse.hawkbit.repository.model.helper.TenantConfigurationManagementHolder; import org.eclipse.hawkbit.security.SystemSecurityContext; +import org.springframework.util.ObjectUtils; /** * JPA implementation of {@link Target}. @@ -140,11 +140,10 @@ public class JpaTarget extends AbstractJpaNamedEntity implements Target, EventAw // set default request controller attributes to true, because we want to request them the first time private boolean requestControllerAttributes = true; - @Setter - @Getter - @OneToOne(fetch = FetchType.LAZY, mappedBy = "target", cascade = { CascadeType.ALL }, orphanRemoval = true) + // actually it is OneToOne - but lazy loading is not supported for OneToOne (at least for hibernate 6.6.2) + @OneToMany(fetch = FetchType.LAZY, mappedBy = "target", cascade = { CascadeType.ALL }, orphanRemoval = true) @PrimaryKeyJoinColumn - private JpaAutoConfirmationStatus autoConfirmationStatus; + private List autoConfirmationStatus; @Setter @Getter @@ -242,6 +241,19 @@ public PollStatus getPollStatus() { .apply(this); } + public JpaAutoConfirmationStatus getAutoConfirmationStatus() { + return ObjectUtils.isEmpty(autoConfirmationStatus) ? null : autoConfirmationStatus.get(0); + } + + public void setAutoConfirmationStatus(final JpaAutoConfirmationStatus autoConfirmationStatus) { + if (this.autoConfirmationStatus == null) { + this.autoConfirmationStatus = new ArrayList<>(); + } else { + this.autoConfirmationStatus.clear(); + } + this.autoConfirmationStatus.add(autoConfirmationStatus); + } + public void addTag(final TargetTag tag) { if (tags == null) { tags = new HashSet<>(); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/ActionRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/ActionRepository.java index 827f3a0647..c0dc2a4cef 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/ActionRepository.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/ActionRepository.java @@ -44,7 +44,7 @@ public interface ActionRepository extends BaseEntityRepository { * @return the found {@link Action} */ @EntityGraph(value = "Action.all", type = EntityGraphType.LOAD) - Optional findWithDetailsById(Long actionId); + Optional findWithDetailsById(@Param("id") Long actionId); /** * Retrieves the latest finished {@link Action} for given target and {@link DistributionSet}. diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/LocalArtifactRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/LocalArtifactRepository.java index 5ab376ac8c..e5b973508e 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/LocalArtifactRepository.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/LocalArtifactRepository.java @@ -31,7 +31,7 @@ public interface LocalArtifactRepository extends BaseEntityRepository sumOfNonDeletedArtifactSize(); /** diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/TargetRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/TargetRepository.java index a731eea796..009c143afa 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/TargetRepository.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/TargetRepository.java @@ -50,10 +50,10 @@ default JpaTarget getByControllerId(final String controllerId) { @Deprecated(forRemoval = true) @Modifying @Transactional - @Query("UPDATE JpaTarget t SET t.assignedDistributionSet = :set, t.lastModifiedAt = :lastModifiedAt, t.lastModifiedBy = :lastModifiedBy, t.updateStatus = :status WHERE t.id IN :targets") - void setAssignedDistributionSetAndUpdateStatus(@Param("status") TargetUpdateStatus status, - @Param("set") JpaDistributionSet set, @Param("lastModifiedAt") Long modifiedAt, - @Param("lastModifiedBy") String modifiedBy, @Param("targets") Collection targets); + @Query("UPDATE JpaTarget t SET t.assignedDistributionSet = :dSet, t.lastModifiedAt = :lastModifiedAt, t.lastModifiedBy = :lastModifiedBy, t.updateStatus = :status WHERE t.id IN :targets") + void setAssignedDistributionSetAndUpdateStatus( + @Param("dSet") JpaDistributionSet set, @Param("lastModifiedAt") Long modifiedAt, @Param("lastModifiedBy") String modifiedBy, @Param("status") TargetUpdateStatus status, + @Param("targets") Collection targets); // TODO AC - remove it and use specification @@ -64,9 +64,10 @@ void setAssignedDistributionSetAndUpdateStatus(@Param("status") TargetUpdateStat @Deprecated(forRemoval = true) @Modifying @Transactional - @Query("UPDATE JpaTarget t SET t.assignedDistributionSet = :set, t.installedDistributionSet = :set, t.installationDate = :lastModifiedAt, t.lastModifiedAt = :lastModifiedAt, t.lastModifiedBy = :lastModifiedBy, t.updateStatus = :status WHERE t.id IN :targets") - void setAssignedAndInstalledDistributionSetAndUpdateStatus(@Param("status") TargetUpdateStatus status, - @Param("set") JpaDistributionSet set, @Param("lastModifiedAt") Long modifiedAt, + @Query("UPDATE JpaTarget t SET t.assignedDistributionSet = :dSet, t.installedDistributionSet = :dSet, t.installationDate = :lastModifiedAt, t.lastModifiedAt = :lastModifiedAt, t.lastModifiedBy = :lastModifiedBy, t.updateStatus = :status WHERE t.id IN :targets") + void setAssignedAndInstalledDistributionSetAndUpdateStatus( + @Param("status") TargetUpdateStatus status, + @Param("dSet") JpaDistributionSet distributionSet, @Param("lastModifiedAt") Long modifiedAt, @Param("lastModifiedBy") String modifiedBy, @Param("targets") Collection targets); /** diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/autocleanup/AutoActionCleanupTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/autocleanup/AutoActionCleanupTest.java index 40fb9fac70..8f5148a95e 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/autocleanup/AutoActionCleanupTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/autocleanup/AutoActionCleanupTest.java @@ -114,7 +114,7 @@ void canceledAndFailedActionsAreCleanedUp() { autoActionCleanup.run(); assertThat(actionRepository.count()).isEqualTo(1); - assertThat(actionRepository.findWithDetailsById(action3)).isPresent(); + assertThat(actionRepository.findById(action3)).isPresent(); } @Test @@ -145,8 +145,8 @@ void canceledActionsAreCleanedUp() { autoActionCleanup.run(); assertThat(actionRepository.count()).isEqualTo(2); - assertThat(actionRepository.findWithDetailsById(action2)).isPresent(); - assertThat(actionRepository.findWithDetailsById(action3)).isPresent(); + assertThat(actionRepository.findById(action2)).isPresent(); + assertThat(actionRepository.findById(action3)).isPresent(); } @Test @@ -184,7 +184,7 @@ void canceledAndFailedActionsAreCleanedUpWhenExpired() throws InterruptedExcepti autoActionCleanup.run(); assertThat(actionRepository.count()).isEqualTo(1); - assertThat(actionRepository.findWithDetailsById(action3)).isPresent(); + assertThat(actionRepository.findById(action3)).isPresent(); } private void setActionToCanceled(final Long id) { diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/ControllerManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/ControllerManagementTest.java index ee26b51a97..09500c163e 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/ControllerManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/ControllerManagementTest.java @@ -1879,7 +1879,7 @@ private void assertInstalledDistributionSetId(final String controllerId, final L } private void assertLastActionStatusCodeInAction(final Long actionId, final Integer expectedLastActionStatusCode) { - final Optional action = actionRepository.findWithDetailsById(actionId); + final Optional action = actionRepository.findById(actionId).map(Action.class::cast); assertThat(action).isPresent(); assertThat(action.get().getLastActionStatusCode()).isEqualTo(Optional.ofNullable(expectedLastActionStatusCode)); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/DeploymentManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/DeploymentManagementTest.java index c18b42d964..8c7c85e3dc 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/DeploymentManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/DeploymentManagementTest.java @@ -996,8 +996,8 @@ void weightValidatedAndSaved() { deploymentManagement.assignDistributionSets(Collections.singletonList(valideRequest1)).get(0)).getId(); final Long valideActionId2 = getFirstAssignedAction( deploymentManagement.assignDistributionSets(Collections.singletonList(valideRequest2)).get(0)).getId(); - assertThat(actionRepository.findWithDetailsById(valideActionId1).get().getWeight()).get().isEqualTo(Action.WEIGHT_MAX); - assertThat(actionRepository.findWithDetailsById(valideActionId2).get().getWeight()).get().isEqualTo(Action.WEIGHT_MIN); + assertThat(actionRepository.findById(valideActionId1).get().getWeight()).get().isEqualTo(Action.WEIGHT_MAX); + assertThat(actionRepository.findById(valideActionId2).get().getWeight()).get().isEqualTo(Action.WEIGHT_MIN); } /** diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLActionFieldsTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLActionFieldsTest.java index d2f0e05d7a..dc2234dd83 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLActionFieldsTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLActionFieldsTest.java @@ -24,7 +24,6 @@ import org.eclipse.hawkbit.repository.model.Action.ActionType; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.DistributionSet; -import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.data.domain.PageRequest; @@ -91,7 +90,7 @@ public void testFilterByParameterExtRef() { assertRSQLQuery(ActionFields.EXTERNALREF.name() + "==extRef*", 10); } - private @NotNull JpaAction newJpaAction(final DistributionSet dsA, final boolean active, final String extRef) { + private JpaAction newJpaAction(final DistributionSet dsA, final boolean active, final String extRef) { final JpaAction newAction = new JpaAction(); newAction.setActionType(ActionType.SOFT); newAction.setDistributionSet(dsA); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLUtilityTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLUtilityTest.java index 26430c2d26..7aa60c746c 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLUtilityTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLUtilityTest.java @@ -63,10 +63,10 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.Spy; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.orm.jpa.vendor.Database; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.context.junit.jupiter.SpringExtension; @ExtendWith(SpringExtension.class) @@ -74,20 +74,21 @@ @Story("RSQL search utility") // TODO: fully document tests -> @Description for long text and reasonable // method name as short text -public class RSQLUtilityTest { +class RSQLUtilityTest { + + private static final TenantConfigurationValue TEST_POLLING_TIME_INTERVAL = + TenantConfigurationValue. builder().value("00:05:00").build(); + private static final TenantConfigurationValue TEST_POLLING_OVERDUE_TIME_INTERVAL = + TenantConfigurationValue. builder().value("00:07:37").build(); - private static final TenantConfigurationValue TEST_POLLING_TIME_INTERVAL = TenantConfigurationValue - . builder().value("00:05:00").build(); - private static final TenantConfigurationValue TEST_POLLING_OVERDUE_TIME_INTERVAL = TenantConfigurationValue - . builder().value("00:07:37").build(); @Spy private final VirtualPropertyResolver macroResolver = new VirtualPropertyResolver(); private final Database testDb = Database.H2; - @MockBean + @MockitoBean private TenantConfigurationManagement confMgmt; - @MockBean + @MockitoBean private SystemSecurityContext securityContext; - @MockBean + @MockitoBean private RsqlVisitorFactory rsqlVisitorFactory; @Mock private Root baseSoftwareModuleRootMock; @@ -103,14 +104,14 @@ public class RSQLUtilityTest { private Attribute attribute; @BeforeEach - public void beforeEach() { + void beforeEach() { setupRoot(baseSoftwareModuleRootMock); setupRoot(subqueryRootMock); } @Test @Description("Testing throwing exception in case of not allowed RSQL key") - public void rsqlUnsupportedFieldExceptionTest() { + void rsqlUnsupportedFieldExceptionTest() { final String rsql1 = "wrongfield == abcd"; assertThatExceptionOfType(RSQLParameterUnsupportedFieldException.class) .isThrownBy(() -> validateRsqlForTestFields(rsql1)); @@ -122,7 +123,7 @@ public void rsqlUnsupportedFieldExceptionTest() { @Test @Description("Testing exception in case of not allowed subkey") - public void rsqlUnsupportedSubkeyThrowException() { + void rsqlUnsupportedSubkeyThrowException() { final String rsql1 = "TESTFIELD_WITH_SUB_ENTITIES.unsupported == abcd and TESTFIELD_WITH_SUB_ENTITIES.subentity22 == 0123"; assertThatExceptionOfType(RSQLParameterUnsupportedFieldException.class) .isThrownBy(() -> validateRsqlForTestFields(rsql1)); @@ -138,7 +139,7 @@ public void rsqlUnsupportedSubkeyThrowException() { @Test @Description("Testing valid RSQL keys based on TestFieldEnum.class") - public void rsqlFieldValidation() { + void rsqlFieldValidation() { final String rsql1 = "TESTFIELD_WITH_SUB_ENTITIES.subentity11 == abcd and TESTFIELD_WITH_SUB_ENTITIES.subentity22 == 0123"; final String rsql2 = "TESTFIELD_WITH_SUB_ENTITIES.subentity11 == abcd or TESTFIELD_WITH_SUB_ENTITIES.subentity22 == 0123"; @@ -151,14 +152,14 @@ public void rsqlFieldValidation() { @Test @Description("Verify that RSQL expressions are validated case insensitive") - public void mixedCaseRsqlFieldValidation() { + void mixedCaseRsqlFieldValidation() { when(rsqlVisitorFactory.validationRsqlVisitor(eq(TargetFields.class))).thenReturn(new FieldValidationRsqlVisitor<>(TargetFields.class)); final String rsqlWithMixedCase = "name==b And name==c aND Name==d OR NAME=iN=y oR nAme=IN=z"; RSQLUtility.validateRsqlFor(rsqlWithMixedCase, TargetFields.class); } @Test - public void wrongRsqlSyntaxThrowSyntaxException() { + void wrongRsqlSyntaxThrowSyntaxException() { final String wrongRSQL = "name==abc;d"; try { RSQLUtility.buildRsqlSpecification(wrongRSQL, SoftwareModuleFields.class, null, testDb) @@ -169,7 +170,7 @@ public void wrongRsqlSyntaxThrowSyntaxException() { } @Test - public void wrongFieldThrowUnsupportedFieldException() { + void wrongFieldThrowUnsupportedFieldException() { final String wrongRSQL = "unknownField==abc"; when(baseSoftwareModuleRootMock.getJavaType()).thenReturn((Class) SoftwareModule.class); try { @@ -182,7 +183,7 @@ public void wrongFieldThrowUnsupportedFieldException() { } @Test - public void wrongRsqlMapSyntaxThrowSyntaxException() { + void wrongRsqlMapSyntaxThrowSyntaxException() { String wrongRSQL = TargetFields.ATTRIBUTE + "==abc"; try { RSQLUtility.buildRsqlSpecification(wrongRSQL, TargetFields.class, null, testDb) @@ -218,7 +219,7 @@ public void wrongRsqlMapSyntaxThrowSyntaxException() { } @Test - public void wrongRsqlSubEntitySyntaxThrowSyntaxException() { + void wrongRsqlSubEntitySyntaxThrowSyntaxException() { String wrongRSQL = TargetFields.ASSIGNEDDS + "==abc"; try { RSQLUtility.buildRsqlSpecification(wrongRSQL, TargetFields.class, null, testDb) @@ -245,7 +246,7 @@ public void wrongRsqlSubEntitySyntaxThrowSyntaxException() { } @Test - public void correctRsqlBuildsPredicate() { + void correctRsqlBuildsPredicate() { reset0(baseSoftwareModuleRootMock, criteriaQueryMock, criteriaBuilderMock); final String correctRsql = "name==abc;version==1.2"; when(baseSoftwareModuleRootMock.get("name")).thenReturn(baseSoftwareModuleRootMock); @@ -266,7 +267,7 @@ public void correctRsqlBuildsPredicate() { } @Test - public void correctRsqlBuildsSimpleNotEqualPredicate() { + void correctRsqlBuildsSimpleNotEqualPredicate() { reset0(baseSoftwareModuleRootMock, criteriaQueryMock, criteriaBuilderMock); final String correctRsql = "name!=abc"; when(baseSoftwareModuleRootMock.get("name")).thenReturn(baseSoftwareModuleRootMock); @@ -289,7 +290,7 @@ public void correctRsqlBuildsSimpleNotEqualPredicate() { } @Test - public void correctRsqlBuildsSimpleNotLikePredicate() { + void correctRsqlBuildsSimpleNotLikePredicate() { reset0(baseSoftwareModuleRootMock, criteriaQueryMock, criteriaBuilderMock); final String correctRsql = "name!=abc*"; when(baseSoftwareModuleRootMock.get("name")).thenReturn(baseSoftwareModuleRootMock); @@ -313,7 +314,7 @@ public void correctRsqlBuildsSimpleNotLikePredicate() { } @Test - public void correctRsqlBuildsNotSimpleNotLikePredicate() { + void correctRsqlBuildsNotSimpleNotLikePredicate() { reset0(baseSoftwareModuleRootMock, criteriaQueryMock, criteriaBuilderMock); // with this query a subquery has to be made, so it is no simple query final String correctRsql = "type!=abc"; @@ -341,7 +342,7 @@ public void correctRsqlBuildsNotSimpleNotLikePredicate() { } @Test - public void correctRsqlBuildsEqualPredicateWithPercentage() { + void correctRsqlBuildsEqualPredicateWithPercentage() { reset0(baseSoftwareModuleRootMock, criteriaQueryMock, criteriaBuilderMock); final String correctRsql = "name==a%"; when(baseSoftwareModuleRootMock.get("name")).thenReturn(baseSoftwareModuleRootMock); @@ -362,7 +363,7 @@ public void correctRsqlBuildsEqualPredicateWithPercentage() { } @Test - public void correctRsqlBuildsLikePredicateWithPercentage() { + void correctRsqlBuildsLikePredicateWithPercentage() { reset0(baseSoftwareModuleRootMock, criteriaQueryMock, criteriaBuilderMock); final String correctRsql = "name==a%*"; when(baseSoftwareModuleRootMock.get("name")).thenReturn(baseSoftwareModuleRootMock); @@ -383,7 +384,7 @@ public void correctRsqlBuildsLikePredicateWithPercentage() { } @Test - public void correctRsqlBuildsLikePredicateWithPercentageSQLServer() { + void correctRsqlBuildsLikePredicateWithPercentageSQLServer() { reset0(baseSoftwareModuleRootMock, criteriaQueryMock, criteriaBuilderMock); final String correctRsql = "name==a%*"; when(baseSoftwareModuleRootMock.get("name")).thenReturn(baseSoftwareModuleRootMock); @@ -405,7 +406,7 @@ public void correctRsqlBuildsLikePredicateWithPercentageSQLServer() { } @Test - public void correctRsqlBuildsLessThanPredicate() { + void correctRsqlBuildsLessThanPredicate() { reset0(baseSoftwareModuleRootMock, criteriaQueryMock, criteriaBuilderMock); final String correctRsql = "name=lt=abc"; when(baseSoftwareModuleRootMock.get("name")).thenReturn(baseSoftwareModuleRootMock); @@ -423,7 +424,7 @@ public void correctRsqlBuildsLessThanPredicate() { } @Test - public void correctRsqlWithEnumValue() { + void correctRsqlWithEnumValue() { reset0(baseSoftwareModuleRootMock, criteriaQueryMock, criteriaBuilderMock); final String correctRsql = "testfield==bumlux"; when(baseSoftwareModuleRootMock.get("testfield")).thenReturn(baseSoftwareModuleRootMock); @@ -440,7 +441,7 @@ public void correctRsqlWithEnumValue() { } @Test - public void wrongRsqlWithWrongEnumValue() { + void wrongRsqlWithWrongEnumValue() { reset0(baseSoftwareModuleRootMock, criteriaQueryMock, criteriaBuilderMock); final String correctRsql = "testfield==unknownValue"; when(baseSoftwareModuleRootMock.get("testfield")).thenReturn(baseSoftwareModuleRootMock); @@ -459,7 +460,7 @@ public void wrongRsqlWithWrongEnumValue() { @Test @Description("Tests the resolution of overdue_ts placeholder in context of a RSQL expression.") - public void correctRsqlWithOverdueMacro() { + void correctRsqlWithOverdueMacro() { reset0(baseSoftwareModuleRootMock, criteriaQueryMock, criteriaBuilderMock); final String overdueProp = "overdue_ts"; final String overduePropPlaceholder = "${" + overdueProp + "}"; @@ -487,7 +488,7 @@ public void correctRsqlWithOverdueMacro() { @Test @Description("Tests RSQL expression with an unknown placeholder.") - public void correctRsqlWithUnknownMacro() { + void correctRsqlWithUnknownMacro() { reset0(baseSoftwareModuleRootMock, criteriaQueryMock, criteriaBuilderMock); final String overdueProp = "unknown"; final String overduePropPlaceholder = "${" + overdueProp + "}"; @@ -510,7 +511,7 @@ public void correctRsqlWithUnknownMacro() { eq(overduePropPlaceholder)); } - public VirtualPropertyReplacer setupMacroLookup() { + VirtualPropertyReplacer setupMacroLookup() { when(securityContext.runAsSystem(Mockito.any())).thenAnswer(a -> ((Callable) a.getArgument(0)).call()); when(confMgmt.getConfigurationValue(TenantConfigurationKey.POLLING_TIME_INTERVAL, String.class)) diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/VirtualPropertyResolverTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/VirtualPropertyResolverTest.java index bb80785403..857736bd0f 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/VirtualPropertyResolverTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/VirtualPropertyResolverTest.java @@ -32,30 +32,31 @@ import org.junit.jupiter.params.provider.ValueSource; import org.mockito.Mockito; import org.mockito.Spy; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.context.junit.jupiter.SpringExtension; @ExtendWith(SpringExtension.class) @Feature("Unit Tests - Repository") @Story("Placeholder resolution for virtual properties") -public class VirtualPropertyResolverTest { +class VirtualPropertyResolverTest { + + private static final TenantConfigurationValue TEST_POLLING_TIME_INTERVAL = + TenantConfigurationValue. builder().value("00:05:00").build(); + private static final TenantConfigurationValue TEST_POLLING_OVERDUE_TIME_INTERVAL = + TenantConfigurationValue. builder().value("00:07:37").build(); - private static final TenantConfigurationValue TEST_POLLING_TIME_INTERVAL = TenantConfigurationValue - . builder().value("00:05:00").build(); - private static final TenantConfigurationValue TEST_POLLING_OVERDUE_TIME_INTERVAL = TenantConfigurationValue - . builder().value("00:07:37").build(); @Spy private final VirtualPropertyResolver resolverUnderTest = new VirtualPropertyResolver(); - @MockBean + @MockitoBean private TenantConfigurationManagement confMgmt; - @MockBean + @MockitoBean private SystemSecurityContext securityContext; private StrSubstitutor substitutor; @BeforeEach - public void before() { + void before() { when(confMgmt.getConfigurationValue(TenantConfigurationKey.POLLING_TIME_INTERVAL, String.class)) .thenReturn(TEST_POLLING_TIME_INTERVAL); when(confMgmt.getConfigurationValue(TenantConfigurationKey.POLLING_OVERDUE_TIME_INTERVAL, String.class)) @@ -67,7 +68,7 @@ public void before() { @Test @Description("Tests VirtualPropertyResolver with a placeholder unknown to VirtualPropertyResolver.") - public void handleUnknownPlaceholder() { + void handleUnknownPlaceholder() { final String placeholder = "${unknown}"; final String testString = "lhs=lt=" + placeholder; @@ -77,7 +78,7 @@ public void handleUnknownPlaceholder() { @Test @Description("Tests escape mechanism for placeholders (syntax is $${SOME_PLACEHOLDER}).") - public void handleEscapedPlaceholder() { + void handleEscapedPlaceholder() { final String placeholder = "${OVERDUE_TS}"; final String escaptedPlaceholder = StrSubstitutor.DEFAULT_ESCAPE + placeholder; final String testString = "lhs=lt=" + escaptedPlaceholder; diff --git a/pom.xml b/pom.xml index 5ac40120fa..e93d62511b 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,7 @@ org.springframework.boot spring-boot-starter-parent - 3.3.5 + 3.4.0 org.eclipse.hawkbit @@ -40,9 +40,9 @@ true - 3.3.5 - 2023.0.2 - 2.6.0 + 3.4.0 + 2024.0.0 + 2.7.0 3.0.0