Search in sources :

Example 1 with FirmwareVersion

use of org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion in project open-smart-grid-platform by OSGP.

the class FirmwareManagementService method firmwareFileContainsAllOfTheseModules.

private static boolean firmwareFileContainsAllOfTheseModules(final FirmwareFile file, final List<FirmwareVersion> firmwareVersions) {
    int numberOfModulesFound = 0;
    final Map<FirmwareModule, String> moduleVersionsInFile = file.getModuleVersions();
    for (final FirmwareVersion firmwareVersion : firmwareVersions) {
        final FirmwareModule module = createFirmwareModule(firmwareVersion);
        if (moduleVersionsInFile.containsKey(module) && moduleVersionsInFile.get(module).equals(firmwareVersion.getVersion())) {
            // module found in this file
            numberOfModulesFound++;
            // check if all different modules are in this file
            if (numberOfModulesFound == firmwareVersions.size()) {
                return true;
            }
        }
    }
    return false;
}
Also used : FirmwareModule(org.opensmartgridplatform.domain.core.entities.FirmwareModule) FirmwareVersion(org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion)

Example 2 with FirmwareVersion

use of org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion in project open-smart-grid-platform by OSGP.

the class FirmwareManagementServiceTest method testCheckFirmwareHistoryForNonExistingVersion.

@Test
void testCheckFirmwareHistoryForNonExistingVersion() {
    // Arrange
    final FirmwareVersion firmwareVersion1 = new FirmwareVersion(FirmwareModuleType.SECURITY, VERSION_2);
    final FirmwareVersion firmwareVersion2 = new FirmwareVersion(FirmwareModuleType.FUNCTIONAL, VERSION_3);
    final List<FirmwareVersion> versionsOnDevice = Arrays.asList(firmwareVersion1, firmwareVersion2);
    final List<FirmwareVersion> expected = Collections.singletonList(firmwareVersion2);
    // Act
    final List<FirmwareVersion> versionsNotInHistory = this.firmwareManagementService.checkFirmwareHistoryForVersion("DVC", versionsOnDevice);
    // Assert
    assertThat(versionsNotInHistory).withFailMessage("Lists should be equal").isEqualTo(expected);
}
Also used : FirmwareVersion(org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion) Test(org.junit.jupiter.api.Test)

Example 3 with FirmwareVersion

use of org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion in project open-smart-grid-platform by OSGP.

the class FirmwareManagementServiceTest method testHandleGetFirmwareVersionResponseVersionNotInHistoryButNoCorrespondingFirmwareFile.

@Test
void testHandleGetFirmwareVersionResponseVersionNotInHistoryButNoCorrespondingFirmwareFile() {
    // Arrange
    // Mock that FUNCTIONAL VERSION 3 and SECURITY VERSION 1 is now
    // installed,
    // no firmware file will hold this combination, so it will fail to save
    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_1);
    final FirmwareVersion firmwareVersion3 = new FirmwareVersion(FirmwareModuleType.FUNCTIONAL, VERSION_3);
    final List<FirmwareVersion> versionsOnDevice = Arrays.asList(firmwareVersion1, firmwareVersion3);
    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, 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 4 with FirmwareVersion

use of org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion in project open-smart-grid-platform by OSGP.

the class FirmwareManagementServiceTest method testTryToAddFirmwareVersionToHistoryWhenFileIsNotAvailable.

@Test
void testTryToAddFirmwareVersionToHistoryWhenFileIsNotAvailable() {
    // Arrange
    final FirmwareFile firmwareFile = new FirmwareFile.Builder().withFilename("filename").withDescription("description").withPushToNewDevices(false).build();
    when(this.firmwareFileRepository.findByDeviceModel(any(DeviceModel.class))).thenReturn(Collections.singletonList(firmwareFile));
    final List<FirmwareVersion> firmwareVersions = Collections.singletonList(new FirmwareVersion(FirmwareModuleType.SECURITY, VERSION_2));
    // Act
    this.firmwareManagementService.tryToAddDeviceFirmwareFile("DVC", firmwareVersions);
    // Assert
    verify(this.deviceFirmwareFileRepository, never()).save(any(DeviceFirmwareFile.class));
}
Also used : DeviceModel(org.opensmartgridplatform.domain.core.entities.DeviceModel) DeviceFirmwareFile(org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile) DeviceFirmwareFile(org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile) FirmwareFile(org.opensmartgridplatform.domain.core.entities.FirmwareFile) FirmwareVersion(org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion) Test(org.junit.jupiter.api.Test)

Example 5 with FirmwareVersion

use of org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion in project open-smart-grid-platform by OSGP.

the class ConfigurationService method handleGetFirmwareVersionGasResponse.

public void handleGetFirmwareVersionGasResponse(final MessageMetadata messageMetadata, final ResponseMessageResultType deviceResult, final OsgpException exception, final FirmwareVersionGasDto firmwareVersionGas) {
    log.info("handleGetFirmwareVersionGasResponse for MessageType: {}", messageMetadata.getMessageType());
    ResponseMessageResultType result = deviceResult;
    if (exception != null) {
        log.error("Get firmware version response not ok. Unexpected Exception", exception);
        result = ResponseMessageResultType.NOT_OK;
    }
    final FirmwareVersion firmwareVersion = this.configurationMapper.map(firmwareVersionGas, FirmwareVersion.class);
    final FirmwareVersionGasResponse firmwareVersionGasResponse = new FirmwareVersionGasResponse(firmwareVersion);
    final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withMessageMetadata(messageMetadata).withResult(result).withOsgpException(exception).withDataObject(firmwareVersionGasResponse).build();
    this.webServiceResponseMessageSender.send(responseMessage, messageMetadata.getMessageType());
    this.firmwareService.saveFirmwareVersionsReturnedFromDevice(firmwareVersionGas.getMbusDeviceIdentification(), Arrays.asList(firmwareVersion));
}
Also used : FirmwareVersionGasResponse(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.FirmwareVersionGasResponse) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) FirmwareVersion(org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion)

Aggregations

FirmwareVersion (org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion)23 Test (org.junit.jupiter.api.Test)13 FirmwareModule (org.opensmartgridplatform.domain.core.entities.FirmwareModule)9 CorrelationIds (org.opensmartgridplatform.shared.infra.jms.CorrelationIds)9 DeviceFirmwareFile (org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile)8 DeviceModel (org.opensmartgridplatform.domain.core.entities.DeviceModel)8 FirmwareFile (org.opensmartgridplatform.domain.core.entities.FirmwareFile)8 FirmwareVersionDto (org.opensmartgridplatform.dto.valueobjects.FirmwareVersionDto)8 ResponseMessage (org.opensmartgridplatform.shared.infra.jms.ResponseMessage)5 ResponseMessageResultType (org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType)5 Date (java.util.Date)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 SsldPendingFirmwareUpdate (org.opensmartgridplatform.domain.core.entities.SsldPendingFirmwareUpdate)4 FirmwareModuleType (org.opensmartgridplatform.domain.core.valueobjects.FirmwareModuleType)4 Serializable (java.io.Serializable)3 ArrayList (java.util.ArrayList)3 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)3 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)3 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)3 Collection (java.util.Collection)2