Upgrades spring to 3.4.0 (#2154)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2024-12-20 11:30:51 +02:00
committed by GitHub
parent 65ef31e702
commit c38f28d5a7
22 changed files with 109 additions and 96 deletions

View File

@@ -11,13 +11,11 @@ package org.eclipse.hawkbit.ddi.rest.resource;
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);

View File

@@ -13,6 +13,7 @@ import static org.hamcrest.Matchers.contains;
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 @@ public abstract class AbstractManagementApiIntegrationTest extends AbstractRestI
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 @@ public abstract class AbstractManagementApiIntegrationTest extends AbstractRestI
return obj;
}
@SneakyThrows
protected static JSONObject getAssignmentObject(final Object id, final MgmtActionType type, final int weight) {
return getAssignmentObject(id, type).put("weight", weight);
}

View File

@@ -15,6 +15,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
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.context.web.WebAppConfiguration;
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 class MgmtBasicAuthResourceTest {
}
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 {

View File

@@ -113,5 +113,4 @@ public interface EntityFactory {
* @return {@link TargetFilterQueryBuilder} object
*/
TargetFilterQueryBuilder targetFilterQuery();
}
}

View File

@@ -48,5 +48,4 @@ public interface Artifact extends TenantAwareBaseEntity {
* @return size of the artifact in bytes.
*/
long getSize();
}
}

View File

@@ -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 class JpaEntityFactory implements EntityFactory {
public TargetFilterQueryBuilder targetFilterQuery() {
return targetFilterQueryBuilder;
}
}
}

View File

@@ -317,7 +317,7 @@ public class JpaArtifactManagement implements ArtifactManagement {
}
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);

View File

@@ -132,8 +132,7 @@ public class OnlineDsAssignmentStrategy extends AbstractDsAssignmentStrategy {
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

View File

@@ -67,9 +67,11 @@ import org.eclipse.hawkbit.repository.model.helper.EventPublisherHolder;
@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

View File

@@ -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 class JpaArtifact extends AbstractJpaTenantAwareBaseEntity implements Art
this.softwareModule = (JpaSoftwareModule) softwareModule;
this.softwareModule.addArtifact(this);
}
@Override
public long getSize() {
return getFileSize();
}
}

View File

@@ -15,7 +15,7 @@ import jakarta.persistence.Entity;
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 @@ import org.springframework.util.StringUtils;
@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;

View File

@@ -35,7 +35,6 @@ import jakarta.persistence.ManyToMany;
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.EventPublisherHolder;
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<JpaAutoConfirmationStatus> autoConfirmationStatus;
@Setter
@Getter
@@ -242,6 +241,19 @@ public class JpaTarget extends AbstractJpaNamedEntity implements Target, EventAw
.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<>();

View File

@@ -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}.

View File

