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