Fix SonarQube issues (2) (#2205)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -32,8 +32,8 @@ public final class AmqpErrorMessageComposer {
|
||||
*/
|
||||
public static String constructErrorMessage(final Throwable throwable) {
|
||||
final String mainErrorMsg = throwable.getCause().getMessage();
|
||||
if (throwable instanceof ListenerExecutionFailedException) {
|
||||
Collection<Message> failedMessages = ((ListenerExecutionFailedException) throwable).getFailedMessages();
|
||||
if (throwable instanceof ListenerExecutionFailedException listenerExecutionFailedException) {
|
||||
Collection<Message> failedMessages = listenerExecutionFailedException.getFailedMessages();
|
||||
// since the intended message content is always on top of the collection, we only extract the first one
|
||||
final Message failedMessage = failedMessages.iterator().next();
|
||||
final byte[] amqpFailedMsgBody = failedMessage.getBody();
|
||||
|
||||
@@ -370,7 +370,7 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
||||
// Handling remote request in parallel streams
|
||||
return StreamSupport.stream(partitions.spliterator(), true) //
|
||||
.flatMap(partition -> withSecurityContext(() -> loadingFunction.apply(partition), context).stream())
|
||||
.collect(Collectors.toList());
|
||||
.toList();
|
||||
}
|
||||
return loadingFunction.apply(controllerIds);
|
||||
}
|
||||
@@ -436,7 +436,7 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}).collect(Collectors.toList()));
|
||||
}).toList());
|
||||
}
|
||||
|
||||
private void sendUpdateMessageToTargets(
|
||||
@@ -570,7 +570,7 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
||||
}
|
||||
|
||||
private List<DmfMetadata> convertMetadata(final List<SoftwareModuleMetadata> metadata) {
|
||||
return metadata.stream().map(md -> new DmfMetadata(md.getKey(), md.getValue())).collect(Collectors.toList());
|
||||
return metadata.stream().map(md -> new DmfMetadata(md.getKey(), md.getValue())).toList();
|
||||
}
|
||||
|
||||
private List<DmfArtifact> convertArtifacts(final Target target, final List<Artifact> localArtifacts) {
|
||||
@@ -579,7 +579,7 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
||||
}
|
||||
|
||||
return localArtifacts.stream().map(localArtifact -> convertArtifact(target, localArtifact))
|
||||
.collect(Collectors.toList());
|
||||
.toList();
|
||||
}
|
||||
|
||||
private DmfArtifact convertArtifact(final Target target, final Artifact localArtifact) {
|
||||
@@ -619,7 +619,7 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
||||
final List<DmfTarget> dmfTargets = targets.stream()
|
||||
.filter(target -> IpUtil.isAmqpUri(target.getAddress()))
|
||||
.map(t -> convertToDmfTarget(t, actions.get(t.getControllerId()).getId()))
|
||||
.collect(Collectors.toList());
|
||||
.toList();
|
||||
|
||||
final DmfBatchDownloadAndUpdateRequest batchRequest = new DmfBatchDownloadAndUpdateRequest();
|
||||
batchRequest.setTimestamp(System.currentTimeMillis());
|
||||
|
||||
@@ -23,6 +23,8 @@ import java.util.UUID;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.hawkbit.dmf.amqp.api.EventTopic;
|
||||
import org.eclipse.hawkbit.dmf.amqp.api.MessageHeaderKey;
|
||||
@@ -215,7 +217,7 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
|
||||
|
||||
// Exception squid:MethodCyclomaticComplexity - false positive, is a simple mapping
|
||||
@SuppressWarnings("squid:MethodCyclomaticComplexity")
|
||||
private static Status mapStatus(final Message message, final DmfActionUpdateStatus actionUpdateStatus, final Action action) {
|
||||
private static @NotNull Status mapStatus(final Message message, final DmfActionUpdateStatus actionUpdateStatus, final Action action) {
|
||||
Status status = null;
|
||||
switch (actionUpdateStatus.getActionStatus()) {
|
||||
case DOWNLOAD: {
|
||||
@@ -226,8 +228,7 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
|
||||
status = Status.RETRIEVED;
|
||||
break;
|
||||
}
|
||||
case RUNNING:
|
||||
case CONFIRMED: {
|
||||
case RUNNING, CONFIRMED: {
|
||||
status = Status.RUNNING;
|
||||
break;
|
||||
}
|
||||
@@ -373,7 +374,7 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
|
||||
}
|
||||
|
||||
private Map<SoftwareModule, List<SoftwareModuleMetadata>> getSoftwareModulesWithMetadata(final DistributionSet distributionSet) {
|
||||
final List<Long> smIds = distributionSet.getModules().stream().map(SoftwareModule::getId).collect(Collectors.toList());
|
||||
final List<Long> smIds = distributionSet.getModules().stream().map(SoftwareModule::getId).toList();
|
||||
final Map<Long, List<SoftwareModuleMetadata>> metadata = controllerManagement.findTargetVisibleMetaDataBySoftwareModuleId(smIds);
|
||||
return distributionSet.getModules().stream().collect(Collectors.toMap(
|
||||
Function.identity(), sm -> metadata.getOrDefault(sm.getId(), Collections.emptyList())));
|
||||
|
||||
@@ -83,7 +83,7 @@ class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTest {
|
||||
private Target testTarget;
|
||||
|
||||
@BeforeEach
|
||||
public void beforeEach() throws Exception {
|
||||
public void beforeEach() {
|
||||
testTarget = targetManagement.create(entityFactory.target().create().controllerId(CONTROLLER_ID)
|
||||
.securityToken(TEST_TOKEN).address(AMQP_URI.toString()));
|
||||
|
||||
@@ -135,8 +135,7 @@ class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTest {
|
||||
assertThat(downloadAndUpdateRequest.getTargetSecurityToken()).isEqualTo(TEST_TOKEN);
|
||||
for (final org.eclipse.hawkbit.dmf.json.model.DmfSoftwareModule softwareModule : downloadAndUpdateRequest
|
||||
.getSoftwareModules()) {
|
||||
assertThat(softwareModule.getArtifacts().isEmpty()).as("Artifact list for softwaremodule should be empty")
|
||||
.isTrue();
|
||||
assertThat(softwareModule.getArtifacts()).as("Artifact list for softwaremodule should be empty").isEmpty();
|
||||
|
||||
assertThat(softwareModule.getMetadata()).allSatisfy(metadata -> {
|
||||
assertThat(metadata.getKey()).isEqualTo(TestdataFactory.VISIBLE_SM_MD_KEY);
|
||||
@@ -202,7 +201,7 @@ class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTest {
|
||||
assertThat(found.get().getSize()).isEqualTo(dbArtifact.getSize());
|
||||
assertThat(found.get().getHashes().getMd5()).isEqualTo(dbArtifact.getMd5Hash());
|
||||
assertThat(found.get().getHashes().getSha1()).isEqualTo(dbArtifact.getSha1Hash());
|
||||
assertThat(found.get().getLastModified()).isGreaterThan(0L);
|
||||
assertThat(found.get().getLastModified()).isPositive();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ import org.springframework.amqp.support.converter.MessageConverter;
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@Feature("Component Tests - Device Management Federation API")
|
||||
@Story("AmqpMessage Handler Service Test")
|
||||
public class AmqpMessageHandlerServiceTest {
|
||||
class AmqpMessageHandlerServiceTest {
|
||||
|
||||
private static final String FAIL_MESSAGE_AMQP_REJECT_REASON = AmqpRejectAndDontRequeueException.class
|
||||
.getSimpleName() + " was expected, ";
|
||||
@@ -128,7 +128,7 @@ public class AmqpMessageHandlerServiceTest {
|
||||
|
||||
@BeforeEach
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public void before() {
|
||||
void before() {
|
||||
messageConverter = new Jackson2JsonMessageConverter();
|
||||
lenient().when(rabbitTemplate.getMessageConverter()).thenReturn(messageConverter);
|
||||
final TenantConfigurationValue multiAssignmentConfig = TenantConfigurationValue.builder().value(Boolean.FALSE)
|
||||
@@ -146,19 +146,20 @@ public class AmqpMessageHandlerServiceTest {
|
||||
|
||||
@Test
|
||||
@Description("Tests not allowed content-type in message")
|
||||
public void wrongContentType() {
|
||||
void wrongContentType() {
|
||||
final MessageProperties messageProperties = new MessageProperties();
|
||||
messageProperties.setContentType("xml");
|
||||
final Message message = new Message(new byte[0], messageProperties);
|
||||
final String type = MessageType.THING_CREATED.name();
|
||||
assertThatExceptionOfType(AmqpRejectAndDontRequeueException.class)
|
||||
.as(FAIL_MESSAGE_AMQP_REJECT_REASON + "due to wrong content type")
|
||||
.isThrownBy(() -> amqpMessageHandlerService.onMessage(message, MessageType.THING_CREATED.name(), TENANT,
|
||||
.isThrownBy(() -> amqpMessageHandlerService.onMessage(message, type, TENANT,
|
||||
VIRTUAL_HOST));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Tests the creation of a target/thing by calling the same method that incoming RabbitMQ messages would access.")
|
||||
public void createThing() {
|
||||
void createThing() {
|
||||
final String knownThingId = "1";
|
||||
|
||||
processThingCreatedMessage(knownThingId, null);
|
||||
@@ -169,7 +170,7 @@ public class AmqpMessageHandlerServiceTest {
|
||||
|
||||
@Test
|
||||
@Description("Tests the creation of a target/thing with specified name by calling the same method that incoming RabbitMQ messages would access.")
|
||||
public void createThingWithName() {
|
||||
void createThingWithName() {
|
||||
final String knownThingId = "2";
|
||||
final String knownThingName = "NonDefaultTargetName";
|
||||
|
||||
@@ -185,7 +186,7 @@ public class AmqpMessageHandlerServiceTest {
|
||||
|
||||
@Test
|
||||
@Description("Tests the creation of a target/thing with specified type name by calling the same method that incoming RabbitMQ messages would access.")
|
||||
public void createThingWithType() {
|
||||
void createThingWithType() {
|
||||
final String knownThingId = "2";
|
||||
final String knownThingTypeName = "TargetTypeName";
|
||||
|
||||
@@ -201,19 +202,17 @@ public class AmqpMessageHandlerServiceTest {
|
||||
|
||||
@Test
|
||||
@Description("Tests not allowed body in message")
|
||||
public void createThingWithWrongBody() {
|
||||
final String knownThingId = "3";
|
||||
|
||||
void createThingWithWrongBody() {
|
||||
final Message message = createMessage("Not allowed Body".getBytes(), getThingCreatedMessageProperties("3"));
|
||||
final String type = MessageType.THING_CREATED.name();
|
||||
assertThatExceptionOfType(MessageConversionException.class)
|
||||
.as("MessageConversionException was excepeted due to wrong body")
|
||||
.isThrownBy(() -> amqpMessageHandlerService.onMessage(
|
||||
createMessage("Not allowed Body".getBytes(), getThingCreatedMessageProperties(knownThingId)),
|
||||
MessageType.THING_CREATED.name(), TENANT, VIRTUAL_HOST));
|
||||
.isThrownBy(() -> amqpMessageHandlerService.onMessage(message, type, TENANT, VIRTUAL_HOST));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Tests the creation of a target/thing with specified attributes by calling the same method that incoming RabbitMQ messages would access.")
|
||||
public void createThingWithAttributes() {
|
||||
void createThingWithAttributes() {
|
||||
final String knownThingId = "4";
|
||||
|
||||
final DmfAttributeUpdate attributeUpdate = new DmfAttributeUpdate();
|
||||
@@ -232,7 +231,7 @@ public class AmqpMessageHandlerServiceTest {
|
||||
|
||||
@Test
|
||||
@Description("Tests the creation of a target/thing with specified name and attributes by calling the same method that incoming RabbitMQ messages would access.")
|
||||
public void createThingWithNameAndAttributes() {
|
||||
void createThingWithNameAndAttributes() {
|
||||
final String knownThingId = "5";
|
||||
final String knownThingName = "NonDefaultTargetName";
|
||||
|
||||
@@ -255,7 +254,7 @@ public class AmqpMessageHandlerServiceTest {
|
||||
|
||||
@Test
|
||||
@Description("Tests the target attribute update by calling the same method that incoming RabbitMQ messages would access.")
|
||||
public void updateAttributes() {
|
||||
void updateAttributes() {
|
||||
final String knownThingId = "1";
|
||||
final MessageProperties messageProperties = createMessageProperties(MessageType.EVENT);
|
||||
messageProperties.setHeader(MessageHeaderKey.THING_ID, knownThingId);
|
||||
@@ -277,7 +276,7 @@ public class AmqpMessageHandlerServiceTest {
|
||||
|
||||
@Test
|
||||
@Description("Verifies that the update mode is retrieved from the UPDATE_ATTRIBUTES message and passed to the controller management.")
|
||||
public void attributeUpdateModes() {
|
||||
void attributeUpdateModes() {
|
||||
final String knownThingId = "1";
|
||||
final MessageProperties messageProperties = createMessageProperties(MessageType.EVENT);
|
||||
messageProperties.setHeader(MessageHeaderKey.THING_ID, knownThingId);
|
||||
@@ -320,32 +319,30 @@ public class AmqpMessageHandlerServiceTest {
|
||||
|
||||
@Test
|
||||
@Description("Tests the creation of a thing without a 'reply to' header in message.")
|
||||
public void createThingWithoutReplyTo() {
|
||||
void createThingWithoutReplyTo() {
|
||||
final MessageProperties messageProperties = createMessageProperties(MessageType.THING_CREATED, null);
|
||||
messageProperties.setHeader(MessageHeaderKey.THING_ID, "1");
|
||||
final Message message = createMessage("", messageProperties);
|
||||
|
||||
final String type = MessageType.THING_CREATED.name();
|
||||
assertThatExceptionOfType(AmqpRejectAndDontRequeueException.class)
|
||||
.as(FAIL_MESSAGE_AMQP_REJECT_REASON + "since no replyTo header was set")
|
||||
.isThrownBy(() -> amqpMessageHandlerService.onMessage(message, MessageType.THING_CREATED.name(), TENANT,
|
||||
VIRTUAL_HOST));
|
||||
.isThrownBy(() -> amqpMessageHandlerService.onMessage(message, type, TENANT, VIRTUAL_HOST));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Tests the creation of a target/thing without a thingID by calling the same method that incoming RabbitMQ messages would access.")
|
||||
public void createThingWithoutID() {
|
||||
void createThingWithoutID() {
|
||||
final MessageProperties messageProperties = createMessageProperties(MessageType.THING_CREATED);
|
||||
final Message message = createMessage(new byte[0], messageProperties);
|
||||
|
||||
final String type = MessageType.THING_CREATED.name();
|
||||
assertThatExceptionOfType(AmqpRejectAndDontRequeueException.class)
|
||||
.as(FAIL_MESSAGE_AMQP_REJECT_REASON + "since no thingId was set")
|
||||
.isThrownBy(() -> amqpMessageHandlerService.onMessage(message, MessageType.THING_CREATED.name(), TENANT,
|
||||
VIRTUAL_HOST));
|
||||
.isThrownBy(() -> amqpMessageHandlerService.onMessage(message, type, TENANT, VIRTUAL_HOST));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Tests the call of the same method that incoming RabbitMQ messages would access with an unknown message type.")
|
||||
public void unknownMessageType() {
|
||||
void unknownMessageType() {
|
||||
final String type = "bumlux";
|
||||
final MessageProperties messageProperties = createMessageProperties(MessageType.THING_CREATED);
|
||||
messageProperties.setHeader(MessageHeaderKey.THING_ID, "");
|
||||
@@ -358,7 +355,7 @@ public class AmqpMessageHandlerServiceTest {
|
||||
|
||||
@Test
|
||||
@Description("Tests a invalid message without event topic")
|
||||
public void invalidEventTopic() {
|
||||
void invalidEventTopic() {
|
||||
final MessageProperties messageProperties = createMessageProperties(MessageType.EVENT);
|
||||
final Message message = new Message(new byte[0], messageProperties);
|
||||
|
||||
@@ -366,52 +363,51 @@ public class AmqpMessageHandlerServiceTest {
|
||||
.as(FAIL_MESSAGE_AMQP_REJECT_REASON + "due to unknown message type").isThrownBy(
|
||||
() -> amqpMessageHandlerService.onMessage(message, "unknownMessageType", TENANT, VIRTUAL_HOST));
|
||||
|
||||
final String type = MessageType.EVENT.name();
|
||||
messageProperties.setHeader(MessageHeaderKey.TOPIC, "wrongTopic");
|
||||
assertThatExceptionOfType(AmqpRejectAndDontRequeueException.class)
|
||||
.as(FAIL_MESSAGE_AMQP_REJECT_REASON + "due to unknown topic").isThrownBy(() -> amqpMessageHandlerService
|
||||
.onMessage(message, MessageType.EVENT.name(), TENANT, VIRTUAL_HOST));
|
||||
.as(FAIL_MESSAGE_AMQP_REJECT_REASON + "due to unknown topic")
|
||||
.isThrownBy(() -> amqpMessageHandlerService.onMessage(message, type, TENANT, VIRTUAL_HOST));
|
||||
|
||||
messageProperties.setHeader(MessageHeaderKey.TOPIC, EventTopic.CANCEL_DOWNLOAD.name());
|
||||
assertThatExceptionOfType(AmqpRejectAndDontRequeueException.class)
|
||||
.as(FAIL_MESSAGE_AMQP_REJECT_REASON + "because there was no event topic")
|
||||
.isThrownBy(() -> amqpMessageHandlerService.onMessage(message, MessageType.EVENT.name(), TENANT,
|
||||
VIRTUAL_HOST));
|
||||
.isThrownBy(() -> amqpMessageHandlerService.onMessage(message, type, TENANT, VIRTUAL_HOST));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Tests the update of an action of a target without a exist action id")
|
||||
public void updateActionStatusWithoutActionId() {
|
||||
void updateActionStatusWithoutActionId() {
|
||||
when(controllerManagementMock.findActionWithDetails(anyLong())).thenReturn(Optional.empty());
|
||||
final MessageProperties messageProperties = createMessageProperties(MessageType.EVENT);
|
||||
messageProperties.setHeader(MessageHeaderKey.TOPIC, EventTopic.UPDATE_ACTION_STATUS.name());
|
||||
final DmfActionUpdateStatus actionUpdateStatus = new DmfActionUpdateStatus(1L, DmfActionStatus.DOWNLOAD);
|
||||
final Message message = createMessage(actionUpdateStatus, messageProperties);
|
||||
|
||||
final String type = MessageType.EVENT.name();
|
||||
assertThatExceptionOfType(AmqpRejectAndDontRequeueException.class)
|
||||
.as(FAIL_MESSAGE_AMQP_REJECT_REASON + "since no action id was set")
|
||||
.isThrownBy(() -> amqpMessageHandlerService.onMessage(message, MessageType.EVENT.name(), TENANT,
|
||||
VIRTUAL_HOST));
|
||||
.isThrownBy(() -> amqpMessageHandlerService.onMessage(message, type, TENANT, VIRTUAL_HOST));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Tests the update of an action of a target without a exist action id")
|
||||
public void updateActionStatusWithoutExistActionId() {
|
||||
void updateActionStatusWithoutExistActionId() {
|
||||
final MessageProperties messageProperties = createMessageProperties(MessageType.EVENT);
|
||||
messageProperties.setHeader(MessageHeaderKey.TOPIC, EventTopic.UPDATE_ACTION_STATUS.name());
|
||||
when(controllerManagementMock.findActionWithDetails(anyLong())).thenReturn(Optional.empty());
|
||||
|
||||
final DmfActionUpdateStatus actionUpdateStatus = createActionUpdateStatus(DmfActionStatus.DOWNLOAD);
|
||||
final Message message = createMessage(actionUpdateStatus, messageProperties);
|
||||
|
||||
final String type = MessageType.EVENT.name();
|
||||
assertThatExceptionOfType(AmqpRejectAndDontRequeueException.class)
|
||||
.as(FAIL_MESSAGE_AMQP_REJECT_REASON + "since no action id was set")
|
||||
.isThrownBy(() -> amqpMessageHandlerService.onMessage(message, MessageType.EVENT.name(), TENANT,
|
||||
.isThrownBy(() -> amqpMessageHandlerService.onMessage(message, type, TENANT,
|
||||
VIRTUAL_HOST));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Tests that messages which cause quota violations are not re-added to message queue so they would block other communication.")
|
||||
public void quotaExceeded() {
|
||||
void quotaExceeded() {
|
||||
final MessageProperties messageProperties = createMessageProperties(MessageType.EVENT);
|
||||
messageProperties.setHeader(MessageHeaderKey.TOPIC, EventTopic.UPDATE_ACTION_STATUS.name());
|
||||
|
||||
@@ -429,14 +425,14 @@ public class AmqpMessageHandlerServiceTest {
|
||||
when(controllerManagementMock.findActionWithDetails(anyLong())).thenReturn(Optional.of(action));
|
||||
when(controllerManagementMock.addUpdateActionStatus(any())).thenThrow(new AssignmentQuotaExceededException());
|
||||
|
||||
final String type = MessageType.EVENT.name();
|
||||
assertThatExceptionOfType(AmqpRejectAndDontRequeueException.class)
|
||||
.isThrownBy(() -> amqpMessageHandlerService.onMessage(message, MessageType.EVENT.name(), TENANT,
|
||||
VIRTUAL_HOST));
|
||||
.isThrownBy(() -> amqpMessageHandlerService.onMessage(message, type, TENANT, VIRTUAL_HOST));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test next update is provided on finished action")
|
||||
public void lookupNextUpdateActionAfterFinished() throws IllegalAccessException {
|
||||
void lookupNextUpdateActionAfterFinished() throws IllegalAccessException {
|
||||
|
||||
// Mock
|
||||
final Action action = createActionWithTarget(22L);
|
||||
@@ -473,7 +469,7 @@ public class AmqpMessageHandlerServiceTest {
|
||||
|
||||
@Test
|
||||
@Description("Test feedback code is persisted in messages when provided with DmfActionUpdateStatus")
|
||||
public void feedBackCodeIsPersistedInMessages() throws IllegalAccessException {
|
||||
void feedBackCodeIsPersistedInMessages() throws IllegalAccessException {
|
||||
|
||||
// Mock
|
||||
final Action action = createActionWithTarget(22L);
|
||||
@@ -509,7 +505,7 @@ public class AmqpMessageHandlerServiceTest {
|
||||
|
||||
@Test
|
||||
@Description("Tests the deletion of a target/thing, requested by the target itself.")
|
||||
public void deleteThing() {
|
||||
void deleteThing() {
|
||||
// prepare valid message
|
||||
final String knownThingId = "1";
|
||||
final MessageProperties messageProperties = createMessageProperties(MessageType.THING_REMOVED);
|
||||
@@ -525,15 +521,15 @@ public class AmqpMessageHandlerServiceTest {
|
||||
|
||||
@Test
|
||||
@Description("Tests the deletion of a target/thing with missing thingId")
|
||||
public void deleteThingWithoutThingId() {
|
||||
void deleteThingWithoutThingId() {
|
||||
// prepare invalid message
|
||||
final MessageProperties messageProperties = createMessageProperties(MessageType.THING_REMOVED);
|
||||
final Message message = createMessage(new byte[0], messageProperties);
|
||||
|
||||
final String type = MessageType.THING_REMOVED.name();
|
||||
assertThatExceptionOfType(AmqpRejectAndDontRequeueException.class)
|
||||
.as(FAIL_MESSAGE_AMQP_REJECT_REASON + "since no thingId was set")
|
||||
.isThrownBy(() -> amqpMessageHandlerService.onMessage(message, MessageType.THING_REMOVED.name(), TENANT,
|
||||
VIRTUAL_HOST));
|
||||
.isThrownBy(() -> amqpMessageHandlerService.onMessage(message, type, TENANT, VIRTUAL_HOST));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -382,9 +382,9 @@ abstract class AbstractAmqpServiceIntegrationTest extends AbstractAmqpIntegratio
|
||||
|
||||
createConditionFactory().untilAsserted(() -> {
|
||||
try {
|
||||
final Map<String, String> controllerAttributes = SecurityContextSwitch
|
||||
.runAsPrivileged(() -> targetManagement.getControllerAttributes(controllerId));
|
||||
assertThat(controllerAttributes.size()).isEqualTo(attributes.size());
|
||||
final Map<String, String> controllerAttributes = SecurityContextSwitch.runAsPrivileged(
|
||||
() -> targetManagement.getControllerAttributes(controllerId));
|
||||
assertThat(controllerAttributes).hasSameSizeAs(attributes);
|
||||
assertThat(controllerAttributes).containsAllEntriesOf(attributes);
|
||||
} catch (final Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
|
||||
@@ -227,12 +227,12 @@ class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpServiceInt
|
||||
registerAndAssertTargetWithExistingTenant(controllerId);
|
||||
|
||||
final Long actionId1 = assignNewDsToTarget(controllerId, 450);
|
||||
final Entry<Long, EventTopic> action1Install = new SimpleEntry<>(actionId1, EventTopic.DOWNLOAD_AND_INSTALL);
|
||||
final SimpleEntry<Long, EventTopic> action1Install = new SimpleEntry<>(actionId1, EventTopic.DOWNLOAD_AND_INSTALL);
|
||||
waitUntilEventMessagesAreDispatchedToTarget(EventTopic.MULTI_ACTION);
|
||||
assertLatestMultiActionMessage(controllerId, Collections.singletonList(action1Install));
|
||||
|
||||
final Long actionId2 = assignNewDsToTarget(controllerId, 111);
|
||||
final Entry<Long, EventTopic> action2Install = new SimpleEntry<>(actionId2, EventTopic.DOWNLOAD_AND_INSTALL);
|
||||
final SimpleEntry<Long, EventTopic> action2Install = new SimpleEntry<>(actionId2, EventTopic.DOWNLOAD_AND_INSTALL);
|
||||
waitUntilEventMessagesAreDispatchedToTarget(EventTopic.MULTI_ACTION);
|
||||
assertLatestMultiActionMessage(controllerId, Arrays.asList(action1Install, action2Install));
|
||||
}
|
||||
@@ -315,8 +315,8 @@ class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpServiceInt
|
||||
deploymentManagement.cancelAction(actionId1);
|
||||
waitUntilEventMessagesAreDispatchedToTarget(EventTopic.MULTI_ACTION);
|
||||
|
||||
final Entry<Long, EventTopic> action1Cancel = new SimpleEntry<>(actionId1, EventTopic.CANCEL_DOWNLOAD);
|
||||
final Entry<Long, EventTopic> action2Install = new SimpleEntry<>(actionId2, EventTopic.DOWNLOAD_AND_INSTALL);
|
||||
final SimpleEntry<Long, EventTopic> action1Cancel = new SimpleEntry<>(actionId1, EventTopic.CANCEL_DOWNLOAD);
|
||||
final SimpleEntry<Long, EventTopic> action2Install = new SimpleEntry<>(actionId2, EventTopic.DOWNLOAD_AND_INSTALL);
|
||||
|
||||
assertLatestMultiActionMessage(controllerId, Arrays.asList(action1Cancel, action2Install));
|
||||
updateActionViaDmfClient(controllerId, actionId1, DmfActionStatus.CANCELED);
|
||||
@@ -349,7 +349,7 @@ class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpServiceInt
|
||||
|
||||
final long actionId1 = assignNewDsToTarget(controllerId, 66);
|
||||
final long actionId2 = assignNewDsToTarget(controllerId, 767);
|
||||
final Entry<Long, EventTopic> action2Install = new SimpleEntry<>(actionId2, EventTopic.DOWNLOAD_AND_INSTALL);
|
||||
final SimpleEntry<Long, EventTopic> action2Install = new SimpleEntry<>(actionId2, EventTopic.DOWNLOAD_AND_INSTALL);
|
||||
waitUntilEventMessagesAreDispatchedToTarget(EventTopic.MULTI_ACTION, EventTopic.MULTI_ACTION);
|
||||
|
||||
updateActionViaDmfClient(controllerId, actionId1, DmfActionStatus.FINISHED);
|
||||
@@ -385,8 +385,8 @@ class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpServiceInt
|
||||
final Long actionId2 = getFirstAssignedAction(assignDistributionSet(dsId, controllerId, 775)).getId();
|
||||
waitUntilEventMessagesAreDispatchedToTarget(EventTopic.MULTI_ACTION);
|
||||
|
||||
final Entry<Long, EventTopic> action1Install = new SimpleEntry<>(actionId1, EventTopic.DOWNLOAD_AND_INSTALL);
|
||||
final Entry<Long, EventTopic> action2Install = new SimpleEntry<>(actionId2, EventTopic.DOWNLOAD_AND_INSTALL);
|
||||
final SimpleEntry<Long, EventTopic> action1Install = new SimpleEntry<>(actionId1, EventTopic.DOWNLOAD_AND_INSTALL);
|
||||
final SimpleEntry<Long, EventTopic> action2Install = new SimpleEntry<>(actionId2, EventTopic.DOWNLOAD_AND_INSTALL);
|
||||
assertLatestMultiActionMessage(controllerId, Arrays.asList(action1Install, action2Install));
|
||||
}
|
||||
|
||||
@@ -567,9 +567,10 @@ class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpServiceInt
|
||||
|
||||
assertThat(message).isNotNull();
|
||||
final Map<String, Object> headers = message.getMessageProperties().getHeaders();
|
||||
assertThat(headers).containsEntry("thingId", controllerId);
|
||||
assertThat(headers).containsEntry("type", EVENT.toString());
|
||||
assertThat(headers).containsEntry("topic", DOWNLOAD.toString());
|
||||
assertThat(headers)
|
||||
.containsEntry("thingId", controllerId)
|
||||
.containsEntry("type", EVENT.toString())
|
||||
.containsEntry("topic", DOWNLOAD.toString());
|
||||
|
||||
final Optional<Target> target = controllerManagement.getByControllerId(controllerId);
|
||||
assertThat(target).isPresent();
|
||||
@@ -596,11 +597,11 @@ class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpServiceInt
|
||||
final List<String> controllerIds) {
|
||||
assertSoftwareModules(softwareModules, request.getSoftwareModules());
|
||||
|
||||
final List<Object> tokens = controllerIds.stream().map(controllerId -> {
|
||||
final List<String> tokens = controllerIds.stream().map(controllerId -> {
|
||||
final Optional<Target> target = controllerManagement.getByControllerId(controllerId);
|
||||
assertThat(target).isPresent();
|
||||
return target.get().getSecurityToken();
|
||||
}).collect(Collectors.toList());
|
||||
}).toList();
|
||||
|
||||
final List<DmfTarget> requestTargets = request.getTargets();
|
||||
|
||||
@@ -700,7 +701,7 @@ class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpServiceInt
|
||||
private static List<DmfDownloadAndUpdateRequest> getDownloadAndUpdateRequests(final DmfMultiActionRequest request) {
|
||||
return request.getElements().stream()
|
||||
.filter(AmqpMessageDispatcherServiceIntegrationTest::isDownloadAndUpdateRequest)
|
||||
.map(multiAction -> (DmfDownloadAndUpdateRequest) multiAction.getAction()).collect(Collectors.toList());
|
||||
.map(multiAction -> (DmfDownloadAndUpdateRequest) multiAction.getAction()).toList();
|
||||
}
|
||||
|
||||
private static boolean isDownloadAndUpdateRequest(final DmfMultiActionElement multiActionElement) {
|
||||
@@ -767,20 +768,20 @@ class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpServiceInt
|
||||
.fromMessage(multiactionMessage);
|
||||
|
||||
final List<Set<Long>> smIdsOfActionsFound = getDownloadAndUpdateRequests(multiActionRequest).stream()
|
||||
.map(AmqpMessageDispatcherServiceIntegrationTest::getSmIds).collect(Collectors.toList());
|
||||
.map(AmqpMessageDispatcherServiceIntegrationTest::getSmIds).toList();
|
||||
assertThat(smIdsOfActionsFound).containsExactlyInAnyOrderElementsOf(smIdsOfActionsExpected);
|
||||
}
|
||||
|
||||
private void assertLatestMultiActionMessage(final String controllerId,
|
||||
final List<Entry<Long, EventTopic>> actionsExpected) {
|
||||
final List<Entry<Long, EventTopic>> actionsFromMessage = getLatestMultiActionMessageActions(controllerId);
|
||||
final List<SimpleEntry<Long, EventTopic>> actionsExpected) {
|
||||
final List<SimpleEntry<Long, EventTopic>> actionsFromMessage = getLatestMultiActionMessageActions(controllerId);
|
||||
assertThat(actionsFromMessage).containsExactlyInAnyOrderElementsOf(actionsExpected);
|
||||
}
|
||||
|
||||
private List<Entry<Long, EventTopic>> getLatestMultiActionMessageActions(final String expectedControllerId) {
|
||||
private List<SimpleEntry<Long, EventTopic>> getLatestMultiActionMessageActions(final String expectedControllerId) {
|
||||
final List<DmfMultiActionElement> multiActionRequest = getLatestMultiActionMessages(expectedControllerId);
|
||||
return multiActionRequest.stream()
|
||||
.map(request -> new SimpleEntry<>(request.getAction().getActionId(), request.getTopic()))
|
||||
.collect(Collectors.toList());
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
@@ -32,7 +31,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.RandomStringUtils;
|
||||
import org.eclipse.hawkbit.amqp.AmqpMessageHandlerService;
|
||||
import org.eclipse.hawkbit.amqp.AmqpProperties;
|
||||
import org.eclipse.hawkbit.dmf.amqp.api.EventTopic;
|
||||
@@ -199,7 +197,7 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
|
||||
@Description("Tests register invalid target with too long controller id")
|
||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class) })
|
||||
void registerInvalidTargetWithTooLongControllerId() {
|
||||
createAndSendThingCreated(RandomStringUtils.randomAlphabetic(Target.CONTROLLER_ID_MAX_SIZE + 1));
|
||||
createAndSendThingCreated(randomString(Target.CONTROLLER_ID_MAX_SIZE + 1));
|
||||
assertAllTargetsCount(0);
|
||||
verifyOneDeadLetterMessage();
|
||||
}
|
||||
@@ -1171,13 +1169,13 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
|
||||
.filter(Objects::nonNull)
|
||||
.filter(message -> message
|
||||
.startsWith(RepositoryConstants.SERVER_MESSAGE_PREFIX + "DMF message"))
|
||||
.collect(Collectors.toList());
|
||||
.toList();
|
||||
|
||||
assertThat(messagesFromServer).hasSize(messages)
|
||||
.allMatch(message -> message.endsWith(CORRELATION_ID));
|
||||
|
||||
final List<Status> status = actionStatusList.stream().map(ActionStatus::getStatus)
|
||||
.collect(Collectors.toList());
|
||||
.toList();
|
||||
assertThat(status).containsOnly(expectedActionStates);
|
||||
|
||||
return null;
|
||||
@@ -1204,7 +1202,7 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
|
||||
assertThat(actionStatusList).hasSize(statusListCount);
|
||||
|
||||
final List<Status> status = actionStatusList.stream().map(ActionStatus::getStatus)
|
||||
.collect(Collectors.toList());
|
||||
.toList();
|
||||
assertThat(status).containsOnly(expectedActionStates);
|
||||
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user