Search in sources :

Example 1 with ChannelElementValuesDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelElementValuesDto in project open-smart-grid-platform by OSGP.

the class CoupleMbusDeviceByChannelCommandExecutorTest method testHappyFlow.

@Test
public void testHappyFlow() throws ProtocolAdapterException {
    final short channel = (short) 1;
    final Short primaryAddress = 9;
    final String manufacturerIdentification = "manufacturerIdentification";
    final short version = 123;
    final short deviceTypeIdentification = 456;
    final String identificationNumber = "identificationNumber";
    final ChannelElementValuesDto dto = new ChannelElementValuesDto(channel, primaryAddress, identificationNumber, manufacturerIdentification, version, deviceTypeIdentification);
    final MessageMetadata messageMetadata = MessageMetadata.newBuilder().withCorrelationUid("123456").build();
    when(this.coupleMbusDeviceByChannelRequestDataDto.getChannel()).thenReturn(channel);
    when(this.deviceChannelsHelper.getChannelElementValues(this.conn, this.device, channel)).thenReturn(dto);
    final CoupleMbusDeviceByChannelResponseDto responseDto = this.commandExecutor.execute(this.conn, this.device, this.coupleMbusDeviceByChannelRequestDataDto, messageMetadata);
    assertThat(responseDto).isNotNull();
    assertThat(responseDto.getChannelElementValues()).isNotNull();
    assertThat(responseDto.getChannelElementValues().getChannel()).isEqualTo(channel);
    assertThat(responseDto.getChannelElementValues().getDeviceTypeIdentification()).isEqualTo(deviceTypeIdentification);
    assertThat(responseDto.getChannelElementValues().getIdentificationNumber()).isEqualTo(identificationNumber);
    assertThat(responseDto.getChannelElementValues().getManufacturerIdentification()).isEqualTo(manufacturerIdentification);
    assertThat(responseDto.getChannelElementValues().getPrimaryAddress()).isEqualTo(primaryAddress);
    assertThat(responseDto.getChannelElementValues().getVersion()).isEqualTo(version);
    verify(this.deviceChannelsHelper, times(1)).getChannelElementValues(eq(this.conn), eq(this.device), any(Short.class));
}
Also used : ChannelElementValuesDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelElementValuesDto) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) CoupleMbusDeviceByChannelResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CoupleMbusDeviceByChannelResponseDto) Test(org.junit.jupiter.api.Test)

Example 2 with ChannelElementValuesDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelElementValuesDto in project open-smart-grid-platform by OSGP.

the class DecoupleMBusDeviceCommandExecutorTest method testHappyFlow.

@Test
public void testHappyFlow() throws ProtocolAdapterException {
    final short channel = (short) 1;
    final ChannelElementValuesDto channelElementValuesDto = mock(ChannelElementValuesDto.class);
    final MessageMetadata messageMetadata = MessageMetadata.newBuilder().withCorrelationUid("123456").build();
    when(this.deviceChannelsHelper.getObisCode(this.device, channel)).thenReturn(new ObisCode("0.1.24.1.0.255"));
    when(this.decoupleMbusDto.getChannel()).thenReturn(channel);
    when(this.deviceChannelsHelper.deinstallSlave(eq(this.conn), eq(this.device), any(Short.class), any(CosemObjectAccessor.class))).thenReturn(MethodResultCode.SUCCESS);
    when(this.deviceChannelsHelper.getChannelElementValues(this.conn, this.device, channel)).thenReturn(channelElementValuesDto);
    final DecoupleMbusDeviceResponseDto responseDto = this.commandExecutor.execute(this.conn, this.device, this.decoupleMbusDto, messageMetadata);
    assertThat(responseDto).isNotNull();
    assertThat(responseDto.getChannelElementValues()).isEqualTo(channelElementValuesDto);
    verify(this.deviceChannelsHelper, times(1)).getChannelElementValues(eq(this.conn), eq(this.device), any(Short.class));
    verify(this.deviceChannelsHelper, times(1)).deinstallSlave(eq(this.conn), eq(this.device), any(Short.class), any(CosemObjectAccessor.class));
    verify(this.deviceChannelsHelper, times(1)).resetMBusClientAttributeValues(eq(this.conn), eq(this.device), any(Short.class), any(String.class));
}
Also used : ChannelElementValuesDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelElementValuesDto) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) CosemObjectAccessor(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.CosemObjectAccessor) DecoupleMbusDeviceResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.DecoupleMbusDeviceResponseDto) ObisCode(org.openmuc.jdlms.ObisCode) Test(org.junit.jupiter.api.Test)

Example 3 with ChannelElementValuesDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelElementValuesDto in project open-smart-grid-platform by OSGP.

the class DeviceChannelsHelperTest method testFindEmptyChannelWhenNoEmptyChannel.

@Test
public void testFindEmptyChannelWhenNoEmptyChannel() {
    final ChannelElementValuesDto result1 = this.deviceChannelsHelper.findEmptyChannel(Collections.emptyList());
    assertThat(result1).isNull();
    final ChannelElementValuesDto nonEmptyChannel = new ChannelElementValuesDto((short) 1, (short) 0, null, "id", (short) 0, (short) 0);
    final ChannelElementValuesDto result2 = this.deviceChannelsHelper.findEmptyChannel(Collections.singletonList(nonEmptyChannel));
    assertThat(result2).isNull();
}
Also used : ChannelElementValuesDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelElementValuesDto) Test(org.junit.jupiter.api.Test)

