From 5452b5ea786a3e7def19c1f328c43ec264da38d5 Mon Sep 17 00:00:00 2001 From: emaclee Date: Wed, 21 Dec 2022 09:29:24 +0000 Subject: Add fix for posting nodes with xPath with '/' - YangUtils method changed from using REGEX to cps path parser - unit test added for cps path util Issue-ID: CPS-1433 Signed-off-by: emaclee Change-Id: Ibb9efdd09423f9bade4a4a557d7d9ed49aa44ef4 --- .../onap/cps/cpspath/parser/CpsPathUtilSpec.groovy | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'cps-path-parser/src/test') diff --git a/cps-path-parser/src/test/groovy/org/onap/cps/cpspath/parser/CpsPathUtilSpec.groovy b/cps-path-parser/src/test/groovy/org/onap/cps/cpspath/parser/CpsPathUtilSpec.groovy index 31c1ed4a3..d62f337b7 100644 --- a/cps-path-parser/src/test/groovy/org/onap/cps/cpspath/parser/CpsPathUtilSpec.groovy +++ b/cps-path-parser/src/test/groovy/org/onap/cps/cpspath/parser/CpsPathUtilSpec.groovy @@ -28,7 +28,7 @@ class CpsPathUtilSpec extends Specification { when: 'xpath with #scenario is parsed' def result = CpsPathUtil.getNormalizedXpath(xpath) then: 'normalized path uses single quotes for leave values' - result == "/parent/child[@common-leaf-name='123']" + assert result == "/parent/child[@common-leaf-name='123']" where: 'the following xpaths are used' scenario | xpath 'no quotes' | '/parent/child[@common-leaf-name=123]' @@ -40,7 +40,7 @@ class CpsPathUtilSpec extends Specification { when: 'a given xpath with #scenario is parsed' def result = CpsPathUtil.getNormalizedParentXpath(xpath) then: 'the result is the expected parent path' - result == expectedParentPath + assert result == expectedParentPath where: 'the following xpaths are used' scenario | xpath || expectedParentPath 'no child' | '/parent' || '' @@ -53,6 +53,22 @@ class CpsPathUtilSpec extends Specification { 'parent is list element using "' | '/parent/child[@id="x"]/grandChild' || "/parent/child[@id='x']" } + def 'Get node ID sequence for given xpath'() { + when: 'a given xpath with #scenario is parsed' + def result = CpsPathUtil.getXpathNodeIdSequence(xpath) + then: 'the result is the expected node ID sequence' + assert result == expectedNodeIdSequence + where: 'the following xpaths are used' + scenario | xpath || expectedNodeIdSequence + 'no child' | '/parent' || ["parent"] + 'child and parent' | '/parent/child' || ["parent","child"] + 'grand child' | '/parent/child/grandChild' || ["parent","child","grandChild"] + 'parent & top is list element' | '/parent[@id=1]/child' || ["parent","child"] + 'parent is list element' | '/parent/child[@id=1]/grandChild' || ["parent","child","grandChild"] + 'parent is list element with /' | "/parent/child[@id='a/b']/grandChild" || ["parent","child","grandChild"] + 'parent is list element with [' | "/parent/child[@id='a[b']/grandChild" || ["parent","child","grandChild"] + } + def 'Recognizing (absolute) xpaths to List elements'() { expect: 'check for list returns the correct values' assert CpsPathUtil.isPathToListElement(xpath) == expectList -- cgit 1.2.3-korg