Search in sources :

Example 11 with FirmwareVersionDto

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

the class DomainCoreMapperTest method testMapFirmwareVersionDtoList.

@Test
void testMapFirmwareVersionDtoList() {
    // Arrange
    final List<FirmwareVersionDto> firmwareVersionsDto = new ArrayList<>();
    final String version = "1";
    firmwareVersionsDto.add(new FirmwareVersionDto(org.opensmartgridplatform.dto.valueobjects.FirmwareModuleType.ACTIVE_FIRMWARE, version));
    final List<FirmwareVersion> expected = Arrays.asList(new FirmwareVersion(FirmwareModuleType.ACTIVE_FIRMWARE, version));
    // Act
    final List<FirmwareVersion> firmwareVersions = this.mapper.mapAsList(firmwareVersionsDto, FirmwareVersion.class);
    // Assert
    assertThat(firmwareVersions).isEqualTo(expected);
}
Also used : ArrayList(java.util.ArrayList) FirmwareVersionDto(org.opensmartgridplatform.dto.valueobjects.FirmwareVersionDto) FirmwareVersion(org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion) Test(org.junit.jupiter.api.Test)

Example 12 with FirmwareVersionDto

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

the class FirmwareManagementServiceTest method testHandleGetFirmwareVersionResponseVersionNotInHistory.

@Test
void testHandleGetFirmwareVersionResponseVersionNotInHistory() {
    // Arrange
    // Mock that VERSION 3 is now installed
    final FirmwareVersionDto firmwareVersionDto1 = new FirmwareVersionDto(org.opensmartgridplatform.dto.valueobjects.FirmwareModuleType.SECURITY, VERSION_3);
    final FirmwareVersionDto firmwareVersionDto2 = new FirmwareVersionDto(org.opensmartgridplatform.dto.valueobjects.FirmwareModuleType.FUNCTIONAL, VERSION_3);
    final List<FirmwareVersionDto> versionsOnDeviceDtos = Arrays.asList(firmwareVersionDto1, firmwareVersionDto2);
    final FirmwareVersion firmwareVersion1 = new FirmwareVersion(FirmwareModuleType.SECURITY, VERSION_3);
    final FirmwareVersion firmwareVersion2 = new FirmwareVersion(FirmwareModuleType.FUNCTIONAL, VERSION_3);
    final List<FirmwareVersion> versionsOnDevice = Arrays.asList(firmwareVersion1, firmwareVersion2);
    final FirmwareFile firmwareFile = new FirmwareFile.Builder().withFilename("filename").withDescription("description").withPushToNewDevices(false).build();
    final FirmwareModule firmwareModule1 = new FirmwareModule(FirmwareModuleType.SECURITY.getDescription().toLowerCase());
    firmwareFile.addFirmwareModule(firmwareModule1, VERSION_3);
    final FirmwareModule firmwareModule2 = new FirmwareModule(FirmwareModuleType.FUNCTIONAL.getDescription().toLowerCase());
    firmwareFile.addFirmwareModule(firmwareModule2, VERSION_3);
    when(this.domainCoreMapper.mapAsList(versionsOnDeviceDtos, FirmwareVersion.class)).thenReturn(versionsOnDevice);
    when(this.ssldPendingFirmwareUpdateRepository.findByDeviceIdentification("DVC")).thenReturn(Collections.emptyList());
    when(this.firmwareFileRepository.findByDeviceModel(any(DeviceModel.class))).thenReturn(Collections.singletonList(firmwareFile));
    final CorrelationIds ids = new CorrelationIds("ORG", "DVC", "CORR");
    // Act
    this.firmwareManagementService.handleGetFirmwareVersionResponse(versionsOnDeviceDtos, ids, "FW", 0, ResponseMessageResultType.OK, null);
    // Validate
    verify(this.deviceFirmwareFileRepository, times(1)).save(any(DeviceFirmwareFile.class));
}
Also used : DeviceModel(org.opensmartgridplatform.domain.core.entities.DeviceModel) DeviceFirmwareFile(org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile) FirmwareModule(org.opensmartgridplatform.domain.core.entities.FirmwareModule) FirmwareVersionDto(org.opensmartgridplatform.dto.valueobjects.FirmwareVersionDto) FirmwareVersion(org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion) DeviceFirmwareFile(org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile) FirmwareFile(org.opensmartgridplatform.domain.core.entities.FirmwareFile) CorrelationIds(org.opensmartgridplatform.shared.infra.jms.CorrelationIds) Test(org.junit.jupiter.api.Test)

