FirmwareManagementService extends AbstractService { public void handleGetFirmwareVersionResponse(final List<FirmwareVersionDto> firmwareVersionsDto, final CorrelationIds ids, final String messageType, final int messagePriority, final ResponseMessageResultType deviceResult, final OsgpException exception) { LOGGER.info("handleResponse for MessageType: {}", messageType); ResponseMessageResultType result = ResponseMessageResultType.OK; OsgpException osgpException = exception; try { if (deviceResult == ResponseMessageResultType.NOT_OK || osgpException != null) { LOGGER.error("Device Response not ok.", osgpException); throw osgpException; } } catch (final Exception e) { LOGGER.error("Unexpected Exception", e); result = ResponseMessageResultType.NOT_OK; osgpException = new TechnicalException(ComponentType.UNKNOWN, "Exception occurred while getting device firmware version", e); } final List<FirmwareVersion> firmwareVersions = this.domainCoreMapper.mapAsList(firmwareVersionsDto, FirmwareVersion.class); this.checkFirmwareHistory(ids.getDeviceIdentification(), firmwareVersions); final boolean hasPendingFirmwareUpdate = this.checkSsldPendingFirmwareUpdate(ids, firmwareVersions); if (!hasPendingFirmwareUpdate) { final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder() .withIds(ids) .withResult(result) .withOsgpException(osgpException) .withDataObject((Serializable) firmwareVersions) .withMessagePriority(messagePriority) .build(); this.webServiceResponseMessageSender.send(responseMessage); } } FirmwareManagementService(); void updateFirmware(final CorrelationIds ids,
            final FirmwareUpdateMessageDataContainer firmwareUpdateMessageDataContainer, final Long scheduleTime,
            final String messageType, final int messagePriority); void handleSsldPendingFirmwareUpdate(final String deviceIdentification); void getFirmwareVersion(@Identification final String organisationIdentification,
            @Identification final String deviceIdentification, final String correlationUid, final String messageType,
            final int messagePriority); void getFirmwareVersion(@Identification final String organisationIdentification,
            @Identification final String deviceIdentification, final String correlationUid, final String messageType,
            final int messagePriority, final Long delay); void handleGetFirmwareVersionResponse(final List<FirmwareVersionDto> firmwareVersionsDto,
            final CorrelationIds ids, final String messageType, final int messagePriority,
            final ResponseMessageResultType deviceResult, final OsgpException exception); List<FirmwareVersion> checkFirmwareHistoryForVersion(final String deviceId,
            final List<FirmwareVersion> firmwareVersions); void tryToAddDeviceFirmwareFile(final String deviceIdentification,
            final List<FirmwareVersion> firmwareVersionsNotCurrent); void switchFirmware(final String organisationIdentification, final String deviceIdentification,
            final String correlationUid, final String messageType, final int messagePriority, final String version);  }
@Test void testHandleGetFirmwareVersionResponseVersionAlreadyInHistoryButNotLast() { final FirmwareVersionDto firmwareVersionDto1 = new FirmwareVersionDto( org.opensmartgridplatform.dto.valueobjects.FirmwareModuleType.SECURITY, VERSION_1); final FirmwareVersionDto firmwareVersionDto2 = new FirmwareVersionDto( org.opensmartgridplatform.dto.valueobjects.FirmwareModuleType.FUNCTIONAL, VERSION_1); final List<FirmwareVersionDto> versionsOnDeviceDtos = Arrays.asList(firmwareVersionDto1, firmwareVersionDto2); final FirmwareVersion firmwareVersion1 = new FirmwareVersion(FirmwareModuleType.SECURITY, VERSION_1); final FirmwareVersion firmwareVersion2 = new FirmwareVersion(FirmwareModuleType.FUNCTIONAL, VERSION_1); 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_1); final FirmwareModule firmwareModule2 = new FirmwareModule( FirmwareModuleType.FUNCTIONAL.getDescription().toLowerCase()); firmwareFile.addFirmwareModule(firmwareModule2, VERSION_1); 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"); this.firmwareManagementService.handleGetFirmwareVersionResponse(versionsOnDeviceDtos, ids, "FW", 0, ResponseMessageResultType.OK, null); verify(this.deviceFirmwareFileRepository, times(1)).save(any(DeviceFirmwareFile.class)); }
@Test void testHandleGetFirmwareVersionResponseVersionNotInHistory() { 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"); this.firmwareManagementService.handleGetFirmwareVersionResponse(versionsOnDeviceDtos, ids, "FW", 0, ResponseMessageResultType.OK, null); verify(this.deviceFirmwareFileRepository, times(1)).save(any(DeviceFirmwareFile.class)); }
@Test void testHandleGetFirmwareVersionResponseVersionNotInHistoryButNoCorrespondingFirmwareFile() { 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"); this.firmwareManagementService.handleGetFirmwareVersionResponse(versionsOnDeviceDtos, ids, "FW", 0, ResponseMessageResultType.OK, null); verify(this.deviceFirmwareFileRepository, never()).save(any(DeviceFirmwareFile.class)); }
@Test void testHandleGetFirmwareVersionResponseVersionAlreadyInAndLast() { 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"); this.firmwareManagementService.handleGetFirmwareVersionResponse(versionsOnDeviceDtos, ids, "FW", 0, ResponseMessageResultType.OK, null); verify(this.deviceFirmwareFileRepository, never()).save(any(DeviceFirmwareFile.class)); }