Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package org.gridsuite.monitor.server.services;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.gridsuite.monitor.commons.MessageType;
import org.gridsuite.monitor.commons.ProcessExecutionStatusUpdate;
Expand Down Expand Up @@ -71,7 +72,7 @@ private void handleStepStatusUpdate(UUID executionId, Message<String> message) {
}

private void handleStepsStatusesUpdate(UUID executionId, Message<String> message) {
List<ProcessExecutionStep> processExecutionSteps = parsePayload(message.getPayload(), List.class);
List<ProcessExecutionStep> processExecutionSteps = parsePayload(message.getPayload(), new TypeReference<List<ProcessExecutionStep>>() { });
monitorService.updateStepsStatuses(executionId, processExecutionSteps);
}

Expand All @@ -82,4 +83,12 @@ private <T> T parsePayload(String payload, Class<T> clazz) {
throw new UncheckedIOException("Failed to parse payload as " + clazz.getSimpleName(), e);
}
}

private <T> T parsePayload(String payload, TypeReference<T> typeReference) {
try {
return objectMapper.readValue(payload, typeReference);
} catch (JsonProcessingException e) {
throw new UncheckedIOException("Failed to parse payload as " + typeReference.getType().getTypeName(), e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,24 @@ void consumeMonitorUpdateThrowsOnInvalidJson() {
verify(monitorService, never()).updateStepStatus(any(), any());
}

@Test
void consumeMonitorUpdateStepsStatusesThrowsOnInvalidJson() {
UUID executionId = UUID.randomUUID();
String invalidPayload = "{invalid json}";
Map<String, Object> headers = new HashMap<>();
headers.put(ConsumerService.HEADER_MESSAGE_TYPE, MessageType.STEPS_STATUSES_UPDATE.toString());
headers.put(ConsumerService.HEADER_EXECUTION_ID, executionId.toString());
Message<String> message = new GenericMessage<>(invalidPayload, headers);
Consumer<Message<String>> consumer = consumerService.consumeMonitorUpdate();

assertThatThrownBy(() -> consumer.accept(message))
.isInstanceOf(UncheckedIOException.class)
.hasMessageContaining("Failed to parse payload as java.util.List<org.gridsuite.monitor.commons.ProcessExecutionStep>");

verify(monitorService, never()).updateExecutionStatus(any(), any(), any(), any(), any());
verify(monitorService, never()).updateStepsStatuses(any(), any());
}

@Test
void consumeProcessExecutionStepUpdateMessage() throws JsonProcessingException {
UUID executionId = UUID.randomUUID();
Expand Down