aboutsummaryrefslogtreecommitdiffstats
path: root/integration-test/src/test/groovy/org
diff options
context:
space:
mode:
authordanielhanrahan <daniel.hanrahan@est.tech>2024-02-08 15:04:05 +0000
committerDaniel Hanrahan <daniel.hanrahan@est.tech>2024-02-12 14:56:01 +0000
commite2d88379376923fbdddc78b59f74d75fd8040ec6 (patch)
tree338da3402e62f1aa0497cebb7282ae469be12031 /integration-test/src/test/groovy/org
parentc72a0132b024141716b35550fd7204338b2fc673 (diff)
Fix test failure by ordering leaf-lists
YANG specifies two ways that leaf-lists can be ordered: - ordered-by user: original order in JSON is preserved - ordered-by system (default): it is up to the system how to order For leaf-lists to preserve same order as the JSON, the Yang module must specify 'ordered-by user'. To ensure consistent behaviour even when system ordering is used, the leaf-list is sorted during parsing. - Add 'ordered-by user' to authors field in bookstore.yang - Sort leaf-list during parsing when using 'ordered-by system' - Add new tests to verify ordering Issue-ID: CPS-2057 Signed-off-by: danielhanrahan <daniel.hanrahan@est.tech> Change-Id: I6ab688ec2fa4a22182e853d1a8b26642f278c40a
Diffstat (limited to 'integration-test/src/test/groovy/org')
-rw-r--r--integration-test/src/test/groovy/org/onap/cps/integration/functional/CpsDataServiceIntegrationSpec.groovy34
-rw-r--r--integration-test/src/test/groovy/org/onap/cps/integration/functional/CpsModuleServiceIntegrationSpec.groovy10
2 files changed, 35 insertions, 9 deletions
diff --git a/integration-test/src/test/groovy/org/onap/cps/integration/functional/CpsDataServiceIntegrationSpec.groovy b/integration-test/src/test/groovy/org/onap/cps/integration/functional/CpsDataServiceIntegrationSpec.groovy
index 64996536e..f967c6203 100644
--- a/integration-test/src/test/groovy/org/onap/cps/integration/functional/CpsDataServiceIntegrationSpec.groovy
+++ b/integration-test/src/test/groovy/org/onap/cps/integration/functional/CpsDataServiceIntegrationSpec.groovy
@@ -423,8 +423,34 @@ class CpsDataServiceIntegrationSpec extends FunctionalSpecBase {
then: 'the updated data nodes are retrieved'
def result = cpsDataService.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_2, "/bookstore/categories[@code=1]/books[@title='Matilda']", INCLUDE_ALL_DESCENDANTS)
and: 'the leaf values are updated as expected'
- assert result.leaves['lang'] == ['English/French']
- assert result.leaves['price'] == [100]
+ assert result[0].leaves['lang'] == 'English/French'
+ assert result[0].leaves['price'] == 100
+ cleanup:
+ restoreBookstoreDataAnchor(2)
+ }
+
+ def 'Order of leaf-list elements is preserved when "ordered-by user" is set in the YANG model.'() {
+ given: 'Updated json for bookstore data'
+ def jsonData = "{'book-store:books':{'title':'Matilda', 'authors': ['beta', 'alpha', 'gamma', 'delta']}}"
+ when: 'update is performed for leaves'
+ objectUnderTest.updateNodeLeaves(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_2, "/bookstore/categories[@code='1']", jsonData, now)
+ and: 'the updated data nodes are retrieved'
+ def result = cpsDataService.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_2, "/bookstore/categories[@code=1]/books[@title='Matilda']", INCLUDE_ALL_DESCENDANTS)
+ then: 'the leaf-list values have expected order'
+ assert result[0].leaves['authors'] == ['beta', 'alpha', 'gamma', 'delta']
+ cleanup:
+ restoreBookstoreDataAnchor(2)
+ }
+
+ def 'Leaf-list elements are sorted when "ordered-by user" is not set in the YANG model.'() {
+ given: 'Updated json for bookstore data'
+ def jsonData = "{'book-store:books':{'title':'Matilda', 'editions': [2011, 1988, 2001, 2022, 2025]}}"
+ when: 'update is performed for leaves'
+ objectUnderTest.updateNodeLeaves(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_2, "/bookstore/categories[@code='1']", jsonData, now)
+ and: 'the updated data nodes are retrieved'
+ def result = cpsDataService.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_2, "/bookstore/categories[@code=1]/books[@title='Matilda']", INCLUDE_ALL_DESCENDANTS)
+ then: 'the leaf-list values have natural order'
+ assert result[0].leaves['editions'] == [1988, 2001, 2011, 2022, 2025]
cleanup:
restoreBookstoreDataAnchor(2)
}
@@ -540,7 +566,7 @@ class CpsDataServiceIntegrationSpec extends FunctionalSpecBase {
def expectedSourceDataInParentNode = ['name':'Children']
def expectedTargetDataInParentNode = ['name':'Kids']
def expectedSourceDataInChildNode = [['lang' : 'English'],['price':20, 'editions':[1988, 2000]]]
- def expectedTargetDataInChildNode = [['lang':'English/German'], ['price':200, 'editions':[2023, 1988, 2000]]]
+ def expectedTargetDataInChildNode = [['lang':'English/German'], ['price':200, 'editions':[1988, 2000, 2023]]]
when: 'attempt to get delta between leaves of existing data nodes'
def result = objectUnderTest.getDeltaByDataspaceAndAnchors(FUNCTIONAL_TEST_DATASPACE_3, BOOKSTORE_ANCHOR_3, BOOKSTORE_ANCHOR_5, parentNodeXpath, INCLUDE_ALL_DESCENDANTS)
def deltaReportEntities = getDeltaReportEntities(result)
@@ -555,7 +581,7 @@ class CpsDataServiceIntegrationSpec extends FunctionalSpecBase {
assert deltaReportEntities.get('xpaths').containsAll(["/bookstore/categories[@code='1']/books[@title='The Gruffalo']", "/bookstore/categories[@code='1']/books[@title='Matilda']"])
and: 'the delta report also has expected source and target data of child nodes'
assert deltaReportEntities.get('sourcePayload').containsAll(expectedSourceDataInChildNode)
- //assert deltaReportEntities.get('targetPayload').containsAll(expectedTargetDataInChildNode) CPS-2057
+ assert deltaReportEntities.get('targetPayload').containsAll(expectedTargetDataInChildNode)
}
def getDeltaReportEntities(List<DeltaReport> deltaReport) {
diff --git a/integration-test/src/test/groovy/org/onap/cps/integration/functional/CpsModuleServiceIntegrationSpec.groovy b/integration-test/src/test/groovy/org/onap/cps/integration/functional/CpsModuleServiceIntegrationSpec.groovy
index 3807a14bc..b7b6fa11a 100644
--- a/integration-test/src/test/groovy/org/onap/cps/integration/functional/CpsModuleServiceIntegrationSpec.groovy
+++ b/integration-test/src/test/groovy/org/onap/cps/integration/functional/CpsModuleServiceIntegrationSpec.groovy
@@ -36,8 +36,8 @@ class CpsModuleServiceIntegrationSpec extends FunctionalSpecBase {
CpsModuleService objectUnderTest
private static def originalNumberOfModuleReferences = 2 // bookstore has two modules
- private static def bookStoreModuleReference = new ModuleReference('stores','2024-01-30')
- private static def bookStoreModuleReferenceWithNamespace = new ModuleReference('stores','2024-01-30', 'org:onap:cps:sample')
+ private static def bookStoreModuleReference = new ModuleReference('stores','2024-02-08')
+ private static def bookStoreModuleReferenceWithNamespace = new ModuleReference('stores','2024-02-08', 'org:onap:cps:sample')
private static def bookStoreTypesModuleReference = new ModuleReference('bookstore-types','2024-01-30')
private static def bookStoreTypesModuleReferenceWithNamespace = new ModuleReference('bookstore-types','2024-01-30', 'org:onap:cps:types:sample')
static def NEW_RESOURCE_REVISION = '2023-05-10'
@@ -155,7 +155,7 @@ class CpsModuleServiceIntegrationSpec extends FunctionalSpecBase {
def result = objectUnderTest.getModuleDefinitionsByAnchorName(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1)
then: 'the correct module definitions are returned'
assert result.size() == 2
- assert result.contains(new ModuleDefinition('stores','2024-01-30',bookstoreModelFileContent))
+ assert result.contains(new ModuleDefinition('stores','2024-02-08',bookstoreModelFileContent))
assert result.contains(new ModuleDefinition('bookstore-types','2024-01-30', bookstoreTypesFileContent))
}
@@ -165,12 +165,12 @@ class CpsModuleServiceIntegrationSpec extends FunctionalSpecBase {
then: 'the correct module definitions are returned'
if (expectedNumberOfDefinitions > 0) {
assert result.size() == expectedNumberOfDefinitions
- def expectedModuleDefinition = new ModuleDefinition('stores', '2024-01-30', bookstoreModelFileContent)
+ def expectedModuleDefinition = new ModuleDefinition('stores', '2024-02-08', bookstoreModelFileContent)
assert result[0] == expectedModuleDefinition
}
where: 'following parameters are used'
scenarios | moduleName | moduleRevision || expectedNumberOfDefinitions
- 'correct module name and revision' | 'stores' | '2024-01-30' || 1
+ 'correct module name and revision' | 'stores' | '2024-02-08' || 1
'correct module name' | 'stores' | null || 1
'incorrect module name' | 'other' | null || 0
'incorrect revision' | 'stores' | '2025-11-22' || 0