Sonar Fixes (7) (#2216)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-01-21 22:13:54 +02:00
committed by GitHub
parent f09db20b71
commit 3d390b9ad7
21 changed files with 101 additions and 101 deletions

View File

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

View File

@@ -51,7 +51,7 @@ public final class MgmtDistributionSetMapper {
*/
static List<DistributionSetCreate> dsFromRequest(
final Collection<MgmtDistributionSetRequestBodyPost> 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<MetaData> fromRequestDsMetadata(final List<MgmtMetadata> 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<MgmtActionId> 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();
}
/**

View File

@@ -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<DistributionSetAssignmentResult> assignmentResults = deployManagement
.assignDistributionSets(deploymentRequests);
final List<DistributionSetAssignmentResult> 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();
}

View File

@@ -455,8 +455,7 @@ class MgmtActionResourceTest extends AbstractManagementApiIntegrationTest {
void invalidRequestsOnActionResource() throws Exception {
final String knownTargetId = "targetId";
final List<Action> actions = generateTargetWithTwoUpdatesWithOneOverride(knownTargetId);
final Long actionId = actions.get(0).getId();
generateTargetWithTwoUpdatesWithOneOverride(knownTargetId);
// not allowed methods
mvc.perform(post(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING))

View File

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

View File

@@ -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<Arguments> confirmationOptions() {