Skip to content

Commit

Permalink
Sonar Fixes (#2232)
Browse files Browse the repository at this point in the history
Signed-off-by: Avgustin Marinov <[email protected]>
  • Loading branch information
avgustinmm authored Jan 24, 2025
1 parent 51054bd commit 0280d96
Show file tree
Hide file tree
Showing 16 changed files with 71 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
@Deprecated(forRemoval = true, since = "0.6.0")
@SuppressWarnings("java:S1133") // will be removed at some point
public class MgmtAssignedDistributionSetRequestBody {

@JsonProperty(value = "id", required = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
@Deprecated(forRemoval = true, since = "0.6.0")
@SuppressWarnings("java:S1133") // will be removed at some point
public class MgmtAssignedTargetRequestBody {

@JsonProperty(required = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
@Deprecated(forRemoval = true, since = "0.6.0")
@SuppressWarnings("java:S1133") // will be removed at some point
public class MgmtDistributionSetTagAssigmentResult {

@JsonProperty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,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
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
private final DistributionSetInvalidationManagement distributionSetInvalidationManagement;
private final TenantConfigHelper tenantConfigHelper;

@SuppressWarnings("java:S107")
MgmtDistributionSetResource(
final SoftwareModuleManagement softwareModuleManagement,
final TargetManagement targetManagement, final TargetFilterQueryManagement targetFilterQueryManagement,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,19 @@ private MgmtDistributionSetTypeMapper() {

}

static List<DistributionSetTypeCreate> smFromRequest(final EntityFactory entityFactory,
final Collection<MgmtDistributionSetTypeRequestBodyPost> smTypesRest) {
static List<DistributionSetTypeCreate> smFromRequest(final EntityFactory entityFactory, final Collection<MgmtDistributionSetTypeRequestBodyPost> smTypesRest) {
if (smTypesRest == null) {
return Collections.emptyList();
}

return smTypesRest.stream().map(smRest -> fromRequest(entityFactory, smRest)).collect(Collectors.toList());
return smTypesRest.stream().map(smRest -> fromRequest(entityFactory, smRest)).toList();
}

static List<MgmtDistributionSetType> toListResponse(final Collection<DistributionSetType> types) {
if (types == null) {
return Collections.emptyList();
}

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

static MgmtDistributionSetType toResponse(final DistributionSetType type) {
Expand Down Expand Up @@ -82,19 +79,18 @@ private static DistributionSetTypeCreate fromRequest(final EntityFactory entityF
final MgmtDistributionSetTypeRequestBodyPost smsRest) {
return entityFactory.distributionSetType().create().key(smsRest.getKey()).name(smsRest.getName())
.description(smsRest.getDescription()).colour(smsRest.getColour())
.mandatory(getMandatoryModules(smsRest)).optional(getOptionalmodules(smsRest));
.mandatory(getMandatoryModules(smsRest)).optional(getOptionalModules(smsRest));
}

private static Collection<Long> getMandatoryModules(final MgmtDistributionSetTypeRequestBodyPost smsRest) {
return Optional.ofNullable(smsRest.getMandatorymodules()).map(
modules -> modules.stream().map(MgmtSoftwareModuleTypeAssignment::getId).collect(Collectors.toList()))
return Optional.ofNullable(smsRest.getMandatorymodules())
.map(modules -> modules.stream().map(MgmtSoftwareModuleTypeAssignment::getId).toList())
.orElse(Collections.emptyList());
}

private static Collection<Long> getOptionalmodules(final MgmtDistributionSetTypeRequestBodyPost smsRest) {
return Optional.ofNullable(smsRest.getOptionalmodules()).map(
modules -> modules.stream().map(MgmtSoftwareModuleTypeAssignment::getId).collect(Collectors.toList()))
private static Collection<Long> getOptionalModules(final MgmtDistributionSetTypeRequestBodyPost smsRest) {
return Optional.ofNullable(smsRest.getOptionalmodules())
.map(modules -> modules.stream().map(MgmtSoftwareModuleTypeAssignment::getId).toList())
.orElse(Collections.emptyList());
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private String getBasicAuth(final String username, final String password) {
return "Basic " + Base64.getEncoder().encodeToString((username + ":" + password).getBytes());
}

private MockMvc withSecurityMock() throws Exception {
private MockMvc withSecurityMock() {
return createMvcWebAppContext(webApplicationContext).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,14 @@
import org.springframework.test.web.servlet.MvcResult;

/**
* With Spring Boot 2.2.x the default charset encoding became deprecated. In
* hawkBit we want to keep the old behavior for now and still return the charset
* in the response, which is achieved through enabling {@link Encoding} via
* properties.
* With Spring Boot 2.2.x the default charset encoding became deprecated. In hawkBit we want to keep the old behavior for now and still
* return the charset in the response, which is achieved through enabling {@link Encoding} via properties.
*/
@SpringBootTest(properties = { "server.servlet.encoding.charset=UTF-8", "server.servlet.encoding.force=true" })
@Import(HttpEncodingAutoConfiguration.class)
@Feature("Component Tests - Management API")
@Story("Response Content-Type")
@SuppressWarnings("java:S1874") // TODO for compatibility, to be checked if we really want to do that
public class MgmtContentTypeTest extends AbstractManagementApiIntegrationTest {

private final String dsName = "DS-ö";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -893,28 +893,28 @@ public void createDistributionSets() throws Exception {

assertThat(
JsonPath.compile("[0]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString())
.isEqualTo("http://localhost/rest/v1/distributionsets/" + one.getId());
.hasToString("http://localhost/rest/v1/distributionsets/" + one.getId());

assertThat(JsonPath.compile("[0]id").read(mvcResult.getResponse().getContentAsString()).toString())
.isEqualTo(String.valueOf(one.getId()));
.hasToString(String.valueOf(one.getId()));
assertThat(
JsonPath.compile("[1]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString())
.isEqualTo("http://localhost/rest/v1/distributionsets/" + two.getId());
.hasToString("http://localhost/rest/v1/distributionsets/" + two.getId());

assertThat(JsonPath.compile("[1]id").read(mvcResult.getResponse().getContentAsString()).toString())
.isEqualTo(String.valueOf(two.getId()));
.hasToString(String.valueOf(two.getId()));
assertThat(
JsonPath.compile("[2]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString())
.isEqualTo("http://localhost/rest/v1/distributionsets/" + three.getId());
.hasToString("http://localhost/rest/v1/distributionsets/" + three.getId());

assertThat(JsonPath.compile("[2]id").read(mvcResult.getResponse().getContentAsString()).toString())
.isEqualTo(String.valueOf(three.getId()));
.hasToString(String.valueOf(three.getId()));

// check in database
assertThat(distributionSetManagement.findByCompleted(PAGE, true)).hasSize(3);
assertThat(one.isRequiredMigrationStep()).isEqualTo(false);
assertThat(two.isRequiredMigrationStep()).isEqualTo(false);
assertThat(three.isRequiredMigrationStep()).isEqualTo(true);
assertThat(one.isRequiredMigrationStep()).isFalse();
assertThat(two.isRequiredMigrationStep()).isFalse();
assertThat(three.isRequiredMigrationStep()).isTrue();

assertThat(one.getCreatedAt()).isGreaterThanOrEqualTo(current);
assertThat(two.getCreatedAt()).isGreaterThanOrEqualTo(current);
Expand All @@ -938,7 +938,7 @@ public void deleteUnassignedistributionSet() throws Exception {

// check repository content
assertThat(distributionSetManagement.findByCompleted(PAGE, true)).isEmpty();
assertThat(distributionSetManagement.count()).isEqualTo(0);
assertThat(distributionSetManagement.count()).isZero();
}

@Test
Expand Down
Loading

0 comments on commit 0280d96

Please sign in to comment.