diff options
author | tragait <rahul.tyagi@est.tech> | 2021-10-11 16:31:59 +0100 |
---|---|---|
committer | tragait <rahul.tyagi@est.tech> | 2021-10-12 11:19:20 +0100 |
commit | 7ad748f44a8f9624b53462850759804ffc185576 (patch) | |
tree | ccde8f22676b02edf7b1de58dec99792a3a83604 /cps-ncmp-service/src/test/groovy | |
parent | 66b598a4243bb702059902af2903d1c3da01d5fa (diff) |
fix for sync and passthough usecase
fixed unknown modules issue, if unknown modules are size 0
dmi should not be called.
fixed 2xx issue for create resource.
fixed options = null issue.
Issue-ID: CPS-730
Signed-off-by: tragait <rahul.tyagi@est.tech>
Change-Id: If6226f65e72753189c27648ad903c45a5d8fa14e
Diffstat (limited to 'cps-ncmp-service/src/test/groovy')
2 files changed, 43 insertions, 32 deletions
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 b5d4713959..1bad8ce0ba 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 @@ -371,7 +371,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { 'testResourceId', '{"operation":"create","dataType":"application/json","data":"{some-json}","cmHandleProperties":' + expectedJsonForCmhandleProperties+ '}') - >> { new ResponseEntity<>(HttpStatus.OK) } + >> { new ResponseEntity<>(HttpStatus.CREATED) } where: scenario | includeCmHandleProperties || expectedJsonForCmhandleProperties 'with' | true || '{"testName":"testValue"}' @@ -398,10 +398,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { } def 'Sync model for a (new) cm handle with #scenario'() { - given: 'DMI Plug-in returns a list of module references' - def knownModule1 = new ModuleReference('module1', '1') - def knownOtherModule = new ModuleReference('some other module', 'some revision') - and: 'persistence cm handle is given' + given: 'persistence cm handle is given' def cmHandleForModelSync = new PersistenceCmHandle(id:'some cm handle', dmiServiceName: 'some service name') and: 'additional properties are set as required' if (additionalProperties!=null) { @@ -415,23 +412,23 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { def moduleReferencesFromCmHandleAsJson = new ResponseEntity<String>(jsonData, HttpStatus.OK) mockDmiOperations.getResourceFromDmiWithJsonData('some service name', expectedJsonBody, 'some cm handle', 'modules') >> moduleReferencesFromCmHandleAsJson and: 'CPS-Core returns list of known modules' - mockCpsModuleService.getYangResourceModuleReferences(_) >> [knownModule1, knownOtherModule] + mockCpsModuleService.getYangResourceModuleReferences(_) >> existingModuleResourcesInCps and: 'DMI-Plugin returns resource(s) for "new" module(s)' def moduleResources = new ResponseEntity<String>(sdncReponseBody, HttpStatus.OK) - def jsonDataToFetchYangResource = '{"data":{"modules":[{"name":"module2","revision":"1"}]},"cmHandleProperties":' + expectedJsonForAdditionalProperties + '}' + def jsonDataToFetchYangResource = '{"data":{"modules":[{"name":"module1","revision":"1"}]},"cmHandleProperties":' + expectedJsonForAdditionalProperties + '}' mockDmiOperations.getResourceFromDmiWithJsonData('some service name', jsonDataToFetchYangResource, 'some cm handle', 'moduleResources') >> moduleResources when: 'module Sync is triggered' objectUnderTest.syncModulesAndCreateAnchor(cmHandleForModelSync) then: 'the CPS module service is called once with the correct parameters' - 1 * mockCpsModuleService.createSchemaSetFromModules(expectedDataspaceName, cmHandleForModelSync.getId(), expectedYangResourceToContentMap, [knownModule1]) + 1 * mockCpsModuleService.createSchemaSetFromModules(expectedDataspaceName, cmHandleForModelSync.getId(), expectedYangResourceToContentMap, expectedKnownModules) and: 'admin service create anchor method has been called with correct parameters' 1 * mockCpsAdminService.createAnchor(expectedDataspaceName, cmHandleForModelSync.getId(), cmHandleForModelSync.getId()) where: 'the following responses are received from SDNC' - scenario | additionalProperties | sdncReponseBody || expectedYangResourceToContentMap | expectedJsonForAdditionalProperties - 'one unknown module' | ['name1':'value1'] | '[{"moduleName" : "someModule", "revision" : "1","yangSource": "[some yang source]"}]' || [someModule: 'some yang source'] | '{"name1":"value1"}' - 'no add. properties' | [:] | '[{"moduleName" : "someModule", "revision" : "1","yangSource": "[some yang source]"}]' || [someModule: 'some yang source'] | '{}' - 'additional properties is null' | null | '[{"moduleName" : "someModule", "revision" : "1","yangSource": "[some yang source]"}]' || [someModule: 'some yang source'] | '{}' - 'no unknown module' | [:] | '[]' || [:] | '{}' + scenario | additionalProperties | existingModuleResourcesInCps | sdncReponseBody || expectedYangResourceToContentMap | expectedKnownModules | expectedJsonForAdditionalProperties + 'one unknown module' | ['name1':'value1'] | [new ModuleReference('module2', '2'), new ModuleReference('module3', '3')] | '[{"moduleName" : "module1", "revision" : "1","yangSource": "[some yang source]"}]' || [module1: 'some yang source'] | [new ModuleReference('module2', '2')] |'{"name1":"value1"}' + 'no add. properties' | [:] | [new ModuleReference('module2', '2'), new ModuleReference('module3', '3')] | '[{"moduleName" : "module1", "revision" : "1","yangSource": "[some yang source]"}]' || [module1: 'some yang source'] | [new ModuleReference('module2', '2')] |'{}' + 'additional properties is null' | null | [new ModuleReference('module2', '2'), new ModuleReference('module3', '3')] | '[{"moduleName" : "module1", "revision" : "1","yangSource": "[some yang source]"}]' || [module1: 'some yang source'] | [new ModuleReference('module2', '2')] |'{}' + 'no unknown module' | [:] | [new ModuleReference('module1', '1'), new ModuleReference('module2', '2')] | '[]' || [:] | [new ModuleReference('module1', '1'), new ModuleReference('module2', '2')] |'{}' } def 'Getting Yang Resources.'() { diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operation/DmiOperationsSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operation/DmiOperationsSpec.groovy index 8e0fb76a56..9405b66325 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operation/DmiOperationsSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operation/DmiOperationsSpec.groovy @@ -41,27 +41,41 @@ class DmiOperationsSpec extends Specification { def 'call get resource data for pass-through:operational datastore from DMI.'() { given: 'expected url' - def expectedUrl = 'testDmiBasePath/dmi/v1/ch/testCmhandle/data/ds' + - '/ncmp-datastore:passthrough-operational?resourceIdentifier=parent/child&options=(a=1,b=2)' + def expectedUrl = 'testDmiBasePath/dmi/v1/ch/testCmhandle/data/ds' + + '/ncmp-datastore:passthrough-operational?resourceIdentifier=parent/child&options=(a=1,b=2)' when: 'get resource data is called to DMI' - objectUnderTest.getResourceDataOperationalFromDmi('testDmiBasePath', - 'testCmhandle', - 'parent/child', - '(a=1,b=2)', - 'testAcceptJson', - 'testJsonbody') + objectUnderTest.getResourceDataOperationalFromDmi('testDmiBasePath', + 'testCmhandle', + 'parent/child', + '(a=1,b=2)', + 'testAcceptJson', + 'testJsonbody') then: 'the put operation is executed with the correct URL' - 1 * mockDmiRestClient.putOperationWithJsonData(expectedUrl, 'testJsonbody', _ as HttpHeaders) + 1 * mockDmiRestClient.putOperationWithJsonData(expectedUrl, 'testJsonbody', _ as HttpHeaders) } def 'call get resource data for pass-through:running datastore from DMI.'() { given: 'expected url' + def expectedUrl = 'testDmiBasePath/dmi/v1/ch/testCmhandle/data/ds' + + '/ncmp-datastore:passthrough-running?resourceIdentifier=parent/child&options=(a=1,b=2)' + when: 'get resource data is called to DMI' + objectUnderTest.getResourceDataPassThroughRunningFromDmi('testDmiBasePath', + 'testCmhandle', + 'parent/child', + '(a=1,b=2)', + 'testAcceptJson', + 'testJsonbody') + then: 'the put operation is executed with the correct URL' + 1 * mockDmiRestClient.putOperationWithJsonData(expectedUrl, 'testJsonbody', _ as HttpHeaders) + } + def 'call get resource data for pass-through:operational datastore from DMI when options is null.'() { + given: 'expected url' def expectedUrl = 'testDmiBasePath/dmi/v1/ch/testCmhandle/data/ds' + - '/ncmp-datastore:passthrough-running?resourceIdentifier=parent/child&options=(a=1,b=2)' + '/ncmp-datastore:passthrough-operational?resourceIdentifier=parent/child' when: 'get resource data is called to DMI' - objectUnderTest.getResourceDataPassThroughRunningFromDmi('testDmiBasePath', + objectUnderTest.getResourceDataOperationalFromDmi('testDmiBasePath', 'testCmhandle', 'parent/child', - '(a=1,b=2)', + null, 'testAcceptJson', 'testJsonbody') then: 'the put operation is executed with the correct URL' @@ -69,15 +83,15 @@ class DmiOperationsSpec extends Specification { } def 'call create resource data for pass-through:running datastore from DMI.'() { given: 'expected url' - def expectedUrl = 'testDmiBasePath/dmi/v1/ch/testCmhandle/data/ds' + - '/ncmp-datastore:passthrough-running?resourceIdentifier=parent/child' + def expectedUrl = 'testDmiBasePath/dmi/v1/ch/testCmhandle/data/ds' + + '/ncmp-datastore:passthrough-running?resourceIdentifier=parent/child' when: 'get resource data is called to DMI' - objectUnderTest.createResourceDataPassThroughRunningFromDmi('testDmiBasePath', - 'testCmhandle', - 'parent/child', - 'testJsonbody') + objectUnderTest.createResourceDataPassThroughRunningFromDmi('testDmiBasePath', + 'testCmhandle', + 'parent/child', + 'testJsonbody') then: 'the put operation is executed with the correct URL' - 1 * mockDmiRestClient.postOperationWithJsonData(expectedUrl, 'testJsonbody', _ as HttpHeaders) + 1 * mockDmiRestClient.postOperationWithJsonData(expectedUrl, 'testJsonbody', _ as HttpHeaders) } def 'Call get resource from dmi.'() { |