Example 4 with ChannelElementValuesDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelElementValuesDto in project open-smart-grid-platform by OSGP.

the class DeviceChannelsHelperTest method testGetChannelElementValuesSmr5.

@Test
void testGetChannelElementValuesSmr5() throws Exception {
    final List<GetResult> resultList = new ArrayList<>(Arrays.asList(this.primaryAddress, this.identificationNumber, this.manufacturerIdentification, this.version, this.deviceType));
    when(this.device.isWithListSupported()).thenReturn(true);
    when(this.conn.getDlmsMessageListener()).thenReturn(this.dlmsMessageListener);
    when(this.conn.getConnection()).thenReturn(this.dlmsConnection);
    when(this.dlmsConnection.get(anyList())).thenReturn(resultList);
    when(this.device.getProtocolName()).thenReturn("SMR");
    when(this.device.getProtocolVersion()).thenReturn("5.1");
    final ChannelElementValuesDto values = this.deviceChannelsHelper.getChannelElementValues(this.conn, this.device, (short) 1);
    assertThat(values.getPrimaryAddress()).isEqualTo(PRIMARY_ADDRESS);
    assertThat(values.getIdentificationNumber()).isEqualTo(IDENTIFICATION_NUMBER_AS_STRING);
    assertThat(values.getManufacturerIdentification()).isEqualTo(MANUFACTURER_IDENTIFICATION_AS_TEXT);
    assertThat(values.getVersion()).isEqualTo(VERSION);
    assertThat(values.getDeviceTypeIdentification()).isEqualTo(DEVICE_TYPE);
}
Also used : ChannelElementValuesDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelElementValuesDto) GetResult(org.openmuc.jdlms.GetResult) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 5 with ChannelElementValuesDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelElementValuesDto in project open-smart-grid-platform by OSGP.

the class SetDeviceLifecycleStatusByChannelCommandExecutor method execute.

@Override
public SetDeviceLifecycleStatusByChannelResponseDto execute(final DlmsConnectionManager conn, final DlmsDevice gatewayDevice, final SetDeviceLifecycleStatusByChannelRequestDataDto request, final MessageMetadata messageMetadata) throws OsgpException {
    final GetMBusDeviceOnChannelRequestDataDto mbusDeviceOnChannelRequest = new GetMBusDeviceOnChannelRequestDataDto(gatewayDevice.getDeviceIdentification(), request.getChannel());
    final ChannelElementValuesDto channelElementValues = this.getMBusDeviceOnChannelCommandExecutor.execute(conn, gatewayDevice, mbusDeviceOnChannelRequest, messageMetadata);
    if (!channelElementValues.hasChannel() || !channelElementValues.hasDeviceTypeIdentification() || !channelElementValues.hasManufacturerIdentification()) {
        throw new FunctionalException(FunctionalExceptionType.NO_DEVICE_FOUND_ON_CHANNEL, ComponentType.PROTOCOL_DLMS);
    }
    final DlmsDevice mbusDevice = this.dlmsDeviceRepository.findByMbusIdentificationNumberAndMbusManufacturerIdentification(channelElementValues.getIdentificationNumber(), channelElementValues.getManufacturerIdentification());
    if (mbusDevice == null) {
        throw new FunctionalException(FunctionalExceptionType.NO_MATCHING_MBUS_DEVICE_FOUND, ComponentType.PROTOCOL_DLMS);
    }
    return new SetDeviceLifecycleStatusByChannelResponseDto(gatewayDevice.getDeviceIdentification(), request.getChannel(), mbusDevice.getDeviceIdentification(), request.getDeviceLifecycleStatus());
}
Also used : ChannelElementValuesDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelElementValuesDto) SetDeviceLifecycleStatusByChannelResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SetDeviceLifecycleStatusByChannelResponseDto) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) GetMBusDeviceOnChannelRequestDataDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.GetMBusDeviceOnChannelRequestDataDto)

Aggregations

ChannelElementValuesDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelElementValuesDto)23 Test (org.junit.jupiter.api.Test)14 MbusChannelElementsDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.MbusChannelElementsDto)7 ArrayList (java.util.ArrayList)4 GetResult (org.openmuc.jdlms.GetResult)3 ObisCode (org.openmuc.jdlms.ObisCode)3 GetMBusDeviceOnChannelRequestDataDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.GetMBusDeviceOnChannelRequestDataDto)3 CosemObjectAccessor (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.CosemObjectAccessor)2 DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)2 CoupleMbusDeviceByChannelResponseDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CoupleMbusDeviceByChannelResponseDto)2 DecoupleMbusDeviceResponseDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.DecoupleMbusDeviceResponseDto)2 MbusChannelElementsResponseDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.MbusChannelElementsResponseDto)2 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)2 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)2 DataObject (org.openmuc.jdlms.datatypes.DataObject)1 DlmsObject (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsObject)1 GetResultImpl (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.testutil.GetResultImpl)1 DataObjectAttrExecutors (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.DataObjectAttrExecutors)1 EncryptionKeyStatusTypeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.EncryptionKeyStatusTypeDto)1 GMeterInfoDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.GMeterInfoDto)1