diff options
Diffstat (limited to 'src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy')
-rw-r--r-- | src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy b/src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy index 9c27dc1b..ac78928d 100644 --- a/src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy +++ b/src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy @@ -20,14 +20,13 @@ package org.onap.cps.ncmp.dmi.rest.controller - import com.fasterxml.jackson.databind.ObjectMapper import org.onap.cps.ncmp.dmi.TestUtils import org.onap.cps.ncmp.dmi.exception.DmiException import org.onap.cps.ncmp.dmi.exception.ModuleResourceNotFoundException import org.onap.cps.ncmp.dmi.exception.ModulesNotFoundException -import org.onap.cps.ncmp.dmi.model.ModuleReference -import org.onap.cps.ncmp.dmi.model.ModuleSchemaList +import org.onap.cps.ncmp.dmi.service.model.ModuleReference +import org.onap.cps.ncmp.dmi.service.model.ModuleSchemaList import org.onap.cps.ncmp.dmi.model.ModuleSet import org.onap.cps.ncmp.dmi.model.ModuleSetSchemas import org.onap.cps.ncmp.dmi.model.YangResource @@ -66,7 +65,7 @@ class DmiRestControllerSpec extends Specification { given: 'REST endpoint for getting all modules' def getModuleUrl = "$basePathV1/ch/node1/modules" and: 'get modules for cm-handle returns a json' - def json = '{"operation" : "read", "cmHandleProperties" : {}}' + def json = '{"cmHandleProperties" : {}}' def moduleSetSchema = new ModuleSetSchemas(namespace:'some-namespace', moduleName:'some-moduleName', revision:'some-revision') @@ -102,7 +101,7 @@ class DmiRestControllerSpec extends Specification { given: 'REST endpoint for getting all modules' def getModuleUrl = "$basePathV1/ch/node1/modules" and: 'given request body and get modules for cm-handle throws #exceptionClass' - def json = '{"operation" : "read", "cmHandleProperties" : {}}' + def json = '{"cmHandleProperties" : {}}' mockDmiService.getModulesForCmHandle('node1') >> { throw Mock(exceptionClass) } when: 'post is invoked' def response = mvc.perform( post(getModuleUrl) @@ -151,7 +150,7 @@ class DmiRestControllerSpec extends Specification { def 'Retrieve module resources.'() { given: 'an endpoint and json data' def getModulesEndpoint = "$basePathV1/ch/some-cm-handle/moduleResources" - def jsonData = TestUtils.getResourceFileContent('GetModules.json') + String jsonData = TestUtils.getResourceFileContent('GetModules.json') and: 'the DMI service returns the yang resources' ModuleReference moduleReference1 = new ModuleReference(name: 'ietf-yang-library', revision: '2016-06-21') ModuleReference moduleReference2 = new ModuleReference(name: 'nc-notifications', revision: '2008-07-14') @@ -173,7 +172,7 @@ class DmiRestControllerSpec extends Specification { def 'Retrieve module resources with exception handling.'() { given: 'an endpoint and json data' def getModulesEndpoint = "$basePathV1/ch/some-cm-handle/moduleResources" - def jsonData = TestUtils.getResourceFileContent('GetModules.json') + String jsonData = TestUtils.getResourceFileContent('GetModules.json') and: 'the service method is invoked to get module resources and throws an exception' mockDmiService.getModuleResources('some-cm-handle', _) >> { throw Mock(ModuleResourceNotFoundException.class) } when: 'get module resource api is invoked' @@ -187,7 +186,7 @@ class DmiRestControllerSpec extends Specification { def 'Get resource data for pass-through operational from cm handle.'() { given: 'Get resource data url' def getResourceDataForCmHandleUrl = "${basePathV1}/ch/some-cmHandle/data/ds/ncmp-datastore:passthrough-operational" + - "/resourceIdentifier?fields=myfields&depth=5" + "?resourceIdentifier=parent/child&options=(fields=myfields,depth=5)" def json = '{"cmHandleProperties" : { "prop1" : "value1", "prop2" : "value2"}}' when: 'get resource data PUT api is invoked' def response = mvc.perform( @@ -198,16 +197,16 @@ class DmiRestControllerSpec extends Specification { response.status == HttpStatus.OK.value() and: 'dmi service called with get resource data for cm handle' 1 * mockDmiService.getResourceDataOperationalForCmHandle('some-cmHandle', - 'resourceIdentifier', + 'parent/child', 'application/json', - 'myfields', - 5, + '(fields=myfields,depth=5)', ['prop1': 'value1', 'prop2': 'value2']) } def 'Write data using passthrough running for a cm handle using #scenario.'() { given: 'write data for cmHandle url and jsonData' - def writeDataforCmHandlePassthroughRunning = "${basePathV1}/ch/some-cmHandle/data/ds/ncmp-datastore:passthrough-running/some-resourceIdentifier" + def writeDataforCmHandlePassthroughRunning = "${basePathV1}/ch/some-cmHandle/data/ds/ncmp-datastore:passthrough-running" + + "?resourceIdentifier=some-resourceIdentifier" def jsonData = TestUtils.getResourceFileContent(requestBodyFile) and: 'dmi service is called' mockDmiService.writeResourceDataPassthroughForCmHandle('some-cmHandle', @@ -228,10 +227,10 @@ class DmiRestControllerSpec extends Specification { 'data with special chars' | 'dataWithSpecialChar.json'|| 'data with quote \" and new line \n' } - def 'Get resource data for pass-through running from cm handle.'() { + def 'Get resource data for pass-through running from cm handle with #scenario value in resource identifier param.'() { given: 'Get resource data url' def getResourceDataForCmHandleUrl = "${basePathV1}/ch/some-cmHandle/data/ds/ncmp-datastore:passthrough-running" + - "/testResourceIdentifier?fields=testFields&depth=5" + "?resourceIdentifier="+resourceIdentifier+"&options=(fields=myfields,depth=5)" def json = '{"cmHandleProperties" : { "prop1" : "value1", "prop2" : "value2"}}' when: 'get resource data PUT api is invoked' def response = mvc.perform( @@ -242,10 +241,18 @@ class DmiRestControllerSpec extends Specification { response.status == HttpStatus.OK.value() and: 'dmi service called with get resource data for cm handle' 1 * mockDmiService.getResourceDataPassThroughRunningForCmHandle('some-cmHandle', - 'testResourceIdentifier', + resourceIdentifier, 'application/json', - 'testFields', - 5, + '(fields=myfields,depth=5)', ['prop1':'value1', 'prop2':'value2']) + where: 'tokens are used in the resource identifier parameter' + scenario | resourceIdentifier + '/' | 'id/with/slashes' + '?' | 'idWith?' + ',' | 'idWith,' + '=' | 'idWith=' + '[]' | 'idWith[]' + '? needs to be encoded as %3F' | 'idWith%3F' + } -}
\ No newline at end of file +} |