Search in sources :

Example 6 with PeriodicMeterReadsGasResponseItemDto

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

the class GetPeriodicMeterReadsGasCommandExecutorIntegrationTest method testExecute.

private void testExecute(final Protocol protocol, final PeriodTypeDto type, final boolean useNullData) throws Exception {
    // SETUP
    final MessageMetadata messageMetadata = MessageMetadata.newBuilder().withCorrelationUid("123456").build();
    // Reset stub
    this.connectionStub.clearRequestedAttributeAddresses();
    // Create device with requested protocol version
    final DlmsDevice device = this.createDlmsDevice(protocol);
    // Create request object
    final PeriodicMeterReadsRequestDto request = new PeriodicMeterReadsRequestDto(type, this.TIME_FROM, this.TIME_TO, ChannelDto.fromNumber(1));
    // Get expected values
    final AttributeAddress expectedAddressProfile = this.createAttributeAddress(protocol, type, this.TIME_FROM, this.TIME_TO);
    final List<AttributeAddress> expectedScalerUnitAddresses = this.getScalerUnitAttributeAddresses(protocol);
    // Set response in stub
    this.setResponseForProfile(expectedAddressProfile, protocol, type, useNullData);
    this.setResponsesForScalerUnit(expectedScalerUnitAddresses);
    // CALL
    final PeriodicMeterReadGasResponseDto response = this.executor.execute(this.connectionManagerStub, device, request, messageMetadata);
    // VERIFY
    // Get resulting requests from connection stub
    final List<AttributeAddress> requestedAttributeAddresses = this.connectionStub.getRequestedAttributeAddresses();
    assertThat(requestedAttributeAddresses.size()).isEqualTo(2);
    // There should be 1 request to the buffer (id = 2) of a profile
    // (class-id = 7)
    final AttributeAddress actualAttributeAddressProfile = requestedAttributeAddresses.stream().filter(a -> a.getClassId() == this.CLASS_ID_PROFILE).collect(Collectors.toList()).get(0);
    AttributeAddressAssert.is(actualAttributeAddressProfile, expectedAddressProfile);
    // Check the amount of requests to the scaler_unit of the meter value in
    // the extended register
    final List<AttributeAddress> attributeAddressesScalerUnit = requestedAttributeAddresses.stream().filter(a -> a.getClassId() == this.CLASS_ID_EXTENDED_REGISTER && a.getId() == this.ATTR_ID_SCALER_UNIT).collect(Collectors.toList());
    assertThat(attributeAddressesScalerUnit.size()).isEqualTo(1);
    // Check response
    assertThat(response.getPeriodType()).isEqualTo(type);
    final List<PeriodicMeterReadsGasResponseItemDto> periodicMeterReads = response.getPeriodicMeterReadsGas();
    final int AMOUNT_OF_PERIODS = 2;
    assertThat(periodicMeterReads.size()).isEqualTo(AMOUNT_OF_PERIODS);
    this.checkClockValues(periodicMeterReads, type, useNullData);
    this.checkValues(periodicMeterReads);
    this.checkAmrStatus(periodicMeterReads, protocol, type);
}
Also used : DATA_NOT_VALID(org.opensmartgridplatform.dto.valueobjects.smartmetering.AmrProfileStatusCodeFlagDto.DATA_NOT_VALID) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) DateTimeZone(org.joda.time.DateTimeZone) PeriodTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodTypeDto) DlmsConnectionManagerStub(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.stub.DlmsConnectionManagerStub) Date(java.util.Date) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) PeriodicMeterReadsGasResponseItemDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsGasResponseItemDto) CRITICAL_ERROR(org.opensmartgridplatform.dto.valueobjects.smartmetering.AmrProfileStatusCodeFlagDto.CRITICAL_ERROR) DlmsObjectConfigService(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectConfigService) ChannelDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelDto) AttributeAddress(org.openmuc.jdlms.AttributeAddress) Calendar(java.util.Calendar) ObisCode(org.openmuc.jdlms.ObisCode) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) PeriodicMeterReadGasResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadGasResponseDto) DlmsConnectionStub(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.stub.DlmsConnectionStub) PeriodicMeterReadsRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsRequestDto) AttributeAddressAssert(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.testutil.AttributeAddressAssert) Protocol(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.Protocol) RECOVERED_VALUE(org.opensmartgridplatform.dto.valueobjects.smartmetering.AmrProfileStatusCodeFlagDto.RECOVERED_VALUE) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) GregorianCalendar(java.util.GregorianCalendar) POWER_DOWN(org.opensmartgridplatform.dto.valueobjects.smartmetering.AmrProfileStatusCodeFlagDto.POWER_DOWN) TimeZone(java.util.TimeZone) DlmsHelper(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.DlmsHelper) DateTime(org.joda.time.DateTime) DAYLIGHT_SAVING(org.opensmartgridplatform.dto.valueobjects.smartmetering.AmrProfileStatusCodeFlagDto.DAYLIGHT_SAVING) DataObject(org.openmuc.jdlms.datatypes.DataObject) DlmsObjectConfigConfiguration(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectConfigConfiguration) AmrProfileStatusCodeHelper(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.AmrProfileStatusCodeHelper) CLOCK_INVALID(org.opensmartgridplatform.dto.valueobjects.smartmetering.AmrProfileStatusCodeFlagDto.CLOCK_INVALID) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) CosemDateTime(org.openmuc.jdlms.datatypes.CosemDateTime) List(java.util.List) SelectiveAccessDescription(org.openmuc.jdlms.SelectiveAccessDescription) CLOCK_ADJUSTED(org.opensmartgridplatform.dto.valueobjects.smartmetering.AmrProfileStatusCodeFlagDto.CLOCK_ADJUSTED) NOT_USED(org.opensmartgridplatform.dto.valueobjects.smartmetering.AmrProfileStatusCodeFlagDto.NOT_USED) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) Collections(java.util.Collections) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) PeriodicMeterReadsGasResponseItemDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsGasResponseItemDto) AttributeAddress(org.openmuc.jdlms.AttributeAddress) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) PeriodicMeterReadGasResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadGasResponseDto) PeriodicMeterReadsRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsRequestDto)

