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;
}
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);
}
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));
}
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));
}
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));
}
Aggregations