use of org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder in project open-smart-grid-platform by OSGP.
the class UpdateFirmwareRequestMessageProcessorTest method processMessageTaskShouldNotUpdateFirmwareWhenFirmwareFileNotAvailable.
@Test
void processMessageTaskShouldNotUpdateFirmwareWhenFirmwareFileNotAvailable() throws JMSException, OsgpException {
// Arrange
final String firmwareIdentification = "unavailable";
final String deviceIdentification = "unavailableEither";
final UpdateFirmwareRequestDto updateFirmwareRequestDto = new UpdateFirmwareRequestDto(firmwareIdentification, deviceIdentification);
final ObjectMessage message = new ObjectMessageBuilder().withObject(updateFirmwareRequestDto).withCorrelationUid("123456").build();
final MessageMetadata messageMetadata = MessageMetadata.fromMessage(message);
when(this.firmwareService.isFirmwareFileAvailable(firmwareIdentification)).thenReturn(false);
// Act
this.processor.processMessageTasks(message.getObject(), messageMetadata, this.dlmsConnectionManagerMock, this.device);
// Assert
verify(this.firmwareService, times(0)).updateFirmware(nullable(DlmsConnectionManager.class), same(this.device), same(updateFirmwareRequestDto), any(MessageMetadata.class));
}
use of org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder in project open-smart-grid-platform by OSGP.
the class DeviceRequestMessageListenerTest method shouldProcessMessageWhenMessageTypeIsSupported.
@Test
void shouldProcessMessageWhenMessageTypeIsSupported() throws JMSException {
// Arrange
final String correlationUid = DEFAULT_CORRELATION_UID;
final ObjectMessage message = new ObjectMessageBuilder().withCorrelationUid(correlationUid).withDeviceIdentification(DEFAULT_DEVICE_IDENTIFICATION).withMessageType(DEFAULT_MESSAGE_TYPE).withObject(new GetHealthStatusRequestDto()).build();
final MessageProcessor messageProcessor = mock(GetHealthStatusRequestMessageProcessor.class);
when(this.iec60870RequestMessageProcessorMap.getMessageProcessor(message)).thenReturn(messageProcessor);
// Act
this.deviceRequestMessageListener.onMessage(message);
// Assert
verify(this.pendingRequestsQueue).enqueue(DEFAULT_DEVICE_IDENTIFICATION, correlationUid);
verify(messageProcessor).processMessage(message);
}
use of org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder in project open-smart-grid-platform by OSGP.
the class DeviceRequestMessageListenerTest method shouldSendErrorMessageWhenMessageTypeIsNotSupported.
@Test
void shouldSendErrorMessageWhenMessageTypeIsNotSupported() throws JMSException {
// Arrange
final String correlationUid = DEFAULT_CORRELATION_UID;
final ObjectMessage message = new ObjectMessageBuilder().withCorrelationUid(correlationUid).withDeviceIdentification(DEFAULT_DEVICE_IDENTIFICATION).withMessageType(DEFAULT_MESSAGE_TYPE).withObject(new GetHealthStatusRequestDto()).build();
when(this.iec60870RequestMessageProcessorMap.getMessageProcessor(message)).thenThrow(JMSException.class);
// Act
this.deviceRequestMessageListener.onMessage(message);
// Assert
verify(this.pendingRequestsQueue).enqueue(DEFAULT_DEVICE_IDENTIFICATION, correlationUid);
verify(this.pendingRequestsQueue).remove(DEFAULT_DEVICE_IDENTIFICATION, correlationUid);
verify(this.deviceResponseMessageSender).send(argThat(new ErrorResponseMessageMatcher()));
}
use of org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder in project open-smart-grid-platform by OSGP.
the class UpdateFirmwareRequestMessageProcessorTest method processMessageTaskShouldSendFirmwareFileRequestWhenFirmwareFileNotAvailable.
@Test
void processMessageTaskShouldSendFirmwareFileRequestWhenFirmwareFileNotAvailable() throws JMSException, OsgpException {
// Arrange
final String firmwareIdentification = "unavailable";
final String deviceIdentification = "unavailableEither";
final UpdateFirmwareRequestDto updateFirmwareRequestDto = new UpdateFirmwareRequestDto(firmwareIdentification, deviceIdentification);
final ObjectMessage message = new ObjectMessageBuilder().withObject(updateFirmwareRequestDto).withCorrelationUid("123456").build();
final MessageMetadata messageMetadata = MessageMetadata.fromMessage(message);
when(this.firmwareService.isFirmwareFileAvailable(firmwareIdentification)).thenReturn(false);
// Act
this.processor.processMessageTasks(message.getObject(), messageMetadata, this.dlmsConnectionManagerMock, this.device);
// Assert
verify(this.osgpRequestMessageSender, times(1)).send(any(RequestMessage.class), any(String.class), any(MessageMetadata.class));
}
use of org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder in project open-smart-grid-platform by OSGP.
the class UpdateFirmwareRequestMessageProcessorTest method processMessageTaskShouldNotSendFirmwareFileRequestWhenFirmwareFileAvailable.
@Test
void processMessageTaskShouldNotSendFirmwareFileRequestWhenFirmwareFileAvailable() throws JMSException, OsgpException {
// Arrange
final String firmwareIdentification = "unavailable";
final String deviceIdentification = "unavailableEither";
final UpdateFirmwareRequestDto updateFirmwareRequestDto = new UpdateFirmwareRequestDto(firmwareIdentification, deviceIdentification);
final ObjectMessage message = new ObjectMessageBuilder().withObject(updateFirmwareRequestDto).withCorrelationUid("123456").build();
final MessageMetadata messageMetadata = MessageMetadata.fromMessage(message);
when(this.firmwareService.isFirmwareFileAvailable(firmwareIdentification)).thenReturn(true);
// Act
this.processor.processMessageTasks(message.getObject(), messageMetadata, this.dlmsConnectionManagerMock, this.device);
// Assert
verify(this.osgpRequestMessageSender, never()).send(any(RequestMessage.class), any(String.class), any(MessageMetadata.class));
}
Aggregations