Skip to content

Commit 4909a65

Browse files
authored
Improve autowiring for tests (Sonar) (#2217)
Signed-off-by: Avgustin Marinov <[email protected]>
1 parent 3d390b9 commit 4909a65

File tree

14 files changed

+169
-178
lines changed

14 files changed

+169
-178
lines changed

hawkbit-repository/hawkbit-repository-core/src/test/java/org/eclipse/hawkbit/event/BusProtoStuffMessageConverterTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ void successfullySerializeAndDeserializeEvent() {
5757
// deserialize
5858
when(messageMock.getPayload()).thenReturn(serializedEvent);
5959
final Object deserializedEvent = underTest.convertFromInternal(messageMock, RemoteApplicationEvent.class, null);
60-
assertThat(deserializedEvent).isInstanceOf(TargetCreatedEvent.class);
61-
assertThat(deserializedEvent).isEqualTo(targetCreatedEvent);
60+
assertThat(deserializedEvent)
61+
.isInstanceOf(TargetCreatedEvent.class)
62+
.isEqualTo(targetCreatedEvent);
6263
}
6364

6465
@Test

hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/AbstractDsAssignmentStrategy.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.eclipse.hawkbit.repository.event.remote.entity.TargetUpdatedEvent;
2727
import org.eclipse.hawkbit.repository.jpa.configuration.Constants;
2828
import org.eclipse.hawkbit.repository.jpa.executor.AfterTransactionCommitExecutor;
29+
import org.eclipse.hawkbit.repository.jpa.model.AbstractJpaBaseEntity_;
2930
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
3031
import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus;
3132
import org.eclipse.hawkbit.repository.jpa.model.JpaAction_;
@@ -60,12 +61,14 @@ public abstract class AbstractDsAssignmentStrategy {
6061
protected final AfterTransactionCommitExecutor afterCommit;
6162
protected final EventPublisherHolder eventPublisherHolder;
6263
protected final ActionRepository actionRepository;
64+
6365
private final ActionStatusRepository actionStatusRepository;
6466
private final QuotaManagement quotaManagement;
6567
private final BooleanSupplier multiAssignmentsConfig;
6668
private final BooleanSupplier confirmationFlowConfig;
6769
private final RepositoryProperties repositoryProperties;
6870

71+
@SuppressWarnings("java:S107")
6972
AbstractDsAssignmentStrategy(
7073
final TargetRepository targetRepository,
7174
final AfterTransactionCommitExecutor afterCommit, final EventPublisherHolder eventPublisherHolder,
@@ -149,7 +152,7 @@ protected List<Long> overrideObsoleteUpdateActions(final Collection<Long> target
149152
cb.equal(root.get(JpaAction_.active), true),
150153
cb.equal(root.get(JpaAction_.distributionSet).get(JpaDistributionSet_.requiredMigrationStep), false),
151154
cb.notEqual(root.get(JpaAction_.status), Action.Status.CANCELING),
152-
root.get(JpaAction_.target).get(JpaTarget_.id).in(targetsIds)
155+
root.get(JpaAction_.target).get(AbstractJpaBaseEntity_.id).in(targetsIds)
153156
);
154157
});
155158

@@ -187,7 +190,7 @@ protected List<Long> closeObsoleteUpdateActions(final Collection<Long> targetsId
187190
return cb.and(
188191
cb.equal(root.get(JpaAction_.active), true),
189192
cb.equal(root.get(JpaAction_.distributionSet).get(JpaDistributionSet_.requiredMigrationStep), false),
190-
root.get(JpaAction_.target).get(JpaTarget_.id).in(targetsIds)
193+
root.get(JpaAction_.target).get(AbstractJpaBaseEntity_.id).in(targetsIds)
191194
);
192195
});
193196

hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/AbstractRemoteEventTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
/**
3838
* Test the remote entity events.
3939
*/
40+
@SuppressWarnings("java:S6813") // constructor injects are not possible for test classes
4041
public abstract class AbstractRemoteEventTest extends AbstractJpaIntegrationTest {
4142

4243
@Autowired

hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTest.java

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
@ContextConfiguration(classes = { RepositoryApplicationConfiguration.class, TestConfiguration.class })
7979
@Import(TestChannelBinderConfiguration.class)
8080
@TestPropertySource(locations = "classpath:/jpa-test.properties")
81+
@SuppressWarnings("java:S6813") // constructor injects are not possible for test classes
8182
public abstract class AbstractJpaIntegrationTest extends AbstractIntegrationTest {
8283

8384
protected static final String INVALID_TEXT_HTML = "</noscript><br><script>";
@@ -91,58 +92,40 @@ public abstract class AbstractJpaIntegrationTest extends AbstractIntegrationTest
9192

9293
@Autowired
9394
protected TargetRepository targetRepository;
94-
9595
@Autowired
9696
protected ActionRepository actionRepository;
97-
9897
@Autowired
9998
protected DistributionSetRepository distributionSetRepository;
100-
10199
@Autowired
102100
protected SoftwareModuleRepository softwareModuleRepository;
103-
104101
@Autowired
105102
protected TenantMetaDataRepository tenantMetaDataRepository;
106-
107103
@Autowired
108104
protected DistributionSetTypeRepository distributionSetTypeRepository;
109-
110105
@Autowired
111106
protected SoftwareModuleTypeRepository softwareModuleTypeRepository;
112-
113107
@Autowired
114108
protected TargetTagRepository targetTagRepository;
115-
116109
@Autowired
117110
protected TargetTypeRepository targetTypeRepository;
118-
119111
@Autowired
120112
protected DistributionSetTagRepository distributionSetTagRepository;
121-
122113
@Autowired
123114
protected SoftwareModuleMetadataRepository softwareModuleMetadataRepository;
124-
125115
@Autowired
126116
protected ActionStatusRepository actionStatusRepository;
127-
128117
@Autowired
129118
protected LocalArtifactRepository artifactRepository;
130-
131119
@Autowired
132120
protected RolloutGroupRepository rolloutGroupRepository;
133-
134121
@Autowired
135122
protected RolloutTargetGroupRepository rolloutTargetGroupRepository;
136-
137123
@Autowired
138124
protected RolloutRepository rolloutRepository;
139-
140125
@Autowired
141126
protected TenantConfigurationProperties tenantConfigurationProperties;
142-
143127
@Autowired
144128
protected RolloutTestApprovalStrategy approvalStrategy;
145-
146129
@Autowired
147130
private JpaProperties jpaProperties;
148131

hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/autoassign/AutoAssignCheckerIntTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
*/
5353
@Feature("Component Tests - Repository")
5454
@Story("Auto assign checker")
55+
@SuppressWarnings("java:S6813") // constructor injects are not possible for test classes
5556
class AutoAssignCheckerIntTest extends AbstractJpaIntegrationTest {
5657

5758
private static final String SPACE_AND_DESCRIPTION = " description";

hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/autocleanup/AutoActionCleanupTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
*/
3434
@Feature("Component Tests - Repository")
3535
@Story("Action cleanup handler")
36+
@SuppressWarnings("java:S6813") // constructor injects are not possible for test classes
3637
class AutoActionCleanupTest extends AbstractJpaIntegrationTest {
3738

3839
@Autowired

hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/autocleanup/AutoCleanupSchedulerTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
*/
2929
@Feature("Component Tests - Repository")
3030
@Story("Auto cleanup scheduler")
31+
@SuppressWarnings("java:S6813") // constructor injects are not possible for test classes
3132
class AutoCleanupSchedulerTest extends AbstractJpaIntegrationTest {
3233

3334
private final AtomicInteger counter = new AtomicInteger();

hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/event/RepositoryEntityEventTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
@Feature("Component Tests - Repository")
5151
@Story("Entity Events")
5252
@SpringBootTest(classes = { RepositoryTestConfiguration.class }, webEnvironment = SpringBootTest.WebEnvironment.NONE)
53+
@SuppressWarnings("java:S6813") // constructor injects are not possible for test classes
5354
public class RepositoryEntityEventTest extends AbstractJpaIntegrationTest {
5455

5556
@Autowired

hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/ConfirmationManagementTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import java.util.Arrays;
1717
import java.util.List;
1818
import java.util.Objects;
19-
import java.util.stream.Collectors;
2019
import java.util.stream.Stream;
2120

2221
import io.qameta.allure.Description;

hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/DeploymentManagementTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,7 +1283,7 @@ void deleteDistributionSet() {
12831283
.asList(DistributionSetSpecification.isDeleted(true), DistributionSetSpecification.isCompleted(true))),
12841284
PAGE).getContent()).as("wrong size of founded ds").hasSize(noOfDistributionSets);
12851285

1286-
for (final DistributionSet ds : deploymentResult.getDistributionSets()) {
1286+
for (final DistributionSet ignored : deploymentResult.getDistributionSets()) {
12871287
testdataFactory.sendUpdateActionStatusToTargets(deploymentResult.getDeployedTargets(), Status.FINISHED,
12881288
Collections.singletonList("blabla alles gut"));
12891289
}
@@ -1316,7 +1316,7 @@ void deletesTargetsAndVerifyCascadeDeletes() {
13161316
final DeploymentResult deploymentResult = prepareComplexRepo(undeployedTargetPrefix, noOfUndeployedTargets,
13171317
deployedTargetPrefix, noOfDeployedTargets, noOfDistributionSets, "myTestDS");
13181318

1319-
for (final DistributionSet ds : deploymentResult.getDistributionSets()) {
1319+
for (final DistributionSet ignored : deploymentResult.getDistributionSets()) {
13201320
testdataFactory.sendUpdateActionStatusToTargets(deploymentResult.getDeployedTargets(), Status.FINISHED,
13211321
Collections.singletonList("blabla alles gut"));
13221322
}

hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLParserValidationOracleTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
@Feature("Component Tests - Repository")
2929
@Story("RSQL filter suggestion")
30+
@SuppressWarnings("java:S6813") // constructor injects are not possible for test classes
3031
public class RSQLParserValidationOracleTest extends AbstractJpaIntegrationTest {
3132

3233
private static final String[] OP_SUGGESTIONS = new String[] { "==", "!=", "=ge=", "=le=", "=gt=", "=lt=", "=in=",
@@ -35,6 +36,7 @@ public class RSQLParserValidationOracleTest extends AbstractJpaIntegrationTest {
3536
.map(field -> field.name().toLowerCase()).toArray(String[]::new);
3637
private static final String[] AND_OR_SUGGESTIONS = new String[] { "and", "or" };
3738
private static final String[] NAME_VERSION_SUGGESTIONS = new String[] { "name", "version" };
39+
3840
@Autowired
3941
private RsqlValidationOracle rsqlValidationOracle;
4042

hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/TestConfiguration.java

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,25 @@
2525
import org.eclipse.hawkbit.cache.TenantAwareCacheManager;
2626
import org.eclipse.hawkbit.event.BusProtoStuffMessageConverter;
2727
import org.eclipse.hawkbit.im.authentication.SpRole;
28+
import org.eclipse.hawkbit.repository.ArtifactManagement;
29+
import org.eclipse.hawkbit.repository.ControllerManagement;
30+
import org.eclipse.hawkbit.repository.DeploymentManagement;
31+
import org.eclipse.hawkbit.repository.DistributionSetInvalidationManagement;
32+
import org.eclipse.hawkbit.repository.DistributionSetManagement;
33+
import org.eclipse.hawkbit.repository.DistributionSetTagManagement;
34+
import org.eclipse.hawkbit.repository.DistributionSetTypeManagement;
35+
import org.eclipse.hawkbit.repository.EntityFactory;
36+
import org.eclipse.hawkbit.repository.QuotaManagement;
2837
import org.eclipse.hawkbit.repository.RolloutApprovalStrategy;
38+
import org.eclipse.hawkbit.repository.RolloutHandler;
39+
import org.eclipse.hawkbit.repository.RolloutManagement;
2940
import org.eclipse.hawkbit.repository.RolloutStatusCache;
41+
import org.eclipse.hawkbit.repository.SoftwareModuleManagement;
42+
import org.eclipse.hawkbit.repository.SoftwareModuleTypeManagement;
43+
import org.eclipse.hawkbit.repository.TargetFilterQueryManagement;
44+
import org.eclipse.hawkbit.repository.TargetManagement;
45+
import org.eclipse.hawkbit.repository.TargetTagManagement;
46+
import org.eclipse.hawkbit.repository.TargetTypeManagement;
3047
import org.eclipse.hawkbit.repository.event.ApplicationEventFilter;
3148
import org.eclipse.hawkbit.repository.model.helper.EventPublisherHolder;
3249
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
@@ -141,8 +158,22 @@ SystemManagementHolder systemManagementHolder() {
141158
}
142159

143160
@Bean
144-
TestdataFactory testdataFactory() {
145-
return new TestdataFactory();
161+
TestdataFactory testdataFactory(
162+
final ControllerManagement controllerManagement, final ArtifactManagement artifactManagement,
163+
final SoftwareModuleManagement softwareModuleManagement, final SoftwareModuleTypeManagement softwareModuleTypeManagement,
164+
final DistributionSetManagement distributionSetManagement,
165+
final DistributionSetInvalidationManagement distributionSetInvalidationManagement,
166+
final DistributionSetTypeManagement distributionSetTypeManagement,
167+
final TargetManagement targetManagement, final TargetFilterQueryManagement targetFilterQueryManagement,
168+
final TargetTypeManagement targetTypeManagement, final TargetTagManagement targetTagManagement,
169+
final DeploymentManagement deploymentManagement, final DistributionSetTagManagement distributionSetTagManagement,
170+
final RolloutManagement rolloutManagement, final RolloutHandler rolloutHandler,
171+
final QuotaManagement quotaManagement,
172+
final EntityFactory entityFactory) {
173+
return new TestdataFactory(controllerManagement, artifactManagement, softwareModuleManagement, softwareModuleTypeManagement,
174+
distributionSetManagement, distributionSetInvalidationManagement, distributionSetTypeManagement, targetManagement,
175+
targetFilterQueryManagement, targetTypeManagement, targetTagManagement, deploymentManagement,
176+
distributionSetTagManagement, rolloutManagement, rolloutHandler, quotaManagement, entityFactory);
146177
}
147178

148179
@Bean

hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
listeners = { EventVerifier.class, CleanupTestExecutionListener.class },
108108
mergeMode = MergeMode.MERGE_WITH_DEFAULTS)
109109
@TestPropertySource(properties = "spring.main.allow-bean-definition-overriding=true")
110+
@SuppressWarnings("java:S6813") // constructor injects are not possible for test classes
110111
public abstract class AbstractIntegrationTest {
111112

112113
protected static final Pageable PAGE = PageRequest.of(0, 500, Sort.by(Direction.ASC, "id"));
@@ -120,6 +121,7 @@ public abstract class AbstractIntegrationTest {
120121
* {@link SystemManagement#getTenantMetadata()};
121122
*/
122123
protected static final int DEFAULT_DS_TYPES = RepositoryConstants.DEFAULT_DS_TYPES_IN_TENANT + 1;
124+
123125
@Autowired
124126
protected EntityFactory entityFactory;
125127
@Autowired
@@ -478,6 +480,7 @@ protected void waitNextMillis() {
478480
}
479481
}
480482

483+
@SuppressWarnings("java:S4042")
481484
private static File createTempDir() {
482485
try {
483486
final File file = Files.createTempDirectory(System.currentTimeMillis() + "_").toFile();

0 commit comments

Comments
 (0)