Example 7 with PeriodicMeterReadsGasResponseItemDto

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

the class GetPeriodicMeterReadsGasCommandExecutorTest method testHappy.

@Test
public void testHappy() throws Exception {
    // SETUP - request
    final PeriodTypeDto periodType = PeriodTypeDto.DAILY;
    final ChannelDto channel = ChannelDto.ONE;
    final PeriodicMeterReadsRequestDto request = new PeriodicMeterReadsRequestDto(periodType, this.fromDateTime.toDate(), this.toDateTime.toDate(), channel);
    // SETUP - dlms objects
    final DlmsObject dlmsClock = new DlmsClock("0.0.1.0.0.255");
    final DlmsCaptureObject captureObject1 = new DlmsCaptureObject(dlmsClock, 2);
    final DlmsObject dlmsExtendedRegister = new DlmsExtendedRegister(DlmsObjectType.MBUS_MASTER_VALUE, "0.0.24.0.0.255", 0, RegisterUnit.M3, Medium.GAS);
    final DlmsCaptureObject captureObject2 = new DlmsCaptureObject(dlmsExtendedRegister, 2);
    final DlmsCaptureObject captureObject3 = new DlmsCaptureObject(dlmsExtendedRegister, 5);
    final List<DlmsCaptureObject> captureObjects = Arrays.asList(captureObject1, captureObject2, captureObject3);
    final DlmsProfile dlmsProfile = new DlmsProfile(DlmsObjectType.DAILY_LOAD_PROFILE, "1.2.3.4.5.6", captureObjects, ProfileCaptureTime.DAY, Medium.COMBINED);
    // SETUP - mock dlms object config to return attribute addresses
    final AttributeAddressForProfile attributeAddressForProfile = this.createAttributeAddressForProfile(dlmsProfile, captureObjects);
    final AttributeAddress attributeAddressScalerUnit = this.createAttributeAddress(dlmsExtendedRegister);
    when(this.dlmsObjectConfigService.findAttributeAddressForProfile(eq(this.device), eq(DlmsObjectType.DAILY_LOAD_PROFILE), eq(channel.getChannelNumber()), eq(this.fromDateTime), eq(this.toDateTime), eq(Medium.GAS))).thenReturn(Optional.of(attributeAddressForProfile));
    when(this.dlmsObjectConfigService.getAttributeAddressesForScalerUnit(eq(attributeAddressForProfile), eq(channel.getChannelNumber()))).thenReturn(Collections.singletonList(attributeAddressScalerUnit));
    final DlmsObject intervalTime = mock(DlmsObject.class);
    when(this.dlmsObjectConfigService.findDlmsObject(any(Protocol.class), any(DlmsObjectType.class), any(Medium.class))).thenReturn(Optional.of(intervalTime));
    // SETUP - mock dlms helper to return data objects on request
    final DataObject data0 = mock(DataObject.class);
    final DataObject data1 = mock(DataObject.class);
    final DataObject data2 = mock(DataObject.class);
    final DataObject bufferedObject1 = mock(DataObject.class);
    when(bufferedObject1.getValue()).thenReturn(asList(data0, data1, data2));
    final DataObject data3 = mock(DataObject.class);
    final DataObject data4 = mock(DataObject.class);
    final DataObject data5 = mock(DataObject.class);
    final DataObject bufferedObject2 = mock(DataObject.class);
    when(bufferedObject2.getValue()).thenReturn(asList(data3, data4, data5));
    final DataObject resultData = mock(DataObject.class);
    when(resultData.getValue()).thenReturn(asList(bufferedObject1, bufferedObject2));
    final String expectedDescription = "retrieve periodic meter reads for " + periodType + ", channel " + channel;
    final GetResult getResult = mock(GetResult.class);
    when(this.dlmsHelper.getAndCheck(eq(this.connectionManager), eq(this.device), eq(expectedDescription), eq(attributeAddressForProfile.getAttributeAddress()))).thenReturn(Collections.singletonList(getResult));
    when(this.dlmsHelper.getAndCheck(this.connectionManager, this.device, expectedDescription, attributeAddressScalerUnit)).thenReturn(Collections.singletonList(getResult));
    when(this.dlmsHelper.readDataObject(eq(getResult), any(String.class))).thenReturn(resultData);
    // SETUP - mock dlms helper to handle converting the data objects
    final String expectedDateTimeDescriptionLogTime = String.format("Clock from %s buffer", periodType);
    final String expectedDateTimeDescriptionCaptureTime = "Clock from mbus interval extended register";
    final CosemDateTimeDto cosemDateTime = new CosemDateTimeDto(this.fromDateTime);
    when(this.dlmsHelper.readDateTime(data0, expectedDateTimeDescriptionLogTime)).thenReturn(cosemDateTime);
    when(this.dlmsHelper.readDateTime(data3, expectedDateTimeDescriptionLogTime)).thenReturn(cosemDateTime);
    when(this.dlmsHelper.readDateTime(data2, expectedDateTimeDescriptionCaptureTime)).thenReturn(cosemDateTime);
    when(this.dlmsHelper.readDateTime(data5, expectedDateTimeDescriptionCaptureTime)).thenReturn(cosemDateTime);
    final DlmsMeterValueDto meterValue1 = mock(DlmsMeterValueDto.class);
    final DlmsMeterValueDto meterValue2 = mock(DlmsMeterValueDto.class);
    when(this.dlmsHelper.getScaledMeterValue(data1, null, "gasValue")).thenReturn(meterValue1);
    when(this.dlmsHelper.getScaledMeterValue(data4, null, "gasValue")).thenReturn(meterValue2);
    // CALL
    final PeriodicMeterReadGasResponseDto result = this.executor.execute(this.connectionManager, this.device, request, this.messageMetadata);
    // VERIFY - the right functions should be called
    verify(this.dlmsMessageListener).setDescription(String.format("GetPeriodicMeterReadsGas for channel ONE, DAILY from %s until %s, retrieve attribute: {%s,%s,%s}", new DateTime(this.from), new DateTime(this.to), dlmsProfile.getClassId(), dlmsProfile.getObisCodeAsString(), dlmsProfile.getDefaultAttributeId()));
    verify(this.dlmsHelper, times(2)).validateBufferedDateTime(any(DateTime.class), argThat(new DateTimeMatcher(this.from)), argThat(new DateTimeMatcher(this.to)));
    verify(this.dlmsObjectConfigService).findDlmsObject(any(Protocol.class), any(DlmsObjectType.class), any(Medium.class));
    // ASSERT - the result should contain 2 values
    final List<PeriodicMeterReadsGasResponseItemDto> periodicMeterReads = result.getPeriodicMeterReadsGas();
    assertThat(periodicMeterReads.size()).isEqualTo(2);
    assertThat(periodicMeterReads.stream().anyMatch(r -> r.getConsumption() == meterValue1)).isEqualTo(true);
    assertThat(periodicMeterReads.stream().anyMatch(r -> r.getConsumption() == meterValue2)).isEqualTo(true);
    assertThat(periodicMeterReads.stream().allMatch(r -> this.areDatesEqual(r.getLogTime(), cosemDateTime))).isEqualTo(true);
    assertThat(periodicMeterReads.stream().allMatch(r -> this.areDatesEqual(r.getCaptureTime(), cosemDateTime))).isEqualTo(true);
}
Also used : AttributeAddressForProfile(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.AttributeAddressForProfile) PeriodTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodTypeDto) GetResult(org.openmuc.jdlms.GetResult) PeriodicMeterReadsGasResponseItemDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsGasResponseItemDto) ChannelDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelDto) AttributeAddress(org.openmuc.jdlms.AttributeAddress) DateTime(org.joda.time.DateTime) CosemDateTimeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateTimeDto) DlmsClock(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsClock) DataObject(org.openmuc.jdlms.datatypes.DataObject) DlmsExtendedRegister(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsExtendedRegister) Medium(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.Medium) DlmsProfile(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsProfile) PeriodicMeterReadGasResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadGasResponseDto) DlmsCaptureObject(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsCaptureObject) Protocol(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.Protocol) PeriodicMeterReadsRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsRequestDto) DlmsObject(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsObject) DlmsObjectType(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectType) DlmsMeterValueDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto) Test(org.junit.jupiter.api.Test)

