diff options
author | Sourabh Sourabh <sourabh.sourabh@est.tech> | 2025-01-17 09:49:36 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2025-01-17 09:49:36 +0000 |
commit | 76a3bddc4494b6856084b02f49e37e7ab7c5d27a (patch) | |
tree | 795ff8592b2a7d745dbba1ca0682626a59b96839 /cps-service/src | |
parent | d5c0c3aef85915cbdd1fd67ecd058b53e77467cc (diff) | |
parent | 9df4a57a05e3ee67ff96284a4f7b1b07c94600b1 (diff) |
Merge "One SchemaSet per moduleSetTag"
Diffstat (limited to 'cps-service/src')
10 files changed, 95 insertions, 236 deletions
diff --git a/cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java b/cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java index e71b44c40f..81b6439efc 100644 --- a/cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java +++ b/cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java @@ -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) 2022 TechMahindra Ltd. * ================================================================================ @@ -58,6 +58,15 @@ public interface CpsModuleService { Collection<ModuleReference> allModuleReferences); /** + * Check if a schema set exist in the given dataspace. + * + * @param dataspaceName Dataspace name + * @param schemaSetName Schema set name + * @return boolean, true if a schema set with the given name exist in the given dataspace + */ + boolean schemaSetExists(String dataspaceName, String schemaSetName); + + /** * Read schema set in the given dataspace. * * @param dataspaceName dataspace name @@ -150,47 +159,13 @@ public interface CpsModuleService { * The system will ignore the namespace of all module references. * * @param moduleReferencesToCheck the moduleReferencesToCheck - * @returns collection of module references (namespace will be always blank) - */ - Collection<ModuleReference> identifyNewModuleReferences( - Collection<ModuleReference> moduleReferencesToCheck); - - /** - * Retrieves module references based on the provided dataspace name, anchor name and attribute filters - * for both parent and child fragments. - - * This method constructs and executes a SQL query to find module references from a database, using - * the specified `dataspaceName`, `anchorName` and two sets of attribute filters: one for parent fragments - * and one for child fragments. The method applies these filters to identify the appropriate fragments - * and schema sets, and then retrieves the corresponding module references. - - * The SQL query is dynamically built based on the provided attribute filters: - * - The `parentAttributes` map is used to filter the parent fragments. The entries in this map are - * converted into a WHERE clause for the parent fragments. - * - The `childAttributes` map is used to filter the child fragments. This is applied to the child fragments - * after filtering the parent fragments. - * - * @param dataspaceName the name of the dataspace to filter on. It is used to locate the relevant dataspace - * in the database. - * @param anchorName the name of the anchor to filter on. It is used to locate the relevant anchor within - * the dataspace. - * @param parentAttributes a map of attributes to filter parent fragments. Each entry in this map represents - * an attribute key-value pair used in the WHERE clause for parent fragments. - * @param childAttributes a map of attributes to filter child fragments. Each entry in this map represents - * an attribute key-value pair used in the WHERE clause for child fragments. - * @return a collection of {@link ModuleReference} objects that match the given criteria. - * Each {@code ModuleReference} contains information about a module's name and revision. - * @implNote The method assumes that both `parentAttributes` and `childAttributes` maps contain at least - * one entry. The first entry from `parentAttributes` is used to filter parent fragments, - * and the first entry from `childAttributes` is used to filter child fragments. + * @return collection of module references (namespace will be always blank) */ - Collection<ModuleReference> getModuleReferencesByAttribute(final String dataspaceName, final String anchorName, - final Map<String, String> parentAttributes, - final Map<String, String> childAttributes); + Collection<ModuleReference> identifyNewModuleReferences(Collection<ModuleReference> moduleReferencesToCheck); /** - * Remove any Yang Resource Modules from the DB that are no longer referenced by any schema set. + * Remove any Yang Resource Modules and Schema Sets from the DB that are no longer referenced by any anchor. */ - void deleteUnusedYangResourceModules(); + void deleteAllUnusedYangModuleData(); } diff --git a/cps-service/src/main/java/org/onap/cps/api/impl/CpsAnchorServiceImpl.java b/cps-service/src/main/java/org/onap/cps/api/impl/CpsAnchorServiceImpl.java index 1bd2b6af56..2a2ddc6c11 100644 --- a/cps-service/src/main/java/org/onap/cps/api/impl/CpsAnchorServiceImpl.java +++ b/cps-service/src/main/java/org/onap/cps/api/impl/CpsAnchorServiceImpl.java @@ -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. @@ -39,7 +39,7 @@ public class CpsAnchorServiceImpl implements CpsAnchorService { @Override public void createAnchor(final String dataspaceName, final String schemaSetName, final String anchorName) { - cpsValidator.validateNameCharacters(dataspaceName, schemaSetName, anchorName); + cpsValidator.validateNameCharacters(dataspaceName, anchorName); cpsAdminPersistenceService.createAnchor(dataspaceName, schemaSetName, anchorName); } @@ -64,7 +64,7 @@ public class CpsAnchorServiceImpl implements CpsAnchorService { @Override public Collection<Anchor> getAnchorsBySchemaSetName(final String dataspaceName, final String schemaSetName) { - cpsValidator.validateNameCharacters(dataspaceName, schemaSetName); + cpsValidator.validateNameCharacters(dataspaceName); return cpsAdminPersistenceService.getAnchorsBySchemaSetName(dataspaceName, schemaSetName); } @@ -72,7 +72,6 @@ public class CpsAnchorServiceImpl implements CpsAnchorService { public Collection<Anchor> getAnchorsBySchemaSetNames(final String dataspaceName, final Collection<String> schemaSetNames) { cpsValidator.validateNameCharacters(dataspaceName); - cpsValidator.validateNameCharacters(schemaSetNames); return cpsAdminPersistenceService.getAnchorsBySchemaSetNames(dataspaceName, schemaSetNames); } diff --git a/cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java b/cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java index 9f5c0a3853..6740262bcc 100644 --- a/cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java +++ b/cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java @@ -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) 2022 Bell Canada * Modifications Copyright (C) 2022 TechMahindra Ltd @@ -58,7 +58,7 @@ public class CpsModuleServiceImpl implements CpsModuleService { description = "Time taken to create (and store) a schemaset") public void createSchemaSet(final String dataspaceName, final String schemaSetName, final Map<String, String> yangResourcesNameToContentMap) { - cpsValidator.validateNameCharacters(dataspaceName, schemaSetName); + cpsValidator.validateNameCharacters(dataspaceName); cpsModulePersistenceService.storeSchemaSet(dataspaceName, schemaSetName, yangResourcesNameToContentMap); final YangTextSchemaSourceSet yangTextSchemaSourceSet = timedYangTextSchemaSourceSetBuilder.getYangTextSchemaSourceSet(yangResourcesNameToContentMap); @@ -69,14 +69,20 @@ public class CpsModuleServiceImpl implements CpsModuleService { public void createSchemaSetFromModules(final String dataspaceName, final String schemaSetName, final Map<String, String> newModuleNameToContentMap, final Collection<ModuleReference> allModuleReferences) { - cpsValidator.validateNameCharacters(dataspaceName, schemaSetName); + cpsValidator.validateNameCharacters(dataspaceName); cpsModulePersistenceService.storeSchemaSetFromModules(dataspaceName, schemaSetName, newModuleNameToContentMap, allModuleReferences); } @Override + public boolean schemaSetExists(final String dataspaceName, final String schemaSetName) { + cpsValidator.validateNameCharacters(dataspaceName); + return cpsModulePersistenceService.schemaSetExists(dataspaceName, schemaSetName); + } + + @Override public SchemaSet getSchemaSet(final String dataspaceName, final String schemaSetName) { - cpsValidator.validateNameCharacters(dataspaceName, schemaSetName); + cpsValidator.validateNameCharacters(dataspaceName); final var yangTextSchemaSourceSet = yangTextSchemaSourceSetCache .get(dataspaceName, schemaSetName); return SchemaSet.builder().name(schemaSetName).dataspaceName(dataspaceName) @@ -96,7 +102,7 @@ public class CpsModuleServiceImpl implements CpsModuleService { @Transactional public void deleteSchemaSet(final String dataspaceName, final String schemaSetName, final CascadeDeleteAllowed cascadeDeleteAllowed) { - cpsValidator.validateNameCharacters(dataspaceName, schemaSetName); + cpsValidator.validateNameCharacters(dataspaceName); final Collection<Anchor> anchors = cpsAnchorService.getAnchorsBySchemaSetName(dataspaceName, schemaSetName); if (!anchors.isEmpty() && isCascadeDeleteProhibited(cascadeDeleteAllowed)) { throw new SchemaSetInUseException(dataspaceName, schemaSetName); @@ -112,7 +118,6 @@ public class CpsModuleServiceImpl implements CpsModuleService { @Transactional public void deleteSchemaSetsWithCascade(final String dataspaceName, final Collection<String> schemaSetNames) { cpsValidator.validateNameCharacters(dataspaceName); - cpsValidator.validateNameCharacters(schemaSetNames); final Collection<String> anchorNames = cpsAnchorService.getAnchorsBySchemaSetNames(dataspaceName, schemaSetNames) .stream().map(Anchor::getName).collect(Collectors.toSet()); @@ -127,7 +132,7 @@ public class CpsModuleServiceImpl implements CpsModuleService { public void upgradeSchemaSetFromModules(final String dataspaceName, final String schemaSetName, final Map<String, String> newModuleNameToContentMap, final Collection<ModuleReference> allModuleReferences) { - cpsValidator.validateNameCharacters(dataspaceName, schemaSetName); + cpsValidator.validateNameCharacters(dataspaceName); cpsModulePersistenceService.updateSchemaSetFromModules(dataspaceName, schemaSetName, newModuleNameToContentMap, allModuleReferences); yangTextSchemaSourceSetCache.removeFromCache(dataspaceName, schemaSetName); @@ -169,20 +174,9 @@ public class CpsModuleServiceImpl implements CpsModuleService { return cpsModulePersistenceService.identifyNewModuleReferences(moduleReferencesToCheck); } - @Timed(value = "cps.module.service.module.reference.query.by.attribute", - description = "Time taken to query list of module references by attribute (e.g moduleSetTag)") - @Override - public Collection<ModuleReference> getModuleReferencesByAttribute(final String dataspaceName, - final String anchorName, - final Map<String, String> parentAttributes, - final Map<String, String> childAttributes) { - return cpsModulePersistenceService.getModuleReferencesByAttribute(dataspaceName, anchorName, parentAttributes, - childAttributes); - } - @Override - public void deleteUnusedYangResourceModules() { - cpsModulePersistenceService.deleteUnusedYangResourceModules(); + public void deleteAllUnusedYangModuleData() { + cpsModulePersistenceService.deleteAllUnusedYangModuleData(); } private boolean isCascadeDeleteProhibited(final CascadeDeleteAllowed cascadeDeleteAllowed) { diff --git a/cps-service/src/main/java/org/onap/cps/api/impl/YangTextSchemaSourceSetCache.java b/cps-service/src/main/java/org/onap/cps/api/impl/YangTextSchemaSourceSetCache.java index 8b85dfca32..b893bcea09 100644 --- a/cps-service/src/main/java/org/onap/cps/api/impl/YangTextSchemaSourceSetCache.java +++ b/cps-service/src/main/java/org/onap/cps/api/impl/YangTextSchemaSourceSetCache.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2021 Pantheon.tech * Modifications Copyright (C) 2022 Bell Canada - * Modifications Copyright (C) 2022-2023 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. @@ -60,7 +60,7 @@ public class YangTextSchemaSourceSetCache { */ @Cacheable(key = "#p0.concat('-').concat(#p1)") public YangTextSchemaSourceSet get(final String dataspaceName, final String schemaSetName) { - cpsValidator.validateNameCharacters(dataspaceName, schemaSetName); + cpsValidator.validateNameCharacters(dataspaceName); final Map<String, String> yangResourceNameToContent = cpsModulePersistenceService.getYangSchemaResources(dataspaceName, schemaSetName); return YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent); @@ -78,7 +78,7 @@ public class YangTextSchemaSourceSetCache { @CanIgnoreReturnValue public YangTextSchemaSourceSet updateCache(final String dataspaceName, final String schemaSetName, final YangTextSchemaSourceSet yangTextSchemaSourceSet) { - cpsValidator.validateNameCharacters(dataspaceName, schemaSetName); + cpsValidator.validateNameCharacters(dataspaceName); yangSchemaCacheCounter.incrementAndGet(); return yangTextSchemaSourceSet; } @@ -91,9 +91,8 @@ public class YangTextSchemaSourceSetCache { */ @CacheEvict(key = "#p0.concat('-').concat(#p1)") public void removeFromCache(final String dataspaceName, final String schemaSetName) { - cpsValidator.validateNameCharacters(dataspaceName, schemaSetName); + cpsValidator.validateNameCharacters(dataspaceName); yangSchemaCacheCounter.decrementAndGet(); - // Spring provides implementation for removing object from cache } } diff --git a/cps-service/src/main/java/org/onap/cps/init/DbCleaner.java b/cps-service/src/main/java/org/onap/cps/init/DbCleaner.java deleted file mode 100644 index 6bd3e1f204..0000000000 --- a/cps-service/src/main/java/org/onap/cps/init/DbCleaner.java +++ /dev/null @@ -1,48 +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 java.util.concurrent.TimeUnit; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.onap.cps.api.CpsModuleService; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Service; - -@Slf4j -@RequiredArgsConstructor -@Service -public class DbCleaner { - - private final CpsModuleService cpsModuleService; - - /** - * This method will clean up the db during application start up. - * It wil run once and currently only removes unused yang resource modules. - * - */ - @Scheduled(initialDelay = 1, timeUnit = TimeUnit.SECONDS) - public void cleanDbAtStartUp() { - log.info("CPS Application started, commencing DB clean up"); - cpsModuleService.deleteUnusedYangResourceModules(); - log.info("DB clean up completed"); - } -} diff --git a/cps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java b/cps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java index 4cfc287a5d..b1f8aad88f 100755 --- a/cps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java +++ b/cps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2020-2024 Nordix Foundation + * Copyright (C) 2020-2025 Nordix Foundation * Modifications Copyright (C) 2020-2022 Bell Canada. * Modifications Copyright (C) 2022 TechMahindra Ltd. * ================================================================================ @@ -65,6 +65,14 @@ public interface CpsModulePersistenceService { final Map<String, String> newModuleNameToContentMap, final Collection<ModuleReference> allModuleReferences); + /** + * Checks whether a schema set exists in the specified dataspace. + * + * @param dataspaceName dataspace name + * @param schemaSetName schema set name + * @return {@code true} if the schema set exists in the given dataspace; {@code false} otherwise + */ + boolean schemaSetExists(String dataspaceName, String schemaSetName); /** * Get all schema sets for a given dataspace. @@ -138,35 +146,18 @@ public interface CpsModulePersistenceService { String moduleName, String moduleRevision); /** - * Remove unused Yang Resource Modules. + * Remove any unused Yang Resource Modules and Schema Sets. */ - void deleteUnusedYangResourceModules(); + void deleteAllUnusedYangModuleData(); /** * Identify new module references from those returned by a node compared to what is in CPS already. * The system will ignore the namespace of all module references. * * @param moduleReferencesToCheck the module references ot check - * @returns Collection of {@link ModuleReference} (namespace will be always blank) - * - */ - Collection<ModuleReference> identifyNewModuleReferences( - Collection<ModuleReference> moduleReferencesToCheck); - - /** - * Retrieves module references based on the specified dataspace, anchor, and attribute filters. - - * Constructs and executes a SQL query to find module references by applying filters for parent and child fragments. - * Uses `parentAttributes` for filtering parent fragments and `childAttributes` for filtering child fragments. + * @return Collection of {@link ModuleReference} (namespace will be always blank) * - * @param dataspaceName the name of the dataspace to filter on. - * @param anchorName the name of the anchor to filter on. - * @param parentAttributes a map of attributes for filtering parent fragments. - * @param childAttributes a map of attributes for filtering child fragments. - * @return a collection of {@link ModuleReference} objects matching the criteria. */ - Collection<ModuleReference> getModuleReferencesByAttribute(final String dataspaceName, final String anchorName, - final Map<String, String> parentAttributes, - final Map<String, String> childAttributes); + Collection<ModuleReference> identifyNewModuleReferences(Collection<ModuleReference> moduleReferencesToCheck); } 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() - } -} |