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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.cps.api.impl
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
30 class NetworkCmProxyDataServiceImplSpec extends Specification {
31 def objectUnderTest = new NetworkCmProxyDataServiceImpl()
32 def mockcpsDataService = Mock(CpsDataService)
33 def mockcpsQueryService = Mock(CpsQueryService)
36 objectUnderTest.cpsDataService = mockcpsDataService
37 objectUnderTest.cpsQueryService = mockcpsQueryService
40 def cmHandle = 'some handle'
41 def expectedDataspaceName = 'NFP-Operational'
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()
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'
64 'root level xpath' | '/'
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)
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)
87 def 'Update data node leaves.'() {
88 given: 'a cm Handle and a cps path'
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)
97 def 'Replace data node tree.'() {
98 given: 'a cm Handle and a cps path'
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)