diff options
Diffstat (limited to 'cps-ncmp-service')
5 files changed, 55 insertions, 38 deletions
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 5594a2a7a5..d6aaf36d3a 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 @@ -284,7 +284,7 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService } private static void handleResponseForPost(final @NotNull ResponseEntity<String> responseEntity) { - if (responseEntity.getStatusCode() != HttpStatus.OK) { + if (!HttpStatus.valueOf(responseEntity.getStatusCodeValue()).is2xxSuccessful()) { throw new NcmpException("Not able to create resource data.", "DMI status code: " + responseEntity.getStatusCodeValue() + ", DMI response body: " + responseEntity.getBody()); @@ -387,9 +387,13 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService final List<ModuleReference> unknownModuleReferences = new ArrayList<>(); prepareModuleSubsets(moduleReferencesFromCmHandle, existingModuleReferences, unknownModuleReferences); - final Map<String, String> newYangResourcesModuleNameToContentMap = - getNewYangResourcesFromDmi(persistenceCmHandle, unknownModuleReferences, cmHandlePropertiesAsMap); - + final Map<String, String> newYangResourcesModuleNameToContentMap; + if (unknownModuleReferences.size() > 0) { + newYangResourcesModuleNameToContentMap = getNewYangResourcesFromDmi(persistenceCmHandle, + unknownModuleReferences, cmHandlePropertiesAsMap); + } else { + newYangResourcesModuleNameToContentMap = new HashMap<>(); + } cpsModuleService.createSchemaSetFromModules(NF_PROXY_DATASPACE_NAME, persistenceCmHandle.getId(), newYangResourcesModuleNameToContentMap, existingModuleReferences); } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operation/DmiOperations.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operation/DmiOperations.java index 363b0ef9b2..f7421cdb71 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operation/DmiOperations.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operation/DmiOperations.java @@ -203,7 +203,9 @@ public class DmiOperations { private void appendOptionsQuery(final StringBuilder stringBuilder, final String optionsParamInQuery) { - stringBuilder.append("&").append(OPTIONS_QUERY_KEY).append("=").append(optionsParamInQuery); + if (optionsParamInQuery != null) { + stringBuilder.append("&").append(OPTIONS_QUERY_KEY).append("=").append(optionsParamInQuery); + } } private HttpHeaders prepareHeader(final String acceptParam) { 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.'() { diff --git a/cps-ncmp-service/src/test/resources/cmHandleModules.json b/cps-ncmp-service/src/test/resources/cmHandleModules.json index d1665bee7d..43e8175ca0 100644 --- a/cps-ncmp-service/src/test/resources/cmHandleModules.json +++ b/cps-ncmp-service/src/test/resources/cmHandleModules.json @@ -6,7 +6,7 @@ }, { "moduleName": "module2", - "revision": "1", + "revision": "2", "namespace": "some namespace" }] }
\ No newline at end of file |