summaryrefslogtreecommitdiffstats
path: root/cps-path-parser/src/test/groovy/org/onap
diff options
context:
space:
mode:
Diffstat (limited to 'cps-path-parser/src/test/groovy/org/onap')
-rw-r--r--cps-path-parser/src/test/groovy/org/onap/cps/cpspath/parser/CpsPathQuerySpec.groovy64
1 files changed, 36 insertions, 28 deletions
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 b837a64fef..153dfbe9ed 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,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2021-2022 Nordix Foundation
+ * Modifications Copyright (C) 2023 TechMahindra Ltd
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -66,19 +67,23 @@ class CpsPathQuerySpec extends Specification {
then: 'the query has the right normalized xpath type'
assert result.normalizedXpath == expectedNormalizedXPath
where: 'the following data is used'
- scenario | cpsPath || expectedNormalizedXPath
- 'yang container' | '/cps-path' || '/cps-path'
- 'descendant anywhere' | '//cps-path' || '//cps-path'
- 'descendant with leaf condition' | '//cps-path[@key=1]' || "//cps-path[@key='1']"
- 'descendant with leaf value and ancestor' | '//cps-path[@key=1]/ancestor:parent[@key=1]' || "//cps-path[@key='1']/ancestor:parent[@key='1']"
- 'parent & child' | '/parent/child' || '/parent/child'
- 'parent leaf of type Integer & child' | '/parent/child[@code=1]/child2' || "/parent/child[@code='1']/child2"
- 'parent leaf with double quotes' | '/parent/child[@code="1"]/child2' || "/parent/child[@code='1']/child2"
- 'parent leaf with double quotes inside single quotes' | '/parent/child[@code=\'"1"\']/child2' || "/parent/child[@code='\"1\"']/child2"
- 'parent leaf with single quotes inside double quotes' | '/parent/child[@code="\'1\'"]/child2' || "/parent/child[@code='\\\'1\\\'']/child2"
- 'leaf with single quotes inside double quotes' | '/parent/child[@code="\'1\'"]' || "/parent/child[@code='\\\'1\\\'']"
- 'leaf with more than one attribute' | '/parent/child[@key1=1 and @key2="abc"]' || "/parent/child[@key1='1' and @key2='abc']"
- 'parent & child with more than one attribute' | '/parent/child[@key1=1 and @key2="abc"]/child2' || "/parent/child[@key1='1' and @key2='abc']/child2"
+ scenario | cpsPath || expectedNormalizedXPath
+ 'yang container' | '/cps-path' || '/cps-path'
+ 'descendant anywhere' | '//cps-path' || '//cps-path'
+ 'descendant with leaf condition' | '//cps-path[@key=1]' || "//cps-path[@key='1']"
+ 'descendant with leaf value and ancestor' | '//cps-path[@key=1]/ancestor:parent[@key=1]' || "//cps-path[@key='1']/ancestor:parent[@key='1']"
+ 'parent & child' | '/parent/child' || '/parent/child'
+ 'parent leaf of type Integer & child' | '/parent/child[@code=1]/child2' || "/parent/child[@code='1']/child2"
+ 'parent leaf with double quotes' | '/parent/child[@code="1"]/child2' || "/parent/child[@code='1']/child2"
+ 'parent leaf with double quotes inside single quotes' | '/parent/child[@code=\'"1"\']/child2' || "/parent/child[@code='\"1\"']/child2"
+ 'parent leaf with single quotes inside double quotes' | '/parent/child[@code="\'1\'"]/child2' || "/parent/child[@code='\\\'1\\\'']/child2"
+ 'leaf with single quotes inside double quotes' | '/parent/child[@code="\'1\'"]' || "/parent/child[@code='\\\'1\\\'']"
+ 'leaf with more than one attribute' | '/parent/child[@key1=1 and @key2="abc"]' || "/parent/child[@key1='1' and @key2='abc']"
+ 'parent & child with more than one attribute' | '/parent/child[@key1=1 and @key2="abc"]/child2' || "/parent/child[@key1='1' and @key2='abc']/child2"
+ 'leaf with more than one attribute has OR operator' | '/parent/child[@key1=1 or @key2="abc"]' || "/parent/child[@key1='1' or @key2='abc']"
+ 'parent & child with more than one attribute has OR operator' | '/parent/child[@key1=1 or @key2="abc"]/child2' || "/parent/child[@key1='1' or @key2='abc']/child2"
+ 'parent & child with multiple AND operators' | '/parent/child[@key1=1 and @key2="abc" and @key="xyz"]/child2' || "/parent/child[@key1='1' and @key2='abc' and @key='xyz']/child2"
+ 'parent & child with multiple OR operators' | '/parent/child[@key1=1 or @key2="abc" or @key="xyz"]/child2' || "/parent/child[@key1='1' or @key2='abc' or @key='xyz']/child2"
}
def 'Parse xpath to form the Normalized xpath containing #scenario.'() {
@@ -100,10 +105,14 @@ class CpsPathQuerySpec extends Specification {
and: 'the right parameters are set'
result.descendantName == "child"
result.leavesData.size() == expectedNumberOfLeaves
+ result.booleanOperatorsType == expectedOperators
where: 'the following data is used'
- scenario | cpsPath || expectedNumberOfLeaves
- 'one attribute' | '//child[@common-leaf-name-int=5]' || 1
- 'more than one attribute' | '//child[@int-leaf=5 and @leaf-name="leaf value"]' || 2
+ scenario | cpsPath || expectedNumberOfLeaves || expectedOperators
+ 'one attribute' | '//child[@common-leaf-name-int=5]' || 1 || null
+ 'more than one attribute has AND operator' | '//child[@int-leaf=5 and @leaf-name="leaf value"]' || 2 || ['and']
+ 'more than one attribute has OR operator' | '//child[@int-leaf=5 or @leaf-name="leaf value"]' || 2 || ['or']
+ 'more than one attribute has combinations and/or operator' | '//child[@int-leaf=5 and @leaf-name="leaf value" and @leaf-name="leaf value1" ]' || 2 || ['and', 'and']
+ 'more than one attribute has combinations or/and operator' | '//child[@int-leaf=5 or @leaf-name="leaf value" or @leaf-name="leaf value1" ]' || 2 || ['or', 'or']
}
def 'Parse #scenario cps path with text function condition'() {
@@ -133,18 +142,17 @@ class CpsPathQuerySpec extends Specification {
then: 'a CpsPathException is thrown'
thrown(PathParsingException)
where: 'the following data is used'
- scenario | cpsPath
- 'no / at the start' | 'invalid-cps-path/child'
- 'additional / after descendant option' | '///cps-path'
- 'float value' | '/parent/child[@someFloat=5.0]'
- 'unmatched quotes, double quote first ' | '/parent/child[@someString="value with unmatched quotes\']'
- 'unmatched quotes, single quote first' | '/parent/child[@someString=\'value with unmatched quotes"]'
- 'end with descendant and more than one attribute separated by "or"' | '//child[@int-leaf=5 or @leaf-name="leaf value"]'
- 'missing attribute value' | '//child[@int-leaf=5 and @name]'
- 'incomplete ancestor value' | '//books/ancestor::'
- 'invalid list element with missing [' | '/parent-206/child-206/grand-child-206@key="A"]'
- 'invalid list element with incorrect ]' | '/parent-206/child-206/grand-child-206]@key="A"]'
- 'invalid list element with incorrect ::' | '/parent-206/child-206/grand-child-206::@key"A"]'
+ scenario | cpsPath
+ 'no / at the start' | 'invalid-cps-path/child'
+ 'additional / after descendant option' | '///cps-path'
+ 'float value' | '/parent/child[@someFloat=5.0]'
+ 'unmatched quotes, double quote first ' | '/parent/child[@someString="value with unmatched quotes\']'
+ 'unmatched quotes, single quote first' | '/parent/child[@someString=\'value with unmatched quotes"]'
+ 'missing attribute value' | '//child[@int-leaf=5 and @name]'
+ 'incomplete ancestor value' | '//books/ancestor::'
+ 'invalid list element with missing [' | '/parent-206/child-206/grand-child-206@key="A"]'
+ 'invalid list element with incorrect ]' | '/parent-206/child-206/grand-child-206]@key="A"]'
+ 'invalid list element with incorrect ::' | '/parent-206/child-206/grand-child-206::@key"A"]'
}
def 'Parse cps path using ancestor by schema node identifier with a #scenario.'() {