Example 13 with FirmwareVersionDto

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

the class FirmwareManagementServiceTest method testHandleGetFirmwareVersionResponseVersionAlreadyInAndLast.

@Test
void testHandleGetFirmwareVersionResponseVersionAlreadyInAndLast() {
    // Arrange
    // Mock that VERSION 2 is now installed
    final FirmwareVersionDto firmwareVersionDto1 = new FirmwareVersionDto(org.opensmartgridplatform.dto.valueobjects.FirmwareModuleType.SECURITY, VERSION_2);
    final FirmwareVersionDto firmwareVersionDto2 = new FirmwareVersionDto(org.opensmartgridplatform.dto.valueobjects.FirmwareModuleType.FUNCTIONAL, VERSION_2);
    final List<FirmwareVersionDto> versionsOnDeviceDtos = Arrays.asList(firmwareVersionDto1, firmwareVersionDto2);
    final FirmwareVersion firmwareVersion1 = new FirmwareVersion(FirmwareModuleType.SECURITY, VERSION_2);
    final FirmwareVersion firmwareVersion2 = new FirmwareVersion(FirmwareModuleType.FUNCTIONAL, VERSION_2);
    final List<FirmwareVersion> versionsOnDevice = Arrays.asList(firmwareVersion1, firmwareVersion2);
    final FirmwareFile firmwareFile = new FirmwareFile.Builder().withFilename("filename").withDescription("description").withPushToNewDevices(false).build();
    final FirmwareModule firmwareModule1 = new FirmwareModule(FirmwareModuleType.SECURITY.getDescription().toLowerCase());
    firmwareFile.addFirmwareModule(firmwareModule1, VERSION_2);
    final FirmwareModule firmwareModule2 = new FirmwareModule(FirmwareModuleType.FUNCTIONAL.getDescription().toLowerCase());
    firmwareFile.addFirmwareModule(firmwareModule2, VERSION_2);
    when(this.domainCoreMapper.mapAsList(versionsOnDeviceDtos, FirmwareVersion.class)).thenReturn(versionsOnDevice);
    when(this.ssldPendingFirmwareUpdateRepository.findByDeviceIdentification("DVC")).thenReturn(Collections.emptyList());
    when(this.firmwareFileRepository.findByDeviceModel(any(DeviceModel.class))).thenReturn(Collections.singletonList(firmwareFile));
    final CorrelationIds ids = new CorrelationIds("ORG", "DVC", "CORR");
    // Act
    this.firmwareManagementService.handleGetFirmwareVersionResponse(versionsOnDeviceDtos, ids, "FW", 0, ResponseMessageResultType.OK, null);
    // Validate
    verify(this.deviceFirmwareFileRepository, never()).save(any(DeviceFirmwareFile.class));
}
Also used : DeviceModel(org.opensmartgridplatform.domain.core.entities.DeviceModel) DeviceFirmwareFile(org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile) FirmwareModule(org.opensmartgridplatform.domain.core.entities.FirmwareModule) FirmwareVersionDto(org.opensmartgridplatform.dto.valueobjects.FirmwareVersionDto) FirmwareVersion(org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion) DeviceFirmwareFile(org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile) FirmwareFile(org.opensmartgridplatform.domain.core.entities.FirmwareFile) CorrelationIds(org.opensmartgridplatform.shared.infra.jms.CorrelationIds) Test(org.junit.jupiter.api.Test)

Example 14 with FirmwareVersionDto

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

the class FirmwareManagementServiceTest method testHandleGetFirmwareVersionWithNonMatchingCorrelationUid.

