use of org.opensmartgridplatform.dto.valueobjects.FirmwareVersionDto in project open-smart-grid-platform by OSGP.
the class FirmwareManagementServiceTest method testHandleGetFirmwareVersionResponseVersionAlreadyInHistoryButNotLast.
@Test
void testHandleGetFirmwareVersionResponseVersionAlreadyInHistoryButNotLast() {
// Arrange
// Mock that VERSION 1 is now installed
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");
// Act
this.firmwareManagementService.handleGetFirmwareVersionResponse(versionsOnDeviceDtos, ids, "FW", 0, ResponseMessageResultType.OK, null);
// Validate
verify(this.deviceFirmwareFileRepository, times(1)).save(any(DeviceFirmwareFile.class));
}
use of org.opensmartgridplatform.dto.valueobjects.FirmwareVersionDto in project open-smart-grid-platform by OSGP.
the class FirmwareManagementServiceTest method testHandleGetFirmwareVersionWithMatchingFirmwareVersion.
@Test
void testHandleGetFirmwareVersionWithMatchingFirmwareVersion() {
final List<FirmwareVersionDto> firmwareVersionDtos = Collections.emptyList();
final SsldPendingFirmwareUpdate ssldPendingFirmwareUpdate = Mockito.mock(SsldPendingFirmwareUpdate.class);
final List<SsldPendingFirmwareUpdate> ssldPendingFirmwareUpdates = Collections.singletonList(ssldPendingFirmwareUpdate);
when(this.ssldPendingFirmwareUpdateRepository.findByDeviceIdentification(any(String.class))).thenReturn(ssldPendingFirmwareUpdates);
when(ssldPendingFirmwareUpdate.getCorrelationUid()).thenReturn(CORRELATION_IDS.getCorrelationUid());
when(ssldPendingFirmwareUpdate.getFirmwareModuleType()).thenReturn(FirmwareModuleType.SECURITY);
when(ssldPendingFirmwareUpdate.getFirmwareVersion()).thenReturn(VERSION_1);
when(this.domainCoreMapper.mapAsList(firmwareVersionDtos, FirmwareVersion.class)).thenReturn(Collections.singletonList(new FirmwareVersion(FirmwareModuleType.SECURITY, VERSION_1)));
this.firmwareManagementService.handleGetFirmwareVersionResponse(firmwareVersionDtos, CORRELATION_IDS, "messageType", 1, ResponseMessageResultType.OK, null);
verifyNoInteractions(this.webServiceResponseMessageSender);
verify(this.ssldPendingFirmwareUpdateRepository).delete(any());
}
use of org.opensmartgridplatform.dto.valueobjects.FirmwareVersionDto in project open-smart-grid-platform by OSGP.
the class CommonGetFirmwareRequestMessageProcessor method handleGetFirmwareVersionDeviceResponse.
private void handleGetFirmwareVersionDeviceResponse(final DeviceResponse deviceResponse, final ResponseMessageSender responseMessageSender, final DomainInformation domainInformation, final String messageType, final int retryCount, final boolean isScheduled) {
ResponseMessageResultType result = ResponseMessageResultType.OK;
OsgpException osgpException = null;
List<FirmwareVersionDto> firmwareVersions = null;
try {
firmwareVersions = ((GetFirmwareVersionDeviceResponse) deviceResponse).getFirmwareVersions();
} catch (final Exception e) {
LOGGER.error("Device Response Exception", e);
result = ResponseMessageResultType.NOT_OK;
osgpException = new TechnicalException(ComponentType.UNKNOWN, "Unexpected exception while retrieving response message", e);
}
final MessageMetadata messageMetadata = MessageMetadata.newBuilder().withDeviceIdentification(deviceResponse.getDeviceIdentification()).withOrganisationIdentification(deviceResponse.getOrganisationIdentification()).withCorrelationUid(deviceResponse.getCorrelationUid()).withMessageType(messageType).withDomain(domainInformation.getDomain()).withDomainVersion(domainInformation.getDomainVersion()).withMessagePriority(deviceResponse.getMessagePriority()).withScheduled(isScheduled).withRetryCount(retryCount).build();
final ProtocolResponseMessage responseMessage = ProtocolResponseMessage.newBuilder().messageMetadata(messageMetadata).result(result).osgpException(osgpException).dataObject((Serializable) firmwareVersions).build();
responseMessageSender.send(responseMessage);
}
Aggregations