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));
}
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));
}
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();
}
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);
}
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());
}
Aggregations