Search in sources :

Example 6 with ObjectMessageBuilder

use of org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder in project open-smart-grid-platform by OSGP.

the class GetFirmwareFileMessageProcessorTest method processMessageShouldSendFirmwareFile.

@Test
public void processMessageShouldSendFirmwareFile() throws JMSException {
    // arrange
    final String correlationUid = "corr-uid-1";
    final String organisationIdentification = "test-org";
    final String deviceIdentification = "dvc-1";
    final String firmwareFileIdentification = "fw";
    final byte[] firmwareFileBytes = firmwareFileIdentification.getBytes();
    final UpdateFirmwareRequestDto updateFirmwareRequestDto = new UpdateFirmwareRequestDto(firmwareFileIdentification, deviceIdentification);
    final RequestMessage requestMessage = new RequestMessage(correlationUid, organisationIdentification, deviceIdentification, updateFirmwareRequestDto);
    final ObjectMessage message = new ObjectMessageBuilder().withCorrelationUid(correlationUid).withMessageType(DeviceFunction.GET_FIRMWARE_FILE.name()).withDeviceIdentification(deviceIdentification).withObject(requestMessage).build();
    when(this.deviceMock.getDeviceIdentification()).thenReturn(deviceIdentification);
    when(this.deviceRepository.findByDeviceIdentification(deviceIdentification)).thenReturn(this.deviceMock);
    when(this.firmwareFileMock.getFilename()).thenReturn(firmwareFileIdentification);
    when(this.firmwareFileMock.getFile()).thenReturn(firmwareFileBytes);
    when(this.firmwareFileRepository.findByIdentificationOnly(firmwareFileIdentification)).thenReturn(this.firmwareFileMock);
    final byte[] expectedFile = firmwareFileBytes;
    final String expectedMessageType = DeviceFunction.GET_FIRMWARE_FILE.name();
    final ArgumentCaptor<ProtocolResponseMessage> responseMessageArgumentCaptor = ArgumentCaptor.forClass(ProtocolResponseMessage.class);
    final ArgumentCaptor<String> messageTypeCaptor = ArgumentCaptor.forClass(String.class);
    // act
    this.getFirmwareFileMessageProcessor.processMessage(message);
    // assert
    verify(this.protocolResponseMessageSender, times(1)).send(responseMessageArgumentCaptor.capture(), messageTypeCaptor.capture(), nullable(ProtocolInfo.class), any(MessageMetadata.class));
    final FirmwareFileDto actualFirmwareFileDto = (FirmwareFileDto) responseMessageArgumentCaptor.getValue().getDataObject();
    final String actualMessageType = messageTypeCaptor.getValue();
    assertThat(actualFirmwareFileDto.getFirmwareFile()).isEqualTo(expectedFile);
    assertThat(actualFirmwareFileDto.getDeviceIdentification()).isEqualTo(deviceIdentification);
    assertThat(actualFirmwareFileDto.getFirmwareIdentification()).isEqualTo(firmwareFileIdentification);
    assertThat(actualMessageType).isEqualTo(expectedMessageType);
}
Also used : UpdateFirmwareRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto) FirmwareFileDto(org.opensmartgridplatform.dto.valueobjects.FirmwareFileDto) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) ProtocolResponseMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage) ObjectMessage(javax.jms.ObjectMessage) RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage) ProtocolInfo(org.opensmartgridplatform.domain.core.entities.ProtocolInfo) ObjectMessageBuilder(org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder) Test(org.junit.jupiter.api.Test)

Example 7 with ObjectMessageBuilder

use of org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder in project open-smart-grid-platform by OSGP.

the class DeviceRequestMessageListenerIT method testProcessRequestMessages.

