3ab9266ba4e2bf8b5177deaa6cf98c9d042fef43
[cps.git] / cps-ncmp-service / src / test / groovy / org / onap / cps / ncmp / api / impl / operations / PersistenceCmHandleRetrieverSpec.groovy
1 package org.onap.cps.ncmp.api.impl.operations
2
3 import org.onap.cps.api.CpsDataService
4 import org.onap.cps.ncmp.api.models.PersistenceCmHandle
5 import spock.lang.Shared
6
7 import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS
8 import org.onap.cps.spi.model.DataNode
9 import spock.lang.Specification
10
11 class PersistenceCmHandleRetrieverSpec extends Specification {
12
13     def mockCpsDataService = Mock(CpsDataService)
14
15     def objectUnderTest = new PersistenceCmHandleRetriever(mockCpsDataService)
16
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']"
20
21     @Shared
22     def childDataNodesForCmHandleProperties = [new DataNode(leaves: ["name":"name1","value":"value1"]),
23                                                new DataNode(leaves: ["name":"name2","value":"value2"])]
24
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")]
43     }
44 }