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.models.PersistenceCmHandle
 
  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 PersistenceCmHandleRetrieverSpec extends Specification {
 
  33     def mockCpsDataService = Mock(CpsDataService)
 
  35     def objectUnderTest = new PersistenceCmHandleRetriever(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 childDataNodesForCmHandleProperties = [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"])]
 
  45     def "Retrieve CmHandle using datanode #scenario."() {
 
  46         given: 'the cps data service returns a data node from the DMI registry'
 
  47             def dataNode = new DataNode(childDataNodes:childDataNodes, leaves: leaves)
 
  48             mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry', xpath, INCLUDE_ALL_DESCENDANTS) >> dataNode
 
  49         when: 'retrieving the persisted cm handle'
 
  50             def result = objectUnderTest.retrieveCmHandleDmiServiceNameAndDmiProperties(cmHandleId)
 
  51         then: 'the result has the correct id and service names'
 
  52             result.id == cmHandleId
 
  53             result.dmiServiceName == 'common service name'
 
  54             result.dmiDataServiceName == 'data service name'
 
  55             result.dmiModelServiceName == 'model service name'
 
  56         and: 'the expected DMI properties'
 
  57             result.dmiProperties == expectedCmHandleProperties
 
  58         where: 'the following parameters are used'
 
  59             scenario                 | childDataNodes                      || expectedCmHandleProperties
 
  60             'without DMI properties' | []                                  || []
 
  61             'with DMI properties'    | childDataNodesForCmHandleProperties || [new PersistenceCmHandle.Property("name1", "value1")]