From 4909a65d8cecde7fd5c2d10956760e0c719a6e11 Mon Sep 17 00:00:00 2001 From: Avgustin Marinov Date: Wed, 22 Jan 2025 15:20:57 +0200 Subject: [PATCH] Improve autowiring for tests (Sonar) (#2217) Signed-off-by: Avgustin Marinov --- .../BusProtoStuffMessageConverterTest.java | 5 +- .../AbstractDsAssignmentStrategy.java | 7 +- .../event/remote/AbstractRemoteEventTest.java | 1 + .../jpa/AbstractJpaIntegrationTest.java | 19 +- .../autoassign/AutoAssignCheckerIntTest.java | 1 + .../autocleanup/AutoActionCleanupTest.java | 1 + .../autocleanup/AutoCleanupSchedulerTest.java | 1 + .../jpa/event/RepositoryEntityEventTest.java | 1 + .../ConfirmationManagementTest.java | 1 - .../management/DeploymentManagementTest.java | 4 +- .../rsql/RSQLParserValidationOracleTest.java | 2 + .../repository/test/TestConfiguration.java | 35 ++- .../test/util/AbstractIntegrationTest.java | 3 + .../repository/test/util/TestdataFactory.java | 266 ++++++++---------- 14 files changed, 169 insertions(+), 178 deletions(-) diff --git a/hawkbit-repository/hawkbit-repository-core/src/test/java/org/eclipse/hawkbit/event/BusProtoStuffMessageConverterTest.java b/hawkbit-repository/hawkbit-repository-core/src/test/java/org/eclipse/hawkbit/event/BusProtoStuffMessageConverterTest.java index b0cba6c255..73573f99a0 100644 --- a/hawkbit-repository/hawkbit-repository-core/src/test/java/org/eclipse/hawkbit/event/BusProtoStuffMessageConverterTest.java +++ b/hawkbit-repository/hawkbit-repository-core/src/test/java/org/eclipse/hawkbit/event/BusProtoStuffMessageConverterTest.java @@ -57,8 +57,9 @@ void successfullySerializeAndDeserializeEvent() { // deserialize when(messageMock.getPayload()).thenReturn(serializedEvent); final Object deserializedEvent = underTest.convertFromInternal(messageMock, RemoteApplicationEvent.class, null); - assertThat(deserializedEvent).isInstanceOf(TargetCreatedEvent.class); - assertThat(deserializedEvent).isEqualTo(targetCreatedEvent); + assertThat(deserializedEvent) + .isInstanceOf(TargetCreatedEvent.class) + .isEqualTo(targetCreatedEvent); } @Test diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/AbstractDsAssignmentStrategy.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/AbstractDsAssignmentStrategy.java index 9099bb8f3a..ed51640262 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/AbstractDsAssignmentStrategy.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/AbstractDsAssignmentStrategy.java @@ -26,6 +26,7 @@ import org.eclipse.hawkbit.repository.event.remote.entity.TargetUpdatedEvent; import org.eclipse.hawkbit.repository.jpa.configuration.Constants; import org.eclipse.hawkbit.repository.jpa.executor.AfterTransactionCommitExecutor; +import org.eclipse.hawkbit.repository.jpa.model.AbstractJpaBaseEntity_; import org.eclipse.hawkbit.repository.jpa.model.JpaAction; import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus; import org.eclipse.hawkbit.repository.jpa.model.JpaAction_; @@ -60,12 +61,14 @@ public abstract class AbstractDsAssignmentStrategy { protected final AfterTransactionCommitExecutor afterCommit; protected final EventPublisherHolder eventPublisherHolder; protected final ActionRepository actionRepository; + private final ActionStatusRepository actionStatusRepository; private final QuotaManagement quotaManagement; private final BooleanSupplier multiAssignmentsConfig; private final BooleanSupplier confirmationFlowConfig; private final RepositoryProperties repositoryProperties; + @SuppressWarnings("java:S107") AbstractDsAssignmentStrategy( final TargetRepository targetRepository, final AfterTransactionCommitExecutor afterCommit, final EventPublisherHolder eventPublisherHolder, @@ -149,7 +152,7 @@ protected List overrideObsoleteUpdateActions(final Collection target cb.equal(root.get(JpaAction_.active), true), cb.equal(root.get(JpaAction_.distributionSet).get(JpaDistributionSet_.requiredMigrationStep), false), cb.notEqual(root.get(JpaAction_.status), Action.Status.CANCELING), - root.get(JpaAction_.target).get(JpaTarget_.id).in(targetsIds) + root.get(JpaAction_.target).get(AbstractJpaBaseEntity_.id).in(targetsIds) ); }); @@ -187,7 +190,7 @@ protected List closeObsoleteUpdateActions(final Collection targetsId return cb.and( cb.equal(root.get(JpaAction_.active), true), cb.equal(root.get(JpaAction_.distributionSet).get(JpaDistributionSet_.requiredMigrationStep), false), - root.get(JpaAction_.target).get(JpaTarget_.id).in(targetsIds) + root.get(JpaAction_.target).get(AbstractJpaBaseEntity_.id).in(targetsIds) ); }); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/AbstractRemoteEventTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/AbstractRemoteEventTest.java index 84c652c868..d8d5f14bf0 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/AbstractRemoteEventTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/AbstractRemoteEventTest.java @@ -37,6 +37,7 @@ /** * Test the remote entity events. */ +@SuppressWarnings("java:S6813") // constructor injects are not possible for test classes public abstract class AbstractRemoteEventTest extends AbstractJpaIntegrationTest { @Autowired diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTest.java index 072e63af4a..ddaa6e6d59 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTest.java @@ -78,6 +78,7 @@ @ContextConfiguration(classes = { RepositoryApplicationConfiguration.class, TestConfiguration.class }) @Import(TestChannelBinderConfiguration.class) @TestPropertySource(locations = "classpath:/jpa-test.properties") +@SuppressWarnings("java:S6813") // constructor injects are not possible for test classes public abstract class AbstractJpaIntegrationTest extends AbstractIntegrationTest { protected static final String INVALID_TEXT_HTML = "