use of org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto in project open-smart-grid-platform by OSGP.
the class MeterReadsGasMappingTest method testMeterReadsGasMappingTest.
// Test the mapping of a complete MeterReadsGasDto object
@Test
public void testMeterReadsGasMappingTest() {
// build test data
final DlmsMeterValueDto consumption = new DlmsMeterValueDto(new BigDecimal(1.0), DlmsUnitTypeDto.M3);
final MeterReadsGasResponseDto meterReadsGasDto = new MeterReadsGasResponseDto(new Date(), consumption, new Date());
// actual mapping
final MeterReadsGas meterReadsGas = this.monitoringMapper.map(meterReadsGasDto, MeterReadsGas.class);
// test mapping
assertThat(meterReadsGas).isNotNull();
assertThat(meterReadsGas.getLogTime()).isEqualTo(meterReadsGasDto.getLogTime());
assertThat(meterReadsGas.getCaptureTime()).isEqualTo(meterReadsGasDto.getCaptureTime());
final BigDecimal bigDecimal1 = consumption.getValue();
final BigDecimal bigDecimal2 = meterReadsGas.getConsumption().getValue();
assertThat(bigDecimal1.compareTo(bigDecimal2) == 0).isTrue();
assertThat(meterReadsGas.getConsumption().getOsgpUnit()).isEqualTo(OsgpUnit.M3);
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto in project open-smart-grid-platform by OSGP.
the class DlmsMeterValueConverterTest method testCalculate.
@Test
public void testCalculate() {
final MonitoringMapper calculator = new MonitoringMapper();
DlmsMeterValueDto response = new DlmsMeterValueDto(BigDecimal.valueOf(123456), DlmsUnitTypeDto.KWH);
assertThat(calculator.map(response, OsgpMeterValue.class).getValue()).isEqualTo(BigDecimal.valueOf(123.456d));
assertThat(calculator.map(response, OsgpMeterValue.class).getOsgpUnit()).isEqualTo(OsgpUnit.KWH);
response = new DlmsMeterValueDto(BigDecimal.valueOf(123456), DlmsUnitTypeDto.M3);
assertThat(calculator.map(response, OsgpMeterValue.class).getValue()).isEqualTo(BigDecimal.valueOf(123456d));
assertThat(calculator.map(response, OsgpMeterValue.class).getOsgpUnit()).isEqualTo(OsgpUnit.M3);
response = new DlmsMeterValueDto(BigDecimal.valueOf(123456), DlmsUnitTypeDto.M3_CORR);
assertThat(calculator.map(response, OsgpMeterValue.class).getValue()).isEqualTo(BigDecimal.valueOf(123456d));
assertThat(calculator.map(response, OsgpMeterValue.class).getOsgpUnit()).isEqualTo(OsgpUnit.M3);
response = new DlmsMeterValueDto(BigDecimal.valueOf(123456), DlmsUnitTypeDto.MONTH);
try {
calculator.map(response, OsgpMeterValue.class);
fail("dlms unit A not supported, expected IllegalArgumentException");
} catch (final IllegalArgumentException ex) {
}
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto in project open-smart-grid-platform by OSGP.
the class PeriodicMeterReadContainerMappingTest method testWithNonEmptyList.
// Test if mapping with a non-empty List succeeds
@Test
public void testWithNonEmptyList() {
// build test data
final DlmsMeterValueDto activeEnergyImport = new DlmsMeterValueDto(new BigDecimal(1.0), DlmsUnitTypeDto.M3);
final DlmsMeterValueDto activeEnergyExport = new DlmsMeterValueDto(new BigDecimal(1.0), DlmsUnitTypeDto.M3);
final Set<AmrProfileStatusCodeFlagDto> amrProfileStatusCodeFlagSet = new TreeSet<>();
amrProfileStatusCodeFlagSet.add(AmrProfileStatusCodeFlagDto.CRITICAL_ERROR);
final AmrProfileStatusCodeDto amrProfileStatusCodeDto = new AmrProfileStatusCodeDto(amrProfileStatusCodeFlagSet);
final PeriodicMeterReadsResponseItemDto periodicMeterReadsDto = new PeriodicMeterReadsResponseItemDto(new Date(), activeEnergyImport, activeEnergyExport, amrProfileStatusCodeDto);
final List<PeriodicMeterReadsResponseItemDto> meterReads = new ArrayList<>();
meterReads.add(periodicMeterReadsDto);
final PeriodTypeDto periodType = PeriodTypeDto.DAILY;
final PeriodicMeterReadsResponseDto periodicMeterReadsContainerDto = new PeriodicMeterReadsResponseDto(periodType, meterReads);
// actual mapping
final PeriodicMeterReadsContainer periodicMeterReadsContainer = this.monitoringMapper.map(periodicMeterReadsContainerDto, PeriodicMeterReadsContainer.class);
// test mapping
assertThat(periodicMeterReadsContainer).isNotNull();
assertThat(periodicMeterReadsContainer.getPeriodType().name()).isEqualTo(periodicMeterReadsContainerDto.getPeriodType().name());
assertThat(periodicMeterReadsContainer.getPeriodicMeterReads().size()).isEqualTo(periodicMeterReadsContainerDto.getPeriodicMeterReads().size());
assertThat(periodicMeterReadsContainer.getPeriodicMeterReads().get(0).getLogTime()).isEqualTo(periodicMeterReadsContainerDto.getPeriodicMeterReads().get(0).getLogTime());
assertThat(periodicMeterReadsContainer.getPeriodicMeterReads().get(0).getActiveEnergyImport().getValue()).isEqualTo(new BigDecimal("1.0"));
assertThat(periodicMeterReadsContainer.getPeriodicMeterReads().get(0).getActiveEnergyImport().getOsgpUnit()).isEqualTo(OsgpUnit.M3);
assertThat(periodicMeterReadsContainer.getPeriodicMeterReads().get(0).getActiveEnergyExport().getValue()).isEqualTo(new BigDecimal("1.0"));
assertThat(periodicMeterReadsContainer.getPeriodicMeterReads().get(0).getActiveEnergyExport().getOsgpUnit()).isEqualTo(OsgpUnit.M3);
assertThat(periodicMeterReadsContainer.getPeriodicMeterReads().get(0).getAmrProfileStatusCode().getAmrProfileStatusCodeFlags().size()).isEqualTo(periodicMeterReadsContainerDto.getPeriodicMeterReads().get(0).getAmrProfileStatusCode().getAmrProfileStatusCodeFlags().size());
assertThat(periodicMeterReadsContainer.getPeriodicMeterReads().get(0).getAmrProfileStatusCode().getAmrProfileStatusCodeFlags().contains(AmrProfileStatusCodeFlag.CRITICAL_ERROR)).isTrue();
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto in project open-smart-grid-platform by OSGP.
the class PeriodicMeterReadsContainerGasMappingTest method testWithNonEmptyList.
// Test if mapping with a non-empty List succeeds
@Test
public void testWithNonEmptyList() {
// build test data
final DlmsMeterValueDto consumption = new DlmsMeterValueDto(new BigDecimal(1.0), DlmsUnitTypeDto.M3);
final Set<AmrProfileStatusCodeFlagDto> amrProfileStatusCodeFlagSet = new TreeSet<>();
amrProfileStatusCodeFlagSet.add(AmrProfileStatusCodeFlagDto.CRITICAL_ERROR);
final AmrProfileStatusCodeDto amrProfileStatusCodeDto = new AmrProfileStatusCodeDto(amrProfileStatusCodeFlagSet);
final PeriodicMeterReadsGasResponseItemDto periodicMeterReadsGasDto = new PeriodicMeterReadsGasResponseItemDto(new Date(), consumption, new Date(), amrProfileStatusCodeDto);
final List<PeriodicMeterReadsGasResponseItemDto> meterReads = new ArrayList<>();
meterReads.add(periodicMeterReadsGasDto);
final PeriodTypeDto periodType = PeriodTypeDto.DAILY;
final PeriodicMeterReadGasResponseDto periodicMeterReadsContainerDto = new PeriodicMeterReadGasResponseDto(periodType, meterReads);
// actual mapping
final PeriodicMeterReadsContainerGas periodicMeterReadsContainerGas = this.monitoringMapper.map(periodicMeterReadsContainerDto, PeriodicMeterReadsContainerGas.class);
// test mapping
assertThat(periodicMeterReadsContainerGas).withFailMessage("Mapping must take place. So the result cannot be null.").isNotNull();
assertThat(periodicMeterReadsContainerGas.getPeriodType().name()).withFailMessage("After the mapping the name of the period must be the same.").isEqualTo(periodicMeterReadsContainerDto.getPeriodType().name());
assertThat(periodicMeterReadsContainerGas.getPeriodicMeterReadsGas().size()).withFailMessage("The number of periodic meter reads before and after the mapping must be equal.").isEqualTo(periodicMeterReadsContainerDto.getPeriodicMeterReadsGas().size());
assertThat(periodicMeterReadsContainerGas.getPeriodicMeterReadsGas().get(0).getLogTime()).withFailMessage("After the mapping the log time of the first entry must be the same.").isEqualTo(periodicMeterReadsContainerDto.getPeriodicMeterReadsGas().get(0).getLogTime());
assertThat(periodicMeterReadsContainerGas.getPeriodicMeterReadsGas().get(0).getCaptureTime()).withFailMessage("After the mapping the capture time of the first entry must be the same.").isEqualTo(periodicMeterReadsContainerDto.getPeriodicMeterReadsGas().get(0).getCaptureTime());
assertThat(periodicMeterReadsContainerGas.getPeriodicMeterReadsGas().get(0).getConsumption().getValue()).withFailMessage("After the mapping the consumption must be equal.").isEqualTo(new BigDecimal("1.0"));
assertThat(periodicMeterReadsContainerGas.getPeriodicMeterReadsGas().get(0).getConsumption().getOsgpUnit()).withFailMessage("After the mapping the osgp unit value must be the same.").isEqualTo(OsgpUnit.M3);
assertThat(periodicMeterReadsContainerGas.getPeriodicMeterReadsGas().get(0).getAmrProfileStatusCode().getAmrProfileStatusCodeFlags().size()).withFailMessage("After the mapping the size of the arm profile status code flags must be the same.").isEqualTo(periodicMeterReadsContainerDto.getPeriodicMeterReadsGas().get(0).getAmrProfileStatusCode().getAmrProfileStatusCodeFlags().size());
assertThat(periodicMeterReadsContainerGas.getPeriodicMeterReadsGas().get(0).getAmrProfileStatusCode().getAmrProfileStatusCodeFlags().contains(AmrProfileStatusCodeFlag.CRITICAL_ERROR)).withFailMessage("After the mapping the amr profile status code flags must contain the CRITICAL_ERROR flag.").isTrue();
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto in project open-smart-grid-platform by OSGP.
the class DlmsHelper method getScaledMeterValue.
public DlmsMeterValueDto getScaledMeterValue(final DataObject value, final DataObject scalerUnitObject, final String description) throws ProtocolAdapterException {
LOGGER.debug(this.getDebugInfo(value));
LOGGER.debug(this.getDebugInfo(scalerUnitObject));
final Long rawValue = this.readLong(value, description);
if (rawValue == null) {
return null;
}
if (!scalerUnitObject.isComplex()) {
throw new ProtocolAdapterException("complex data (structure) expected while retrieving scaler and unit." + this.getDebugInfo(scalerUnitObject));
}
final List<DataObject> dataObjects = scalerUnitObject.getValue();
if (dataObjects.size() != 2) {
throw new ProtocolAdapterException("expected 2 values while retrieving scaler and unit." + this.getDebugInfo(scalerUnitObject));
}
final int scaler = this.readLongNotNull(dataObjects.get(0), description).intValue();
final DlmsUnitTypeDto unit = DlmsUnitTypeDto.getUnitType(this.readLongNotNull(dataObjects.get(1), description).intValue());
// determine value
BigDecimal scaledValue = BigDecimal.valueOf(rawValue);
if (scaler != 0) {
scaledValue = scaledValue.multiply(BigDecimal.valueOf(Math.pow(10, scaler)));
}
return new DlmsMeterValueDto(scaledValue, unit);
}
Aggregations