From: niamhcore Date: Tue, 4 May 2021 08:52:19 +0000 (+0100) Subject: Fix ancestor cps path to recognize ancestor list value X-Git-Tag: 1.1.0~59 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=10f834104ead71661cff6823a79b9346169b79e1;p=cps.git Fix ancestor cps path to recognize ancestor list value Issue-ID: CPS-305 Signed-off-by: niamhcore Change-Id: I28f7f0c120a39190068a3192dccf0a1a6fbfeaf2 --- diff --git a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java index ab135fd3ae..343a0886b3 100644 --- a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java +++ b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java @@ -175,8 +175,8 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService final CpsPathQuery cpsPathQuery) { final Set ancestorXpath = new HashSet<>(); final var pattern = - Pattern.compile("(\\S*\\/" + cpsPathQuery.getAncestorSchemaNodeIdentifier() + REG_EX_FOR_OPTIONAL_LIST_INDEX - + "\\/\\S*"); + Pattern.compile("(\\S*\\/" + Pattern.quote(cpsPathQuery.getAncestorSchemaNodeIdentifier()) + + REG_EX_FOR_OPTIONAL_LIST_INDEX + "\\/\\S*"); for (final FragmentEntity fragmentEntity : fragmentEntities) { final var matcher = pattern.matcher(fragmentEntity.getXpath()); if (matcher.matches()) { diff --git a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceQueryDataNodeSpec.groovy b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceQueryDataNodeSpec.groovy index 4bebff9f84..45cd2e6d2e 100644 --- a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceQueryDataNodeSpec.groovy +++ b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceQueryDataNodeSpec.groovy @@ -107,8 +107,8 @@ class CpsDataPersistenceQueryDataNodeSpec extends CpsPersistenceSpecBase { } where: 'the following data is used' scenario | cpsPath || expectedXPaths - 'one leaf' | '//child-202[@common-leaf-name-int=5]' || ['/parent-200/child-202','/parent-201/child-202'] - 'trailing "and" is ignored' | '//child-202[@common-leaf-name-int=5 and]' || ['/parent-200/child-202','/parent-201/child-202'] + 'one leaf' | '//child-202[@common-leaf-name-int=5]' || ['/parent-200/child-202', '/parent-201/child-202'] + 'trailing "and" is ignored' | '//child-202[@common-leaf-name-int=5 and]' || ['/parent-200/child-202', '/parent-201/child-202'] 'more than one leaf' | '//child-202[@common-leaf-name-int=5 and @common-leaf-name="common-leaf value"]' || ['/parent-200/child-202'] 'leaves reversed in order' | '//child-202[@common-leaf-name="common-leaf value" and @common-leaf-name-int=5]' || ['/parent-200/child-202'] } @@ -120,14 +120,14 @@ class CpsDataPersistenceQueryDataNodeSpec extends CpsPersistenceSpecBase { then: 'the correct number of data nodes are retrieved' result.size() == expectedXPaths.size() and: 'xpaths of the retrieved data nodes are as expected' - for(int i = 0; i