Example 8 with PeriodicMeterReadsGasResponseItemDto

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

the class GetPeriodicMeterReadsGasCommandExecutorIntegrationTest method checkAmrStatus.

private void checkAmrStatus(final List<PeriodicMeterReadsGasResponseItemDto> periodicMeterReads, final Protocol protocol, final PeriodTypeDto type) {
    final PeriodicMeterReadsGasResponseItemDto period1 = periodicMeterReads.get(0);
    final PeriodicMeterReadsGasResponseItemDto period2 = periodicMeterReads.get(1);
    if (protocol == Protocol.DSMR_4_2_2 && type == PeriodTypeDto.MONTHLY) {
        assertThat(period1.getAmrProfileStatusCode()).isNull();
        assertThat(period2.getAmrProfileStatusCode()).isNull();
    } else {
        assertThat(period1.getAmrProfileStatusCode().getAmrProfileStatusCodeFlags()).containsExactly(CRITICAL_ERROR, CLOCK_INVALID, DATA_NOT_VALID, DAYLIGHT_SAVING);
        assertThat(period2.getAmrProfileStatusCode().getAmrProfileStatusCodeFlags()).containsExactlyInAnyOrder(NOT_USED, CLOCK_ADJUSTED, RECOVERED_VALUE, POWER_DOWN);
    }
}
Also used : PeriodicMeterReadsGasResponseItemDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsGasResponseItemDto)

