GetFirmwareFileResponseMessageProcessor extends OsgpResponseMessageProcessor { @SuppressWarnings("squid:S1193") @Override public void processMessage(final ObjectMessage message) throws JMSException { LOGGER.debug("Processing {} response message", this.messageType.name()); MessageMetadata messageMetadata = null; DlmsConnectionManager conn = null; DlmsDevice device = null; try { messageMetadata = new MessageMetadata.Builder(MessageMetadata.fromMessage(message)).withMessageType( MessageType.UPDATE_FIRMWARE.name()).build(); device = this.domainHelperService.findDlmsDevice(messageMetadata); LOGGER.info("{} called for device: {} for organisation: {}", message.getJMSType(), messageMetadata.getDeviceIdentification(), messageMetadata.getOrganisationIdentification()); final 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) { if (!(exception instanceof SilentException)) { 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(); @SuppressWarnings("squid:S1193") // SilentException cannot be caught since it does not extend Exception. @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.dlmsDevice); when(this.dlmsConnectionManagerMock.getDlmsMessageListener()).thenReturn(this.dlmsMessageListenerMock); when(this.connectionHelper .createConnectionForDevice(same(this.dlmsDevice), nullable(DlmsMessageListener.class))) .thenReturn(this.dlmsConnectionManagerMock); when(this.firmwareService.updateFirmware(this.dlmsConnectionManagerMock, this.dlmsDevice, firmwareFileDto)) .thenReturn(updateFirmwareResponseDto); this.getFirmwareFileResponseMessageProcessor.processMessage(message); verify(this.responseMessageSender, times(1)).send(responseMessageArgumentCaptor.capture()); assertThat(responseMessageArgumentCaptor.getValue().getDataObject()).isSameAs(updateFirmwareResponseDto); assertThat(responseMessageArgumentCaptor.getValue().getResult()).isSameAs(ResponseMessageResultType.OK); }