Skip to content

Commit

Permalink
Sonar Fixes (7) (#2216)
Browse files Browse the repository at this point in the history
Signed-off-by: Avgustin Marinov <[email protected]>
  • Loading branch information
avgustinmm authored Jan 21, 2025
1 parent f09db20 commit 3d390b9
Show file tree
Hide file tree
Showing 21 changed files with 101 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
*/
@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<? extends Class<?>> matchingClasses = scanResult.getAllClasses()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

/**
* Request Body for PUT.
*
* @deprecated Since 0.6.0
*/
@Data
@Accessors(chain = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@

@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.")
@ExpectEvents({
@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<DistributionSet> sets = testdataFactory.createDistributionSetsWithoutModules(setsAssigned);
Expand All @@ -64,8 +64,8 @@ public void toggleDistributionSetTagAssignment() throws Exception {

List<DistributionSet> 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"));
Expand All @@ -87,7 +87,7 @@ public void toggleDistributionSetTagAssignment() throws Exception {
@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<DistributionSet> sets = testdataFactory.createDistributionSetsWithoutModules(setsAssigned);
Expand All @@ -104,8 +104,8 @@ public void assignDistributionSetsWithRequestBody() throws Exception {

final List<DistributionSet> 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)));
Expand All @@ -117,7 +117,7 @@ public void assignDistributionSetsWithRequestBody() throws Exception {
@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<Target> targets = testdataFactory.createTargets(targetsAssigned);
Expand All @@ -126,8 +126,8 @@ public void toggleTargetTagAssignment() throws Exception {

List<Target> 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"));
Expand All @@ -148,24 +148,24 @@ public void toggleTargetTagAssignment() throws Exception {
@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<Target> targets = testdataFactory.createTargets(targetsAssigned);

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())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE));

final List<Target> 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)));
Expand All @@ -175,7 +175,7 @@ private ResultActions toggle(final DistributionSetTag tag, final List<Distributi
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())
Expand All @@ -196,7 +196,7 @@ private ResultActions toggle(final TargetTag tag, final List<Target> targets) th
.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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
Expand Down Expand Up @@ -41,7 +40,7 @@ public static List<MgmtAction> toResponse(final Collection<Action> actions, fina
}
return new ResponseList<>(actions.stream()
.map(action -> toResponse(action, repMode))
.collect(Collectors.toList()));
.toList());
}

static MgmtAction toResponse(final Action action, final MgmtRepresentationMode repMode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -61,7 +61,7 @@ static List<MetaData> fromRequestDsMetadata(final List<MgmtMetadata> metadata, f

return metadata.stream()
.map(metadataRest -> entityFactory.generateDsMetadata(metadataRest.getKey(), metadataRest.getValue()))
.collect(Collectors.toList());
.toList();
}

static MgmtDistributionSet toResponse(final DistributionSet distributionSet) {
Expand Down Expand Up @@ -111,7 +111,7 @@ static MgmtTargetAssignmentResponseBody toResponse(final DistributionSetAssignme
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;
}

Expand All @@ -123,7 +123,7 @@ static MgmtTargetAssignmentResponseBody toResponse(
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;
Expand All @@ -136,7 +136,7 @@ public static List<MgmtDistributionSet> toResponseDistributionSets(final Collect
}

return new ResponseList<>(
sets.stream().map(MgmtDistributionSetMapper::toResponse).collect(Collectors.toList()));
sets.stream().map(MgmtDistributionSetMapper::toResponse).toList());
}

static MgmtMetadata toResponseDsMetadata(final DistributionSetMetadata metadata) {
Expand All @@ -159,7 +159,7 @@ static List<MgmtDistributionSet> toResponseFromDsList(final List<DistributionSet
return Collections.emptyList();
}

return sets.stream().map(MgmtDistributionSetMapper::toResponse).collect(Collectors.toList());
return sets.stream().map(MgmtDistributionSetMapper::toResponse).toList();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,9 @@ public ResponseEntity<MgmtTargetAssignmentResponseBody> createAssignedTarget(
: 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));
}

Expand Down Expand Up @@ -338,7 +337,7 @@ public ResponseEntity<Void> assignSoftwareModules(
distributionSetId,
softwareModuleIDs.stream()
.map(MgmtSoftwareModuleAssignment::getId)
.collect(Collectors.toList()));
.toList());
return ResponseEntity.ok().build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,7 @@ void getMultipleActionsWithPagingLimitRequestParameter() throws Exception {
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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
@Import(TestChannelBinderConfiguration.class)
@Feature("Component Tests - Management API")
@Story("Basic auth Userinfo Resource")
public class MgmtBasicAuthResourceTest {
class MgmtBasicAuthResourceTest {

@Autowired
protected WebApplicationContext webApplicationContext;
Expand All @@ -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())
Expand All @@ -98,7 +98,7 @@ public void validateBasicAuthWithUserDetails() throws Exception {

@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())
Expand Down
Loading

0 comments on commit 3d390b9

Please sign in to comment.