aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryService.java10
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImpl.java101
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryServiceImpl.java54
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImplSpec.groovy52
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryServiceSpec.groovy4
5 files changed, 102 insertions, 119 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryService.java
index 9447f13b68..f1f71dc57c 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryService.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryService.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.
@@ -110,12 +110,4 @@ public interface CmHandleQueryService {
Collection<String> getCmHandleReferencesByDmiPluginIdentifier(String dmiPluginIdentifier,
boolean outputAlternateId);
- /**
- * Get map of cmHandle references by DMI plugin identifier.
- *
- * @param dmiPluginIdentifier DMI plugin identifier
- * @return map of cmHandle references key:CmHandleId Value:AlternateId
- */
- Map<String, String> getCmHandleReferencesMapByDmiPluginIdentifier(String dmiPluginIdentifier);
-
}
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 ae913ddfe7..770ada0a5f 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
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2022-2024 Nordix Foundation
+ * Copyright (C) 2022-2025 Nordix Foundation
* Modifications Copyright (C) 2023 TechMahindra Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -28,9 +28,9 @@ import static org.onap.cps.ncmp.impl.inventory.NcmpPersistence.NCMP_DMI_REGISTRY
import java.util.Collection;
import java.util.Collections;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.onap.cps.api.CpsDataService;
@@ -90,7 +90,8 @@ public class CmHandleQueryServiceImpl implements CmHandleQueryService {
@Override
public Collection<String> queryCmHandleIdsByState(final CmHandleState cmHandleState) {
final Collection<DataNode> cmHandlesAsDataNodes =
- queryNcmpRegistryByCpsPath("//state[@cm-handle-state='" + cmHandleState + "']", OMIT_DESCENDANTS);
+ queryNcmpRegistryByCpsPath("//state[@cm-handle-state='" + cmHandleState + "']",
+ OMIT_DESCENDANTS);
return cmHandlesAsDataNodes.stream()
.map(DataNode::getXpath)
.map(YangDataConverter::extractCmHandleIdFromXpath)
@@ -106,7 +107,7 @@ public class CmHandleQueryServiceImpl implements CmHandleQueryService {
@Override
public Collection<DataNode> queryCmHandleAncestorsByCpsPath(final String cpsPath,
- final FetchDescendantsOption fetchDescendantsOption) {
+ final FetchDescendantsOption fetchDescendantsOption) {
if (CpsPathUtil.getCpsPathQuery(cpsPath).getXpathPrefix().endsWith("/cm-handles")) {
return queryNcmpRegistryByCpsPath(cpsPath, fetchDescendantsOption);
}
@@ -128,84 +129,60 @@ public class CmHandleQueryServiceImpl implements CmHandleQueryService {
@Override
public Collection<String> getCmHandleReferencesByDmiPluginIdentifier(final String dmiPluginIdentifier,
- final boolean outputAlternateId) {
+ final boolean outputAlternateId) {
final Collection<String> cmHandleReferences = new HashSet<>();
for (final ModelledDmiServiceLeaves modelledDmiServiceLeaf : ModelledDmiServiceLeaves.values()) {
- for (final DataNode cmHandleAsDataNode: getCmHandlesByDmiPluginIdentifierAndDmiProperty(
- dmiPluginIdentifier,
- modelledDmiServiceLeaf.getLeafName())) {
- if (outputAlternateId) {
- cmHandleReferences.add(cmHandleAsDataNode.getLeaves().get(ALTERNATE_ID).toString());
- } else {
- cmHandleReferences.add(cmHandleAsDataNode.getLeaves().get("id").toString());
- }
- }
+ cmHandleReferences.addAll(getIdsByDmiPluginIdentifierAndDmiProperty(
+ dmiPluginIdentifier, modelledDmiServiceLeaf.getLeafName(), outputAlternateId));
}
return cmHandleReferences;
}
- @Override
- public Map<String, String> getCmHandleReferencesMapByDmiPluginIdentifier(final String dmiPluginIdentifier) {
- final Map<String, String> cmHandleReferencesMap = new HashMap<>();
- for (final ModelledDmiServiceLeaves modelledDmiServiceLeaf : ModelledDmiServiceLeaves.values()) {
- for (final DataNode cmHandleAsDataNode: getCmHandlesByDmiPluginIdentifierAndDmiProperty(
- dmiPluginIdentifier,
- modelledDmiServiceLeaf.getLeafName())) {
- cmHandleReferencesMap.put(cmHandleAsDataNode.getLeaves().get("id").toString(),
- cmHandleAsDataNode.getLeaves().get(ALTERNATE_ID).toString());
- }
- }
- return cmHandleReferencesMap;
- }
-
private Collection<String> getCmHandleReferencesByTrustLevel(final TrustLevel targetTrustLevel,
final boolean outputAlternateId) {
final Collection<String> selectedCmHandleReferences = new HashSet<>();
-
for (final Map.Entry<String, TrustLevel> mapEntry : trustLevelPerDmiPlugin.entrySet()) {
final String dmiPluginIdentifier = mapEntry.getKey();
final TrustLevel dmiTrustLevel = mapEntry.getValue();
- final Map<String, String> candidateCmHandleReferences =
- getCmHandleReferencesMapByDmiPluginIdentifier(dmiPluginIdentifier);
- for (final Map.Entry<String, String> candidateCmHandleReference : candidateCmHandleReferences.entrySet()) {
- final TrustLevel candidateCmHandleTrustLevel =
- trustLevelPerCmHandleId.get(candidateCmHandleReference.getKey());
+ final Collection<String> candidateCmHandleIds = getCmHandleReferencesByDmiPluginIdentifier(
+ dmiPluginIdentifier, false);
+ for (final String candidateCmHandleId : candidateCmHandleIds) {
+ final TrustLevel candidateCmHandleTrustLevel = trustLevelPerCmHandleId.get(candidateCmHandleId);
final TrustLevel effectiveTrustlevel =
- candidateCmHandleTrustLevel.getEffectiveTrustLevel(dmiTrustLevel);
+ candidateCmHandleTrustLevel.getEffectiveTrustLevel(dmiTrustLevel);
if (targetTrustLevel.equals(effectiveTrustlevel)) {
- if (outputAlternateId) {
- selectedCmHandleReferences.add(candidateCmHandleReference.getValue());
- } else {
- selectedCmHandleReferences.add(candidateCmHandleReference.getKey());
- }
+ selectedCmHandleReferences.add(candidateCmHandleId);
}
}
}
+ if (outputAlternateId) {
+ return getAlternateIdsByCmHandleIds(selectedCmHandleReferences);
+ }
return selectedCmHandleReferences;
}
private Collection<String> collectCmHandleReferencesFromDataNodes(final Collection<DataNode> dataNodes,
- final boolean outputAlternateId) {
+ final boolean outputAlternateId) {
if (outputAlternateId) {
return dataNodes.stream().map(dataNode ->
- (String) dataNode.getLeaves().get(ALTERNATE_ID)).collect(Collectors.toSet());
+ (String) dataNode.getLeaves().get(ALTERNATE_ID)).collect(Collectors.toSet());
} else {
return dataNodes.stream().map(dataNode ->
- (String) dataNode.getLeaves().get("id")).collect(Collectors.toSet());
+ (String) dataNode.getLeaves().get("id")).collect(Collectors.toSet());
}
}
private Collection<String> queryCmHandleAnyProperties(
- final Map<String, String> propertyQueryPairs,
- final PropertyType propertyType, final boolean outputAlternateId) {
+ final Map<String, String> propertyQueryPairs,
+ final PropertyType propertyType, final boolean outputAlternateId) {
if (propertyQueryPairs.isEmpty()) {
return Collections.emptySet();
}
Collection<String> cmHandleReferences = null;
for (final Map.Entry<String, String> publicPropertyQueryPair : propertyQueryPairs.entrySet()) {
final String cpsPath = DESCENDANT_PATH + propertyType.getYangContainerName() + "[@name=\""
- + publicPropertyQueryPair.getKey()
- + "\" and @value=\"" + publicPropertyQueryPair.getValue() + "\"]";
+ + publicPropertyQueryPair.getKey()
+ + "\" and @value=\"" + publicPropertyQueryPair.getValue() + "\"]";
final Collection<DataNode> dataNodes = queryCmHandleAncestorsByCpsPath(cpsPath,
OMIT_DESCENDANTS);
@@ -223,17 +200,35 @@ public class CmHandleQueryServiceImpl implements CmHandleQueryService {
return cmHandleReferences;
}
- private Collection<DataNode> getCmHandlesByDmiPluginIdentifierAndDmiProperty(final String dmiPluginIdentifier,
- final String dmiProperty) {
- return cpsQueryService.queryDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
- NCMP_DMI_REGISTRY_PARENT + "/cm-handles[@" + dmiProperty + "='" + dmiPluginIdentifier + "']",
- OMIT_DESCENDANTS);
+ private Set<String> getIdsByDmiPluginIdentifierAndDmiProperty(final String dmiPluginIdentifier,
+ final String dmiProperty,
+ final boolean outputAlternateId) {
+ final String attributeName = outputAlternateId ? ALTERNATE_ID : "id";
+ final String cpsPath = String.format("%s/cm-handles[@%s='%s']/@%s",
+ NCMP_DMI_REGISTRY_PARENT, dmiProperty, dmiPluginIdentifier, attributeName);
+ return cpsQueryService.queryDataLeaf(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, cpsPath, String.class);
+ }
+
+ private Collection<String> getAlternateIdsByCmHandleIds(final Collection<String> cmHandleIds) {
+
+ final String cpsPath = NCMP_DMI_REGISTRY_PARENT + "/cm-handles["
+ + createFormattedQueryString(cmHandleIds) + "]/@alternate-id";
+
+ return cpsQueryService.queryDataLeaf(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, cpsPath, String.class);
+ }
+
+ private String createFormattedQueryString(final Collection<String> cmHandleIds) {
+ return cmHandleIds.stream()
+ .map(cmHandleId -> "@id='" + cmHandleId + "'")
+ .collect(Collectors.joining(" or "));
}
+
private DataNode getCmHandleState(final String cmHandleId) {
cpsValidator.validateNameCharacters(cmHandleId);
final String xpath = NCMP_DMI_REGISTRY_PARENT + "/cm-handles[@id='" + cmHandleId + "']/state";
return cpsDataService.getDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
xpath, OMIT_DESCENDANTS).iterator().next();
}
-}
+
+} \ No newline at end of file
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 428c6f6491..4c1032efad 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
@@ -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.
@@ -62,13 +62,13 @@ public class ParameterizedCmHandleQueryServiceImpl implements ParameterizedCmHan
@Override
public Collection<String> queryCmHandleReferenceIds(
- final CmHandleQueryServiceParameters cmHandleQueryServiceParameters,
- final boolean outputAlternateId) {
+ final CmHandleQueryServiceParameters cmHandleQueryServiceParameters,
+ final boolean outputAlternateId) {
return executeQueries(cmHandleQueryServiceParameters, outputAlternateId,
- this::executeCpsPathQuery,
- this::queryCmHandlesByPublicProperties,
- this::executeModuleNameQuery,
- this::queryCmHandlesByTrustLevel);
+ this::executeCpsPathQuery,
+ this::queryCmHandlesByPublicProperties,
+ this::executeModuleNameQuery,
+ this::queryCmHandlesByTrustLevel);
}
@Override
@@ -84,7 +84,7 @@ public class ParameterizedCmHandleQueryServiceImpl implements ParameterizedCmHan
@Override
public Collection<NcmpServiceCmHandle> queryCmHandles(
- final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
+ final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
if (cmHandleQueryServiceParameters.getCmHandleQueryParameters().isEmpty()) {
return getAllCmHandles();
@@ -111,15 +111,11 @@ public class ParameterizedCmHandleQueryServiceImpl implements ParameterizedCmHan
}
final String dmiPluginIdentifierValue = dmiPropertyQueryPairs
- .get(PropertyType.DMI_PLUGIN.getYangContainerName());
+ .get(PropertyType.DMI_PLUGIN.getYangContainerName());
+
+ return cmHandleQueryService.getCmHandleReferencesByDmiPluginIdentifier(
+ dmiPluginIdentifierValue, outputAlternateId);
- if (outputAlternateId) {
- return
- cmHandleQueryService.getCmHandleReferencesMapByDmiPluginIdentifier(dmiPluginIdentifierValue).values();
- } else {
- return cmHandleQueryService.getCmHandleReferencesByDmiPluginIdentifier(dmiPluginIdentifierValue,
- outputAlternateId);
- }
}
private Collection<String> queryCmHandlesByPrivateProperties(
@@ -175,7 +171,7 @@ public class ParameterizedCmHandleQueryServiceImpl implements ParameterizedCmHan
private Collection<String> executeCpsPathQuery(
final CmHandleQueryServiceParameters cmHandleQueryServiceParameters, final boolean outputAlternateId) {
final Map<String, String> cpsPathCondition
- = getCpsPathCondition(cmHandleQueryServiceParameters.getCmHandleQueryParameters());
+ = getCpsPathCondition(cmHandleQueryServiceParameters.getCmHandleQueryParameters());
if (!validateCpsPathConditionProperties(cpsPathCondition)) {
return Collections.emptySet();
}
@@ -185,8 +181,8 @@ public class ParameterizedCmHandleQueryServiceImpl implements ParameterizedCmHan
}
try {
cpsPathQueryResult = collectCmHandleReferencesFromDataNodes(
- cmHandleQueryService.queryCmHandleAncestorsByCpsPath(cpsPathCondition.get("cpsPath"), OMIT_DESCENDANTS),
- outputAlternateId);
+ cmHandleQueryService.queryCmHandleAncestorsByCpsPath(cpsPathCondition.get("cpsPath"),
+ OMIT_DESCENDANTS), outputAlternateId);
} catch (final PathParsingException pathParsingException) {
throw new DataValidationException(pathParsingException.getMessage(), pathParsingException.getDetails(),
pathParsingException);
@@ -211,7 +207,7 @@ public class ParameterizedCmHandleQueryServiceImpl implements ParameterizedCmHan
}
private Map<String, String> getPropertyPairs(final List<ConditionProperties> conditionProperties,
- final String queryProperty) {
+ final String queryProperty) {
final Map<String, String> result = new HashMap<>();
getConditions(conditionProperties, queryProperty).forEach(result::putAll);
return result;
@@ -229,18 +225,18 @@ public class ParameterizedCmHandleQueryServiceImpl implements ParameterizedCmHan
private Collection<String> getAllCmHandleReferences(final boolean outputAlternateId) {
final DataNode dataNode = inventoryPersistence.getDataNode(NCMP_DMI_REGISTRY_PARENT, DIRECT_CHILDREN_ONLY)
- .iterator().next();
+ .iterator().next();
return collectCmHandleReferencesFromDataNodes(dataNode.getChildDataNodes(), outputAlternateId);
}
private Collection<NcmpServiceCmHandle> getNcmpServiceCmHandles(final Collection<String> cmHandleIds) {
final Collection<YangModelCmHandle> yangModelcmHandles
- = inventoryPersistence.getYangModelCmHandles(cmHandleIds);
+ = inventoryPersistence.getYangModelCmHandles(cmHandleIds);
final Collection<NcmpServiceCmHandle> ncmpServiceCmHandles = new ArrayList<>(yangModelcmHandles.size());
yangModelcmHandles.forEach(yangModelcmHandle ->
- ncmpServiceCmHandles.add(YangDataConverter.toNcmpServiceCmHandle(yangModelcmHandle))
+ ncmpServiceCmHandles.add(YangDataConverter.toNcmpServiceCmHandle(yangModelcmHandle))
);
return ncmpServiceCmHandles;
}
@@ -252,15 +248,15 @@ public class ParameterizedCmHandleQueryServiceImpl implements ParameterizedCmHan
private Collection<String> executeQueries(final CmHandleQueryServiceParameters cmHandleQueryServiceParameters,
final boolean outputAlternateId,
final BiFunction<CmHandleQueryServiceParameters, Boolean,
- Collection<String>>... queryFunctions) {
+ Collection<String>>... queryFunctions) {
if (cmHandleQueryServiceParameters.getCmHandleQueryParameters().isEmpty()) {
return getAllCmHandleReferences(outputAlternateId);
}
Collection<String> combinedQueryResult = NO_QUERY_TO_EXECUTE;
for (final BiFunction<CmHandleQueryServiceParameters, Boolean,
- Collection<String>> queryFunction : queryFunctions) {
+ Collection<String>> queryFunction : queryFunctions) {
final Collection<String> queryResult = queryFunction.apply(cmHandleQueryServiceParameters,
- outputAlternateId);
+ outputAlternateId);
if (noEntriesFoundCanStopQuerying(queryResult)) {
return Collections.emptySet();
}
@@ -288,13 +284,13 @@ public class ParameterizedCmHandleQueryServiceImpl implements ParameterizedCmHan
}
private Collection<String> collectCmHandleReferencesFromDataNodes(final Collection<DataNode> dataNodes,
- final boolean outputAlternateId) {
+ final boolean outputAlternateId) {
if (outputAlternateId) {
return dataNodes.stream().map(dataNode ->
- (String) dataNode.getLeaves().get("alternate-id")).collect(Collectors.toSet());
+ (String) dataNode.getLeaves().get("alternate-id")).collect(Collectors.toSet());
} else {
return dataNodes.stream().map(dataNode ->
- (String) dataNode.getLeaves().get("id")).collect(Collectors.toSet());
+ (String) dataNode.getLeaves().get("id")).collect(Collectors.toSet());
}
}
}
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 1cbdc7beca..6e6116e409 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
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2022-2024 Nordix Foundation
+ * Copyright (C) 2022-2025 Nordix Foundation
* Modifications Copyright (C) 2023 TechMahindra Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -86,21 +86,21 @@ class CmHandleQueryServiceImplSpec extends Specification {
}
def 'Query cm handles on trust level'() {
- given: 'query properties for trust level COMPLETE'
- def trustLevelPropertyQueryPairs = ['trustLevel' : TrustLevel.COMPLETE.toString()]
+ given: 'query properties for #trustLevel'
+ def trustLevelPropertyQueryPairs = ['trustLevel' : trustLevel.toString()]
and: 'the dmi cache has been initialised and "knows" about my-dmi-plugin-identifier'
- trustLevelPerDmiPlugin.put('my-dmi-plugin-identifier', TrustLevel.COMPLETE)
+ trustLevelPerDmiPlugin.put('my-dmi-plugin-identifier', trustLevel)
and: 'the DataNodes queried for a given cpsPath are returned from the persistence service'
mockResponses()
when: 'the query is run'
def result = objectUnderTest.queryCmHandlesByTrustLevel(trustLevelPropertyQueryPairs, outputAlternateId)
then: 'the result contain trusted cmHandle reference'
- assert result.size() == 1
- assert result[0] == expectedCmHandleReference
+ assert result as Set == expectedCmHandleReference as Set
where: 'the following data is used'
- senario | outputAlternateId | expectedCmHandleReference
- 'output cmHandleId' | false | 'PNFDemo'
- 'output AlternateId' | true | 'alt-PNFDemo'
+ senario | outputAlternateId | expectedCmHandleReference | trustLevel || resultSize
+ 'output cmHandleId for trustLevel Complete' | false | ['PNFDemo'] | TrustLevel.COMPLETE || 1
+ 'output alternateId for trustLevel Complete'| true | ['alt-PNFDemo'] | TrustLevel.COMPLETE || 1
+ 'output alternateIds for trustLevel None' | true | ['alt-PNFDemo2', 'alt-PNFDemo', 'alt-PNFDemo4']| TrustLevel.NONE || 3
}
def 'Query CmHandles using empty public properties query pair.'() {
@@ -143,8 +143,8 @@ class CmHandleQueryServiceImplSpec extends Specification {
def cmHandleState = state
and: 'the persistence service returns a list of data nodes'
mockCpsDataService.getDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
- NCMP_DMI_REGISTRY_PARENT + '/cm-handles[@id=\'some-cm-handle\']/state',
- OMIT_DESCENDANTS) >> [new DataNode(leaves: ['cm-handle-state': 'READY'])]
+ NCMP_DMI_REGISTRY_PARENT + '/cm-handles[@id=\'some-cm-handle\']/state',
+ OMIT_DESCENDANTS) >> [new DataNode(leaves: ['cm-handle-state': 'READY'])]
when: 'cm handles are compared by state'
def result = objectUnderTest.cmHandleHasState('some-cm-handle', cmHandleState)
then: 'the returned result matches the expected result from the persistence service'
@@ -160,8 +160,8 @@ class CmHandleQueryServiceImplSpec extends Specification {
def cmHandleState = CmHandleState.READY
and: 'cps data service returns a list of data nodes'
mockCpsDataService.getDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
- NCMP_DMI_REGISTRY_PARENT + '/cm-handles[@id=\'some-cm-handle\']/state',
- OMIT_DESCENDANTS) >> [new DataNode(leaves: ['cm-handle-state': 'READY'])]
+ NCMP_DMI_REGISTRY_PARENT + '/cm-handles[@id=\'some-cm-handle\']/state',
+ OMIT_DESCENDANTS) >> [new DataNode(leaves: ['cm-handle-state': 'READY'])]
when: 'cm handles are fetched by state and id'
def result = objectUnderTest.getCmHandleState('some-cm-handle')
then: 'the returned result is a list of data nodes returned by cps data service'
@@ -200,8 +200,8 @@ class CmHandleQueryServiceImplSpec extends Specification {
def cpsPath = "//cm-handles[@alternate-id='1']"
and: 'cps data service returns a valid data node'
mockCpsQueryService.queryDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
- cpsPath, INCLUDE_ALL_DESCENDANTS)
- >> Arrays.asList(cmHandleDataNode)
+ cpsPath, INCLUDE_ALL_DESCENDANTS)
+ >> Arrays.asList(cmHandleDataNode)
when: 'get cm handles by cps path is invoked'
def result = objectUnderTest.queryCmHandleAncestorsByCpsPath(cpsPath, INCLUDE_ALL_DESCENDANTS)
then: 'the returned result is a list of data nodes returned by cps data service'
@@ -223,18 +223,8 @@ class CmHandleQueryServiceImplSpec extends Specification {
'output is for cm handle ids' | false || ['PNFDemo', 'PNFDemo2', 'PNFDemo4']
}
- def 'Get all alternateIds by dmi plugin identifier'() {
- given: 'the DataNodes queried for a given cpsPath are returned from the persistence service.'
- mockResponses()
- when: 'cm Handles are fetched for a given dmi plugin identifier'
- def result = objectUnderTest.getCmHandleReferencesMapByDmiPluginIdentifier('my-dmi-plugin-identifier').values()
- then: 'result is the correct size'
- assert result.size() == 3
- and: 'result contains the correct alternate Ids'
- assert result.containsAll('alt-PNFDemo', 'alt-PNFDemo2', 'alt-PNFDemo4')
- }
-
void mockResponses() {
+
mockCpsQueryService.queryDataNodes(_, _, '//public-properties[@name=\"Contact\" and @value=\"newemailforstore@bookstore.com\"]/ancestor::cm-handles', _) >> [pnfDemo, pnfDemo2, pnfDemo4]
mockCpsQueryService.queryDataNodes(_, _, '//public-properties[@name=\"wont_match\" and @value=\"wont_match\"]/ancestor::cm-handles', _) >> []
mockCpsQueryService.queryDataNodes(_, _, '//public-properties[@name=\"Contact2\" and @value=\"newemailforstore2@bookstore.com\"]/ancestor::cm-handles', _) >> [pnfDemo4]
@@ -244,6 +234,16 @@ class CmHandleQueryServiceImplSpec extends Specification {
mockCpsQueryService.queryDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, '/dmi-registry/cm-handles[@dmi-service-name=\'my-dmi-plugin-identifier\']', OMIT_DESCENDANTS) >> [pnfDemo, pnfDemo2]
mockCpsQueryService.queryDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, '/dmi-registry/cm-handles[@dmi-data-service-name=\'my-dmi-plugin-identifier\']', OMIT_DESCENDANTS) >> [pnfDemo, pnfDemo4]
mockCpsQueryService.queryDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, '/dmi-registry/cm-handles[@dmi-model-service-name=\'my-dmi-plugin-identifier\']', OMIT_DESCENDANTS) >> [pnfDemo2, pnfDemo4]
+
+ mockCpsQueryService.queryDataLeaf(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, '/dmi-registry/cm-handles[@dmi-service-name=\'my-dmi-plugin-identifier\']/@id', _) >> [pnfDemo.getLeaves().get('id'), pnfDemo2.getLeaves().get('id')]
+ mockCpsQueryService.queryDataLeaf(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, '/dmi-registry/cm-handles[@dmi-data-service-name=\'my-dmi-plugin-identifier\']/@id', _) >> [pnfDemo.getLeaves().get('id'), pnfDemo4.getLeaves().get('id')]
+ mockCpsQueryService.queryDataLeaf(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, '/dmi-registry/cm-handles[@dmi-model-service-name=\'my-dmi-plugin-identifier\']/@id', _) >> [pnfDemo2.getLeaves().get('id'), pnfDemo4.getLeaves().get('id')]
+
+ mockCpsQueryService.queryDataLeaf(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, '/dmi-registry/cm-handles[@dmi-service-name=\'my-dmi-plugin-identifier\']/@alternate-id', _) >> [pnfDemo.getLeaves().get('alternate-id'), pnfDemo2.getLeaves().get('alternate-id')]
+ 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')]
}
def static createDataNode(dataNodeId) {
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryServiceSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryServiceSpec.groovy
index bf6ea36d65..7ba2bdf1e3 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryServiceSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryServiceSpec.groovy
@@ -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.
@@ -206,7 +206,7 @@ class ParameterizedCmHandleQueryServiceSpec extends Specification {
def conditionProperties = createConditionProperties('cmHandleWithDmiPlugin', [['some-key': 'some-value']])
cmHandleQueryParameters.setCmHandleQueryParameters([conditionProperties])
and: 'the inventoryPersistence returns different CmHandleIds'
- partiallyMockedCmHandleQueries.getCmHandleReferencesMapByDmiPluginIdentifier(*_) >> [:]
+ partiallyMockedCmHandleQueries.getCmHandleReferencesByDmiPluginIdentifier(_,_) >> []
when: 'the query executed'
def result = objectUnderTestWithPartiallyMockedQueries.queryCmHandleIdsForInventory(cmHandleQueryParameters, true)
then: 'the expected number of results are returned.'