X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cps-path-parser%2Fsrc%2Ftest%2Fgroovy%2Forg%2Fonap%2Fcps%2Fcpspath%2Fparser%2FCpsPathQuerySpec.groovy;h=9ab5491b5d974390cc4343e964116ebce12276ed;hb=ad61e283f7d981c3c8e307af871fb3a63e0cf4f9;hp=153dfbe9ed1671ef991413e08e4e2c198ebedd99;hpb=13237bbca932741b8ff3061bc79a9c45d38d80d5;p=cps.git 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 153dfbe9e..9ab5491b5 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 @@ -71,6 +71,10 @@ class CpsPathQuerySpec extends Specification { '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 condition has ">" operator' | '//cps-path[@key>9]' || "//cps-path[@key>'9']" + 'descendant with leaf condition has "<" operator' | '//cps-path[@key<10]' || "//cps-path[@key<'10']" + 'descendant with leaf condition has ">=" operator' | '//cps-path[@key>=8]' || "//cps-path[@key>='8']" + 'descendant with leaf condition has "<=" operator' | '//cps-path[@key<=12]' || "//cps-path[@key<='12']" '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" @@ -84,6 +88,8 @@ class CpsPathQuerySpec extends Specification { '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" + 'parent & child with multiple AND/OR combination' | '/parent/child[@key1=1 and @key2="abc" or @key="xyz"]/child2' || "/parent/child[@key1='1' and @key2='abc' or @key='xyz']/child2" + 'parent & child with multiple OR/AND combination' | '/parent/child[@key1=1 or @key2="abc" and @key="xyz"]/child2' || "/parent/child[@key1='1' or @key2='abc' and @key='xyz']/child2" } def 'Parse xpath to form the Normalized xpath containing #scenario.'() { @@ -105,14 +111,23 @@ class CpsPathQuerySpec extends Specification { and: 'the right parameters are set' result.descendantName == "child" result.leavesData.size() == expectedNumberOfLeaves - result.booleanOperatorsType == expectedOperators + and: 'the given operator(s) returns in the correct order' + result.booleanOperators == expectedOperators + and: 'the given comparativeOperator(s) returns in the correct order' + result.comparativeOperators == expectedComparativeOperator where: 'the following data is used' - 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'] + scenario | cpsPath || expectedNumberOfLeaves || expectedOperators || expectedComparativeOperator + 'one attribute' | '//child[@common-leaf-name-int=5]' || 1 || [] || ['='] + '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 operators' | '//child[@int-leaf=5 and @common-leaf-name="leaf value" and @leaf-name="leaf value1" ]' || 3 || ['and', 'and'] || ['=', '=', '='] + 'more than one attribute has combinations OR operators' | '//child[@int-leaf=5 or @common-leaf-name="leaf value" or @leaf-name="leaf value1" ]' || 3 || ['or', 'or'] || ['=', '=', '='] + 'more than one attribute has combinations AND/OR combination' | '//child[@int-leaf=5 and @common-leaf-name="leaf value" or @leaf-name="leaf value1" ]' || 3 || ['and', 'or'] || ['=', '=', '='] + 'more than one attribute has combinations OR/AND combination' | '//child[@int-leaf=5 or @common-leaf-name="leaf value" and @leaf-name="leaf value1" ]' || 3 || ['or', 'and'] || ['=', '=', '='] + 'more than one attribute has AND/> operators' | '//child[@int-leaf>15 and @leaf-name="leaf value"]' || 2 || ['and'] || ['>', '='] + 'more than one attribute has OR/< operators' | '//child[@int-leaf<5 or @leaf-name="leaf value"]' || 2 || ['or'] || ['<', '='] + 'more than one attribute has combinations AND/>= operators' | '//child[@int-leaf>=18 and @common-leaf-name="leaf value" and @leaf-name="leaf value1" ]' || 3 || ['and', 'and'] || ['>=', '=', '='] + 'more than one attribute has combinations OR/<= operators' | '//child[@int-leaf<=25 or @common-leaf-name="leaf value" or @leaf-name="leaf value1" ]' || 3 || ['or', 'or'] || ['<=', '=', '='] } def 'Parse #scenario cps path with text function condition'() { @@ -136,6 +151,17 @@ class CpsPathQuerySpec extends Specification { 'descendant with leaf value and ancestor' | '//child[@other-leaf=1]/leaf-name[text()="search"]/ancestor::parent' || true | true } + def 'Parse cps path with contains function condition'() { + when: 'the given cps path is parsed' + def result = CpsPathQuery.createFrom('//someContainer[contains(@lang,"en")]') + then: 'the query has the right xpath type' + result.cpsPathPrefixType == DESCENDANT + and: 'the right contains function condition is set' + result.hasContainsFunctionCondition() + result.containsFunctionConditionLeafName == 'lang' + result.containsFunctionConditionValue == 'en' + } + def 'Parse cps path with error: #scenario.'() { when: 'the given cps path is parsed' CpsPathQuery.createFrom(cpsPath)