Search in sources :

Example 11 with MbusChannelElementsDto

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

the class CoupleMbusDeviceCommandExecutorTest method testNoMatchButEmptyChannel.

@Test
public void testNoMatchButEmptyChannel() throws ProtocolAdapterException {
    // Add empty channel to the list of candidate channels
    final ChannelElementValuesDto emptyChannel = new ChannelElementValuesDto((short) 2, (short) 0, "00000000", null, (short) 0, (short) 0);
    final List<ChannelElementValuesDto> candidateChannelElementValuesWithEmptyChannel = Arrays.asList(this.candidateChannelElementValues.get(0), emptyChannel);
    final MbusChannelElementsDto mbusChannelElementsDto = new MbusChannelElementsDto((short) -1, "noMatch", "noMatch", "noMatch", (short) -1, (short) -1);
    when(this.deviceChannelsHelper.findCandidateChannelsForDevice(eq(this.conn), eq(this.device), any(MbusChannelElementsDto.class))).thenReturn(candidateChannelElementValuesWithEmptyChannel);
    when(this.deviceChannelsHelper.findEmptyChannel(candidateChannelElementValuesWithEmptyChannel)).thenReturn(emptyChannel);
    when(this.deviceChannelsHelper.writeUpdatedMbus(eq(this.conn), eq(this.device), eq(mbusChannelElementsDto), eq(emptyChannel.getChannel()), any(String.class))).thenReturn(new ChannelElementValuesDto(emptyChannel.getChannel(), mbusChannelElementsDto.getPrimaryAddress(), mbusChannelElementsDto.getMbusIdentificationNumber(), mbusChannelElementsDto.getMbusManufacturerIdentification(), mbusChannelElementsDto.getMbusVersion(), mbusChannelElementsDto.getMbusDeviceTypeIdentification()));
    when(this.deviceChannelsHelper.correctFirstChannelOffset(any(ChannelElementValuesDto.class))).thenReturn((short) (emptyChannel.getChannel() - 1));
    final MbusChannelElementsResponseDto responseDto = this.commandExecutor.execute(this.conn, this.device, mbusChannelElementsDto, this.messageMetadata);
    assertThat(responseDto.getChannel()).isEqualTo((short) 2);
    assertThat(responseDto.getRetrievedChannelElements().get(0).getDeviceTypeIdentification()).isEqualTo(this.deviceTypeIdentification);
    assertThat(responseDto.getRetrievedChannelElements().get(0).getIdentificationNumber()).isEqualTo(this.identificationNumber);
    assertThat(responseDto.getRetrievedChannelElements().get(0).getManufacturerIdentification()).isEqualTo(this.manufacturerIdentification);
    assertThat(responseDto.getRetrievedChannelElements().get(0).getPrimaryAddress()).isEqualTo(this.primaryAddress);
    assertThat(responseDto.getRetrievedChannelElements().get(0).getVersion()).isEqualTo(this.version);
    verify(this.deviceChannelsHelper, times(1)).findCandidateChannelsForDevice(eq(this.conn), eq(this.device), any(MbusChannelElementsDto.class));
}
Also used : ChannelElementValuesDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelElementValuesDto) MbusChannelElementsResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.MbusChannelElementsResponseDto) MbusChannelElementsDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.MbusChannelElementsDto) Test(org.junit.jupiter.api.Test)

Example 12 with MbusChannelElementsDto

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

the class CoupleMbusDeviceCommandExecutorTest method testBestMatch.

@Test
public void testBestMatch() throws ProtocolAdapterException {
    final MbusChannelElementsDto mbusChannelElementsDto = new MbusChannelElementsDto((short) 8, this.mbusDeviceIdentification, this.identificationNumber, this.manufacturerIdentification, this.version, this.deviceTypeIdentification);
    when(this.deviceChannelsHelper.findCandidateChannelsForDevice(eq(this.conn), eq(this.device), any(MbusChannelElementsDto.class))).thenReturn(this.candidateChannelElementValues);
    final MbusChannelElementsResponseDto responseDto = this.commandExecutor.execute(this.conn, this.device, mbusChannelElementsDto, this.messageMetadata);
    assertThat(responseDto.getChannel()).isEqualTo(this.channel);
    assertThat(responseDto.getRetrievedChannelElements().get(0).getDeviceTypeIdentification()).isEqualTo(this.deviceTypeIdentification);
    assertThat(responseDto.getRetrievedChannelElements().get(0).getIdentificationNumber()).isEqualTo(this.identificationNumber);
    assertThat(responseDto.getRetrievedChannelElements().get(0).getManufacturerIdentification()).isEqualTo(this.manufacturerIdentification);
    assertThat(responseDto.getRetrievedChannelElements().get(0).getPrimaryAddress()).isEqualTo(this.primaryAddress);
    assertThat(responseDto.getRetrievedChannelElements().get(0).getVersion()).isEqualTo(this.version);
    verify(this.deviceChannelsHelper, times(1)).findCandidateChannelsForDevice(eq(this.conn), eq(this.device), any(MbusChannelElementsDto.class));
}
Also used : MbusChannelElementsResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.MbusChannelElementsResponseDto) MbusChannelElementsDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.MbusChannelElementsDto) Test(org.junit.jupiter.api.Test)

Aggregations

MbusChannelElementsDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.MbusChannelElementsDto)12 Test (org.junit.jupiter.api.Test)10 ChannelElementValuesDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelElementValuesDto)7 MbusChannelElementsResponseDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.MbusChannelElementsResponseDto)4 SmartMeter (org.opensmartgridplatform.domain.core.entities.SmartMeter)1