GetFirmwareFileMessageProcessor extends AbstractProtocolRequestMessageProcessor { @Override public void processMessage(final ObjectMessage message) throws JMSException { MessageMetadata metadata = null; Device device = null; String firmwareFileIdentification = StringUtils.EMPTY; try { metadata = MessageMetadata.fromMessage(message); LOGGER.info( "[{}] - Received message of messageType: {}, organisationIdentification: {}, deviceIdentification: {}", metadata.getCorrelationUid(), metadata.getMessageType(), metadata.getOrganisationIdentification(), metadata.getDeviceIdentification()); device = this.deviceRepository.findByDeviceIdentification(metadata.getDeviceIdentification()); final RequestMessage requestMessage = (RequestMessage) message.getObject(); firmwareFileIdentification = (String) requestMessage.getRequest(); final FirmwareFile firmwareFile = this.firmwareFileRepository .findByIdentification(firmwareFileIdentification); final FirmwareFileDto firmwareFileDto = new FirmwareFileDto(firmwareFile.getIdentification(), firmwareFile.getFile()); this.sendSuccesResponse(metadata, device.getProtocolInfo(), firmwareFileDto); } catch (final Exception e) { LOGGER.error("Exception while retrieving firmware file: {}", firmwareFileIdentification); final OsgpException osgpException = new OsgpException(ComponentType.OSGP_CORE, "Exception while retrieving firmware file.", e); this.sendFailureResponse(metadata, device.getProtocolInfo(), osgpException); } } protected  GetFirmwareFileMessageProcessor(); @Override void processMessage(final ObjectMessage message);  }
@Test public void processMessageShouldSendFirmwareFile() throws JMSException { 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 RequestMessage requestMessage = new RequestMessage(correlationUid, organisationIdentification, deviceIdentification, firmwareFileIdentification); 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.findByIdentification(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); this.getFirmwareFileMessageProcessor.processMessage(message); verify(this.protocolResponseMessageSender, times(1)).send(responseMessageArgumentCaptor.capture(), messageTypeCaptor.capture(), nullable(ProtocolInfo.class), any(MessageMetadata.class)); final byte[] actualFile = ((FirmwareFileDto) responseMessageArgumentCaptor.getValue().getDataObject()) .getFirmwareFile(); final String actualMessageType = messageTypeCaptor.getValue(); assertThat(actualFile).isEqualTo(expectedFile); assertThat(actualMessageType).isEqualTo(expectedMessageType); }