2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2022-2025 Nordix Foundation
4 * Modifications Copyright (C) 2022 Bell Canada
5 * Modifications Copyright (C) 2024 TechMahindra Ltd.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
23 package org.onap.cps.ncmp.impl.inventory
25 import com.fasterxml.jackson.databind.ObjectMapper
26 import java.time.OffsetDateTime
27 import java.time.ZoneOffset
28 import java.time.format.DateTimeFormatter
29 import org.onap.cps.api.CpsAnchorService
30 import org.onap.cps.api.CpsDataService
31 import org.onap.cps.api.CpsModuleService
32 import org.onap.cps.api.exceptions.DataNodeNotFoundException
33 import org.onap.cps.api.exceptions.DataValidationException
34 import org.onap.cps.api.model.DataNode
35 import org.onap.cps.api.model.ModuleDefinition
36 import org.onap.cps.api.model.ModuleReference
37 import org.onap.cps.api.parameters.FetchDescendantsOption
38 import org.onap.cps.utils.CpsValidator
39 import org.onap.cps.ncmp.api.exceptions.CmHandleNotFoundException
40 import org.onap.cps.ncmp.api.inventory.models.CompositeState
41 import org.onap.cps.ncmp.api.inventory.models.CmHandleState
42 import org.onap.cps.ncmp.impl.inventory.models.YangModelCmHandle
43 import org.onap.cps.ncmp.impl.utils.YangDataConverter
44 import org.onap.cps.utils.ContentType
45 import org.onap.cps.utils.JsonObjectMapper
46 import spock.lang.Shared
47 import spock.lang.Specification
49 import static org.onap.cps.api.parameters.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS
50 import static org.onap.cps.api.parameters.FetchDescendantsOption.OMIT_DESCENDANTS
51 import static org.onap.cps.ncmp.impl.inventory.NcmpPersistence.NCMP_DATASPACE_NAME
52 import static org.onap.cps.ncmp.impl.inventory.NcmpPersistence.NCMP_DMI_REGISTRY_ANCHOR
53 import static org.onap.cps.ncmp.impl.inventory.NcmpPersistence.NCMP_DMI_REGISTRY_PARENT
54 import static org.onap.cps.ncmp.impl.inventory.NcmpPersistence.NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME
55 import static org.onap.cps.ncmp.impl.inventory.NcmpPersistence.NO_TIMESTAMP
57 class InventoryPersistenceImplSpec extends Specification {
59 def spiedJsonObjectMapper = Spy(new JsonObjectMapper(new ObjectMapper()))
61 def mockCpsDataService = Mock(CpsDataService)
63 def mockCpsModuleService = Mock(CpsModuleService)
65 def mockCpsAnchorService = Mock(CpsAnchorService)
67 def mockCpsValidator = Mock(CpsValidator)
69 def mockCmHandleQueries = Mock(CmHandleQueryService)
71 def mockYangDataConverter = Mock(YangDataConverter)
73 def objectUnderTest = new InventoryPersistenceImpl(mockCpsValidator, spiedJsonObjectMapper, mockCpsAnchorService, mockCpsModuleService, mockCpsDataService, mockCmHandleQueries)
75 def formattedDateAndTime = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
76 .format(OffsetDateTime.of(2022, 12, 31, 20, 30, 40, 1, ZoneOffset.UTC))
78 def cmHandleId = 'some-cm-handle'
79 def alternateId = 'some-alternate-id'
80 def leaves = ["id":cmHandleId, "alternateId":alternateId,"dmi-service-name":"common service name","dmi-data-service-name":"data service name","dmi-model-service-name":"model service name"]
81 def xpath = "/dmi-registry/cm-handles[@id='some-cm-handle']"
83 def cmHandleId2 = 'another-cm-handle'
84 def alternateId2 = 'another-alternate-id'
85 def xpath2 = "/dmi-registry/cm-handles[@id='another-cm-handle']"
87 def dataNode = new DataNode(xpath: "/dmi-registry/cm-handles[@id='some cm handle']/additional-properties[@name='name1']", leaves: leaves)
90 def childDataNodesForCmHandleWithAllProperties = [new DataNode(xpath: "/dmi-registry/cm-handles[@id='some cm handle']/additional-properties[@name='name1']", leaves: ["name":"name1", "value":"value1"]),
91 new DataNode(xpath: "/dmi-registry/cm-handles[@id='some cm handle']/public-properties[@name='name2']", leaves: ["name":"name2","value":"value2"])]
94 def childDataNodesForCmHandleWithDMIProperties = [new DataNode(xpath: "/dmi-registry/cm-handles[@id='some-cm-handle']/additional-properties[@name='name1']", leaves: ["name":"name1", "value":"value1"])]
97 def childDataNodesForCmHandleWithPublicProperties = [new DataNode(xpath: "/dmi-registry/cm-handles[@id='some-cm-handle']/public-properties[@name='name2']", leaves: ["name":"name2","value":"value2"])]
100 def childDataNodesForCmHandleWithState = [new DataNode(xpath: "/dmi-registry/cm-handles[@id='some-cm-handle']/state", leaves: ['cm-handle-state': 'ADVISED'])]
102 def 'Retrieve CmHandle using datanode with #scenario.'() {
103 given: 'the cps data service returns a data node from the DMI registry'
104 def dataNode = new DataNode(childDataNodes:childDataNodes, leaves: leaves)
105 mockCpsDataService.getDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, xpath, INCLUDE_ALL_DESCENDANTS) >> [dataNode]
106 when: 'retrieving the yang modelled cm handle'
107 def result = objectUnderTest.getYangModelCmHandle(cmHandleId)
108 then: 'the result has the correct id and service names'
109 result.id == cmHandleId
110 result.dmiServiceName == 'common service name'
111 result.dmiDataServiceName == 'data service name'
112 result.dmiModelServiceName == 'model service name'
113 and: 'the expected DMI properties'
114 result.dmiProperties == expectedDmiProperties
115 result.publicProperties == expectedPublicProperties
116 and: 'the state details are returned'
117 result.compositeState.cmHandleState == expectedCompositeState
118 and: 'the CM Handle ID is validated'
119 1 * mockCpsValidator.validateNameCharacters(cmHandleId)
120 where: 'the following parameters are used'
121 scenario | childDataNodes || expectedDmiProperties || expectedPublicProperties || expectedCompositeState
122 'no properties' | [] || [] || [] || null
123 'DMI and public properties' | childDataNodesForCmHandleWithAllProperties || [new YangModelCmHandle.Property("name1", "value1")] || [new YangModelCmHandle.Property("name2", "value2")] || null
124 'just DMI properties' | childDataNodesForCmHandleWithDMIProperties || [new YangModelCmHandle.Property("name1", "value1")] || [] || null
125 'just public properties' | childDataNodesForCmHandleWithPublicProperties || [] || [new YangModelCmHandle.Property("name2", "value2")] || null
126 'with state details' | childDataNodesForCmHandleWithState || [] || [] || CmHandleState.ADVISED
129 def 'Handling missing service names as null.'() {
130 given: 'the cps data service returns a data node from the DMI registry with empty child and leaf attributes'
131 def dataNode = new DataNode(childDataNodes:[], leaves: ['id':cmHandleId])
132 mockCpsDataService.getDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, xpath, INCLUDE_ALL_DESCENDANTS) >> [dataNode]
133 when: 'retrieving the yang modelled cm handle'
134 def result = objectUnderTest.getYangModelCmHandle(cmHandleId)
135 then: 'the service names are returned as null'
136 result.dmiServiceName == null
137 result.dmiDataServiceName == null
138 result.dmiModelServiceName == null
139 and: 'the CM Handle ID is validated'
140 1 * mockCpsValidator.validateNameCharacters(cmHandleId)
143 def 'Retrieve multiple YangModelCmHandles using cm handle ids'() {
144 given: 'the cps data service returns 2 data nodes from the DMI registry'
145 def dataNodes = [new DataNode(xpath: xpath, leaves: ['id': cmHandleId]), new DataNode(xpath: xpath2, leaves: ['id': cmHandleId2])]
146 mockCpsDataService.getDataNodesForMultipleXpaths(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, [xpath, xpath2] , INCLUDE_ALL_DESCENDANTS) >> dataNodes
147 when: 'retrieving the yang modelled cm handles'
148 def results = objectUnderTest.getYangModelCmHandles([cmHandleId, cmHandleId2])
149 then: 'verify both have returned and cm handle Ids are correct'
150 assert results.size() == 2
151 assert results.id.containsAll([cmHandleId, cmHandleId2])
154 def 'YangModelCmHandles are not returned for invalid cm handle ids'() {
155 given: 'invalid cm handle id throws a data validation exception'
156 mockCpsValidator.validateNameCharacters('Invalid Cm Handle Id') >> {throw new DataValidationException('','')}
157 and: 'empty collection is returned as no valid cm handle ids are given'
158 mockCpsDataService.getDataNodesForMultipleXpaths(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, [] , INCLUDE_ALL_DESCENDANTS) >> []
159 when: 'retrieving the yang modelled cm handles'
160 def results = objectUnderTest.getYangModelCmHandles(['Invalid Cm Handle Id'])
161 then: 'no YangModelCmHandle is returned'
162 assert results.size() == 0
165 def "Retrieve multiple YangModelCmHandles using cm handle references"() {
166 given: 'the cps data service returns 2 data nodes from the DMI registry'
167 def dataNodes = [new DataNode(xpath: xpath, leaves: ['id': cmHandleId, 'alternate-id':alternateId]), new DataNode(xpath: xpath2, leaves: ['id': cmHandleId2,'alternate-id':alternateId2])]
168 mockCmHandleQueries.queryNcmpRegistryByCpsPath(_, INCLUDE_ALL_DESCENDANTS) >> dataNodes
169 when: 'retrieving the yang modelled cm handle'
170 def results = objectUnderTest.getYangModelCmHandlesFromCmHandleReferences([cmHandleId, cmHandleId2])
171 then: 'verify both have returned and cmhandleIds are correct'
172 assert results.size() == 2
173 assert results.id.containsAll([cmHandleId, cmHandleId2])
176 def 'Get a Cm Handle Composite State'() {
177 given: 'a valid cm handle id'
178 def cmHandleId = 'Some-Cm-Handle'
179 def dataNode = new DataNode(leaves: ['cm-handle-state': 'ADVISED'])
180 and: 'cps data service returns a valid data node'
181 mockCpsDataService.getDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
182 '/dmi-registry/cm-handles[@id=\'Some-Cm-Handle\']/state', FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> [dataNode]
183 when: 'get cm handle state is invoked'
184 def result = objectUnderTest.getCmHandleState(cmHandleId)
185 then: 'result has returned the correct cm handle state'
186 result.cmHandleState == CmHandleState.ADVISED
187 and: 'the CM Handle ID is validated'
188 1 * mockCpsValidator.validateNameCharacters(cmHandleId)
191 def 'Update Cm Handle with #scenario State'() {
192 given: 'a cm handle and a composite state'
193 def cmHandleId = 'Some-Cm-Handle'
194 def compositeState = new CompositeState(cmHandleState: cmHandleState, lastUpdateTime: formattedDateAndTime)
195 when: 'update cm handle state is invoked with the #scenario state'
196 objectUnderTest.saveCmHandleState(cmHandleId, compositeState)
197 then: 'update node leaves is invoked with the correct params'
198 1 * mockCpsDataService.updateDataNodeAndDescendants(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, '/dmi-registry/cm-handles[@id=\'Some-Cm-Handle\']', expectedJsonData, _ as OffsetDateTime, ContentType.JSON)
199 where: 'the following states are used'
200 scenario | cmHandleState || expectedJsonData
201 'READY' | CmHandleState.READY || '{"state":{"cm-handle-state":"READY","last-update-time":"2022-12-31T20:30:40.000+0000"}}'
202 'LOCKED' | CmHandleState.LOCKED || '{"state":{"cm-handle-state":"LOCKED","last-update-time":"2022-12-31T20:30:40.000+0000"}}'
203 'DELETING' | CmHandleState.DELETING || '{"state":{"cm-handle-state":"DELETING","last-update-time":"2022-12-31T20:30:40.000+0000"}}'
206 def 'Update Cm Handles with #scenario States'() {
207 given: 'a map of cm handles composite states'
208 def compositeState1 = new CompositeState(cmHandleState: cmHandleState, lastUpdateTime: formattedDateAndTime)
209 def compositeState2 = new CompositeState(cmHandleState: cmHandleState, lastUpdateTime: formattedDateAndTime)
210 when: 'update cm handle state is invoked with the #scenario state'
211 def cmHandleStateMap = ['Some-Cm-Handle1' : compositeState1, 'Some-Cm-Handle2' : compositeState2]
212 objectUnderTest.saveCmHandleStateBatch(cmHandleStateMap)
213 then: 'update node leaves is invoked with the correct params'
214 1 * mockCpsDataService.updateDataNodesAndDescendants(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, cmHandlesJsonDataMap, _ as OffsetDateTime, ContentType.JSON)
215 where: 'the following states are used'
216 scenario | cmHandleState || cmHandlesJsonDataMap
217 'READY' | CmHandleState.READY || ['/dmi-registry/cm-handles[@id=\'Some-Cm-Handle1\']':'{"state":{"cm-handle-state":"READY","last-update-time":"2022-12-31T20:30:40.000+0000"}}', '/dmi-registry/cm-handles[@id=\'Some-Cm-Handle2\']':'{"state":{"cm-handle-state":"READY","last-update-time":"2022-12-31T20:30:40.000+0000"}}']
218 'LOCKED' | CmHandleState.LOCKED || ['/dmi-registry/cm-handles[@id=\'Some-Cm-Handle1\']':'{"state":{"cm-handle-state":"LOCKED","last-update-time":"2022-12-31T20:30:40.000+0000"}}', '/dmi-registry/cm-handles[@id=\'Some-Cm-Handle2\']':'{"state":{"cm-handle-state":"LOCKED","last-update-time":"2022-12-31T20:30:40.000+0000"}}']
219 'DELETING' | CmHandleState.DELETING || ['/dmi-registry/cm-handles[@id=\'Some-Cm-Handle1\']':'{"state":{"cm-handle-state":"DELETING","last-update-time":"2022-12-31T20:30:40.000+0000"}}', '/dmi-registry/cm-handles[@id=\'Some-Cm-Handle2\']':'{"state":{"cm-handle-state":"DELETING","last-update-time":"2022-12-31T20:30:40.000+0000"}}']
222 def 'Getting module definitions by module'() {
223 given: 'cps module service returns module definition for module name'
224 def moduleDefinitions = [new ModuleDefinition('moduleName','revision','content')]
225 mockCpsModuleService.getModuleDefinitionsByAnchorAndModule(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME,'some-cmHandle-Id', 'some-module', '2024-01-25') >> moduleDefinitions
226 when: 'get module definitions is invoked with module name'
227 def result = objectUnderTest.getModuleDefinitionsByCmHandleAndModule('some-cmHandle-Id', 'some-module', '2024-01-25')
228 then: 'returned result are the same module definitions as returned from module service'
229 assert result == moduleDefinitions
230 and: 'cm handle id and module name validated'
231 1 * mockCpsValidator.validateNameCharacters('some-cmHandle-Id', 'some-module')
234 def 'Getting module definitions with cm handle id'() {
235 given: 'cps module service returns module definitions for cm handle id'
236 def moduleDefinitions = [new ModuleDefinition('moduleName','revision','content')]
237 mockCpsModuleService.getModuleDefinitionsByAnchorName(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME,'some-cmHandle-Id') >> moduleDefinitions
238 when: 'get module definitions is invoked with cm handle id'
239 def result = objectUnderTest.getModuleDefinitionsByCmHandleId('some-cmHandle-Id')
240 then: 'the returned result are the same module definitions as returned from the module service'
241 assert result == moduleDefinitions
244 def 'Get module references'() {
245 given: 'cps module service returns a collection of module references'
246 def moduleReferences = [new ModuleReference('moduleName','revision','namespace')]
247 mockCpsModuleService.getYangResourcesModuleReferences(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME,'some-cmHandle-Id') >> moduleReferences
248 when: 'get yang resources module references by cmHandle is invoked'
249 def result = objectUnderTest.getYangResourcesModuleReferences('some-cmHandle-Id')
250 then: 'the returned result is a collection of module definitions'
251 assert result == moduleReferences
252 and: 'the CM Handle ID is validated'
253 1 * mockCpsValidator.validateNameCharacters('some-cmHandle-Id')
256 def 'Save Cmhandle'() {
257 given: 'cmHandle represented as Yang Model'
258 def yangModelCmHandle = new YangModelCmHandle(id: 'cmhandle', dmiProperties: [], publicProperties: [])
259 when: 'the method to save cmhandle is called'
260 objectUnderTest.saveCmHandle(yangModelCmHandle)
261 then: 'the data service method to save list elements is called once'
262 1 * mockCpsDataService.saveListElements(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, NCMP_DMI_REGISTRY_PARENT,
263 _,null, ContentType.JSON) >> {
265 assert args[3].startsWith('{"cm-handles":[{"id":"cmhandle","additional-properties":[],"public-properties":[]}]}')
270 def 'Save Multiple Cmhandles'() {
271 given: 'cm handles represented as Yang Model'
272 def yangModelCmHandle1 = new YangModelCmHandle(id: 'cmhandle1')
273 def yangModelCmHandle2 = new YangModelCmHandle(id: 'cmhandle2')
274 when: 'the cm handles are saved'
275 objectUnderTest.saveCmHandleBatch([yangModelCmHandle1, yangModelCmHandle2])
276 then: 'CPS Data Service persists both cm handles as a batch'
277 1 * mockCpsDataService.saveListElements(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
278 NCMP_DMI_REGISTRY_PARENT, _,null, ContentType.JSON) >> {
280 def jsonData = (args[3] as String)
281 jsonData.contains('cmhandle1')
282 jsonData.contains('cmhandle2')
287 def 'Delete list or list elements'() {
288 when: 'the method to delete list or list elements is called'
289 objectUnderTest.deleteListOrListElement('sample xPath')
290 then: 'the data service method to save list elements is called once'
291 1 * mockCpsDataService.deleteListOrListElement(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,'sample xPath',null)
294 def 'Get data node via xPath'() {
295 when: 'the method to get data nodes is called'
296 objectUnderTest.getDataNode('sample xPath')
297 then: 'the data persistence service method to get data node is invoked once'
298 1 * mockCpsDataService.getDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,'sample xPath', INCLUDE_ALL_DESCENDANTS)
301 def 'Get cmHandle data node'() {
302 given: 'expected xPath to get cmHandle data node'
303 def expectedXPath = '/dmi-registry/cm-handles[@id=\'sample cmHandleId\']'
304 when: 'the method to get data nodes is called'
305 objectUnderTest.getCmHandleDataNodeByCmHandleId('sample cmHandleId')
306 then: 'the data persistence service method to get cmHandle data node is invoked once with expected xPath'
307 1 * mockCpsDataService.getDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, expectedXPath, INCLUDE_ALL_DESCENDANTS)
310 def 'Get yang model cm handle by alternate id'() {
311 given: 'expected xPath to get cmHandle data node'
312 def expectedXPath = '/dmi-registry/cm-handles[@alternate-id=\'alternate id\']'
313 def expectedDataNode = new DataNode(xpath: expectedXPath, leaves: [id: 'id', alternateId: 'alternate id'])
314 and: 'query service is invoked with expected xpath'
315 mockCmHandleQueries.queryNcmpRegistryByCpsPath(expectedXPath, OMIT_DESCENDANTS) >> [expectedDataNode]
316 mockYangDataConverter.toYangModelCmHandle(expectedDataNode) >> new YangModelCmHandle(id: 'id')
317 expect: 'getting the yang model cm handle'
318 assert objectUnderTest.getYangModelCmHandleByAlternateId('alternate id') == new YangModelCmHandle(id: 'id')
321 def 'Attempt to get non existing yang model cm handle by alternate id'() {
322 given: 'query service is invoked and returns empty collection of data nodes'
323 mockCmHandleQueries.queryNcmpRegistryByCpsPath(*_) >> []
324 when: 'getting the yang model cm handle'
325 objectUnderTest.getYangModelCmHandleByAlternateId('alternate id')
326 then: 'no data found exception thrown'
327 def thrownException = thrown(CmHandleNotFoundException)
328 assert thrownException.getMessage().contains('Cm handle not found')
329 assert thrownException.getDetails().contains('No cm handles found with reference alternate id')
332 def 'Get multiple yang model cm handles by alternate ids #scenario'() {
333 when: 'getting the yang model cm handle with a empty/populated collection of alternate Ids'
334 objectUnderTest.getYangModelCmHandleByAlternateIds(alternateIdCollection)
335 then: 'query service invoked when needed'
336 expectedInvocations * mockCmHandleQueries.queryNcmpRegistryByCpsPath(*_) >> [dataNode]
337 where: 'collections are either empty or populated with alternate ids'
338 scenario | alternateIdCollection || expectedInvocations
339 'empty collection' | [] || 0
340 'populated collection' | ['alt'] || 1
343 def 'Get CM handle ids for CM Handles that has given module names'() {
344 when: 'the method to get cm handles is called'
345 objectUnderTest.getCmHandleReferencesWithGivenModules(['sample-module-name'], false)
346 then: 'the admin persistence service method to query anchors is invoked once with the same parameter'
347 1 * mockCpsAnchorService.queryAnchorNames(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, ['sample-module-name'])
350 def 'Get Alternate Ids for CM Handles that has given module names'() {
351 given: 'A Collection of data nodes'
352 def dataNodes = [new DataNode(xpath: "/dmi-registry/cm-handles[@id='ch-1']", leaves: ['id': 'ch-1', 'alternate-id': 'alt-1'])]
353 when: 'the methods to get dataNodes is called and returns correct values'
354 mockCpsAnchorService.queryAnchorNames(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, ['sample-module-name']) >> ['ch-1']
355 mockCpsDataService.getDataNodesForMultipleXpaths(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, ["/dmi-registry/cm-handles[@id='ch-1']"], INCLUDE_ALL_DESCENDANTS) >> dataNodes
356 and: 'the method returns a result'
357 def result = objectUnderTest.getCmHandleReferencesWithGivenModules(['sample-module-name'], true)
358 then: 'the result contains the correct alternate Id'
359 assert result == ['alt-1'] as HashSet
362 def 'Replace list content'() {
363 when: 'replace list content method is called with xpath and data nodes collection'
364 objectUnderTest.replaceListContent('sample xpath', [new DataNode()])
365 then: 'the cps data service method to replace list content is invoked once with same parameters'
366 1 * mockCpsDataService.replaceListContent(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,'sample xpath', [new DataNode()], NO_TIMESTAMP);
369 def 'Delete data node via xPath'() {
370 when: 'Delete data node method is called with xpath as parameter'
371 objectUnderTest.deleteDataNode('sample dataNode xpath')
372 then: 'the cps data service method to delete data node is invoked once with the same xPath'
373 1 * mockCpsDataService.deleteDataNode(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, 'sample dataNode xpath', NO_TIMESTAMP);
376 def 'Delete multiple data nodes via xPath'() {
377 when: 'Delete data nodes method is called with multiple xpaths as parameters'
378 objectUnderTest.deleteDataNodes(['xpath1', 'xpath2'])
379 then: 'the cps data service method to delete data nodes is invoked once with the same xPaths'
380 1 * mockCpsDataService.deleteDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, ['xpath1', 'xpath2'], NO_TIMESTAMP);
383 def 'CM handle exists'() {
384 given: 'data service returns a datanode with correct cm handle id'
385 mockCpsDataService.getDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, xpath, INCLUDE_ALL_DESCENDANTS) >> [dataNode]
386 expect: 'cm handle exists for given cm handle id'
387 assert true == objectUnderTest.isExistingCmHandleId(cmHandleId)
390 def 'CM handle does not exist, empty dataNode collection returned'() {
391 given: 'data service returns an empty datanode'
392 mockCpsDataService.getDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, xpath, INCLUDE_ALL_DESCENDANTS) >> []
393 expect: 'false is returned for non-existent cm handle'
394 assert false == objectUnderTest.isExistingCmHandleId(cmHandleId)
397 def 'CM handle does not exist, exception thrown'() {
398 given: 'data service throws an exception'
399 mockCpsDataService.getDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, "/dmi-registry/cm-handles[@id='non-existent-cm-handle']", INCLUDE_ALL_DESCENDANTS) >> {throw new DataNodeNotFoundException('','')}
400 expect: 'false is returned for non-existent cm handle'
401 assert false == objectUnderTest.isExistingCmHandleId('non-existent-cm-handle')