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);
}
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));
}
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);
}
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());
}
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();
}
Aggregations