Example 9 with PeriodicMeterReadsGasResponseItemDto

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

the class GetPeriodicMeterReadsGasCommandExecutorIntegrationTest method checkClockValues.

private void checkClockValues(final List<PeriodicMeterReadsGasResponseItemDto> periodicMeterReads, final PeriodTypeDto type, final boolean useNullData) {
    final PeriodicMeterReadsGasResponseItemDto periodicMeterRead1 = periodicMeterReads.get(0);
    assertThat(periodicMeterRead1.getLogTime()).isEqualTo(this.PERIOD_1_CLOCK_VALUE);
    final PeriodicMeterReadsGasResponseItemDto periodicMeterRead2 = periodicMeterReads.get(1);
    if (!useNullData) {
        // The timestamps should be the same as the times
        // set in the test
        assertThat(periodicMeterRead2.getLogTime()).isEqualTo(this.PERIOD_2_CLOCK_VALUE);
    } else {
        // starting from the time of period 1
        if (type == PeriodTypeDto.INTERVAL) {
            assertThat(periodicMeterRead2.getLogTime()).isEqualTo(this.PERIOD_2_CLOCK_VALUE_NULL_DATA_PERIOD_HOURLY);
        } else if (type == PeriodTypeDto.DAILY) {
            assertThat(periodicMeterRead2.getLogTime()).isEqualTo(this.PERIOD_2_CLOCK_VALUE_NULL_DATA_PERIOD_DAILY);
        } else if (type == PeriodTypeDto.MONTHLY) {
            assertThat(periodicMeterRead2.getLogTime()).isEqualTo(this.PERIOD_2_CLOCK_VALUE_NULL_DATA_PERIOD_MONTHLY);
        }
    }
}
Also used : PeriodicMeterReadsGasResponseItemDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsGasResponseItemDto)

