use of org.opensmartgridplatform.dto.valueobjects.FirmwareFileDto in project open-smart-grid-platform by OSGP.
the class FirmwareServiceTest method updateFirmwareUsingFirmwareFileShouldStoreFirmwareFileAndCallExecutor.
@Test
public void updateFirmwareUsingFirmwareFileShouldStoreFirmwareFileAndCallExecutor() throws OsgpException {
// Arrange
final byte[] firmwareFile = firmwareIdentification.getBytes();
final byte[] firmwareImageIdentifier = Hex.decode("496d6167654964656e746966696572");
final FirmwareFileDto firmwareFileDto = new FirmwareFileDto(firmwareIdentification, deviceIdentification, firmwareFile, firmwareImageIdentifier);
final MessageMetadata messageMetadata = MessageMetadata.newBuilder().withCorrelationUid("123456").build();
when(this.firmwareFileCachingRepository.isAvailable(firmwareIdentification)).thenReturn(true);
when(this.firmwareFileCachingRepository.retrieve(firmwareIdentification)).thenReturn(firmwareFile);
when(this.firmwareImageIdentifierCachingRepository.isAvailable(firmwareIdentification)).thenReturn(true);
when(this.firmwareImageIdentifierCachingRepository.retrieve(firmwareIdentification)).thenReturn(firmwareImageIdentifier);
// Act
this.firmwareService.updateFirmware(this.dlmsConnectionManagerMock, this.dlmsDeviceMock, firmwareFileDto, messageMetadata);
// Assert
verify(this.firmwareFileCachingRepository, times(1)).store(firmwareIdentification, firmwareFile);
verify(this.firmwareImageIdentifierCachingRepository, times(1)).store(firmwareIdentification, firmwareImageIdentifier);
verify(this.updateFirmwareCommandExecutor, times(1)).execute(same(this.dlmsConnectionManagerMock), same(this.dlmsDeviceMock), any(UpdateFirmwareRequestDto.class), same(messageMetadata));
}
use of org.opensmartgridplatform.dto.valueobjects.FirmwareFileDto in project open-smart-grid-platform by OSGP.
the class GetFirmwareFileResponseMessageProcessor method handleMessage.
@Override
protected Serializable handleMessage(final DlmsConnectionManager conn, final DlmsDevice device, final Serializable response) throws OsgpException {
if (!(response instanceof ResponseMessage)) {
throw new ProtocolAdapterException("Invalid response type, expected ResponseMessage object.");
}
final ResponseMessage responseMessage = (ResponseMessage) response;
if (ResponseMessageResultType.OK.equals(responseMessage.getResult())) {
final FirmwareFileDto firmwareFileDto = (FirmwareFileDto) responseMessage.getDataObject();
final MessageMetadata messageMetadata = this.messageMetadataFromResponseMessage(responseMessage);
return this.firmwareService.updateFirmware(conn, device, firmwareFileDto, messageMetadata);
} else {
throw new ProtocolAdapterException("Get Firmware File failed.", responseMessage.getOsgpException());
}
}
use of org.opensmartgridplatform.dto.valueobjects.FirmwareFileDto in project open-smart-grid-platform by OSGP.
the class GetFirmwareFileResponseMessageProcessor method createUpdateFirmwareRequestDto.
private UpdateFirmwareRequestDto createUpdateFirmwareRequestDto(final Serializable messageObject) {
if (messageObject instanceof ProtocolResponseMessage) {
final ProtocolResponseMessage protocolResponseMessage = (ProtocolResponseMessage) messageObject;
final Serializable dataObject = protocolResponseMessage.getDataObject();
if (dataObject instanceof FirmwareFileDto) {
final FirmwareFileDto firmwareFileDto = (FirmwareFileDto) dataObject;
return new UpdateFirmwareRequestDto(firmwareFileDto.getFirmwareIdentification(), protocolResponseMessage.getDeviceIdentification());
}
}
LOGGER.warn("Firmware Identification not present.");
return null;
}
use of org.opensmartgridplatform.dto.valueobjects.FirmwareFileDto in project open-smart-grid-platform by OSGP.
the class GetFirmwareFileMessageProcessor method processMessage.
@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();
final UpdateFirmwareRequestDto updateFirmwareRequestDto = (UpdateFirmwareRequestDto) requestMessage.getRequest();
firmwareFileIdentification = updateFirmwareRequestDto.getFirmwareIdentification();
final FirmwareFile firmwareFile = this.firmwareFileRepository.findByIdentificationOnly(firmwareFileIdentification);
final FirmwareFileDto firmwareFileDto = new FirmwareFileDto(firmwareFileIdentification, updateFirmwareRequestDto.getDeviceIdentification(), firmwareFile.getFile(), firmwareFile.getImageIdentifier());
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);
}
}
use of org.opensmartgridplatform.dto.valueobjects.FirmwareFileDto in project open-smart-grid-platform by OSGP.
the class GetFirmwareFileMessageProcessorTest method processMessageShouldSendFirmwareFile.
@Test
public void processMessageShouldSendFirmwareFile() throws JMSException {
// arrange
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 UpdateFirmwareRequestDto updateFirmwareRequestDto = new UpdateFirmwareRequestDto(firmwareFileIdentification, deviceIdentification);
final RequestMessage requestMessage = new RequestMessage(correlationUid, organisationIdentification, deviceIdentification, updateFirmwareRequestDto);
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.findByIdentificationOnly(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);
// act
this.getFirmwareFileMessageProcessor.processMessage(message);
// assert
verify(this.protocolResponseMessageSender, times(1)).send(responseMessageArgumentCaptor.capture(), messageTypeCaptor.capture(), nullable(ProtocolInfo.class), any(MessageMetadata.class));
final FirmwareFileDto actualFirmwareFileDto = (FirmwareFileDto) responseMessageArgumentCaptor.getValue().getDataObject();
final String actualMessageType = messageTypeCaptor.getValue();
assertThat(actualFirmwareFileDto.getFirmwareFile()).isEqualTo(expectedFile);
assertThat(actualFirmwareFileDto.getDeviceIdentification()).isEqualTo(deviceIdentification);
assertThat(actualFirmwareFileDto.getFirmwareIdentification()).isEqualTo(firmwareFileIdentification);
assertThat(actualMessageType).isEqualTo(expectedMessageType);
}
Aggregations