diff options
author | Toine Siebelink <toine.siebelink@est.tech> | 2021-09-27 08:11:04 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2021-09-27 08:11:04 +0000 |
commit | cb8bc88d47fb1614aa6d89ce1f0054a1e2775821 (patch) | |
tree | e359d042685501f3ffd2bb8007e59a0a3693043c /src/test/groovy | |
parent | e55af78a795c46d467e5ce63d647cfb6124c62ad (diff) | |
parent | 4f431887d66854589354c7361f2614f76420d738 (diff) |
Merge "Add get modules response type to openapi"
Diffstat (limited to 'src/test/groovy')
-rw-r--r-- | src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy | 19 | ||||
-rw-r--r-- | src/test/groovy/org/onap/cps/ncmp/dmi/service/DmiServiceImplSpec.groovy | 26 |
2 files changed, 19 insertions, 26 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 ac4fde3d..dd5e79da 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 @@ -30,6 +30,8 @@ import org.onap.cps.ncmp.dmi.model.ModuleReference import org.onap.cps.ncmp.dmi.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 +import org.onap.cps.ncmp.dmi.model.YangResources import org.onap.cps.ncmp.dmi.service.DmiService import org.spockframework.spring.SpringBean import org.springframework.beans.factory.annotation.Autowired @@ -149,15 +151,14 @@ class DmiRestControllerSpec extends Specification { given: 'an endpoint and json data' def getModulesEndpoint = "$basePathV1/ch/some-cm-handle/moduleResources" def jsonData = TestUtils.getResourceFileContent('GetModules.json') - and: 'the DMI service returns some json data' - ModuleReference moduleReference1 = new ModuleReference() - moduleReference1.name = 'ietf-yang-library' - moduleReference1.revision = '2016-06-21' - ModuleReference moduleReference2 = new ModuleReference() - moduleReference2.name = 'nc-notifications' - moduleReference2.revision = '2008-07-14' + 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') def moduleReferences = [moduleReference1, moduleReference2] - mockDmiService.getModuleResources('some-cm-handle', moduleReferences) >> '{some-json}' + def yangResources = new YangResources() + def yangResource = new YangResource(yangSource: '"some-data"', moduleName: 'NAME', revision: 'REVISION') + yangResources.add(yangResource) + mockDmiService.getModuleResources('some-cm-handle', moduleReferences) >> yangResources when: 'get module resource api is invoked' def response = mvc.perform(post(getModulesEndpoint) .contentType(MediaType.APPLICATION_JSON) @@ -165,7 +166,7 @@ class DmiRestControllerSpec extends Specification { then: 'a OK status is returned' response.status == HttpStatus.OK.value() and: 'the expected response is returned' - response.getContentAsString() == '{some-json}' + response.getContentAsString() == '[{"yangSource":"\\"some-data\\"","moduleName":"NAME","revision":"REVISION"}]' } def 'Retrieve module resources with exception handling.'() { diff --git a/src/test/groovy/org/onap/cps/ncmp/dmi/service/DmiServiceImplSpec.groovy b/src/test/groovy/org/onap/cps/ncmp/dmi/service/DmiServiceImplSpec.groovy index c1700a2e..93bc641e 100644 --- a/src/test/groovy/org/onap/cps/ncmp/dmi/service/DmiServiceImplSpec.groovy +++ b/src/test/groovy/org/onap/cps/ncmp/dmi/service/DmiServiceImplSpec.groovy @@ -30,6 +30,8 @@ import org.onap.cps.ncmp.dmi.exception.ModuleResourceNotFoundException import org.onap.cps.ncmp.dmi.exception.ModulesNotFoundException import org.onap.cps.ncmp.dmi.exception.ResourceDataNotFound import org.onap.cps.ncmp.dmi.model.ModuleReference +import org.onap.cps.ncmp.dmi.model.YangResource +import org.onap.cps.ncmp.dmi.model.YangResources import org.onap.cps.ncmp.dmi.service.client.NcmpRestClient import org.onap.cps.ncmp.dmi.service.operation.SdncOperations import org.springframework.http.HttpStatus @@ -134,21 +136,6 @@ class DmiServiceImplSpec extends Specification { thrown(DmiException.class) } - def 'Get a single module resource.'() { - given: 'a cmHandle and module reference list' - def cmHandle = 'some-cmHandle' - def moduleReference = new ModuleReference(name: 'NAME',revision: 'REVISION') - def moduleList = [moduleReference] - and: 'the sdnc request body contains the correct name and revision' - def expectedRequestBody = '{"ietf-netconf-monitoring:input":{"ietf-netconf-monitoring:identifier":"NAME","ietf-netconf-monitoring:version":"REVISION"}}' - when: 'get module resources is invoked with the given cm handle and a module list' - def result = objectUnderTest.getModuleResources(cmHandle, moduleList) - then: 'get modules resources is called once with the expected cm handle and request body' - 1 * mockSdncOperations.getModuleResource(cmHandle, expectedRequestBody) >> new ResponseEntity<String>('{"ietf-netconf-monitoring:output": {"data": "some-data"}}', HttpStatus.OK) - and: 'the result is an array containing one json object with the expected name, revision and yang-source' - assert result == '[{"yangSource":"\\"some-data\\"","moduleName":"NAME","revision":"REVISION"}]' - } - def 'Get multiple module resources.'() { given: 'a cmHandle and module reference list' def cmHandle = 'some-cmHandle' @@ -160,8 +147,13 @@ class DmiServiceImplSpec extends Specification { then: 'get modules resources is called twice' 2 * mockSdncOperations.getModuleResource(cmHandle, _) >>> [new ResponseEntity<String>('{"ietf-netconf-monitoring:output": {"data": "some-data1"}}', HttpStatus.OK), new ResponseEntity<String>('{"ietf-netconf-monitoring:output": {"data": "some-data2"}}', HttpStatus.OK)] - and: 'the result is an array containing json objects with the expected name, revision and yang-source' - assert result == '[{"yangSource":"\\"some-data1\\"","moduleName":"name-1","revision":"revision-1"},{"yangSource":"\\"some-data2\\"","moduleName":"name-2","revision":"revision-2"}]' + and: 'the result is a yang resources object with the expected names, revisions and yang-sources' + def yangResources = new YangResources() + def yangResource1 = new YangResource(yangSource: '"some-data1"', moduleName: 'name-1', revision: 'revision-1') + def yangResource2 = new YangResource(yangSource: '"some-data2"', moduleName: 'name-2', revision: 'revision-2') + yangResources.add(yangResource1) + yangResources.add(yangResource2) + assert result == yangResources } def 'Get a module resource with module resource not found exception for #scenario.'() { |