use of org.opensmartgridplatform.dto.valueobjects.FirmwareVersionDto in project open-smart-grid-platform by OSGP.
the class FirmwareManagementServiceTest method testHandleGetFirmwareVersionResponseVersionNotInHistoryButNoCorrespondingFirmwareFile.
@Test
void testHandleGetFirmwareVersionResponseVersionNotInHistoryButNoCorrespondingFirmwareFile() {
// Arrange
// Mock that FUNCTIONAL VERSION 3 and SECURITY VERSION 1 is now
// installed,
// no firmware file will hold this combination, so it will fail to save
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");
// Act
this.firmwareManagementService.handleGetFirmwareVersionResponse(versionsOnDeviceDtos, ids, "FW", 0, ResponseMessageResultType.OK, null);
// Validate
verify(this.deviceFirmwareFileRepository, never()).save(any(DeviceFirmwareFile.class));
}
use of org.opensmartgridplatform.dto.valueobjects.FirmwareVersionDto in project open-smart-grid-platform by OSGP.
the class FirmwareManagementServiceTest method testHandleGetFirmwareVersionErrorNotNull.
@Test
void testHandleGetFirmwareVersionErrorNotNull() {
final List<FirmwareVersionDto> versionsOnDevice = new ArrayList<>();
this.firmwareManagementService.handleGetFirmwareVersionResponse(versionsOnDevice, CORRELATION_IDS, "messageType", 1, ResponseMessageResultType.OK, DEFAULT_EXCEPTION);
verify(this.webServiceResponseMessageSender).send(this.responseMessageCaptor.capture());
verify(this.ssldPendingFirmwareUpdateRepository, never()).delete(any());
final ResponseMessage responseMessage = this.responseMessageCaptor.getValue();
final ResponseMessage expectedResponseMessage = ResponseMessage.newResponseMessageBuilder().withIds(CORRELATION_IDS).withResult(ResponseMessageResultType.NOT_OK).withOsgpException(new TechnicalException("Exception occurred while getting device firmware version")).withMessagePriority(1).withMessageType(MessageType.GET_FIRMWARE_VERSION.name()).build();
assertThat(responseMessage).usingRecursiveComparison().ignoringFields("dataObject").isEqualTo(expectedResponseMessage);
}
use of org.opensmartgridplatform.dto.valueobjects.FirmwareVersionDto in project open-smart-grid-platform by OSGP.
the class GetFirmwareVersionsCommandExecutorTest method returns4FirmwareVersionsForSmr51Device.
@Test
public void returns4FirmwareVersionsForSmr51Device() throws Exception {
final DlmsDevice device = new DlmsDevice();
device.setProtocol(Protocol.SMR_5_1);
final GetResult getResult1 = new GetResultBuilder().build();
final GetResult getResult2 = new GetResultBuilder().build();
final GetResult getResult3 = new GetResultBuilder().build();
final GetResult getResult4 = new GetResultBuilder().build();
when(this.helperService.getAndCheck(same(this.connectionHolder), same(device), eq("retrieve firmware versions"), refEq(new AttributeAddress(CLASS_ID, OBIS_CODE_ACTIVE_FIRMWARE_VERSION, ATTRIBUTE_ID)), refEq(new AttributeAddress(CLASS_ID, OBIS_CODE_MODULE_ACTIVE_FIRMWARE_VERSION, ATTRIBUTE_ID)), refEq(new AttributeAddress(CLASS_ID, OBIS_CODE_COMMUNICATION_MODULE_ACTIVE_FIRMWARE_VERSION, ATTRIBUTE_ID)), refEq(new AttributeAddress(CLASS_ID, OBIS_CODE_MBUS_DRIVER_ACTIVE_FIRMWARE_VERSION, ATTRIBUTE_ID)))).thenReturn(asList(getResult1, getResult2, getResult3, getResult4));
when(this.helperService.readString(getResult1.getResultData(), FirmwareModuleType.ACTIVE_FIRMWARE.getDescription())).thenReturn("string1");
when(this.helperService.readString(getResult2.getResultData(), FirmwareModuleType.MODULE_ACTIVE.getDescription())).thenReturn("string2");
when(this.helperService.readString(getResult3.getResultData(), FirmwareModuleType.COMMUNICATION.getDescription())).thenReturn("string3");
when(this.helperService.readString(getResult4.getResultData(), FirmwareModuleType.M_BUS_DRIVER_ACTIVE.getDescription())).thenReturn("string4");
final List<FirmwareVersionDto> result = this.executor.execute(this.connectionHolder, device, null, this.messageMetadata);
Assertions.assertThat(result).usingRecursiveFieldByFieldElementComparator().containsExactly(new FirmwareVersionDto(FirmwareModuleType.ACTIVE_FIRMWARE, "string1"), new FirmwareVersionDto(FirmwareModuleType.MODULE_ACTIVE, "string2"), new FirmwareVersionDto(FirmwareModuleType.COMMUNICATION, "string3"), new FirmwareVersionDto(FirmwareModuleType.M_BUS_DRIVER_ACTIVE, "string4"));
}
use of org.opensmartgridplatform.dto.valueobjects.FirmwareVersionDto in project open-smart-grid-platform by OSGP.
the class GetFirmwareVersionsCommandExecutorTest method returns3FirmwareVersionsForDsmr422Device.
@Test
public void returns3FirmwareVersionsForDsmr422Device() throws Exception {
final DlmsDevice device = new DlmsDevice();
final GetResult getResult1 = new GetResultBuilder().build();
final GetResult getResult2 = new GetResultBuilder().build();
final GetResult getResult3 = new GetResultBuilder().build();
when(this.helperService.getAndCheck(same(this.connectionHolder), same(device), eq("retrieve firmware versions"), refEq(new AttributeAddress(CLASS_ID, OBIS_CODE_ACTIVE_FIRMWARE_VERSION, ATTRIBUTE_ID)), refEq(new AttributeAddress(CLASS_ID, OBIS_CODE_MODULE_ACTIVE_FIRMWARE_VERSION, ATTRIBUTE_ID)), refEq(new AttributeAddress(CLASS_ID, OBIS_CODE_COMMUNICATION_MODULE_ACTIVE_FIRMWARE_VERSION, ATTRIBUTE_ID)))).thenReturn(asList(getResult1, getResult2, getResult3));
when(this.helperService.readString(getResult1.getResultData(), FirmwareModuleType.ACTIVE_FIRMWARE.getDescription())).thenReturn("string1");
when(this.helperService.readString(getResult2.getResultData(), FirmwareModuleType.MODULE_ACTIVE.getDescription())).thenReturn("string2");
when(this.helperService.readString(getResult3.getResultData(), FirmwareModuleType.COMMUNICATION.getDescription())).thenReturn("string3");
final List<FirmwareVersionDto> result = this.executor.execute(this.connectionHolder, device, null, this.messageMetadata);
Assertions.assertThat(result).usingRecursiveFieldByFieldElementComparator().containsExactly(new FirmwareVersionDto(FirmwareModuleType.ACTIVE_FIRMWARE, "string1"), new FirmwareVersionDto(FirmwareModuleType.MODULE_ACTIVE, "string2"), new FirmwareVersionDto(FirmwareModuleType.COMMUNICATION, "string3"));
}
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 String domain, final String domainVersion, final String messageType, final int retryCount) {
ResponseMessageResultType result = ResponseMessageResultType.OK;
final String firmwareVersion;
OsgpException osgpException = null;
final List<FirmwareVersionDto> firmwareVersions = new ArrayList<>();
try {
final GetFirmwareVersionDeviceResponse response = (GetFirmwareVersionDeviceResponse) deviceResponse;
firmwareVersion = response.getFirmwareVersion();
firmwareVersions.add(new FirmwareVersionDto(FirmwareModuleType.FUNCTIONAL, firmwareVersion));
} catch (final Exception e) {
LOGGER.error("Device Response Exception", e);
result = ResponseMessageResultType.NOT_OK;
osgpException = new TechnicalException(ComponentType.UNKNOWN, "Exception occurred while getting device firmware version", e);
}
final ProtocolResponseMessage responseMessage = ProtocolResponseMessage.newBuilder().messageMetadata(MessageMetadataFactory.from(deviceResponse, messageType).builder().withDomain(domain).withDomainVersion(domainVersion).withRetryCount(retryCount).build()).result(result).osgpException(osgpException).dataObject((Serializable) firmwareVersions).build();
responseMessageSender.send(responseMessage);
}
Aggregations