2 * ============LICENSE_START=======================================================
\r
3 * Copyright (C) 2021-2024 Nordix Foundation.
\r
4 * Modifications Copyright (C) 2021-2022 Bell Canada.
\r
5 * Modifications Copyright (C) 2021 Pantheon.tech
\r
6 * Modifications Copyright (C) 2022-2023 TechMahindra Ltd.
\r
7 * ================================================================================
\r
8 * Licensed under the Apache License, Version 2.0 (the "License");
\r
9 * you may not use this file except in compliance with the License.
\r
10 * You may obtain a copy of the License at
\r
12 * http://www.apache.org/licenses/LICENSE-2.0
\r
14 * Unless required by applicable law or agreed to in writing, software
\r
15 * distributed under the License is distributed on an "AS IS" BASIS,
\r
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
17 * See the License for the specific language governing permissions and
\r
18 * limitations under the License.
\r
20 * SPDX-License-Identifier: Apache-2.0
\r
21 * ============LICENSE_END=========================================================
\r
24 package org.onap.cps.api.impl
\r
26 import org.onap.cps.TestUtils
\r
27 import org.onap.cps.api.CpsAnchorService
\r
28 import org.onap.cps.api.CpsDeltaService
\r
29 import org.onap.cps.spi.CpsDataPersistenceService
\r
30 import org.onap.cps.spi.CpsModulePersistenceService
\r
31 import org.onap.cps.spi.model.Anchor
\r
32 import org.onap.cps.spi.utils.CpsValidator
\r
33 import org.onap.cps.utils.ContentType
\r
34 import org.onap.cps.utils.YangParser
\r
35 import org.onap.cps.utils.YangParserHelper
\r
36 import org.onap.cps.yang.TimedYangTextSchemaSourceSetBuilder
\r
37 import org.onap.cps.yang.YangTextSchemaSourceSetBuilder
\r
38 import spock.lang.Specification
\r
40 class E2ENetworkSliceSpec extends Specification {
\r
41 def mockModuleStoreService = Mock(CpsModulePersistenceService)
\r
42 def mockDataStoreService = Mock(CpsDataPersistenceService)
\r
43 def mockCpsAnchorService = Mock(CpsAnchorService)
\r
44 def mockYangTextSchemaSourceSetCache = Mock(YangTextSchemaSourceSetCache)
\r
45 def mockCpsValidator = Mock(CpsValidator)
\r
46 def timedYangTextSchemaSourceSetBuilder = new TimedYangTextSchemaSourceSetBuilder()
\r
47 def yangParser = new YangParser(new YangParserHelper(), mockYangTextSchemaSourceSetCache)
\r
48 def mockCpsDeltaService = Mock(CpsDeltaService)
\r
50 def cpsModuleServiceImpl = new CpsModuleServiceImpl(mockModuleStoreService,
\r
51 mockYangTextSchemaSourceSetCache, mockCpsAnchorService, mockCpsValidator,timedYangTextSchemaSourceSetBuilder)
\r
53 def cpsDataServiceImpl = new CpsDataServiceImpl(mockDataStoreService, mockCpsAnchorService, mockCpsValidator, yangParser, mockCpsDeltaService)
\r
55 def dataspaceName = 'someDataspace'
\r
56 def anchorName = 'someAnchor'
\r
57 def schemaSetName = 'someSchemaSet'
\r
58 def noTimestamp = null
\r
60 def 'E2E model can be parsed by CPS.'() {
\r
61 given: 'Valid yang resource as name-to-content map'
\r
62 def yangResourcesNameToContentMap = TestUtils.getYangResourcesAsMap(
\r
63 'ietf/ietf-inet-types@2013-07-15.yang',
\r
64 'ietf/ietf-yang-types@2013-07-15.yang',
\r
65 'e2e/basic/ran-network2020-08-06.yang'
\r
67 when: 'Create schema set method is invoked'
\r
68 cpsModuleServiceImpl.createSchemaSet(dataspaceName, schemaSetName, yangResourcesNameToContentMap)
\r
69 then: 'Parameters are validated and processing is delegated to persistence service'
\r
70 1 * mockModuleStoreService.storeSchemaSet(dataspaceName, schemaSetName, yangResourcesNameToContentMap)
\r
73 def 'E2E Coverage Area-Tracking Area & TA-Cell mapping model can be parsed by CPS.'() {
\r
74 given: 'Valid yang resource as name-to-content map'
\r
75 def yangResourcesNameToContentMap = TestUtils.getYangResourcesAsMap(
\r
76 'e2e/basic/cps-cavsta-onap-internal2021-01-28.yang')
\r
77 when: 'Create schema set method is invoked'
\r
78 cpsModuleServiceImpl.createSchemaSet(dataspaceName, schemaSetName, yangResourcesNameToContentMap)
\r
79 then: 'Parameters are validated and processing is delegated to persistence service'
\r
80 1 * mockModuleStoreService.storeSchemaSet(dataspaceName, schemaSetName, yangResourcesNameToContentMap)
\r
83 def 'E2E Coverage Area-Tracking Area & TA-Cell mapping data can be parsed by CPS.'() {
\r
84 given: 'Valid yang resource as name-to-content map'
\r
85 def yangResourcesNameToContentMap = TestUtils.getYangResourcesAsMap(
\r
86 'e2e/basic/cps-cavsta-onap-internal2021-01-28.yang')
\r
87 def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourcesNameToContentMap).getSchemaContext()
\r
89 and : 'a valid json is provided for the model'
\r
90 def jsonData = TestUtils.getResourceFileContent('e2e/basic/cps-Cavsta-Data.txt')
\r
91 and : 'all the further dependencies are mocked '
\r
92 mockCpsAnchorService.getAnchor(dataspaceName, anchorName) >>
\r
93 new Anchor().builder().name(anchorName).schemaSetName(schemaSetName).dataspaceName(dataspaceName).build()
\r
94 mockYangTextSchemaSourceSetCache.get(dataspaceName, schemaSetName) >>
\r
95 YangTextSchemaSourceSetBuilder.of(yangResourcesNameToContentMap)
\r
96 mockModuleStoreService.getYangSchemaResources(dataspaceName, schemaSetName) >> schemaContext
\r
97 when: 'saveData method is invoked'
\r
98 cpsDataServiceImpl.saveData(dataspaceName, anchorName, jsonData, noTimestamp)
\r
99 then: 'Parameters are validated and processing is delegated to persistence service'
\r
100 1 * mockDataStoreService.storeDataNodes('someDataspace', 'someAnchor', _) >>
\r
101 { args -> dataNodeStored = args[2]}
\r
102 def child = dataNodeStored[0].childDataNodes[0]
\r
103 assert child.childDataNodes.size() == 1
\r
104 and: 'list of Tracking Area for a Coverage Area are stored with correct xpath and child nodes '
\r
105 def listOfTAForCoverageArea = child.childDataNodes[0]
\r
106 listOfTAForCoverageArea.xpath == '/ran-coverage-area/pLMNIdList[@mcc=\'310\' and @mnc=\'410\']/' +
\r
107 'coverage-area[@coverageArea=\'Washington\']'
\r
108 listOfTAForCoverageArea.childDataNodes[0].leaves.get('nRTAC') == 234
\r
109 and: 'list of cells in a tracking area are stored with correct xpath and child nodes '
\r
110 def listOfCellsInTrackingArea = listOfTAForCoverageArea.childDataNodes[0]
\r
111 listOfCellsInTrackingArea.xpath == '/ran-coverage-area/pLMNIdList[@mcc=\'310\' and @mnc=\'410\']/' +
\r
112 'coverage-area[@coverageArea=\'Washington\']/coverageAreaTAList[@nRTAC=\'234\']'
\r
113 listOfCellsInTrackingArea.childDataNodes[0].leaves.get('cellLocalId') == 15709
\r
116 def 'E2E Coverage Area-Tracking Area & TA-Cell mapping data can be parsed for RAN inventory.'() {
\r
118 given: 'valid yang resource as name-to-content map'
\r
119 def yangResourcesNameToContentMap = TestUtils.getYangResourcesAsMap(
\r
120 'e2e/basic/cps-ran-inventory@2021-01-28.yang')
\r
121 def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourcesNameToContentMap).getSchemaContext()
\r
122 and : 'a valid json is provided for the model'
\r
123 def jsonData = TestUtils.getResourceFileContent('e2e/basic/cps-ran-inventory-data.json')
\r
124 and : 'all the further dependencies are mocked '
\r
125 mockCpsAnchorService.getAnchor('someDataspace', 'someAnchor') >>
\r
126 new Anchor().builder().name('someAnchor').schemaSetName('someSchemaSet').dataspaceName(dataspaceName).build()
\r
127 mockYangTextSchemaSourceSetCache.get('someDataspace', 'someSchemaSet') >> YangTextSchemaSourceSetBuilder.of(yangResourcesNameToContentMap)
\r
128 mockModuleStoreService.getYangSchemaResources('someDataspace', 'someSchemaSet') >> schemaContext
\r
129 when: 'saveData method is invoked'
\r
130 cpsDataServiceImpl.saveData('someDataspace', 'someAnchor', jsonData, noTimestamp)
\r
131 then: 'parameters are validated and processing is delegated to persistence service'
\r
132 1 * mockDataStoreService.storeDataNodes('someDataspace', 'someAnchor', _) >>
\r
133 { args -> dataNodeStored = args[2]}
\r
134 and: 'the size of the tree is correct'
\r
135 def cpsRanInventory = TestUtils.getFlattenMapByXpath(dataNodeStored[0])
\r
136 assert cpsRanInventory.size() == 4
\r
137 and: 'ran-inventory contains the correct child node'
\r
138 def ranInventory = cpsRanInventory.get('/ran-inventory')
\r
139 def ranSlices = cpsRanInventory.get('/ran-inventory/ran-slices[@rannfnssiid=\'14559ead-f4fe-4c1c-a94c-8015fad3ea35\']')
\r
140 def sliceProfilesList = cpsRanInventory.get('/ran-inventory/ran-slices[@rannfnssiid=\'14559ead-f4fe-4c1c-a94c-8015fad3ea35\']/sliceProfilesList[@sliceProfileId=\'f33a9dd8-ae51-4acf-8073-c9390c25f6f1\']')
\r
141 def pLMNIdList = cpsRanInventory.get('/ran-inventory/ran-slices[@rannfnssiid=\'14559ead-f4fe-4c1c-a94c-8015fad3ea35\']/sliceProfilesList[@sliceProfileId=\'f33a9dd8-ae51-4acf-8073-c9390c25f6f1\']/pLMNIdList[@mcc=\'310\' and @mnc=\'410\']')
\r
142 ranInventory.getChildDataNodes().size() == 1
\r
143 ranInventory.getChildDataNodes().find( {it.xpath == ranSlices.xpath})
\r
144 and: 'ranSlices contains the correct child node'
\r
145 ranSlices.getChildDataNodes().size() == 1
\r
146 ranSlices.getChildDataNodes().find( {it.xpath == sliceProfilesList.xpath})
\r
147 and: 'sliceProfilesList contains the correct child node'
\r
148 sliceProfilesList.getChildDataNodes().size() == 1
\r
149 sliceProfilesList.getChildDataNodes().find( {it.xpath == pLMNIdList.xpath})
\r
150 and: 'pLMNIdList contains no children'
\r
151 pLMNIdList.getChildDataNodes().size() == 0
\r
155 def 'E2E RAN Schema Model.'(){
\r
156 given: 'yang resources'
\r
157 def yangResourcesNameToContentMap = TestUtils.getYangResourcesAsMap(
\r
158 'ietf/ietf-inet-types@2013-07-15.yang',
\r
159 'ietf/ietf-yang-types@2013-07-15.yang',
\r
160 'e2e/basic/cps-ran-schema-model@2021-05-19.yang'
\r
163 def jsonData = TestUtils.getResourceFileContent('e2e/basic/cps-ran-schema-model-data-v4.json')
\r
164 expect: 'schema context is built with no exception indicating the schema set being valid '
\r
165 def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourcesNameToContentMap).getSchemaContext()
\r
166 and: 'data is parsed with no exception indicating the model match'
\r
167 new YangParserHelper().parseData(ContentType.JSON, jsonData, schemaContext, '') != null
\r