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.utils.CpsValidator
38 import org.onap.cps.ncmp.api.exceptions.CmHandleNotFoundException
39 import org.onap.cps.ncmp.api.inventory.models.CompositeState
40 import org.onap.cps.ncmp.api.inventory.models.CmHandleState
41 import org.onap.cps.ncmp.impl.inventory.models.YangModelCmHandle
42 import org.onap.cps.ncmp.impl.utils.YangDataConverter
43 import org.onap.cps.utils.ContentType
44 import org.onap.cps.utils.JsonObjectMapper
45 import spock.lang.Shared
46 import spock.lang.Specification
48 import static org.onap.cps.api.parameters.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS
49 import static org.onap.cps.api.parameters.FetchDescendantsOption.OMIT_DESCENDANTS
50 import static org.onap.cps.ncmp.impl.inventory.NcmpPersistence.NCMP_DATASPACE_NAME
51 import static org.onap.cps.ncmp.impl.inventory.NcmpPersistence.NCMP_DMI_REGISTRY_ANCHOR
52 import static org.onap.cps.ncmp.impl.inventory.NcmpPersistence.NCMP_DMI_REGISTRY_PARENT
53 import static org.onap.cps.ncmp.impl.inventory.NcmpPersistence.NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME
54 import static org.onap.cps.ncmp.impl.inventory.NcmpPersistence.NO_TIMESTAMP
56 class InventoryPersistenceImplSpec extends Specification {
58 def spiedJsonObjectMapper = Spy(new JsonObjectMapper(new ObjectMapper()))
60 def mockCpsDataService = Mock(CpsDataService)
62 def mockCpsModuleService = Mock(CpsModuleService)
64 def mockCpsAnchorService = Mock(CpsAnchorService)
66 def mockCpsValidator = Mock(CpsValidator)
68 def mockCmHandleQueries = Mock(CmHandleQueryService)
70 def mockYangDataConverter = Mock(YangDataConverter)
72 def objectUnderTest = new InventoryPersistenceImpl(mockCpsValidator, spiedJsonObjectMapper, mockCpsAnchorService, mockCpsModuleService, mockCpsDataService, mockCmHandleQueries)
74 def formattedDateAndTime = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
75 .format(OffsetDateTime.of(2022, 12, 31, 20, 30, 40, 1, ZoneOffset.UTC))
77 def cmHandleId = 'some-cm-handle'
78 def alternateId = 'some-alternate-id'
79 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"]
80 def xpath = "/dmi-registry/cm-handles[@id='some-cm-handle']"
82 def cmHandleId2 = 'another-cm-handle'
83 def alternateId2 = 'another-alternate-id'
84 def xpath2 = "/dmi-registry/cm-handles[@id='another-cm-handle']"
86 def dataNode = new DataNode(xpath: "/dmi-registry/cm-handles[@id='some cm handle']/additional-properties[@name='name1']", leaves: leaves)
89 def childDataNodesForCmHandleWithAllProperties = [new DataNode(xpath: "/dmi-registry/cm-handles[@id='some cm handle']/additional-properties[@name='name1']", leaves: ["name":"name1", "value":"value1"]),
90 new DataNode(xpath: "/dmi-registry/cm-handles[@id='some cm handle']/public-properties[@name='name2']", leaves: ["name":"name2","value":"value2"])]
93 def childDataNodesForCmHandleWithDMIProperties = [new DataNode(xpath: "/dmi-registry/cm-handles[@id='some-cm-handle']/additional-properties[@name='name1']", leaves: ["name":"name1", "value":"value1"])]
96 def childDataNodesForCmHandleWithPublicProperties = [new DataNode(xpath: "/dmi-registry/cm-handles[@id='some-cm-handle']/public-properties[@name='name2']", leaves: ["name":"name2","value":"value2"])]
99 def childDataNodesForCmHandleWithState = [new DataNode(xpath: "/dmi-registry/cm-handles[@id='some-cm-handle']/state", leaves: ['cm-handle-state': 'ADVISED'])]
101 def 'Retrieve CmHandle using datanode with #scenario.'() {
102 given: 'the cps data service returns a data node from the DMI registry'
103 def dataNode = new DataNode(childDataNodes:childDataNodes, leaves: leaves)
104 mockCpsDataService.getDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, xpath, INCLUDE_ALL_DESCENDANTS) >> [dataNode]
105 when: 'retrieving the yang modelled cm handle'
106 def result = objectUnderTest.getYangModelCmHandle(cmHandleId)
107 then: 'the result has the correct id and service names'
108 result.id == cmHandleId
109 result.dmiServiceName == 'common service name'
110 result.dmiDataServiceName == 'data service name'
111 result.dmiModelServiceName == 'model service name'
112 and: 'the expected DMI properties'
113 result.dmiProperties == expectedDmiProperties
114 result.publicProperties == expectedPublicProperties
115 and: 'the state details are returned'
116 result.compositeState.cmHandleState == expectedCompositeState
117 and: 'the CM Handle ID is validated'
118 1 * mockCpsValidator.validateNameCharacters(cmHandleId)
119 where: 'the following parameters are used'
120 scenario | childDataNodes || expectedDmiProperties || expectedPublicProperties || expectedCompositeState
121 'no properties' | [] || [] || [] || null
122 'DMI and public properties' | childDataNodesForCmHandleWithAllProperties || [new YangModelCmHandle.Property("name1", "value1")] || [new YangModelCmHandle.Property("name2", "value2")] || null
123 'just DMI properties' | childDataNodesForCmHandleWithDMIProperties || [new YangModelCmHandle.Property("name1", "value1")] || [] || null
124 'just public properties' | childDataNodesForCmHandleWithPublicProperties || [] || [new YangModelCmHandle.Property("name2", "value2")] || null
125 'with state details' | childDataNodesForCmHandleWithState || [] || [] || CmHandleState.ADVISED
128 def 'Handling missing service names as null.'() {
129 given: 'the cps data service returns a data node from the DMI registry with empty child and leaf attributes'
130 def dataNode = new DataNode(childDataNodes:[], leaves: ['id':cmHandleId])
131 mockCpsDataService.getDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, xpath, INCLUDE_ALL_DESCENDANTS) >> [dataNode]
132 when: 'retrieving the yang modelled cm handle'
133 def result = objectUnderTest.getYangModelCmHandle(cmHandleId)
134 then: 'the service names are returned as null'
135 result.dmiServiceName == null
136 result.dmiDataServiceName == null
137 result.dmiModelServiceName == null
138 and: 'the CM Handle ID is validated'
139 1 * mockCpsValidator.validateNameCharacters(cmHandleId)
142 def 'Retrieve multiple YangModelCmHandles using cm handle ids'() {
143 given: 'the cps data service returns 2 data nodes from the DMI registry'
144 def dataNodes = [new DataNode(xpath: xpath, leaves: ['id': cmHandleId]), new DataNode(xpath: xpath2, leaves: ['id': cmHandleId2])]
145 mockCpsDataService.getDataNodesForMultipleXpaths(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, [xpath, xpath2] , INCLUDE_ALL_DESCENDANTS) >> dataNodes
146 when: 'retrieving the yang modelled cm handles'
147 def results = objectUnderTest.getYangModelCmHandles([cmHandleId, cmHandleId2])
148 then: 'verify both have returned and cm handle Ids are correct'
149 assert results.size() == 2
150 assert results.id.containsAll([cmHandleId, cmHandleId2])
153 def 'YangModelCmHandles are not returned for invalid cm handle ids'() {
154 given: 'invalid cm handle id throws a data validation exception'
155 mockCpsValidator.validateNameCharacters('Invalid Cm Handle Id') >> {throw new DataValidationException('','')}
156 and: 'empty collection is returned as no valid cm handle ids are given'
157 mockCpsDataService.getDataNodesForMultipleXpaths(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, [] , INCLUDE_ALL_DESCENDANTS) >> []
158 when: 'retrieving the yang modelled cm handles'
159 def results = objectUnderTest.getYangModelCmHandles(['Invalid Cm Handle Id'])
160 then: 'no YangModelCmHandle is returned'
161 assert results.size() == 0
164 def 'Get a Cm Handle Composite State'() {
165 given: 'a valid cm handle id'
166 def cmHandleId = 'Some-Cm-Handle'
167 def dataNode = new DataNode(leaves: ['cm-handle-state': 'ADVISED'])
168 and: 'cps data service returns a valid data node'
169 mockCpsDataService.getDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
170 '/dmi-registry/cm-handles[@id=\'Some-Cm-Handle\']/state', INCLUDE_ALL_DESCENDANTS) >> [dataNode]
171 when: 'get cm handle state is invoked'
172 def result = objectUnderTest.getCmHandleState(cmHandleId)
173 then: 'result has returned the correct cm handle state'
174 result.cmHandleState == CmHandleState.ADVISED
175 and: 'the CM Handle ID is validated'
176 1 * mockCpsValidator.validateNameCharacters(cmHandleId)
179 def 'Update Cm Handle with #scenario State'() {
180 given: 'a cm handle and a composite state'
181 def cmHandleId = 'Some-Cm-Handle'
182 def compositeState = new CompositeState(cmHandleState: cmHandleState, lastUpdateTime: formattedDateAndTime)
183 when: 'update cm handle state is invoked with the #scenario state'
184 objectUnderTest.saveCmHandleState(cmHandleId, compositeState)
185 then: 'update node leaves is invoked with the correct params'
186 1 * mockCpsDataService.updateDataNodeAndDescendants(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, '/dmi-registry/cm-handles[@id=\'Some-Cm-Handle\']', expectedJsonData, _ as OffsetDateTime, ContentType.JSON)
187 where: 'the following states are used'
188 scenario | cmHandleState || expectedJsonData
189 'READY' | CmHandleState.READY || '{"state":{"cm-handle-state":"READY","last-update-time":"2022-12-31T20:30:40.000+0000"}}'
190 'LOCKED' | CmHandleState.LOCKED || '{"state":{"cm-handle-state":"LOCKED","last-update-time":"2022-12-31T20:30:40.000+0000"}}'
191 'DELETING' | CmHandleState.DELETING || '{"state":{"cm-handle-state":"DELETING","last-update-time":"2022-12-31T20:30:40.000+0000"}}'
194 def 'Update Cm Handles with #scenario States'() {
195 given: 'a map of cm handles composite states'
196 def compositeState1 = new CompositeState(cmHandleState: cmHandleState, lastUpdateTime: formattedDateAndTime)
197 def compositeState2 = new CompositeState(cmHandleState: cmHandleState, lastUpdateTime: formattedDateAndTime)
198 when: 'update cm handle state is invoked with the #scenario state'
199 def cmHandleStateMap = ['Some-Cm-Handle1' : compositeState1, 'Some-Cm-Handle2' : compositeState2]
200 objectUnderTest.saveCmHandleStateBatch(cmHandleStateMap)
201 then: 'update node leaves is invoked with the correct params'
202 1 * mockCpsDataService.updateDataNodesAndDescendants(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, cmHandlesJsonDataMap, _ as OffsetDateTime, ContentType.JSON)
203 where: 'the following states are used'
204 scenario | cmHandleState || cmHandlesJsonDataMap
205 '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"}}']
206 '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"}}']
207 '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"}}']
210 def 'Getting module definitions by module'() {
211 given: 'cps module service returns module definition for module name'
212 def moduleDefinitions = [new ModuleDefinition('moduleName','revision','content')]
213 mockCpsModuleService.getModuleDefinitionsByAnchorAndModule(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME,'some-cmHandle-Id', 'some-module', '2024-01-25') >> moduleDefinitions
214 when: 'get module definitions is invoked with module name'
215 def result = objectUnderTest.getModuleDefinitionsByCmHandleAndModule('some-cmHandle-Id', 'some-module', '2024-01-25')
216 then: 'returned result are the same module definitions as returned from module service'
217 assert result == moduleDefinitions
218 and: 'cm handle id and module name validated'
219 1 * mockCpsValidator.validateNameCharacters('some-cmHandle-Id', 'some-module')
222 def 'Getting module definitions with cm handle id'() {
223 given: 'cps module service returns module definitions for cm handle id'
224 def moduleDefinitions = [new ModuleDefinition('moduleName','revision','content')]
225 mockCpsModuleService.getModuleDefinitionsByAnchorName(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME,'some-cmHandle-Id') >> moduleDefinitions
226 when: 'get module definitions is invoked with cm handle id'
227 def result = objectUnderTest.getModuleDefinitionsByCmHandleId('some-cmHandle-Id')
228 then: 'the returned result are the same module definitions as returned from the module service'
229 assert result == moduleDefinitions
232 def 'Get module references'() {
233 given: 'cps module service returns a collection of module references'
234 def moduleReferences = [new ModuleReference('moduleName','revision','namespace')]
235 mockCpsModuleService.getYangResourcesModuleReferences(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME,'some-cmHandle-Id') >> moduleReferences
236 when: 'get yang resources module references by cmHandle is invoked'
237 def result = objectUnderTest.getYangResourcesModuleReferences('some-cmHandle-Id')
238 then: 'the returned result is a collection of module definitions'
239 assert result == moduleReferences
240 and: 'the CM Handle ID is validated'
241 1 * mockCpsValidator.validateNameCharacters('some-cmHandle-Id')
244 def 'Save Cmhandle'() {
245 given: 'cmHandle represented as Yang Model'
246 def yangModelCmHandle = new YangModelCmHandle(id: 'cmhandle', dmiProperties: [], publicProperties: [])
247 when: 'the method to save cmhandle is called'
248 objectUnderTest.saveCmHandle(yangModelCmHandle)
249 then: 'the data service method to save list elements is called once'
250 1 * mockCpsDataService.saveListElements(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, NCMP_DMI_REGISTRY_PARENT,
251 _,null, ContentType.JSON) >> {
253 assert args[3].startsWith('{"cm-handles":[{"id":"cmhandle","additional-properties":[],"public-properties":[]}]}')
258 def 'Save Multiple Cmhandles'() {
259 given: 'cm handles represented as Yang Model'
260 def yangModelCmHandle1 = new YangModelCmHandle(id: 'cmhandle1')
261 def yangModelCmHandle2 = new YangModelCmHandle(id: 'cmhandle2')
262 when: 'the cm handles are saved'
263 objectUnderTest.saveCmHandleBatch([yangModelCmHandle1, yangModelCmHandle2])
264 then: 'CPS Data Service persists both cm handles as a batch'
265 1 * mockCpsDataService.saveListElements(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
266 NCMP_DMI_REGISTRY_PARENT, _,null, ContentType.JSON) >> {
268 def jsonData = (args[3] as String)
269 jsonData.contains('cmhandle1')
270 jsonData.contains('cmhandle2')
275 def 'Delete list or list elements'() {
276 when: 'the method to delete list or list elements is called'
277 objectUnderTest.deleteListOrListElement('sample xPath')
278 then: 'the data service method to save list elements is called once'
279 1 * mockCpsDataService.deleteListOrListElement(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,'sample xPath',null)
282 def 'Get data node via xPath'() {
283 when: 'the method to get data nodes is called'
284 objectUnderTest.getDataNode('sample xPath')
285 then: 'the data persistence service method to get data node is invoked once'
286 1 * mockCpsDataService.getDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,'sample xPath', INCLUDE_ALL_DESCENDANTS)
289 def 'Get cmHandle data node'() {
290 given: 'expected xPath to get cmHandle data node'
291 def expectedXPath = '/dmi-registry/cm-handles[@id=\'sample cmHandleId\']'
292 when: 'the method to get data nodes is called'
293 objectUnderTest.getCmHandleDataNodeByCmHandleId('sample cmHandleId', INCLUDE_ALL_DESCENDANTS)
294 then: 'the data persistence service method to get cmHandle data node is invoked once with expected xPath'
295 1 * mockCpsDataService.getDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, expectedXPath, INCLUDE_ALL_DESCENDANTS)
298 def 'Get yang model cm handle by alternate id'() {
299 given: 'expected xPath to get cmHandle data node'
300 def expectedXPath = '/dmi-registry/cm-handles[@alternate-id=\'alternate id\']'
301 def expectedDataNode = new DataNode(xpath: expectedXPath, leaves: [id: 'id', alternateId: 'alternate id'])
302 and: 'query service is invoked with expected xpath'
303 mockCmHandleQueries.queryNcmpRegistryByCpsPath(expectedXPath, OMIT_DESCENDANTS, _) >> [expectedDataNode]
304 mockYangDataConverter.toYangModelCmHandle(expectedDataNode) >> new YangModelCmHandle(id: 'id')
305 expect: 'getting the yang model cm handle'
306 assert objectUnderTest.getYangModelCmHandleByAlternateId('alternate id') == new YangModelCmHandle(id: 'id')
309 def 'Attempt to get non existing yang model cm handle by alternate id'() {
310 given: 'query service is invoked and returns empty collection of data nodes'
311 mockCmHandleQueries.queryNcmpRegistryByCpsPath(*_) >> []
312 when: 'getting the yang model cm handle'
313 objectUnderTest.getYangModelCmHandleByAlternateId('alternate id')
314 then: 'no data found exception thrown'
315 def thrownException = thrown(CmHandleNotFoundException)
316 assert thrownException.getMessage().contains('Cm handle not found')
317 assert thrownException.getDetails().contains('No cm handles found with reference alternate id')
320 def 'Get multiple yang model cm handles by alternate ids #scenario'() {
321 when: 'getting the yang model cm handle with a empty/populated collection of alternate Ids'
322 objectUnderTest.getYangModelCmHandleByAlternateIds(alternateIdCollection)
323 then: 'query service invoked when needed'
324 expectedInvocations * mockCmHandleQueries.queryNcmpRegistryByCpsPath(*_) >> [dataNode]
325 where: 'collections are either empty or populated with alternate ids'
326 scenario | alternateIdCollection || expectedInvocations
327 'empty collection' | [] || 0
328 'populated collection' | ['alt'] || 1
331 def 'Get CM handle ids for CM Handles that has given module names'() {
332 when: 'the method to get cm handles is called'
333 objectUnderTest.getCmHandleReferencesWithGivenModules(['sample-module-name'], false)
334 then: 'the admin persistence service method to query anchors is invoked once with the same parameter'
335 1 * mockCpsAnchorService.queryAnchorNames(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, ['sample-module-name'])
338 def 'Get Alternate Ids for CM Handles that has given module names'() {
339 given: 'A Collection of data nodes'
340 def dataNodes = [new DataNode(xpath: "/dmi-registry/cm-handles[@id='ch-1']", leaves: ['id': 'ch-1', 'alternate-id': 'alt-1'])]
341 when: 'the methods to get dataNodes is called and returns correct values'
342 mockCpsAnchorService.queryAnchorNames(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, ['sample-module-name']) >> ['ch-1']
343 mockCpsDataService.getDataNodesForMultipleXpaths(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, ["/dmi-registry/cm-handles[@id='ch-1']"], INCLUDE_ALL_DESCENDANTS) >> dataNodes
344 and: 'the method returns a result'
345 def result = objectUnderTest.getCmHandleReferencesWithGivenModules(['sample-module-name'], true)
346 then: 'the result contains the correct alternate Id'
347 assert result == ['alt-1'] as HashSet
350 def 'Replace list content'() {
351 when: 'replace list content method is called with xpath and data nodes collection'
352 objectUnderTest.replaceListContent('sample xpath', [new DataNode()])
353 then: 'the cps data service method to replace list content is invoked once with same parameters'
354 1 * mockCpsDataService.replaceListContent(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,'sample xpath', [new DataNode()], NO_TIMESTAMP);
357 def 'Delete data node via xPath'() {
358 when: 'Delete data node method is called with xpath as parameter'
359 objectUnderTest.deleteDataNode('sample dataNode xpath')
360 then: 'the cps data service method to delete data node is invoked once with the same xPath'
361 1 * mockCpsDataService.deleteDataNode(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, 'sample dataNode xpath', NO_TIMESTAMP);
364 def 'Delete multiple data nodes via xPath'() {
365 when: 'Delete data nodes method is called with multiple xpaths as parameters'
366 objectUnderTest.deleteDataNodes(['xpath1', 'xpath2'])
367 then: 'the cps data service method to delete data nodes is invoked once with the same xPaths'
368 1 * mockCpsDataService.deleteDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, ['xpath1', 'xpath2'], NO_TIMESTAMP);
371 def 'CM handle exists'() {
372 given: 'data service returns a datanode with correct cm handle id'
373 mockCpsDataService.getDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, xpath, OMIT_DESCENDANTS) >> [dataNode]
374 expect: 'cm handle exists for given cm handle id'
375 assert true == objectUnderTest.isExistingCmHandleId(cmHandleId)
378 def 'CM handle does not exist, empty dataNode collection returned'() {
379 given: 'data service returns an empty datanode'
380 mockCpsDataService.getDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, xpath, OMIT_DESCENDANTS) >> []
381 expect: 'false is returned for non-existent cm handle'
382 assert false == objectUnderTest.isExistingCmHandleId(cmHandleId)
385 def 'CM handle does not exist, exception thrown'() {
386 given: 'data service throws an exception'
387 mockCpsDataService.getDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, "/dmi-registry/cm-handles[@id='non-existent-cm-handle']", OMIT_DESCENDANTS) >> {throw new DataNodeNotFoundException('','')}
388 expect: 'false is returned for non-existent cm handle'
389 assert false == objectUnderTest.isExistingCmHandleId('non-existent-cm-handle')