@@ -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();
/**

View File

@@ -50,10 +50,10 @@ public interface TargetRepository extends BaseEntityRepository<JpaTarget> {
@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
@@ -64,9 +64,10 @@ public interface TargetRepository extends BaseEntityRepository<JpaTarget> {
@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);
/**

View File

@@ -114,7 +114,7 @@ class AutoActionCleanupTest extends AbstractJpaIntegrationTest {
autoActionCleanup.run();
assertThat(actionRepository.count()).isEqualTo(1);
assertThat(actionRepository.findWithDetailsById(action3)).isPresent();
assertThat(actionRepository.findById(action3)).isPresent();
}
@Test
@@ -145,8 +145,8 @@ class AutoActionCleanupTest extends AbstractJpaIntegrationTest {
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 @@ class AutoActionCleanupTest extends AbstractJpaIntegrationTest {
autoActionCleanup.run();
assertThat(actionRepository.count()).isEqualTo(1);
assertThat(actionRepository.findWithDetailsById(action3)).isPresent();
assertThat(actionRepository.findById(action3)).isPresent();
}
private void setActionToCanceled(final Long id) {

View File

@@ -1879,7 +1879,7 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
}
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));
}

View File

@@ -996,8 +996,8 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
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);
}
/**

View File

@@ -24,7 +24,6 @@ import org.eclipse.hawkbit.repository.model.Action;
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 class RSQLActionFieldsTest extends AbstractJpaIntegrationTest {
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);

View File

@@ -63,10 +63,10 @@ import org.junit.jupiter.api.extension.ExtendWith;
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 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
@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<String> TEST_POLLING_TIME_INTERVAL =
TenantConfigurationValue.<String> builder().value("00:05:00").build();
private static final TenantConfigurationValue<String> TEST_POLLING_OVERDUE_TIME_INTERVAL =
TenantConfigurationValue.<String> builder().value("00:07:37").build();
private static final TenantConfigurationValue<String> TEST_POLLING_TIME_INTERVAL = TenantConfigurationValue
.<String> builder().value("00:05:00").build();
private static final TenantConfigurationValue<String> TEST_POLLING_OVERDUE_TIME_INTERVAL = TenantConfigurationValue
.<String> 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<Object> 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 class RSQLUtilityTest {
@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 class RSQLUtilityTest {
@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 class RSQLUtilityTest {
@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 class RSQLUtilityTest {
}
@Test
public void wrongFieldThrowUnsupportedFieldException() {
void wrongFieldThrowUnsupportedFieldException() {
final String wrongRSQL = "unknownField==abc";
when(baseSoftwareModuleRootMock.getJavaType()).thenReturn((Class) SoftwareModule.class);
try {
@@ -182,7 +183,7 @@ public class RSQLUtilityTest {
}
@Test
public void wrongRsqlMapSyntaxThrowSyntaxException() {
void wrongRsqlMapSyntaxThrowSyntaxException() {
String wrongRSQL = TargetFields.ATTRIBUTE + "==abc";
try {
RSQLUtility.buildRsqlSpecification(wrongRSQL, TargetFields.class, null, testDb)
@@ -218,7 +219,7 @@ public class RSQLUtilityTest {
}
@Test
public void wrongRsqlSubEntitySyntaxThrowSyntaxException() {
void wrongRsqlSubEntitySyntaxThrowSyntaxException() {
String wrongRSQL = TargetFields.ASSIGNEDDS + "==abc";
try {
RSQLUtility.buildRsqlSpecification(wrongRSQL, TargetFields.class, null, testDb)
@@ -245,7 +246,7 @@ public class RSQLUtilityTest {
}
@Test
public <T> void correctRsqlBuildsPredicate() {
<T> 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 class RSQLUtilityTest {
}
@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 class RSQLUtilityTest {
}
@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 class RSQLUtilityTest {
}
@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 class RSQLUtilityTest {
}
@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 class RSQLUtilityTest {
}
@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 class RSQLUtilityTest {
}
@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 class RSQLUtilityTest {
}
@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 class RSQLUtilityTest {
}
@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 class RSQLUtilityTest {
}
@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 class RSQLUtilityTest {
@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 class RSQLUtilityTest {
@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 class RSQLUtilityTest {
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))

View File

@@ -32,30 +32,31 @@ import org.junit.jupiter.params.ParameterizedTest;
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<String> TEST_POLLING_TIME_INTERVAL =
TenantConfigurationValue.<String> builder().value("00:05:00").build();
private static final TenantConfigurationValue<String> TEST_POLLING_OVERDUE_TIME_INTERVAL =
TenantConfigurationValue.<String> builder().value("00:07:37").build();
private static final TenantConfigurationValue<String> TEST_POLLING_TIME_INTERVAL = TenantConfigurationValue
.<String> builder().value("00:05:00").build();
private static final TenantConfigurationValue<String> TEST_POLLING_OVERDUE_TIME_INTERVAL = TenantConfigurationValue
.<String> 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 class VirtualPropertyResolverTest {
@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 class VirtualPropertyResolverTest {
@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;

View File

@@ -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>
@@ -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 -->