Search in sources :

Example 6 with UpdateFirmwareRequestDto

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();
}
Also used : FirmwareFileDto(org.opensmartgridplatform.dto.valueobjects.FirmwareFileDto) UpdateFirmwareRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) ObjectMessage(javax.jms.ObjectMessage) DlmsDeviceBuilder(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDeviceBuilder) ObjectMessageBuilder(org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ProtocolResponseMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) ObjectMessageBuilder(org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder) Test(org.junit.jupiter.api.Test)

Example 7 with UpdateFirmwareRequestDto

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));
}
Also used : UpdateFirmwareRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) ObjectMessage(javax.jms.ObjectMessage) DlmsConnectionManager(org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager) ObjectMessageBuilder(org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder) Test(org.junit.jupiter.api.Test)

Example 8 with UpdateFirmwareRequestDto

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());
}
Also used : UpdateFirmwareRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto) Device(org.opensmartgridplatform.domain.core.entities.Device) SmartMeter(org.opensmartgridplatform.domain.core.entities.SmartMeter)

Example 9 with UpdateFirmwareRequestDto

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

Example 10 with UpdateFirmwareRequestDto

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

Aggregations

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