Search in sources :

Example 11 with ObjectMessageBuilder

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));
}
Also used : UpdateFirmwareRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) ObjectMessage(javax.jms.ObjectMessage) DlmsConnectionManager(org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager) ObjectMessageBuilder(org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder) Test(org.junit.jupiter.api.Test)

Example 12 with ObjectMessageBuilder

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);
}
Also used : GetHealthStatusRequestDto(org.opensmartgridplatform.dto.da.GetHealthStatusRequestDto) ObjectMessage(javax.jms.ObjectMessage) MessageProcessor(org.opensmartgridplatform.shared.infra.jms.MessageProcessor) GetHealthStatusRequestMessageProcessor(org.opensmartgridplatform.adapter.protocol.iec60870.infra.messaging.processors.GetHealthStatusRequestMessageProcessor) ObjectMessageBuilder(org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder) Test(org.junit.jupiter.api.Test)

Example 13 with ObjectMessageBuilder

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()));
}
Also used : GetHealthStatusRequestDto(org.opensmartgridplatform.dto.da.GetHealthStatusRequestDto) ObjectMessage(javax.jms.ObjectMessage) ErrorResponseMessageMatcher(org.opensmartgridplatform.adapter.protocol.iec60870.testutils.matchers.ErrorResponseMessageMatcher) ObjectMessageBuilder(org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder) Test(org.junit.jupiter.api.Test)

Example 14 with ObjectMessageBuilder

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));
}
Also used : UpdateFirmwareRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) ObjectMessage(javax.jms.ObjectMessage) RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage) ObjectMessageBuilder(org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder) Test(org.junit.jupiter.api.Test)

Example 15 with ObjectMessageBuilder

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));
}
Also used : UpdateFirmwareRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) ObjectMessage(javax.jms.ObjectMessage) RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage) ObjectMessageBuilder(org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

ObjectMessageBuilder (org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder)17 ObjectMessage (javax.jms.ObjectMessage)15 Test (org.junit.jupiter.api.Test)12 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)9 UpdateFirmwareRequestDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto)6 RequestMessage (org.opensmartgridplatform.shared.infra.jms.RequestMessage)6 FirmwareFileDto (org.opensmartgridplatform.dto.valueobjects.FirmwareFileDto)4 ProtocolResponseMessage (org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage)4 ResponseMessage (org.opensmartgridplatform.shared.infra.jms.ResponseMessage)4 When (io.cucumber.java.en.When)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 Date (java.util.Date)2 DlmsDeviceBuilder (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDeviceBuilder)2 DlmsConnectionManager (org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager)2 DomainInfo (org.opensmartgridplatform.domain.core.entities.DomainInfo)2 ConnectRequestDto (org.opensmartgridplatform.dto.da.ConnectRequestDto)2 GetHealthStatusRequestDto (org.opensmartgridplatform.dto.da.GetHealthStatusRequestDto)2 Collections (java.util.Collections)1 JMSException (javax.jms.JMSException)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1