Search in sources :

Example 11 with UpdateFirmwareRequestDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto in project open-smart-grid-platform by OSGP.

the class UpdateFirmwareRequestMessageProcessorTest method processMessageTaskShouldNotSendFirmwareFileRequestWhenFirmwareFileAvailable.

@Test
void processMessageTaskShouldNotSendFirmwareFileRequestWhenFirmwareFileAvailable() 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(true);
    // Act
    this.processor.processMessageTasks(message.getObject(), messageMetadata, this.dlmsConnectionManagerMock, this.device);
    // Assert
    verify(this.osgpRequestMessageSender, never()).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)

Example 12 with UpdateFirmwareRequestDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto in project open-smart-grid-platform by OSGP.

the class UpdateFirmwareRequestMessageProcessorTest method processMessageTaskShouldUpdateFirmwareWhenFirmwareFileAvailable.

@Test
void processMessageTaskShouldUpdateFirmwareWhenFirmwareFileAvailable() throws JMSException, OsgpException {
    // Arrange
    final String firmwareIdentification = "available";
    final String deviceIdentification = "availableToo";
    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(true);
    // Act
    this.processor.processMessageTasks(message.getObject(), messageMetadata, this.dlmsConnectionManagerMock, this.device);
    // Assert
    verify(this.configurationService, times(1)).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 13 with UpdateFirmwareRequestDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto in project open-smart-grid-platform by OSGP.

the class UpdateFirmwareCommandExecutorIntegrationTest method testExecuteMbusFirmware.

@Test
void testExecuteMbusFirmware() throws Exception {
    final DlmsDevice device = new DlmsDevice();
    device.setMbusIdentificationNumber("00000001");
    final String firmwareIdentification = RandomStringUtils.randomAlphabetic(10);
    final String deviceIdentification = RandomStringUtils.randomAlphabetic(10);
    device.setDeviceIdentification(deviceIdentification);
    final byte[] firmwareFile = org.bouncycastle.util.encoders.Hex.decode("534d523500230011004000310000001000020801e91effffffff500303000000000000831c9d5aa5b4f" + "fbfd057035a8a7896a4abe7afa36687fbc48944bcee0343eed3a75aab882ec1cf57820adfd4394e262d" + "5fa821c678e71c05c47e1c69c4bfffe1fd");
    when(this.dlmsDeviceRepository.findByDeviceIdentification(deviceIdentification)).thenReturn(device);
    when(this.firmwareFileCachingRepository.retrieve(firmwareIdentification)).thenReturn(firmwareFile);
    when(this.macGenerationService.calculateMac(any(), any(), any())).thenReturn(new byte[16]);
    final UpdateFirmwareRequestDto updateFirmwareRequestDto = new UpdateFirmwareRequestDto(firmwareIdentification, deviceIdentification);
    this.commandExecutor.execute(this.connectionManagerStub, device, updateFirmwareRequestDto, this.messageMetadata);
    verify(this.dlmsDeviceRepository, times(1)).findByDeviceIdentification(deviceIdentification);
    verify(this.macGenerationService, times(1)).calculateMac(any(), any(), any());
    verify(this.firmwareFileCachingRepository, times(1)).retrieve(firmwareIdentification);
    verify(this.firmwareImageIdentifierCachingRepository, never()).retrieve(firmwareIdentification);
    this.assertImageTransferRelatedInteractionWithConnection();
}
Also used : UpdateFirmwareRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) Test(org.junit.jupiter.api.Test)

Example 14 with UpdateFirmwareRequestDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto in project open-smart-grid-platform by OSGP.

the class UpdateFirmwareCommandExecutorIntegrationTest method testExecute.

@Test
void testExecute() throws Exception {
    final DlmsDevice device = new DlmsDevice();
    final String firmwareIdentification = RandomStringUtils.randomAlphabetic(10);
    final String deviceIdentification = RandomStringUtils.randomAlphabetic(10);
    final byte[] firmwareFile = RandomStringUtils.randomAlphabetic(100).getBytes(StandardCharsets.UTF_8);
    final byte[] firmwareImageIdentifier = Hex.decode("496d6167654964656e746966696572");
    when(this.firmwareFileCachingRepository.retrieve(firmwareIdentification)).thenReturn(firmwareFile);
    when(this.firmwareImageIdentifierCachingRepository.retrieve(firmwareIdentification)).thenReturn(firmwareImageIdentifier);
    final UpdateFirmwareRequestDto updateFirmwareRequestDto = new UpdateFirmwareRequestDto(firmwareIdentification, deviceIdentification);
    this.commandExecutor.execute(this.connectionManagerStub, device, updateFirmwareRequestDto, this.messageMetadata);
    verify(this.dlmsDeviceRepository, never()).findByDeviceIdentification(deviceIdentification);
    verify(this.macGenerationService, never()).calculateMac(any(), any(), any());
    verify(this.firmwareFileCachingRepository, times(1)).retrieve(firmwareIdentification);
    verify(this.firmwareImageIdentifierCachingRepository, times(1)).retrieve(firmwareIdentification);
    this.assertImageTransferRelatedInteractionWithConnection();
}
Also used : UpdateFirmwareRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) 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