ee435cc3842bd653eb74584396cb5bfc3039bdb6
[cps.git] / cps-ncmp-service / src / test / groovy / org / onap / cps / api / impl / NetworkCmProxyDataServiceImplSpec.groovy
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2021 Nordix Foundation
4  *  Modifications Copyright (C) 2021 Pantheon.tech
5  *  ================================================================================
6  *  Licensed under the Apache License, Version 2.0 (the "License");
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License.
17  *
18  *  SPDX-License-Identifier: Apache-2.0
19  *  ============LICENSE_END=========================================================
20  */
21
22 package org.onap.cps.api.impl
23
24 import org.onap.cps.api.CpsDataService
25 import org.onap.cps.api.CpsQueryService
26 import org.onap.cps.ncmp.api.impl.NetworkCmProxyDataServiceImpl
27 import org.onap.cps.spi.FetchDescendantsOption
28 import spock.lang.Specification
29
30 class NetworkCmProxyDataServiceImplSpec extends Specification {
31     def objectUnderTest = new NetworkCmProxyDataServiceImpl()
32     def mockcpsDataService = Mock(CpsDataService)
33     def mockcpsQueryService = Mock(CpsQueryService)
34
35     def setup() {
36         objectUnderTest.cpsDataService = mockcpsDataService
37         objectUnderTest.cpsQueryService = mockcpsQueryService
38     }
39
40     def cmHandle = 'some handle'
41     def expectedDataspaceName = 'NFP-Operational'
42
43     def 'Query data nodes by cps path with #fetchDescendantsOption.'() {
44         given: 'a cm Handle and a cps path'
45             def cpsPath = '/cps-path'
46         when: 'queryDataNodes is invoked'
47             objectUnderTest.queryDataNodes(cmHandle, cpsPath, fetchDescendantsOption)
48         then: 'the persistence service is called once with the correct parameters'
49             1 * mockcpsQueryService.queryDataNodes(expectedDataspaceName, cmHandle, cpsPath, fetchDescendantsOption)
50         where: 'all fetch descendants options are supported'
51             fetchDescendantsOption << FetchDescendantsOption.values()
52     }
53
54     def 'Create full data node: #scenario.'() {
55         given: 'a cm handle and root xpath'
56             def jsonData = 'some json'
57         when: 'createDataNode is invoked'
58             objectUnderTest.createDataNode(cmHandle, xpath, jsonData)
59         then: 'the CPS service method is invoked once with the expected parameters'
60             1 * mockcpsDataService.saveData(expectedDataspaceName, cmHandle, jsonData)
61         where: 'following parameters were used'
62             scenario           | xpath
63             'no xpath'         | ''
64             'root level xpath' | '/'
65     }
66
67     def 'Create child data node.'() {
68         given: 'a cm handle and parent node xpath'
69             def jsonData = 'some json'
70             def xpath = '/test-node'
71         when: 'createDataNode is invoked'
72             objectUnderTest.createDataNode(cmHandle, xpath, jsonData)
73         then: 'the CPS service method is invoked once with the expected parameters'
74             1 * mockcpsDataService.saveData(expectedDataspaceName, cmHandle, xpath, jsonData)
75     }
76
77     def 'Add list-node elements.'() {
78         given: 'a cm handle and parent node xpath'
79             def jsonData = 'some json'
80             def xpath = '/test-node'
81         when: 'addListNodeElements is invoked'
82             objectUnderTest.addListNodeElements(cmHandle, xpath, jsonData)
83         then: 'the CPS service method is invoked once with the expected parameters'
84             1 * mockcpsDataService.saveListNodeData(expectedDataspaceName, cmHandle, xpath, jsonData)
85     }
86
87     def 'Update data node leaves.'() {
88         given: 'a cm Handle and a cps path'
89             def xpath = '/xpath'
90             def jsonData = 'some json'
91         when: 'updateNodeLeaves is invoked'
92             objectUnderTest.updateNodeLeaves(cmHandle, xpath, jsonData)
93         then: 'the persistence service is called once with the correct parameters'
94             1 * mockcpsDataService.updateNodeLeaves(expectedDataspaceName, cmHandle, xpath, jsonData)
95     }
96
97     def 'Replace data node tree.'() {
98         given: 'a cm Handle and a cps path'
99             def xpath = '/xpath'
100             def jsonData = 'some json'
101         when: 'replaceNodeTree is invoked'
102             objectUnderTest.replaceNodeTree(cmHandle, xpath, jsonData)
103         then: 'the persistence service is called once with the correct parameters'
104             1 * mockcpsDataService.replaceNodeTree(expectedDataspaceName, cmHandle, xpath, jsonData)
105     }
106 }