@Test
void testHandleGetFirmwareVersionWithNonMatchingCorrelationUid() {
    final List<FirmwareVersionDto> versionsOnDevice = new ArrayList<>();
    final SsldPendingFirmwareUpdate ssldPendingFirmwareUpdate = Mockito.mock(SsldPendingFirmwareUpdate.class);
    final List<SsldPendingFirmwareUpdate> ssldPendingFirmwareUpdates = Collections.singletonList(ssldPendingFirmwareUpdate);
    when(this.ssldPendingFirmwareUpdateRepository.findByDeviceIdentification(any())).thenReturn(ssldPendingFirmwareUpdates);
    when(ssldPendingFirmwareUpdate.getCorrelationUid()).thenReturn("differentUid");
    this.firmwareManagementService.handleGetFirmwareVersionResponse(versionsOnDevice, CORRELATION_IDS, "messageType", 1, ResponseMessageResultType.OK, null);
    verify(this.webServiceResponseMessageSender).send(this.responseMessageCaptor.capture());
    final ResponseMessage responseMessage = this.responseMessageCaptor.getValue();
    final ResponseMessage expectedResponseMessage = ResponseMessage.newResponseMessageBuilder().withIds(CORRELATION_IDS).withResult(ResponseMessageResultType.OK).withMessagePriority(1).withMessageType(MessageType.GET_FIRMWARE_VERSION.name()).build();
    assertThat(responseMessage).usingRecursiveComparison().ignoringFields("dataObject").isEqualTo(expectedResponseMessage);
}
Also used : SsldPendingFirmwareUpdate(org.opensmartgridplatform.domain.core.entities.SsldPendingFirmwareUpdate) ArrayList(java.util.ArrayList) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) FirmwareVersionDto(org.opensmartgridplatform.dto.valueobjects.FirmwareVersionDto) Test(org.junit.jupiter.api.Test)

Example 15 with FirmwareVersionDto

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

the class FirmwareManagementServiceTest method testHandleGetFirmwareVersionResponseNotOk.

@Test
void testHandleGetFirmwareVersionResponseNotOk() {
    final List<FirmwareVersionDto> versionsOnDevice = new ArrayList<>();
    this.firmwareManagementService.handleGetFirmwareVersionResponse(versionsOnDevice, CORRELATION_IDS, "messageType", 1, ResponseMessageResultType.NOT_OK, null);
    verify(this.webServiceResponseMessageSender).send(this.responseMessageCaptor.capture());
    final ResponseMessage responseMessage = this.responseMessageCaptor.getValue();
    assertThat(responseMessage.getResult()).isEqualTo(ResponseMessageResultType.NOT_OK);
    assertThat(responseMessage.getOsgpException().getMessage()).isEqualTo("Exception occurred while getting device firmware version");
}
Also used : ArrayList(java.util.ArrayList) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) FirmwareVersionDto(org.opensmartgridplatform.dto.valueobjects.FirmwareVersionDto) Test(org.junit.jupiter.api.Test)

Aggregations

FirmwareVersionDto (org.opensmartgridplatform.dto.valueobjects.FirmwareVersionDto)18 Test (org.junit.jupiter.api.Test)11 ArrayList (java.util.ArrayList)8 FirmwareVersion (org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion)6 CorrelationIds (org.opensmartgridplatform.shared.infra.jms.CorrelationIds)5 JMSException (javax.jms.JMSException)4 DeviceFirmwareFile (org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile)4 DeviceModel (org.opensmartgridplatform.domain.core.entities.DeviceModel)4 FirmwareFile (org.opensmartgridplatform.domain.core.entities.FirmwareFile)4 FirmwareModule (org.opensmartgridplatform.domain.core.entities.FirmwareModule)4 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)4 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)4 ResponseMessage (org.opensmartgridplatform.shared.infra.jms.ResponseMessage)4 List (java.util.List)3 GetResult (org.openmuc.jdlms.GetResult)3 ResponseMessageResultType (org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType)3 Serializable (java.io.Serializable)2 AttributeAddress (org.openmuc.jdlms.AttributeAddress)2 GetResultBuilder (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.testutil.GetResultBuilder)2 DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)2