2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021-2022 Nordix Foundation
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * 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.ncmp.api.impl.operations
23 import org.onap.cps.api.CpsDataService
24 import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle
25 import spock.lang.Shared
27 import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS
28 import org.onap.cps.spi.model.DataNode
29 import spock.lang.Specification
31 class YangModelCmHandleRetrieverSpec extends Specification {
33 def mockCpsDataService = Mock(CpsDataService)
35 def objectUnderTest = new YangModelCmHandleRetriever(mockCpsDataService)
37 def cmHandleId = 'some cm handle'
38 def leaves = ["dmi-service-name":"common service name","dmi-data-service-name":"data service name","dmi-model-service-name":"model service name"]
39 def xpath = "/dmi-registry/cm-handles[@id='some cm handle']"
42 def childDataNodesForCmHandleWithAllProperties = [new DataNode(xpath: "/dmi-registry/cm-handles[@id='some cm handle']/additional-properties[@name='name1']", leaves: ["name":"name1", "value":"value1"]),
43 new DataNode(xpath: "/dmi-registry/cm-handles[@id='some cm handle']/public-properties[@name='name2']", leaves: ["name":"name2","value":"value2"])]
46 def childDataNodesForCmHandleWithDMIProperties = [new DataNode(xpath: "/dmi-registry/cm-handles[@id='some cm handle']/additional-properties[@name='name1']", leaves: ["name":"name1", "value":"value1"])]
49 def childDataNodesForCmHandleWithPublicProperties = [new DataNode(xpath: "/dmi-registry/cm-handles[@id='some cm handle']/public-properties[@name='name2']", leaves: ["name":"name2","value":"value2"])]
51 def "Retrieve CmHandle using datanode with #scenario."() {
52 given: 'the cps data service returns a data node from the DMI registry'
53 def dataNode = new DataNode(childDataNodes:childDataNodes, leaves: leaves)
54 mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry', xpath, INCLUDE_ALL_DESCENDANTS) >> dataNode
55 when: 'retrieving the yang modelled cm handle'
56 def result = objectUnderTest.getDmiServiceNamesAndProperties(cmHandleId)
57 then: 'the result has the correct id and service names'
58 result.id == cmHandleId
59 result.dmiServiceName == 'common service name'
60 result.dmiDataServiceName == 'data service name'
61 result.dmiModelServiceName == 'model service name'
62 and: 'the expected DMI properties'
63 result.dmiProperties == expectedDmiProperties
64 result.publicProperties == expectedPublicProperties
65 where: 'the following parameters are used'
66 scenario | childDataNodes || expectedDmiProperties || expectedPublicProperties
67 'no properties' | [] || [] || []
68 'DMI and public properties' | childDataNodesForCmHandleWithAllProperties || [new YangModelCmHandle.Property("name1", "value1")] || [new YangModelCmHandle.Property("name2", "value2")]
69 'just DMI properties' | childDataNodesForCmHandleWithDMIProperties || [new YangModelCmHandle.Property("name1", "value1")] || []
70 'just public properties' | childDataNodesForCmHandleWithPublicProperties || [] || [new YangModelCmHandle.Property("name2", "value2")]