@Test
void testProcessRequestMessages() throws JMSException, OsgpException {
    // SETUP
    final DlmsDevice dlmsDevice = new DlmsDevice();
    dlmsDevice.setDeviceIdentification("1");
    dlmsDevice.setIpAddress("127.0.0.1");
    dlmsDevice.setHls5Active(true);
    when(this.domainHelperService.findDlmsDevice(any(MessageMetadata.class))).thenReturn(dlmsDevice);
    doNothing().when(this.protocolDlmsOutboundOsgpCoreResponsesMessageSender).send(any(ResponseMessage.class));
    // EXECUTE
    LOGGER.info("Starting Test");
    for (int i = 0; i < 200; i++) {
        LOGGER.info("Send message number {} ", i);
        final ObjectMessage message = new ObjectMessageBuilder().withDeviceIdentification("osgp").withMessageType(MessageType.GET_PROFILE_GENERIC_DATA.toString()).withObject(new GetPowerQualityProfileRequestDataDto("PUBLIC", new Date(), new Date(), null)).build();
        this.listener.onMessage(message);
    }
    verify(this.protocolDlmsOutboundOsgpCoreResponsesMessageSender, times(200)).send(any(ResponseMessage.class));
}
Also used : MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) ObjectMessage(javax.jms.ObjectMessage) GetPowerQualityProfileRequestDataDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.GetPowerQualityProfileRequestDataDto) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) Date(java.util.Date) ObjectMessageBuilder(org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder) Test(org.junit.jupiter.api.Test)

Example 8 with ObjectMessageBuilder

use of org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder in project open-smart-grid-platform by OSGP.

the class GetFirmwareFileResponseMessageProcessorTest method processMessageShouldSendOkResponseMessageContainingFirmwareVersions.

@Test
void processMessageShouldSendOkResponseMessageContainingFirmwareVersions() throws OsgpException, JMSException {
    // arrange
    final FirmwareFileDto firmwareFileDto = this.setupFirmwareFileDto();
    final ResponseMessage responseMessage = this.setupResponseMessage(firmwareFileDto);
    final ObjectMessage message = new ObjectMessageBuilder().withMessageType(MessageType.GET_FIRMWARE_FILE.name()).withObject(responseMessage).build();
    final UpdateFirmwareResponseDto updateFirmwareResponseDto = new UpdateFirmwareResponseDto(firmwareFileDto.getFirmwareIdentification());
    final ArgumentCaptor<ResponseMessage> responseMessageArgumentCaptor = ArgumentCaptor.forClass(ResponseMessage.class);
    final MessageMetadata messageMetadata = new MessageMetadata.Builder(MessageMetadata.fromMessage(message)).withMessageType(MessageType.UPDATE_FIRMWARE.name()).build();
    when(this.domainHelperService.findDlmsDevice(any(MessageMetadata.class))).thenReturn(this.dlmsDevice);
    when(this.dlmsConnectionManagerMock.getDlmsMessageListener()).thenReturn(this.dlmsMessageListenerMock);
    when(this.firmwareService.updateFirmware(same(this.dlmsConnectionManagerMock), same(this.dlmsDevice), same(firmwareFileDto), any(MessageMetadata.class))).thenReturn(updateFirmwareResponseDto);
    // act
    this.getFirmwareFileResponseMessageProcessor.processMessageTasks(message.getObject(), messageMetadata, this.dlmsConnectionManagerMock);
    // assert
    verify(this.responseMessageSender, times(1)).send(responseMessageArgumentCaptor.capture());
    assertThat(responseMessageArgumentCaptor.getValue().getDataObject()).isSameAs(updateFirmwareResponseDto);
    assertThat(responseMessageArgumentCaptor.getValue().getResult()).isSameAs(ResponseMessageResultType.OK);
}
Also used : FirmwareFileDto(org.opensmartgridplatform.dto.valueobjects.FirmwareFileDto) UpdateFirmwareResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareResponseDto) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) ObjectMessage(javax.jms.ObjectMessage) DlmsDeviceBuilder(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDeviceBuilder) ObjectMessageBuilder(org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ProtocolResponseMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage) ObjectMessageBuilder(org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder) Test(org.junit.jupiter.api.Test)

Example 9 with ObjectMessageBuilder

use of org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder in project open-smart-grid-platform by OSGP.

