Fix some compile warnings (#2919)

* Fix some compile warnings
* Some classes made final
* JPA entities made not serializable

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2026-02-11 14:05:46 +02:00
committed by GitHub
parent 17eacc729b
commit 62c76311e5
89 changed files with 362 additions and 358 deletions

View File

@@ -16,19 +16,13 @@ import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
import org.springframework.util.ErrorHandler;
/**
* {@link RabbitListenerContainerFactory} that can be configured through
* hawkBit's {@link AmqpProperties}.
* {@link RabbitListenerContainerFactory} that can be configured through hawkBit's {@link AmqpProperties}.
*/
public class ConfigurableRabbitListenerContainerFactory extends SimpleRabbitListenerContainerFactory {
public final class ConfigurableRabbitListenerContainerFactory extends SimpleRabbitListenerContainerFactory {
private final int declarationRetries;
/**
* Constructor.
*
* @param missingQueuesFatal the missingQueuesFatal to set.
* @param declarationRetries The number of retries
* @param errorHandler the error handler which should be use
* @see SimpleMessageListenerContainer#setMissingQueuesFatal
*/
public ConfigurableRabbitListenerContainerFactory(

View File

@@ -32,7 +32,7 @@ import org.springframework.util.ObjectUtils;
*/
@ToString
@Slf4j
class RequeueExceptionStrategy implements FatalExceptionStrategy {
final class RequeueExceptionStrategy implements FatalExceptionStrategy {
private final List<FatalExceptionStrategy> fatalExceptionStrategies = new ArrayList<>();

View File

@@ -43,7 +43,6 @@ import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.ActionProperties;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TenantConfigurationValue;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -427,8 +426,8 @@ class AmqpMessageHandlerServiceTest {
* Test next update is provided on finished action
*/
@Test
@SuppressWarnings("unchecked")
void lookupNextUpdateActionAfterFinished() {
// Mock
final Action action = createActionWithTarget(22L);
when(controllerManagementMock.findActionWithDetails(anyLong())).thenReturn(Optional.of(action));
@@ -460,7 +459,7 @@ class AmqpMessageHandlerServiceTest {
* Test feedback code is persisted in messages when provided with DmfActionUpdateStatus
*/
@Test
void feedBackCodeIsPersistedInMessages() throws IllegalAccessException {
void feedBackCodeIsPersistedInMessages() {
// Mock
final Action action = createActionWithTarget(22L);
when(controllerManagementMock.findActionWithDetails(anyLong())).thenReturn(Optional.of(action));
@@ -471,9 +470,7 @@ class AmqpMessageHandlerServiceTest {
final MessageProperties messageProperties = createMessageProperties(MessageType.EVENT);
messageProperties.setHeader(MessageHeaderKey.TOPIC, EventTopic.UPDATE_ACTION_STATUS.name());
final DmfActionUpdateStatus actionUpdateStatus = new DmfActionUpdateStatus(
23L, DmfActionStatus.RUNNING, null, 2L, null, 12);
final DmfActionUpdateStatus actionUpdateStatus = new DmfActionUpdateStatus(23L, DmfActionStatus.RUNNING, null, 2L, null, 12);
final Message message = createMessage(actionUpdateStatus, messageProperties);
// test

View File

@@ -84,7 +84,7 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
private static final String DMF_ATTR_TEST_CONTROLLER_ID = "Dmf_hand_updateAttributes";
private static final String UPDATE_ATTR_TEST_CONTROLLER_ID = "ControllerAttributeTestTarget";
private static final String TARGET_PREFIX = "Dmf_hand_";
@Autowired
private AmqpProperties amqpProperties;
@@ -133,11 +133,8 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
void registerTargetWithName() {
final String controllerId = TARGET_PREFIX + "registerTargetWithName";
final String name = "NonDefaultTargetName";
registerAndAssertTargetWithExistingTenant(controllerId, name, 1, TargetUpdateStatus.REGISTERED, CREATED_BY,
null);
registerSameTargetAndAssertBasedOnVersion(controllerId, name + "_updated", 1, TargetUpdateStatus.REGISTERED,
null);
registerAndAssertTargetWithExistingTenant(controllerId, name, 1, TargetUpdateStatus.REGISTERED, CREATED_BY, null);
registerSameTargetAndAssertBasedOnVersion(controllerId, name + "_updated", 1, TargetUpdateStatus.REGISTERED, null);
Mockito.verifyNoInteractions(getDeadletterListener());
}
@@ -156,8 +153,7 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
attributes.put("testKey1", "testValue1");
attributes.put("testKey2", "testValue2");
registerAndAssertTargetWithExistingTenant(controllerId, null, 1, TargetUpdateStatus.REGISTERED, CREATED_BY,
attributes);
registerAndAssertTargetWithExistingTenant(controllerId, null, 1, TargetUpdateStatus.REGISTERED, CREATED_BY, attributes);
attributes.put("testKey3", "testValue3");
registerSameTargetAndAssertBasedOnVersion(controllerId, null, 1, TargetUpdateStatus.REGISTERED, attributes);
@@ -176,24 +172,22 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
void registerTargetWithNameAndAttributes() {
final String controllerId = TARGET_PREFIX + "registerTargetWithAttributes";
final String name = "NonDefaultTargetName";
final Map<String, String> attributes = new HashMap<>();
attributes.put("testKey1", "testValue1");
attributes.put("testKey2", "testValue2");
registerAndAssertTargetWithExistingTenant(controllerId, name, 1, TargetUpdateStatus.REGISTERED, CREATED_BY,
attributes);
registerAndAssertTargetWithExistingTenant(controllerId, name, 1, TargetUpdateStatus.REGISTERED, CREATED_BY, attributes);
attributes.put("testKey3", "testValue3");
registerSameTargetAndAssertBasedOnVersion(controllerId, name + "_updated", 1, TargetUpdateStatus.REGISTERED,
attributes);
registerSameTargetAndAssertBasedOnVersion(controllerId, name + "_updated", 1, TargetUpdateStatus.REGISTERED, attributes);
Mockito.verifyNoInteractions(getDeadletterListener());
}
@ParameterizedTest
/**
* Tests register invalid target with empty controller id.
*/
@ParameterizedTest
@ValueSource(strings = { "", "Invalid Invalid" })
@NullSource
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class) })
@@ -328,10 +322,10 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
assertAllTargetsCount(0);
}
@ParameterizedTest
/**
* Tests null type message header. This message should forwarded to the deadletter queue
*/
@ParameterizedTest
@ValueSource(strings = { "", "NotExist" })
@NullSource
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class) })
@@ -344,10 +338,10 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
assertAllTargetsCount(0);
}
@ParameterizedTest
/**
* Tests null topic message header. This message should forwarded to the deadletter queue
*/
@ParameterizedTest
@ValueSource(strings = { "", "NotExist" })
@NullSource
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class) })
@@ -372,10 +366,10 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
verifyOneDeadLetterMessage();
}
@ParameterizedTest
/**
* Tests invalid null message content. This message should forwarded to the deadletter queue
*/
@ParameterizedTest
@ValueSource(strings = { "", "Invalid Content" })
@NullSource
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class) })
@@ -431,7 +425,7 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
@Expect(type = SoftwareModuleCreatedEvent.class, count = 3),
@Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock
@Expect(type = SoftwareModuleUpdatedEvent.class, count = 9), // implicit lock
@Expect(type = TargetUpdatedEvent.class, count = 1),
@Expect(type = TargetUpdatedEvent.class, count = 1),
@Expect(type = TargetPollEvent.class, count = 1) })
void runningActionStatus() {
final String controllerId = TARGET_PREFIX + "runningActionStatus";
@@ -451,7 +445,7 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
@Expect(type = SoftwareModuleCreatedEvent.class, count = 3),
@Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock
@Expect(type = SoftwareModuleUpdatedEvent.class, count = 9), // implicit lock
@Expect(type = TargetUpdatedEvent.class, count = 1),
@Expect(type = TargetUpdatedEvent.class, count = 1),
@Expect(type = TargetPollEvent.class, count = 1) })
void downloadedActionStatus() {
final String controllerId = TARGET_PREFIX + "downloadedActionStatus";
@@ -470,7 +464,7 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
@Expect(type = SoftwareModuleCreatedEvent.class, count = 3),
@Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock
@Expect(type = SoftwareModuleUpdatedEvent.class, count = 9), // implicit lock
@Expect(type = TargetUpdatedEvent.class, count = 1),
@Expect(type = TargetUpdatedEvent.class, count = 1),
@Expect(type = TargetPollEvent.class, count = 1) })
void downloadActionStatus() {
final String controllerId = TARGET_PREFIX + "downloadActionStatus";
@@ -490,7 +484,7 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
@Expect(type = SoftwareModuleCreatedEvent.class, count = 3),
@Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock
@Expect(type = SoftwareModuleUpdatedEvent.class, count = 9), // implicit lock
@Expect(type = TargetUpdatedEvent.class, count = 2),
@Expect(type = TargetUpdatedEvent.class, count = 2),
@Expect(type = TargetPollEvent.class, count = 1) })
void errorActionStatus() {
final String controllerId = TARGET_PREFIX + "errorActionStatus";
@@ -509,7 +503,7 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
@Expect(type = SoftwareModuleCreatedEvent.class, count = 3),
@Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock
@Expect(type = SoftwareModuleUpdatedEvent.class, count = 9), // implicit lock
@Expect(type = TargetUpdatedEvent.class, count = 1),
@Expect(type = TargetUpdatedEvent.class, count = 1),
@Expect(type = TargetPollEvent.class, count = 1) })
void warningActionStatus() {
final String controllerId = TARGET_PREFIX + "warningActionStatus";
@@ -528,7 +522,7 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
@Expect(type = SoftwareModuleCreatedEvent.class, count = 3),
@Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock
@Expect(type = SoftwareModuleUpdatedEvent.class, count = 9), // implicit lock
@Expect(type = TargetUpdatedEvent.class, count = 1),
@Expect(type = TargetUpdatedEvent.class, count = 1),
@Expect(type = TargetPollEvent.class, count = 1) })
void retrievedActionStatus() {
final String controllerId = TARGET_PREFIX + "retrievedActionStatus";
@@ -547,7 +541,7 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
@Expect(type = SoftwareModuleCreatedEvent.class, count = 3),
@Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock
@Expect(type = SoftwareModuleUpdatedEvent.class, count = 9), // implicit lock
@Expect(type = TargetUpdatedEvent.class, count = 1),
@Expect(type = TargetUpdatedEvent.class, count = 1),
@Expect(type = TargetPollEvent.class, count = 1) })
void cancelNotAllowActionStatus() {
final String controllerId = TARGET_PREFIX + "cancelNotAllowActionStatus";
@@ -567,7 +561,7 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
@Expect(type = SoftwareModuleCreatedEvent.class, count = 3),
@Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock
@Expect(type = SoftwareModuleUpdatedEvent.class, count = 9), // implicit lock
@Expect(type = TargetUpdatedEvent.class, count = 1),
@Expect(type = TargetUpdatedEvent.class, count = 1),
@Expect(type = TargetPollEvent.class, count = 2) })
void receiveDownloadAndInstallMessageAfterAssignment() {
final String controllerId = TARGET_PREFIX + "receiveDownLoadAndInstallMessageAfterAssignment";
@@ -598,7 +592,7 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
@Expect(type = SoftwareModuleCreatedEvent.class, count = 3),
@Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock
@Expect(type = SoftwareModuleUpdatedEvent.class, count = 9), // implicit lock
@Expect(type = TargetUpdatedEvent.class, count = 1),
@Expect(type = TargetUpdatedEvent.class, count = 1),
@Expect(type = TargetPollEvent.class, count = 2) })
void receiveDownloadMessageBeforeMaintenanceWindowStartTime() {
final String controllerId = TARGET_PREFIX + "receiveDownLoadMessageBeforeMaintenanceWindowStartTime";
@@ -607,8 +601,8 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
registerAndAssertTargetWithExistingTenant(controllerId);
final DistributionSet distributionSet = testdataFactory.createDistributionSet(UUID.randomUUID().toString());
testdataFactory.addSoftwareModuleMetadata(distributionSet);
assignDistributionSetWithMaintenanceWindow(distributionSet.getId(), controllerId, getTestSchedule(2),
getTestDuration(1), getTestTimeZone());
assignDistributionSetWithMaintenanceWindow(
distributionSet.getId(), controllerId, getTestSchedule(2), getTestDuration(1), getTestTimeZone());
// test
registerSameTargetAndAssertBasedOnVersion(controllerId, 1, TargetUpdateStatus.PENDING);
@@ -630,7 +624,7 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
@Expect(type = SoftwareModuleCreatedEvent.class, count = 3),
@Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock
@Expect(type = SoftwareModuleUpdatedEvent.class, count = 9), // implicit lock
@Expect(type = TargetUpdatedEvent.class, count = 1),
@Expect(type = TargetUpdatedEvent.class, count = 1),
@Expect(type = TargetPollEvent.class, count = 2) })
void receiveDownloadAndInstallMessageDuringMaintenanceWindow() {
final String controllerId = TARGET_PREFIX + "receiveDownLoadAndInstallMessageDuringMaintenanceWindow";
@@ -639,8 +633,8 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
registerAndAssertTargetWithExistingTenant(controllerId);
final DistributionSet distributionSet = testdataFactory.createDistributionSet(UUID.randomUUID().toString());
testdataFactory.addSoftwareModuleMetadata(distributionSet);
assignDistributionSetWithMaintenanceWindow(distributionSet.getId(), controllerId, getTestSchedule(-5),
getTestDuration(10), getTestTimeZone());
assignDistributionSetWithMaintenanceWindow(
distributionSet.getId(), controllerId, getTestSchedule(-5), getTestDuration(10), getTestTimeZone());
// test
registerSameTargetAndAssertBasedOnVersion(controllerId, 1, TargetUpdateStatus.PENDING);
@@ -722,7 +716,7 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
@Expect(type = SoftwareModuleCreatedEvent.class, count = 3),
@Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock
@Expect(type = SoftwareModuleUpdatedEvent.class, count = 9), // implicit lock
@Expect(type = TargetUpdatedEvent.class, count = 1),
@Expect(type = TargetUpdatedEvent.class, count = 1),
@Expect(type = TargetPollEvent.class, count = 1) })
void canceledRejectedNotAllowActionStatus() {
final String controllerId = TARGET_PREFIX + "canceledRejectedNotAllowActionStatus";
@@ -744,7 +738,7 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
@Expect(type = SoftwareModuleCreatedEvent.class, count = 3),
@Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock
@Expect(type = SoftwareModuleUpdatedEvent.class, count = 9), // implicit lock
@Expect(type = TargetUpdatedEvent.class, count = 1),
@Expect(type = TargetUpdatedEvent.class, count = 1),
@Expect(type = TargetPollEvent.class, count = 1) })
void canceledRejectedActionStatus() {
final String controllerId = TARGET_PREFIX + "canceledRejectedActionStatus";
@@ -770,22 +764,16 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
@Expect(type = TargetPollEvent.class, count = 1) })
void updateAttributesWithDifferentUpdateModes() {
final String controllerId = TARGET_PREFIX + "updateAttributes";
// setup
registerAndAssertTargetWithExistingTenant(controllerId);
// no update mode specified
updateAttributesWithoutUpdateMode();
// update mode REPLACE
updateAttributesWithUpdateModeReplace();
// update mode MERGE
updateAttributesWithUpdateModeMerge();
// update mode REMOVE
updateAttributesWithUpdateModeRemove();
}
/**
@@ -827,7 +815,7 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
void updateAttributesWithWrongBody() {
// setup
registerAndAssertTargetWithExistingTenant(UPDATE_ATTR_TEST_CONTROLLER_ID);
final Message createUpdateAttributesMessageWrongBody = createUpdateAttributesMessageWrongBody( UPDATE_ATTR_TEST_CONTROLLER_ID);
final Message createUpdateAttributesMessageWrongBody = createUpdateAttributesMessageWrongBody(UPDATE_ATTR_TEST_CONTROLLER_ID);
// test
getDmfClient().send(createUpdateAttributesMessageWrongBody);
@@ -902,8 +890,7 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
@Expect(type = TargetAttributesRequestedEvent.class, count = 2),
@Expect(type = TargetUpdatedEvent.class, count = 3),
@Expect(type = TargetPollEvent.class, count = 1) })
void downloadOnlyAssignmentAllowsActionStatusUpdatesWhenTargetReportsFinishedAndUpdatesInstalledDS()
throws IOException {
void downloadOnlyAssignmentAllowsActionStatusUpdatesWhenTargetReportsFinishedAndUpdatesInstalledDS() throws IOException {
// create target
final String controllerId = TARGET_PREFIX + "registerTargets_1";
final DistributionSet distributionSet = createTargetAndDistributionSetAndAssign(controllerId, DOWNLOAD_ONLY);
@@ -1125,10 +1112,8 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
}
private void updateAttributesWithUpdateModeRemove() {
// assemble the expected attributes
final Map<String, String> expectedAttributes = targetManagement
.getControllerAttributes(DMF_ATTR_TEST_CONTROLLER_ID);
final Map<String, String> expectedAttributes = targetManagement.getControllerAttributes(DMF_ATTR_TEST_CONTROLLER_ID);
expectedAttributes.remove("k1");
expectedAttributes.remove("k3");
@@ -1256,8 +1241,7 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
}
private void sendUpdateAttributeMessage(final DmfAttributeUpdate attributeUpdate) {
final Message updateMessage = createUpdateAttributesMessage(DMF_ATTR_TEST_CONTROLLER_ID,
AbstractAmqpServiceIntegrationTest.TENANT_EXIST, attributeUpdate);
final Message updateMessage = createUpdateAttributesMessage(DMF_ATTR_TEST_CONTROLLER_ID, TENANT_EXIST, attributeUpdate);
getDmfClient().send(updateMessage);
}
@@ -1266,8 +1250,7 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
await().untilAsserted(() -> {
try {
SecurityContextSwitch.asPrivileged(() -> {
final List<ActionStatus> actionStatusList = deploymentManagement
.findActionStatusByAction(actionId, PAGE).getContent();
final List<ActionStatus> actionStatusList = deploymentManagement.findActionStatusByAction(actionId, PAGE).getContent();
assertThat(actionStatusList).hasSize(statusListCount);
final List<Status> status = actionStatusList.stream().map(ActionStatus::getStatus)
@@ -1283,9 +1266,8 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
}
private int getAuthenticationMessageCount() {
return Integer
.parseInt(Objects.requireNonNull(getRabbitAdmin().getQueueProperties(amqpProperties.getReceiverQueue()))
.get(RabbitAdmin.QUEUE_MESSAGE_COUNT).toString());
return Integer.parseInt(Objects.requireNonNull(
getRabbitAdmin().getQueueProperties(amqpProperties.getReceiverQueue())).get(RabbitAdmin.QUEUE_MESSAGE_COUNT).toString());
}
private void assertEmptyReceiverQueueCount() {
@@ -1298,8 +1280,7 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
private void verifyNumberOfDeadLetterMessages(final int numberOfInvocations) {
assertEmptyReceiverQueueCount();
await().untilAsserted(
() -> Mockito.verify(getDeadletterListener(), Mockito.times(numberOfInvocations)).handleMessage(Mockito.any()));
await().untilAsserted(() -> Mockito.verify(getDeadletterListener(), Mockito.times(numberOfInvocations)).handleMessage(Mockito.any()));
Mockito.reset(getDeadletterListener());
}
}