summaryrefslogtreecommitdiffstats
path: root/cps-path-parser/src
diff options
context:
space:
mode:
authorRudrangi Anupriya <ra00745022@techmahindra.com>2023-04-25 13:13:16 +0530
committerRudrangi Anupriya <ra00745022@techmahindra.com>2023-04-25 21:45:40 +0530
commitc58a0f44bb4c7ea26143371fbe04a01974507e1c (patch)
tree9711550936276caf2f92cd9256e84cb158fb89e2 /cps-path-parser/src
parent2de9389a61f0feb37f0bcc22d6269e36dcfbd47c (diff)
Ordering of leaf elements to support combination of AND/OR in cps-path
Issue-ID: CPS-1629 Change-Id: Ib9df87e8171f4d53c49d80d27e3c6cf75aa3b209 Signed-off-by: Rudrangi Anupriya <ra00745022@techmahindra.com>
Diffstat (limited to 'cps-path-parser/src')
-rw-r--r--cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathBuilder.java4
-rw-r--r--cps-path-parser/src/test/groovy/org/onap/cps/cpspath/parser/CpsPathQuerySpec.groovy19
2 files changed, 14 insertions, 9 deletions
diff --git a/cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathBuilder.java b/cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathBuilder.java
index 854450c8bb..f44e310a1f 100644
--- a/cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathBuilder.java
+++ b/cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathBuilder.java
@@ -24,7 +24,7 @@ package org.onap.cps.cpspath.parser;
import static org.onap.cps.cpspath.parser.CpsPathPrefixType.DESCENDANT;
import java.util.ArrayList;
-import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -47,7 +47,7 @@ public class CpsPathBuilder extends CpsPathBaseListener {
final CpsPathQuery cpsPathQuery = new CpsPathQuery();
- final Map<String, Object> leavesData = new HashMap<>();
+ final Map<String, Object> leavesData = new LinkedHashMap<>();
final StringBuilder normalizedXpathBuilder = new StringBuilder();
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 96fdf88cf6..9552a4d342 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
@@ -84,6 +84,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 +107,17 @@ class CpsPathQuerySpec extends Specification {
and: 'the right parameters are set'
result.descendantName == "child"
result.leavesData.size() == expectedNumberOfLeaves
+ and: 'the given operator(s) returns in the correct order'
result.booleanOperatorsType == expectedOperators
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
+ '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 operators' | '//child[@int-leaf=5 and @leaf-name="leaf value" and @leaf-name="leaf value1" ]' || 2 || ['and', 'and']
+ 'more than one attribute has combinations or operators' | '//child[@int-leaf=5 or @leaf-name="leaf value" or @leaf-name="leaf value1" ]' || 2 || ['or', 'or']
+ 'more than one attribute has combinations and/or combination' | '//child[@int-leaf=5 and @leaf-name="leaf value" or @leaf-name="leaf value1" ]' || 2 || ['and', 'or']
+ 'more than one attribute has combinations or/and combination' | '//child[@int-leaf=5 or @leaf-name="leaf value" and @leaf-name="leaf value1" ]' || 2 || ['or', 'and']
}
def 'Parse #scenario cps path with text function condition'() {
@@ -136,7 +141,7 @@ class CpsPathQuerySpec extends Specification {
'descendant with leaf value and ancestor' | '//child[@other-leaf=1]/leaf-name[text()="search"]/ancestor::parent' || true | true
}
- def 'Parse #scenario cps path with contains function condition'() {
+ 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'