FirmwareService { public UpdateFirmwareResponseDto updateFirmware(final DlmsConnectionHolder 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 DlmsConnectionHolder conn, final DlmsDevice device); UpdateFirmwareResponseDto updateFirmware(final DlmsConnectionHolder conn, final DlmsDevice device,
            final String firmwareIdentification); UpdateFirmwareResponseDto updateFirmware(final DlmsConnectionHolder 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.dlmsConnectionHolderMock, this.dlmsDeviceMock, firmwareIdentification); verify(this.updateFirmwareCommandExecutor, times(1)).execute(this.dlmsConnectionHolderMock, this.dlmsDeviceMock, firmwareIdentification); }
@Test(expected = ProtocolAdapterException.class) public void updateFirmwareShouldThrowExceptionWhenFirmwareFileNotInCache() throws OsgpException { final String firmwareIdentification = "fw"; when(this.firmwareFileCachingRepository.retrieve(firmwareIdentification)).thenReturn(null); this.firmwareService.updateFirmware(this.dlmsConnectionHolderMock, 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.dlmsConnectionHolderMock, this.dlmsDeviceMock, firmwareIdentification); } catch (final ProtocolAdapterException e) { e.printStackTrace(); } verify(this.updateFirmwareCommandExecutor, never()).execute(this.dlmsConnectionHolderMock, 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.dlmsConnectionHolderMock, this.dlmsDeviceMock, firmwareFileDto); verify(this.firmwareFileCachingRepository, times(1)).store(firmwareIdentification, firmwareFile); verify(this.updateFirmwareCommandExecutor, times(1)).execute(this.dlmsConnectionHolderMock, this.dlmsDeviceMock, firmwareIdentification); }