Skip to content

Commit

Permalink
Upgrades spring to 3.4.0
Browse files Browse the repository at this point in the history
Signed-off-by: Avgustin Marinov <[email protected]>
  • Loading branch information
avgustinmm committed Dec 19, 2024
1 parent 52fec7c commit ac4dcc3
Show file tree
Hide file tree
Showing 16 changed files with 42 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -184,13 +185,15 @@ 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);
obj.put("type", type.getName());
return obj;
}

@SneakyThrows
protected static JSONObject getAssignmentObject(final Object id, final MgmtActionType type, final int weight) {
return getAssignmentObject(id, type).put("weight", weight);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,4 @@ public interface Artifact extends TenantAwareBaseEntity {
* @return size of the artifact in bytes.
*/
long getSize();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public interface ActionRepository extends BaseEntityRepository<JpaAction> {
* @return the found {@link Action}
*/
@EntityGraph(value = "Action.all", type = EntityGraphType.LOAD)
Optional<Action> findWithDetailsById(Long actionId);
Optional<Action> findWithDetailsById(@Param("id") Long actionId);

/**
* Retrieves the latest finished {@link Action} for given target and {@link DistributionSet}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public interface LocalArtifactRepository extends BaseEntityRepository<JpaArtifac
*
* @return sum of artifacts size in bytes
*/
@Query("SELECT SUM(la.size) FROM JpaArtifact la WHERE la.softwareModule.deleted = false")
@Query("SELECT SUM(a.fileSize) FROM JpaArtifact a WHERE a.softwareModule.deleted = false")
Optional<Long> sumOfNonDeletedArtifactSize();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Long> 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<Long> targets);

// TODO AC - remove it and use specification

Expand All @@ -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<Long> targets);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void canceledAndFailedActionsAreCleanedUp() {
autoActionCleanup.run();

assertThat(actionRepository.count()).isEqualTo(1);
assertThat(actionRepository.findWithDetailsById(action3)).isPresent();
assertThat(actionRepository.findById(action3)).isPresent();
}

@Test
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1879,7 +1879,7 @@ private void assertInstalledDistributionSetId(final String controllerId, final L
}

private void assertLastActionStatusCodeInAction(final Long actionId, final Integer expectedLastActionStatusCode) {
final Optional<Action> action = actionRepository.findWithDetailsById(actionId);
final Optional<Action> action = actionRepository.findById(actionId).map(Action.class::cast);
assertThat(action).isPresent();
assertThat(action.get().getLastActionStatusCode()).isEqualTo(Optional.ofNullable(expectedLastActionStatusCode));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.5</version>
<version>3.4.0</version>
</parent>

<groupId>org.eclipse.hawkbit</groupId>
Expand All @@ -40,9 +40,9 @@

<snapshotDependencyAllowed>true</snapshotDependencyAllowed>

<spring.boot.version>3.3.5</spring.boot.version>
<spring.cloud.version>2023.0.2</spring.cloud.version>
<springdoc-openapi.version>2.6.0</springdoc-openapi.version>
<spring.boot.version>3.4.0</spring.boot.version>
<spring.cloud.version>2024.0.0</spring.cloud.version>
<springdoc-openapi.version>2.7.0</springdoc-openapi.version>
<spring.plugin.core.version>3.0.0</spring.plugin.core.version>
<!-- Spring boot version overrides (should be reviewed with every boot upgrade) - START -->
<!-- Newer versions needed than defined in Boot -->
Expand Down

0 comments on commit ac4dcc3

Please sign in to comment.