2 * ============LICENSE_START=======================================================
\r
3 * Copyright (C) 2021 Nordix Foundation. All rights reserved.
\r
4 * Modifications Copyright (C) 2021 Bell Canada.
\r
5 * ================================================================================
\r
6 * Licensed under the Apache License, Version 2.0 (the "License");
\r
7 * you may not use this file except in compliance with the License.
\r
8 * You may obtain a copy of the License at
\r
10 * http://www.apache.org/licenses/LICENSE-2.0
\r
12 * Unless required by applicable law or agreed to in writing, software
\r
13 * distributed under the License is distributed on an "AS IS" BASIS,
\r
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
15 * See the License for the specific language governing permissions and
\r
16 * limitations under the License.
\r
18 * SPDX-License-Identifier: Apache-2.0
\r
19 * ============LICENSE_END=========================================================
\r
22 package org.onap.cps.api.impl
\r
24 import org.onap.cps.TestUtils
\r
25 import org.onap.cps.api.CpsAdminService
\r
26 import org.onap.cps.spi.CpsDataPersistenceService
\r
27 import org.onap.cps.spi.CpsModulePersistenceService
\r
28 import org.onap.cps.spi.model.Anchor
\r
29 import org.onap.cps.spi.model.DataNode
\r
30 import org.onap.cps.yang.YangTextSchemaSourceSetBuilder
\r
31 import spock.lang.Specification
\r
33 class E2ENetworkSliceSpec extends Specification {
\r
34 def mockModuleStoreService = Mock(CpsModulePersistenceService)
\r
35 def mockDataStoreService = Mock(CpsDataPersistenceService)
\r
36 def mockCpsAdminService = Mock(CpsAdminService)
\r
37 def cpsModuleServiceImpl = new CpsModuleServiceImpl()
\r
38 def cpsDataServiceImple = new CpsDataServiceImpl()
\r
39 def mockYangTextSchemaSourceSetCache = Mock(YangTextSchemaSourceSetCache)
\r
41 def dataspaceName = 'someDataspace'
\r
42 def anchorName = 'someAnchor'
\r
43 def schemaSetName = 'someSchemaSet'
\r
46 cpsDataServiceImple.cpsDataPersistenceService = mockDataStoreService
\r
47 cpsDataServiceImple.cpsAdminService = mockCpsAdminService
\r
48 cpsDataServiceImple.yangTextSchemaSourceSetCache = mockYangTextSchemaSourceSetCache
\r
49 cpsModuleServiceImpl.yangTextSchemaSourceSetCache = mockYangTextSchemaSourceSetCache
\r
50 cpsModuleServiceImpl.cpsModulePersistenceService = mockModuleStoreService
\r
53 def 'E2E model can be parsed by CPS.'() {
\r
54 given: 'Valid yang resource as name-to-content map'
\r
55 def yangResourcesNameToContentMap = TestUtils.getYangResourcesAsMap('e2e/basic/ietf-inet-types.yang','e2e/basic/ietf-yang-types.yang','e2e/basic/ran-network2020-08-06.yang')
\r
56 when: 'Create schema set method is invoked'
\r
57 cpsModuleServiceImpl.createSchemaSet(dataspaceName, schemaSetName, yangResourcesNameToContentMap)
\r
58 then: 'Parameters are validated and processing is delegated to persistence service'
\r
59 1 * mockModuleStoreService.storeSchemaSet(dataspaceName, schemaSetName, yangResourcesNameToContentMap)
\r
62 def 'E2E Coverage Area-Tracking Area & TA-Cell mapping model can be parsed by CPS.'() {
\r
63 given: 'Valid yang resource as name-to-content map'
\r
64 def yangResourcesNameToContentMap = TestUtils.getYangResourcesAsMap(
\r
65 'e2e/basic/cps-cavsta-onap-internal2021-01-28.yang')
\r
66 when: 'Create schema set method is invoked'
\r
67 cpsModuleServiceImpl.createSchemaSet(dataspaceName, schemaSetName, yangResourcesNameToContentMap)
\r
68 then: 'Parameters are validated and processing is delegated to persistence service'
\r
69 1 * mockModuleStoreService.storeSchemaSet(dataspaceName, schemaSetName, yangResourcesNameToContentMap)
\r
72 def 'E2E Coverage Area-Tracking Area & TA-Cell mapping data can be parsed by CPS.'() {
\r
73 given: 'Valid yang resource as name-to-content map'
\r
74 def yangResourcesNameToContentMap = TestUtils.getYangResourcesAsMap(
\r
75 'e2e/basic/cps-cavsta-onap-internal2021-01-28.yang')
\r
76 def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourcesNameToContentMap).getSchemaContext()
\r
78 and : 'a valid json is provided for the model'
\r
79 def jsonData = TestUtils.getResourceFileContent('e2e/basic/cps-Cavsta-Data.txt')
\r
80 and : 'all the further dependencies are mocked '
\r
81 mockCpsAdminService.getAnchor(dataspaceName, anchorName) >>
\r
82 new Anchor().builder().name(anchorName).schemaSetName(schemaSetName).build()
\r
83 mockYangTextSchemaSourceSetCache.get(dataspaceName, schemaSetName) >>
\r
84 YangTextSchemaSourceSetBuilder.of(yangResourcesNameToContentMap)
\r
85 mockModuleStoreService.getYangSchemaResources(dataspaceName, schemaSetName) >> schemaContext
\r
86 when: 'saveData method is invoked'
\r
87 cpsDataServiceImple.saveData(dataspaceName, anchorName, jsonData)
\r
88 then: 'Parameters are validated and processing is delegated to persistence service'
\r
89 1 * mockDataStoreService.storeDataNode('someDataspace', 'someAnchor', _) >>
\r
90 { args -> dataNodeStored = args[2]}
\r
91 def child = dataNodeStored.childDataNodes[0]
\r
92 assert child.childDataNodes.size() == 1
\r
93 and: 'list of Tracking Area for a Coverage Area are stored with correct xpath and child nodes '
\r
94 def listOfTAForCoverageArea = child.childDataNodes[0]
\r
95 listOfTAForCoverageArea.xpath == '/ran-coverage-area/pLMNIdList[@mcc=\'310\' and @mnc=\'410\']/' +
\r
96 'coverage-area[@coverageArea=\'Washington\']'
\r
97 listOfTAForCoverageArea.childDataNodes[0].leaves.get('nRTAC') == 234
\r
98 and: 'list of cells in a tracking area are stored with correct xpath and child nodes '
\r
99 def listOfCellsInTrackingArea = listOfTAForCoverageArea.childDataNodes[0]
\r
100 listOfCellsInTrackingArea.xpath == '/ran-coverage-area/pLMNIdList[@mcc=\'310\' and @mnc=\'410\']/' +
\r
101 'coverage-area[@coverageArea=\'Washington\']/coverageAreaTAList[@nRTAC=\'234\']'
\r
102 listOfCellsInTrackingArea.childDataNodes[0].leaves.get('cellLocalId') == 15709
\r
105 def 'E2E Coverage Area-Tracking Area & TA-Cell mapping data can be parsed for RAN inventory.'() {
\r
107 given: 'valid yang resource as name-to-content map'
\r
108 def yangResourcesNameToContentMap = TestUtils.getYangResourcesAsMap(
\r
109 'e2e/basic/cps-ran-inventory.yang')
\r
110 def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourcesNameToContentMap).getSchemaContext()
\r
111 and : 'a valid json is provided for the model'
\r
112 def jsonData = TestUtils.getResourceFileContent('e2e/basic/cps-ran-inventory-data.json')
\r
113 and : 'all the further dependencies are mocked '
\r
114 mockCpsAdminService.getAnchor('someDataspace', 'someAnchor') >>
\r
115 new Anchor().builder().name('someAnchor').schemaSetName('someSchemaSet').build()
\r
116 mockYangTextSchemaSourceSetCache.get('someDataspace', 'someSchemaSet') >> YangTextSchemaSourceSetBuilder.of(yangResourcesNameToContentMap)
\r
117 mockModuleStoreService.getYangSchemaResources('someDataspace', 'someSchemaSet') >> schemaContext
\r
118 when: 'saveData method is invoked'
\r
119 cpsDataServiceImple.saveData('someDataspace', 'someAnchor', jsonData)
\r
120 then: 'parameters are validated and processing is delegated to persistence service'
\r
121 1 * mockDataStoreService.storeDataNode('someDataspace', 'someAnchor', _) >>
\r
122 { args -> dataNodeStored = args[2]}
\r
123 and: 'the size of the tree is correct'
\r
124 def cpsRanInventory = treeToFlatMapByXpath(new HashMap<>(), dataNodeStored)
\r
125 assert cpsRanInventory.size() == 3
\r
126 and: 'ran-inventory contains the correct child node'
\r
127 def ranInventory = cpsRanInventory.get('/ran-inventory')
\r
128 def sliceProfilesList = cpsRanInventory.get('/ran-inventory/sliceProfilesList[@sliceProfileId=\'f33a9dd8-ae51-4acf-8073-c9390c25f6f1\']')
\r
129 def pLMNIdList = cpsRanInventory.get('/ran-inventory/sliceProfilesList[@sliceProfileId=\'f33a9dd8-ae51-4acf-8073-c9390c25f6f1\']/pLMNIdList[@mcc=\'310\' and @mnc=\'410\']')
\r
130 ranInventory.getChildDataNodes().size() == 1
\r
131 ranInventory.getChildDataNodes().find( {it.xpath == sliceProfilesList.xpath})
\r
132 and: 'sliceProfilesList contains the correct child node'
\r
133 sliceProfilesList.getChildDataNodes().size() == 1
\r
134 sliceProfilesList.getChildDataNodes().find( {it.xpath == pLMNIdList.xpath})
\r
135 and: 'pLMNIdList contains the no child nodes'
\r
136 pLMNIdList.getChildDataNodes().size() == 0
\r
139 def static treeToFlatMapByXpath(Map<String, DataNode> flatMap, DataNode dataNodeTree) {
\r
140 flatMap.put(dataNodeTree.getXpath(), dataNodeTree)
\r
141 dataNodeTree.getChildDataNodes()
\r
142 .forEach(childDataNode -> treeToFlatMapByXpath(flatMap, childDataNode))
\r