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
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.cps.api.impl
23 import org.onap.cps.api.CpsDataService
24 import org.onap.cps.api.CpsQueryService
25 import org.onap.cps.ncmp.api.impl.NetworkCmProxyDataServiceImpl
26 import org.onap.cps.spi.FetchDescendantsOption
27 import spock.lang.Specification
29 class NetworkCmProxyDataServiceImplSpec extends Specification {
30 def objectUnderTest = new NetworkCmProxyDataServiceImpl()
31 def mockcpsDataService = Mock(CpsDataService)
32 def mockcpsQueryService = Mock(CpsQueryService)
35 objectUnderTest.cpsDataService = mockcpsDataService
36 objectUnderTest.cpsQueryService = mockcpsQueryService
39 def cmHandle = 'some handle'
40 def expectedDataspaceName = 'NFP-Operational'
42 def 'Query data nodes by cps path with #fetchDescendantsOption.'() {
43 given: 'a cm Handle and a cps path'
44 def cpsPath = '/cps-path'
45 when: 'queryDataNodes is invoked'
46 objectUnderTest.queryDataNodes(cmHandle, cpsPath, fetchDescendantsOption)
47 then: 'the persistence service is called once with the correct parameters'
48 1 * mockcpsQueryService.queryDataNodes(expectedDataspaceName, cmHandle, cpsPath, fetchDescendantsOption)
49 where: 'all fetch descendants options are supported'
50 fetchDescendantsOption << FetchDescendantsOption.values()
53 def 'Create full data node: #scenario.'() {
54 given: 'a cm handle and root xpath'
55 def jsonData = 'some json'
56 when: 'createDataNode is invoked'
57 objectUnderTest.createDataNode(cmHandle, xpath, jsonData)
58 then: 'the CPS service method is invoked once with the expected parameters'
59 1 * mockcpsDataService.saveData(expectedDataspaceName, cmHandle, jsonData)
60 where: 'following parameters were used'
63 'root level xpath' | '/'
66 def 'Create child data node.'() {
67 given: 'a cm handle and parent node xpath'
68 def jsonData = 'some json'
69 def xpath = '/test-node'
70 when: 'createDataNode is invoked'
71 objectUnderTest.createDataNode(cmHandle, xpath, jsonData)
72 then: 'the CPS service method is invoked once with the expected parameters'
73 1 * mockcpsDataService.saveData(expectedDataspaceName, cmHandle, xpath, jsonData)
76 def 'Update data node leaves.'() {
77 given: 'a cm Handle and a cps path'
79 def jsonData = 'some json'
80 when: 'updateNodeLeaves is invoked'
81 objectUnderTest.updateNodeLeaves(cmHandle, xpath, jsonData)
82 then: 'the persistence service is called once with the correct parameters'
83 1 * mockcpsDataService.updateNodeLeaves(expectedDataspaceName, cmHandle, xpath, jsonData)
86 def 'Replace data node tree.'() {
87 given: 'a cm Handle and a cps path'
89 def jsonData = 'some json'
90 when: 'replaceNodeTree is invoked'
91 objectUnderTest.replaceNodeTree(cmHandle, xpath, jsonData)
92 then: 'the persistence service is called once with the correct parameters'
93 1 * mockcpsDataService.replaceNodeTree(expectedDataspaceName, cmHandle, xpath, jsonData)