Search in sources :

Example 6 with PeriodicMeterReadsRequestDto

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

the class GetPeriodicMeterReadsGasCommandExecutor method fromBundleRequestInput.

@Override
public PeriodicMeterReadsRequestDto fromBundleRequestInput(final ActionRequestDto bundleInput) throws ProtocolAdapterException {
    this.checkActionRequestType(bundleInput);
    final PeriodicMeterReadsGasRequestDto periodicMeterReadsGasRequestDto = (PeriodicMeterReadsGasRequestDto) bundleInput;
    return new PeriodicMeterReadsRequestDto(periodicMeterReadsGasRequestDto.getPeriodType(), periodicMeterReadsGasRequestDto.getBeginDate(), periodicMeterReadsGasRequestDto.getEndDate(), periodicMeterReadsGasRequestDto.getChannel());
}
Also used : PeriodicMeterReadsGasRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsGasRequestDto) PeriodicMeterReadsRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsRequestDto)

Example 7 with PeriodicMeterReadsRequestDto

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

the class PeriodicMeterReadsQueryMappingTest method TestMapping.

// Test if mapping a PeriodicMeterReadsQuery succeeds if both beginDate and
// endDate are non-null.
@Test
public void TestMapping() {
    // build test data
    final PeriodType periodType = PeriodType.DAILY;
    final Date beginDate = new Date();
    final Date endDate = new Date();
    final boolean mbusDevice = false;
    final PeriodicMeterReadsQuery periodicMeterReadsQuery = new PeriodicMeterReadsQuery(periodType, beginDate, endDate, mbusDevice);
    // actual mapping
    final PeriodicMeterReadsRequestDto periodicMeterReadsQueryDto = this.monitoringMapper.map(periodicMeterReadsQuery, PeriodicMeterReadsRequestDto.class);
    // test mapping
    assertThat(periodicMeterReadsQueryDto).isNotNull();
    assertThat(periodicMeterReadsQueryDto.getPeriodType().name()).isEqualTo(periodicMeterReadsQuery.getPeriodType().name());
    assertThat(periodicMeterReadsQueryDto.getBeginDate()).isEqualTo(periodicMeterReadsQuery.getBeginDate());
    assertThat(periodicMeterReadsQueryDto.getEndDate()).isEqualTo(periodicMeterReadsQuery.getEndDate());
    assertThat(periodicMeterReadsQueryDto.isMbusQuery()).isEqualTo(periodicMeterReadsQuery.isMbusDevice());
}
Also used : PeriodType(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PeriodType) PeriodicMeterReadsQuery(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PeriodicMeterReadsQuery) PeriodicMeterReadsRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsRequestDto) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 8 with PeriodicMeterReadsRequestDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsRequestDto 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 9 with PeriodicMeterReadsRequestDto

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

the class GetPeriodicMeterReadsCommandExecutorTest method testExecuteObjectNotFound.

@Test
void testExecuteObjectNotFound() {
    // SETUP
    final PeriodicMeterReadsRequestDto request = new PeriodicMeterReadsRequestDto(PeriodTypeDto.DAILY, this.fromDateTime.toDate(), this.toDateTime.toDate(), ChannelDto.ONE);
    when(this.dlmsObjectConfigService.findAttributeAddressForProfile(any(), any(), any(), any(), any(), any())).thenReturn(Optional.empty());
    // CALL
    try {
        this.executor.execute(this.connectionManager, this.device, request, this.messageMetadata);
        fail("When no matching object is found, then execute should fail");
    } catch (final ProtocolAdapterException e) {
        assertThat(e.getMessage()).isEqualTo("No address found for " + DlmsObjectType.DAILY_LOAD_PROFILE);
    }
}
Also used : ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) PeriodicMeterReadsRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsRequestDto) Test(org.junit.jupiter.api.Test)

Example 10 with PeriodicMeterReadsRequestDto

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

the class GetPeriodicMeterReadsCommandExecutorTest method testBundle.

@Test
void testBundle() throws ProtocolAdapterException {
    final PeriodicMeterReadsRequestDataDto request = new PeriodicMeterReadsRequestDataDto(PeriodTypeDto.DAILY, new Date(this.from), new Date(this.to));
    final PeriodicMeterReadsRequestDto dto = this.executor.fromBundleRequestInput(request);
    assertThat(dto).isNotNull();
}
Also used : PeriodicMeterReadsRequestDataDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsRequestDataDto) PeriodicMeterReadsRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsRequestDto) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Aggregations

PeriodicMeterReadsRequestDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsRequestDto)12 Test (org.junit.jupiter.api.Test)8 Date (java.util.Date)5 DateTime (org.joda.time.DateTime)4 AttributeAddress (org.openmuc.jdlms.AttributeAddress)4 DataObject (org.openmuc.jdlms.datatypes.DataObject)4 Protocol (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.Protocol)4 PeriodTypeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodTypeDto)4 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Calendar (java.util.Calendar)2 Collections (java.util.Collections)2 GregorianCalendar (java.util.GregorianCalendar)2 List (java.util.List)2 TimeZone (java.util.TimeZone)2 Collectors (java.util.stream.Collectors)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 DateTimeZone (org.joda.time.DateTimeZone)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)2