From 057284ee3336e4a2c21c7e40b89599c36ef38e8b Mon Sep 17 00:00:00 2001 From: danielhanrahan Date: Wed, 5 Apr 2023 16:41:55 +0100 Subject: Migrate query tests to integration-test module #1 Issue-ID: CPS-1597 Signed-off-by: danielhanrahan Change-Id: I0403641e2e5293571c61a58aa2b67b144cf68ac4 --- .../CpsDataPersistenceQueryDataNodeSpec.groovy | 51 +--------------------- .../CpsQueryServiceIntegrationSpec.groovy | 48 +++++++++++++++++--- 2 files changed, 43 insertions(+), 56 deletions(-) diff --git a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceQueryDataNodeSpec.groovy b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceQueryDataNodeSpec.groovy index 9df20f721e..8e50017746 100644 --- a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceQueryDataNodeSpec.groovy +++ b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceQueryDataNodeSpec.groovy @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2021-2022 Nordix Foundation + * Copyright (C) 2021-2023 Nordix Foundation * Modifications Copyright (C) 2021 Pantheon.tech * Modifications Copyright (C) 2021 Bell Canada. * Modifications Copyright (C) 2023 TechMahindra Ltd. @@ -23,13 +23,10 @@ package org.onap.cps.spi.impl import org.onap.cps.spi.CpsDataPersistenceService -import org.onap.cps.spi.FetchDescendantsOption import org.onap.cps.spi.exceptions.CpsPathException import org.springframework.beans.factory.annotation.Autowired import org.springframework.test.context.jdbc.Sql -import java.util.stream.Collectors - import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS import static org.onap.cps.spi.FetchDescendantsOption.OMIT_DESCENDANTS @@ -40,52 +37,6 @@ class CpsDataPersistenceQueryDataNodeSpec extends CpsPersistenceSpecBase { static final String SET_DATA = '/data/cps-path-query.sql' - @Sql([CLEAR_DATA, SET_DATA]) - def 'Cps Path query for leaf value(s) 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_SHOP_EXAMPLE, cpsPath, fetchDescendantsOption) - then: 'the correct number of parent nodes are returned' - result.size() == expectedNumberOfParentNodes - then: 'the correct data is returned' - result.each { - assert it.getChildDataNodes().size() == expectedNumberOfChildNodes - } - where: 'the following data is used' - scenario | cpsPath | fetchDescendantsOption || expectedNumberOfParentNodes | expectedNumberOfChildNodes - 'String and no descendants' | '/shops/shop[@id=1]/categories[@code=1]/book[@title="Dune"]' | OMIT_DESCENDANTS || 1 | 0 - 'Integer and descendants' | '/shops/shop[@id=1]/categories[@code=1]/book[@price=5]' | INCLUDE_ALL_DESCENDANTS || 1 | 1 - 'No condition no descendants' | '/shops/shop[@id=1]/categories' | OMIT_DESCENDANTS || 3 | 0 - 'Integer and level 1 descendants' | '/shops' | new FetchDescendantsOption(1) || 1 | 5 - 'Integer and level 2 descendants' | '/shops/shop[@id=1]' | new FetchDescendantsOption(2) || 1 | 3 - } - - @Sql([CLEAR_DATA, SET_DATA]) - def 'Query for attribute by cps path with cps paths that return no data because of #scenario.'() { - when: 'a query is executed to get data nodes for the given cps path' - def result = objectUnderTest.queryDataNodes(DATASPACE_NAME, ANCHOR_FOR_SHOP_EXAMPLE, cpsPath, OMIT_DESCENDANTS) - then: 'no data is returned' - result.isEmpty() - where: 'following cps queries are performed' - scenario | cpsPath - 'cps path is incomplete' | '/shops[@title="Dune"]' - 'leaf value does not exist' | '/shops/shop[@id=1]/categories[@code=1]/book[@title=\'does not exist\']' - 'incomplete end of xpath prefix' | '/shops/shop[@id=1]/categories/book[@price=15]' - } - - @Sql([CLEAR_DATA, SET_DATA]) - 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 = '//categories[@code=1]' - def result = objectUnderTest.queryDataNodes(DATASPACE_NAME, ANCHOR_FOR_SHOP_EXAMPLE, cpsPath, includeDescendantsOption) - then: 'the data node has the correct number of children' - def dataNode = result.stream().findFirst().get() - dataNode.getChildDataNodes().size() == expectedNumberOfChildNodes - where: 'the following data is used' - type | includeDescendantsOption || expectedNumberOfChildNodes - 'omit' | OMIT_DESCENDANTS || 0 - 'include' | INCLUDE_ALL_DESCENDANTS || 1 - } - @Sql([CLEAR_DATA, SET_DATA]) def 'Cps Path query using descendant anywhere with #scenario '() { when: 'a query is executed to get a data node by the given cps path' 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 a33d9fa5e4..1f3a76d6c7 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 @@ -24,14 +24,10 @@ 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 { @@ -52,8 +48,48 @@ class CpsQueryServiceIntegrationSpec extends FunctionalSpecBase { }) where: scenario | cpsPath || expectedResultSize | expectedLeaves - '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 | [] + '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 'Cps Path query for leaf value(s) with #scenario.'() { + when: 'a query is executed to get a data node by the given cps path' + def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE, BOOKSTORE_ANCHOR, cpsPath, fetchDescendantsOption) + then: 'the correct number of parent nodes are returned' + assert result.size() == expectedNumberOfParentNodes + and: 'the correct total number of data nodes are returned' + assert countDataNodesInTree(result) == expectedTotalNumberOfNodes + where: 'the following data is used' + scenario | cpsPath | fetchDescendantsOption || expectedNumberOfParentNodes | expectedTotalNumberOfNodes + 'string and no descendants' | '/bookstore/categories[@code="1"]/books[@title="Matilda"]' | OMIT_DESCENDANTS || 1 | 1 + 'integer and descendants' | '/bookstore/categories[@code="1"]/books[@price=15]' | INCLUDE_ALL_DESCENDANTS || 1 | 1 + 'no condition and no descendants' | '/bookstore/categories' | OMIT_DESCENDANTS || 3 | 3 + 'no condition and level 1 descendants' | '/bookstore' | new FetchDescendantsOption(1) || 1 | 4 + 'no condition and level 2 descendants' | '/bookstore' | new FetchDescendantsOption(2) || 1 | 8 + } + + def 'Query for attribute by cps path with cps paths that return no data because of #scenario.'() { + when: 'a query is executed to get data nodes for the given cps path' + def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE, BOOKSTORE_ANCHOR, cpsPath, OMIT_DESCENDANTS) + then: 'no data is returned' + assert result.isEmpty() + where: 'following cps queries are performed' + scenario | cpsPath + 'cps path is incomplete' | '/bookstore[@title="Matilda"]' + 'leaf value does not exist' | '/bookstore/categories[@code="1"]/books[@title=\'does not exist\']' + 'incomplete end of xpath prefix' | '/bookstore/categories/books[@price=15]' + } + + 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 result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE, BOOKSTORE_ANCHOR, '/bookstore/categories[@code="1"]', fetchDescendantsOption) + then: 'the data node has the correct number of children' + assert result[0].childDataNodes.xpath.sort() == expectedChildNodes.sort() + where: 'the following data is used' + type | fetchDescendantsOption || expectedChildNodes + 'omit' | OMIT_DESCENDANTS || [] + 'include' | INCLUDE_ALL_DESCENDANTS || ["/bookstore/categories[@code='1']/books[@title='Matilda']", + "/bookstore/categories[@code='1']/books[@title='The Gruffalo']"] } def 'Query for attribute by cps path of type ancestor with #scenario.'() { -- cgit 1.2.3-korg