Sonar Fixes (#2233)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-01-24 15:41:06 +02:00
committed by GitHub
parent 0280d96d2c
commit a61e9cd6ae
66 changed files with 401 additions and 387 deletions

View File

@@ -387,8 +387,11 @@ public interface MgmtTargetTagRestApi {
@RequestBody List<String> controllerId);
enum OnNotFoundPolicy {
// if it has not found - operation fail
FAIL, // default
// if it has not found - do operation on found operation and fail indicating that not all are found
ON_WHAT_FOUND_AND_FAIL,
// if it has not found - do operation on found operation and success, silently
ON_WHAT_FOUND_AND_SUCCESS
}
}

View File

@@ -22,18 +22,18 @@ import org.junit.jupiter.api.Test;
@Feature("Unit Tests - Management API")
@Story("Paged List Handling")
public class PagedListTest {
class PagedListTest {
@Test
@Description("Ensures that a null payload entity throws an exception.")
public void createListWithNullContentThrowsException() {
void createListWithNullContentThrowsException() {
assertThatThrownBy(() -> new PagedList<>(null, 0))
.isInstanceOf(NullPointerException.class);
}
@Test
@Description("Create list with payload and verify content.")
public void createListWithContent() {
void createListWithContent() {
final long knownTotal = 2;
final List<String> knownContentList = new ArrayList<>();
knownContentList.add("content1");
@@ -44,7 +44,7 @@ public class PagedListTest {
@Test
@Description("Create list with payload and verify size values.")
public void createListWithSmallerTotalThanContentSizeIsOk() {
void createListWithSmallerTotalThanContentSizeIsOk() {
final long knownTotal = 0;
final List<String> knownContentList = new ArrayList<>();
knownContentList.add("content1");

View File

@@ -14,7 +14,6 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -24,7 +23,7 @@ import org.springframework.context.annotation.Description;
@Story("Retrieve all open action ids")
@Description("Tests for the MgmtTargetAssignmentResponseBody")
public class MgmtTargetAssignmentResponseBodyTest {
class MgmtTargetAssignmentResponseBodyTest {
private static final List<Long> ASSIGNED_ACTIONS = Arrays.asList(4L, 5L, 6L);
private static final int ALREADY_ASSIGNED_COUNT = 3;
@@ -32,7 +31,7 @@ public class MgmtTargetAssignmentResponseBodyTest {
@Test
@Description("Tests that the ActionIds are serialized correctly in MgmtTargetAssignmentResponseBody")
public void testActionIdsSerialization() throws IOException {
void testActionIdsSerialization() throws IOException {
final MgmtTargetAssignmentResponseBody responseBody = generateResponseBody();
final ObjectMapper objectMapper = new ObjectMapper();
final String responseBodyAsString = objectMapper.writeValueAsString(responseBody);
@@ -70,9 +69,8 @@ public class MgmtTargetAssignmentResponseBodyTest {
}
private static MgmtTargetAssignmentResponseBody generateResponseBody() {
MgmtTargetAssignmentResponseBody response = new MgmtTargetAssignmentResponseBody();
response.setAssignedActions(
ASSIGNED_ACTIONS.stream().map(id -> new MgmtActionId(CONTROLLER_ID, id)).collect(Collectors.toList()));
final MgmtTargetAssignmentResponseBody response = new MgmtTargetAssignmentResponseBody();
response.setAssignedActions(ASSIGNED_ACTIONS.stream().map(id -> new MgmtActionId(CONTROLLER_ID, id)).toList());
response.setAlreadyAssigned(ALREADY_ASSIGNED_COUNT);
return response;
}

View File

@@ -32,6 +32,7 @@ import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTarget;
@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 MgmtTargetTagAssigmentResult {
@JsonProperty

View File

@@ -16,7 +16,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionSetType;
import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionSetTypeRequestBodyPost;

View File

@@ -37,10 +37,13 @@ import org.springframework.web.context.WebApplicationContext;
@Scope(value = WebApplicationContext.SCOPE_REQUEST)
public class MgmtDownloadArtifactResource implements MgmtDownloadArtifactRestApi {
@Autowired
private SoftwareModuleManagement softwareModuleManagement;
@Autowired
private ArtifactManagement artifactManagement;
private final SoftwareModuleManagement softwareModuleManagement;
private final ArtifactManagement artifactManagement;
public MgmtDownloadArtifactResource(final SoftwareModuleManagement softwareModuleManagement, final ArtifactManagement artifactManagement) {
this.softwareModuleManagement = softwareModuleManagement;
this.artifactManagement = artifactManagement;
}
/**
* Handles the GET request for downloading an artifact.

View File

@@ -15,7 +15,6 @@ import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
@@ -68,7 +67,7 @@ final class MgmtRolloutMapper {
return Collections.emptyList();
}
return rollouts.stream().map(rollout -> toResponseRollout(rollout, withDetails)).collect(Collectors.toList());
return rollouts.stream().map(rollout -> toResponseRollout(rollout, withDetails)).toList();
}
static MgmtRolloutResponseBody toResponseRollout(final Rollout rollout, final boolean withDetails) {
@@ -200,14 +199,13 @@ final class MgmtRolloutMapper {
return conditions.build();
}
static List<MgmtRolloutGroupResponseBody> toResponseRolloutGroup(final List<RolloutGroup> rollouts,
final boolean confirmationFlowEnabled, final boolean withDetails) {
static List<MgmtRolloutGroupResponseBody> toResponseRolloutGroup(
final List<RolloutGroup> rollouts, final boolean confirmationFlowEnabled, final boolean withDetails) {
if (rollouts == null) {
return Collections.emptyList();
}
return rollouts.stream().map(group -> toResponseRolloutGroup(group, withDetails, confirmationFlowEnabled))
.collect(Collectors.toList());
return rollouts.stream().map(group -> toResponseRolloutGroup(group, withDetails, confirmationFlowEnabled)).toList();
}
static MgmtRolloutGroupResponseBody toResponseRolloutGroup(final RolloutGroup rolloutGroup,

View File

@@ -12,7 +12,6 @@ package org.eclipse.hawkbit.mgmt.rest.resource;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
import jakarta.validation.ValidationException;
@@ -147,7 +146,7 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi {
rolloutRequestBody).orElse(confirmationFlowActive);
return MgmtRolloutMapper.fromRequest(entityFactory, mgmtRolloutGroup)
.confirmationRequired(confirmationRequired);
}).collect(Collectors.toList());
}).toList();
rollout = rolloutManagement.create(create, rolloutGroups, rolloutGroupConditions);
} else if (rolloutRequestBody.getAmountGroups() != null) {
final boolean confirmationRequired = rolloutRequestBody.getConfirmationRequired() == null

View File

@@ -15,7 +15,6 @@ import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
@@ -57,7 +56,7 @@ public final class MgmtSoftwareModuleMapper {
.map(metadataRest -> entityFactory.softwareModuleMetadata().create(softwareModuleId)
.key(metadataRest.getKey()).value(metadataRest.getValue())
.targetVisible(metadataRest.isTargetVisible()))
.collect(Collectors.toList());
.toList();
}
static List<SoftwareModuleCreate> smFromRequest(final EntityFactory entityFactory,
@@ -66,7 +65,7 @@ public final class MgmtSoftwareModuleMapper {
return Collections.emptyList();
}
return smsRest.stream().map(smRest -> fromRequest(entityFactory, smRest)).collect(Collectors.toList());
return smsRest.stream().map(smRest -> fromRequest(entityFactory, smRest)).toList();
}
static List<MgmtSoftwareModule> toResponse(final Collection<SoftwareModule> softwareModules) {
@@ -74,8 +73,7 @@ public final class MgmtSoftwareModuleMapper {
return Collections.emptyList();
}
return new ResponseList<>(
softwareModules.stream().map(MgmtSoftwareModuleMapper::toResponse).collect(Collectors.toList()));
return new ResponseList<>(softwareModules.stream().map(MgmtSoftwareModuleMapper::toResponse).toList());
}
static List<MgmtSoftwareModuleMetadata> toResponseSwMetadata(final Collection<SoftwareModuleMetadata> metadata) {
@@ -83,7 +81,7 @@ public final class MgmtSoftwareModuleMapper {
return Collections.emptyList();
}
return metadata.stream().map(MgmtSoftwareModuleMapper::toResponseSwMetadata).collect(Collectors.toList());
return metadata.stream().map(MgmtSoftwareModuleMapper::toResponseSwMetadata).toList();
}
static MgmtSoftwareModuleMetadata toResponseSwMetadata(final SoftwareModuleMetadata metadata) {

View File

@@ -15,7 +15,6 @@ import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
@@ -39,7 +38,7 @@ final class MgmtSoftwareModuleTypeMapper {
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<MgmtSoftwareModuleType> toTypesResponse(final Collection<SoftwareModuleType> types) {
@@ -47,7 +46,7 @@ final class MgmtSoftwareModuleTypeMapper {
return Collections.emptyList();
}
return new ResponseList<>(types.stream().map(MgmtSoftwareModuleTypeMapper::toResponse).collect(Collectors.toList()));
return new ResponseList<>(types.stream().map(MgmtSoftwareModuleTypeMapper::toResponse).toList());
}
static MgmtSoftwareModuleType toResponse(final SoftwareModuleType type) {

View File

@@ -70,8 +70,7 @@ public class MgmtSystemManagementResource implements MgmtSystemManagementRestApi
.setOverallArtifactVolumeInBytes(report.getOverallArtifactVolumeInBytes())
.setOverallTargets(report.getOverallTargets()).setOverallTenants(report.getTenants().size());
result.setTenantStats(report.getTenants().stream().map(MgmtSystemManagementResource::convertTenant)
.collect(Collectors.toList()));
result.setTenantStats(report.getTenants().stream().map(MgmtSystemManagementResource::convertTenant).toList());
return ResponseEntity.ok(result);
}
@@ -89,7 +88,7 @@ public class MgmtSystemManagementResource implements MgmtSystemManagementRestApi
.ok(cacheNames.stream().map(cacheManager::getCache)
.filter(Objects::nonNull)
.map(cache -> new MgmtSystemCache(cache.getName(), Collections.emptyList()))
.collect(Collectors.toList()));
.toList());
}
/**

View File

@@ -15,7 +15,6 @@ import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
@@ -111,7 +110,7 @@ final class MgmtTagMapper {
return tags.stream()
.map(tagRest -> entityFactory.tag().create().name(tagRest.getName())
.description(tagRest.getDescription()).colour(tagRest.getColour()))
.collect(Collectors.toList());
.toList();
}
private static void mapTag(final MgmtTag response, final Tag tag) {

View File

@@ -38,12 +38,12 @@ import org.springframework.util.CollectionUtils;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class MgmtTargetFilterQueryMapper {
static List<MgmtTargetFilterQuery> toResponse(final List<TargetFilterQuery> filters,
final boolean confirmationFlowEnabled, final boolean isRepresentationFull) {
static List<MgmtTargetFilterQuery> toResponse(
final List<TargetFilterQuery> filters, final boolean confirmationFlowEnabled, final boolean isRepresentationFull) {
if (CollectionUtils.isEmpty(filters)) {
return Collections.emptyList();
}
return filters.stream().map(filter -> toResponse(filter, confirmationFlowEnabled, isRepresentationFull)).collect(Collectors.toList());
return filters.stream().map(filter -> toResponse(filter, confirmationFlowEnabled, isRepresentationFull)).toList();
}
static MgmtTargetFilterQuery toResponse(final TargetFilterQuery filter, final boolean confirmationFlowEnabled,

View File

@@ -19,7 +19,6 @@ import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
@@ -124,7 +123,7 @@ public final class MgmtTargetMapper {
final Function<Target, PollStatus> pollStatusResolver = configHelper.pollStatusResolver();
return new ResponseList<>(
targets.stream().map(target -> toResponse(target, configHelper, pollStatusResolver)).collect(Collectors.toList()));
targets.stream().map(target -> toResponse(target, configHelper, pollStatusResolver)).toList());
}
/**
@@ -194,7 +193,7 @@ public final class MgmtTargetMapper {
}
return targetsRest.stream().map(targetRest -> fromRequest(entityFactory, targetRest))
.collect(Collectors.toList());
.toList();
}
static List<MetaData> fromRequestTargetMetadata(final List<MgmtMetadata> metadata,
@@ -205,7 +204,7 @@ public final class MgmtTargetMapper {
return metadata.stream().map(
metadataRest -> entityFactory.generateTargetMetadata(metadataRest.getKey(), metadataRest.getValue()))
.collect(Collectors.toList());
.toList();
}
static List<MgmtActionStatus> toActionStatusRestResponse(final Collection<ActionStatus> actionStatus,
@@ -219,7 +218,7 @@ public final class MgmtTargetMapper {
deploymentManagement.findMessagesByActionStatusId(
PageRequest.of(0, MgmtRestConstants.REQUEST_PARAMETER_PAGING_MAX_LIMIT), status.getId())
.getContent()))
.collect(Collectors.toList());
.toList();
}
static MgmtAction toResponse(final String targetId, final Action action) {
@@ -317,7 +316,7 @@ public final class MgmtTargetMapper {
}
static List<MgmtMetadata> toResponseTargetMetadata(final List<TargetMetadata> metadata) {
return metadata.stream().map(MgmtTargetMapper::toResponseTargetMetadata).collect(Collectors.toList());
return metadata.stream().map(MgmtTargetMapper::toResponseTargetMetadata).toList();
}
private static void addPollStatus(final Target target, final MgmtTarget targetRest, final Function<Target, PollStatus> pollStatusResolver) {

View File

@@ -137,7 +137,7 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
@Override
public ResponseEntity<MgmtTarget> updateTarget(final String targetId, final MgmtTargetRequestBody targetRest) {
if (targetRest.getRequestAttributes() != null) {
if (targetRest.getRequestAttributes()) {
if (Boolean.TRUE.equals(targetRest.getRequestAttributes())) {
targetManagement.requestControllerAttributes(targetId);
} else {
return ResponseEntity.badRequest().build();
@@ -336,7 +336,7 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
: dsAssignment.getConfirmationRequired();
return MgmtDeploymentRequestMapper.createAssignmentRequestBuilder(dsAssignment, targetId)
.setConfirmationRequired(isConfirmationRequired).build();
}).collect(Collectors.toList());
}).toList();
final List<DistributionSetAssignmentResult> assignmentResults = deploymentManagement
.assignDistributionSets(deploymentRequests);

View File

@@ -157,11 +157,9 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi {
} else {
final AtomicReference<Collection<String>> notFound = new AtomicReference<>();
this.targetManagement.assignTag(controllerIds, targetTagId, notFound::set);
if (notFound.get() != null) {
// has not found
if (onNotFoundPolicy == OnNotFoundPolicy.ON_WHAT_FOUND_AND_FAIL) {
throw new EntityNotFoundException(Target.class, notFound.get());
} // else - success
if (notFound.get() != null && onNotFoundPolicy == OnNotFoundPolicy.ON_WHAT_FOUND_AND_FAIL) {
// has not found and ON_WHAT_FOUND_AND_FAIL
throw new EntityNotFoundException(Target.class, notFound.get());
}
}
return ResponseEntity.ok().build();
@@ -183,11 +181,9 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi {
} else {
final AtomicReference<Collection<String>> notFound = new AtomicReference<>();
this.targetManagement.unassignTag(controllerIds, targetTagId, notFound::set);
if (notFound.get() != null) {
// has not found
if (onNotFoundPolicy == OnNotFoundPolicy.ON_WHAT_FOUND_AND_FAIL) {
throw new EntityNotFoundException(Target.class, notFound.get());
} // else - success
if (notFound.get() != null && onNotFoundPolicy == OnNotFoundPolicy.ON_WHAT_FOUND_AND_FAIL) {
// has not found and ON_WHAT_FOUND_AND_FAIL
throw new EntityNotFoundException(Target.class, notFound.get());
}
}
return ResponseEntity.ok().build();

View File

@@ -16,7 +16,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
@@ -43,14 +42,14 @@ public final class MgmtTargetTypeMapper {
}
return targetTypesRest.stream()
.map(targetRest -> fromRequest(entityFactory, targetRest))
.collect(Collectors.toList());
.toList();
}
static List<MgmtTargetType> toListResponse(final List<TargetType> types) {
if (types == null) {
return Collections.emptyList();
}
return new ResponseList<>(types.stream().map(MgmtTargetTypeMapper::toResponse).collect(Collectors.toList()));
return new ResponseList<>(types.stream().map(MgmtTargetTypeMapper::toResponse).toList());
}
static MgmtTargetType toResponse(final TargetType type) {
@@ -78,7 +77,7 @@ public final class MgmtTargetTypeMapper {
private static Collection<Long> getDistributionSets(final MgmtTargetTypeRequestBodyPost targetTypesRest) {
return Optional.ofNullable(targetTypesRest.getCompatibledistributionsettypes())
.map(ds -> ds.stream().map(MgmtDistributionSetTypeAssignment::getId).collect(Collectors.toList()))
.map(ds -> ds.stream().map(MgmtDistributionSetTypeAssignment::getId).toList())
.orElse(Collections.emptyList());
}
}
}

View File

@@ -23,7 +23,7 @@ import org.eclipse.hawkbit.repository.model.TenantConfigurationValue;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class MgmtTenantManagementMapper {
public static String DEFAULT_DISTRIBUTION_SET_TYPE_KEY = "default.ds.type";
public static final String DEFAULT_DISTRIBUTION_SET_TYPE_KEY = "default.ds.type";
public static MgmtSystemTenantConfigurationValue toResponseTenantConfigurationValue(
final String key, final TenantConfigurationValue<?> repoConfValue) {

View File

@@ -891,23 +891,20 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
.getWithDetails(distributionSetManagement.findByRsql("name==three", PAGE).getContent().get(0).getId())
.get();
assertThat(
JsonPath.compile("[0]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString())
assertThat((Object)JsonPath.compile("[0]_links.self.href").read(mvcResult.getResponse().getContentAsString()))
.hasToString("http://localhost/rest/v1/distributionsets/" + one.getId());
assertThat(JsonPath.compile("[0]id").read(mvcResult.getResponse().getContentAsString()).toString())
assertThat((Object)JsonPath.compile("[0]id").read(mvcResult.getResponse().getContentAsString()))
.hasToString(String.valueOf(one.getId()));
assertThat(
JsonPath.compile("[1]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString())
assertThat((Object)JsonPath.compile("[1]_links.self.href").read(mvcResult.getResponse().getContentAsString()))
.hasToString("http://localhost/rest/v1/distributionsets/" + two.getId());
assertThat(JsonPath.compile("[1]id").read(mvcResult.getResponse().getContentAsString()).toString())
assertThat((Object)JsonPath.compile("[1]id").read(mvcResult.getResponse().getContentAsString()))
.hasToString(String.valueOf(two.getId()));
assertThat(
JsonPath.compile("[2]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString())
assertThat((Object)JsonPath.compile("[2]_links.self.href").read(mvcResult.getResponse().getContentAsString()))
.hasToString("http://localhost/rest/v1/distributionsets/" + three.getId());
assertThat(JsonPath.compile("[2]id").read(mvcResult.getResponse().getContentAsString()).toString())
assertThat((Object)JsonPath.compile("[2]id").read(mvcResult.getResponse().getContentAsString()))
.hasToString(String.valueOf(three.getId()));
// check in database

View File

@@ -685,14 +685,11 @@ class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIntegrati
assertThat(created2.getOptionalModuleTypes()).containsOnly(osType, runtimeType, appType);
assertThat(created3.getMandatoryModuleTypes()).containsOnly(osType, runtimeType);
assertThat(
JsonPath.compile("[0]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString())
assertThat((Object)JsonPath.compile("[0]_links.self.href").read(mvcResult.getResponse().getContentAsString()))
.hasToString("http://localhost/rest/v1/distributionsettypes/" + created1.getId());
assertThat(
JsonPath.compile("[1]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString())
assertThat((Object)JsonPath.compile("[1]_links.self.href").read(mvcResult.getResponse().getContentAsString()))
.hasToString("http://localhost/rest/v1/distributionsettypes/" + created2.getId());
assertThat(
JsonPath.compile("[2]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString())
assertThat((Object)JsonPath.compile("[2]_links.self.href").read(mvcResult.getResponse().getContentAsString()))
.hasToString("http://localhost/rest/v1/distributionsettypes/" + created3.getId());
assertThat(distributionSetTypeManagement.count()).isEqualTo(7);

View File

@@ -188,7 +188,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
approvalStrategy.setApproveDecidedBy("testUser");
final int amountTargets = 2;
final String remark = "Some remark";
final List<Target> targets = testdataFactory.createTargets(amountTargets, "rollout");
testdataFactory.createTargets(amountTargets, "rollout");
final DistributionSet dsA = testdataFactory.createDistributionSet("");
final Rollout rollout = createRollout("rollout1", 3, dsA.getId(), "controllerId==rollout*", false);
@@ -1927,10 +1927,6 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
retrieveAndCompareRolloutsContent(dsA, urlTemplate, isFullRepresentation, false, null, null);
}
private Rollout getRollout(final long rolloutId) {
return rolloutManagement.get(rolloutId).orElseThrow(NoSuchElementException::new);
}
private void retrieveAndCompareRolloutsContent(final DistributionSet dsA, final String urlTemplate,
final boolean isFullRepresentation, final boolean isStartTypeScheduled, final Long startAt,
final Long forcetime) throws Exception {

View File

@@ -104,7 +104,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
public void createSMFromAlreadyMarkedAsDeletedType() throws Exception {
final String SM_TYPE = "someSmType";
final SoftwareModule sm = testdataFactory.createSoftwareModule(SM_TYPE);
final DistributionSetType t = testdataFactory.findOrCreateDistributionSetType(
testdataFactory.findOrCreateDistributionSetType(
"testKey", "testType", Collections.singletonList(sm.getType()),
Collections.singletonList(sm.getType()));
final DistributionSetType type = testdataFactory.findOrCreateDistributionSetType("testKey", "testType");
@@ -295,7 +295,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
.andExpect(jsonPath("$.lastModifiedAt", equalTo(sm.getLastModifiedAt())))
.andExpect(jsonPath("$.deleted", equalTo(false)));
final SoftwareModule updatedSm = softwareModuleManagement.get(sm.getId()).get();
softwareModuleManagement.get(sm.getId());
assertThat(sm.getLastModifiedBy()).isEqualTo("smUpdateTester");
assertThat(sm.getLastModifiedAt()).isEqualTo(sm.getLastModifiedAt());
assertThat(sm.isDeleted()).isFalse();
@@ -400,15 +400,12 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
mvcResult.getResponse().getContentAsString());
final Long artId = softwareModuleManagement.get(sm.getId()).get().getArtifacts().get(0).getId();
assertThat(artResult.getArtifactId()).as("Wrong artifact id").isEqualTo(artId);
assertThat(JsonPath.compile("$._links.self.href")
.read(mvcResult.getResponse().getContentAsString())
.toString()).as("Link contains no self url")
.isEqualTo("http://localhost/rest/v1/softwaremodules/" + sm.getId() + "/artifacts/" + artId);
assertThat(JsonPath.compile("$._links.download.href")
.read(mvcResult.getResponse().getContentAsString())
.toString()).as("response contains no download url ")
.isEqualTo(
"http://localhost/rest/v1/softwaremodules/" + sm.getId() + "/artifacts/" + artId + "/download");
assertThat((Object)JsonPath.compile("$._links.self.href").read(mvcResult.getResponse().getContentAsString()))
.as("Link contains no self url")
.hasToString("http://localhost/rest/v1/softwaremodules/" + sm.getId() + "/artifacts/" + artId);
assertThat((Object)JsonPath.compile("$._links.download.href").read(mvcResult.getResponse().getContentAsString()))
.as("response contains no download url ")
.hasToString("http://localhost/rest/v1/softwaremodules/" + sm.getId() + "/artifacts/" + artId + "/download");
assertArtifact(sm, random);
}

View File

@@ -213,15 +213,12 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt
final SoftwareModuleType created2 = softwareModuleTypeManagement.findByKey("test2").get();
final SoftwareModuleType created3 = softwareModuleTypeManagement.findByKey("test3").get();
assertThat(
JsonPath.compile("[0]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString())
.isEqualTo("http://localhost/rest/v1/softwaremoduletypes/" + created1.getId());
assertThat(
JsonPath.compile("[1]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString())
.isEqualTo("http://localhost/rest/v1/softwaremoduletypes/" + created2.getId());
assertThat(
JsonPath.compile("[2]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString())
.isEqualTo("http://localhost/rest/v1/softwaremoduletypes/" + created3.getId());
assertThat((Object) JsonPath.compile("[0]_links.self.href").read(mvcResult.getResponse().getContentAsString()))
.hasToString("http://localhost/rest/v1/softwaremoduletypes/" + created1.getId());
assertThat((Object)JsonPath.compile("[1]_links.self.href").read(mvcResult.getResponse().getContentAsString()))
.hasToString("http://localhost/rest/v1/softwaremoduletypes/" + created2.getId());
assertThat((Object)JsonPath.compile("[2]_links.self.href").read(mvcResult.getResponse().getContentAsString()))
.hasToString("http://localhost/rest/v1/softwaremoduletypes/" + created3.getId());
assertThat(softwareModuleTypeManagement.count()).isEqualTo(6);
}
@@ -334,7 +331,7 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt
testType = softwareModuleTypeManagement.get(testType.getId()).get();
assertThat(testType.getLastModifiedAt()).isEqualTo(testType.getLastModifiedAt());
assertThat(testType.isDeleted()).isEqualTo(false);
assertThat(testType.isDeleted()).isFalse();
}
@Test
@@ -466,15 +463,4 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt
.update(entityFactory.softwareModuleType().update(testType.getId()).description("Desc1234"));
return testType;
}
private void createSoftwareModulesAlphabetical(final int amount) {
char character = 'a';
for (int index = 0; index < amount; index++) {
final String str = String.valueOf(character);
softwareModuleManagement.create(entityFactory.softwareModule().create().type(osType).name(str)
.description(str).vendor(str).version(str));
character++;
}
}
}
}

View File

@@ -97,8 +97,7 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte
@Description("Handles the GET request of retrieving all target filter queries within SP.")
public void getTargetFilterQueries() throws Exception {
final String filterName = "filter_01";
final TargetFilterQuery filterQuery = createSingleTargetFilterQuery(filterName, "name==test_01");
createSingleTargetFilterQuery(filterName, "name==test_01");
mvc.perform(get(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING))
.andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print());
@@ -393,7 +392,7 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte
.andExpect(status().isBadRequest())
.andReturn();
assertThat(targetFilterQueryManagement.count()).isEqualTo(0);
assertThat(targetFilterQueryManagement.count()).isZero();
// verify response json exception message
final ExceptionInfo exceptionInfo = ResourceUtility
@@ -414,7 +413,7 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte
.andExpect(status().isBadRequest())
.andReturn();
assertThat(targetFilterQueryManagement.count()).isEqualTo(0);
assertThat(targetFilterQueryManagement.count()).isZero();
}
@Test
@@ -613,7 +612,7 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte
final List<TargetFilterQuery> filters = targetFilterQueryManagement.findAll(PAGE).getContent();
assertThat(filters).hasSize(1);
assertThat(filters.get(0).getAutoAssignWeight().get()).isEqualTo(45);
assertThat(filters.get(0).getAutoAssignWeight()).contains(45);
}
@ParameterizedTest

View File

@@ -1006,15 +1006,12 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
.andExpect(jsonPath("[2].createdBy", equalTo("bumlux")))
.andReturn();
assertThat(
JsonPath.compile("[0]._links.self.href").read(mvcResult.getResponse().getContentAsString()).toString())
.isEqualTo("http://localhost/rest/v1/targets/id1");
assertThat(
JsonPath.compile("[1]._links.self.href").read(mvcResult.getResponse().getContentAsString()).toString())
.isEqualTo("http://localhost/rest/v1/targets/id2");
assertThat(
JsonPath.compile("[2]._links.self.href").read(mvcResult.getResponse().getContentAsString()).toString())
.isEqualTo("http://localhost/rest/v1/targets/id3");
assertThat((Object) JsonPath.compile("[0]._links.self.href").read(mvcResult.getResponse().getContentAsString()))
.hasToString("http://localhost/rest/v1/targets/id1");
assertThat((Object)JsonPath.compile("[1]._links.self.href").read(mvcResult.getResponse().getContentAsString()))
.hasToString("http://localhost/rest/v1/targets/id2");
assertThat((Object)JsonPath.compile("[2]._links.self.href").read(mvcResult.getResponse().getContentAsString()))
.hasToString("http://localhost/rest/v1/targets/id3");
final Target t1 = assertTarget("id1", "testname1", "testid1");
assertThat(t1.getSecurityToken()).isEqualTo("token");
@@ -2275,7 +2272,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
final List<Target> targets = Arrays.asList(test1, test2, test3);
final MvcResult mvcPostResult = mvc
mvc
.perform(post("/rest/v1/targets").content(JsonBuilder.targets(targets, true))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())

View File

@@ -91,9 +91,7 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
@Test
@Description("Handles the GET request of retrieving all targets tags within SP based by parameter")
public void getTargetTagsWithParameters() throws Exception {
final List<TargetTag> tags = testdataFactory.createTargetTags(2, "");
final TargetTag assigned = tags.get(0);
final TargetTag unassigned = tags.get(1);
testdataFactory.createTargetTags(2, "");
mvc.perform(get(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING + "?limit=10&sort=name:ASC&offset=0&q=name==targetTag"))
.andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print());
@@ -233,7 +231,7 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
final TargetTag tag = testdataFactory.createTargetTags(1, "").get(0);
final int targetsAssigned = 5;
final List<Target> targets = testdataFactory.createTargets(targetsAssigned);
targetManagement.assignTag(targets.stream().map(Target::getControllerId).collect(Collectors.toList()), tag.getId());
targetManagement.assignTag(targets.stream().map(Target::getControllerId).toList(), tag.getId());
mvc.perform(get(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned"))
.andDo(MockMvcResultPrinter.print())
@@ -254,7 +252,7 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
final int targetsAssigned = 5;
final int limitSize = 1;
final List<Target> targets = testdataFactory.createTargets(targetsAssigned);
targetManagement.assignTag(targets.stream().map(Target::getControllerId).collect(Collectors.toList()), tag.getId());
targetManagement.assignTag(targets.stream().map(Target::getControllerId).toList(), tag.getId());
mvc.perform(get(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned")
.param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, String.valueOf(limitSize)))
@@ -278,7 +276,7 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
final int expectedSize = targetsAssigned - offsetParam;
final List<Target> targets = testdataFactory.createTargets(targetsAssigned);
targetManagement.assignTag(targets.stream().map(Target::getControllerId).collect(Collectors.toList()), tag.getId());
targetManagement.assignTag(targets.stream().map(Target::getControllerId).toList(), tag.getId());
mvc.perform(get(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned")
.param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, String.valueOf(offsetParam))
@@ -306,8 +304,7 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
.andExpect(status().isOk());
final List<Target> updated = targetManagement.findByTag(PAGE, tag.getId()).getContent();
assertThat(updated.stream().map(Target::getControllerId).collect(Collectors.toList()))
.containsOnly(assigned.getControllerId());
assertThat(updated.stream().map(Target::getControllerId).toList()).containsOnly(assigned.getControllerId());
}
@Test
@@ -329,7 +326,7 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
.andExpect(status().isOk());
final List<Target> updated = targetManagement.findByTag(PAGE, tag.getId()).getContent();
assertThat(updated.stream().map(Target::getControllerId).collect(Collectors.toList()))
assertThat(updated.stream().map(Target::getControllerId).toList())
.containsOnly(assigned0.getControllerId(), assigned1.getControllerId());
}
@@ -459,7 +456,7 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
final Target assigned = targets.get(0);
final Target unassigned = targets.get(1);
targetManagement.assignTag(targets.stream().map(Target::getControllerId).collect(Collectors.toList()), tag.getId());
targetManagement.assignTag(targets.stream().map(Target::getControllerId).toList(), tag.getId());
mvc.perform(delete(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned/" +
unassigned.getControllerId()))
@@ -467,7 +464,7 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
.andExpect(status().isOk());
final List<Target> updated = targetManagement.findByTag(PAGE, tag.getId()).getContent();
assertThat(updated.stream().map(Target::getControllerId).collect(Collectors.toList()))
assertThat(updated.stream().map(Target::getControllerId).toList())
.containsOnly(assigned.getControllerId());
}
@@ -484,7 +481,7 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
final Target unassigned0 = targets.get(1);
final Target unassigned1 = targets.get(2);
targetManagement.assignTag(targets.stream().map(Target::getControllerId).collect(Collectors.toList()), tag.getId());
targetManagement.assignTag(targets.stream().map(Target::getControllerId).toList(), tag.getId());
mvc.perform(delete(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned")
.content(JsonBuilder.toArray(Arrays.asList(unassigned0.getControllerId(), unassigned1.getControllerId())))
@@ -493,7 +490,7 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
.andExpect(status().isOk());
final List<Target> updated = targetManagement.findByTag(PAGE, tag.getId()).getContent();
assertThat(updated.stream().map(Target::getControllerId).collect(Collectors.toList()))
assertThat(updated.stream().map(Target::getControllerId).toList())
.containsOnly(assigned.getControllerId());
}

View File

@@ -164,7 +164,7 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
String typeNameA = "ATestTypeGETsorted";
String typeNameB = "BTestTypeGETsorted";
String typeNameC = "CTestTypeGETsorted";
TargetType testTypeB = createTestTargetTypeInDB(typeNameB);
createTestTargetTypeInDB(typeNameB);
TargetType testTypeC = createTestTargetTypeInDB(typeNameC);
TargetType testTypeA = createTestTargetTypeInDB(typeNameA);

View File

@@ -26,12 +26,12 @@ import org.springframework.http.HttpStatus;
@Feature("Integration Test - Security")
@Story("PreAuthorized enabled")
public class PreAuthorizeEnabledTest extends AbstractSecurityTest {
class PreAuthorizeEnabledTest extends AbstractSecurityTest {
@Test
@Description("Tests whether request fail if a role is forbidden for the user")
@WithUser(authorities = { SpPermission.READ_TARGET }, autoCreateTenant = false)
public void failIfNoRole() throws Exception {
void failIfNoRole() throws Exception {
mvc.perform(get("/rest/v1/distributionsets")).andExpect(result ->
assertThat(result.getResponse().getStatus()).isEqualTo(HttpStatus.FORBIDDEN.value()));
}
@@ -39,7 +39,7 @@ public class PreAuthorizeEnabledTest extends AbstractSecurityTest {
@Test
@Description("Tests whether request succeed if a role is granted for the user")
@WithUser(authorities = { SpPermission.READ_REPOSITORY }, autoCreateTenant = false)
public void successIfHasRole() throws Exception {
void successIfHasRole() throws Exception {
mvc.perform(get("/rest/v1/distributionsets")).andExpect(result ->
assertThat(result.getResponse().getStatus()).isEqualTo(HttpStatus.OK.value()));
}
@@ -47,7 +47,7 @@ public class PreAuthorizeEnabledTest extends AbstractSecurityTest {
@Test
@Description("Tests whether request succeed if a role is granted for the user")
@WithUser(authorities = { SpRole.TENANT_ADMIN }, autoCreateTenant = false)
public void successIfHasTenantAdminRole() throws Exception {
void successIfHasTenantAdminRole() throws Exception {
mvc.perform(get("/rest/v1/distributionsets")).andExpect(result ->
assertThat(result.getResponse().getStatus()).isEqualTo(HttpStatus.OK.value()));
}
@@ -55,20 +55,19 @@ public class PreAuthorizeEnabledTest extends AbstractSecurityTest {
@Test
@Description("Tests whether read tenant config request fail if a tenant config (or read read) is not granted for the user")
@WithUser(authorities = { SpPermission.READ_TARGET }, autoCreateTenant = false)
public void onlyDSIfNoTenantConfig() throws Exception {
void onlyDSIfNoTenantConfig() throws Exception {
mvc.perform(get("/rest/v1/system/configs")).andExpect(result -> {
// returns default DS type because of READ_TARGET
assertThat(result.getResponse().getStatus()).isEqualTo(HttpStatus.OK.value());
assertThat(
new ObjectMapper().reader().readValue(result.getResponse().getContentAsString(), HashMap.class).size())
.isEqualTo(1);
assertThat(new ObjectMapper().reader().readValue(result.getResponse().getContentAsString(), HashMap.class))
.hasSize(1);
});
}
@Test
@Description("Tests whether read tenant config request succeed if a tenant config (not read explicitly) is granted for the user")
@WithUser(authorities = { SpPermission.TENANT_CONFIGURATION }, autoCreateTenant = false)
public void successIfHasTenantConfig() throws Exception {
void successIfHasTenantConfig() throws Exception {
mvc.perform(get("/rest/v1/system/configs")).andExpect(result ->
assertThat(result.getResponse().getStatus()).isEqualTo(HttpStatus.OK.value()));
}