1 package org.onap.cps.ncmp.api.impl.operations
3 import org.onap.cps.api.CpsDataService
4 import org.onap.cps.ncmp.api.models.PersistenceCmHandle
5 import spock.lang.Shared
7 import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS
8 import org.onap.cps.spi.model.DataNode
9 import spock.lang.Specification
11 class PersistenceCmHandleRetrieverSpec extends Specification {
13 def mockCpsDataService = Mock(CpsDataService)
15 def objectUnderTest = new PersistenceCmHandleRetriever(mockCpsDataService)
17 def cmHandleId = 'some cm handle'
18 def leaves = ["dmi-service-name":"common service name","dmi-data-service-name":"data service name","dmi-model-service-name":"model service name"]
19 def xpath = "/dmi-registry/cm-handles[@id='some cm handle']"
22 def childDataNodesForCmHandleProperties = [new DataNode(leaves: ["name":"name1","value":"value1"]),
23 new DataNode(leaves: ["name":"name2","value":"value2"])]
25 def "Retrieve CmHandle using datanode #scenario."() {
26 given: 'the cps data service returns a data node from the dmi registry'
27 def dataNode = new DataNode(childDataNodes:childDataNodes, leaves: leaves)
28 mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry', xpath, INCLUDE_ALL_DESCENDANTS) >> dataNode
29 when: 'retrieving the persisted cm handle'
30 def result = objectUnderTest.retrieveCmHandleDmiServiceNameAndProperties(cmHandleId)
31 then: 'the result has the correct id and service names'
32 result.id == cmHandleId
33 result.dmiServiceName == 'common service name'
34 result.dmiDataServiceName == 'data service name'
35 result.dmiModelServiceName == 'model service name'
36 and: 'the expected additional properties'
37 result.additionalProperties == expectedCmHandleProperties
38 where: 'the following parameters are used'
39 scenario | childDataNodes || expectedCmHandleProperties
40 'without additional properties' | [] || []
41 'with additional properties' | childDataNodesForCmHandleProperties || [new PersistenceCmHandle.AdditionalProperty("name1", "value1"),
42 new PersistenceCmHandle.AdditionalProperty("name2", "value2")]