From bed18fd895d1ac240c7fdb361cb0ed994d392ecf Mon Sep 17 00:00:00 2001 From: lukegleeson Date: Fri, 6 May 2022 12:02:42 +0100 Subject: Get cm-handle public properties endpoint Added RestOuputCmHandlePublicProperties OpenApi Object Added Get cm-handle public properties endpoint Added rest and service layer functionality for endpoint with tests Fixed Copyright Checker violations Issue-ID: CPS-1018 Signed-off-by: lukegleeson Change-Id: Ifc13cde350a49f6ba705a09e31853dc9c73be168 --- .../cps/ncmp/api/NetworkCmProxyDataService.java | 9 ++++++ .../api/impl/NetworkCmProxyDataServiceImpl.java | 18 ++++++++++++ .../impl/NetworkCmProxyDataServiceImplSpec.groovy | 34 ++++++++++++++++++---- 3 files changed, 55 insertions(+), 6 deletions(-) (limited to 'cps-ncmp-service') diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java index 058c42b7b9..7527ae5c50 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java @@ -26,6 +26,7 @@ package org.onap.cps.ncmp.api; import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum; import java.util.Collection; +import java.util.Map; import java.util.Set; import org.onap.cps.ncmp.api.models.CmHandleQueryApiParameters; import org.onap.cps.ncmp.api.models.DmiPluginRegistration; @@ -121,6 +122,14 @@ public interface NetworkCmProxyDataService { */ NcmpServiceCmHandle getNcmpServiceCmHandle(String cmHandleId); + /** + * Get cm handle public properties by cm handle id. + * + * @param cmHandleId cm handle identifier + * @return a collection of cm handle public properties. + */ + Map getCmHandlePublicProperties(String cmHandleId); + /** * Query and return cm handles that match the given query parameters. * diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java index c0f73d92d6..0e748c7fe7 100755 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java @@ -34,6 +34,7 @@ import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_ALLOWED; import com.google.common.base.Strings; import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -193,6 +194,23 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService return ncmpServiceCmHandle; } + /** + * Get cm handle public properties for a given cm handle id. + * + * @param cmHandleId cm handle identifier + * @return cm handle public properties + */ + @Override + public Map getCmHandlePublicProperties(final String cmHandleId) { + CpsValidator.validateNameCharacters(cmHandleId); + final YangModelCmHandle yangModelCmHandle = + yangModelCmHandleRetriever.getYangModelCmHandle(cmHandleId); + final List yangModelPublicProperties = yangModelCmHandle.getPublicProperties(); + final Map cmHandlePublicProperties = new HashMap<>(); + asPropertiesMap(yangModelPublicProperties, cmHandlePublicProperties); + return cmHandlePublicProperties; + } + /** * THis method registers a cm handle and initiates modules sync. * diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy index 65f007d14f..01f3bfed7b 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy @@ -1,5 +1,5 @@ /* - * ============LICENSE_START======================================================= + * ============LICENSE_START======================================================= * Copyright (C) 2021-2022 Nordix Foundation * Modifications Copyright (C) 2021 Pantheon.tech * Modifications Copyright (C) 2021-2022 Bell Canada @@ -74,7 +74,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { def cmHandleXPath = "/dmi-registry/cm-handles[@id='testCmHandle']" - def dataNode = new DataNode(leaves: ['id': 'Some-Cm-Handle', 'dmi-service-name': 'testDmiService']) + def dataNode = new DataNode(leaves: ['id': 'some-cm-handle', 'dmi-service-name': 'testDmiService']) def 'Write resource data for pass-through running from DMI using POST #scenario cm handle properties.'() { given: 'cpsDataService returns valid datanode' @@ -284,12 +284,12 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { def dmiServiceName = 'some service name' def dmiProperties = [new YangModelCmHandle.Property('Book', 'Romance Novel')] def publicProperties = [new YangModelCmHandle.Property('Public Book', 'Public Romance Novel')] - def yangModelCmHandle = new YangModelCmHandle(id:'Some-Cm-Handle', dmiServiceName: dmiServiceName, dmiProperties: dmiProperties, publicProperties: publicProperties) - 1 * mockYangModelCmHandleRetriever.getYangModelCmHandle('Some-Cm-Handle') >> yangModelCmHandle + def yangModelCmHandle = new YangModelCmHandle(id:'some-cm-handle', dmiServiceName: dmiServiceName, dmiProperties: dmiProperties, publicProperties: publicProperties) + 1 * mockYangModelCmHandleRetriever.getYangModelCmHandle('some-cm-handle') >> yangModelCmHandle when: 'getting cm handle details for a given cm handle id from ncmp service' - def result = objectUnderTest.getNcmpServiceCmHandle('Some-Cm-Handle') + def result = objectUnderTest.getNcmpServiceCmHandle('some-cm-handle') then: 'the result returns the correct data' - result.cmHandleId == 'Some-Cm-Handle' + result.cmHandleId == 'some-cm-handle' result.dmiProperties ==[ Book:'Romance Novel' ] result.publicProperties == [ "Public Book":'Public Romance Novel' ] @@ -304,6 +304,28 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { 0 * mockYangModelCmHandleRetriever.getYangModelCmHandle(_) } + def 'Get cm handle public properties'() { + given: 'a yang modelled cm handle' + def dmiProperties = [new YangModelCmHandle.Property('prop', 'some DMI property')] + def publicProperties = [new YangModelCmHandle.Property('public prop', 'some public prop')] + def yangModelCmHandle = new YangModelCmHandle(id:'some-cm-handle', dmiServiceName: 'some service name', dmiProperties: dmiProperties, publicProperties: publicProperties) + and: 'the system returns this yang modelled cm handle' + 1 * mockYangModelCmHandleRetriever.getYangModelCmHandle('some-cm-handle') >> yangModelCmHandle + when: 'getting cm handle public properties for a given cm handle id from ncmp service' + def result = objectUnderTest.getCmHandlePublicProperties('some-cm-handle') + then: 'the result returns the correct data' + result == [ 'public prop' : 'some public prop' ] + } + + def 'Get cm handle public properties with an invalid id.'() { + when: 'getting cm handle details for a given cm handle id with an invalid name' + objectUnderTest.getCmHandlePublicProperties('invalid cm handle with spaces') + then: 'an exception is thrown' + thrown(DataValidationException) + and: 'the yang model cm handle retriever is not invoked' + 0 * mockYangModelCmHandleRetriever.getYangModelCmHandle(_) + } + def 'Update resource data for pass-through running from dmi using POST #scenario DMI properties.'() { given: 'cpsDataService returns valid datanode' mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry', -- cgit 1.2.3-korg