UpdateFirmwareRequestMessageProcessor extends DeviceRequestMessageProcessor { @Override public void processMessage(final ObjectMessage message) { LOGGER.debug("Processing {} request message", this.messageType); MessageMetadata messageMetadata = null; try { messageMetadata = MessageMetadata.fromMessage(message); LOGGER.info("{} called for device: {} for organisation: {}", messageMetadata.getMessageType(), messageMetadata.getDeviceIdentification(), messageMetadata.getOrganisationIdentification()); final String firmwareIdentification = (String) message.getObject(); if (this.firmwareService.isFirmwareFileAvailable(firmwareIdentification)) { LOGGER.info("[{}] - Firmware file [{}] available. Updating firmware on device [{}]", messageMetadata.getCorrelationUid(), firmwareIdentification, messageMetadata.getDeviceIdentification()); this.processUpdateFirmwareRequest(messageMetadata, firmwareIdentification); } else { LOGGER.info("[{}] - Firmware file [{}] not available. Sending GetFirmwareFile request to core.", messageMetadata.getCorrelationUid(), firmwareIdentification); this.sendGetFirmwareFileRequest(messageMetadata, firmwareIdentification); } } catch (final JMSException exception) { this.logJmsException(LOGGER, exception, messageMetadata); } } protected  UpdateFirmwareRequestMessageProcessor(); @Override void processMessage(final ObjectMessage message);  }
@Test public void processMessageShouldSendFirmwareFileRequestWhenFirmwareFileNotAvailable() throws JMSException { final String firmwareIdentification = "unavailable"; final ObjectMessage message = new ObjectMessageBuilder().withObject(firmwareIdentification).build(); when(this.firmwareService.isFirmwareFileAvailable(firmwareIdentification)).thenReturn(false); this.processor.processMessage(message); verify(this.osgpRequestMessageSender, times(1)) .send(any(RequestMessage.class), any(String.class), any(MessageMetadata.class)); }
@Test public void processMessageShouldNotSendFirmwareFileRequestWhenFirmwareFileAvailable() throws JMSException { final String firmwareIdentification = "unavailable"; final ObjectMessage message = new ObjectMessageBuilder().withObject(firmwareIdentification).build(); when(this.firmwareService.isFirmwareFileAvailable(firmwareIdentification)).thenReturn(true); this.processor.processMessage(message); verify(this.osgpRequestMessageSender, never()) .send(any(RequestMessage.class), any(String.class), any(MessageMetadata.class)); }
@Test public void processMessageShouldUpdateFirmwareWhenFirmwareFileAvailable() throws JMSException, OsgpException { final String firmwareIdentification = "available"; final ObjectMessage message = new ObjectMessageBuilder().withObject(firmwareIdentification).build(); when(this.firmwareService.isFirmwareFileAvailable(firmwareIdentification)).thenReturn(true); this.processor.processMessage(message); verify(this.configurationService, times(1)).updateFirmware(null, this.device, firmwareIdentification); }
@Test public void processMessageShouldNotUpdateFirmwareWhenFirmwareFileNotAvailable() throws JMSException, OsgpException { final String firmwareIdentification = "unavailable"; final ObjectMessage message = new ObjectMessageBuilder().withObject(firmwareIdentification).build(); when(this.firmwareService.isFirmwareFileAvailable(firmwareIdentification)).thenReturn(false); this.processor.processMessage(message); verify(this.firmwareService, times(0)) .updateFirmware(this.dlmsConnectionManagerMock, this.device, firmwareIdentification); }