Sonar Fixes (5) (#2211)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-01-21 11:20:50 +02:00
committed by GitHub
parent 33a6250646
commit 567e8b38f1
59 changed files with 240 additions and 276 deletions

View File

@@ -11,6 +11,7 @@ package org.eclipse.hawkbit.repository.event.remote;
import java.io.Serial;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.eclipse.hawkbit.repository.model.ActionStatus;
@@ -18,6 +19,7 @@ import org.eclipse.hawkbit.repository.model.ActionStatus;
* TenantAwareEvent that contains an updated download progress for a given
* ActionStatus that was written for a download request.
*/
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor // for serialization libs like jackson
public class DownloadProgressEvent extends RemoteTenantAwareEvent {

View File

@@ -11,6 +11,7 @@ package org.eclipse.hawkbit.repository.event.remote.entity;
import java.io.Serial;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.eclipse.hawkbit.repository.event.entity.EntityUpdatedEvent;
import org.eclipse.hawkbit.repository.model.DistributionSet;
@@ -19,6 +20,7 @@ import org.eclipse.hawkbit.repository.model.DistributionSet;
* Defines the remote event for updating a {@link DistributionSet}.
*/
@NoArgsConstructor // for serialization libs like jackson
@EqualsAndHashCode(callSuper = true)
public class DistributionSetUpdatedEvent extends RemoteEntityEvent<DistributionSet> implements EntityUpdatedEvent {
@Serial

View File

@@ -12,7 +12,6 @@ package org.eclipse.hawkbit.repository.builder;
import java.util.Optional;
import org.eclipse.hawkbit.repository.ValidString;
import org.springframework.util.StringUtils;
/**
* Create and update builder DTO.

View File

@@ -30,7 +30,7 @@ import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.converter.MessageConversionException;
@ExtendWith(MockitoExtension.class)
public class BusProtoStuffMessageConverterTest {
class BusProtoStuffMessageConverterTest {
private final BusProtoStuffMessageConverter underTest = new BusProtoStuffMessageConverter();
@@ -41,13 +41,13 @@ public class BusProtoStuffMessageConverterTest {
private Message<Object> messageMock;
@BeforeEach
public void before() {
void before() {
when(targetMock.getId()).thenReturn(1L);
}
@Test
@Description("Verifies that the TargetCreatedEvent can be successfully serialized and deserialized")
public void successfullySerializeAndDeserializeEvent() {
void successfullySerializeAndDeserializeEvent() {
final TargetCreatedEvent targetCreatedEvent = new TargetCreatedEvent(targetMock, "1");
// serialize
final Object serializedEvent = underTest.convertToInternal(targetCreatedEvent,
@@ -63,7 +63,7 @@ public class BusProtoStuffMessageConverterTest {
@Test
@Description("Verifies that a MessageConversationException is thrown on missing event-type information encoding")
public void missingEventTypeMappingThrowsMessageConversationException() {
void missingEventTypeMappingThrowsMessageConversationException() {
final DummyRemoteEntityEvent dummyEvent = new DummyRemoteEntityEvent(targetMock, "applicationId");
final MessageHeaders messageHeaders = new MessageHeaders(new HashMap<>());

View File

@@ -26,15 +26,13 @@ import org.springframework.data.repository.core.support.RepositoryFactorySupport
* @param <S>
* @param <ID>
*/
public class CustomBaseRepositoryFactoryBean<T extends Repository<S, ID>, S, ID>
extends JpaRepositoryFactoryBean<T, S, ID> {
public class CustomBaseRepositoryFactoryBean<T extends Repository<S, ID>, S, ID> extends JpaRepositoryFactoryBean<T, S, ID> {
@Autowired
BaseRepositoryTypeProvider baseRepoProvider;
/**
* Creates a new {@link JpaRepositoryFactoryBean} for the given repository
* interface.
* Creates a new {@link JpaRepositoryFactoryBean} for the given repository interface.
*
* @param repositoryInterface must not be {@literal null}.
*/

View File

@@ -23,7 +23,7 @@ import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.util.StringUtils;
import org.springframework.util.ObjectUtils;
/**
* Default implementation of {@link RolloutApprovalStrategy}. Decides whether
@@ -93,7 +93,7 @@ public class DefaultRolloutApprovalStrategy implements RolloutApprovalStrategy {
if (RolloutStatus.CREATING == rollout.getStatus()) {
final String actor = rollout.getLastModifiedBy() != null ? rollout.getLastModifiedBy()
: rollout.getCreatedBy();
if (!StringUtils.isEmpty(actor)) {
if (!ObjectUtils.isEmpty(actor)) {
return systemSecurityContext.runAsSystem(
() -> userAuthoritiesResolver.getUserAuthorities(rollout.getTenant(), actor));
}

View File

@@ -16,7 +16,6 @@ import jakarta.persistence.Column;
import jakarta.persistence.ConstraintMode;
import jakarta.persistence.EmbeddedId;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.ForeignKey;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;

View File

@@ -124,8 +124,8 @@ public interface BaseEntityRepository<T extends AbstractJpaTenantAwareBaseEntity
default <T extends AbstractJpaTenantAwareBaseEntity> Specification<T> byIdsSpec(final Iterable<Long> ids) {
final Collection<Long> collection;
if (ids instanceof Collection<Long>) {
collection = (Collection<Long>) ids;
if (ids instanceof Collection<Long> idCollection) {
collection = idCollection;
} else {
collection = new LinkedList<>();
ids.forEach(collection::add);

View File

@@ -326,8 +326,7 @@ public class BaseEntityRepositoryACM<T extends AbstractJpaTenantAwareBaseEntity>
try {
// TODO - cache mapping so to speed things
final Method delegateMethod =
BaseEntityRepositoryACM.class.getDeclaredMethod(
method.getName(), method.getParameterTypes());
BaseEntityRepositoryACM.class.getDeclaredMethod(method.getName(), method.getParameterTypes());
return delegateMethod.invoke(repositoryACM, args);
} catch (final NoSuchMethodException e) {
// call to repository itself
@@ -369,7 +368,7 @@ public class BaseEntityRepositoryACM<T extends AbstractJpaTenantAwareBaseEntity>
}
@SuppressWarnings({ "rawtypes", "unchecked" })
private static <T extends Long> Set<Long> toSetDistinct(final Iterable<T> i) {
private static Set<Long> toSetDistinct(final Iterable<? extends Long> i) {
final Set<Long> set = new HashSet<>();
i.forEach(set::add);
return set;

View File

@@ -20,11 +20,11 @@ import org.junit.jupiter.api.Test;
*/
@Feature("Component Tests - Repository")
@Story("Test DistributionSetCreatedEvent")
public class DistributionSetCreatedEventTest extends AbstractRemoteEntityEventTest<DistributionSet> {
class DistributionSetCreatedEventTest extends AbstractRemoteEntityEventTest<DistributionSet> {
@Test
@Description("Verifies that the distribution set entity reloading by remote created event works")
public void testDistributionSetCreatedEvent() {
void testDistributionSetCreatedEvent() {
assertAndCreateRemoteEvent(DistributionSetCreatedEvent.class);
}
@@ -33,5 +33,4 @@ public class DistributionSetCreatedEventTest extends AbstractRemoteEntityEventTe
return distributionSetManagement.create(entityFactory.distributionSet().create()
.name("incomplete").version("2").description("incomplete").type("os"));
}
}
}

View File

@@ -20,17 +20,17 @@ import org.junit.jupiter.api.Test;
*/
@Feature("Component Tests - Repository")
@Story("Test DistributionSetTagCreatedEvent and DistributionSetTagUpdateEvent")
public class DistributionSetTagEventTest extends AbstractRemoteEntityEventTest<DistributionSetTag> {
class DistributionSetTagEventTest extends AbstractRemoteEntityEventTest<DistributionSetTag> {
@Test
@Description("Verifies that the distribution set tag entity reloading by remote created event works")
public void testDistributionSetTagCreatedEvent() {
void testDistributionSetTagCreatedEvent() {
assertAndCreateRemoteEvent(DistributionSetTagCreatedEvent.class);
}
@Test
@Description("Verifies that the distribution set tag entity reloading by remote updated event works")
public void testDistributionSetTagUpdateEvent() {
void testDistributionSetTagUpdateEvent() {
assertAndCreateRemoteEvent(DistributionSetTagUpdatedEvent.class);
}

View File

@@ -20,11 +20,11 @@ import org.junit.jupiter.api.Test;
*/
@Feature("Component Tests - Repository")
@Story("Test DistributionSetUpdateEvent")
public class DistributionSetUpdatedEventTest extends AbstractRemoteEntityEventTest<DistributionSet> {
class DistributionSetUpdatedEventTest extends AbstractRemoteEntityEventTest<DistributionSet> {
@Test
@Description("Verifies that the distribution set entity reloading by remote updated event works")
public void testDistributionSetUpdateEvent() {
void testDistributionSetUpdateEvent() {
assertAndCreateRemoteEvent(DistributionSetUpdatedEvent.class);
}

View File

@@ -20,17 +20,17 @@ import org.junit.jupiter.api.Test;
*/
@Feature("Component Tests - Repository")
@Story("Test SoftwareModuleCreatedEvent, SoftwareModuleUpdatedEvent")
public class SoftwareModuleEventTest extends AbstractRemoteEntityEventTest<SoftwareModule> {
class SoftwareModuleEventTest extends AbstractRemoteEntityEventTest<SoftwareModule> {
@Test
@Description("Verifies that the software module entity reloading by remote created event works")
public void testTargetCreatedEvent() {
void testTargetCreatedEvent() {
assertAndCreateRemoteEvent(SoftwareModuleCreatedEvent.class);
}
@Test
@Description("Verifies that the software module entity reloading by remote updated event works")
public void testTargetUpdatedEvent() {
void testTargetUpdatedEvent() {
assertAndCreateRemoteEvent(SoftwareModuleUpdatedEvent.class);
}
@@ -38,5 +38,4 @@ public class SoftwareModuleEventTest extends AbstractRemoteEntityEventTest<Softw
protected SoftwareModule createEntity() {
return testdataFactory.createSoftwareModuleApp();
}
}
}

View File

@@ -51,11 +51,11 @@ import org.springframework.test.context.TestPropertySource;
@Story("Concurrent Distribution Set invalidation")
@ContextConfiguration(classes = ConcurrentDistributionSetInvalidationTest.Config.class)
@TestPropertySource(properties = { "hawkbit.server.repository.dsInvalidationLockTimeout=1" })
public class ConcurrentDistributionSetInvalidationTest extends AbstractJpaIntegrationTest {
class ConcurrentDistributionSetInvalidationTest extends AbstractJpaIntegrationTest {
@Test
@Description("Verify that a large rollout causes a timeout when trying to invalidate a distribution set")
public void verifyInvalidateDistributionSetWithLargeRolloutThrowsException() throws Exception {
void verifyInvalidateDistributionSetWithLargeRolloutThrowsException() {
final DistributionSet distributionSet = testdataFactory.createDistributionSet();
final Rollout rollout = createRollout(distributionSet);
final String tenant = tenantAware.getCurrentTenant();

View File

@@ -195,7 +195,7 @@ class ConfirmationManagementTest extends AbstractJpaIntegrationTest {
final List<Action> actions = assignDistributionSets(
Arrays.asList(toDeploymentRequest(controllerId, dsId), toDeploymentRequest(controllerId, dsId2)))
.stream().flatMap(s -> s.getAssignedEntity().stream()).collect(Collectors.toList());
.stream().flatMap(s -> s.getAssignedEntity().stream()).toList();
assertThat(actions).hasSize(2);
assertThat(confirmationManagement.findActiveActionsWaitingConfirmation(controllerId)).hasSize(2)

View File

@@ -23,7 +23,6 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.io.ByteArrayInputStream;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -39,7 +38,6 @@ import io.qameta.allure.Description;
import io.qameta.allure.Feature;
import io.qameta.allure.Step;
import io.qameta.allure.Story;
import org.apache.commons.lang3.RandomUtils;
import org.assertj.core.api.Assertions;
import org.eclipse.hawkbit.im.authentication.SpPermission;
import org.eclipse.hawkbit.repository.RepositoryProperties;
@@ -199,7 +197,6 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
.status(Action.Status.RUNNING).occurredAt(System.currentTimeMillis())
.messages(List.of("proceeding message 1")));
final long createTime = System.currentTimeMillis();
waitNextMillis();
controllerManagement.addUpdateActionStatus(entityFactory.actionStatus().create(actionId)
.status(Action.Status.RUNNING).occurredAt(System.currentTimeMillis())
@@ -307,7 +304,7 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
assertThat(actionStatusRepository.count()).isEqualTo(2);
assertThat(controllerManagement.findActionStatusByAction(PAGE, actionId).getNumberOfElements()).isEqualTo(2);
assertThat(activeActionExistsForControllerId(DEFAULT_CONTROLLER_ID)).isEqualTo(true);
assertThat(activeActionExistsForControllerId(DEFAULT_CONTROLLER_ID)).isTrue();
}
@Test
@@ -338,7 +335,7 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
@ExpectEvents({
@Expect(type = TargetCreatedEvent.class, count = 1),
@Expect(type = SoftwareModuleCreatedEvent.class, count = 1) })
void entityQueriesReferringToNotExistingEntitiesThrowsException() throws URISyntaxException {
void entityQueriesReferringToNotExistingEntitiesThrowsException() {
final Target target = testdataFactory.createTarget();
final SoftwareModule module = testdataFactory.createSoftwareModuleOs();
@@ -622,7 +619,7 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
@Expect(type = TargetAssignDistributionSetEvent.class, count = 1) })
void hasTargetArtifactAssignedIsTrueWithMultipleArtifacts() {
final int artifactSize = 5 * 1024;
final byte[] random = RandomUtils.nextBytes(artifactSize);
final byte[] random = randomBytes(artifactSize);
final DistributionSet ds = testdataFactory.createDistributionSet("");
final DistributionSet ds2 = testdataFactory.createDistributionSet("2");
@@ -1164,7 +1161,7 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
assertThat(actionStatusRepository.count()).isEqualTo(2);
assertThat(controllerManagement.findActionStatusByAction(PAGE, actionId).getNumberOfElements()).isEqualTo(2);
assertThat(activeActionExistsForControllerId(DEFAULT_CONTROLLER_ID)).isEqualTo(false);
assertThat(activeActionExistsForControllerId(DEFAULT_CONTROLLER_ID)).isFalse();
}
@Test
@@ -1191,7 +1188,7 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
assertThat(actionStatusRepository.count()).isEqualTo(3);
assertThat(controllerManagement.findActionStatusByAction(PAGE, actionId).getNumberOfElements()).isEqualTo(3);
assertThat(activeActionExistsForControllerId(DEFAULT_CONTROLLER_ID)).isEqualTo(false);
assertThat(activeActionExistsForControllerId(DEFAULT_CONTROLLER_ID)).isFalse();
}
@Test
@@ -1219,7 +1216,7 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
assertThat(actionStatusRepository.count()).isEqualTo(4);
assertThat(controllerManagement.findActionStatusByAction(PAGE, actionId).getNumberOfElements()).isEqualTo(4);
assertThat(activeActionExistsForControllerId(DEFAULT_CONTROLLER_ID)).isEqualTo(false);
assertThat(activeActionExistsForControllerId(DEFAULT_CONTROLLER_ID)).isFalse();
}
@Test
@@ -1564,7 +1561,7 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
controllerManagement.deleteExistingTarget(target.getControllerId());
assertThat(targetRepository.count()).as("target should not exist anymore").isEqualTo(0L);
assertThat(targetRepository.count()).as("target should not exist anymore").isZero();
}
@Test
@@ -1574,7 +1571,7 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
assertThatExceptionOfType(EntityNotFoundException.class)
.as("No EntityNotFoundException thrown when deleting a non-existing target")
.isThrownBy(() -> controllerManagement.deleteExistingTarget("BB"));
assertThat(targetRepository.count()).as("target should not exist").isEqualTo(0L);
assertThat(targetRepository.count()).as("target should not exist").isZero();
}
@Test
@@ -1589,7 +1586,7 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
assertThat(targetRepository.count()).as("target exists and is ready for deletion").isEqualTo(1L);
controllerManagement.deleteExistingTarget(target.getControllerId());
assertThat(targetRepository.count()).as("target should not exist anymore").isEqualTo(0L);
assertThat(targetRepository.count()).as("target should not exist anymore").isZero();
assertThatExceptionOfType(EntityNotFoundException.class)
.as("No EntityNotFoundException thrown when deleting a non-existing target")
@@ -1769,7 +1766,7 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
// verify attribute removal
final Map<String, String> updatedAttributes = targetManagement.getControllerAttributes(controllerId);
assertThat(updatedAttributes.size()).isEqualTo(previousSize - 2);
assertThat(updatedAttributes).hasSize(previousSize - 2);
assertThat(updatedAttributes).doesNotContainKeys("k1", "k3");
}
@@ -1786,9 +1783,9 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
// verify attribute merge
final Map<String, String> updatedAttributes = targetManagement.getControllerAttributes(controllerId);
assertThat(updatedAttributes.size()).isEqualTo(4);
assertThat(updatedAttributes).hasSize(4);
assertThat(updatedAttributes).containsAllEntriesOf(mergeAttributes);
assertThat(updatedAttributes.get("k1")).isEqualTo("v1_modified_again");
assertThat(updatedAttributes).containsEntry("k1", "v1_modified_again");
attributes.keySet().forEach(assertThat(updatedAttributes)::containsKey);
}
@@ -1806,9 +1803,9 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
// verify attribute replacement
final Map<String, String> updatedAttributes = targetManagement.getControllerAttributes(controllerId);
assertThat(updatedAttributes.size()).isEqualTo(replacementAttributes.size());
assertThat(updatedAttributes).hasSameSizeAs(replacementAttributes);
assertThat(updatedAttributes).containsAllEntriesOf(replacementAttributes);
assertThat(updatedAttributes.get("k1")).isEqualTo("v1_modified");
assertThat(updatedAttributes).containsEntry("k1", "v1_modified");
attributes.entrySet().forEach(assertThat(updatedAttributes)::doesNotContain);
}
@@ -1822,7 +1819,7 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
// verify initial attributes
final Map<String, String> updatedAttributes = targetManagement.getControllerAttributes(controllerId);
assertThat(updatedAttributes.size()).isEqualTo(attributes.size());
assertThat(updatedAttributes).hasSameSizeAs(attributes);
assertThat(updatedAttributes).containsAllEntriesOf(attributes);
}
@@ -1849,7 +1846,7 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
.addUpdateActionStatus(entityFactory.actionStatus().create(actionId).status(Status.DOWNLOADED));
controllerManagement.addUpdateActionStatus(entityFactory.actionStatus().create(actionId).status(status));
assertThat(activeActionExistsForControllerId(DEFAULT_CONTROLLER_ID)).isEqualTo(false);
assertThat(activeActionExistsForControllerId(DEFAULT_CONTROLLER_ID)).isFalse();
}
@Step
@@ -1883,7 +1880,7 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
}
private void assertNoActiveActionsExistsForControllerId(final String controllerId) {
assertThat(activeActionExistsForControllerId(controllerId)).isEqualTo(false);
assertThat(activeActionExistsForControllerId(controllerId)).isFalse();
}
private boolean activeActionExistsForControllerId(final String controllerId) {

View File

@@ -23,9 +23,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import jakarta.validation.ConstraintViolationException;
@@ -108,7 +106,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Tests that an exception is thrown when a target is assigned to an incomplete distribution set")
public void verifyAssignTargetsToIncompleteDistribution() {
void verifyAssignTargetsToIncompleteDistribution() {
final DistributionSet distributionSet = testdataFactory.createIncompleteDistributionSet();
final Target target = testdataFactory.createTarget();
@@ -119,7 +117,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Tests that an exception is thrown when a target is assigned to an invalidated distribution set")
public void verifyAssignTargetsToInvalidDistribution() {
void verifyAssignTargetsToInvalidDistribution() {
final DistributionSet distributionSet = testdataFactory.createAndInvalidateDistributionSet();
final Target target = testdataFactory.createTarget();
@@ -484,7 +482,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
void assignedDistributionSet() {
final List<String> controllerIds = testdataFactory.createTargets(10).stream().map(Target::getControllerId)
.collect(Collectors.toList());
.toList();
final List<Target> onlineAssignedTargets = testdataFactory.createTargets(10, "2");
controllerIds.addAll(onlineAssignedTargets.stream().map(Target::getControllerId).toList());
@@ -494,12 +492,12 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
final long current = System.currentTimeMillis();
final List<Entry<String, Long>> offlineAssignments = controllerIds.stream()
.map(targetId -> new SimpleEntry<>(targetId, ds.getId())).collect(Collectors.toList());
.map(targetId -> (Entry<String, Long>)new SimpleEntry<>(targetId, ds.getId())).toList();
final List<DistributionSetAssignmentResult> assignmentResults = deploymentManagement
.offlineAssignedDistributionSets(offlineAssignments);
assertThat(assignmentResults).hasSize(1);
final List<Target> targets = assignmentResults.get(0).getAssignedEntity().stream().map(Action::getTarget)
.collect(Collectors.toList());
.toList();
assertThat(actionRepository.count()).isEqualTo(20);
assertThat(findActionsByDistributionSet(PAGE, ds.getId())).as("Offline actions are not active")
@@ -547,7 +545,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
.isEqualTo(tenantAware.getCurrentUsername());
return a;
})
.map(action -> action.getDistributionSet().getId()).collect(Collectors.toList());
.map(action -> action.getDistributionSet().getId()).toList();
assertThat(assignedDsIds).containsExactlyInAnyOrderElementsOf(dsIds);
});
}
@@ -610,7 +608,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
void previousAssignmentsAreNotCanceledInMultiAssignMode() {
enableMultiAssignments();
final List<Target> targets = testdataFactory.createTargets(10);
final List<String> targetIds = targets.stream().map(Target::getControllerId).collect(Collectors.toList());
final List<String> targetIds = targets.stream().map(Target::getControllerId).toList();
// First assignment
final DistributionSet ds1 = testdataFactory.createDistributionSet("Multi-assign-1");
@@ -648,7 +646,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
.assignDistributionSets(deploymentRequests);
assertThat(getResultingActionCount(results)).isEqualTo(deploymentRequests.size());
final List<Long> dsIds = distributionSets.stream().map(DistributionSet::getId).collect(Collectors.toList());
final List<Long> dsIds = distributionSets.stream().map(DistributionSet::getId).toList();
targets.forEach(target -> {
final List<Long> assignedDsIds = deploymentManagement.findActionsByTarget(target.getControllerId(), PAGE)
.stream()
@@ -658,7 +656,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
.isEqualTo(tenantAware.getCurrentUsername());
return a;
})
.map(action -> action.getDistributionSet().getId()).collect(Collectors.toList());
.map(action -> action.getDistributionSet().getId()).toList();
assertThat(assignedDsIds).containsExactlyInAnyOrderElementsOf(dsIds);
});
}
@@ -689,7 +687,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
assertThat(getResultingActionCount(results)).isEqualTo(deploymentRequests.size());
final List<Long> dsIds = distributionSets.stream().map(DistributionSet::getId).collect(Collectors.toList());
final List<Long> dsIds = distributionSets.stream().map(DistributionSet::getId).toList();
targets.forEach(target ->
deploymentManagement.findActionsByTarget(target.getControllerId(), PAGE).forEach(action -> {
assertThat(action.getDistributionSet().getId()).isIn(dsIds);
@@ -748,8 +746,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
@ValueSource(booleans = { true, false })
@Description("Assignments with confirmation flow active will result in actions in 'WAIT_FOR_CONFIRMATION' state")
void assignmentWithConfirmationFlowActive(final boolean confirmationRequired) {
final List<String> controllerIds = testdataFactory.createTargets(1).stream().map(Target::getControllerId)
.collect(Collectors.toList());
final List<String> controllerIds = testdataFactory.createTargets(1).stream().map(Target::getControllerId).toList();
final DistributionSet distributionSet = testdataFactory.createDistributionSet();
enableConfirmationFlow();
@@ -859,16 +856,14 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Assignments with confirmation flow deactivated will result in actions in only in 'RUNNING' state")
void verifyConfirmationRequiredFlagHaveNoInfluenceIfFlowIsDeactivated() {
final List<String> targets1 = testdataFactory.createTargets("group1", 1).stream().map(Target::getControllerId)
.collect(Collectors.toList());
final List<String> targets2 = testdataFactory.createTargets("group2", 1).stream().map(Target::getControllerId)
.collect(Collectors.toList());
final List<String> targets1 = testdataFactory.createTargets("group1", 1).stream().map(Target::getControllerId).toList();
final List<String> targets2 = testdataFactory.createTargets("group2", 1).stream().map(Target::getControllerId).toList();
final DistributionSet distributionSet = testdataFactory.createDistributionSet();
final List<DistributionSetAssignmentResult> results = Stream
.concat(assignDistributionSetToTargets(distributionSet, targets1, true).stream(), //
assignDistributionSetToTargets(distributionSet, targets2, false).stream()) //
.collect(Collectors.toList());
.toList();
final List<String> controllerIds = Stream.concat(targets1.stream(), targets2.stream()).toList();
@@ -1073,7 +1068,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
@Expect(type = TargetCreatedEvent.class, count = 10),
@Expect(type = ActionCreatedEvent.class, count = 10),
@Expect(type = TargetUpdatedEvent.class, count = 10) })
void failDistributionSetAssigmentThatIsNotComplete() throws InterruptedException {
void failDistributionSetAssigmentThatIsNotComplete() {
final List<Target> targets = testdataFactory.createTargets(10);
final SoftwareModule ah = testdataFactory.createSoftwareModuleApp();
@@ -1131,7 +1126,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
assertThat(page.getTotalElements()).as("wrong size of actions")
.isEqualTo(noOfDeployedTargets * noOfDistributionSets);
// only records retrieved from the DB can be evaluated to be sure that all fields are populated;
// only records retrieved from the DB can be evaluated to be sure that all fields are populated
final List<JpaTarget> allFoundTargets = targetRepository.findAll();
final List<JpaTarget> deployedTargetsFromDB = targetRepository.findAllById(deployedTargetIDs);
@@ -1203,7 +1198,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
final List<Target> updatedTsDsA = testdataFactory
.sendUpdateActionStatusToTargets(deployResWithDsA.getDeployedTargets(), Status.FINISHED,
Collections.singletonList("alles gut"))
.stream().map(Action::getTarget).collect(Collectors.toList());
.stream().map(Action::getTarget).toList();
// verify, that dsA is deployed correctly
for (final Target t_ : updatedTsDsA) {
@@ -1223,12 +1218,12 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
// activeActions, add a corresponding cancelAction and another
// UpdateAction for dsA
final List<Target> deployed2DS = assignDistributionSet(dsA, deployResWithDsB.getDeployedTargets())
.getAssignedEntity().stream().map(Action::getTarget).collect(Collectors.toList());
.getAssignedEntity().stream().map(Action::getTarget).toList();
findActionsByDistributionSet(pageRequest, dsA.getId()).getContent().get(1);
// get final updated version of targets
final List<Target> deployResWithDsBTargets = targetManagement.getByControllerID(deployResWithDsB
.getDeployedTargets().stream().map(Target::getControllerId).collect(Collectors.toList()));
.getDeployedTargets().stream().map(Target::getControllerId).toList());
assertThat(deployed2DS).as("deployed ds is wrong").usingElementComparator(controllerIdComparator())
.containsAll(deployResWithDsBTargets);
@@ -1285,7 +1280,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
// verify that deleted attribute is used correctly
List<DistributionSet> allFoundDS = distributionSetManagement.findByCompleted(PAGE, true).getContent();
assertThat(allFoundDS.size()).as("no ds should be founded").isZero();
assertThat(allFoundDS).as("no ds should be founded").isEmpty();
assertThat(distributionSetRepository.findAll(SpecificationsBuilder.combineWithAnd(Arrays
.asList(DistributionSetSpecification.isDeleted(true), DistributionSetSpecification.isCompleted(true))),
@@ -1302,7 +1297,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
// successfully and no activeAction is referring to created distribution
// sets
allFoundDS = distributionSetManagement.findByCompleted(pageRequest, true).getContent();
assertThat(allFoundDS.size()).as("no ds should be founded").isZero();
assertThat(allFoundDS).as("no ds should be founded").isEmpty();
assertThat(distributionSetRepository.findAll(SpecificationsBuilder.combineWithAnd(Arrays
.asList(DistributionSetSpecification.isDeleted(true), DistributionSetSpecification.isCompleted(true))),
PAGE).getContent()).as("wrong size of founded ds").hasSize(noOfDistributionSets);
@@ -1349,7 +1344,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
// doing the assignment
targs = assignDistributionSet(dsA, targs).getAssignedEntity().stream().map(Action::getTarget)
.collect(Collectors.toList());
.toList();
implicitLock(dsA);
Target targ = targetManagement.getByControllerID(targs.iterator().next().getControllerId()).get();
@@ -1392,7 +1387,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
"wrong installed ds");
targs = assignDistributionSet(dsB.getId(), "target-id-A").getAssignedEntity().stream().map(Action::getTarget)
.collect(Collectors.toList());
.toList();
implicitLock(dsB);
targ = targs.iterator().next();
@@ -1696,7 +1691,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
// deployedTargets
for (final DistributionSet ds : dsList) {
deployedTargets = assignDistributionSet(ds, deployedTargets).getAssignedEntity().stream()
.map(Action::getTarget).collect(Collectors.toList());
.map(Action::getTarget).toList();
implicitLock(ds);
}

View File

@@ -69,7 +69,7 @@ class DistributionSetInvalidationManagementTest extends AbstractJpaIntegrationTe
// if status is pending, the assignment has not been canceled
assertThat(targetRepository.findById(target.getId()).get().getUpdateStatus())
.isEqualTo(TargetUpdateStatus.PENDING);
assertThat(findActionsByTarget(target).size()).isEqualTo(1);
assertThat(findActionsByTarget(target)).hasSize(1);
assertThat(findActionsByTarget(target).get(0).getStatus()).isEqualTo(Status.RUNNING);
}
}
@@ -101,7 +101,7 @@ class DistributionSetInvalidationManagementTest extends AbstractJpaIntegrationTe
assertThat(
targetRepository.findById(invalidationTestData.getTargets().get(0).getId()).get().getUpdateStatus())
.isEqualTo(TargetUpdateStatus.PENDING);
assertThat(findActionsByTarget(target).size()).isEqualTo(1);
assertThat(findActionsByTarget(target)).hasSize(1);
assertThat(findActionsByTarget(target).get(0).getStatus()).isEqualTo(Status.RUNNING);
}
}
@@ -131,7 +131,7 @@ class DistributionSetInvalidationManagementTest extends AbstractJpaIntegrationTe
for (final Target target : invalidationTestData.getTargets()) {
assertThat(targetRepository.findById(target.getId()).get().getUpdateStatus())
.isEqualTo(TargetUpdateStatus.IN_SYNC);
assertThat(findActionsByTarget(target).size()).isEqualTo(1);
assertThat(findActionsByTarget(target)).hasSize(1);
assertThat(findActionsByTarget(target).get(0).getStatus()).isEqualTo(Status.CANCELED);
}
}
@@ -158,7 +158,7 @@ class DistributionSetInvalidationManagementTest extends AbstractJpaIntegrationTe
for (final Target target : invalidationTestData.getTargets()) {
assertThat(targetRepository.findById(target.getId()).get().getUpdateStatus())
.isEqualTo(TargetUpdateStatus.PENDING);
assertThat(findActionsByTarget(target).size()).isEqualTo(1);
assertThat(findActionsByTarget(target)).hasSize(1);
assertThat(findActionsByTarget(target).get(0).getStatus()).isEqualTo(Status.CANCELING);
}
}

View File

@@ -46,7 +46,7 @@ class DistributionSetManagementSecurityTest
@Test
@Description("Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.")
public void assignSoftwareModulesPermissionsCheck() {
void assignSoftwareModulesPermissionsCheck() {
assertPermissions(() -> distributionSetManagement.assignSoftwareModules(1L, List.of(1L)), List.of(SpPermission.UPDATE_REPOSITORY));
}

View File

@@ -320,20 +320,21 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
final DistributionSetTag tag = distributionSetTagManagement.create(entityFactory.tag().create().name(TAG1_NAME));
final List<DistributionSet> assignedDS = distributionSetManagement.assignTag(assignDS, tag.getId());
assertThat(assignedDS.size()).as("assigned ds has wrong size").isEqualTo(4);
assignedDS.stream().map(JpaDistributionSet.class::cast).forEach(ds -> assertThat(ds.getTags().size())
assertThat(assignedDS).as("assigned ds has wrong size").hasSize(4);
assignedDS.stream().map(JpaDistributionSet.class::cast).forEach(ds -> assertThat(ds.getTags())
.as("ds has wrong tag size")
.isEqualTo(1));
.hasSize(1));
final DistributionSetTag findDistributionSetTag = getOrThrow(distributionSetTagManagement.findByName(TAG1_NAME));
assertThat(assignedDS.size()).as("assigned ds has wrong size")
.isEqualTo(distributionSetManagement.findByTag(tag.getId(), PAGE).getNumberOfElements());
assertThat(assignedDS)
.as("assigned ds has wrong size")
.hasSize(distributionSetManagement.findByTag(tag.getId(), PAGE).getNumberOfElements());
final JpaDistributionSet unAssignDS = (JpaDistributionSet) distributionSetManagement
.unassignTag(List.of(assignDS.get(0)), findDistributionSetTag.getId()).get(0);
assertThat(unAssignDS.getId()).as("unassigned ds is wrong").isEqualTo(assignDS.get(0));
assertThat(unAssignDS.getTags().size()).as("unassigned ds has wrong tag size").isZero();
assertThat(unAssignDS.getTags()).as("unassigned ds has wrong tag size").isEmpty();
assertThat(distributionSetTagManagement.findByName(TAG1_NAME)).isPresent();
assertThat(distributionSetManagement.findByTag(tag.getId(), PAGE).getNumberOfElements())
.as("ds tag ds has wrong ds size").isEqualTo(3);
@@ -559,7 +560,7 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
final DistributionSet dsNewType = distributionSetManagement.create(
entityFactory.distributionSet().create().name("newtype").version("1").type(newType.getKey()).modules(
dsDeleted.getModules().stream().map(SoftwareModule::getId).collect(Collectors.toList())));
dsDeleted.getModules().stream().map(SoftwareModule::getId).toList()));
assignDistributionSet(dsDeleted, testdataFactory.createTargets(5));
distributionSetManagement.delete(dsDeleted.getId());
@@ -616,7 +617,7 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
distributionSetManagement.get(distributionSet.getId()).map(DistributionSet::isLocked).orElse(false))
.isTrue();
// assert software modules are locked
assertThat(distributionSet.getModules().size()).isNotEqualTo(0);
assertThat(distributionSet.getModules().size()).isNotZero();
distributionSetManagement.getWithDetails(distributionSet.getId()).map(DistributionSet::getModules)
.orElseThrow().forEach(module -> assertThat(module.isLocked()).isTrue());
}
@@ -667,7 +668,7 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
.orElse(true))
.isFalse();
// assert software modules are not unlocked
assertThat(distributionSet.getModules().size()).isNotEqualTo(0);
assertThat(distributionSet.getModules().size()).isNotZero();
distributionSetManagement.getWithDetails(distributionSet.getId()).map(DistributionSet::getModules)
.orElseThrow().forEach(module -> assertThat(module.isLocked()).isTrue());
}
@@ -677,7 +678,7 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
void lockDistributionSetApplied() {
final DistributionSet distributionSet = testdataFactory.createDistributionSet("ds-1");
final int softwareModuleCount = distributionSet.getModules().size();
assertThat(softwareModuleCount).isNotEqualTo(0);
assertThat(softwareModuleCount).isNotZero();
distributionSetManagement.lock(distributionSet.getId());
assertThat(
distributionSetManagement.get(distributionSet.getId()).map(DistributionSet::isLocked).orElse(false))
@@ -688,18 +689,18 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
.as("Attempt to modify a locked DS software modules should throw an exception")
.isThrownBy(() -> distributionSetManagement.assignSoftwareModules(
distributionSet.getId(), List.of(testdataFactory.createSoftwareModule("sm-1").getId())));
assertThat(distributionSetManagement.getWithDetails(distributionSet.getId()).get().getModules().size())
assertThat(distributionSetManagement.getWithDetails(distributionSet.getId()).get().getModules())
.as("Software module shall not be added to a locked DS.")
.isEqualTo(softwareModuleCount);
.hasSize(softwareModuleCount);
// try remove
assertThatExceptionOfType(LockedException.class)
.as("Attempt to modify a locked DS software modules should throw an exception")
.isThrownBy(() -> distributionSetManagement.unassignSoftwareModule(
distributionSet.getId(), distributionSet.getModules().stream().findFirst().get().getId()));
assertThat(distributionSetManagement.getWithDetails(distributionSet.getId()).get().getModules().size())
assertThat(distributionSetManagement.getWithDetails(distributionSet.getId()).get().getModules())
.as("Software module shall not be removed from a locked DS.")
.isEqualTo(softwareModuleCount);
.hasSize(softwareModuleCount);
}
@Test
@@ -853,7 +854,7 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
assertThat(foundDs).hasSize(3);
final List<Long> collect = foundDs.stream().map(DistributionSet::getId).collect(Collectors.toList());
final List<Long> collect = foundDs.stream().map(DistributionSet::getId).toList();
assertThat(collect).containsAll(searchIds);
}
@@ -1029,7 +1030,6 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
@Step
private void createAndUpdateDistributionSetWithInvalidVersion(final DistributionSet set) {
assertThatExceptionOfType(ConstraintViolationException.class)
.as("entity with too long version should not be created")
.isThrownBy(() -> distributionSetManagement.create(entityFactory.distributionSet().create().name("a")

View File

@@ -26,8 +26,7 @@ import org.springframework.data.domain.Pageable;
@Feature("SecurityTests - DistributionSetTagManagement")
@Story("SecurityTests DistributionSetTagManagement")
public class DistributionSetTagManagementSecurityTest
extends AbstractRepositoryManagementSecurityTest<DistributionSetTag, TagCreate, TagUpdate> {
class DistributionSetTagManagementSecurityTest extends AbstractRepositoryManagementSecurityTest<DistributionSetTag, TagCreate, TagUpdate> {
@Override
protected RepositoryManagement<DistributionSetTag, TagCreate, TagUpdate> getRepositoryManagement() {

View File

@@ -25,7 +25,7 @@ import org.junit.jupiter.api.Test;
@Feature("SecurityTests - DistributionSetTypeManagement")
@Story("SecurityTests DistributionSetTypeManagement")
public class DistributionSetTypeManagementSecurityTest
class DistributionSetTypeManagementSecurityTest
extends AbstractRepositoryManagementSecurityTest<DistributionSetType, DistributionSetTypeCreate, DistributionSetTypeUpdate> {
@Override

View File

@@ -156,8 +156,7 @@ class DistributionSetTypeManagementTest extends AbstractJpaIntegrationTest {
distributionSetTypeManagement.assignMandatorySoftwareModuleTypes(dsType2.getId(),
moduleTypeIds.subList(0, quota));
assertThat(distributionSetTypeManagement.get(dsType2.getId())).isNotEmpty();
assertThat(distributionSetTypeManagement.get(dsType2.getId()).get().getMandatoryModuleTypes().size())
.isEqualTo(quota);
assertThat(distributionSetTypeManagement.get(dsType2.getId()).get().getMandatoryModuleTypes()).hasSize(quota);
// assign one more to trigger the quota exceeded error
assertThatExceptionOfType(AssignmentQuotaExceededException.class)
.isThrownBy(() -> distributionSetTypeManagement.assignMandatorySoftwareModuleTypes(dsType2.getId(),
@@ -168,8 +167,7 @@ class DistributionSetTypeManagementTest extends AbstractJpaIntegrationTest {
.create(entityFactory.distributionSetType().create().key("dst3").name("dst3"));
distributionSetTypeManagement.assignOptionalSoftwareModuleTypes(dsType3.getId(), moduleTypeIds.subList(0, quota));
assertThat(distributionSetTypeManagement.get(dsType3.getId())).isNotEmpty();
assertThat(distributionSetTypeManagement.get(dsType3.getId()).get().getOptionalModuleTypes().size())
.isEqualTo(quota);
assertThat(distributionSetTypeManagement.get(dsType3.getId()).get().getOptionalModuleTypes()).hasSize(quota);
// assign one more to trigger the quota exceeded error
assertThatExceptionOfType(AssignmentQuotaExceededException.class)
.isThrownBy(() -> distributionSetTypeManagement.assignOptionalSoftwareModuleTypes(dsType3.getId(),

View File

@@ -346,9 +346,8 @@ public abstract class AbstractIntegrationTest {
return distributionSetAssignmentResults;
}
protected DistributionSetAssignmentResult assignDistributionSet(final DistributionSet ds,
final List<Target> targets) {
final List<String> targetIds = targets.stream().map(Target::getControllerId).collect(Collectors.toList());
protected DistributionSetAssignmentResult assignDistributionSet(final DistributionSet ds, final List<Target> targets) {
final List<String> targetIds = targets.stream().map(Target::getControllerId).toList();
return assignDistributionSet(ds.getId(), targetIds, ActionType.FORCED);
}

View File

@@ -33,9 +33,6 @@ public class DatasourceContext {
private final String password;
private final String randomSchemaName = RANDOM_DB_PREFIX + TestdataFactory.randomString(10);
/**
* Constructor
*/
public DatasourceContext(final String database, final String datasourceUrl, final String username, final String password) {
this.database = database;
this.datasourceUrl = datasourceUrl;

View File

@@ -93,6 +93,8 @@ public class TestdataFactory {
public static final String INVISIBLE_SM_MD_KEY = "invisibleMetdataKey";
public static final String INVISIBLE_SM_MD_VALUE = "invisibleMetdataValue";
public static final RandomStringUtils RANDOM_STRING_UTILS = RandomStringUtils.secure();
/**
* default {@link Target#getControllerId()}.
*/
@@ -119,27 +121,22 @@ public class TestdataFactory {
public static final String DS_TYPE_DEFAULT = "test_default_ds_type";
/**
* Key of test "os" {@link SoftwareModuleType} : mandatory firmware in
* {@link #DS_TYPE_DEFAULT}.
* Key of test "os" {@link SoftwareModuleType} : mandatory firmware in {@link #DS_TYPE_DEFAULT}.
*/
public static final String SM_TYPE_OS = "os";
/**
* Key of test "runtime" {@link SoftwareModuleType} : optional firmware in
* {@link #DS_TYPE_DEFAULT}.
* Key of test "runtime" {@link SoftwareModuleType} : optional firmware in {@link #DS_TYPE_DEFAULT}.
*/
public static final String SM_TYPE_RT = "runtime";
/**
* Key of test "application" {@link SoftwareModuleType} : optional software in
* {@link #DS_TYPE_DEFAULT}.
* Key of test "application" {@link SoftwareModuleType} : optional software in {@link #DS_TYPE_DEFAULT}.
*/
public static final String SM_TYPE_APP = "application";
public static final String DEFAULT_COLOUR = "#000000";
public static final RandomStringUtils RANDOM_STRING_UTILS = RandomStringUtils.secure();
private static final String SPACE_AND_DESCRIPTION = " description";
@Autowired