use of org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto 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();
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto in project open-smart-grid-platform by OSGP.
the class UpdateFirmwareRequestMessageProcessorTest method processMessageTaskShouldNotUpdateFirmwareWhenFirmwareFileNotAvailable.
@Test
void processMessageTaskShouldNotUpdateFirmwareWhenFirmwareFileNotAvailable() throws JMSException, OsgpException {
// Arrange
final String firmwareIdentification = "unavailable";
final String deviceIdentification = "unavailableEither";
final UpdateFirmwareRequestDto updateFirmwareRequestDto = new UpdateFirmwareRequestDto(firmwareIdentification, deviceIdentification);
final ObjectMessage message = new ObjectMessageBuilder().withObject(updateFirmwareRequestDto).withCorrelationUid("123456").build();
final MessageMetadata messageMetadata = MessageMetadata.fromMessage(message);
when(this.firmwareService.isFirmwareFileAvailable(firmwareIdentification)).thenReturn(false);
// Act
this.processor.processMessageTasks(message.getObject(), messageMetadata, this.dlmsConnectionManagerMock, this.device);
// Assert
verify(this.firmwareService, times(0)).updateFirmware(nullable(DlmsConnectionManager.class), same(this.device), same(updateFirmwareRequestDto), any(MessageMetadata.class));
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto in project open-smart-grid-platform by OSGP.
the class ConfigurationService method requestUpdateFirmware.
public void requestUpdateFirmware(final MessageMetadata messageMetadata, final UpdateFirmwareRequestData updateFirmwareRequestData) throws FunctionalException {
log.info("requestUpdateFirmware for organisationIdentification: {} for deviceIdentification: {}", messageMetadata.getOrganisationIdentification(), messageMetadata.getDeviceIdentification());
final SmartMeter smartMeter = this.domainHelperService.findSmartMeter(messageMetadata.getDeviceIdentification());
final String firmwareIdentification = updateFirmwareRequestData.getFirmwareIdentification();
this.firmwareService.checkFirmwareFileSupportsDeviceModel(smartMeter, this.firmwareService.getFirmwareFile(firmwareIdentification));
/*
* The request here is applicable for an E-meter or G-meter. The assumption here
* is that an E-meter has no gateway device and the G-meter always has one.
* Therefore no distinction has to be made between requests for E or G-meters.
* In case the device to be updated has a gateway device the request will be
* sent to this gateway device. The UpdateFirmwareRequestDto contains the
* identification of the device to be updated
*/
final String deviceIdentification;
final String ipAddress;
final Integer baseTransceiverStationId;
final Integer cellId;
final String identificationOfDeviceToBeUpdated = smartMeter.getDeviceIdentification();
final Device gatewayDevice = smartMeter.getGatewayDevice();
if (gatewayDevice != null) {
deviceIdentification = gatewayDevice.getDeviceIdentification();
ipAddress = gatewayDevice.getIpAddress();
baseTransceiverStationId = gatewayDevice.getBtsId();
cellId = gatewayDevice.getCellId();
} else {
deviceIdentification = smartMeter.getDeviceIdentification();
ipAddress = smartMeter.getIpAddress();
baseTransceiverStationId = smartMeter.getBtsId();
cellId = smartMeter.getCellId();
}
final UpdateFirmwareRequestDto requestDto = new UpdateFirmwareRequestDto(firmwareIdentification, identificationOfDeviceToBeUpdated);
this.osgpCoreRequestMessageSender.send(requestDto, messageMetadata.builder().withDeviceIdentification(deviceIdentification).withIpAddress(ipAddress).withNetworkSegmentIds(baseTransceiverStationId, cellId).build());
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto in project open-smart-grid-platform by OSGP.
the class UpdateFirmwareRequestMessageProcessor method handleMessage.
@Override
protected Serializable handleMessage(final DlmsConnectionManager conn, final DlmsDevice device, final Serializable requestObject, final MessageMetadata messageMetadata) throws OsgpException {
final String deviceIdentification = messageMetadata.getDeviceIdentification();
final String organisationIdentification = messageMetadata.getOrganisationIdentification();
final String correlationUid = messageMetadata.getCorrelationUid();
final String messageType = messageMetadata.getMessageType();
this.assertRequestObjectType(UpdateFirmwareRequestDto.class, requestObject);
LOGGER.info("{} called for device: {} for organisation: {}", messageType, deviceIdentification, organisationIdentification);
final UpdateFirmwareRequestDto updateFirmwareRequestDto = (UpdateFirmwareRequestDto) requestObject;
final String firmwareIdentification = updateFirmwareRequestDto.getFirmwareIdentification();
if (this.firmwareService.isFirmwareFileAvailable(firmwareIdentification)) {
LOGGER.info("[{}] - Firmware file [{}] available. Updating firmware on device [{}]", correlationUid, firmwareIdentification, deviceIdentification);
return this.configurationService.updateFirmware(conn, device, updateFirmwareRequestDto, messageMetadata);
} else {
LOGGER.info("[{}] - Firmware file [{}] not available. Sending GetFirmwareFile request to core.", correlationUid, firmwareIdentification);
final RequestMessage message = new RequestMessage(correlationUid, organisationIdentification, deviceIdentification, updateFirmwareRequestDto);
this.osgpRequestMessageSender.send(message, MessageType.GET_FIRMWARE_FILE.name(), messageMetadata);
return NO_RESPONSE;
}
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto in project open-smart-grid-platform by OSGP.
the class UpdateFirmwareRequestMessageProcessorTest method processMessageTaskShouldSendFirmwareFileRequestWhenFirmwareFileNotAvailable.
@Test
void processMessageTaskShouldSendFirmwareFileRequestWhenFirmwareFileNotAvailable() throws JMSException, OsgpException {
// Arrange
final String firmwareIdentification = "unavailable";
final String deviceIdentification = "unavailableEither";
final UpdateFirmwareRequestDto updateFirmwareRequestDto = new UpdateFirmwareRequestDto(firmwareIdentification, deviceIdentification);
final ObjectMessage message = new ObjectMessageBuilder().withObject(updateFirmwareRequestDto).withCorrelationUid("123456").build();
final MessageMetadata messageMetadata = MessageMetadata.fromMessage(message);
when(this.firmwareService.isFirmwareFileAvailable(firmwareIdentification)).thenReturn(false);
// Act
this.processor.processMessageTasks(message.getObject(), messageMetadata, this.dlmsConnectionManagerMock, this.device);
// Assert
verify(this.osgpRequestMessageSender, times(1)).send(any(RequestMessage.class), any(String.class), any(MessageMetadata.class));
}
Aggregations