From 8f3103dd1eaf5d537cd085dd8fab5ef39d7d914d Mon Sep 17 00:00:00 2001 From: sourabh_sourabh Date: Mon, 8 Jul 2024 17:40:38 +0100 Subject: NCMP: NCMP search API fixed to handle cps path that is ancestor axis as well - Cps path builder is fixed to handle ancestor axis that is target as well while quering. Issue-ID: CPS-2308 Change-Id: Iaf215851ada17d21516ae83fa142ac77ff1c6c19 Signed-off-by: sourabh_sourabh --- .../org/onap/cps/cpspath/parser/CpsPathBuilder.java | 4 ++++ .../onap/cps/cpspath/parser/CpsPathQuerySpec.groovy | 19 ++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) (limited to 'cps-path-parser') diff --git a/cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathBuilder.java b/cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathBuilder.java index de261e64b3..0bb09235ff 100644 --- a/cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathBuilder.java +++ b/cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathBuilder.java @@ -165,6 +165,10 @@ public class CpsPathBuilder extends CpsPathBaseListener { cpsPathQuery.setContainerNames(containerNames); cpsPathQuery.setBooleanOperators(booleanOperators); cpsPathQuery.setComparativeOperators(comparativeOperators); + if (cpsPathQuery.hasAncestorAxis() && cpsPathQuery.getXpathPrefix() + .endsWith("/" + cpsPathQuery.getAncestorSchemaNodeIdentifier())) { + cpsPathQuery.setAncestorSchemaNodeIdentifier(""); + } return cpsPathQuery; } diff --git a/cps-path-parser/src/test/groovy/org/onap/cps/cpspath/parser/CpsPathQuerySpec.groovy b/cps-path-parser/src/test/groovy/org/onap/cps/cpspath/parser/CpsPathQuerySpec.groovy index ae7ee598ab..15f6b11823 100644 --- a/cps-path-parser/src/test/groovy/org/onap/cps/cpspath/parser/CpsPathQuerySpec.groovy +++ b/cps-path-parser/src/test/groovy/org/onap/cps/cpspath/parser/CpsPathQuerySpec.groovy @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2021-2023 Nordix Foundation + * Copyright (C) 2021-2024 Nordix Foundation * Modifications Copyright (C) 2023 TechMahindra Ltd * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -253,4 +253,21 @@ class CpsPathQuerySpec extends Specification { '/test[@name2="value2" and @name1="value1"]' || 'name2' | 'name1' } + def 'Ancestor axis matching prefix'() { + when: 'building a cps path query' + def result = parseXPathAndBuild(xpath) + then: 'ancestor axis is removed when same as prefix' + assert result.hasAncestorAxis() == expectAncestorAxis + where: 'the following xpaths are used' + xpath || expectAncestorAxis + '//abc/def/ancestor::abc' || true + '//abc/def/ancestor::def' || false + '//abc/def/ancestor::ef' || true + } + + def parseXPathAndBuild(xpath) { + def cpsPathBuilder = CpsPathUtil.getCpsPathBuilder(xpath) + cpsPathBuilder.build() + } + } -- cgit 1.2.3-korg