use of org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationObjectDto in project open-smart-grid-platform by OSGP.
the class GetConfigurationObjectServiceSmr5 method getConfigurationObject.
@Override
ConfigurationObjectDto getConfigurationObject(final GetResult result) throws ProtocolAdapterException {
final DataObject resultData = result.getResultData();
if (resultData == null || !resultData.isBitString()) {
LOGGER.warn("Configuration object result data is not a BitString: {}", resultData);
throw new ProtocolAdapterException("Expected bit-string data as Configuration object result data, but got: " + (resultData == null ? "null" : resultData.getType()));
}
LOGGER.info("SMR5 Configuration object current BitString: {}", this.dlmsHelper.getDebugInfo(resultData));
final BitString bitString = resultData.getValue();
final byte[] flagByteArray = bitString.getBitString();
final List<ConfigurationFlagDto> configurationFlagDtos = this.toConfigurationFlags(flagByteArray);
final ConfigurationFlagsDto configurationFlagsDto = new ConfigurationFlagsDto(configurationFlagDtos);
return new ConfigurationObjectDto(configurationFlagsDto);
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationObjectDto in project open-smart-grid-platform by OSGP.
the class SetConfigurationObjectRequestMappingTest method testMappingWithEmptyList.
// Test if mapping with ConfigurationFlags with an empty list succeeds.
@Test
public void testMappingWithEmptyList() {
// build test data
final String deviceIdentification = "nr1";
final GprsOperationModeType gprsOperationModeType = GprsOperationModeType.ALWAYS_ON;
final ConfigurationFlags configurationFlags = new ConfigurationFlags(new ArrayList<>());
final ConfigurationObject configurationObject = new ConfigurationObject(gprsOperationModeType, configurationFlags);
final SetConfigurationObjectRequestData setConfigurationObjectRequestData = new SetConfigurationObjectRequestData(configurationObject);
// actual mapping
final SetConfigurationObjectRequest setConfigurationObjectRequest = new SetConfigurationObjectRequest(deviceIdentification, setConfigurationObjectRequestData);
final SetConfigurationObjectRequestDto setConfigurationObjectRequestDto = this.configurationMapper.map(setConfigurationObjectRequest, SetConfigurationObjectRequestDto.class);
// check values
assertThat(setConfigurationObjectRequestDto).isNotNull();
assertThat(setConfigurationObjectRequestDto.getDeviceIdentification()).isEqualTo(deviceIdentification);
final ConfigurationObjectDto configurationObjectDto = setConfigurationObjectRequestDto.getSetConfigurationObjectRequestData().getConfigurationObject();
assertThat(configurationObjectDto).isNotNull();
// Check if both configurationFlags instances have an empty list
assertThat(configurationObjectDto.getConfigurationFlags().getFlags()).isEmpty();
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationObjectDto in project open-smart-grid-platform by OSGP.
the class SetConfigurationObjectRequestMappingTest method checkSetConfigurationObjectRequestData.
// method to check values of all objects that are mapped when a
// SetConfigurationObjectRequest is mapped.
private void checkSetConfigurationObjectRequestData(final GprsOperationModeType gprsOperationModeType, final ConfigurationFlagType configurationFlagType, final ConfigurationFlags configurationFlags, final SetConfigurationObjectRequestDto setConfigurationObjectRequestDto) {
// check if SetConfigurationObjectRequesDataDto object is present
final SetConfigurationObjectRequestDataDto setConfigurationObjectRequestDataDto = setConfigurationObjectRequestDto.getSetConfigurationObjectRequestData();
assertThat(setConfigurationObjectRequestDto).isNotNull();
// check if ConfigurationObjectDto object is present
final ConfigurationObjectDto configurationObjectDto = setConfigurationObjectRequestDataDto.getConfigurationObject();
assertThat(configurationObjectDto).isNotNull();
// check the GprsOperationModeTypeDto value
final GprsOperationModeTypeDto gprsOperationModeTypeDto = configurationObjectDto.getGprsOperationMode();
assertThat(gprsOperationModeTypeDto.name()).isEqualTo(gprsOperationModeType.name());
// check if ConfigurationFlagsDto object is present, and if its List is
// of an equal size.
final ConfigurationFlagsDto configurationFlagsDto = configurationObjectDto.getConfigurationFlags();
assertThat(configurationFlagsDto).isNotNull();
assertThat(configurationFlagsDto.getFlags().size()).isEqualTo(configurationFlags.getFlags().size());
// check ConfigurationObjectFlagTypeDto value.
final ConfigurationFlagDto configurationFlagDto = configurationFlagsDto.getFlags().get(0);
final ConfigurationFlagTypeDto configurationFlagTypeDto = configurationFlagDto.getConfigurationFlagType();
assertThat(configurationFlagTypeDto.name()).isEqualTo(configurationFlagType.name());
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationObjectDto in project open-smart-grid-platform by OSGP.
the class GetConfigurationObjectResponseMappingTest method testMapConfigurationObjectDto.
@Test
public void testMapConfigurationObjectDto() {
final ConfigurationObjectDto dto = this.makeConfigurationObjectDto();
final ConfigurationObject result = this.mapper.map(dto, ConfigurationObject.class);
assertThat(result).withFailMessage("mapping ConfigurationObjectDto should not return null").isNotNull();
assertThat(result).withFailMessage("mapping ConfigurationObjectDto should return correct type").isOfAnyClassIn(ConfigurationObject.class);
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationObjectDto in project open-smart-grid-platform by OSGP.
the class GetConfigurationObjectResponseMappingTest method makeConfigurationObjectDto.
private ConfigurationObjectDto makeConfigurationObjectDto() {
final List<ConfigurationFlagDto> configurationFlags = new ArrayList<>();
configurationFlags.add(this.makeConfigurationFlagDto());
final ConfigurationFlagsDto flags = new ConfigurationFlagsDto(configurationFlags);
final ConfigurationObjectDto configObjectDto = new ConfigurationObjectDto(GprsOperationModeTypeDto.ALWAYS_ON, flags);
return configObjectDto;
}
Aggregations