ccfb23b449bfb111b1fe411df5d82fc8bed5a818
[cps.git] / cps-service / src / test / groovy / org / onap / cps / api / impl / E2ENetworkSliceSpec.groovy
1 /*\r
2  * ============LICENSE_START=======================================================\r
3  * Copyright (C) 2021-2022 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 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
11  *\r
12  *       http://www.apache.org/licenses/LICENSE-2.0\r
13  *\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
19  *\r
20  * SPDX-License-Identifier: Apache-2.0\r
21  * ============LICENSE_END=========================================================\r
22  */\r
23 \r
24 package org.onap.cps.api.impl\r
25 \r
26 import org.onap.cps.TestUtils\r
27 import org.onap.cps.api.CpsAdminService\r
28 import org.onap.cps.notification.NotificationService\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.YangUtils\r
34 import org.onap.cps.yang.YangTextSchemaSourceSetBuilder\r
35 import spock.lang.Specification\r
36 \r
37 class E2ENetworkSliceSpec extends Specification {\r
38     def mockModuleStoreService = Mock(CpsModulePersistenceService)\r
39     def mockDataStoreService = Mock(CpsDataPersistenceService)\r
40     def mockCpsAdminService = Mock(CpsAdminService)\r
41     def mockNotificationService = Mock(NotificationService)\r
42     def mockYangTextSchemaSourceSetCache = Mock(YangTextSchemaSourceSetCache)\r
43     def mockCpsValidator = Mock(CpsValidator)\r
44     def cpsModuleServiceImpl = new CpsModuleServiceImpl(mockModuleStoreService,\r
45             mockYangTextSchemaSourceSetCache, mockCpsAdminService, mockCpsValidator)\r
46     def cpsDataServiceImpl = new CpsDataServiceImpl(mockDataStoreService, mockCpsAdminService,\r
47             mockYangTextSchemaSourceSetCache, mockNotificationService, mockCpsValidator)\r
48 \r
49     def dataspaceName = 'someDataspace'\r
50     def anchorName = 'someAnchor'\r
51     def schemaSetName = 'someSchemaSet'\r
52     def noTimestamp = null\r
53 \r
54     def 'E2E model can be parsed by CPS.'() {\r
55         given: 'Valid yang resource as name-to-content map'\r
56             def yangResourcesNameToContentMap = TestUtils.getYangResourcesAsMap(\r
57                     'ietf/ietf-inet-types@2013-07-15.yang',\r
58                     'ietf/ietf-yang-types@2013-07-15.yang',\r
59                     'e2e/basic/ran-network2020-08-06.yang'\r
60             )\r
61         when: 'Create schema set method is invoked'\r
62             cpsModuleServiceImpl.createSchemaSet(dataspaceName, schemaSetName, yangResourcesNameToContentMap)\r
63         then: 'Parameters are validated and processing is delegated to persistence service'\r
64             1 * mockModuleStoreService.storeSchemaSet(dataspaceName, schemaSetName, yangResourcesNameToContentMap)\r
65     }\r
66 \r
67     def 'E2E Coverage Area-Tracking Area & TA-Cell mapping model can be parsed by CPS.'() {\r
68         given: 'Valid yang resource as name-to-content map'\r
69             def yangResourcesNameToContentMap = TestUtils.getYangResourcesAsMap(\r
70                     'e2e/basic/cps-cavsta-onap-internal2021-01-28.yang')\r
71         when: 'Create schema set method is invoked'\r
72             cpsModuleServiceImpl.createSchemaSet(dataspaceName, schemaSetName, yangResourcesNameToContentMap)\r
73         then: 'Parameters are validated and processing is delegated to persistence service'\r
74             1 * mockModuleStoreService.storeSchemaSet(dataspaceName, schemaSetName, yangResourcesNameToContentMap)\r
75     }\r
76 \r
77     def 'E2E Coverage Area-Tracking Area & TA-Cell mapping data can be parsed by CPS.'() {\r
78         given: 'Valid yang resource as name-to-content map'\r
79             def yangResourcesNameToContentMap = TestUtils.getYangResourcesAsMap(\r
80                     'e2e/basic/cps-cavsta-onap-internal2021-01-28.yang')\r
81             def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourcesNameToContentMap).getSchemaContext()\r
82             def dataNodeStored\r
83         and : 'a valid json is provided for the model'\r
84             def jsonData = TestUtils.getResourceFileContent('e2e/basic/cps-Cavsta-Data.txt')\r
85         and : 'all the further dependencies are mocked '\r
86             mockCpsAdminService.getAnchor(dataspaceName, anchorName) >>\r
87                     new Anchor().builder().name(anchorName).schemaSetName(schemaSetName).build()\r
88             mockYangTextSchemaSourceSetCache.get(dataspaceName, schemaSetName) >>\r
89                     YangTextSchemaSourceSetBuilder.of(yangResourcesNameToContentMap)\r
90             mockModuleStoreService.getYangSchemaResources(dataspaceName, schemaSetName) >> schemaContext\r
91         when: 'saveData method is invoked'\r
92             cpsDataServiceImpl.saveData(dataspaceName, anchorName, jsonData, noTimestamp)\r
93         then: 'Parameters are validated and processing is delegated to persistence service'\r
94             1 * mockDataStoreService.storeDataNodes('someDataspace', 'someAnchor', _) >>\r
95                     { args -> dataNodeStored = args[2]}\r
96             def child = dataNodeStored[0].childDataNodes[0]\r
97             assert child.childDataNodes.size() == 1\r
98         and: 'list of Tracking Area for a Coverage Area are stored with correct xpath and child nodes '\r
99             def listOfTAForCoverageArea = child.childDataNodes[0]\r
100             listOfTAForCoverageArea.xpath == '/ran-coverage-area/pLMNIdList[@mcc=\'310\' and @mnc=\'410\']/' +\r
101                     'coverage-area[@coverageArea=\'Washington\']'\r
102             listOfTAForCoverageArea.childDataNodes[0].leaves.get('nRTAC') == 234\r
103         and: 'list of cells in a tracking area are stored with correct xpath and child nodes '\r
104             def listOfCellsInTrackingArea = listOfTAForCoverageArea.childDataNodes[0]\r
105             listOfCellsInTrackingArea.xpath == '/ran-coverage-area/pLMNIdList[@mcc=\'310\' and @mnc=\'410\']/' +\r
106                     'coverage-area[@coverageArea=\'Washington\']/coverageAreaTAList[@nRTAC=\'234\']'\r
107             listOfCellsInTrackingArea.childDataNodes[0].leaves.get('cellLocalId') == 15709\r
108     }\r
109 \r
110     def 'E2E Coverage Area-Tracking Area & TA-Cell mapping data can be parsed for RAN inventory.'() {\r
111         def dataNodeStored\r
112         given: 'valid yang resource as name-to-content map'\r
113             def yangResourcesNameToContentMap = TestUtils.getYangResourcesAsMap(\r
114                     'e2e/basic/cps-ran-inventory@2021-01-28.yang')\r
115             def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourcesNameToContentMap).getSchemaContext()\r
116         and : 'a valid json is provided for the model'\r
117             def jsonData = TestUtils.getResourceFileContent('e2e/basic/cps-ran-inventory-data.json')\r
118         and : 'all the further dependencies are mocked '\r
119             mockCpsAdminService.getAnchor('someDataspace', 'someAnchor') >>\r
120                     new Anchor().builder().name('someAnchor').schemaSetName('someSchemaSet').build()\r
121             mockYangTextSchemaSourceSetCache.get('someDataspace', 'someSchemaSet') >> YangTextSchemaSourceSetBuilder.of(yangResourcesNameToContentMap)\r
122             mockModuleStoreService.getYangSchemaResources('someDataspace', 'someSchemaSet') >> schemaContext\r
123         when: 'saveData method is invoked'\r
124             cpsDataServiceImpl.saveData('someDataspace', 'someAnchor', jsonData, noTimestamp)\r
125         then: 'parameters are validated and processing is delegated to persistence service'\r
126             1 * mockDataStoreService.storeDataNodes('someDataspace', 'someAnchor', _) >>\r
127                     { args -> dataNodeStored = args[2]}\r
128         and: 'the size of the tree is correct'\r
129             def cpsRanInventory = TestUtils.getFlattenMapByXpath(dataNodeStored[0])\r
130             assert  cpsRanInventory.size() == 4\r
131         and: 'ran-inventory contains the correct child node'\r
132             def ranInventory = cpsRanInventory.get('/ran-inventory')\r
133             def ranSlices = cpsRanInventory.get('/ran-inventory/ran-slices[@rannfnssiid=\'14559ead-f4fe-4c1c-a94c-8015fad3ea35\']')\r
134             def sliceProfilesList = cpsRanInventory.get('/ran-inventory/ran-slices[@rannfnssiid=\'14559ead-f4fe-4c1c-a94c-8015fad3ea35\']/sliceProfilesList[@sliceProfileId=\'f33a9dd8-ae51-4acf-8073-c9390c25f6f1\']')\r
135             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
136             ranInventory.getChildDataNodes().size() == 1\r
137             ranInventory.getChildDataNodes().find( {it.xpath == ranSlices.xpath})\r
138         and: 'ranSlices contains the correct child node'\r
139             ranSlices.getChildDataNodes().size() == 1\r
140             ranSlices.getChildDataNodes().find( {it.xpath == sliceProfilesList.xpath})\r
141         and: 'sliceProfilesList contains the correct child node'\r
142             sliceProfilesList.getChildDataNodes().size() == 1\r
143             sliceProfilesList.getChildDataNodes().find( {it.xpath == pLMNIdList.xpath})\r
144         and: 'pLMNIdList contains no children'\r
145             pLMNIdList.getChildDataNodes().size() == 0\r
146 \r
147     }\r
148 \r
149     def 'E2E RAN Schema Model.'(){\r
150         given: 'yang resources'\r
151             def yangResourcesNameToContentMap = TestUtils.getYangResourcesAsMap(\r
152                     'ietf/ietf-inet-types@2013-07-15.yang',\r
153                     'ietf/ietf-yang-types@2013-07-15.yang',\r
154                     'e2e/basic/cps-ran-schema-model@2021-05-19.yang'\r
155             )\r
156         and : 'json data'\r
157             def jsonData = TestUtils.getResourceFileContent('e2e/basic/cps-ran-schema-model-data-v4.json')\r
158         expect: 'schema context is built with no exception indicating the schema set being valid '\r
159             def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourcesNameToContentMap).getSchemaContext()\r
160         and: 'data is parsed with no exception indicating the model match'\r
161             YangUtils.parseJsonData(jsonData, schemaContext) != null\r
162     }\r
163 }\r