From 3d390b9ad78ca3e05770f8612dbd9bf3826a827c Mon Sep 17 00:00:00 2001 From: Avgustin Marinov Date: Tue, 21 Jan 2025 22:13:54 +0200 Subject: [PATCH] Sonar Fixes (7) (#2216) Signed-off-by: Avgustin Marinov --- .../JsonIgnorePropertiesAnnotationTest.java | 4 +-- .../model/MgmtAssignedTargetRequestBody.java | 2 ++ .../MgmtDeprecatedResourceTest.java | 32 +++++++++---------- .../mgmt/rest/resource/MgmtActionMapper.java | 3 +- .../resource/MgmtDistributionSetMapper.java | 12 +++---- .../resource/MgmtDistributionSetResource.java | 7 ++-- .../rest/resource/MgmtActionResourceTest.java | 3 +- .../resource/MgmtBasicAuthResourceTest.java | 6 ++-- .../MgmtDistributionSetResourceTest.java | 28 ++++++++-------- .../repository/MaintenanceScheduleHelper.java | 7 ++-- .../MaintenanceScheduleHelperTest.java | 16 +++++----- .../JpaSoftwareModuleManagement.java | 21 +++++++----- .../jpa/management/JpaSystemManagement.java | 5 ++- .../jpa/management/JpaTargetManagement.java | 5 ++- .../JpaTenantConfigurationManagement.java | 2 +- .../repository/jpa/model/JpaTargetType.java | 1 + .../JpaSpecificationEntityGraphExecutor.java | 8 ----- .../LazyControllerManagementTest.java | 4 +-- .../rsql/RSQLDistributionSetFieldTest.java | 24 +++++++------- .../org/eclipse/hawkbit/sdk/mgmt/MgmtApi.java | 8 ++--- .../eclipse/hawkbit/security/MdcHandler.java | 4 +-- 21 files changed, 101 insertions(+), 101 deletions(-) diff --git a/hawkbit-ddi/hawkbit-ddi-api/src/test/java/org/eclipse/hawkbit/ddi/json/model/JsonIgnorePropertiesAnnotationTest.java b/hawkbit-ddi/hawkbit-ddi-api/src/test/java/org/eclipse/hawkbit/ddi/json/model/JsonIgnorePropertiesAnnotationTest.java index 56a7549fd..fd4fbf631 100644 --- a/hawkbit-ddi/hawkbit-ddi-api/src/test/java/org/eclipse/hawkbit/ddi/json/model/JsonIgnorePropertiesAnnotationTest.java +++ b/hawkbit-ddi/hawkbit-ddi-api/src/test/java/org/eclipse/hawkbit/ddi/json/model/JsonIgnorePropertiesAnnotationTest.java @@ -28,11 +28,11 @@ import org.junit.jupiter.api.Test; */ @Feature("Unit Tests - Direct Device Integration API") @Story("Serialization of DDI api Models") -public class JsonIgnorePropertiesAnnotationTest { +class JsonIgnorePropertiesAnnotationTest { @Test @Description("This test verifies that all model classes within the 'org.eclipse.hawkbit.ddi.json.model' package are annotated with '@JsonIgnoreProperties(ignoreUnknown = true)'") - public void shouldCheckAnnotationsForAllModelClasses() { + void shouldCheckAnnotationsForAllModelClasses() { final String packageName = getClass().getPackage().getName(); try (final ScanResult scanResult = new ClassGraph().acceptPackages(packageName).scan()) { final List> matchingClasses = scanResult.getAllClasses() diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/json/model/MgmtAssignedTargetRequestBody.java b/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/json/model/MgmtAssignedTargetRequestBody.java index c7451b2b0..db7901a38 100644 --- a/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/json/model/MgmtAssignedTargetRequestBody.java +++ b/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/json/model/MgmtAssignedTargetRequestBody.java @@ -20,6 +20,8 @@ import lombok.experimental.Accessors; /** * Request Body for PUT. + * + * @deprecated Since 0.6.0 */ @Data @Accessors(chain = true) diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/MgmtDeprecatedResourceTest.java b/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/MgmtDeprecatedResourceTest.java index d4da0e223..cb52d8bc5 100644 --- a/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/MgmtDeprecatedResourceTest.java +++ b/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/MgmtDeprecatedResourceTest.java @@ -46,7 +46,7 @@ import org.springframework.test.web.servlet.ResultActions; @Feature("Component Tests - Management API") @Story("Distribution Set Tag Resource") -public class MgmtDeprecatedResourceTest extends AbstractManagementApiIntegrationTest { +class MgmtDeprecatedResourceTest extends AbstractManagementApiIntegrationTest { @Test @Description("Verifies that tag assignments done through toggle API command are correctly assigned or unassigned.") @@ -54,7 +54,7 @@ public class MgmtDeprecatedResourceTest extends AbstractManagementApiIntegration @Expect(type = DistributionSetTagCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 2), @Expect(type = DistributionSetUpdatedEvent.class, count = 4) }) - public void toggleDistributionSetTagAssignment() throws Exception { + void toggleDistributionSetTagAssignment() throws Exception { final DistributionSetTag tag = testdataFactory.createDistributionSetTags(1).get(0); final int setsAssigned = 2; final List sets = testdataFactory.createDistributionSetsWithoutModules(setsAssigned); @@ -64,8 +64,8 @@ public class MgmtDeprecatedResourceTest extends AbstractManagementApiIntegration List updated = distributionSetManagement.findByTag(tag.getId(), PAGE).getContent(); - assertThat(updated.stream().map(DistributionSet::getId).collect(Collectors.toList())) - .containsAll(sets.stream().map(DistributionSet::getId).collect(Collectors.toList())); + assertThat(updated.stream().map(DistributionSet::getId).toList()) + .containsAll(sets.stream().map(DistributionSet::getId).toList()); result.andExpect(applyBaseEntityMatcherOnArrayResult(updated.get(0), "assignedDistributionSets")) .andExpect(applyBaseEntityMatcherOnArrayResult(updated.get(1), "assignedDistributionSets")); @@ -87,7 +87,7 @@ public class MgmtDeprecatedResourceTest extends AbstractManagementApiIntegration @Expect(type = DistributionSetTagCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 2), @Expect(type = DistributionSetUpdatedEvent.class, count = 2) }) - public void assignDistributionSetsWithRequestBody() throws Exception { + void assignDistributionSetsWithRequestBody() throws Exception { final DistributionSetTag tag = testdataFactory.createDistributionSetTags(1).get(0); final int setsAssigned = 2; final List sets = testdataFactory.createDistributionSetsWithoutModules(setsAssigned); @@ -104,8 +104,8 @@ public class MgmtDeprecatedResourceTest extends AbstractManagementApiIntegration final List updated = distributionSetManagement.findByTag(tag.getId(), PAGE).getContent(); - assertThat(updated.stream().map(DistributionSet::getId).collect(Collectors.toList())) - .containsAll(sets.stream().map(DistributionSet::getId).collect(Collectors.toList())); + assertThat(updated.stream().map(DistributionSet::getId).toList()) + .containsAll(sets.stream().map(DistributionSet::getId).toList()); result.andExpect(applyBaseEntityMatcherOnArrayResult(updated.get(0))) .andExpect(applyBaseEntityMatcherOnArrayResult(updated.get(1))); @@ -117,7 +117,7 @@ public class MgmtDeprecatedResourceTest extends AbstractManagementApiIntegration @Expect(type = TargetTagCreatedEvent.class, count = 1), @Expect(type = TargetCreatedEvent.class, count = 2), @Expect(type = TargetUpdatedEvent.class, count = 4) }) - public void toggleTargetTagAssignment() throws Exception { + void toggleTargetTagAssignment() throws Exception { final TargetTag tag = testdataFactory.createTargetTags(1, "").get(0); final int targetsAssigned = 2; final List targets = testdataFactory.createTargets(targetsAssigned); @@ -126,8 +126,8 @@ public class MgmtDeprecatedResourceTest extends AbstractManagementApiIntegration List updated = targetManagement.findByTag(PAGE, tag.getId()).getContent(); - assertThat(updated.stream().map(Target::getControllerId).collect(Collectors.toList())) - .containsAll(targets.stream().map(Target::getControllerId).collect(Collectors.toList())); + assertThat(updated.stream().map(Target::getControllerId).toList()) + .containsAll(targets.stream().map(Target::getControllerId).toList()); result.andExpect(applyTargetEntityMatcherOnArrayResult(updated.get(0), "assignedTargets")) .andExpect(applyTargetEntityMatcherOnArrayResult(updated.get(1), "assignedTargets")); @@ -148,7 +148,7 @@ public class MgmtDeprecatedResourceTest extends AbstractManagementApiIntegration @Expect(type = TargetTagCreatedEvent.class, count = 1), @Expect(type = TargetCreatedEvent.class, count = 2), @Expect(type = TargetUpdatedEvent.class, count = 2) }) - public void assignTargetsByRequestBody() throws Exception { + void assignTargetsByRequestBody() throws Exception { final TargetTag tag = testdataFactory.createTargetTags(1, "").get(0); final int targetsAssigned = 2; final List targets = testdataFactory.createTargets(targetsAssigned); @@ -156,7 +156,7 @@ public class MgmtDeprecatedResourceTest extends AbstractManagementApiIntegration final ResultActions result = mvc .perform(post(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned") .content(controllerIdsOld( - targets.stream().map(Target::getControllerId).collect(Collectors.toList()))) + targets.stream().map(Target::getControllerId).toList())) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()) .andExpect(status().isOk()) @@ -164,8 +164,8 @@ public class MgmtDeprecatedResourceTest extends AbstractManagementApiIntegration final List updated = targetManagement.findByTag(PAGE, tag.getId()).getContent(); - assertThat(updated.stream().map(Target::getControllerId).collect(Collectors.toList())) - .containsAll(targets.stream().map(Target::getControllerId).collect(Collectors.toList())); + assertThat(updated.stream().map(Target::getControllerId).toList()) + .containsAll(targets.stream().map(Target::getControllerId).toList()); result.andExpect(applyTargetEntityMatcherOnArrayResult(updated.get(0))) .andExpect(applyTargetEntityMatcherOnArrayResult(updated.get(1))); @@ -175,7 +175,7 @@ public class MgmtDeprecatedResourceTest extends AbstractManagementApiIntegration return mvc .perform(post(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned/toggleTagAssignment").content( - JsonBuilder.ids(sets.stream().map(DistributionSet::getId).collect(Collectors.toList()))) + JsonBuilder.ids(sets.stream().map(DistributionSet::getId).toList())) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()) .andExpect(status().isOk()) @@ -196,7 +196,7 @@ public class MgmtDeprecatedResourceTest extends AbstractManagementApiIntegration .perform(post(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned/toggleTagAssignment") .content(controllerIdsOld( - targets.stream().map(Target::getControllerId).collect(Collectors.toList()))) + targets.stream().map(Target::getControllerId).toList())) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()) .andExpect(status().isOk()) diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtActionMapper.java b/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtActionMapper.java index f0754d0c7..b39c2957f 100644 --- a/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtActionMapper.java +++ b/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtActionMapper.java @@ -12,7 +12,6 @@ package org.eclipse.hawkbit.mgmt.rest.resource; import java.util.Collection; import java.util.Collections; import java.util.List; -import java.util.stream.Collectors; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -41,7 +40,7 @@ public final class MgmtActionMapper { } return new ResponseList<>(actions.stream() .map(action -> toResponse(action, repMode)) - .collect(Collectors.toList())); + .toList()); } static MgmtAction toResponse(final Action action, final MgmtRepresentationMode repMode) { diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetMapper.java b/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetMapper.java index 9310c261d..90273c76e 100644 --- a/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetMapper.java +++ b/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetMapper.java @@ -51,7 +51,7 @@ public final class MgmtDistributionSetMapper { */ static List dsFromRequest( final Collection sets, final EntityFactory entityFactory) { - return sets.stream().map(dsRest -> fromRequest(dsRest, entityFactory)).collect(Collectors.toList()); + return sets.stream().map(dsRest -> fromRequest(dsRest, entityFactory)).toList(); } static List fromRequestDsMetadata(final List metadata, final EntityFactory entityFactory) { @@ -61,7 +61,7 @@ public final class MgmtDistributionSetMapper { return metadata.stream() .map(metadataRest -> entityFactory.generateDsMetadata(metadataRest.getKey(), metadataRest.getValue())) - .collect(Collectors.toList()); + .toList(); } static MgmtDistributionSet toResponse(final DistributionSet distributionSet) { @@ -111,7 +111,7 @@ public final class MgmtDistributionSetMapper { final MgmtTargetAssignmentResponseBody result = new MgmtTargetAssignmentResponseBody(); result.setAlreadyAssigned(dsAssignmentResult.getAlreadyAssigned()); result.setAssignedActions(dsAssignmentResult.getAssignedEntity().stream() - .map(a -> new MgmtActionId(a.getTarget().getControllerId(), a.getId())).collect(Collectors.toList())); + .map(a -> new MgmtActionId(a.getTarget().getControllerId(), a.getId())).toList()); return result; } @@ -123,7 +123,7 @@ public final class MgmtDistributionSetMapper { final List assignedActions = dsAssignmentResults.stream() .flatMap(assignmentResult -> assignmentResult.getAssignedEntity().stream()) .map(action -> new MgmtActionId(action.getTarget().getControllerId(), action.getId())) - .collect(Collectors.toList()); + .toList(); result.setAlreadyAssigned(alreadyAssigned); result.setAssignedActions(assignedActions); return result; @@ -136,7 +136,7 @@ public final class MgmtDistributionSetMapper { } return new ResponseList<>( - sets.stream().map(MgmtDistributionSetMapper::toResponse).collect(Collectors.toList())); + sets.stream().map(MgmtDistributionSetMapper::toResponse).toList()); } static MgmtMetadata toResponseDsMetadata(final DistributionSetMetadata metadata) { @@ -159,7 +159,7 @@ public final class MgmtDistributionSetMapper { return Collections.emptyList(); } - return sets.stream().map(MgmtDistributionSetMapper::toResponse).collect(Collectors.toList()); + return sets.stream().map(MgmtDistributionSetMapper::toResponse).toList(); } /** diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java b/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java index b77845163..765db157c 100644 --- a/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java +++ b/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java @@ -268,10 +268,9 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi { : dsAssignment.getConfirmationRequired(); return MgmtDeploymentRequestMapper.createAssignmentRequestBuilder(dsAssignment, distributionSetId) .setConfirmationRequired(isConfirmationRequired).build(); - }).collect(Collectors.toList()); + }).toList(); - final List assignmentResults = deployManagement - .assignDistributionSets(deploymentRequests); + final List assignmentResults = deployManagement.assignDistributionSets(deploymentRequests); return ResponseEntity.ok(MgmtDistributionSetMapper.toResponse(assignmentResults)); } @@ -338,7 +337,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi { distributionSetId, softwareModuleIDs.stream() .map(MgmtSoftwareModuleAssignment::getId) - .collect(Collectors.toList())); + .toList()); return ResponseEntity.ok().build(); } diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtActionResourceTest.java b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtActionResourceTest.java index ec9f2369a..df965f9c5 100644 --- a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtActionResourceTest.java +++ b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtActionResourceTest.java @@ -455,8 +455,7 @@ class MgmtActionResourceTest extends AbstractManagementApiIntegrationTest { void invalidRequestsOnActionResource() throws Exception { final String knownTargetId = "targetId"; - final List actions = generateTargetWithTwoUpdatesWithOneOverride(knownTargetId); - final Long actionId = actions.get(0).getId(); + generateTargetWithTwoUpdatesWithOneOverride(knownTargetId); // not allowed methods mvc.perform(post(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING)) 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 0a7d7602c..35e4b3ee5 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 @@ -74,7 +74,7 @@ import org.springframework.web.context.WebApplicationContext; @Import(TestChannelBinderConfiguration.class) @Feature("Component Tests - Management API") @Story("Basic auth Userinfo Resource") -public class MgmtBasicAuthResourceTest { +class MgmtBasicAuthResourceTest { @Autowired protected WebApplicationContext webApplicationContext; @@ -86,7 +86,7 @@ public class MgmtBasicAuthResourceTest { @Test @Description("Test of userinfo api with basic auth validation") @WithUser(principal = TEST_USER) - public void validateBasicAuthWithUserDetails() throws Exception { + void validateBasicAuthWithUserDetails() throws Exception { withSecurityMock().perform(get(MgmtRestConstants.AUTH_V1_REQUEST_MAPPING)) .andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print()) @@ -98,7 +98,7 @@ public class MgmtBasicAuthResourceTest { @Test @Description("Test of userinfo api with invalid basic auth fails") - public void validateBasicAuthFailsWithInvalidCredentials() throws Exception { + void validateBasicAuthFailsWithInvalidCredentials() throws Exception { defaultMock.perform(get(MgmtRestConstants.AUTH_V1_REQUEST_MAPPING) .header(HttpHeaders.AUTHORIZATION, getBasicAuth("wrongUser", "wrongSecret"))) .andDo(MockMvcResultPrinter.print()) diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java index 2efe8bb4b..5bc87dd3f 100644 --- a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java +++ b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java @@ -790,7 +790,7 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr @Description("Ensures that multiple DS requested are listed with expected payload.") public void getDistributionSets() throws Exception { // prepare test data - assertThat(distributionSetManagement.findByCompleted(PAGE, true)).hasSize(0); + assertThat(distributionSetManagement.findByCompleted(PAGE, true)).isEmpty(); DistributionSet set = testdataFactory.createDistributionSet("one"); set = distributionSetManagement.update(entityFactory.distributionSet().update(set.getId()) @@ -865,7 +865,7 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr @WithUser(principal = "uploadTester", allSpPermissions = true) @Description("Ensures that multipe DS posted to API are created in the repository.") public void createDistributionSets() throws Exception { - assertThat(distributionSetManagement.findByCompleted(PAGE, true)).hasSize(0); + assertThat(distributionSetManagement.findByCompleted(PAGE, true)).isEmpty(); final SoftwareModule ah = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_APP); final SoftwareModule jvm = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_RT); final SoftwareModule os = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_OS); @@ -925,7 +925,7 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr @Description("Ensures that DS deletion request to API is reflected by the repository.") public void deleteUnassignedistributionSet() throws Exception { // prepare test data - assertThat(distributionSetManagement.findByCompleted(PAGE, true)).hasSize(0); + assertThat(distributionSetManagement.findByCompleted(PAGE, true)).isEmpty(); final DistributionSet set = testdataFactory.createDistributionSet("one"); @@ -953,7 +953,7 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr @Description("Ensures that assigned DS deletion request to API is reflected by the repository by means of deleted flag set.") public void deleteAssignedDistributionSet() throws Exception { // prepare test data - assertThat(distributionSetManagement.findByCompleted(PAGE, true)).hasSize(0); + assertThat(distributionSetManagement.findByCompleted(PAGE, true)).isEmpty(); final DistributionSet set = testdataFactory.createDistributionSet("one"); testdataFactory.createTarget("test"); @@ -976,14 +976,14 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr .andExpect(jsonPath("$.deleted", equalTo(true))); // check repository content - assertThat(distributionSetManagement.findByCompleted(PAGE, true)).hasSize(0); + assertThat(distributionSetManagement.findByCompleted(PAGE, true)).isEmpty(); } @Test @Description("Ensures that DS property update request to API is reflected by the repository.") public void updateDistributionSet() throws Exception { // prepare test data - assertThat(distributionSetManagement.findByCompleted(PAGE, true)).hasSize(0); + assertThat(distributionSetManagement.findByCompleted(PAGE, true)).isEmpty(); final DistributionSet set = testdataFactory.createDistributionSet("one"); assertThat(distributionSetManagement.count()).isEqualTo(1); @@ -1002,10 +1002,10 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr final DistributionSet setupdated = distributionSetManagement.get(set.getId()).get(); - assertThat(setupdated.isRequiredMigrationStep()).isEqualTo(true); + assertThat(setupdated.isRequiredMigrationStep()).isTrue(); assertThat(setupdated.getVersion()).isEqualTo("anotherVersion"); assertThat(setupdated.getName()).isEqualTo(set.getName()); - assertThat(setupdated.isDeleted()).isEqualTo(false); + assertThat(setupdated.isDeleted()).isFalse(); } @Test @@ -1013,7 +1013,7 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr public void updateRequiredMigrationStepFailsIfDistributionSetisInUse() throws Exception { // prepare test data - assertThat(distributionSetManagement.findByCompleted(PAGE, true)).hasSize(0); + assertThat(distributionSetManagement.findByCompleted(PAGE, true)).isEmpty(); final DistributionSet set = testdataFactory.createDistributionSet("one"); assignDistributionSet(set.getId(), testdataFactory.createTarget().getControllerId()); @@ -1028,7 +1028,7 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr final DistributionSet setupdated = distributionSetManagement.get(set.getId()).get(); - assertThat(setupdated.isRequiredMigrationStep()).isEqualTo(false); + assertThat(setupdated.isRequiredMigrationStep()).isFalse(); assertThat(setupdated.getVersion()).isEqualTo(set.getVersion()); assertThat(setupdated.getName()).isEqualTo(set.getName()); } @@ -1674,7 +1674,7 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr @Description("Tests the lock. It is verified that the distribution set can be marked as locked through update operation.") void lockDistributionSet() throws Exception { // prepare test data - assertThat(distributionSetManagement.findByCompleted(PAGE, true)).hasSize(0); + assertThat(distributionSetManagement.findByCompleted(PAGE, true)).isEmpty(); final DistributionSet set = testdataFactory.createDistributionSet("one"); assertThat(distributionSetManagement.count()).isEqualTo(1); @@ -1689,14 +1689,14 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr .andExpect(jsonPath("$.locked", equalTo(true))); final DistributionSet updatedSet = distributionSetManagement.get(set.getId()).get(); - assertThat(updatedSet.isLocked()).isEqualTo(true); + assertThat(updatedSet.isLocked()).isTrue(); } @Test @Description("Tests the unlock.") void unlockDistributionSet() throws Exception { // prepare test data - assertThat(distributionSetManagement.findByCompleted(PAGE, true)).hasSize(0); + assertThat(distributionSetManagement.findByCompleted(PAGE, true)).isEmpty(); final DistributionSet set = testdataFactory.createDistributionSet("one"); assertThat(distributionSetManagement.count()).isEqualTo(1); @@ -1715,7 +1715,7 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr .andExpect(jsonPath("$.locked", equalTo(false))); final DistributionSet updatedSet = distributionSetManagement.get(set.getId()).get(); - assertThat(updatedSet.isLocked()).isEqualTo(false); + assertThat(updatedSet.isLocked()).isFalse(); } private static Stream confirmationOptions() { diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/MaintenanceScheduleHelper.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/MaintenanceScheduleHelper.java index 1470cc577..9e958b4cc 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/MaintenanceScheduleHelper.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/MaintenanceScheduleHelper.java @@ -22,6 +22,7 @@ import com.cronutils.model.definition.CronDefinitionBuilder; import com.cronutils.model.time.ExecutionTime; import com.cronutils.parser.CronParser; import org.eclipse.hawkbit.repository.exception.InvalidMaintenanceScheduleException; +import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; /** @@ -170,14 +171,14 @@ public final class MaintenanceScheduleHelper { } private static boolean atLeastOneNotEmpty(final String cronSchedule, final String duration, final String timezone) { - return !(StringUtils.isEmpty(cronSchedule) && StringUtils.isEmpty(duration) && StringUtils.isEmpty(timezone)); + return !(ObjectUtils.isEmpty(cronSchedule) && ObjectUtils.isEmpty(duration) && ObjectUtils.isEmpty(timezone)); } private static boolean allNotEmpty(final String cronSchedule, final String duration, final String timezone) { - return !StringUtils.isEmpty(cronSchedule) && !StringUtils.isEmpty(duration) && !StringUtils.isEmpty(timezone); + return !ObjectUtils.isEmpty(cronSchedule) && !ObjectUtils.isEmpty(duration) && !ObjectUtils.isEmpty(timezone); } private static LocalTime convertDurationToLocalTime(final String timeInterval) { - return LocalTime.parse(StringUtils.trimWhitespace(timeInterval)); + return LocalTime.parse(timeInterval.strip()); } } diff --git a/hawkbit-repository/hawkbit-repository-api/src/test/java/org/eclipse/hawkbit/repository/MaintenanceScheduleHelperTest.java b/hawkbit-repository/hawkbit-repository-api/src/test/java/org/eclipse/hawkbit/repository/MaintenanceScheduleHelperTest.java index 0aedc4593..40b182529 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/test/java/org/eclipse/hawkbit/repository/MaintenanceScheduleHelperTest.java +++ b/hawkbit-repository/hawkbit-repository-api/src/test/java/org/eclipse/hawkbit/repository/MaintenanceScheduleHelperTest.java @@ -24,25 +24,25 @@ import org.junit.jupiter.api.Test; @Feature("Unit Tests - Repository") @Story("Maintenance Schedule Utility") -public class MaintenanceScheduleHelperTest { +class MaintenanceScheduleHelperTest { @Test @Description("Verifies that the Cron object is returned for valid cron expression") - public void getCronFromExpressionValid() { + void getCronFromExpressionValid() { final String validCron = "0 0 0 ? * 6"; // at 00:00 every Saturday assertThat(MaintenanceScheduleHelper.getCronFromExpression(validCron)).isNotNull().isInstanceOf(Cron.class); } @Test @Description("Verifies that the Duration object is returned for valid duration format (hh:mm or hh:mm:ss)") - public void convertToISODurationValid() { + void convertToISODurationValid() { final String duration = "00:10"; assertThat(MaintenanceScheduleHelper.convertToISODuration(duration)).isNotNull().isInstanceOf(Duration.class); } @Test @Description("Verifies that the InvalidMaintenanceScheduleException is thrown for invalid duration format") - public void validateDurationInvalid() { + void validateDurationInvalid() { final String duration = "10"; assertThatThrownBy(() -> MaintenanceScheduleHelper.validateDuration(duration)) .isInstanceOf(InvalidMaintenanceScheduleException.class).hasMessage("Provided duration is not valid") @@ -51,7 +51,7 @@ public class MaintenanceScheduleHelperTest { @Test @Description("Verifies that the InvalidMaintenanceScheduleException is thrown for invalid cron expression") - public void validateCronScheduleInvalid() { + void validateCronScheduleInvalid() { final String invalidCron = "0 0 0 * * 6"; assertThatThrownBy(() -> MaintenanceScheduleHelper.validateCronSchedule(invalidCron)) .isInstanceOf(InvalidMaintenanceScheduleException.class) @@ -60,7 +60,7 @@ public class MaintenanceScheduleHelperTest { @Test @Description("Verifies that there is a maintenance window available for correct schedule, duration and timezone") - public void getNextMaintenanceWindowValid() { + void getNextMaintenanceWindowValid() { final ZonedDateTime currentTime = ZonedDateTime.now(); final String cronSchedule = String.format("0 %d %d %d %d ? %d", currentTime.getMinute(), currentTime.getHour(), currentTime.getDayOfMonth(), currentTime.getMonthValue(), currentTime.getYear()); @@ -71,7 +71,7 @@ public class MaintenanceScheduleHelperTest { @Test @Description("Verifies the maintenance schedule when only one required field is present") - public void validateMaintenanceScheduleAtLeastOneNotEmpty() { + void validateMaintenanceScheduleAtLeastOneNotEmpty() { final String duration = "00:10"; assertThatThrownBy(() -> MaintenanceScheduleHelper.validateMaintenanceSchedule(null, duration, null)) .isInstanceOf(InvalidMaintenanceScheduleException.class) @@ -80,7 +80,7 @@ public class MaintenanceScheduleHelperTest { @Test @Description("Verifies that there is no valid maintenance window available, scheduled before current time") - public void validateMaintenanceScheduleBeforeCurrentTime() { + void validateMaintenanceScheduleBeforeCurrentTime() { ZonedDateTime currentTime = ZonedDateTime.now(); currentTime = currentTime.plusMinutes(-30); final String cronSchedule = String.format("0 %d %d %d %d ? %d", currentTime.getMinute(), currentTime.getHour(), diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaSoftwareModuleManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaSoftwareModuleManagement.java index 2db91b325..880638f81 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaSoftwareModuleManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaSoftwareModuleManagement.java @@ -183,7 +183,7 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) public void delete(final long id) { - delete(List.of(id)); + delete0(List.of(id)); } @Override @@ -191,6 +191,9 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) public void delete(final Collection ids) { + delete0(ids); + } + private void delete0(final Collection ids) { final List swModulesToDelete = softwareModuleRepository.findAllById(ids); if (swModulesToDelete.size() < ids.size()) { throw new EntityNotFoundException(SoftwareModule.class, ids, @@ -283,7 +286,7 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement { // touch to update revision and last modified timestamp JpaManagementHelper.touch(entityManager, softwareModuleRepository, (JpaSoftwareModule) get(id) .orElseThrow(() -> new EntityNotFoundException(SoftwareModule.class, id))); - return createJpaMetadataCreateStream(create).map(this::saveMetadata).collect(Collectors.toList()); + return createJpaMetadataCreateStream(create).map(this::saveMetadata).toList(); } else { // group by software module id to minimize database access final Map> groups = createJpaMetadataCreateStream(create) @@ -298,7 +301,7 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement { JpaManagementHelper.touch(entityManager, softwareModuleRepository, (JpaSoftwareModule) get(id) .orElseThrow(() -> new EntityNotFoundException(SoftwareModule.class, id))); return group.stream().map(this::saveMetadata); - }).collect(Collectors.toList()); + }).toList(); } } @@ -346,11 +349,10 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) public void deleteMetaData(final long id, final String key) { - final JpaSoftwareModuleMetadata metadata = (JpaSoftwareModuleMetadata) findMetaDataBySoftwareModuleId(id, - key).orElseThrow(() -> new EntityNotFoundException(SoftwareModuleMetadata.class, id, key)); + final JpaSoftwareModuleMetadata metadata = (JpaSoftwareModuleMetadata) findMetaDataBySoftwareModuleId0(id, key) + .orElseThrow(() -> new EntityNotFoundException(SoftwareModuleMetadata.class, id, key)); - JpaManagementHelper.touch(entityManager, softwareModuleRepository, - (JpaSoftwareModule) metadata.getSoftwareModule()); + JpaManagementHelper.touch(entityManager, softwareModuleRepository, metadata.getSoftwareModule()); softwareModuleMetadataRepository.deleteById(metadata.getId()); } @@ -427,6 +429,9 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement { @Override public Optional findMetaDataBySoftwareModuleId(final long id, final String key) { + return findMetaDataBySoftwareModuleId0(id, key); + } + private Optional findMetaDataBySoftwareModuleId0(final long id, final String key) { assertSoftwareModuleExists(id); return softwareModuleMetadataRepository.findById(new SwMetadataCompositeKey(id, key)) @@ -510,7 +515,7 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement { accessController.assertOperationAllowed(AccessController.Operation.DELETE, swModule)); final Set sha1Hashes = swModule.getArtifacts().stream().map(Artifact::getSha1Hash).collect(Collectors.toSet()); AfterTransactionCommitExecutorHolder.getInstance().getAfterCommit().afterCommit(() -> - sha1Hashes.forEach(sha1Hash -> ((JpaArtifactManagement) artifactManagement).clearArtifactBinary(sha1Hash))); + sha1Hashes.forEach(((JpaArtifactManagement) artifactManagement)::clearArtifactBinary)); } private Specification buildSmSearchQuerySpec(final String searchText) { diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaSystemManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaSystemManagement.java index fd37d9610..5dc4810ea 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaSystemManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaSystemManagement.java @@ -176,6 +176,9 @@ public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, Syst // Exception squid:S2229 - calling findTenants without transaction is intended in this case @SuppressWarnings("squid:S2229") public void forEachTenant(final Consumer consumer) { + forEachTenant0(consumer); + } + private void forEachTenant0(final Consumer consumer) { Page tenants; Pageable query = PageRequest.of(0, MAX_TENANTS_QUERY); do { @@ -281,7 +284,7 @@ public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, Syst } private void usageStatsPerTenant(final SystemUsageReportWithTenants report) { - forEachTenant(tenant -> report.addTenantData(systemStatsManagement.getStatsOfTenant())); + forEachTenant0(tenant -> report.addTenantData(systemStatsManagement.getStatsOfTenant())); } private DistributionSetType createStandardSoftwareDataSetup() { diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaTargetManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaTargetManagement.java index b5b50d08d..d2f5b8ea0 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaTargetManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaTargetManagement.java @@ -606,9 +606,8 @@ public class JpaTargetManagement implements TargetManagement { public Target assignType(final String controllerId, final Long targetTypeId) { final JpaTarget target = getByControllerIdAndThrowIfNotFound(controllerId); - targetRepository.getAccessController().ifPresent(acm -> { - acm.assertOperationAllowed(AccessController.Operation.UPDATE, target); - }); + targetRepository.getAccessController().ifPresent(acm -> + acm.assertOperationAllowed(AccessController.Operation.UPDATE, target)); final JpaTargetType targetType = getTargetTypeByIdAndThrowIfNotFound(targetTypeId); target.setTargetType(targetType); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaTenantConfigurationManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaTenantConfigurationManagement.java index aa522c689..3d3d37fd9 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaTenantConfigurationManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaTenantConfigurationManagement.java @@ -286,7 +286,7 @@ public class JpaTenantConfigurationManagement implements TenantConfigurationMana @SuppressWarnings("squid:S1172") private void assertAutoCloseValueChange(final String key, final JpaTenantConfiguration valueChange) { if (REPOSITORY_ACTIONS_AUTOCLOSE_ENABLED.equals(key) - && getConfigurationValue(MULTI_ASSIGNMENTS_ENABLED, Boolean.class).getValue()) { + && Boolean.TRUE.equals(getConfigurationValue(MULTI_ASSIGNMENTS_ENABLED, Boolean.class).getValue())) { log.debug( "The property '{}' must not be changed because the Multi-Assignments feature is currently enabled.", key); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetType.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetType.java index bfea5c59a..b6e7cbd38 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetType.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetType.java @@ -43,6 +43,7 @@ import org.eclipse.hawkbit.repository.model.helper.EventPublisherHolder; @Table(name = "sp_target_type", indexes = { @Index(name = "sp_idx_target_type_prim", columnList = "tenant,id") }, uniqueConstraints = { @UniqueConstraint(columnNames = { "name", "tenant" }, name = "uk_target_type_name") }) +@SuppressWarnings("java:S2160") // the super class equals/hashcode shall be used public class JpaTargetType extends AbstractJpaTypeEntity implements TargetType, EventAwareEntity { @Serial diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/JpaSpecificationEntityGraphExecutor.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/JpaSpecificationEntityGraphExecutor.java index 36c5ad773..0350202b1 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/JpaSpecificationEntityGraphExecutor.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/JpaSpecificationEntityGraphExecutor.java @@ -11,19 +11,11 @@ package org.eclipse.hawkbit.repository.jpa.repository; import java.util.List; import java.util.Optional; -import java.util.function.Function; -import jakarta.persistence.criteria.CriteriaBuilder; -import jakarta.persistence.criteria.CriteriaQuery; -import jakarta.persistence.criteria.Root; - -import org.eclipse.hawkbit.repository.model.BaseEntity; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Slice; import org.springframework.data.domain.Sort; import org.springframework.data.jpa.domain.Specification; -import org.springframework.data.repository.query.FluentQuery; import org.springframework.lang.Nullable; /** diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/LazyControllerManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/LazyControllerManagementTest.java index 3883014a6..0004d32d9 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/LazyControllerManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/LazyControllerManagementTest.java @@ -32,7 +32,7 @@ import org.springframework.test.context.TestPropertySource; @TestPropertySource(locations = "classpath:/jpa-test.properties", properties = { "hawkbit.server.repository.eagerPollPersistence=false", "hawkbit.server.repository.pollPersistenceFlushTime=1000" }) -public class LazyControllerManagementTest extends AbstractJpaIntegrationTest { +class LazyControllerManagementTest extends AbstractJpaIntegrationTest { @Autowired private RepositoryProperties repositoryProperties; @@ -42,7 +42,7 @@ public class LazyControllerManagementTest extends AbstractJpaIntegrationTest { @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 2) }) - public void lazyFindOrRegisterTargetIfItDoesNotExist() throws InterruptedException { + void lazyFindOrRegisterTargetIfItDoesNotExist() throws InterruptedException { final Target target = controllerManagement.findOrRegisterTargetIfItDoesNotExist("AA", LOCALHOST); assertThat(target).as("target should not be null").isNotNull(); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLDistributionSetFieldTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLDistributionSetFieldTest.java index 1699c9e1f..a4c69a0e4 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLDistributionSetFieldTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLDistributionSetFieldTest.java @@ -36,13 +36,13 @@ import org.springframework.orm.jpa.vendor.Database; @Feature("Component Tests - Repository") @Story("RSQL filter distribution set") -public class RSQLDistributionSetFieldTest extends AbstractJpaIntegrationTest { +class RSQLDistributionSetFieldTest extends AbstractJpaIntegrationTest { private DistributionSet ds; private SoftwareModule sm; @BeforeEach - public void setupBeforeTest() { + void setupBeforeTest() { sm = testdataFactory.createSoftwareModuleApp("SM"); @@ -70,7 +70,7 @@ public class RSQLDistributionSetFieldTest extends AbstractJpaIntegrationTest { @Test @Description("Test filter distribution set by id") - public void testFilterByParameterId() { + void testFilterByParameterId() { assertRSQLQuery(DistributionSetFields.ID.name() + "==" + ds.getId(), 1); assertRSQLQuery(DistributionSetFields.ID.name() + "!=" + ds.getId(), 4); assertRSQLQuery(DistributionSetFields.ID.name() + "==" + -1, 0); @@ -87,7 +87,7 @@ public class RSQLDistributionSetFieldTest extends AbstractJpaIntegrationTest { @Test @Description("Test filter distribution set by name") - public void testFilterByParameterName() { + void testFilterByParameterName() { assertRSQLQuery(DistributionSetFields.NAME.name() + "==DS", 1); assertRSQLQuery(DistributionSetFields.NAME.name() + "!=DS", 4); assertRSQLQuery(DistributionSetFields.NAME.name() + "==*DS", 4); @@ -98,7 +98,7 @@ public class RSQLDistributionSetFieldTest extends AbstractJpaIntegrationTest { @Test @Description("Test filter distribution set by assigned software module") - public void testFilterBySoftwareModule() { + void testFilterBySoftwareModule() { assertRSQLQuery(DistributionSetFields.MODULE.name() + "." + SoftwareModuleFields.NAME.name() + "==" + sm.getName(), 1); assertRSQLQuery(DistributionSetFields.MODULE.name() + "." + SoftwareModuleFields.ID.name() + "==" + sm.getId(), 1); assertRSQLQuery(DistributionSetFields.MODULE.name() + "." + SoftwareModuleFields.NAME.name() + "==noExist", 0); @@ -108,7 +108,7 @@ public class RSQLDistributionSetFieldTest extends AbstractJpaIntegrationTest { @Test @Description("Test filter distribution set by description") - public void testFilterByParameterDescription() { + void testFilterByParameterDescription() { assertRSQLQuery(DistributionSetFields.DESCRIPTION.name() + "==''", 1); assertRSQLQuery(DistributionSetFields.DESCRIPTION.name() + "!=''", 4); assertRSQLQuery(DistributionSetFields.DESCRIPTION.name() + "==DS", 1); @@ -123,7 +123,7 @@ public class RSQLDistributionSetFieldTest extends AbstractJpaIntegrationTest { @Test @Description("Test filter distribution set by version") - public void testFilterByParameterVersion() { + void testFilterByParameterVersion() { assertRSQLQuery(DistributionSetFields.VERSION.name() + "==" + TestdataFactory.DEFAULT_VERSION, 1); assertRSQLQuery(DistributionSetFields.VERSION.name() + "!=" + TestdataFactory.DEFAULT_VERSION, 4); assertRSQLQuery(DistributionSetFields.VERSION.name() + "=in=(" + TestdataFactory.DEFAULT_VERSION + ",1.0.0,1.0.1)", 3); @@ -132,7 +132,7 @@ public class RSQLDistributionSetFieldTest extends AbstractJpaIntegrationTest { @Test @Description("Test filter distribution set by complete property") - public void testFilterByAttributeComplete() { + void testFilterByAttributeComplete() { assertRSQLQuery(DistributionSetFields.COMPLETE.name() + "==true", 3); try { assertRSQLQuery(DistributionSetFields.COMPLETE.name() + "==noExist*", 0); @@ -145,7 +145,7 @@ public class RSQLDistributionSetFieldTest extends AbstractJpaIntegrationTest { @Test @Description("Test filter distribution set by valid property") - public void testFilterByAttributeValid() { + void testFilterByAttributeValid() { assertRSQLQuery(DistributionSetFields.VALID.name() + "==true", 4); assertRSQLQuery(DistributionSetFields.VALID.name() + "==false", 1); assertThatExceptionOfType(RSQLParameterSyntaxException.class) @@ -156,7 +156,7 @@ public class RSQLDistributionSetFieldTest extends AbstractJpaIntegrationTest { @Test @Description("Test filter distribution set by tag name") - public void testFilterByTag() { + void testFilterByTag() { assertRSQLQuery(DistributionSetFields.TAG.name() + "==Tag1", 2); assertRSQLQuery(DistributionSetFields.TAG.name() + "!=Tag1", 3); assertRSQLQuery(DistributionSetFields.TAG.name() + "==T*", 2); @@ -167,7 +167,7 @@ public class RSQLDistributionSetFieldTest extends AbstractJpaIntegrationTest { @Test @Description("Test filter distribution set by type key") - public void testFilterByType() { + void testFilterByType() { assertRSQLQuery(DistributionSetFields.TYPE.name() + "==" + TestdataFactory.DS_TYPE_DEFAULT, 4); assertRSQLQuery(DistributionSetFields.TYPE.name() + "==noExist*", 0); assertRSQLQuery(DistributionSetFields.TYPE.name() + "=in=(" + TestdataFactory.DS_TYPE_DEFAULT + ",ecl)", 4); @@ -176,7 +176,7 @@ public class RSQLDistributionSetFieldTest extends AbstractJpaIntegrationTest { @Test @Description("Test filter distribution set by metadata") - public void testFilterByMetadata() { + void testFilterByMetadata() { createDistributionSetWithMetadata("key.dot", "value.dot"); assertRSQLQuery(DistributionSetFields.METADATA.name() + ".metaKey==metaValue", 1); diff --git a/hawkbit-sdk/hawkbit-sdk-mgmt/src/main/java/org/eclipse/hawkbit/sdk/mgmt/MgmtApi.java b/hawkbit-sdk/hawkbit-sdk-mgmt/src/main/java/org/eclipse/hawkbit/sdk/mgmt/MgmtApi.java index c2df9641f..4afaf7f6c 100644 --- a/hawkbit-sdk/hawkbit-sdk-mgmt/src/main/java/org/eclipse/hawkbit/sdk/mgmt/MgmtApi.java +++ b/hawkbit-sdk/hawkbit-sdk-mgmt/src/main/java/org/eclipse/hawkbit/sdk/mgmt/MgmtApi.java @@ -59,17 +59,17 @@ public class MgmtApi { hawkbitClient.mgmtService(MgmtTenantManagementRestApi.class, tenant); final String gatewayToken = tenant.getGatewayToken(); if (ObjectUtils.isEmpty(gatewayToken)) { - if (!((Boolean) Objects.requireNonNull(mgmtTenantManagementRestApi + if (!(Boolean.TRUE.equals(Objects.requireNonNull(mgmtTenantManagementRestApi .getTenantConfigurationValue(AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED) - .getBody()).getValue())) { + .getBody()).getValue()))) { mgmtTenantManagementRestApi.updateTenantConfiguration( Map.of(AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED, true) ); } } else { - if (!((Boolean) Objects.requireNonNull(mgmtTenantManagementRestApi + if (!(Boolean.TRUE.equals(Objects.requireNonNull(mgmtTenantManagementRestApi .getTenantConfigurationValue(AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_ENABLED) - .getBody()).getValue())) { + .getBody()).getValue()))) { mgmtTenantManagementRestApi.updateTenantConfiguration( Map.of(AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_ENABLED, true) ); diff --git a/hawkbit-security/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/security/MdcHandler.java b/hawkbit-security/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/security/MdcHandler.java index e74bf663a..fd97baff6 100644 --- a/hawkbit-security/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/security/MdcHandler.java +++ b/hawkbit-security/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/security/MdcHandler.java @@ -33,8 +33,8 @@ import org.springframework.web.filter.OncePerRequestFilter; @NoArgsConstructor(access = AccessLevel.PRIVATE) public class MdcHandler { - public static String MDC_KEY_TENANT = "tenant"; - public static String MDC_KEY_USER = "user"; + public static final String MDC_KEY_TENANT = "tenant"; + public static final String MDC_KEY_USER = "user"; private static final MdcHandler SINGLETON = new MdcHandler();