2 * ============LICENSE_START=======================================================
\r
3 * Copyright (C) 2021-2023 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.CpsDataPersistenceService
\r
31 import org.onap.cps.spi.CpsModulePersistenceService
\r
32 import org.onap.cps.spi.model.Anchor
\r
33 import org.onap.cps.spi.utils.CpsValidator
\r
34 import org.onap.cps.utils.TimedYangParser
\r
35 import org.onap.cps.utils.YangUtils
\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 timedYangParser = new TimedYangParser()
\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,
\r
54 mockYangTextSchemaSourceSetCache, mockCpsValidator, timedYangParser, mockCpsDeltaService)
\r
56 def dataspaceName = 'someDataspace'
\r
57 def anchorName = 'someAnchor'
\r
58 def schemaSetName = 'someSchemaSet'
\r
59 def noTimestamp = null
\r
61 def 'E2E model can be parsed by CPS.'() {
\r
62 given: 'Valid yang resource as name-to-content map'
\r
63 def yangResourcesNameToContentMap = TestUtils.getYangResourcesAsMap(
\r
64 'ietf/ietf-inet-types@2013-07-15.yang',
\r
65 'ietf/ietf-yang-types@2013-07-15.yang',
\r
66 'e2e/basic/ran-network2020-08-06.yang'
\r
68 when: 'Create schema set method is invoked'
\r
69 cpsModuleServiceImpl.createSchemaSet(dataspaceName, schemaSetName, yangResourcesNameToContentMap)
\r
70 then: 'Parameters are validated and processing is delegated to persistence service'
\r
71 1 * mockModuleStoreService.storeSchemaSet(dataspaceName, schemaSetName, yangResourcesNameToContentMap)
\r
74 def 'E2E Coverage Area-Tracking Area & TA-Cell mapping model can be parsed by CPS.'() {
\r
75 given: 'Valid yang resource as name-to-content map'
\r
76 def yangResourcesNameToContentMap = TestUtils.getYangResourcesAsMap(
\r
77 'e2e/basic/cps-cavsta-onap-internal2021-01-28.yang')
\r
78 when: 'Create schema set method is invoked'
\r
79 cpsModuleServiceImpl.createSchemaSet(dataspaceName, schemaSetName, yangResourcesNameToContentMap)
\r
80 then: 'Parameters are validated and processing is delegated to persistence service'
\r
81 1 * mockModuleStoreService.storeSchemaSet(dataspaceName, schemaSetName, yangResourcesNameToContentMap)
\r
84 def 'E2E Coverage Area-Tracking Area & TA-Cell mapping data can be parsed by CPS.'() {
\r
85 given: 'Valid yang resource as name-to-content map'
\r
86 def yangResourcesNameToContentMap = TestUtils.getYangResourcesAsMap(
\r
87 'e2e/basic/cps-cavsta-onap-internal2021-01-28.yang')
\r
88 def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourcesNameToContentMap).getSchemaContext()
\r
90 and : 'a valid json is provided for the model'
\r
91 def jsonData = TestUtils.getResourceFileContent('e2e/basic/cps-Cavsta-Data.txt')
\r
92 and : 'all the further dependencies are mocked '
\r
93 mockCpsAnchorService.getAnchor(dataspaceName, anchorName) >>
\r
94 new Anchor().builder().name(anchorName).schemaSetName(schemaSetName).dataspaceName(dataspaceName).build()
\r
95 mockYangTextSchemaSourceSetCache.get(dataspaceName, schemaSetName) >>
\r
96 YangTextSchemaSourceSetBuilder.of(yangResourcesNameToContentMap)
\r
97 mockModuleStoreService.getYangSchemaResources(dataspaceName, schemaSetName) >> schemaContext
\r
98 when: 'saveData method is invoked'
\r
99 cpsDataServiceImpl.saveData(dataspaceName, anchorName, jsonData, noTimestamp)
\r
100 then: 'Parameters are validated and processing is delegated to persistence service'
\r
101 1 * mockDataStoreService.storeDataNodes('someDataspace', 'someAnchor', _) >>
\r
102 { args -> dataNodeStored = args[2]}
\r
103 def child = dataNodeStored[0].childDataNodes[0]
\r
104 assert child.childDataNodes.size() == 1
\r
105 and: 'list of Tracking Area for a Coverage Area are stored with correct xpath and child nodes '
\r
106 def listOfTAForCoverageArea = child.childDataNodes[0]
\r
107 listOfTAForCoverageArea.xpath == '/ran-coverage-area/pLMNIdList[@mcc=\'310\' and @mnc=\'410\']/' +
\r
108 'coverage-area[@coverageArea=\'Washington\']'
\r
109 listOfTAForCoverageArea.childDataNodes[0].leaves.get('nRTAC') == 234
\r
110 and: 'list of cells in a tracking area are stored with correct xpath and child nodes '
\r
111 def listOfCellsInTrackingArea = listOfTAForCoverageArea.childDataNodes[0]
\r
112 listOfCellsInTrackingArea.xpath == '/ran-coverage-area/pLMNIdList[@mcc=\'310\' and @mnc=\'410\']/' +
\r
113 'coverage-area[@coverageArea=\'Washington\']/coverageAreaTAList[@nRTAC=\'234\']'
\r
114 listOfCellsInTrackingArea.childDataNodes[0].leaves.get('cellLocalId') == 15709
\r
117 def 'E2E Coverage Area-Tracking Area & TA-Cell mapping data can be parsed for RAN inventory.'() {
\r
119 given: 'valid yang resource as name-to-content map'
\r
120 def yangResourcesNameToContentMap = TestUtils.getYangResourcesAsMap(
\r
121 'e2e/basic/cps-ran-inventory@2021-01-28.yang')
\r
122 def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourcesNameToContentMap).getSchemaContext()
\r
123 and : 'a valid json is provided for the model'
\r
124 def jsonData = TestUtils.getResourceFileContent('e2e/basic/cps-ran-inventory-data.json')
\r
125 and : 'all the further dependencies are mocked '
\r
126 mockCpsAnchorService.getAnchor('someDataspace', 'someAnchor') >>
\r
127 new Anchor().builder().name('someAnchor').schemaSetName('someSchemaSet').dataspaceName(dataspaceName).build()
\r
128 mockYangTextSchemaSourceSetCache.get('someDataspace', 'someSchemaSet') >> YangTextSchemaSourceSetBuilder.of(yangResourcesNameToContentMap)
\r
129 mockModuleStoreService.getYangSchemaResources('someDataspace', 'someSchemaSet') >> schemaContext
\r
130 when: 'saveData method is invoked'
\r
131 cpsDataServiceImpl.saveData('someDataspace', 'someAnchor', jsonData, noTimestamp)
\r
132 then: 'parameters are validated and processing is delegated to persistence service'
\r
133 1 * mockDataStoreService.storeDataNodes('someDataspace', 'someAnchor', _) >>
\r
134 { args -> dataNodeStored = args[2]}
\r
135 and: 'the size of the tree is correct'
\r
136 def cpsRanInventory = TestUtils.getFlattenMapByXpath(dataNodeStored[0])
\r
137 assert cpsRanInventory.size() == 4
\r
138 and: 'ran-inventory contains the correct child node'
\r
139 def ranInventory = cpsRanInventory.get('/ran-inventory')
\r
140 def ranSlices = cpsRanInventory.get('/ran-inventory/ran-slices[@rannfnssiid=\'14559ead-f4fe-4c1c-a94c-8015fad3ea35\']')
\r
141 def sliceProfilesList = cpsRanInventory.get('/ran-inventory/ran-slices[@rannfnssiid=\'14559ead-f4fe-4c1c-a94c-8015fad3ea35\']/sliceProfilesList[@sliceProfileId=\'f33a9dd8-ae51-4acf-8073-c9390c25f6f1\']')
\r
142 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
143 ranInventory.getChildDataNodes().size() == 1
\r
144 ranInventory.getChildDataNodes().find( {it.xpath == ranSlices.xpath})
\r
145 and: 'ranSlices contains the correct child node'
\r
146 ranSlices.getChildDataNodes().size() == 1
\r
147 ranSlices.getChildDataNodes().find( {it.xpath == sliceProfilesList.xpath})
\r
148 and: 'sliceProfilesList contains the correct child node'
\r
149 sliceProfilesList.getChildDataNodes().size() == 1
\r
150 sliceProfilesList.getChildDataNodes().find( {it.xpath == pLMNIdList.xpath})
\r
151 and: 'pLMNIdList contains no children'
\r
152 pLMNIdList.getChildDataNodes().size() == 0
\r
156 def 'E2E RAN Schema Model.'(){
\r
157 given: 'yang resources'
\r
158 def yangResourcesNameToContentMap = TestUtils.getYangResourcesAsMap(
\r
159 'ietf/ietf-inet-types@2013-07-15.yang',
\r
160 'ietf/ietf-yang-types@2013-07-15.yang',
\r
161 'e2e/basic/cps-ran-schema-model@2021-05-19.yang'
\r
164 def jsonData = TestUtils.getResourceFileContent('e2e/basic/cps-ran-schema-model-data-v4.json')
\r
165 expect: 'schema context is built with no exception indicating the schema set being valid '
\r
166 def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourcesNameToContentMap).getSchemaContext()
\r
167 and: 'data is parsed with no exception indicating the model match'
\r
168 YangUtils.parseJsonData(jsonData, schemaContext) != null
\r