Search in sources :

Example 1 with FirmwareFileDto

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));
}
Also used : FirmwareFileDto(org.opensmartgridplatform.dto.valueobjects.FirmwareFileDto) UpdateFirmwareRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) Test(org.junit.jupiter.api.Test)

Example 2 with FirmwareFileDto

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());
    }
}
Also used : FirmwareFileDto(org.opensmartgridplatform.dto.valueobjects.FirmwareFileDto) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ProtocolResponseMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)

Example 3 with FirmwareFileDto

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;
}
Also used : FirmwareFileDto(org.opensmartgridplatform.dto.valueobjects.FirmwareFileDto) UpdateFirmwareRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto) Serializable(java.io.Serializable) ProtocolResponseMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage)

Example 4 with FirmwareFileDto

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);
    }
}
Also used : UpdateFirmwareRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto) FirmwareFileDto(org.opensmartgridplatform.dto.valueobjects.FirmwareFileDto) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) Device(org.opensmartgridplatform.domain.core.entities.Device) RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage) FirmwareFile(org.opensmartgridplatform.domain.core.entities.FirmwareFile) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) JMSException(javax.jms.JMSException)

Example 5 with FirmwareFileDto

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);
}
Also used : UpdateFirmwareRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto) FirmwareFileDto(org.opensmartgridplatform.dto.valueobjects.FirmwareFileDto) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) ProtocolResponseMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage) ObjectMessage(javax.jms.ObjectMessage) RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage) ProtocolInfo(org.opensmartgridplatform.domain.core.entities.ProtocolInfo) ObjectMessageBuilder(org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

FirmwareFileDto (org.opensmartgridplatform.dto.valueobjects.FirmwareFileDto)9 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)8 ProtocolResponseMessage (org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage)7 Test (org.junit.jupiter.api.Test)6 UpdateFirmwareRequestDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto)5 ResponseMessage (org.opensmartgridplatform.shared.infra.jms.ResponseMessage)5 ObjectMessage (javax.jms.ObjectMessage)4 ObjectMessageBuilder (org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder)4 DlmsDeviceBuilder (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDeviceBuilder)2 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)2 RequestMessage (org.opensmartgridplatform.shared.infra.jms.RequestMessage)2 Serializable (java.io.Serializable)1 JMSException (javax.jms.JMSException)1 Device (org.opensmartgridplatform.domain.core.entities.Device)1 FirmwareFile (org.opensmartgridplatform.domain.core.entities.FirmwareFile)1 ProtocolInfo (org.opensmartgridplatform.domain.core.entities.ProtocolInfo)1 UpdateFirmwareResponseDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareResponseDto)1 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)1