the class GetFirmwareFileResponseMessageProcessorTest method processMessageShouldCallConnectionHelperCreateAndHandleConnection.

@Test
void processMessageShouldCallConnectionHelperCreateAndHandleConnection() throws JMSException, OsgpException {
    final FirmwareFileDto firmwareFileDto = this.setupFirmwareFileDto();
    final ResponseMessage responseMessage = this.setupResponseMessage(firmwareFileDto);
    final ObjectMessage message = new ObjectMessageBuilder().withMessageType(MessageType.GET_FIRMWARE_FILE.name()).withObject(responseMessage).build();
    when(this.domainHelperService.findDlmsDevice(any(MessageMetadata.class))).thenReturn(this.dlmsDevice);
    this.getFirmwareFileResponseMessageProcessor.processMessage(message);
    verify(this.connectionHelper).createAndHandleConnectionForDevice(any(MessageMetadata.class), eq(this.dlmsDevice), isNull(), isNull(), any());
}
Also used : FirmwareFileDto(org.opensmartgridplatform.dto.valueobjects.FirmwareFileDto) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) ObjectMessage(javax.jms.ObjectMessage) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ProtocolResponseMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage) ObjectMessageBuilder(org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder) Test(org.junit.jupiter.api.Test)

Example 10 with ObjectMessageBuilder

use of org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder in project open-smart-grid-platform by OSGP.

the class GetFirmwareFileResponseMessageProcessorTest method processMessageShouldSendNotOkResponseMessageContainingOriginalFirmwareUpdateRequest.

@Test
void processMessageShouldSendNotOkResponseMessageContainingOriginalFirmwareUpdateRequest() throws OsgpException, JMSException {
    // arrange
    final FirmwareFileDto firmwareFileDto = this.setupFirmwareFileDto();
    final ResponseMessage responseMessage = this.setupResponseMessage(firmwareFileDto);
    final ObjectMessage message = new ObjectMessageBuilder().withMessageType(MessageType.GET_FIRMWARE_FILE.name()).withObject(responseMessage).build();
    final MessageMetadata messageMetadata = new MessageMetadata.Builder(MessageMetadata.fromMessage(message)).withMessageType(MessageType.UPDATE_FIRMWARE.name()).build();
    final ArgumentCaptor<ResponseMessage> responseMessageArgumentCaptor = ArgumentCaptor.forClass(ResponseMessage.class);
    when(this.domainHelperService.findDlmsDevice(any(MessageMetadata.class))).thenReturn(this.dlmsDevice);
    when(this.dlmsConnectionManagerMock.getDlmsMessageListener()).thenReturn(this.dlmsMessageListenerMock);
    when(this.firmwareService.updateFirmware(same(this.dlmsConnectionManagerMock), same(this.dlmsDevice), same(firmwareFileDto), any(MessageMetadata.class))).thenThrow(new ProtocolAdapterException("Firmware file fw is not available."));
    // act
    this.getFirmwareFileResponseMessageProcessor.processMessageTasks(message.getObject(), messageMetadata, this.dlmsConnectionManagerMock);
    // assert
    verify(this.responseMessageSender, times(1)).send(responseMessageArgumentCaptor.capture());
    final ResponseMessage capturedValue = responseMessageArgumentCaptor.getValue();
    assertThat(((UpdateFirmwareRequestDto) capturedValue.getDataObject()).getFirmwareIdentification()).isSameAs(firmwareFileDto.getFirmwareIdentification());
    assertThat(capturedValue.getResult()).isSameAs(ResponseMessageResultType.NOT_OK);
    assertThat(capturedValue.bypassRetry()).isFalse();
}
Also used : FirmwareFileDto(org.opensmartgridplatform.dto.valueobjects.FirmwareFileDto) UpdateFirmwareRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) ObjectMessage(javax.jms.ObjectMessage) DlmsDeviceBuilder(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDeviceBuilder) ObjectMessageBuilder(org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ProtocolResponseMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) 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