diff options
author | 2025-02-06 16:31:29 +0000 | |
---|---|---|
committer | 2025-02-06 16:31:29 +0000 | |
commit | 5e1fb6f6917d286d6deadc6a00b2de4a55b78f17 (patch) | |
tree | c7ca0841f06acff7c3de6ff51a7b051a1aa565fc /cps-service | |
parent | 2489064ffa94f76a5e49fed8e06d1299ec9cc671 (diff) | |
parent | 4ec2a5d944b4c2bad799e6610f03912f5c955b50 (diff) |
Merge "Fix duplicated yang resource references V2"
Diffstat (limited to 'cps-service')
13 files changed, 105 insertions, 103 deletions
diff --git a/cps-service/src/main/java/org/onap/cps/api/CpsDataService.java b/cps-service/src/main/java/org/onap/cps/api/CpsDataService.java index 345bc8825b..41713746b7 100644 --- a/cps-service/src/main/java/org/onap/cps/api/CpsDataService.java +++ b/cps-service/src/main/java/org/onap/cps/api/CpsDataService.java @@ -314,13 +314,13 @@ public interface CpsDataService { * @param dataspaceName source dataspace name * @param sourceAnchorName source anchor name * @param xpath xpath - * @param yangResourcesNameToContentMap YANG resources (files) map where key is a name and value is content + * @param yangResourceContentPerName YANG resources (files) map where key is a name and value is content * @param targetData target data to be compared in JSON string format * @param fetchDescendantsOption defines the scope of data to fetch: defaulted to INCLUDE_ALL_DESCENDANTS * @return list containing {@link DeltaReport} objects */ List<DeltaReport> getDeltaByDataspaceAnchorAndPayload(String dataspaceName, String sourceAnchorName, String xpath, - Map<String, String> yangResourcesNameToContentMap, + Map<String, String> yangResourceContentPerName, String targetData, FetchDescendantsOption fetchDescendantsOption); 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 c6b8c60ab9..2494be4021 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 @@ -40,21 +40,21 @@ public interface CpsModuleService { * * @param dataspaceName dataspace name * @param schemaSetName schema set name - * @param yangResourcesNameToContentMap yang resources (files) as a mep where key is resource name + * @param yangResourceContentPerName yang resources (files) as a mep where key is resource name * and value is content */ void createSchemaSet(String dataspaceName, String schemaSetName, - Map<String, String> yangResourcesNameToContentMap); + Map<String, String> yangResourceContentPerName); /** * Create or upgrade a schema set from new modules and existing modules or only existing modules. - * @param dataspaceName Dataspace name - * @param schemaSetName schema set name - * @param newModuleNameToContentMap YANG resources map where key is a module name and value is content - * @param allModuleReferences All YANG resource module references + * @param dataspaceName Dataspace name + * @param schemaSetName schema set name + * @param yangResourceContentPerName YANG resources map where key is a name and value is content + * @param allModuleReferences All YANG resource module references */ void createSchemaSetFromModules(String dataspaceName, String schemaSetName, - Map<String, String> newModuleNameToContentMap, + Map<String, String> yangResourceContentPerName, Collection<ModuleReference> allModuleReferences); /** diff --git a/cps-service/src/main/java/org/onap/cps/impl/CpsDataServiceImpl.java b/cps-service/src/main/java/org/onap/cps/impl/CpsDataServiceImpl.java index 71e6f79bb7..9f70ac9132 100644 --- a/cps-service/src/main/java/org/onap/cps/impl/CpsDataServiceImpl.java +++ b/cps-service/src/main/java/org/onap/cps/impl/CpsDataServiceImpl.java @@ -230,7 +230,7 @@ public class CpsDataServiceImpl implements CpsDataService { @Override public List<DeltaReport> getDeltaByDataspaceAnchorAndPayload(final String dataspaceName, final String sourceAnchorName, final String xpath, - final Map<String, String> yangResourcesNameToContentMap, + final Map<String, String> yangResourceContentPerName, final String targetData, final FetchDescendantsOption fetchDescendantsOption) { @@ -243,7 +243,7 @@ public class CpsDataServiceImpl implements CpsDataService { new ArrayList<>(rebuildSourceDataNodes(xpath, sourceAnchor, sourceDataNodes)); final Collection<DataNode> targetDataNodes = - new ArrayList<>(buildTargetDataNodes(sourceAnchor, xpath, yangResourcesNameToContentMap, targetData)); + new ArrayList<>(buildTargetDataNodes(sourceAnchor, xpath, yangResourceContentPerName, targetData)); return cpsDeltaService.getDeltaReports(sourceDataNodesRebuilt, targetDataNodes); } @@ -380,12 +380,12 @@ public class CpsDataServiceImpl implements CpsDataService { } private Collection<DataNode> buildTargetDataNodes(final Anchor sourceAnchor, final String xpath, - final Map<String, String> yangResourcesNameToContentMap, + final Map<String, String> yangResourceContentPerName, final String targetData) { - if (yangResourcesNameToContentMap.isEmpty()) { + if (yangResourceContentPerName.isEmpty()) { return buildDataNodesWithAnchorAndXpath(sourceAnchor, xpath, targetData, ContentType.JSON); } else { - return buildDataNodesWithYangResourceAndXpath(yangResourcesNameToContentMap, xpath, + return buildDataNodesWithYangResourceAndXpath(yangResourceContentPerName, xpath, targetData, ContentType.JSON); } } @@ -454,12 +454,12 @@ public class CpsDataServiceImpl implements CpsDataService { } private Collection<DataNode> buildDataNodesWithParentNodeXpath( - final Map<String, String> yangResourcesNameToContentMap, final String xpath, + final Map<String, String> yangResourceContentPerName, final String xpath, final String nodeData, final ContentType contentType) { if (isRootNodeXpath(xpath)) { final ContainerNode containerNode = yangParser.parseData(contentType, nodeData, - yangResourcesNameToContentMap, PARENT_NODE_XPATH_FOR_ROOT_NODE_XPATH); + yangResourceContentPerName, PARENT_NODE_XPATH_FOR_ROOT_NODE_XPATH); final Collection<DataNode> dataNodes = new DataNodeBuilder() .withContainerNode(containerNode) .buildCollection(); @@ -470,7 +470,7 @@ public class CpsDataServiceImpl implements CpsDataService { } final String normalizedParentNodeXpath = CpsPathUtil.getNormalizedXpath(xpath); final ContainerNode containerNode = - yangParser.parseData(contentType, nodeData, yangResourcesNameToContentMap, normalizedParentNodeXpath); + yangParser.parseData(contentType, nodeData, yangResourceContentPerName, normalizedParentNodeXpath); final Collection<DataNode> dataNodes = new DataNodeBuilder() .withParentNodeXpath(normalizedParentNodeXpath) .withContainerNode(containerNode) @@ -496,18 +496,18 @@ public class CpsDataServiceImpl implements CpsDataService { } private Collection<DataNode> buildDataNodesWithYangResourceAndXpath( - final Map<String, String> yangResourcesNameToContentMap, final String xpath, + final Map<String, String> yangResourceContentPerName, final String xpath, final String nodeData, final ContentType contentType) { if (!isRootNodeXpath(xpath)) { final String parentNodeXpath = CpsPathUtil.getNormalizedParentXpath(xpath); if (parentNodeXpath.isEmpty()) { - return buildDataNodesWithParentNodeXpath(yangResourcesNameToContentMap, ROOT_NODE_XPATH, + return buildDataNodesWithParentNodeXpath(yangResourceContentPerName, ROOT_NODE_XPATH, nodeData, contentType); } - return buildDataNodesWithParentNodeXpath(yangResourcesNameToContentMap, parentNodeXpath, + return buildDataNodesWithParentNodeXpath(yangResourceContentPerName, parentNodeXpath, nodeData, contentType); } - return buildDataNodesWithParentNodeXpath(yangResourcesNameToContentMap, xpath, nodeData, contentType); + return buildDataNodesWithParentNodeXpath(yangResourceContentPerName, xpath, nodeData, contentType); } private static boolean isRootNodeXpath(final String xpath) { diff --git a/cps-service/src/main/java/org/onap/cps/impl/CpsModuleServiceImpl.java b/cps-service/src/main/java/org/onap/cps/impl/CpsModuleServiceImpl.java index b16abcc31f..e50325c739 100644 --- a/cps-service/src/main/java/org/onap/cps/impl/CpsModuleServiceImpl.java +++ b/cps-service/src/main/java/org/onap/cps/impl/CpsModuleServiceImpl.java @@ -57,21 +57,21 @@ public class CpsModuleServiceImpl implements CpsModuleService { @Timed(value = "cps.module.service.schemaset.create", description = "Time taken to create (and store) a schemaset") public void createSchemaSet(final String dataspaceName, final String schemaSetName, - final Map<String, String> yangResourcesNameToContentMap) { + final Map<String, String> yangResourceContentPerName) { cpsValidator.validateNameCharacters(dataspaceName); - cpsModulePersistenceService.storeSchemaSet(dataspaceName, schemaSetName, yangResourcesNameToContentMap); + cpsModulePersistenceService.createSchemaSet(dataspaceName, schemaSetName, yangResourceContentPerName); final YangTextSchemaSourceSet yangTextSchemaSourceSet = - timedYangTextSchemaSourceSetBuilder.getYangTextSchemaSourceSet(yangResourcesNameToContentMap); + timedYangTextSchemaSourceSetBuilder.getYangTextSchemaSourceSet(yangResourceContentPerName); yangTextSchemaSourceSetCache.updateCache(dataspaceName, schemaSetName, yangTextSchemaSourceSet); } @Override public void createSchemaSetFromModules(final String dataspaceName, final String schemaSetName, - final Map<String, String> newModuleNameToContentMap, + final Map<String, String> yangResourceContentPerName, final Collection<ModuleReference> allModuleReferences) { cpsValidator.validateNameCharacters(dataspaceName); - cpsModulePersistenceService.storeSchemaSetFromModules(dataspaceName, schemaSetName, - newModuleNameToContentMap, allModuleReferences); + cpsModulePersistenceService.createSchemaSetFromNewAndExistingModules(dataspaceName, schemaSetName, + yangResourceContentPerName, allModuleReferences); } @Override @@ -83,7 +83,7 @@ public class CpsModuleServiceImpl implements CpsModuleService { @Override public SchemaSet getSchemaSet(final String dataspaceName, final String schemaSetName) { cpsValidator.validateNameCharacters(dataspaceName); - final var yangTextSchemaSourceSet = yangTextSchemaSourceSetCache + final YangTextSchemaSourceSet yangTextSchemaSourceSet = yangTextSchemaSourceSetCache .get(dataspaceName, schemaSetName); return SchemaSet.builder().name(schemaSetName).dataspaceName(dataspaceName) .moduleReferences(yangTextSchemaSourceSet.getModuleReferences()).build(); @@ -130,15 +130,14 @@ public class CpsModuleServiceImpl implements CpsModuleService { @Override public void upgradeSchemaSetFromModules(final String dataspaceName, final String schemaSetName, - final Map<String, String> newModuleNameToContentMap, + final Map<String, String> newYangResourceContentPerModule, final Collection<ModuleReference> allModuleReferences) { cpsValidator.validateNameCharacters(dataspaceName); - cpsModulePersistenceService.updateSchemaSetFromModules(dataspaceName, schemaSetName, - newModuleNameToContentMap, allModuleReferences); + cpsModulePersistenceService.updateSchemaSetFromNewAndExistingModules(dataspaceName, schemaSetName, + newYangResourceContentPerModule, allModuleReferences); yangTextSchemaSourceSetCache.removeFromCache(dataspaceName, schemaSetName); } - @Override public Collection<ModuleReference> getYangResourceModuleReferences(final String dataspaceName) { cpsValidator.validateNameCharacters(dataspaceName); diff --git a/cps-service/src/main/java/org/onap/cps/init/AbstractModelLoader.java b/cps-service/src/main/java/org/onap/cps/init/AbstractModelLoader.java index e864633f25..a80239039a 100644 --- a/cps-service/src/main/java/org/onap/cps/init/AbstractModelLoader.java +++ b/cps-service/src/main/java/org/onap/cps/init/AbstractModelLoader.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2023-2024 Nordix Foundation + * Copyright (C) 2023-2025 Nordix Foundation * Modifications Copyright (C) 2024 TechMahindra Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -77,7 +77,7 @@ public abstract class AbstractModelLoader implements ModelLoader { } catch (final AlreadyDefinedException alreadyDefinedException) { log.warn("Creating new schema set failed as schema set already exists"); } catch (final Exception exception) { - log.error("Creating schema set failed: {} ", exception.getMessage()); + log.error("Creating schema set {} failed: {} ", schemaSetName, exception.getMessage()); throw new ModelOnboardingException("Creating schema set failed", exception.getMessage()); } } 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 86ad50252d..02e1b6c754 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 @@ -36,34 +36,37 @@ public interface CpsModulePersistenceService { /** * Stores Schema Set. * - * @param dataspaceName dataspace name - * @param schemaSetName schema set name - * @param yangResourcesNameToContentMap YANG resources (files) map where key is a name and value is content + * @param dataspaceName dataspace name + * @param schemaSetName schema set name + * @param yangResourceContentPerName a map of YANG resources map where key is a name and value is content */ - void storeSchemaSet(String dataspaceName, String schemaSetName, Map<String, String> yangResourcesNameToContentMap); + void createSchemaSet(String dataspaceName, String schemaSetName, Map<String, String> yangResourceContentPerName); /** * Stores a new schema set from new modules and existing modules. * - * @param dataspaceName Dataspace name - * @param schemaSetName Schema set name - * @param newModuleNameToContentMap YANG resources map where key is a module name and value is content - * @param allModuleReferences All YANG resources module references + * @param dataspaceName dataspace name + * @param schemaSetName Schema set name + * @param newYangResourceContentPerName a map of only the new YANG resources + * the key is a name and value is its content + * @param allModuleReferences all YANG resources module references */ - void storeSchemaSetFromModules(String dataspaceName, String schemaSetName, - Map<String, String> newModuleNameToContentMap, Collection<ModuleReference> allModuleReferences); + void createSchemaSetFromNewAndExistingModules(String dataspaceName, String schemaSetName, + Map<String, String> newYangResourceContentPerName, + Collection<ModuleReference> allModuleReferences); /** * Update an existing schema set from new modules and existing modules. * - * @param dataspaceName Dataspace name + * @param dataspaceName dataspace name * @param schemaSetName Schema set name - * @param newModuleNameToContentMap YANG resources map where key is a module name and value is content - * @param allModuleReferences All YANG resources module references + * @param newYangResourcesPerName a map of only the new YANG resources + * the key is a module name and value is its content + * @param allModuleReferences all YANG resources module references */ - void updateSchemaSetFromModules(final String dataspaceName, final String schemaSetName, - final Map<String, String> newModuleNameToContentMap, - final Collection<ModuleReference> allModuleReferences); + void updateSchemaSetFromNewAndExistingModules(String dataspaceName, String schemaSetName, + Map<String, String> newYangResourcesPerName, + Collection<ModuleReference> allModuleReferences); /** * Checks whether a schema set exists in the specified dataspace. diff --git a/cps-service/src/main/java/org/onap/cps/utils/YangParser.java b/cps-service/src/main/java/org/onap/cps/utils/YangParser.java index 08f450e2f1..5dfeb2fb3f 100644 --- a/cps-service/src/main/java/org/onap/cps/utils/YangParser.java +++ b/cps-service/src/main/java/org/onap/cps/utils/YangParser.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2024 Nordix Foundation. + * Copyright (C) 2024-2025 Nordix Foundation. * Modifications Copyright (C) 2024 TechMahindra Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -71,17 +71,17 @@ public class YangParser { /** * Parses data into (normalized) ContainerNode according to schema context for the given yang resource. * - * @param nodeData data string - * @param yangResourcesNameToContentMap yang resource to content map - * @return the NormalizedNode object + * @param nodeData data string + * @param yangResourceContentPerName yang resource content per name + * @return the NormalizedNode object */ @Timed(value = "cps.utils.yangparser.nodedata.with.parent.with.yangResourceMap.parse", description = "Time taken to parse node data with a parent") public ContainerNode parseData(final ContentType contentType, final String nodeData, - final Map<String, String> yangResourcesNameToContentMap, + final Map<String, String> yangResourceContentPerName, final String parentNodeXpath) { - final SchemaContext schemaContext = getSchemaContext(yangResourcesNameToContentMap); + final SchemaContext schemaContext = getSchemaContext(yangResourceContentPerName); return yangParserHelper.parseData(contentType, nodeData, schemaContext, parentNodeXpath, VALIDATE_AND_PARSE); } @@ -114,8 +114,8 @@ public class YangParser { anchor.getSchemaSetName()).getSchemaContext(); } - private SchemaContext getSchemaContext(final Map<String, String> yangResourcesNameToContentMap) { - return timedYangTextSchemaSourceSetBuilder.getYangTextSchemaSourceSet(yangResourcesNameToContentMap) + private SchemaContext getSchemaContext(final Map<String, String> yangResourceContentPerName) { + return timedYangTextSchemaSourceSetBuilder.getYangTextSchemaSourceSet(yangResourceContentPerName) .getSchemaContext(); } diff --git a/cps-service/src/main/java/org/onap/cps/yang/TimedYangTextSchemaSourceSetBuilder.java b/cps-service/src/main/java/org/onap/cps/yang/TimedYangTextSchemaSourceSetBuilder.java index 013faff0c8..9b2ac944dc 100644 --- a/cps-service/src/main/java/org/onap/cps/yang/TimedYangTextSchemaSourceSetBuilder.java +++ b/cps-service/src/main/java/org/onap/cps/yang/TimedYangTextSchemaSourceSetBuilder.java @@ -30,8 +30,8 @@ public class TimedYangTextSchemaSourceSetBuilder { @Timed(value = "cps.yangtextschemasourceset.build", description = "Time taken to build a yang text schema source set") public YangTextSchemaSourceSet getYangTextSchemaSourceSet( - final Map<String, String> yangResourcesNameToContentMap) { - return YangTextSchemaSourceSetBuilder.of(yangResourcesNameToContentMap); + final Map<String, String> yangResourceContentPerName) { + return YangTextSchemaSourceSetBuilder.of(yangResourceContentPerName); } } diff --git a/cps-service/src/test/groovy/org/onap/cps/impl/CpsDataServiceImplSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/impl/CpsDataServiceImplSpec.groovy index 34d2b7564a..abcda6c696 100644 --- a/cps-service/src/test/groovy/org/onap/cps/impl/CpsDataServiceImplSpec.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/impl/CpsDataServiceImplSpec.groovy @@ -248,10 +248,10 @@ class CpsDataServiceImplSpec extends Specification { def 'Get delta between anchor and payload with user provided schema #scenario'() { given: 'user provided schema set ' - def yangResourcesNameToContentMap = TestUtils.getYangResourcesAsMap('bookstore.yang') - setupSchemaSetMocksForDelta(yangResourcesNameToContentMap) + def yangResourceContentPerName = TestUtils.getYangResourcesAsMap('bookstore.yang') + setupSchemaSetMocksForDelta(yangResourceContentPerName) when: 'attempt to get delta between an anchor and a JSON payload' - objectUnderTest.getDeltaByDataspaceAnchorAndPayload(dataspaceName, anchorName, xpath, yangResourcesNameToContentMap, jsonData, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) + objectUnderTest.getDeltaByDataspaceAnchorAndPayload(dataspaceName, anchorName, xpath, yangResourceContentPerName, jsonData, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) then: 'dataspacename and anchor names are validated' 1 * mockCpsValidator.validateNameCharacters(['some-dataspace', 'some-anchor']) and: 'source data nodes are fetched using appropriate persistence layer method' @@ -285,10 +285,10 @@ class CpsDataServiceImplSpec extends Specification { def 'Delta between anchor and payload error scenario #scenario'() { given: 'schema set for given anchor and dataspace references bookstore model' - def yangResourcesNameToContentMap = TestUtils.getYangResourcesAsMap('bookstore.yang') - setupSchemaSetMocksForDelta(yangResourcesNameToContentMap) + def yangResourceContentPerName = TestUtils.getYangResourcesAsMap('bookstore.yang') + setupSchemaSetMocksForDelta(yangResourceContentPerName) when: 'attempt to get delta between anchor and payload' - objectUnderTest.getDeltaByDataspaceAnchorAndPayload(dataspaceName, anchorName, xpath, yangResourcesNameToContentMap, jsonData, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) + objectUnderTest.getDeltaByDataspaceAnchorAndPayload(dataspaceName, anchorName, xpath, yangResourceContentPerName, jsonData, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) then: 'expected exception is thrown' thrown(DataValidationException) where: 'following parameters were used' @@ -654,11 +654,11 @@ class CpsDataServiceImplSpec extends Specification { mockYangTextSchemaSourceSet.getSchemaContext() >> schemaContext } - def setupSchemaSetMocksForDelta(Map<String, String> yangResourcesNameToContentMap) { + def setupSchemaSetMocksForDelta(Map<String, String> yangResourceContentPerName) { def mockYangTextSchemaSourceSet = Mock(YangTextSchemaSourceSet) - mockTimedYangTextSchemaSourceSetBuilder.getYangTextSchemaSourceSet(yangResourcesNameToContentMap) >> mockYangTextSchemaSourceSet + mockTimedYangTextSchemaSourceSetBuilder.getYangTextSchemaSourceSet(yangResourceContentPerName) >> mockYangTextSchemaSourceSet mockYangTextSchemaSourceSetCache.get(_, _) >> mockYangTextSchemaSourceSet - def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourcesNameToContentMap).getSchemaContext() + def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceContentPerName).getSchemaContext() mockYangTextSchemaSourceSet.getSchemaContext() >> schemaContext } diff --git a/cps-service/src/test/groovy/org/onap/cps/impl/CpsModuleServiceImplSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/impl/CpsModuleServiceImplSpec.groovy index 041ce605c4..48db53c882 100644 --- a/cps-service/src/test/groovy/org/onap/cps/impl/CpsModuleServiceImplSpec.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/impl/CpsModuleServiceImplSpec.groovy @@ -56,7 +56,7 @@ class CpsModuleServiceImplSpec extends Specification { when: 'Create schema set method is invoked' objectUnderTest.createSchemaSet('someDataspace', 'schemaSetName@with Special!Characters', [:]) then: 'Parameters are validated and processing is delegated to persistence service' - 1 * mockCpsModulePersistenceService.storeSchemaSet('someDataspace', 'schemaSetName@with Special!Characters', [:]) + 1 * mockCpsModulePersistenceService.createSchemaSet('someDataspace', 'schemaSetName@with Special!Characters', [:]) and: 'the CpsValidator is called on the dataspaceName' 1 * mockCpsValidator.validateNameCharacters('someDataspace') } @@ -68,16 +68,16 @@ class CpsModuleServiceImplSpec extends Specification { 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) + 1 * mockCpsModulePersistenceService.createSchemaSetFromNewAndExistingModules('someDataspaceName', 'someSchemaSetName', [newModule: 'newContent'], listOfExistingModulesModuleReference) and: 'the CpsValidator is called on the dataspaceName' 1 * mockCpsValidator.validateNameCharacters('someDataspaceName') } def 'Create schema set from invalid resources'() { given: 'Invalid yang resource as name-to-content map' - def yangResourcesNameToContentMap = TestUtils.getYangResourcesAsMap('invalid.yang') + def yangResourceContentPerName = TestUtils.getYangResourcesAsMap('invalid.yang') when: 'Create schema set method is invoked' - objectUnderTest.createSchemaSet('someDataspace', 'someSchemaSet', yangResourcesNameToContentMap) + objectUnderTest.createSchemaSet('someDataspace', 'someSchemaSet', yangResourceContentPerName) then: 'Model validation exception is thrown' thrown(ModelValidationException) } @@ -85,7 +85,7 @@ class CpsModuleServiceImplSpec extends Specification { def 'Create schema set with duplicate yang resource exception in persistence layer.'() { given: 'the persistence layer throws an duplicated yang resource exception' def originalException = new DuplicatedYangResourceException('name', '123', null) - mockCpsModulePersistenceService.storeSchemaSet(*_) >> { throw originalException } + mockCpsModulePersistenceService.createSchemaSet(*_) >> { throw originalException } when: 'attempt to create schema set' objectUnderTest.createSchemaSet('someDataspace', 'someSchemaSet', [:]) then: 'the same duplicated yang resource exception is thrown (up)' @@ -98,9 +98,9 @@ class CpsModuleServiceImplSpec extends Specification { def 'Get schema set by name and dataspace.'() { given: 'an already present schema set' - def yangResourcesNameToContentMap = TestUtils.getYangResourcesAsMap('bookstore.yang') + def yangResourceContentPerName = TestUtils.getYangResourcesAsMap('bookstore.yang') and: 'yang resource cache returns the expected schema set' - mockYangTextSchemaSourceSetCache.get('someDataspace', 'schemaSetName@with Special!Characters') >> YangTextSchemaSourceSetBuilder.of(yangResourcesNameToContentMap) + mockYangTextSchemaSourceSetCache.get('someDataspace', 'schemaSetName@with Special!Characters') >> YangTextSchemaSourceSetBuilder.of(yangResourceContentPerName) when: 'get schema set method is invoked' def result = objectUnderTest.getSchemaSet('someDataspace', 'schemaSetName@with Special!Characters') then: 'the correct schema set is returned' diff --git a/cps-service/src/test/groovy/org/onap/cps/impl/E2ENetworkSliceSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/impl/E2ENetworkSliceSpec.groovy index 8171209947..db5b4f104e 100755 --- a/cps-service/src/test/groovy/org/onap/cps/impl/E2ENetworkSliceSpec.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/impl/E2ENetworkSliceSpec.groovy @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2021-2024 Nordix Foundation. + * Copyright (C) 2021-2025 Nordix Foundation. * Modifications Copyright (C) 2021-2022 Bell Canada. * Modifications Copyright (C) 2021 Pantheon.tech * Modifications Copyright (C) 2022-2024 TechMahindra Ltd. @@ -66,32 +66,32 @@ class E2ENetworkSliceSpec extends Specification { def 'E2E model can be parsed by CPS.'() { given: 'Valid yang resource as name-to-content map' - def yangResourcesNameToContentMap = TestUtils.getYangResourcesAsMap( + def yangResourceContentPerName = TestUtils.getYangResourcesAsMap( 'ietf/ietf-inet-types@2013-07-15.yang', 'ietf/ietf-yang-types@2013-07-15.yang', 'e2e/basic/ran-network2020-08-06.yang' ) when: 'Create schema set method is invoked' - cpsModuleServiceImpl.createSchemaSet(dataspaceName, schemaSetName, yangResourcesNameToContentMap) + cpsModuleServiceImpl.createSchemaSet(dataspaceName, schemaSetName, yangResourceContentPerName) then: 'Parameters are validated and processing is delegated to persistence service' - 1 * mockModuleStoreService.storeSchemaSet(dataspaceName, schemaSetName, yangResourcesNameToContentMap) + 1 * mockModuleStoreService.createSchemaSet(dataspaceName, schemaSetName, yangResourceContentPerName) } def 'E2E Coverage Area-Tracking Area & TA-Cell mapping model can be parsed by CPS.'() { given: 'Valid yang resource as name-to-content map' - def yangResourcesNameToContentMap = TestUtils.getYangResourcesAsMap( + def yangResourceContentPerName = TestUtils.getYangResourcesAsMap( 'e2e/basic/cps-cavsta-onap-internal2021-01-28.yang') when: 'Create schema set method is invoked' - cpsModuleServiceImpl.createSchemaSet(dataspaceName, schemaSetName, yangResourcesNameToContentMap) + cpsModuleServiceImpl.createSchemaSet(dataspaceName, schemaSetName, yangResourceContentPerName) then: 'Parameters are validated and processing is delegated to persistence service' - 1 * mockModuleStoreService.storeSchemaSet(dataspaceName, schemaSetName, yangResourcesNameToContentMap) + 1 * mockModuleStoreService.createSchemaSet(dataspaceName, schemaSetName, yangResourceContentPerName) } def 'E2E Coverage Area-Tracking Area & TA-Cell mapping data can be parsed by CPS.'() { given: 'Valid yang resource as name-to-content map' - def yangResourcesNameToContentMap = TestUtils.getYangResourcesAsMap( + def yangResourceContentPerName = TestUtils.getYangResourcesAsMap( 'e2e/basic/cps-cavsta-onap-internal2021-01-28.yang') - def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourcesNameToContentMap).getSchemaContext() + def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceContentPerName).getSchemaContext() def dataNodeStored and : 'a valid json is provided for the model' def jsonData = TestUtils.getResourceFileContent('e2e/basic/cps-Cavsta-Data.txt') @@ -99,7 +99,7 @@ class E2ENetworkSliceSpec extends Specification { mockCpsAnchorService.getAnchor(dataspaceName, anchorName) >> new Anchor().builder().name(anchorName).schemaSetName(schemaSetName).dataspaceName(dataspaceName).build() mockYangTextSchemaSourceSetCache.get(dataspaceName, schemaSetName) >> - YangTextSchemaSourceSetBuilder.of(yangResourcesNameToContentMap) + YangTextSchemaSourceSetBuilder.of(yangResourceContentPerName) mockModuleStoreService.getYangSchemaResources(dataspaceName, schemaSetName) >> schemaContext when: 'saveData method is invoked' cpsDataServiceImpl.saveData(dataspaceName, anchorName, jsonData, noTimestamp) @@ -123,15 +123,15 @@ class E2ENetworkSliceSpec extends Specification { def 'E2E Coverage Area-Tracking Area & TA-Cell mapping data can be parsed for RAN inventory.'() { def dataNodeStored given: 'valid yang resource as name-to-content map' - def yangResourcesNameToContentMap = TestUtils.getYangResourcesAsMap( + def yangResourceContentPerName = TestUtils.getYangResourcesAsMap( 'e2e/basic/cps-ran-inventory@2021-01-28.yang') - def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourcesNameToContentMap).getSchemaContext() + def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceContentPerName).getSchemaContext() and : 'a valid json is provided for the model' def jsonData = TestUtils.getResourceFileContent('e2e/basic/cps-ran-inventory-data.json') and : 'all the further dependencies are mocked ' mockCpsAnchorService.getAnchor('someDataspace', 'someAnchor') >> new Anchor().builder().name('someAnchor').schemaSetName('someSchemaSet').dataspaceName(dataspaceName).build() - mockYangTextSchemaSourceSetCache.get('someDataspace', 'someSchemaSet') >> YangTextSchemaSourceSetBuilder.of(yangResourcesNameToContentMap) + mockYangTextSchemaSourceSetCache.get('someDataspace', 'someSchemaSet') >> YangTextSchemaSourceSetBuilder.of(yangResourceContentPerName) mockModuleStoreService.getYangSchemaResources('someDataspace', 'someSchemaSet') >> schemaContext when: 'saveData method is invoked' cpsDataServiceImpl.saveData('someDataspace', 'someAnchor', jsonData, noTimestamp) @@ -161,7 +161,7 @@ class E2ENetworkSliceSpec extends Specification { def 'E2E RAN Schema Model.'(){ given: 'yang resources' - def yangResourcesNameToContentMap = TestUtils.getYangResourcesAsMap( + def yangResourceContentPerName = TestUtils.getYangResourcesAsMap( 'ietf/ietf-inet-types@2013-07-15.yang', 'ietf/ietf-yang-types@2013-07-15.yang', 'e2e/basic/cps-ran-schema-model@2021-05-19.yang' @@ -169,7 +169,7 @@ class E2ENetworkSliceSpec extends Specification { and : 'json data' def jsonData = TestUtils.getResourceFileContent('e2e/basic/cps-ran-schema-model-data-v4.json') expect: 'schema context is built with no exception indicating the schema set being valid ' - def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourcesNameToContentMap).getSchemaContext() + def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceContentPerName).getSchemaContext() and: 'data is parsed with no exception indicating the model match' new YangParserHelper().parseData(ContentType.JSON, jsonData, schemaContext, '', false) != null } diff --git a/cps-service/src/test/groovy/org/onap/cps/impl/YangTextSchemaSourceSetCacheSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/impl/YangTextSchemaSourceSetCacheSpec.groovy index 6694e7712f..e71782ce4f 100644 --- a/cps-service/src/test/groovy/org/onap/cps/impl/YangTextSchemaSourceSetCacheSpec.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/impl/YangTextSchemaSourceSetCacheSpec.groovy @@ -65,13 +65,13 @@ class YangTextSchemaSourceSetCacheSpec extends Specification { given: 'cache is empty' yangResourceCacheImpl.clear() and: 'a schema set exists' - def yangResourcesNameToContentMap = TestUtils.getYangResourcesAsMap('bookstore.yang') - def expectedYangTextSchemaSourceSet = YangTextSchemaSourceSetBuilder.of(yangResourcesNameToContentMap) + def yangResourceContentPerName = TestUtils.getYangResourcesAsMap('bookstore.yang') + def expectedYangTextSchemaSourceSet = YangTextSchemaSourceSetBuilder.of(yangResourceContentPerName) when: 'schema-set information is asked' def result = objectUnderTest.get('my-dataspace', 'my-schemaset') then: 'information fetched from cps module persistence' 1 * mockModuleStoreService.getYangSchemaResources('my-dataspace', 'my-schemaset') - >> yangResourcesNameToContentMap + >> yangResourceContentPerName and: 'stored in the cache' def cachedValue = getCachedValue('my-dataspace', 'my-schemaset') assert cachedValue.getModuleReferences() == expectedYangTextSchemaSourceSet.getModuleReferences() @@ -83,8 +83,8 @@ class YangTextSchemaSourceSetCacheSpec extends Specification { def 'Cache Hit: Respond from cache'() { given: 'a schema set exists' - def yangResourcesNameToContentMap = TestUtils.getYangResourcesAsMap('bookstore.yang') - def expectedYangTextSchemaSourceSet = YangTextSchemaSourceSetBuilder.of(yangResourcesNameToContentMap) + def yangResourceContentPerName = TestUtils.getYangResourcesAsMap('bookstore.yang') + def expectedYangTextSchemaSourceSet = YangTextSchemaSourceSetBuilder.of(yangResourceContentPerName) and: 'stored in cache' yangResourceCacheImpl.put(getCacheKey('my-dataspace', 'my-schemaset'), expectedYangTextSchemaSourceSet) when: 'schema-set information is asked' @@ -97,8 +97,8 @@ class YangTextSchemaSourceSetCacheSpec extends Specification { def 'Cache Update: when no data exist in the cache'() { given: 'a schema set exists' - def yangResourcesNameToContentMap = TestUtils.getYangResourcesAsMap('bookstore.yang') - def yangTextSchemaSourceSet = YangTextSchemaSourceSetBuilder.of(yangResourcesNameToContentMap) + def yangResourceContentPerName = TestUtils.getYangResourcesAsMap('bookstore.yang') + def yangTextSchemaSourceSet = YangTextSchemaSourceSetBuilder.of(yangResourceContentPerName) when: 'cache is updated' objectUnderTest.updateCache('my-dataspace', 'my-schemaset', yangTextSchemaSourceSet) then: 'cached value is same as expected' @@ -110,8 +110,8 @@ class YangTextSchemaSourceSetCacheSpec extends Specification { def 'Cache Evict:with invalid #scenario'() { given: 'a schema set exists in cache' - def yangResourcesNameToContentMap = TestUtils.getYangResourcesAsMap('bookstore.yang') - def yangTextSchemaSourceSet = YangTextSchemaSourceSetBuilder.of(yangResourcesNameToContentMap) + def yangResourceContentPerName = TestUtils.getYangResourcesAsMap('bookstore.yang') + def yangTextSchemaSourceSet = YangTextSchemaSourceSetBuilder.of(yangResourceContentPerName) yangResourceCacheImpl.put(getCacheKey('my-dataspace', 'my-schemaset'), yangTextSchemaSourceSet) def cachedValue = getCachedValue('my-dataspace', 'my-schemaset') assert cachedValue.getModuleReferences() == yangTextSchemaSourceSet.getModuleReferences() diff --git a/cps-service/src/test/groovy/org/onap/cps/utils/YangParserSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/utils/YangParserSpec.groovy index a2fadb7e9f..cb7a16cb84 100644 --- a/cps-service/src/test/groovy/org/onap/cps/utils/YangParserSpec.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/utils/YangParserSpec.groovy @@ -40,7 +40,7 @@ class YangParserSpec extends Specification { def objectUnderTest = new YangParser(mockYangParserHelper, mockYangTextSchemaSourceSetCache, mockTimedYangTextSchemaSourceSetBuilder) def anchor = new Anchor(dataspaceName: 'my dataspace', schemaSetName: 'my schema') - def yangResourcesNameToContentMap = TestUtils.getYangResourcesAsMap('bookstore.yang') + def yangResourceContentPerName = TestUtils.getYangResourcesAsMap('bookstore.yang') def mockYangTextSchemaSourceSet = Mock(YangTextSchemaSourceSet) def mockSchemaContext = Mock(SchemaContext) def containerNodeFromYangUtils = Mock(ContainerNode) @@ -91,9 +91,9 @@ class YangParserSpec extends Specification { def 'Parsing data with yang resource to context map.'() { given: 'the schema source set for the yang resource map is returned' - mockTimedYangTextSchemaSourceSetBuilder.getYangTextSchemaSourceSet(yangResourcesNameToContentMap) >> mockYangTextSchemaSourceSet + mockTimedYangTextSchemaSourceSetBuilder.getYangTextSchemaSourceSet(yangResourceContentPerName) >> mockYangTextSchemaSourceSet when: 'parsing some json data' - def result = objectUnderTest.parseData(ContentType.JSON, 'some json', yangResourcesNameToContentMap, noParent) + def result = objectUnderTest.parseData(ContentType.JSON, 'some json', yangResourceContentPerName, noParent) then: 'the yang parser helper always returns a container node' 1 * mockYangParserHelper.parseData(ContentType.JSON, 'some json', mockSchemaContext, noParent, validateAndParse) >> containerNodeFromYangUtils and: 'the result is the same container node as return from yang utils' |