GetFirmwareFileResponseMessageProcessor extends OsgpResponseMessageProcessor { @Override public void processMessage(final ObjectMessage message) throws JMSException { LOGGER.debug("Processing {} response message", this.messageType.name()); MessageMetadata messageMetadata = null; DlmsConnectionHolder conn = null; DlmsDevice device = null; try { messageMetadata = new MessageMetadata.Builder(MessageMetadata.fromMessage(message)) .withMessageType(DeviceFunctionDto.UPDATE_FIRMWARE.name()).build(); device = this.domainHelperService.findDlmsDevice(messageMetadata); LOGGER.info("{} called for device: {} for organisation: {}", message.getJMSType(), messageMetadata.getDeviceIdentification(), messageMetadata.getOrganisationIdentification()); Serializable response; conn = this.createConnectionForDevice(device, messageMetadata); response = this.handleMessage(conn, device, message.getObject()); this.sendResponseMessage(messageMetadata, ResponseMessageResultType.OK, null, this.responseMessageSender, response); } catch (final JMSException exception) { this.logJmsException(LOGGER, exception, messageMetadata); } catch (final Exception exception) { LOGGER.error("Unexpected exception during {}", this.messageType.name(), exception); this.sendResponseMessage(messageMetadata, ResponseMessageResultType.NOT_OK, exception, this.responseMessageSender, message.getObject()); } finally { this.doConnectionPostProcessing(device, conn); } } protected  GetFirmwareFileResponseMessageProcessor(); @Override void processMessage(final ObjectMessage message);  }
@Test public void processMessageShouldSendOkResponseMessageContainingFirmwareVersions() throws OsgpException, JMSException { 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(), new LinkedList<>()); final ArgumentCaptor<ResponseMessage> responseMessageArgumentCaptor = ArgumentCaptor .forClass(ResponseMessage.class); when(this.domainHelperService.findDlmsDevice(any(MessageMetadata.class))).thenReturn(this.dlmsDeviceMock); when(this.dlmsConnectionFactory.getConnection(this.dlmsDeviceMock, null)) .thenReturn(this.dlmsConnectionHolderMock); when(this.dlmsConnectionHolderMock.getDlmsMessageListener()).thenReturn(this.dlmsMessageListenerMock); when(this.dlmsDeviceMock.isInDebugMode()).thenReturn(false); when(this.firmwareService.updateFirmware(this.dlmsConnectionHolderMock, this.dlmsDeviceMock, firmwareFileDto)) .thenReturn(updateFirmwareResponseDto); this.getFirmwareFileResponseMessageProcessor.processMessage(message); verify(this.responseMessageSender, times(1)).send(responseMessageArgumentCaptor.capture()); assertThat(responseMessageArgumentCaptor.getValue().getDataObject(), is(updateFirmwareResponseDto)); assertThat(responseMessageArgumentCaptor.getValue().getResult(), is(ResponseMessageResultType.OK)); }