diff options
-rw-r--r-- | .readthedocs.yaml | 38 | ||||
-rw-r--r-- | docs/index.rst | 2 | ||||
-rw-r--r-- | docs/openapi/components.yml | 19 | ||||
-rw-r--r-- | docs/openapi/openapi.yml | 14 | ||||
-rw-r--r-- | docs/requirements-docs.txt | 16 | ||||
-rw-r--r-- | docs/tox.ini | 6 | ||||
-rw-r--r-- | pom.xml | 1 | ||||
-rw-r--r-- | src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java | 30 | ||||
-rw-r--r-- | src/main/java/org/onap/cps/ncmp/dmi/service/DmiService.java | 5 | ||||
-rw-r--r-- | src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java | 24 | ||||
-rw-r--r-- | src/main/resources/spotbugs-exclude.xml | 54 | ||||
-rw-r--r-- | src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy | 34 | ||||
-rw-r--r-- | src/test/groovy/org/onap/cps/ncmp/dmi/service/DmiServiceImplSpec.groovy | 26 |
13 files changed, 188 insertions, 81 deletions
diff --git a/.readthedocs.yaml b/.readthedocs.yaml new file mode 100644 index 00000000..9c22c0b4 --- /dev/null +++ b/.readthedocs.yaml @@ -0,0 +1,38 @@ +# ============LICENSE_START======================================================= +# Copyright (C) 2021 Nordix Foundation +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# ============LICENSE_END========================================================= + +--- +# .readthedocs.yml +# Read the Docs configuration file +# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details +# Required +version: 2 + +formats: + - htmlzip + +build: + image: latest + +python: + version: 3.7 + install: + - requirements: docs/requirements-docs.txt + +sphinx: + configuration: docs/conf.py diff --git a/docs/index.rst b/docs/index.rst index bc299aeb..54da6148 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -3,7 +3,7 @@ .. Copyright (C) 2021 Nordix Foundation .. DO NOT CHANGE THIS LABEL FOR RELEASE NOTES - EVEN THOUGH IT GIVES A WARNING -.. _dmi: +.. _master_index: .. THIS IS USED INTERNALLY IN CPS ONLY .. _dmi-framework-doc: diff --git a/docs/openapi/components.yml b/docs/openapi/components.yml index 3866b834..9cce52de 100644 --- a/docs/openapi/components.yml +++ b/docs/openapi/components.yml @@ -19,12 +19,14 @@ components: items: type: string - DmiReadRequestBody: + DmiModuleReadRequestBody: type: object properties: operation: type: string enum: [read] + dataType: + type: string data: type: object properties: @@ -58,6 +60,21 @@ components: namespace: type: string + YangResources: + type: array + items: + type: object + $ref: '#/components/schemas/YangResource' + + YangResource: + properties: + yangSource: + type: string + moduleName: + type: string + revision: + type: string + DataAccessReadRequest: type: object properties: diff --git a/docs/openapi/openapi.yml b/docs/openapi/openapi.yml index a9accdb9..f66897a2 100644 --- a/docs/openapi/openapi.yml +++ b/docs/openapi/openapi.yml @@ -45,6 +45,12 @@ paths: required: true schema: type: string + requestBody: + description: Operational body + content: + application/json: + schema: + $ref: 'components.yml#/components/schemas/DataAccessReadRequest' responses: '200': description: OK @@ -107,10 +113,14 @@ paths: content: application/json: schema: - $ref: 'components.yml#/components/schemas/DmiReadRequestBody' + $ref: 'components.yml#/components/schemas/DmiModuleReadRequestBody' responses: '200': - $ref: 'components.yml#/components/responses/Ok' + description: OK + content: + application/json: + schema: + $ref: 'components.yml#/components/schemas/YangResources' '400': $ref: 'components.yml#/components/responses/BadRequest' '401': diff --git a/docs/requirements-docs.txt b/docs/requirements-docs.txt index b3188ddd..5a3d2f17 100644 --- a/docs/requirements-docs.txt +++ b/docs/requirements-docs.txt @@ -1,15 +1 @@ -tox -Sphinx -doc8 -docutils -setuptools -six -sphinx_rtd_theme>=0.4.3 -sphinxcontrib-blockdiag -sphinxcontrib-needs>=0.2.3 -sphinxcontrib-nwdiag -sphinxcontrib-seqdiag -sphinxcontrib-swaggerdoc -sphinxcontrib-plantuml -sphinx_bootstrap_theme -lfdocs-conf +lfdocs-conf
\ No newline at end of file diff --git a/docs/tox.ini b/docs/tox.ini index edac8c35..4e9449e2 100644 --- a/docs/tox.ini +++ b/docs/tox.ini @@ -6,6 +6,8 @@ skipsdist = true [testenv:docs] basepython = python3 deps = -r{toxinidir}/requirements-docs.txt + -chttps://git.onap.org/doc/plain/etc/upper-constraints.os.txt + -chttps://git.onap.org/doc/plain/etc/upper-constraints.onap.txt commands = sphinx-build -b html -n -d {envtmpdir}/doctrees ./ {toxinidir}/_build/html echo "Generated docs available in {toxinidir}/_build/html" @@ -16,7 +18,9 @@ whitelist_externals = [testenv:docs-linkcheck] basepython = python3 -#deps = -r{toxinidir}/requirements-docs.txt +deps = -r{toxinidir}/requirements-docs.txt + -chttps://git.onap.org/doc/plain/etc/upper-constraints.os.txt + -chttps://git.onap.org/doc/plain/etc/upper-constraints.onap.txt commands = echo "Link Checking not enforced" #commands = sphinx-build -b linkcheck -d {envtmpdir}/doctrees ./ {toxinidir}/_build/linkcheck whitelist_externals = echo @@ -431,6 +431,7 @@ <threshold>Low</threshold> <failOnError>true</failOnError> <excludeFilterFile>spotbugs-exclude.xml</excludeFilterFile> + <addSourceDirs>true</addSourceDirs> <xmlOutput>true</xmlOutput> <xmlOutputDirectory>${basedir}/target/spotbugs</xmlOutputDirectory> </configuration> diff --git a/src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java b/src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java index 37381fb1..ff3cefcd 100644 --- a/src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java +++ b/src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java @@ -29,9 +29,10 @@ import lombok.extern.slf4j.Slf4j; import org.onap.cps.ncmp.dmi.model.CmHandles; import org.onap.cps.ncmp.dmi.model.DataAccessReadRequest; import org.onap.cps.ncmp.dmi.model.DataAccessWriteRequest; -import org.onap.cps.ncmp.dmi.model.DmiReadRequestBody; +import org.onap.cps.ncmp.dmi.model.DmiModuleReadRequestBody; import org.onap.cps.ncmp.dmi.model.ModuleReference; import org.onap.cps.ncmp.dmi.model.ModuleSet; +import org.onap.cps.ncmp.dmi.model.YangResources; import org.onap.cps.ncmp.dmi.rest.api.DmiPluginApi; import org.onap.cps.ncmp.dmi.rest.api.DmiPluginInternalApi; import org.onap.cps.ncmp.dmi.service.DmiService; @@ -56,23 +57,23 @@ public class DmiRestController implements DmiPluginApi, DmiPluginInternalApi { } @Override - public ResponseEntity<ModuleSet> getModulesForCmHandle(final String cmHandle) { + public ResponseEntity<ModuleSet> getModulesForCmHandle(final String cmHandle, + final @Valid DataAccessReadRequest body) { + // For onap-dmi-plugin we don't need cmHandleProperties, so DataAccessReadRequest is not used. final var moduleSet = dmiService.getModulesForCmHandle(cmHandle); - return new ResponseEntity<>(moduleSet, HttpStatus.OK); + return ResponseEntity.ok(moduleSet); } @Override - public ResponseEntity<Object> retrieveModuleResources(@Valid final DmiReadRequestBody dmiReadRequestBody, - final String cmHandle) { - if (dmiReadRequestBody.getOperation().toString().equals("read")) { - final var moduleReferenceList = convertRestObjectToJavaApiObject(dmiReadRequestBody); + public ResponseEntity<YangResources> retrieveModuleResources( + final @Valid DmiModuleReadRequestBody dmiModuleReadRequestBody, + final String cmHandle) { + if (dmiModuleReadRequestBody.getOperation().toString().equals("read")) { + final var moduleReferenceList = convertRestObjectToJavaApiObject(dmiModuleReadRequestBody); final var response = dmiService.getModuleResources(cmHandle, moduleReferenceList); - if (response.isEmpty()) { - return new ResponseEntity<>(response, HttpStatus.NOT_FOUND); - } return new ResponseEntity<>(response, HttpStatus.OK); } - return new ResponseEntity<>("Unsupported operation", HttpStatus.CONFLICT); + return new ResponseEntity<>(HttpStatus.CONFLICT); } /** @@ -165,9 +166,10 @@ public class DmiRestController implements DmiPluginApi, DmiPluginInternalApi { return ResponseEntity.ok(modulesListAsJson); } - private List<ModuleReference> convertRestObjectToJavaApiObject(final DmiReadRequestBody dmiReadRequestBody) { + private List<ModuleReference> convertRestObjectToJavaApiObject( + final DmiModuleReadRequestBody dmiModuleSchemaReadRequestBody) { return objectMapper - .convertValue(dmiReadRequestBody.getData().getModules(), new TypeReference<List<ModuleReference>>() { - }); + .convertValue(dmiModuleSchemaReadRequestBody.getData().getModules(), + new TypeReference<List<ModuleReference>>() {}); } }
\ No newline at end of file diff --git a/src/main/java/org/onap/cps/ncmp/dmi/service/DmiService.java b/src/main/java/org/onap/cps/ncmp/dmi/service/DmiService.java index 7f79a04c..bd0dc600 100644 --- a/src/main/java/org/onap/cps/ncmp/dmi/service/DmiService.java +++ b/src/main/java/org/onap/cps/ncmp/dmi/service/DmiService.java @@ -26,6 +26,7 @@ import javax.validation.constraints.NotNull; import org.onap.cps.ncmp.dmi.exception.DmiException; import org.onap.cps.ncmp.dmi.model.ModuleReference; import org.onap.cps.ncmp.dmi.model.ModuleSet; +import org.onap.cps.ncmp.dmi.model.YangResources; /** * Interface for handling Dmi plugin Data. @@ -54,9 +55,9 @@ public interface DmiService { * * @param cmHandle cmHandle * @param modules a list of module data - * @return returns all module resources + * @return returns all yang resources */ - String getModuleResources(String cmHandle, List<ModuleReference> modules); + YangResources getModuleResources(String cmHandle, List<ModuleReference> modules); /** * This method use to fetch the resource data from cm handle for datastore pass-through operational and resource diff --git a/src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java b/src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java index 11668904..182bdd84 100644 --- a/src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java +++ b/src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java @@ -30,8 +30,6 @@ import java.util.List; import java.util.Map; import javax.validation.constraints.NotNull; import lombok.extern.slf4j.Slf4j; -import net.minidev.json.JSONArray; -import net.minidev.json.JSONObject; import org.apache.groovy.parser.antlr4.util.StringUtils; import org.onap.cps.ncmp.dmi.config.DmiPluginConfig.DmiPluginProperties; import org.onap.cps.ncmp.dmi.exception.CmHandleRegistrationException; @@ -46,6 +44,8 @@ import org.onap.cps.ncmp.dmi.model.ModuleSchemaProperties; import org.onap.cps.ncmp.dmi.model.ModuleSchemas; 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.client.NcmpRestClient; import org.onap.cps.ncmp.dmi.service.operation.SdncOperations; import org.springframework.http.HttpStatus; @@ -100,13 +100,13 @@ public class DmiServiceImpl implements DmiService { } @Override - public String getModuleResources(final String cmHandle, final List<ModuleReference> moduleReferences) { - final var getModuleResponses = new JSONArray(); + public YangResources getModuleResources(final String cmHandle, final List<ModuleReference> moduleReferences) { + final YangResources yangResources = new YangResources(); for (final var moduleReference : moduleReferences) { final var moduleRequest = createModuleRequest(moduleReference); final ResponseEntity<String> responseEntity = sdncOperations.getModuleResource(cmHandle, moduleRequest); if (responseEntity.getStatusCode() == HttpStatus.OK) { - getModuleResponses.add(toJsonObject(moduleReference, responseEntity)); + yangResources.add(toYangResource(moduleReference, responseEntity)); } else if (responseEntity.getStatusCode() == HttpStatus.NOT_FOUND) { log.error("SDNC did not return a module resource for the given cmHandle {}", cmHandle); throw new ModuleResourceNotFoundException(cmHandle, @@ -117,7 +117,7 @@ public class DmiServiceImpl implements DmiService { RESPONSE_CODE + responseEntity.getStatusCode() + MESSAGE + responseEntity.getBody()); } } - return getModuleResponses.toJSONString(); + return yangResources; } @Override @@ -248,13 +248,13 @@ public class DmiServiceImpl implements DmiService { return moduleRequest; } - private JSONObject toJsonObject(final ModuleReference moduleReference, + private YangResource toYangResource(final ModuleReference moduleReference, final ResponseEntity<String> response) { - final var jsonObject = new JSONObject(); - jsonObject.put("moduleName", moduleReference.getName()); - jsonObject.put("revision", moduleReference.getRevision()); - jsonObject.put("yangSource", extractYangSourceFromBody(response)); - return jsonObject; + final YangResource yangResource = new YangResource(); + yangResource.setModuleName(moduleReference.getName()); + yangResource.setRevision(moduleReference.getRevision()); + yangResource.setYangSource(extractYangSourceFromBody(response)); + return yangResource; } private String extractYangSourceFromBody(final ResponseEntity<String> responseEntity) { diff --git a/src/main/resources/spotbugs-exclude.xml b/src/main/resources/spotbugs-exclude.xml new file mode 100644 index 00000000..e8a1f6e2 --- /dev/null +++ b/src/main/resources/spotbugs-exclude.xml @@ -0,0 +1,54 @@ +<!-- + ============LICENSE_START======================================================= + Copyright (C) 2021 Nordix Foundation. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= +--> + +<FindBugsFilter> + <Match> + <!-- Ignore generated code --> + <Source name="~.*generated-sources.*.java"/> + </Match> + <Match> + <Or> + <!-- Anonymous inner classes are very common. --> + <Bug pattern="SIC_INNER_SHOULD_BE_STATIC_ANON" /> + + <!-- We use static slf4j Logger (this rule is from KengoTODA/findbugs-slf4j jp.skypencil.findbugs.slf4:bug-pattern) --> + <Bug pattern="SLF4J_LOGGER_SHOULD_BE_NON_STATIC" /> + + <!-- Guava 25.1+ uses the Checker Framework's @Nullable which SpotBugs doesn't handle correctly, even though it's + supposed to; see https://github.com/spotbugs/spotbugs/issues/743 --> + <Bug pattern="NP_NONNULL_PARAM_VIOLATION" /> + <Bug pattern="NP_NULL_PARAM_DEREF" /> + <Bug pattern="NP_PARAMETER_MUST_BE_NONNULL_BUT_MARKED_AS_NULLABLE" /> + <Bug pattern="RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE" /> + + <!-- https://stackoverflow.com/a/34674776. Doesn't detect Lombok All Args Constructor variables being used with map get key and value, which can lead to spotbugs being detected + on used fields --> + <Bug pattern="URF_UNREAD_FIELD"/> + + <!-- https://github.com/spotbugs/spotbugs/issues/511. Strict reading of Object.equals() contract means that + evenever equals() behaviour is defined, all implementations need to adhere to it. The only reason + to override the method (assuming correct API design, of course) is to provide a more efficient + implementation. This rule would be forcing a @SuppressFBWarnings on perfectly compliant classes. --> + <Bug pattern="EQ_DOESNT_OVERRIDE_EQUALS"/> + + <!-- https://github.com/spotbugs/spotbugs/issues/756. spotbugs does not grok Java 11's try-with-resources --> + <Bug pattern="RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE"/> + </Or> + </Match> + +</FindBugsFilter> 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..9c27dc1b 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 @@ -64,17 +66,17 @@ 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 moduleSetSchema = new ModuleSetSchemas() - moduleSetSchema.namespace('some-namespace') - moduleSetSchema.moduleName('some-moduleName') - moduleSetSchema.revision('some-revision') + def json = '{"operation" : "read", "cmHandleProperties" : {}}' + def moduleSetSchema = new ModuleSetSchemas(namespace:'some-namespace', + moduleName:'some-moduleName', + revision:'some-revision') def moduleSetSchemasList = [moduleSetSchema] as List<ModuleSetSchemas> def moduleSet = new ModuleSet() moduleSet.schemas(moduleSetSchemasList) mockDmiService.getModulesForCmHandle('node1') >> moduleSet when: 'post is being called' def response = mvc.perform(post(getModuleUrl) - .contentType(MediaType.APPLICATION_JSON)) + .contentType(MediaType.APPLICATION_JSON).content(json)) .andReturn().response then: 'status is OK' response.status == HttpStatus.OK.value() @@ -99,11 +101,12 @@ class DmiRestControllerSpec extends Specification { def 'Get all modules for given cm handle with exception handling of #scenario.'() { given: 'REST endpoint for getting all modules' def getModuleUrl = "$basePathV1/ch/node1/modules" - and: 'get modules for cm-handle throws #exceptionClass' + and: 'given request body and get modules for cm-handle throws #exceptionClass' + def json = '{"operation" : "read", "cmHandleProperties" : {}}' mockDmiService.getModulesForCmHandle('node1') >> { throw Mock(exceptionClass) } when: 'post is invoked' def response = mvc.perform( post(getModuleUrl) - .contentType(MediaType.APPLICATION_JSON)) + .contentType(MediaType.APPLICATION_JSON).content(json)) .andReturn().response then: 'response status is #expectedResponse' response.status == expectedResponse @@ -149,15 +152,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 +167,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.'() { |