From e1f73e264e2dca1f10c273620653f541c2f25d69 Mon Sep 17 00:00:00 2001 From: emaclee Date: Fri, 17 Jun 2022 17:42:56 +0100 Subject: Add method to get YANG module sources for CM handle - part of this commit includes renaming the enum SyncState to DataStoreSyncState Issue-ID: CPS-1064 Signed-off-by: emaclee Change-Id: I6bf419141a1b33f09871946445cdfff422c8c354 --- .../rest/controller/NcmpRestInputMapperSpec.groovy | 17 +++++++++++++++++ .../controller/NetworkCmProxyControllerSpec.groovy | 19 +++++++++++++++++-- .../ncmp/rest/mapper/CmHandleStateMapperTest.groovy | 4 ++-- 3 files changed, 36 insertions(+), 4 deletions(-) (limited to 'cps-ncmp-rest/src/test/groovy') diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NcmpRestInputMapperSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NcmpRestInputMapperSpec.groovy index bb762080d..cd3770eb8 100644 --- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NcmpRestInputMapperSpec.groovy +++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NcmpRestInputMapperSpec.groovy @@ -24,7 +24,9 @@ import org.mapstruct.factory.Mappers import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle import org.onap.cps.ncmp.rest.model.RestDmiPluginRegistration import org.onap.cps.ncmp.rest.model.RestInputCmHandle +import org.onap.cps.ncmp.rest.model.RestModuleDefinition import org.onap.cps.ncmp.rest.model.RestModuleReference +import org.onap.cps.spi.model.ModuleDefinition import org.onap.cps.spi.model.ModuleReference import spock.lang.Specification @@ -87,4 +89,19 @@ class NcmpRestInputMapperSpec extends Specification { then: 'the result is of the correct class RestModuleReference' result.class == RestModuleReference.class } + + def 'Convert a ModuleDefinition to a RestModuleDefinition'() { + given: 'a ModuleDefinition' + def moduleDefinition = new ModuleDefinition('moduleName','revision', 'content') + when: 'toRestModuleDefinition is called' + def result = objectUnderTest.toRestModuleDefinition(moduleDefinition) + then: 'the result is of the correct class RestModuleDefinition' + result.class == RestModuleDefinition.class + and: 'all contents are mapped correctly' + result.toString()=='class RestModuleDefinition {\n' + + ' moduleName: moduleName\n' + + ' revision: revision\n' + + ' content: content\n' + + '}' + } } diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy index 93d8358fe..729df9ce4 100644 --- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy +++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy @@ -26,12 +26,13 @@ package org.onap.cps.ncmp.rest.controller import org.mapstruct.factory.Mappers import org.onap.cps.ncmp.api.inventory.CmHandleState import org.onap.cps.ncmp.api.inventory.CompositeState -import org.onap.cps.ncmp.api.inventory.SyncState import org.onap.cps.ncmp.api.inventory.LockReasonCategory +import org.onap.cps.ncmp.api.inventory.DataStoreSyncState import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle import org.onap.cps.ncmp.rest.mapper.CmHandleStateMapper import org.onap.cps.ncmp.rest.executor.CpsNcmpTaskExecutor import org.onap.cps.ncmp.rest.util.DeprecationHelper +import org.onap.cps.spi.model.ModuleDefinition import spock.lang.Shared import java.time.OffsetDateTime @@ -408,10 +409,24 @@ class NetworkCmProxyControllerSpec extends Specification { ':passthrough-running' | 'passthrough-running' } + def 'Get module definitions based on cmHandleId.' () { + when: 'get module definition request is performed' + def response = mvc.perform(get("$ncmpBasePathV1/ch/some-cmhandle/modules/definitions")) + .andReturn().response + then: 'ncmp service method to get module definitions is called' + mockNetworkCmProxyDataService.getModuleDefinitionsByCmHandleId('some-cmhandle') + >> [new ModuleDefinition('sampleModuleName', '2021-10-03', + String.format('module sampleModuleName{ %n sample module content %n }'))] + and: 'response contains an array with the module name, revision and content where content contains \\n for newlines' + response.getContentAsString() == '[{"moduleName":"sampleModuleName","revision":"2021-10-03","content":"module sampleModuleName{ \\n sample module content \\n }"}]' + and: 'response returns an OK http code' + response.status == HttpStatus.OK.value() + } + def dataStores() { DataStores.builder() .operationalDataStore(Operational.builder() - .syncState(SyncState.NONE_REQUESTED) + .dataStoreSyncState(DataStoreSyncState.NONE_REQUESTED) .lastSyncTime(formattedDateAndTime.toString()).build()).build() } diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/mapper/CmHandleStateMapperTest.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/mapper/CmHandleStateMapperTest.groovy index a6c1278d9..42fda770b 100644 --- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/mapper/CmHandleStateMapperTest.groovy +++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/mapper/CmHandleStateMapperTest.groovy @@ -24,8 +24,8 @@ import org.mapstruct.factory.Mappers import org.onap.cps.ncmp.api.inventory.CmHandleState import org.onap.cps.ncmp.api.inventory.CompositeStateBuilder import org.onap.cps.ncmp.api.inventory.LockReasonCategory -import org.onap.cps.ncmp.api.inventory.SyncState import org.onap.cps.ncmp.rest.model.CmHandleCompositeState +import org.onap.cps.ncmp.api.inventory.DataStoreSyncState import spock.lang.Specification import java.time.OffsetDateTime @@ -44,7 +44,7 @@ class CmHandleStateMapperTest extends Specification { .withCmHandleState(CmHandleState.ADVISED) .withLastUpdatedTime(formattedDateAndTime.toString()) .withLockReason(LockReasonCategory.LOCKED_MISBEHAVING, 'locked other details') - .withOperationalDataStores(SyncState.SYNCHRONIZED, formattedDateAndTime).build() + .withOperationalDataStores(DataStoreSyncState.SYNCHRONIZED, formattedDateAndTime).build() compositeState.setDataSyncEnabled(false) when: 'mapper is called' def result = objectUnderTest.toCmHandleCompositeState(compositeState) -- cgit 1.2.3-korg