Example 10 with PeriodicMeterReadsGasResponseItemDto

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

the class GetPeriodicMeterReadsGasCommandExecutorIntegrationTest method checkValues.

private void checkValues(final List<PeriodicMeterReadsGasResponseItemDto> periodicMeterReads) {
    final PeriodicMeterReadsGasResponseItemDto period1 = periodicMeterReads.get(0);
    final PeriodicMeterReadsGasResponseItemDto period2 = periodicMeterReads.get(1);
    assertThat(period1.getConsumption().getValue().longValue()).isEqualTo(this.PERIOD_1_LONG_VALUE);
    assertThat(period2.getConsumption().getValue().longValue()).isEqualTo(this.PERIOD_2_LONG_VALUE);
}
Also used : PeriodicMeterReadsGasResponseItemDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsGasResponseItemDto)

Aggregations

PeriodicMeterReadsGasResponseItemDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsGasResponseItemDto)10 PeriodTypeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodTypeDto)6 PeriodicMeterReadGasResponseDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadGasResponseDto)6 Test (org.junit.jupiter.api.Test)5 DataObject (org.openmuc.jdlms.datatypes.DataObject)4 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 DateTime (org.joda.time.DateTime)3 AttributeAddress (org.openmuc.jdlms.AttributeAddress)3 GetResult (org.openmuc.jdlms.GetResult)2 AttributeAddressForProfile (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.AttributeAddressForProfile)2 Protocol (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.Protocol)2 PeriodicMeterReadsContainerGas (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PeriodicMeterReadsContainerGas)2 ChannelDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelDto)2 PeriodicMeterReadsRequestDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsRequestDto)2 BigDecimal (java.math.BigDecimal)1 Arrays (java.util.Arrays)1 Calendar (java.util.Calendar)1 Collections (java.util.Collections)1 GregorianCalendar (java.util.GregorianCalendar)1