aboutsummaryrefslogtreecommitdiffstats
path: root/cps-service/src/test
diff options
context:
space:
mode:
authorToineSiebelink <toine.siebelink@est.tech>2025-01-16 14:41:18 +0000
committerToineSiebelink <toine.siebelink@est.tech>2025-01-16 14:41:27 +0000
commit9df4a57a05e3ee67ff96284a4f7b1b07c94600b1 (patch)
treeea2fbc005c69e76284e8dcc0c5ddac0638aa07b3 /cps-service/src/test
parent856619ceb02f533ec7c5dff9a67ab17ef780276c (diff)
One SchemaSet per moduleSetTag
- Registration: create and upgrade cases. - Handle moduleSetTag deletion (all orphans) for testware - Unit tests updated - additional logging of details for upgrade scenarios - Integration Tests updated - Remove cache for module sets being processed - Removed DbCleaner (startup) - Removed redundant methods in NCMP Inventory for deleting schema set(s) - Removed validation check for all schema set interactions - Updated some schema set tests to use special characters previously not allowed - Checked integration test scenarios for upgrades with and without tags: all scenarios covered! TODO - REST endpoint to remove orphaned schema set data, separate story: CPS-2554 - Investigate exception handling regarding DuplicateYangResourceException: CPS-2555 Issue-ID: CPS-2540 Signed-off-by: ToineSiebelink <toine.siebelink@est.tech> Change-Id: Iaa59cbdb86b7a4a8044624829bc002506ff40cc7
Diffstat (limited to 'cps-service/src/test')
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAnchorServiceImplSpec.groovy13
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy75
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/api/impl/YangTextSchemaSourceSetCacheSpec.groovy19
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/init/DbCleanerSpec.groovy38
4 files changed, 47 insertions, 98 deletions
diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAnchorServiceImplSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAnchorServiceImplSpec.groovy
index e8617d445d..223ae71987 100644
--- a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAnchorServiceImplSpec.groovy
+++ b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAnchorServiceImplSpec.groovy
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2023-2024 Nordix Foundation
+ * Copyright (C) 2023-2025 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -40,8 +40,8 @@ class CpsAnchorServiceImplSpec extends Specification {
objectUnderTest.createAnchor('someDataspace', 'someSchemaSet', 'someAnchorName')
then: 'the persistence service method is invoked with same parameters'
1 * mockCpsAdminPersistenceService.createAnchor('someDataspace', 'someSchemaSet', 'someAnchorName')
- and: 'the CpsValidator is called on the dataspaceName, schemaSetName and anchorName'
- 1 * mockCpsValidator.validateNameCharacters('someDataspace', 'someSchemaSet', 'someAnchorName')
+ and: 'the CpsValidator is called on the dataspaceName and anchorName'
+ 1 * mockCpsValidator.validateNameCharacters('someDataspace', 'someAnchorName')
}
def 'Retrieve all anchors for dataspace.'() {
@@ -64,8 +64,8 @@ class CpsAnchorServiceImplSpec extends Specification {
def result = objectUnderTest.getAnchorsBySchemaSetName('someDataspace', 'someSchemaSet')
then: 'the collection provided by persistence service is returned as result'
result == anchors
- and: 'the CpsValidator is called on the dataspaceName, schemaSetName'
- 1 * mockCpsValidator.validateNameCharacters('someDataspace', 'someSchemaSet')
+ and: 'the CpsValidator is called on the dataspaceName'
+ 1 * mockCpsValidator.validateNameCharacters('someDataspace')
}
def 'Retrieve all anchors for multiple schema-sets.'() {
@@ -76,9 +76,8 @@ class CpsAnchorServiceImplSpec extends Specification {
def result = objectUnderTest.getAnchorsBySchemaSetNames('someDataspace', ['schemaSet1', 'schemaSet2'])
then: 'the collection provided by persistence service is returned as result'
result == anchors
- and: 'the CpsValidator is called on the dataspace name and schema-set names'
+ and: 'the CpsValidator is called on the dataspace name'
1 * mockCpsValidator.validateNameCharacters('someDataspace')
- 1 * mockCpsValidator.validateNameCharacters(_)
}
def 'Retrieve anchor for dataspace and provided anchor name.'() {
diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy
index 97b9f7fffd..d1101fc248 100644
--- a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy
+++ b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2020-2024 Nordix Foundation
+ * Copyright (C) 2020-2025 Nordix Foundation
* Modifications Copyright (C) 2020-2021 Pantheon.tech
* Modifications Copyright (C) 2020-2022 Bell Canada.
* Modifications Copyright (C) 2022 TechMahindra Ltd.
@@ -54,23 +54,23 @@ class CpsModuleServiceImplSpec extends Specification {
def 'Create schema set.'() {
when: 'Create schema set method is invoked'
- objectUnderTest.createSchemaSet('someDataspace', 'someSchemaSet', [:])
+ objectUnderTest.createSchemaSet('someDataspace', 'schemaSetName@with Special!Characters', [:])
then: 'Parameters are validated and processing is delegated to persistence service'
- 1 * mockCpsModulePersistenceService.storeSchemaSet('someDataspace', 'someSchemaSet', [:])
- and: 'the CpsValidator is called on the dataspaceName and schemaSetName'
- 1 * mockCpsValidator.validateNameCharacters('someDataspace', 'someSchemaSet')
+ 1 * mockCpsModulePersistenceService.storeSchemaSet('someDataspace', 'schemaSetName@with Special!Characters', [:])
+ and: 'the CpsValidator is called on the dataspaceName'
+ 1 * mockCpsValidator.validateNameCharacters('someDataspace')
}
def 'Create schema set from new modules and existing modules.'() {
given: 'a list of existing modules module reference'
- def moduleReferenceForExistingModule = new ModuleReference('test', '2021-10-12','test.org')
+ def moduleReferenceForExistingModule = new ModuleReference('test', '2021-10-12', 'test.org')
def listOfExistingModulesModuleReference = [moduleReferenceForExistingModule]
when: 'create schema set from modules method is invoked'
objectUnderTest.createSchemaSetFromModules('someDataspaceName', 'someSchemaSetName', [newModule: 'newContent'], listOfExistingModulesModuleReference)
then: 'processing is delegated to persistence service'
1 * mockCpsModulePersistenceService.storeSchemaSetFromModules('someDataspaceName', 'someSchemaSetName', [newModule: 'newContent'], listOfExistingModulesModuleReference)
- and: 'the CpsValidator is called on the dataspaceName and schemaSetName'
- 1 * mockCpsValidator.validateNameCharacters('someDataspaceName', 'someSchemaSetName')
+ and: 'the CpsValidator is called on the dataspaceName'
+ 1 * mockCpsValidator.validateNameCharacters('someDataspaceName')
}
def 'Create schema set from invalid resources'() {
@@ -100,15 +100,15 @@ class CpsModuleServiceImplSpec extends Specification {
given: 'an already present schema set'
def yangResourcesNameToContentMap = TestUtils.getYangResourcesAsMap('bookstore.yang')
and: 'yang resource cache returns the expected schema set'
- mockYangTextSchemaSourceSetCache.get('someDataspace', 'someSchemaSet') >> YangTextSchemaSourceSetBuilder.of(yangResourcesNameToContentMap)
+ mockYangTextSchemaSourceSetCache.get('someDataspace', 'schemaSetName@with Special!Characters') >> YangTextSchemaSourceSetBuilder.of(yangResourcesNameToContentMap)
when: 'get schema set method is invoked'
- def result = objectUnderTest.getSchemaSet('someDataspace', 'someSchemaSet')
+ def result = objectUnderTest.getSchemaSet('someDataspace', 'schemaSetName@with Special!Characters')
then: 'the correct schema set is returned'
- result.getName().contains('someSchemaSet')
+ result.getName().contains('schemaSetName@with Special!Characters')
result.getDataspaceName().contains('someDataspace')
result.getModuleReferences().contains(new ModuleReference('stores', '2020-09-15', 'org:onap:ccsdk:sample'))
- and: 'the CpsValidator is called on the dataspaceName and schemaSetName'
- 1 * mockCpsValidator.validateNameCharacters('someDataspace', 'someSchemaSet')
+ and: 'the CpsValidator is called on the dataspaceName'
+ 1 * mockCpsValidator.validateNameCharacters('someDataspace')
}
def 'Get schema sets by dataspace name.'() {
@@ -142,8 +142,8 @@ class CpsModuleServiceImplSpec extends Specification {
1 * mockCpsModulePersistenceService.deleteSchemaSet('my-dataspace', 'my-schemaset')
and: 'schema set will be removed from the cache'
1 * mockYangTextSchemaSourceSetCache.removeFromCache('my-dataspace', 'my-schemaset')
- and: 'the CpsValidator is called on the dataspaceName and schemaSetName'
- 1 * mockCpsValidator.validateNameCharacters('my-dataspace', _)
+ and: 'the CpsValidator is called on the dataspaceName'
+ 1 * mockCpsValidator.validateNameCharacters('my-dataspace')
where: 'following parameters are used'
numberOfAnchors << [0, 3]
}
@@ -159,8 +159,8 @@ class CpsModuleServiceImplSpec extends Specification {
1 * mockCpsModulePersistenceService.deleteSchemaSet('my-dataspace', 'my-schemaset')
and: 'schema set will be removed from the cache'
1 * mockYangTextSchemaSourceSetCache.removeFromCache('my-dataspace', 'my-schemaset')
- and: 'the CpsValidator is called on the dataspaceName and schemaSetName'
- 1 * mockCpsValidator.validateNameCharacters('my-dataspace', 'my-schemaset')
+ and: 'the CpsValidator is called on the dataspaceName'
+ 1 * mockCpsValidator.validateNameCharacters('my-dataspace')
}
def 'Delete schema-set when cascade is prohibited and schema-set has anchors.'() {
@@ -185,17 +185,15 @@ class CpsModuleServiceImplSpec extends Specification {
2 * mockYangTextSchemaSourceSetCache.removeFromCache('my-dataspace', _)
and: 'the CpsValidator is called on the dataspaceName'
1 * mockCpsValidator.validateNameCharacters('my-dataspace')
- and: 'the CpsValidator is called on the schemaSetNames'
- 1 * mockCpsValidator.validateNameCharacters(_)
where: 'following parameters are used'
numberOfAnchors << [0, 3]
}
def 'Upgrade existing schema set'() {
when: 'schema set update is requested'
- objectUnderTest.upgradeSchemaSetFromModules('my-dataspace', 'my-schemaset', [:], moduleReferences)
+ objectUnderTest.upgradeSchemaSetFromModules('my-dataspace', 'my-schemaset', [:], moduleReferences)
then: 'no exception is thrown '
- noExceptionThrown()
+ noExceptionThrown()
}
def 'Get all yang resources module references.'() {
@@ -206,7 +204,7 @@ class CpsModuleServiceImplSpec extends Specification {
def result = objectUnderTest.getYangResourceModuleReferences('someDataspaceName')
then: 'the list provided by persistence service is returned as result'
result == moduleReferences
- and: 'the CpsValidator is called on the dataspaceName and schemaSetName'
+ and: 'the CpsValidator is called on the dataspaceName'
1 * mockCpsValidator.validateNameCharacters('someDataspaceName')
}
@@ -218,7 +216,7 @@ class CpsModuleServiceImplSpec extends Specification {
def result = objectUnderTest.getYangResourcesModuleReferences('someDataspaceName', 'someAnchorName')
then: 'the list provided by persistence service is returned as result'
result == moduleReferences
- and: 'the CpsValidator is called on the dataspaceName and schemaSetName'
+ and: 'the CpsValidator is called on the dataspaceName and anchorName'
1 * mockCpsValidator.validateNameCharacters('someDataspaceName', 'someAnchorName')
}
@@ -231,22 +229,6 @@ class CpsModuleServiceImplSpec extends Specification {
1 * mockCpsModulePersistenceService.identifyNewModuleReferences(moduleReferencesToCheck)
}
- def 'Get module references when queried by attributes'() {
- given: 'a valid dataspace name and anchor name'
- def dataspaceName = 'someDataspace'
- def anchorName = 'someAnchor'
- and: 'a set of parent attributes and child attributes used for filtering'
- def parentAttributes = ['some-property-key1': 'some-property-val1']
- def childAttributes = ['some-property-key2': 'some-property-val2']
- and: 'a list of expected module references returned by the persistence service'
- def expectedModuleReferences = [new ModuleReference(moduleName: 'some-name', revision: 'some-revision')]
- mockCpsModulePersistenceService.getModuleReferencesByAttribute(dataspaceName, anchorName, parentAttributes, childAttributes) >> expectedModuleReferences
- when: 'the method is invoked to retrieve module references by attributes'
- def actualModuleReferences = objectUnderTest.getModuleReferencesByAttribute(dataspaceName, anchorName, parentAttributes, childAttributes)
- then: 'the retrieved module references should match the expected module references'
- assert actualModuleReferences == expectedModuleReferences
- }
-
def 'Getting module definitions with module name'() {
given: 'module persistence service returns module definitions for module name'
@@ -270,11 +252,18 @@ class CpsModuleServiceImplSpec extends Specification {
1 * mockCpsValidator.validateNameCharacters('some-dataspace-name', 'some-anchor-name')
}
- def 'Delete unused yang resource modules.'() {
- when: 'deleting unused yang resource modules'
- objectUnderTest.deleteUnusedYangResourceModules()
+ def 'Delete all unused yang module data.'() {
+ when: 'deleting unused yang module data'
+ objectUnderTest.deleteAllUnusedYangModuleData()
then: 'it is delegated to the module persistence service'
- 1 * mockCpsModulePersistenceService.deleteUnusedYangResourceModules()
+ 1 * mockCpsModulePersistenceService.deleteAllUnusedYangModuleData()
+ }
+
+ def 'Schema set exists.'() {
+ when: 'checking if schema set exists'
+ objectUnderTest.schemaSetExists('some-dataspace-name', 'some-schema-set-name')
+ then: 'the call is delegated to the module persistence service'
+ 1 * mockCpsModulePersistenceService.schemaSetExists('some-dataspace-name', 'some-schema-set-name')
}
def getModuleReferences() {
diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/YangTextSchemaSourceSetCacheSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/YangTextSchemaSourceSetCacheSpec.groovy
index 189e28521b..5b9d11f439 100644
--- a/cps-service/src/test/groovy/org/onap/cps/api/impl/YangTextSchemaSourceSetCacheSpec.groovy
+++ b/cps-service/src/test/groovy/org/onap/cps/api/impl/YangTextSchemaSourceSetCacheSpec.groovy
@@ -1,7 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2022 Bell Canada
- * Modifications Copyright (C) 2022 Nordix Foundation
+ * Modifications Copyright (C) 2022-2025 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -77,8 +77,8 @@ class YangTextSchemaSourceSetCacheSpec extends Specification {
assert cachedValue.getModuleReferences() == expectedYangTextSchemaSourceSet.getModuleReferences()
and: 'the response is as expected'
assert result.getModuleReferences() == expectedYangTextSchemaSourceSet.getModuleReferences()
- and: 'the CpsValidator is called on the dataspaceName and schemaSetName'
- 1 * mockCpsValidator.validateNameCharacters('my-dataspace', 'my-schemaset')
+ and: 'the CpsValidator is called on the dataspaceName'
+ 1 * mockCpsValidator.validateNameCharacters('my-dataspace')
}
def 'Cache Hit: Respond from cache'() {
@@ -104,8 +104,8 @@ class YangTextSchemaSourceSetCacheSpec extends Specification {
then: 'cached value is same as expected'
def cachedValue = getCachedValue('my-dataspace', 'my-schemaset')
cachedValue.getModuleReferences() == yangTextSchemaSourceSet.getModuleReferences()
- and: 'the CpsValidator is called on the dataspaceName and schemaSetName'
- 1 * mockCpsValidator.validateNameCharacters('my-dataspace', 'my-schemaset')
+ and: 'the CpsValidator is called on the dataspaceName'
+ 1 * mockCpsValidator.validateNameCharacters('my-dataspace')
}
def 'Cache Evict:with invalid #scenario'() {
@@ -119,8 +119,8 @@ class YangTextSchemaSourceSetCacheSpec extends Specification {
objectUnderTest.removeFromCache('my-dataspace', 'my-schemaset')
then: 'cached does not have value'
assert getCachedValue('my-dataspace', 'my-schemaset') == null
- and: 'the CpsValidator is called on the dataspaceName and schemaSetName'
- 1 * mockCpsValidator.validateNameCharacters('my-dataspace', 'my-schemaset')
+ and: 'the CpsValidator is called on the dataspaceName'
+ 1 * mockCpsValidator.validateNameCharacters('my-dataspace')
}
def 'Cache Evict: remove when does not exist'() {
@@ -130,8 +130,8 @@ class YangTextSchemaSourceSetCacheSpec extends Specification {
objectUnderTest.removeFromCache('my-dataspace', 'my-schemaset')
then: 'cached does not have value'
assert getCachedValue('my-dataspace', 'my-schemaset') == null
- and: 'the CpsValidator is called on the dataspaceName and schemaSetName'
- 1 * mockCpsValidator.validateNameCharacters('my-dataspace', 'my-schemaset')
+ and: 'the CpsValidator is called on the dataspaceName'
+ 1 * mockCpsValidator.validateNameCharacters('my-dataspace')
}
def getCachedValue(dataSpace, schemaSet) {
@@ -142,5 +142,4 @@ class YangTextSchemaSourceSetCacheSpec extends Specification {
return new String("${dataSpace}-${schemaSet}")
}
-
}
diff --git a/cps-service/src/test/groovy/org/onap/cps/init/DbCleanerSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/init/DbCleanerSpec.groovy
deleted file mode 100644
index 5106d29fa5..0000000000
--- a/cps-service/src/test/groovy/org/onap/cps/init/DbCleanerSpec.groovy
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2024 Nordix Foundation
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.cps.init
-
-import org.onap.cps.api.CpsModuleService
-import spock.lang.Specification
-
-class DbCleanerSpec extends Specification {
-
- def mockCpsModuleService = Mock(CpsModuleService)
-
- def objectUnderTest = new DbCleaner(mockCpsModuleService)
-
- def 'DB clean up.'() {
- when: 'scheduled method is triggered'
- objectUnderTest.cleanDbAtStartUp()
- then: 'the unused yang resource modules are deleted'
- 1 * mockCpsModuleService.deleteUnusedYangResourceModules()
- }
-}