diff options
author | niamhcore <niamh.core@est.tech> | 2021-03-03 12:05:09 +0000 |
---|---|---|
committer | niamhcore <niamh.core@est.tech> | 2021-03-04 16:27:53 +0000 |
commit | 50130c04626e0c5b09b344b2e11bb99c62dbf926 (patch) | |
tree | 72e703c7c74e40165dacd993ecf35ddb4670da51 /cps-ri/src/test/groovy/org | |
parent | 333f2b5a7a54f325a8d7137e6b8c0502fc860441 (diff) |
CPS-265 - Update cps path query to support 'ends with'
Issue-ID: CPS-265
Signed-off-by: niamhcore <niamh.core@est.tech>
Change-Id: I604191feaad820983d86e6fd844f543f51096a4e
Diffstat (limited to 'cps-ri/src/test/groovy/org')
-rw-r--r-- | cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceSpec.groovy | 47 | ||||
-rw-r--r-- | cps-ri/src/test/groovy/org/onap/cps/spi/query/CpsPathQuerySpec.groovy | 41 |
2 files changed, 67 insertions, 21 deletions
diff --git a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceSpec.groovy b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceSpec.groovy index 8001c659ff..bb0b471256 100644 --- a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceSpec.groovy +++ b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceSpec.groovy @@ -312,14 +312,14 @@ class CpsDataPersistenceServiceSpec extends CpsPersistenceSpecBase { when: 'a query is executed to get a data node by the given cps path' def result = objectUnderTest.queryDataNodes(DATASPACE_NAME, ANCHOR_FOR_DATA_NODES_WITH_LEAVES, cpsPath, includeDescendantsOption) then: 'the correct data is returned' - def leaves ='[common-leaf-name:common-leaf-value, common-leaf-name-int:5.0]' + def leaves = '[common-leaf-name:common-leaf-value, common-leaf-name-int:5.0]' DataNode dataNode = result.stream().findFirst().get() dataNode.getLeaves().toString() == leaves dataNode.getChildDataNodes().size() == expectedNumberOfChidlNodes where: 'the following data is used' - type | cpsPath | includeDescendantsOption | expectedNumberOfChidlNodes - 'String and no descendants' | '/parent-200/child-202[@common-leaf-name=\'common-leaf-value\']' | OMIT_DESCENDANTS | 0 - 'Integer and descendants' | '/parent-200/child-202[@common-leaf-name-int=5]' | INCLUDE_ALL_DESCENDANTS | 1 + type | cpsPath | includeDescendantsOption | expectedNumberOfChidlNodes + 'String and no descendants' | '/parent-200/child-202[@common-leaf-name=\'common-leaf-value\']' | OMIT_DESCENDANTS | 0 + 'Integer and descendants' | '/parent-200/child-202[@common-leaf-name-int=5]' | INCLUDE_ALL_DESCENDANTS | 1 } @Unroll @@ -330,10 +330,39 @@ class CpsDataPersistenceServiceSpec extends CpsPersistenceSpecBase { then: 'no data is returned' result.isEmpty() where: 'following cps queries are performed' - scenario | cpsPath - 'cps path is incomplete' | '/parent-200[@common-leaf-name-int=5]' - 'missing / at beginning of path' | 'parent-200/child-202[@common-leaf-name-int=5]' - 'leaf value does not exist' | '/parent-200/child-202[@common-leaf-name=\'does not exist\']' - 'incomplete end of xpath prefix' | '/parent-200/child-20[@common-leaf-name-int=5]' + scenario | cpsPath + 'cps path is incomplete' | '/parent-200[@common-leaf-name-int=5]' + 'leaf value does not exist' | '/parent-200/child-202[@common-leaf-name=\'does not exist\']' + 'incomplete end of xpath prefix' | '/parent-200/child-20[@common-leaf-name-int=5]' + 'empty cps path of type ends with' | '///' + } + + @Unroll + @Sql([CLEAR_DATA, SET_DATA]) + def 'Cps Path query with and without descendants using #type.'() { + when: 'a query is executed to get a data node by the given cps path' + def cpsPath = '///child-202' + def result = objectUnderTest.queryDataNodes(DATASPACE_NAME, ANCHOR_FOR_DATA_NODES_WITH_LEAVES, cpsPath, includeDescendantsOption) + then: 'the data node has the correct number of children' + DataNode dataNode = result.stream().findFirst().get() + dataNode.getChildDataNodes().size() == expectedNumberOfChildNodes + where: 'the following data is used' + type | includeDescendantsOption | expectedNumberOfChildNodes + 'ends with and omit descendants' | OMIT_DESCENDANTS | 0 + 'ends with and include all descendants' | INCLUDE_ALL_DESCENDANTS | 1 + } + + @Unroll + @Sql([CLEAR_DATA, SET_DATA]) + def 'Cps Path query using ends with variations of #type.'() { + when: 'a query is executed to get a data node by the given cps path' + def result = objectUnderTest.queryDataNodes(DATASPACE_NAME, ANCHOR_FOR_DATA_NODES_WITH_LEAVES, cpsPath, OMIT_DESCENDANTS) + then: 'the correct number of data nodes is returned' + result.size() == expectedNumberOfDataNodes + where: 'the following data is used' + type | cpsPath | expectedNumberOfDataNodes + 'single match with / prefix' | '///child-202' | 1 + 'single match without / prefix' | '//grand-child-202' | 1 + 'multiple matches' | '//202' | 2 } } diff --git a/cps-ri/src/test/groovy/org/onap/cps/spi/query/CpsPathQuerySpec.groovy b/cps-ri/src/test/groovy/org/onap/cps/spi/query/CpsPathQuerySpec.groovy index 1e457fb062..708761326b 100644 --- a/cps-ri/src/test/groovy/org/onap/cps/spi/query/CpsPathQuerySpec.groovy +++ b/cps-ri/src/test/groovy/org/onap/cps/spi/query/CpsPathQuerySpec.groovy @@ -28,28 +28,45 @@ class CpsPathQuerySpec extends Specification { def objectUnderTest = new CpsPathQuery() @Unroll - def 'Parse cps path with valid cps path and a filter for a leaf of type : #type.'() - { when: 'the given cps path is parsed' - def result = objectUnderTest.createFrom(cpsPath) - then: 'object has the expected attribute' + def 'Parse cps path with valid cps path and a filter for a leaf of type : #type.'() { + when: 'the given cps path is parsed' + def result = objectUnderTest.createFrom(cpsPath) + then: 'the query has the right type' + result.cpsPathQueryType == CpsPathQueryType.XPATH_LEAF_VALUE + and: 'the right query parameters are set' result.xpathPrefix == '/parent-200/child-202' result.leafName == expectedLeafName result.leafValue == expectedLeafValue where: 'the following data is used' - type | cpsPath || expectedLeafName | expectedLeafValue - 'String' | '/parent-200/child-202[@common-leaf-name=\'common-leaf-value\']' || 'common-leaf-name' | 'common-leaf-value' - 'Integer' | '/parent-200/child-202[@common-leaf-name-int=5]' || 'common-leaf-name-int' | 5 + type | cpsPath || expectedLeafName | expectedLeafValue + 'String' | '/parent-200/child-202[@common-leaf-name=\'common-leaf-value\']' || 'common-leaf-name' | 'common-leaf-value' + 'Integer' | '/parent-200/child-202[@common-leaf-name-int=5]' || 'common-leaf-name-int' | 5 + 'Integer value with spaces' | '/parent-200/child-202[@common-leaf-name-int = 5]' || 'common-leaf-name-int' | 5 } @Unroll - def 'Parse cps path with : #scenario.'() - { when: 'the given cps path is parsed' + def 'Parse cps path of type ends with a #scenario.'() { + when: 'the given cps path is parsed' + def result = objectUnderTest.createFrom(cpsPath) + then: 'the query has the right type' + result.cpsPathQueryType == CpsPathQueryType.XPATH_ENDS_WITH + and: 'the right ends with parameters are set' + result.endsWith == expectedEndsWithValue + where: 'the following data is used' + scenario | cpsPath || expectedEndsWithValue + 'yang container' | '///cps-path' || '/cps-path' + 'yang list' | '///cps-path[@key=value]' || '/cps-path[@key=value]' + } + + @Unroll + def 'Parse cps path with #scenario.'() { + when: 'the given cps path is parsed' objectUnderTest.createFrom(cpsPath) then: 'a CpsPathException is thrown' thrown(CpsPathException) where: 'the following data is used' - scenario | cpsPath - 'invalid cps path' | 'invalid-cps-path' - 'cps path with float value' | '/parent-200/child-202[@common-leaf-name-float=5.0]' + scenario | cpsPath + 'no / at the start' | 'invalid-cps-path/child' + 'float value' | '/parent-200/child-202[@common-leaf-name-float=5.0]' } } |