@Test void checkSsldPendingFirmwareUpdateReturnsTrueAndDeletesPendingUpdateWithMatchingCorrelationUid() { final String organisationIdentification = "test-org"; final String deviceIdentification = "device-identification"; final String correlationUid = "correlation-uid-matching-pending-update"; final CorrelationIds ids = new CorrelationIds(organisationIdentification, deviceIdentification, correlationUid); final List<FirmwareVersion> firmwareVersions = Collections .singletonList(new FirmwareVersion(FirmwareModuleType.FUNCTIONAL, VERSION_2)); final SsldPendingFirmwareUpdate matchingPendingFirmwareUpdate = this.anSsldPendingFirmwareUpdate(437L, new Date(), deviceIdentification, correlationUid); when(this.ssldPendingFirmwareUpdateRepository.findByDeviceIdentification(deviceIdentification)) .thenReturn(Arrays.asList( this.anSsldPendingFirmwareUpdate(457198L, new Date(), deviceIdentification, "some-other-correlation-uid"), matchingPendingFirmwareUpdate, this.anSsldPendingFirmwareUpdate(94085089L, new Date(), deviceIdentification, "yet-another-correlation-uid"))); final boolean hasPendingFirmwareUpdate = this.firmwareManagementService.checkSsldPendingFirmwareUpdate(ids, firmwareVersions); assertThat(hasPendingFirmwareUpdate).isTrue(); verify(this.ssldPendingFirmwareUpdateRepository).delete(matchingPendingFirmwareUpdate); }
boolean checkSsldPendingFirmwareUpdate(final CorrelationIds ids, final List<FirmwareVersion> firmwareVersions) { final String deviceIdentification = ids.getDeviceIdentification(); final SsldPendingFirmwareUpdate ssldPendingFirmwareUpdate = this.ssldPendingFirmwareUpdateRepository .findByDeviceIdentification(deviceIdentification) .stream() .filter(pendingUpdate -> pendingUpdate.getCorrelationUid().equals(ids.getCorrelationUid())) .findAny() .orElse(null); if (ssldPendingFirmwareUpdate == null) { return false; } LOGGER.info("Found SSLD pending firmware update record for device identification: {}, {}.", deviceIdentification, ssldPendingFirmwareUpdate); final FirmwareModuleType expectedFirmwareModuleType = ssldPendingFirmwareUpdate.getFirmwareModuleType(); final String expectedFirmwareVersion = ssldPendingFirmwareUpdate.getFirmwareVersion(); final boolean foundExpectedFirmwareVersion = firmwareVersions.stream() .anyMatch(fv -> expectedFirmwareModuleType.equals(fv.getFirmwareModuleType()) && expectedFirmwareVersion.equals(fv.getVersion())); if (foundExpectedFirmwareVersion) { LOGGER.info( "Expected firmware version from SSLD pending firmware update record matches firmware version as retrieved from device identification: {}, firmware version: {}, firmware module type: {}.", deviceIdentification, expectedFirmwareVersion, expectedFirmwareModuleType); } else { LOGGER.error( "Expected firmware version from SSLD pending firmware update record does )not match firmware version as retrieved from device identification: {}, expected firmware version: {}, expected firmware module type: {}, actual firmware version and module type list: {}", deviceIdentification, expectedFirmwareVersion, expectedFirmwareModuleType, firmwareVersions); } this.ssldPendingFirmwareUpdateRepository.delete(ssldPendingFirmwareUpdate); return true; }
FirmwareManagementService extends AbstractService { boolean checkSsldPendingFirmwareUpdate(final CorrelationIds ids, final List<FirmwareVersion> firmwareVersions) { final String deviceIdentification = ids.getDeviceIdentification(); final SsldPendingFirmwareUpdate ssldPendingFirmwareUpdate = this.ssldPendingFirmwareUpdateRepository .findByDeviceIdentification(deviceIdentification) .stream() .filter(pendingUpdate -> pendingUpdate.getCorrelationUid().equals(ids.getCorrelationUid())) .findAny() .orElse(null); if (ssldPendingFirmwareUpdate == null) { return false; } LOGGER.info("Found SSLD pending firmware update record for device identification: {}, {}.", deviceIdentification, ssldPendingFirmwareUpdate); final FirmwareModuleType expectedFirmwareModuleType = ssldPendingFirmwareUpdate.getFirmwareModuleType(); final String expectedFirmwareVersion = ssldPendingFirmwareUpdate.getFirmwareVersion(); final boolean foundExpectedFirmwareVersion = firmwareVersions.stream() .anyMatch(fv -> expectedFirmwareModuleType.equals(fv.getFirmwareModuleType()) && expectedFirmwareVersion.equals(fv.getVersion())); if (foundExpectedFirmwareVersion) { LOGGER.info( "Expected firmware version from SSLD pending firmware update record matches firmware version as retrieved from device identification: {}, firmware version: {}, firmware module type: {}.", deviceIdentification, expectedFirmwareVersion, expectedFirmwareModuleType); } else { LOGGER.error( "Expected firmware version from SSLD pending firmware update record does )not match firmware version as retrieved from device identification: {}, expected firmware version: {}, expected firmware module type: {}, actual firmware version and module type list: {}", deviceIdentification, expectedFirmwareVersion, expectedFirmwareModuleType, firmwareVersions); } this.ssldPendingFirmwareUpdateRepository.delete(ssldPendingFirmwareUpdate); return true; } }
FirmwareManagementService extends AbstractService { boolean checkSsldPendingFirmwareUpdate(final CorrelationIds ids, final List<FirmwareVersion> firmwareVersions) { final String deviceIdentification = ids.getDeviceIdentification(); final SsldPendingFirmwareUpdate ssldPendingFirmwareUpdate = this.ssldPendingFirmwareUpdateRepository .findByDeviceIdentification(deviceIdentification) .stream() .filter(pendingUpdate -> pendingUpdate.getCorrelationUid().equals(ids.getCorrelationUid())) .findAny() .orElse(null); if (ssldPendingFirmwareUpdate == null) { return false; } LOGGER.info("Found SSLD pending firmware update record for device identification: {}, {}.", deviceIdentification, ssldPendingFirmwareUpdate); final FirmwareModuleType expectedFirmwareModuleType = ssldPendingFirmwareUpdate.getFirmwareModuleType(); final String expectedFirmwareVersion = ssldPendingFirmwareUpdate.getFirmwareVersion(); final boolean foundExpectedFirmwareVersion = firmwareVersions.stream() .anyMatch(fv -> expectedFirmwareModuleType.equals(fv.getFirmwareModuleType()) && expectedFirmwareVersion.equals(fv.getVersion())); if (foundExpectedFirmwareVersion) { LOGGER.info( "Expected firmware version from SSLD pending firmware update record matches firmware version as retrieved from device identification: {}, firmware version: {}, firmware module type: {}.", deviceIdentification, expectedFirmwareVersion, expectedFirmwareModuleType); } else { LOGGER.error( "Expected firmware version from SSLD pending firmware update record does )not match firmware version as retrieved from device identification: {}, expected firmware version: {}, expected firmware module type: {}, actual firmware version and module type list: {}", deviceIdentification, expectedFirmwareVersion, expectedFirmwareModuleType, firmwareVersions); } this.ssldPendingFirmwareUpdateRepository.delete(ssldPendingFirmwareUpdate); return true; } FirmwareManagementService(); }
FirmwareManagementService extends AbstractService { boolean checkSsldPendingFirmwareUpdate(final CorrelationIds ids, final List<FirmwareVersion> firmwareVersions) { final String deviceIdentification = ids.getDeviceIdentification(); final SsldPendingFirmwareUpdate ssldPendingFirmwareUpdate = this.ssldPendingFirmwareUpdateRepository .findByDeviceIdentification(deviceIdentification) .stream() .filter(pendingUpdate -> pendingUpdate.getCorrelationUid().equals(ids.getCorrelationUid())) .findAny() .orElse(null); if (ssldPendingFirmwareUpdate == null) { return false; } LOGGER.info("Found SSLD pending firmware update record for device identification: {}, {}.", deviceIdentification, ssldPendingFirmwareUpdate); final FirmwareModuleType expectedFirmwareModuleType = ssldPendingFirmwareUpdate.getFirmwareModuleType(); final String expectedFirmwareVersion = ssldPendingFirmwareUpdate.getFirmwareVersion(); final boolean foundExpectedFirmwareVersion = firmwareVersions.stream() .anyMatch(fv -> expectedFirmwareModuleType.equals(fv.getFirmwareModuleType()) && expectedFirmwareVersion.equals(fv.getVersion())); if (foundExpectedFirmwareVersion) { LOGGER.info( "Expected firmware version from SSLD pending firmware update record matches firmware version as retrieved from device identification: {}, firmware version: {}, firmware module type: {}.", deviceIdentification, expectedFirmwareVersion, expectedFirmwareModuleType); } else { LOGGER.error( "Expected firmware version from SSLD pending firmware update record does )not match firmware version as retrieved from device identification: {}, expected firmware version: {}, expected firmware module type: {}, actual firmware version and module type list: {}", deviceIdentification, expectedFirmwareVersion, expectedFirmwareModuleType, firmwareVersions); } this.ssldPendingFirmwareUpdateRepository.delete(ssldPendingFirmwareUpdate); return true; } 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); }
FirmwareManagementService extends AbstractService { boolean checkSsldPendingFirmwareUpdate(final CorrelationIds ids, final List<FirmwareVersion> firmwareVersions) { final String deviceIdentification = ids.getDeviceIdentification(); final SsldPendingFirmwareUpdate ssldPendingFirmwareUpdate = this.ssldPendingFirmwareUpdateRepository .findByDeviceIdentification(deviceIdentification) .stream() .filter(pendingUpdate -> pendingUpdate.getCorrelationUid().equals(ids.getCorrelationUid())) .findAny() .orElse(null); if (ssldPendingFirmwareUpdate == null) { return false; } LOGGER.info("Found SSLD pending firmware update record for device identification: {}, {}.", deviceIdentification, ssldPendingFirmwareUpdate); final FirmwareModuleType expectedFirmwareModuleType = ssldPendingFirmwareUpdate.getFirmwareModuleType(); final String expectedFirmwareVersion = ssldPendingFirmwareUpdate.getFirmwareVersion(); final boolean foundExpectedFirmwareVersion = firmwareVersions.stream() .anyMatch(fv -> expectedFirmwareModuleType.equals(fv.getFirmwareModuleType()) && expectedFirmwareVersion.equals(fv.getVersion())); if (foundExpectedFirmwareVersion) { LOGGER.info( "Expected firmware version from SSLD pending firmware update record matches firmware version as retrieved from device identification: {}, firmware version: {}, firmware module type: {}.", deviceIdentification, expectedFirmwareVersion, expectedFirmwareModuleType); } else { LOGGER.error( "Expected firmware version from SSLD pending firmware update record does )not match firmware version as retrieved from device identification: {}, expected firmware version: {}, expected firmware module type: {}, actual firmware version and module type list: {}", deviceIdentification, expectedFirmwareVersion, expectedFirmwareModuleType, firmwareVersions); } this.ssldPendingFirmwareUpdateRepository.delete(ssldPendingFirmwareUpdate); return true; } 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);  }