X-Git-Url: https://gerrit.onap.org/r/gitweb?p=cps.git;a=blobdiff_plain;f=cps-ncmp-service%2Fsrc%2Ftest%2Fgroovy%2Forg%2Fonap%2Fcps%2Fncmp%2Fapi%2Fimpl%2Foperations%2FYangModelCmHandleRetrieverSpec.groovy;h=5ecc8b0da376ea5466224663ab051f38f8e8e7b9;hp=593a6ec936892d48a12b4c92f1b700081478f334;hb=ef62391fb034f599f92b113e27f90f7cedc1a5c0;hpb=59aa954d37f8819acc1f927d045087254e7a6aea diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/YangModelCmHandleRetrieverSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/YangModelCmHandleRetrieverSpec.groovy index 593a6ec93..5ecc8b0da 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/YangModelCmHandleRetrieverSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/YangModelCmHandleRetrieverSpec.groovy @@ -22,6 +22,7 @@ package org.onap.cps.ncmp.api.impl.operations import org.onap.cps.api.CpsDataService import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle +import org.onap.cps.spi.exceptions.DataValidationException import spock.lang.Shared import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS @@ -34,26 +35,26 @@ class YangModelCmHandleRetrieverSpec extends Specification { def objectUnderTest = new YangModelCmHandleRetriever(mockCpsDataService) - def cmHandleId = 'some cm handle' + def cmHandleId = 'some-cm-handle' def leaves = ["dmi-service-name":"common service name","dmi-data-service-name":"data service name","dmi-model-service-name":"model service name"] - def xpath = "/dmi-registry/cm-handles[@id='some cm handle']" + def xpath = "/dmi-registry/cm-handles[@id='some-cm-handle']" @Shared def childDataNodesForCmHandleWithAllProperties = [new DataNode(xpath: "/dmi-registry/cm-handles[@id='some cm handle']/additional-properties[@name='name1']", leaves: ["name":"name1", "value":"value1"]), new DataNode(xpath: "/dmi-registry/cm-handles[@id='some cm handle']/public-properties[@name='name2']", leaves: ["name":"name2","value":"value2"])] @Shared - def childDataNodesForCmHandleWithDMIProperties = [new DataNode(xpath: "/dmi-registry/cm-handles[@id='some cm handle']/additional-properties[@name='name1']", leaves: ["name":"name1", "value":"value1"])] + def childDataNodesForCmHandleWithDMIProperties = [new DataNode(xpath: "/dmi-registry/cm-handles[@id='some-cm-handle']/additional-properties[@name='name1']", leaves: ["name":"name1", "value":"value1"])] @Shared - def childDataNodesForCmHandleWithPublicProperties = [new DataNode(xpath: "/dmi-registry/cm-handles[@id='some cm handle']/public-properties[@name='name2']", leaves: ["name":"name2","value":"value2"])] + def childDataNodesForCmHandleWithPublicProperties = [new DataNode(xpath: "/dmi-registry/cm-handles[@id='some-cm-handle']/public-properties[@name='name2']", leaves: ["name":"name2","value":"value2"])] def "Retrieve CmHandle using datanode with #scenario."() { given: 'the cps data service returns a data node from the DMI registry' def dataNode = new DataNode(childDataNodes:childDataNodes, leaves: leaves) mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry', xpath, INCLUDE_ALL_DESCENDANTS) >> dataNode when: 'retrieving the yang modelled cm handle' - def result = objectUnderTest.getDmiServiceNamesAndProperties(cmHandleId) + def result = objectUnderTest.getYangModelCmHandle(cmHandleId) then: 'the result has the correct id and service names' result.id == cmHandleId result.dmiServiceName == 'common service name' @@ -69,4 +70,25 @@ class YangModelCmHandleRetrieverSpec extends Specification { 'just DMI properties' | childDataNodesForCmHandleWithDMIProperties || [new YangModelCmHandle.Property("name1", "value1")] || [] 'just public properties' | childDataNodesForCmHandleWithPublicProperties || [] || [new YangModelCmHandle.Property("name2", "value2")] } + + def "Retrieve CmHandle using datanode with invalid CmHandle id."() { + when: 'retrieving the yang modelled cm handle with an invalid id' + def result = objectUnderTest.getYangModelCmHandle('cm handle id with spaces') + then: 'a data validation exception is thrown' + thrown(DataValidationException) + and: 'the result is not returned' + result == null + } + + def "Handling missing service names as null CPS-1043."() { + given: 'the cps data service returns a data node from the DMI registry with empty child and leaf attributes' + def dataNode = new DataNode(childDataNodes:[], leaves: [:]) + mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry', xpath, INCLUDE_ALL_DESCENDANTS) >> dataNode + when: 'retrieving the yang modelled cm handle' + def result = objectUnderTest.getYangModelCmHandle(cmHandleId) + then: 'the service names ae returned as null' + result.dmiServiceName == null + result.dmiDataServiceName == null + result.dmiModelServiceName == null + } }