From acc0f8b83a320b979cb5db23906f4ef3baf5f42c Mon Sep 17 00:00:00 2001 From: niamhcore Date: Wed, 6 Oct 2021 09:49:12 +0100 Subject: Updating get module schema request body Issue-ID: CPS-706 Signed-off-by: niamhcore Change-Id: I92d241c4ccde77aaaf8aa5a3903437016edf65d0 --- docs/openapi/components.yml | 29 ++++++++++++++-------- docs/openapi/openapi.yml | 6 ++--- .../dmi/rest/controller/DmiRestController.java | 26 ++++++++----------- .../rest/controller/DmiRestControllerSpec.groovy | 26 +++---------------- src/test/resources/GetModules.json | 1 - 5 files changed, 37 insertions(+), 51 deletions(-) diff --git a/docs/openapi/components.yml b/docs/openapi/components.yml index a03cb1f8..30e5987f 100644 --- a/docs/openapi/components.yml +++ b/docs/openapi/components.yml @@ -19,14 +19,15 @@ components: items: type: string - DmiModuleReadRequestBody: + ModuleReferencesRequest: + type: object + properties: + cmHandleProperties: + $ref: '#/components/schemas/cmHandleProperties' + + ModuleResourcesReadRequest: type: object properties: - operation: - type: string - enum: [read] - dataType: - type: string data: type: object properties: @@ -36,9 +37,9 @@ components: type: object properties: name: - type: string + $ref: '#/components/schemas/name' revision: - type: string + $ref: '#/components/schemas/revision' cmHandleProperties: $ref: '#/components/schemas/cmHandleProperties' @@ -53,7 +54,7 @@ components: moduleName: type: string revision: - type: string + $ref: '#/components/schemas/revision' namespace: type: string @@ -70,7 +71,7 @@ components: moduleName: type: string revision: - type: string + $ref: '#/components/schemas/revision' DataAccessReadRequest: type: object @@ -100,6 +101,14 @@ components: type: string example: {"prop1":"value1","prop2":"value2"} + name: + type: string + example: someName + + revision: + type: string + example: someRevision + responses: NotFound: description: The specified resource was not found diff --git a/docs/openapi/openapi.yml b/docs/openapi/openapi.yml index 66f2e6b1..83c05abb 100644 --- a/docs/openapi/openapi.yml +++ b/docs/openapi/openapi.yml @@ -37,7 +37,7 @@ paths: - dmi-plugin summary: Get all modules for cm handle description: Get all modules for given cm handle - operationId: getModulesForCmHandle + operationId: getModuleReferences parameters: - name: cmHandle in: path @@ -50,7 +50,7 @@ paths: content: application/json: schema: - $ref: 'components.yml#/components/schemas/DataAccessReadRequest' + $ref: 'components.yml#/components/schemas/ModuleReferencesRequest' responses: '200': description: OK @@ -113,7 +113,7 @@ paths: content: application/json: schema: - $ref: 'components.yml#/components/schemas/DmiModuleReadRequestBody' + $ref: 'components.yml#/components/schemas/ModuleResourcesReadRequest' responses: '200': description: OK 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 908ccbe2..b17280ae 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 @@ -20,8 +20,6 @@ package org.onap.cps.ncmp.dmi.rest.controller; -import static org.onap.cps.ncmp.dmi.model.DmiModuleReadRequestBody.OperationEnum.READ; - import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import java.util.List; @@ -30,7 +28,8 @@ 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.DmiModuleReadRequestBody; +import org.onap.cps.ncmp.dmi.model.ModuleReferencesRequest; +import org.onap.cps.ncmp.dmi.model.ModuleResourcesReadRequest; 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; @@ -58,8 +57,8 @@ public class DmiRestController implements DmiPluginApi, DmiPluginInternalApi { } @Override - public ResponseEntity getModulesForCmHandle(final String cmHandle, - final @Valid DataAccessReadRequest body) { + public ResponseEntity getModuleReferences(final String cmHandle, + final @Valid ModuleReferencesRequest body) { // For onap-dmi-plugin we don't need cmHandleProperties, so DataAccessReadRequest is not used. final var moduleSet = dmiService.getModulesForCmHandle(cmHandle); return ResponseEntity.ok(moduleSet); @@ -67,14 +66,11 @@ public class DmiRestController implements DmiPluginApi, DmiPluginInternalApi { @Override public ResponseEntity retrieveModuleResources( - final @Valid DmiModuleReadRequestBody dmiModuleReadRequestBody, - final String cmHandle) { - if (READ.equals(dmiModuleReadRequestBody.getOperation())) { - final var moduleReferenceList = convertRestObjectToJavaApiObject(dmiModuleReadRequestBody); - final var response = dmiService.getModuleResources(cmHandle, moduleReferenceList); - return new ResponseEntity<>(response, HttpStatus.OK); - } - return new ResponseEntity<>(HttpStatus.CONFLICT); + final @Valid ModuleResourcesReadRequest moduleResourcesReadRequest, + final String cmHandle) { + final List moduleReferences = convertRestObjectToJavaApiObject(moduleResourcesReadRequest); + final YangResources yangResources = dmiService.getModuleResources(cmHandle, moduleReferences); + return new ResponseEntity<>(yangResources, HttpStatus.OK); } /** @@ -162,9 +158,9 @@ public class DmiRestController implements DmiPluginApi, DmiPluginInternalApi { } private List convertRestObjectToJavaApiObject( - final DmiModuleReadRequestBody dmiModuleSchemaReadRequestBody) { + final ModuleResourcesReadRequest moduleResourcesReadRequest) { return objectMapper - .convertValue(dmiModuleSchemaReadRequestBody.getData().getModules(), + .convertValue(moduleResourcesReadRequest.getData().getModules(), new TypeReference>() {}); } } 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 3bc1f3be..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 @@ -65,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') @@ -101,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) @@ -150,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" - String jsonData = getJsonDataForGetModules('read') + 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') @@ -169,22 +169,10 @@ class DmiRestControllerSpec extends Specification { response.getContentAsString() == '[{"yangSource":"\\"some-data\\"","moduleName":"NAME","revision":"REVISION"}]' } - def 'Retrieve module resources with invalid operation.'() { - given: 'an endpoint and json data with invalid operation value' - def getModulesEndpoint = "$basePathV1/ch/some-cm-handle/moduleResources" - def jsonData = getJsonDataForGetModules('invalid operation') - when: 'get module resource api is invoked' - def response = mvc.perform(post(getModulesEndpoint) - .contentType(MediaType.APPLICATION_JSON) - .content(jsonData)).andReturn().response - then: 'a conflict status is returned' - response.status == HttpStatus.CONFLICT.value() - } - def 'Retrieve module resources with exception handling.'() { given: 'an endpoint and json data' def getModulesEndpoint = "$basePathV1/ch/some-cm-handle/moduleResources" - String jsonData = getJsonDataForGetModules('read') + 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' @@ -267,10 +255,4 @@ class DmiRestControllerSpec extends Specification { '? needs to be encoded as %3F' | 'idWith%3F' } - - def getJsonDataForGetModules(operation) { - def jsonData = TestUtils.getResourceFileContent('GetModules.json') - return jsonData.replace('${operation-for-test}', operation) - } - } diff --git a/src/test/resources/GetModules.json b/src/test/resources/GetModules.json index 98e41672..57f5aefd 100644 --- a/src/test/resources/GetModules.json +++ b/src/test/resources/GetModules.json @@ -1,5 +1,4 @@ { - "operation": "${operation-for-test}", "data": { "modules": [ { -- cgit 1.2.3-korg