FirmwareService { public UpdateFirmwareResponseDto updateFirmware(final DlmsConnectionManager conn, final DlmsDevice device, final String firmwareIdentification) throws OsgpException { LOGGER.info("Updating firmware of device {} to firmware with identification {}", device, firmwareIdentification); return this.executeFirmwareUpdate(conn, device, firmwareIdentification); }  List<FirmwareVersionDto> getFirmwareVersions(final DlmsConnectionManager conn, final DlmsDevice device); UpdateFirmwareResponseDto updateFirmware(final DlmsConnectionManager conn, final DlmsDevice device,
            final String firmwareIdentification); UpdateFirmwareResponseDto updateFirmware(final DlmsConnectionManager conn, final DlmsDevice device,
            final FirmwareFileDto firmwareFileDto); boolean isFirmwareFileAvailable(final String firmwareIdentification);  }
@Test public void updateFirmwareShouldCallExecutorWhenFirmwareFileInCache() throws OsgpException { final String firmwareIdentification = "fw"; final byte[] firmwareFile = firmwareIdentification.getBytes(); when(this.firmwareFileCachingRepository.isAvailable(firmwareIdentification)).thenReturn(true); when(this.firmwareFileCachingRepository.retrieve(firmwareIdentification)).thenReturn(firmwareFile); this.firmwareService.updateFirmware(this.dlmsConnectionManagerMock, this.dlmsDeviceMock, firmwareIdentification); verify(this.updateFirmwareCommandExecutor, times(1)).execute(this.dlmsConnectionManagerMock, this.dlmsDeviceMock, firmwareIdentification); }
@Test public void updateFirmwareShouldThrowExceptionWhenFirmwareFileNotInCache() throws OsgpException { final String firmwareIdentification = "fw"; when(this.firmwareFileCachingRepository.retrieve(firmwareIdentification)).thenReturn(null); assertThatExceptionOfType(ProtocolAdapterException.class).isThrownBy(() -> { this.firmwareService.updateFirmware(this.dlmsConnectionManagerMock, this.dlmsDeviceMock, firmwareIdentification); }); }
@Test public void updateFirmwareShouldNotCallExecutorWhenFirmwareFileNotInCache() throws OsgpException { final String firmwareIdentification = "fw"; when(this.firmwareFileCachingRepository.retrieve(firmwareIdentification)).thenReturn(null); try { this.firmwareService.updateFirmware(this.dlmsConnectionManagerMock, this.dlmsDeviceMock, firmwareIdentification); } catch (final ProtocolAdapterException e) { } verify(this.updateFirmwareCommandExecutor, never()).execute(this.dlmsConnectionManagerMock, this.dlmsDeviceMock, firmwareIdentification); }
@Test public void updateFirmwareUsingFirmwareFileShouldStoreFirmwareFileAndCallExecutor() throws OsgpException { final String firmwareIdentification = "fw"; final byte[] firmwareFile = firmwareIdentification.getBytes(); final FirmwareFileDto firmwareFileDto = new FirmwareFileDto(firmwareIdentification, firmwareFile); when(this.firmwareFileCachingRepository.isAvailable(firmwareIdentification)).thenReturn(true); when(this.firmwareFileCachingRepository.retrieve(firmwareIdentification)).thenReturn(firmwareFile); this.firmwareService.updateFirmware(this.dlmsConnectionManagerMock, this.dlmsDeviceMock, firmwareFileDto); verify(this.firmwareFileCachingRepository, times(1)).store(firmwareIdentification, firmwareFile); verify(this.updateFirmwareCommandExecutor, times(1)).execute(this.dlmsConnectionManagerMock, this.dlmsDeviceMock, firmwareIdentification); }