Search in sources :

Example 1 with FirmwareVersionDto

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));
}
Also used : DeviceModel(org.opensmartgridplatform.domain.core.entities.DeviceModel) DeviceFirmwareFile(org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile) FirmwareModule(org.opensmartgridplatform.domain.core.entities.FirmwareModule) FirmwareVersionDto(org.opensmartgridplatform.dto.valueobjects.FirmwareVersionDto) FirmwareVersion(org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion) DeviceFirmwareFile(org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile) FirmwareFile(org.opensmartgridplatform.domain.core.entities.FirmwareFile) CorrelationIds(org.opensmartgridplatform.shared.infra.jms.CorrelationIds) Test(org.junit.jupiter.api.Test)

Example 2 with FirmwareVersionDto

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);
}
Also used : TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) ArrayList(java.util.ArrayList) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) FirmwareVersionDto(org.opensmartgridplatform.dto.valueobjects.FirmwareVersionDto) Test(org.junit.jupiter.api.Test)

Example 3 with FirmwareVersionDto

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"));
}
Also used : GetResult(org.openmuc.jdlms.GetResult) AttributeAddress(org.openmuc.jdlms.AttributeAddress) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) GetResultBuilder(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.testutil.GetResultBuilder) FirmwareVersionDto(org.opensmartgridplatform.dto.valueobjects.FirmwareVersionDto) Test(org.junit.jupiter.api.Test)

Example 4 with FirmwareVersionDto

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"));
}
Also used : GetResult(org.openmuc.jdlms.GetResult) AttributeAddress(org.openmuc.jdlms.AttributeAddress) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) GetResultBuilder(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.testutil.GetResultBuilder) FirmwareVersionDto(org.opensmartgridplatform.dto.valueobjects.FirmwareVersionDto) Test(org.junit.jupiter.api.Test)

Example 5 with FirmwareVersionDto

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);
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) Serializable(java.io.Serializable) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) ProtocolResponseMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage) GetFirmwareVersionDeviceResponse(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.responses.GetFirmwareVersionDeviceResponse) ArrayList(java.util.ArrayList) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) FirmwareVersionDto(org.opensmartgridplatform.dto.valueobjects.FirmwareVersionDto) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) IOException(java.io.IOException) JMSException(javax.jms.JMSException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)

Aggregations

FirmwareVersionDto (org.opensmartgridplatform.dto.valueobjects.FirmwareVersionDto)18 Test (org.junit.jupiter.api.Test)11 ArrayList (java.util.ArrayList)8 FirmwareVersion (org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion)6 CorrelationIds (org.opensmartgridplatform.shared.infra.jms.CorrelationIds)5 JMSException (javax.jms.JMSException)4 DeviceFirmwareFile (org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile)4 DeviceModel (org.opensmartgridplatform.domain.core.entities.DeviceModel)4 FirmwareFile (org.opensmartgridplatform.domain.core.entities.FirmwareFile)4 FirmwareModule (org.opensmartgridplatform.domain.core.entities.FirmwareModule)4 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)4 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)4 ResponseMessage (org.opensmartgridplatform.shared.infra.jms.ResponseMessage)4 List (java.util.List)3 GetResult (org.openmuc.jdlms.GetResult)3 ResponseMessageResultType (org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType)3 Serializable (java.io.Serializable)2 AttributeAddress (org.openmuc.jdlms.AttributeAddress)2 GetResultBuilder (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.testutil.GetResultBuilder)2 DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)2