DlmsObjectConfigService { public Optional<AttributeAddressForProfile> findAttributeAddressForProfile(final DlmsDevice device, final DlmsObjectType type, final Integer channel, final DateTime from, final DateTime to, final Medium filterMedium) { return this.findDlmsObject(Protocol.forDevice(device), type, filterMedium) .map(dlmsObject -> this.getAttributeAddressForProfile(new AddressRequest(device, dlmsObject, channel, from, to, filterMedium))); } @Autowired  DlmsObjectConfigService(final DlmsHelper dlmsHelper, final List<DlmsObjectConfig> dlmsObjectConfigs); Optional<AttributeAddress> findAttributeAddress(final DlmsDevice device, final DlmsObjectType type,
                                                           final Integer channel); Optional<AttributeAddressForProfile> findAttributeAddressForProfile(final DlmsDevice device,
                                                                               final DlmsObjectType type, final Integer channel, final DateTime from, final DateTime to,
                                                                               final Medium filterMedium); Optional<DlmsObject> findDlmsObject(final Protocol protocol, final DlmsObjectType type,
                                               final Medium filterMedium); List<AttributeAddress> getAttributeAddressesForScalerUnit(final AttributeAddressForProfile attributeAddressForProfile,
                                                                     final Integer channel);  }
@Test public void testProfileWithOneMedium() throws Exception { final Integer channel = null; final Medium filterMedium = Medium.ELECTRICITY; final DataObject selectedValues = DataObject.newArrayData(Collections.emptyList()); final DataObject accessParams = this.getAccessParams(selectedValues); final SelectiveAccessDescription access = new SelectiveAccessDescription(1, accessParams); final AttributeAddress expectedAddress = new AttributeAddress(this.profileE.getClassId(), this.profileE.getObisCodeAsString(), this.profileE.getDefaultAttributeId(), access); final Optional<AttributeAddressForProfile> attributeAddressForProfile = this.service .findAttributeAddressForProfile(this.device422, DlmsObjectType.INTERVAL_VALUES, channel, this.from, this.to, filterMedium); AttributeAddressAssert.is(attributeAddressForProfile.get() .getAttributeAddress(), expectedAddress); assertThat(attributeAddressForProfile.get() .getSelectedObjects()).isEqualTo(this.captureObjectsE); }
@Test public void testProfileWithMediumCombinedAndFilterMedium() throws Exception { final Integer channel = null; final Medium filterMedium = Medium.ELECTRICITY; final List<DlmsCaptureObject> expectedSelectedObjects = this.captureObjectsCombined.stream() .filter(c -> !(c.getRelatedObject() instanceof DlmsRegister) || ((DlmsRegister) c.getRelatedObject()).getMedium() == filterMedium) .collect(Collectors.toList()); final DataObject selectedValues = DataObject.newArrayData(expectedSelectedObjects.stream() .map(o -> this.getDataObject(o.getRelatedObject())) .collect(Collectors.toList())); final DataObject accessParams = this.getAccessParams(selectedValues); final SelectiveAccessDescription access = new SelectiveAccessDescription(1, accessParams); final AttributeAddress expectedAddress = new AttributeAddress(this.profileCombined.getClassId(), this.profileCombined.getObisCodeAsString(), this.profileCombined.getDefaultAttributeId(), access); final Optional<AttributeAddressForProfile> attributeAddressForProfile = this.service .findAttributeAddressForProfile(this.device422, DlmsObjectType.DAILY_LOAD_PROFILE, channel, this.from, this.to, filterMedium); AttributeAddressAssert.is(attributeAddressForProfile.get() .getAttributeAddress(), expectedAddress); assertThat(attributeAddressForProfile.get() .getSelectedObjects()).isEqualTo(expectedSelectedObjects); }
@Test public void testProfileWithMediumCombinedAndNoFilterMedium() throws Exception { final Integer channel = 1; final Medium filterMedium = null; final DataObject selectedValues = DataObject.newArrayData(Collections.emptyList()); final DataObject accessParams = this.getAccessParams(selectedValues); final SelectiveAccessDescription access = new SelectiveAccessDescription(1, accessParams); final AttributeAddress expectedAddress = new AttributeAddress(this.profileCombined.getClassId(), this.profileCombined.getObisCodeAsString(), this.profileCombined.getDefaultAttributeId(), access); final Optional<AttributeAddressForProfile> attributeAddressForProfile = this.service .findAttributeAddressForProfile(this.device422, DlmsObjectType.DAILY_LOAD_PROFILE, channel, this.from, this.to, filterMedium); AttributeAddressAssert.is(attributeAddressForProfile.get() .getAttributeAddress(), expectedAddress); assertThat(attributeAddressForProfile.get() .getSelectedObjects()).isEqualTo(this.captureObjectsCombined); }