summaryrefslogtreecommitdiffstats
path: root/integration-test/src/test
diff options
context:
space:
mode:
authorSourabh Sourabh <sourabh.sourabh@est.tech>2023-04-11 09:06:58 +0000
committerGerrit Code Review <gerrit@onap.org>2023-04-11 09:06:58 +0000
commitda0192e77e40239a1f3ffb3d71dcf958e6e7cc8f (patch)
tree48bc199ddb22dafdd822d91160b915684efb7f19 /integration-test/src/test
parentaf6c308365a6245020f34ed5446ab6c6b9d2a7c7 (diff)
parentc62dbd7d3538392c6b72e73631f026fef198715c (diff)
Merge "Migrate query tests to integration-test module #4"
Diffstat (limited to 'integration-test/src/test')
-rw-r--r--integration-test/src/test/groovy/org/onap/cps/integration/functional/CpsQueryServiceIntegrationSpec.groovy52
1 files changed, 50 insertions, 2 deletions
diff --git a/integration-test/src/test/groovy/org/onap/cps/integration/functional/CpsQueryServiceIntegrationSpec.groovy b/integration-test/src/test/groovy/org/onap/cps/integration/functional/CpsQueryServiceIntegrationSpec.groovy
index 496b36db99..a33d9fa5e4 100644
--- a/integration-test/src/test/groovy/org/onap/cps/integration/functional/CpsQueryServiceIntegrationSpec.groovy
+++ b/integration-test/src/test/groovy/org/onap/cps/integration/functional/CpsQueryServiceIntegrationSpec.groovy
@@ -20,18 +20,28 @@
package org.onap.cps.integration.functional
+import org.onap.cps.api.CpsQueryService
import org.onap.cps.integration.base.FunctionalSpecBase
import org.onap.cps.spi.FetchDescendantsOption
+import org.onap.cps.spi.exceptions.CpsPathException
+import org.springframework.test.context.jdbc.Sql
+
+import java.util.stream.Collectors
+
+import static org.onap.cps.spi.FetchDescendantsOption.DIRECT_CHILDREN_ONLY
+import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS
+import static org.onap.cps.spi.FetchDescendantsOption.OMIT_DESCENDANTS
+import static org.onap.cps.spi.FetchDescendantsOption.getFetchDescendantsOption
class CpsQueryServiceIntegrationSpec extends FunctionalSpecBase {
- def objectUnderTest
+ CpsQueryService objectUnderTest
def setup() { objectUnderTest = cpsQueryService }
def 'Query bookstore using CPS path where #scenario.'() {
when: 'query data nodes for bookstore container'
- def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE, BOOKSTORE_ANCHOR, cpsPath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS)
+ def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE, BOOKSTORE_ANCHOR, cpsPath, INCLUDE_ALL_DESCENDANTS)
then: 'the result contains expected number of nodes'
assert result.size() == expectedResultSize
and: 'the result contains the expected leaf values'
@@ -45,4 +55,42 @@ class CpsQueryServiceIntegrationSpec extends FunctionalSpecBase {
'the and condition is used' | '//books[@lang="English" and @price=15]' || 2 | [lang:"English", price:15]
'the and is used where result does not exist' | '//books[@lang="English" and @price=1000]' || 0 | []
}
+
+ def 'Query for attribute by cps path of type ancestor with #scenario.'() {
+ when: 'the given cps path is parsed'
+ def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE, BOOKSTORE_ANCHOR, cpsPath, OMIT_DESCENDANTS)
+ then: 'the xpaths of the retrieved data nodes are as expected'
+ assert result.xpath.sort() == expectedXPaths.sort()
+ where: 'the following data is used'
+ scenario | cpsPath || expectedXPaths
+ 'multiple list-ancestors' | '//books/ancestor::categories' || ["/bookstore/categories[@code='1']", "/bookstore/categories[@code='2']", "/bookstore/categories[@code='3']"]
+ 'one ancestor with list value' | '//books/ancestor::categories[@code="1"]' || ["/bookstore/categories[@code='1']"]
+ 'top ancestor' | '//books/ancestor::bookstore' || ["/bookstore"]
+ 'list with index value in the xpath prefix' | '//categories[@code="1"]/books/ancestor::bookstore' || ["/bookstore"]
+ 'ancestor with parent list' | '//books/ancestor::bookstore/categories' || ["/bookstore/categories[@code='1']", "/bookstore/categories[@code='2']", "/bookstore/categories[@code='3']"]
+ 'ancestor with parent' | '//books/ancestor::bookstore/categories[@code="2"]' || ["/bookstore/categories[@code='2']"]
+ 'ancestor combined with text condition' | '//books/title[text()="Matilda"]/ancestor::bookstore' || ["/bookstore"]
+ 'ancestor with parent that does not exist' | '//books/ancestor::parentDoesNoExist/categories' || []
+ 'ancestor does not exist' | '//books/ancestor::ancestorDoesNotExist' || []
+ }
+
+ def 'Query for attribute by cps path of type ancestor with #scenario descendants.'() {
+ when: 'the given cps path is parsed'
+ def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE, BOOKSTORE_ANCHOR, '//books/ancestor::bookstore', fetchDescendantsOption)
+ then: 'the xpaths of the retrieved data nodes are as expected'
+ assert countDataNodesInTree(result) == expectedNumberOfNodes
+ where: 'the following data is used'
+ scenario | fetchDescendantsOption || expectedNumberOfNodes
+ 'no' | OMIT_DESCENDANTS || 1
+ 'direct' | DIRECT_CHILDREN_ONLY || 4
+ 'all' | INCLUDE_ALL_DESCENDANTS || 8
+ }
+
+ def 'Cps Path query with syntax error throws a CPS Path Exception.'() {
+ when: 'trying to execute a query with a syntax (parsing) error'
+ objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE, BOOKSTORE_ANCHOR, 'cpsPath that cannot be parsed' , OMIT_DESCENDANTS)
+ then: 'a cps path exception is thrown'
+ thrown(CpsPathException)
+ }
+
}