summaryrefslogtreecommitdiffstats
path: root/cps-ri/src/test
diff options
context:
space:
mode:
authorToineSiebelink <toine.siebelink@est.tech>2021-04-15 12:15:01 +0100
committerToineSiebelink <toine.siebelink@est.tech>2021-04-15 12:30:51 +0100
commitf92d32193545e0b2cd8f9124b01433678b813435 (patch)
treeab578726eccc6690e08e5d0491d1d2ea365d7fad /cps-ri/src/test
parenta2d25b524c49d869cbd4479a807aaeb9313474a6 (diff)
Fix "ends-with" query syntax to conform with xPath definition
"ends-with" is HOW we resolve it in sql query. 'descendant anywhere' is the correct Path name for the '//' operator - Updated method names, variable names, test description to reflect the correct terminolgy - Udpated query to always perfix the target (descendant name) with an '\' so it alwasy only matches whole node names - Updated regex for cpsPath to NOT accept triple /// (as per xPath this is invalid since a ndoeName cannot start with or contain a node separator Issue-ID: CPS-336 Signed-off-by: ToineSiebelink <toine.siebelink@est.tech> Change-Id: I9f181d6986d038311b839e3f9c5afc4237c7d347
Diffstat (limited to 'cps-ri/src/test')
-rw-r--r--cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceSpec.groovy32
-rw-r--r--cps-ri/src/test/groovy/org/onap/cps/spi/query/CpsPathQuerySpec.groovy20
2 files changed, 27 insertions, 25 deletions
diff --git a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceSpec.groovy b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceSpec.groovy
index 231a57283c..a2c7a09478 100644
--- a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceSpec.groovy
+++ b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceSpec.groovy
@@ -338,9 +338,9 @@ class CpsDataPersistenceServiceSpec extends CpsPersistenceSpecBase {
dataNode.getLeaves().toString() == leaves
dataNode.getChildDataNodes().size() == expectedNumberOfChidlNodes
where: 'the following data is used'
- type | cpsPath | includeDescendantsOption | expectedNumberOfChidlNodes
- 'String and no descendants' | '/parent-200/child-202[@common-leaf-name=\'common-leaf-value\']' | OMIT_DESCENDANTS | 0
- 'Integer and descendants' | '/parent-200/child-202[@common-leaf-name-int=5]' | INCLUDE_ALL_DESCENDANTS | 1
+ type | cpsPath | includeDescendantsOption || expectedNumberOfChidlNodes
+ 'String and no descendants' | '/parent-200/child-202[@common-leaf-name=\'common-leaf-value\']' | OMIT_DESCENDANTS || 0
+ 'Integer and descendants' | '/parent-200/child-202[@common-leaf-name-int=5]' | INCLUDE_ALL_DESCENDANTS || 1
}
@Unroll
@@ -355,35 +355,35 @@ class CpsDataPersistenceServiceSpec extends CpsPersistenceSpecBase {
'cps path is incomplete' | '/parent-200[@common-leaf-name-int=5]'
'leaf value does not exist' | '/parent-200/child-202[@common-leaf-name=\'does not exist\']'
'incomplete end of xpath prefix' | '/parent-200/child-20[@common-leaf-name-int=5]'
- 'empty cps path of type ends with' | '///'
}
@Unroll
@Sql([CLEAR_DATA, SET_DATA])
- def 'Cps Path query with and without descendants using #type.'() {
+ def 'Cps Path query using descendant anywhere and #type (further) descendants.'() {
when: 'a query is executed to get a data node by the given cps path'
- def cpsPath = '///child-202'
+ def cpsPath = '//child-202'
def result = objectUnderTest.queryDataNodes(DATASPACE_NAME, ANCHOR_FOR_DATA_NODES_WITH_LEAVES, cpsPath, includeDescendantsOption)
then: 'the data node has the correct number of children'
DataNode dataNode = result.stream().findFirst().get()
dataNode.getChildDataNodes().size() == expectedNumberOfChildNodes
where: 'the following data is used'
- type | includeDescendantsOption | expectedNumberOfChildNodes
- 'ends with and omit descendants' | OMIT_DESCENDANTS | 0
- 'ends with and include all descendants' | INCLUDE_ALL_DESCENDANTS | 1
+ type | includeDescendantsOption || expectedNumberOfChildNodes
+ 'omit' | OMIT_DESCENDANTS || 0
+ 'include' | INCLUDE_ALL_DESCENDANTS || 1
}
@Unroll
@Sql([CLEAR_DATA, SET_DATA])
- def 'Cps Path query using ends with variations of #type.'() {
+ def 'Cps Path query using descendant anywhere with %scenario '() {
when: 'a query is executed to get a data node by the given cps path'
def result = objectUnderTest.queryDataNodes(DATASPACE_NAME, ANCHOR_FOR_DATA_NODES_WITH_LEAVES, cpsPath, OMIT_DESCENDANTS)
- then: 'the correct number of data nodes is returned'
- result.size() == expectedNumberOfDataNodes
+ then: 'Only one data node is returned'
+ result.size() == 1
+ and:
+ result.stream().findFirst().get().xpath == expectedXPath
where: 'the following data is used'
- type | cpsPath | expectedNumberOfDataNodes
- 'single match with / prefix' | '///child-202' | 1
- 'single match without / prefix' | '//grand-child-202' | 1
- 'multiple matches' | '//202' | 2
+ scenario | cpsPath || expectedXPath
+ 'fully unique descendant name' | '//grand-child-202' || '/parent-200/child-202/grand-child-202'
+ 'descendant name match end of other node' | '//child-202' || '/parent-200/child-202'
}
}
diff --git a/cps-ri/src/test/groovy/org/onap/cps/spi/query/CpsPathQuerySpec.groovy b/cps-ri/src/test/groovy/org/onap/cps/spi/query/CpsPathQuerySpec.groovy
index 0bc99c6441..7f558dd10b 100644
--- a/cps-ri/src/test/groovy/org/onap/cps/spi/query/CpsPathQuerySpec.groovy
+++ b/cps-ri/src/test/groovy/org/onap/cps/spi/query/CpsPathQuerySpec.groovy
@@ -50,13 +50,14 @@ class CpsPathQuerySpec extends Specification {
when: 'the given cps path is parsed'
def result = objectUnderTest.createFrom(cpsPath)
then: 'the query has the right type'
- result.cpsPathQueryType == CpsPathQueryType.XPATH_ENDS_WITH
+ result.cpsPathQueryType == CpsPathQueryType.XPATH_HAS_DESCENDANT_ANYWHERE
and: 'the right ends with parameters are set'
- result.endsWith == expectedEndsWithValue
+ result.descendantName == expectedEndsWithValue
where: 'the following data is used'
- scenario | cpsPath || expectedEndsWithValue
- 'yang container' | '///cps-path' || '/cps-path'
- 'yang list' | '///cps-path[@key=value]' || '/cps-path[@key=value]'
+ scenario | cpsPath || expectedEndsWithValue
+ 'yang container' | '//cps-path' || 'cps-path'
+ 'yang list' | '//cps-path[@key=value]' || 'cps-path[@key=value]'
+ 'parent & child' | '//parent/child' || 'parent/child'
}
@Unroll
@@ -66,9 +67,10 @@ class CpsPathQuerySpec extends Specification {
then: 'a CpsPathException is thrown'
thrown(CpsPathException)
where: 'the following data is used'
- scenario | cpsPath
- 'no / at the start' | 'invalid-cps-path/child'
- 'float value' | '/parent-200/child-202[@common-leaf-name-float=5.0]'
- 'too many containers' | '/1/2/3/4/5/6/7/8/9/10/11/12/13/14/15/16/17/18/19/20/21/22/23/24/25/26/27/28/29/30/31/32/33/34/35/36/37/38/39/40/41/42/43/44/45/46/47/48/49/50/51/52/53/54/55/56/57/58/59/60/61/62/63/64/65/66/67/68/69/70/71/72/73/74/75/76/77/78/79/80/81/82/83/84/85/86/87/88/89/90/91/92/93/94/95/96/97/98/99/100[@a=1]'
+ scenario | cpsPath
+ 'no / at the start' | 'invalid-cps-path/child'
+ 'additional / after descendant option' | '///cps-path'
+ 'float value' | '/parent-200/child-202[@common-leaf-name-float=5.0]'
+ 'too many containers' | '/1/2/3/4/5/6/7/8/9/10/11/12/13/14/15/16/17/18/19/20/21/22/23/24/25/26/27/28/29/30/31/32/33/34/35/36/37/38/39/40/41/42/43/44/45/46/47/48/49/50/51/52/53/54/55/56/57/58/59/60/61/62/63/64/65/66/67/68/69/70/71/72/73/74/75/76/77/78/79/80/81/82/83/84/85/86/87/88/89/90/91/92/93/94/95/96/97/98/99/100[@a=1]'
}
}