diff options
Diffstat (limited to 'cps-ncmp-service')
9 files changed, 102 insertions, 76 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/NcmpCachedResourceRequestHandler.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/NcmpCachedResourceRequestHandler.java index 2d33234478..1b5dd2f853 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/NcmpCachedResourceRequestHandler.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/NcmpCachedResourceRequestHandler.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2022-2024 Nordix Foundation + * Copyright (C) 2022-2025 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,7 +47,8 @@ public class NcmpCachedResourceRequestHandler extends NcmpDatastoreRequestHandle */ public Collection<DataNode> executeRequest(final String cmHandleId, final String resourceIdentifier, final boolean includeDescendants) { - final FetchDescendantsOption fetchDescendantsOption = getFetchDescendantsOption(includeDescendants); + final FetchDescendantsOption fetchDescendantsOption + = FetchDescendantsOption.getFetchDescendantsOption(includeDescendants); return networkCmProxyQueryService.queryResourceDataOperational(cmHandleId, resourceIdentifier, fetchDescendantsOption); } @@ -59,7 +60,8 @@ public class NcmpCachedResourceRequestHandler extends NcmpDatastoreRequestHandle final String requestId, final boolean includeDescendants, final String authorization) { - final FetchDescendantsOption fetchDescendantsOption = getFetchDescendantsOption(includeDescendants); + final FetchDescendantsOption fetchDescendantsOption + = FetchDescendantsOption.getFetchDescendantsOption(includeDescendants); final DataNode dataNode = cpsDataService.getDataNodes(cmResourceAddress.getDatastoreName(), cmResourceAddress.resolveCmHandleReferenceToId(), @@ -68,8 +70,4 @@ public class NcmpCachedResourceRequestHandler extends NcmpDatastoreRequestHandle return Mono.justOrEmpty(dataNode); } - private static FetchDescendantsOption getFetchDescendantsOption(final boolean includeDescendants) { - return includeDescendants ? FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS - : FetchDescendantsOption.OMIT_DESCENDANTS; - } } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/WriteRequestExaminer.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/WriteRequestExaminer.java index 429a3790d4..f200aa2ad7 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/WriteRequestExaminer.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/WriteRequestExaminer.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2024 Nordix Foundation + * Copyright (C) 2024-2025 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,8 +21,8 @@ package org.onap.cps.ncmp.impl.datajobs; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; -import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import lombok.RequiredArgsConstructor; @@ -31,7 +31,9 @@ import org.onap.cps.ncmp.api.datajobs.models.DataJobWriteRequest; import org.onap.cps.ncmp.api.datajobs.models.DmiWriteOperation; import org.onap.cps.ncmp.api.datajobs.models.ProducerKey; import org.onap.cps.ncmp.api.datajobs.models.WriteOperation; -import org.onap.cps.ncmp.impl.inventory.models.YangModelCmHandle; +import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle; +import org.onap.cps.ncmp.impl.dmi.DmiServiceNameResolver; +import org.onap.cps.ncmp.impl.inventory.ParameterizedCmHandleQueryService; import org.onap.cps.ncmp.impl.models.RequiredDmiService; import org.onap.cps.ncmp.impl.utils.AlternateIdMatcher; import org.springframework.stereotype.Service; @@ -42,6 +44,7 @@ import org.springframework.stereotype.Service; public class WriteRequestExaminer { private final AlternateIdMatcher alternateIdMatcher; + private final ParameterizedCmHandleQueryService parameterizedCmHandleQueryService; private static final String PATH_SEPARATOR = "/"; /** @@ -52,25 +55,35 @@ public class WriteRequestExaminer { * @return {@code Map} map of Dmi Write Operations per Producer Key */ public Map<ProducerKey, List<DmiWriteOperation>> splitDmiWriteOperationsFromRequest( - final String dataJobId, - final DataJobWriteRequest dataJobWriteRequest) { + final String dataJobId, final DataJobWriteRequest dataJobWriteRequest) { final Map<ProducerKey, List<DmiWriteOperation>> dmiWriteOperationsPerProducerKey = new HashMap<>(); + final Map<String, NcmpServiceCmHandle> cmHandlePerAlternateId = getAllNcmpServiceCmHandlesWithoutProperties(); for (final WriteOperation writeOperation : dataJobWriteRequest.data()) { - examineWriteOperation(dataJobId, dmiWriteOperationsPerProducerKey, writeOperation); + examineWriteOperation(dataJobId, dmiWriteOperationsPerProducerKey, writeOperation, cmHandlePerAlternateId); } return dmiWriteOperationsPerProducerKey; } + private Map<String, NcmpServiceCmHandle> getAllNcmpServiceCmHandlesWithoutProperties() { + final Map<String, NcmpServiceCmHandle> ncmpServiceCmHandles = new HashMap<>(); + for (final NcmpServiceCmHandle ncmpServiceCmHandle + : parameterizedCmHandleQueryService.getAllCmHandlesWithoutProperties()) { + ncmpServiceCmHandles.put(ncmpServiceCmHandle.getAlternateId(), ncmpServiceCmHandle); + } + return ncmpServiceCmHandles; + } + private void examineWriteOperation(final String dataJobId, final Map<ProducerKey, List<DmiWriteOperation>> dmiWriteOperationsPerProducerKey, - final WriteOperation writeOperation) { + final WriteOperation writeOperation, + final Map<String, NcmpServiceCmHandle> cmHandlePerAlternateId) { log.debug("data job id for write operation is: {}", dataJobId); - final YangModelCmHandle yangModelCmHandle = alternateIdMatcher - .getYangModelCmHandleByLongestMatchingAlternateId(writeOperation.path(), PATH_SEPARATOR); + final NcmpServiceCmHandle ncmpServiceCmHandle = alternateIdMatcher + .getCmHandleByLongestMatchingAlternateId(writeOperation.path(), PATH_SEPARATOR, cmHandlePerAlternateId); - final DmiWriteOperation dmiWriteOperation = createDmiWriteOperation(writeOperation, yangModelCmHandle); + final DmiWriteOperation dmiWriteOperation = createDmiWriteOperation(writeOperation, ncmpServiceCmHandle); - final ProducerKey producerKey = createProducerKey(yangModelCmHandle); + final ProducerKey producerKey = createProducerKey(ncmpServiceCmHandle); final List<DmiWriteOperation> dmiWriteOperations; if (dmiWriteOperationsPerProducerKey.containsKey(producerKey)) { dmiWriteOperations = dmiWriteOperationsPerProducerKey.get(producerKey); @@ -81,27 +94,20 @@ public class WriteRequestExaminer { dmiWriteOperations.add(dmiWriteOperation); } - private ProducerKey createProducerKey(final YangModelCmHandle yangModelCmHandle) { - return new ProducerKey(yangModelCmHandle.resolveDmiServiceName(RequiredDmiService.DATA), - yangModelCmHandle.getDataProducerIdentifier()); + private ProducerKey createProducerKey(final NcmpServiceCmHandle ncmpServiceCmHandle) { + final String dmiDataServiceName = + DmiServiceNameResolver.resolveDmiServiceName(RequiredDmiService.DATA, ncmpServiceCmHandle); + return new ProducerKey(dmiDataServiceName, ncmpServiceCmHandle.getDataProducerIdentifier()); } private DmiWriteOperation createDmiWriteOperation(final WriteOperation writeOperation, - final YangModelCmHandle yangModelCmHandle) { + final NcmpServiceCmHandle ncmpServiceCmHandle) { return new DmiWriteOperation( writeOperation.path(), writeOperation.op(), - yangModelCmHandle.getModuleSetTag(), + ncmpServiceCmHandle.getModuleSetTag(), writeOperation.value(), writeOperation.operationId(), - getPrivatePropertiesFromDataNode(yangModelCmHandle)); + Collections.emptyMap()); // TODO: Private properties will be removed as part of CPS-2693. } - - private Map<String, String> getPrivatePropertiesFromDataNode(final YangModelCmHandle yangModelCmHandle) { - final Map<String, String> cmHandleDmiProperties = new LinkedHashMap<>(); - yangModelCmHandle.getDmiProperties() - .forEach(dmiProperty -> cmHandleDmiProperties.put(dmiProperty.getName(), dmiProperty.getValue())); - return cmHandleDmiProperties; - } - } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImpl.java index 8b6934b54c..74e862691a 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImpl.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImpl.java @@ -26,6 +26,7 @@ import static org.onap.cps.ncmp.impl.inventory.NcmpPersistence.NCMP_DATASPACE_NA import static org.onap.cps.ncmp.impl.inventory.NcmpPersistence.NCMP_DMI_REGISTRY_ANCHOR; import static org.onap.cps.ncmp.impl.inventory.NcmpPersistence.NCMP_DMI_REGISTRY_PARENT; +import com.hazelcast.map.IMap; import java.util.Collection; import java.util.Collections; import java.util.HashSet; @@ -62,7 +63,7 @@ public class CmHandleQueryServiceImpl implements CmHandleQueryService { private final Map<String, TrustLevel> trustLevelPerDmiPlugin; @Qualifier(TrustLevelCacheConfig.TRUST_LEVEL_PER_CM_HANDLE) - private final Map<String, TrustLevel> trustLevelPerCmHandleId; + private final IMap<String, TrustLevel> trustLevelPerCmHandleId; private final CpsValidator cpsValidator; @@ -152,14 +153,15 @@ public class CmHandleQueryServiceImpl implements CmHandleQueryService { final TrustLevel dmiTrustLevel = mapEntry.getValue(); final Collection<String> candidateCmHandleIds = getCmHandleReferencesByDmiPluginIdentifier( dmiPluginIdentifier, false); - for (final String candidateCmHandleId : candidateCmHandleIds) { - final TrustLevel candidateCmHandleTrustLevel = trustLevelPerCmHandleId.get(candidateCmHandleId); - final TrustLevel effectiveTrustlevel = - candidateCmHandleTrustLevel.getEffectiveTrustLevel(dmiTrustLevel); - if (targetTrustLevel.equals(effectiveTrustlevel)) { - selectedCmHandleReferences.add(candidateCmHandleId); + final Set<String> candidateCmHandleIdsSet = new HashSet<>(candidateCmHandleIds); + final Map<String, TrustLevel> trustLevelPerCmHandleIdInBatch = + trustLevelPerCmHandleId.getAll(candidateCmHandleIdsSet); + trustLevelPerCmHandleIdInBatch.forEach((cmHandleId, trustLevel) -> { + final TrustLevel effectiveTrustLevel = trustLevel.getEffectiveTrustLevel(dmiTrustLevel); + if (targetTrustLevel.equals(effectiveTrustLevel)) { + selectedCmHandleReferences.add(cmHandleId); } - } + }); } if (outputAlternateId) { return getAlternateIdsByCmHandleIds(selectedCmHandleReferences); diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryService.java index 3db4920d3e..fc8884433c 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryService.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryService.java @@ -75,4 +75,14 @@ public interface ParameterizedCmHandleQueryService { * @return collection of cm handles */ Collection<NcmpServiceCmHandle> getAllCmHandles(); + + /** + * Retrieves all {@code NcmpServiceCmHandle} instances without their associated properties. + * This method fetches the relevant data nodes from the inventory persistence layer and + * converts them into {@code NcmpServiceCmHandle} objects. Only the handles are returned, + * without any additional properties. + * + * @return a collection of {@code NcmpServiceCmHandle} instances without properties. + */ + Collection<NcmpServiceCmHandle> getAllCmHandlesWithoutProperties(); } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryServiceImpl.java index 4c1032efad..c44234d28c 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryServiceImpl.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryServiceImpl.java @@ -97,7 +97,16 @@ public class ParameterizedCmHandleQueryServiceImpl implements ParameterizedCmHan @Override public Collection<NcmpServiceCmHandle> getAllCmHandles() { - final DataNode dataNode = inventoryPersistence.getDataNode(NCMP_DMI_REGISTRY_PARENT).iterator().next(); + return toNcmpServiceCmHandles(inventoryPersistence.getDataNode(NCMP_DMI_REGISTRY_PARENT)); + } + + @Override + public Collection<NcmpServiceCmHandle> getAllCmHandlesWithoutProperties() { + return toNcmpServiceCmHandles(inventoryPersistence.getDataNode(NCMP_DMI_REGISTRY_PARENT, DIRECT_CHILDREN_ONLY)); + } + + private Collection<NcmpServiceCmHandle> toNcmpServiceCmHandles(final Collection<DataNode> dataNodes) { + final DataNode dataNode = dataNodes.iterator().next(); return dataNode.getChildDataNodes().stream().map(this::createNcmpServiceCmHandle).collect(Collectors.toSet()); } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/utils/AlternateIdMatcher.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/utils/AlternateIdMatcher.java index 750a5050f2..b8e4e7feda 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/utils/AlternateIdMatcher.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/utils/AlternateIdMatcher.java @@ -20,12 +20,12 @@ package org.onap.cps.ncmp.impl.utils; +import java.util.Map; import lombok.RequiredArgsConstructor; import org.apache.commons.lang3.StringUtils; -import org.onap.cps.ncmp.api.exceptions.CmHandleNotFoundException; +import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle; import org.onap.cps.ncmp.exceptions.NoAlternateIdMatchFoundException; import org.onap.cps.ncmp.impl.inventory.InventoryPersistence; -import org.onap.cps.ncmp.impl.inventory.models.YangModelCmHandle; import org.onap.cps.utils.CpsValidator; import org.springframework.stereotype.Service; @@ -37,24 +37,26 @@ public class AlternateIdMatcher { private final CpsValidator cpsValidator; /** - * Get yang model cm handle that matches longest alternate id by removing elements + * Get cm handle that matches longest alternate id by removing elements * (as defined by the separator string) from right to left. * If alternate id contains a hash then all elements after that hash are ignored. * - * @param alternateId alternate ID - * @param separator a string that separates each element from the next. - * @return yang model cm handle + * @param alternateId alternate ID + * @param separator a string that separates each element from the next. + * @param cmHandlePerAlternateId all CM-handles by alternate ID + * @return ncmp service cm handle */ - public YangModelCmHandle getYangModelCmHandleByLongestMatchingAlternateId(final String alternateId, - final String separator) { + public NcmpServiceCmHandle getCmHandleByLongestMatchingAlternateId( + final String alternateId, final String separator, + final Map<String, NcmpServiceCmHandle> cmHandlePerAlternateId) { final String[] splitPath = alternateId.split("#", 2); String bestMatch = splitPath[0]; while (StringUtils.isNotEmpty(bestMatch)) { - try { - return inventoryPersistence.getYangModelCmHandleByAlternateId(bestMatch); - } catch (final CmHandleNotFoundException ignored) { - bestMatch = getParentPath(bestMatch, separator); + final NcmpServiceCmHandle ncmpServiceCmHandle = cmHandlePerAlternateId.get(bestMatch); + if (ncmpServiceCmHandle != null) { + return ncmpServiceCmHandle; } + bestMatch = getParentPath(bestMatch, separator); } throw new NoAlternateIdMatchFoundException(alternateId); } diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/WriteRequestExaminerSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/WriteRequestExaminerSpec.groovy index 6aa84d1c7f..d051927b3d 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/WriteRequestExaminerSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/WriteRequestExaminerSpec.groovy @@ -23,24 +23,27 @@ package org.onap.cps.ncmp.impl.datajobs import org.onap.cps.ncmp.api.datajobs.models.DataJobWriteRequest import org.onap.cps.ncmp.api.datajobs.models.WriteOperation import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle -import org.onap.cps.ncmp.impl.inventory.models.YangModelCmHandle +import org.onap.cps.ncmp.impl.inventory.ParameterizedCmHandleQueryService import org.onap.cps.ncmp.impl.utils.AlternateIdMatcher import spock.lang.Specification class WriteRequestExaminerSpec extends Specification { def mockAlternateIdMatcher = Mock(AlternateIdMatcher) - def objectUnderTest = new WriteRequestExaminer(mockAlternateIdMatcher) + def mockParameterizedCmHandleQueryService = Mock(ParameterizedCmHandleQueryService) + def objectUnderTest = new WriteRequestExaminer(mockAlternateIdMatcher, mockParameterizedCmHandleQueryService) def setup() { - def ch1 = new YangModelCmHandle(id: 'ch1', dmiServiceName: 'dmiA', dataProducerIdentifier: 'p1', dmiProperties: []) - def ch2 = new YangModelCmHandle(id: 'ch2', dmiServiceName: 'dmiA', dataProducerIdentifier: 'p1', dmiProperties: []) - def ch3 = new YangModelCmHandle(id: 'ch3', dmiServiceName: 'dmiA', dataProducerIdentifier: 'p2', dmiProperties: []) - def ch4 = new YangModelCmHandle(id: 'ch4', dmiServiceName: 'dmiB', dataProducerIdentifier: 'p1', dmiProperties: []) - mockAlternateIdMatcher.getYangModelCmHandleByLongestMatchingAlternateId('fdn1', '/') >> ch1 - mockAlternateIdMatcher.getYangModelCmHandleByLongestMatchingAlternateId('fdn2', '/') >> ch2 - mockAlternateIdMatcher.getYangModelCmHandleByLongestMatchingAlternateId('fdn3', '/') >> ch3 - mockAlternateIdMatcher.getYangModelCmHandleByLongestMatchingAlternateId('fdn4', '/') >> ch4 + def ch1 = new NcmpServiceCmHandle(cmHandleId: 'ch1', dmiServiceName: 'dmiA', moduleSetTag: 'someModuleSetTag', alternateId: 'fdn1', dataProducerIdentifier: 'p1') + def ch2 = new NcmpServiceCmHandle(cmHandleId: 'ch2', dmiServiceName: 'dmiA', moduleSetTag: 'someModuleSetTag', alternateId: 'fdn2', dataProducerIdentifier: 'p1') + def ch3 = new NcmpServiceCmHandle(cmHandleId: 'ch3', dmiServiceName: 'dmiA', moduleSetTag: 'someModuleSetTag', alternateId: 'fdn3', dataProducerIdentifier: 'p2') + def ch4 = new NcmpServiceCmHandle(cmHandleId: 'ch4', dmiServiceName: 'dmiB', moduleSetTag: 'someModuleSetTag', alternateId: 'fdn4', dataProducerIdentifier: 'p1') + def cmHandlePerAlternateId = ['fdn1': ch1, 'fdn2': ch2, 'fdn3': ch3, 'fdn4': ch4] + mockAlternateIdMatcher.getCmHandleByLongestMatchingAlternateId('fdn1', '/', cmHandlePerAlternateId) >> ch1 + mockAlternateIdMatcher.getCmHandleByLongestMatchingAlternateId('fdn2', '/', cmHandlePerAlternateId) >> ch2 + mockAlternateIdMatcher.getCmHandleByLongestMatchingAlternateId('fdn3', '/', cmHandlePerAlternateId) >> ch3 + mockAlternateIdMatcher.getCmHandleByLongestMatchingAlternateId('fdn4', '/', cmHandlePerAlternateId) >> ch4 + mockParameterizedCmHandleQueryService.getAllCmHandlesWithoutProperties() >> [ch1, ch2, ch3, ch4] } def 'Create a map of dmi write requests per producer key with #scenario.'() { @@ -83,9 +86,9 @@ class WriteRequestExaminerSpec extends Specification { def 'Validate the creation of a ProducerKey with correct dmiservicename.'() { given: 'yangModelCmHandles with service name: "#dmiServiceName" and data service name: "#dataServiceName"' - def yangModelCmHandle = YangModelCmHandle.toYangModelCmHandle(dmiServiceName, dataServiceName, '', new NcmpServiceCmHandle(cmHandleId: 'cm-handle-id-1'), '', '', 'dpi1') + def ncmpServiceCmHandle = new NcmpServiceCmHandle(dmiServiceName: dmiServiceName, dmiDataServiceName: dataServiceName, dataProducerIdentifier: 'dpi1') when: 'the ProducerKey is created' - def result = objectUnderTest.createProducerKey(yangModelCmHandle).toString() + def result = objectUnderTest.createProducerKey(ncmpServiceCmHandle).toString() then: 'we get the ProducerKey with the correct service name' assert result == expectedProducerKey where: 'the following services are registered' diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImplSpec.groovy index 6ac42db782..12e4d6b85d 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImplSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImplSpec.groovy @@ -241,7 +241,7 @@ class CmHandleQueryServiceImplSpec extends Specification { mockCpsQueryService.queryDataLeaf(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, '/dmi-registry/cm-handles[@dmi-data-service-name=\'my-dmi-plugin-identifier\']/@alternate-id', _) >> [pnfDemo.getLeaves().get('alternate-id'), pnfDemo4.getLeaves().get('alternate-id')] mockCpsQueryService.queryDataLeaf(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, '/dmi-registry/cm-handles[@dmi-model-service-name=\'my-dmi-plugin-identifier\']/@alternate-id', _) >> [pnfDemo2.getLeaves().get('alternate-id'), pnfDemo4.getLeaves().get('alternate-id')] mockCpsQueryService.queryDataLeaf(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, '/dmi-registry/cm-handles[@id=\'PNFDemo\']/@alternate-id', _) >> [pnfDemo.getLeaves().get('alternate-id')] - mockCpsQueryService.queryDataLeaf(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, '/dmi-registry/cm-handles[@id=\'PNFDemo2\' or @id=\'PNFDemo\' or @id=\'PNFDemo4\']/@alternate-id', _) >> [pnfDemo2.getLeaves().get('alternate-id'), pnfDemo.getLeaves().get('alternate-id'), pnfDemo4.getLeaves().get('alternate-id')] + mockCpsQueryService.queryDataLeaf(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, '/dmi-registry/cm-handles[@id=\'PNFDemo2\' or @id=\'PNFDemo4\' or @id=\'PNFDemo\']/@alternate-id', _) >> [pnfDemo2.getLeaves().get('alternate-id'), pnfDemo.getLeaves().get('alternate-id'), pnfDemo4.getLeaves().get('alternate-id')] mockCpsQueryService.queryDataLeaf(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, '//public-properties[@name=\'Contact\' and @value=\'newemailforstore@bookstore.com\']/ancestor::cm-handles/@id',_) >> [pnfDemo.getLeaves().get('id'), pnfDemo2.getLeaves().get('id'), pnfDemo4.getLeaves().get('id')] mockCpsQueryService.queryDataLeaf(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, '//public-properties[@name=\'Contact\' and @value=\'newemailforstore@bookstore.com\']/ancestor::cm-handles/@alternate-id',_) >> [pnfDemo.getLeaves().get('alternate-id'), pnfDemo2.getLeaves().get('alternate-id'), pnfDemo4.getLeaves().get('alternate-id')] diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/utils/AlternateIdMatcherSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/utils/AlternateIdMatcherSpec.groovy index b59dd1a55f..098e88a644 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/utils/AlternateIdMatcherSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/utils/AlternateIdMatcherSpec.groovy @@ -20,7 +20,7 @@ package org.onap.cps.ncmp.impl.utils -import org.onap.cps.ncmp.api.exceptions.CmHandleNotFoundException +import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle import org.onap.cps.ncmp.exceptions.NoAlternateIdMatchFoundException import org.onap.cps.ncmp.impl.inventory.InventoryPersistence import org.onap.cps.ncmp.impl.inventory.models.YangModelCmHandle @@ -37,16 +37,12 @@ class AlternateIdMatcherSpec extends Specification { def objectUnderTest = new AlternateIdMatcher(mockInventoryPersistence, new CpsValidatorImpl()) - def setup() { - given: 'cm handle in the registry with alternate id /a/b' - mockInventoryPersistence.getYangModelCmHandleByAlternateId('/a/b') >> new YangModelCmHandle() - and: 'no other cm handle' - mockInventoryPersistence.getYangModelCmHandleByAlternateId(_) >> { throw new CmHandleNotFoundException('') } - } - def 'Finding longest alternate id matches.'() { + given: 'a cm handle with alternate id /a/b in the cached map of all cm handles' + def ch1 = new NcmpServiceCmHandle(cmHandleId: 'ch1', alternateId: '/a/b') + def cmHandlePerAlternateId = ['/a/b': ch1] expect: 'querying for alternate id a matching result found' - assert objectUnderTest.getYangModelCmHandleByLongestMatchingAlternateId(targetAlternateId, '/') != null + assert objectUnderTest.getCmHandleByLongestMatchingAlternateId(targetAlternateId, '/', cmHandlePerAlternateId) != null where: 'the following parameters are used' scenario | targetAlternateId 'exact match' | '/a/b' @@ -61,7 +57,7 @@ class AlternateIdMatcherSpec extends Specification { def 'Attempt to find longest alternate id match without any matches.'() { when: 'attempt to find alternateId' - objectUnderTest.getYangModelCmHandleByLongestMatchingAlternateId(targetAlternateId, '/') + objectUnderTest.getCmHandleByLongestMatchingAlternateId(targetAlternateId, '/', [:]) then: 'no alternate id match found exception thrown' def thrown = thrown(NoAlternateIdMatchFoundException) and: 'the exception has the relevant details from the error response' |