summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortragait <rahul.tyagi@est.tech>2021-09-22 10:50:15 +0100
committertragait <rahul.tyagi@est.tech>2021-09-27 11:29:53 +0100
commit400b6c7a610e18e2c648a0680fe04b93792664cd (patch)
tree7b13886152e75eacd9d130cefefecd57ca075f2f
parentcb8bc88d47fb1614aa6d89ce1f0054a1e2775821 (diff)
fix fetch modules request body
Issue-ID: CPS-653 Signed-off-by: tragait <rahul.tyagi@est.tech> Change-Id: I6b5f0fc74ea4e70e65b05ed353e25311ed36135e
-rw-r--r--docs/openapi/components.yml4
-rw-r--r--docs/openapi/openapi.yml8
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java24
-rw-r--r--src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy15
4 files changed, 32 insertions, 19 deletions
diff --git a/docs/openapi/components.yml b/docs/openapi/components.yml
index 94742c82..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:
diff --git a/docs/openapi/openapi.yml b/docs/openapi/openapi.yml
index 716528b1..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,7 +113,7 @@ paths:
content:
application/json:
schema:
- $ref: 'components.yml#/components/schemas/DmiReadRequestBody'
+ $ref: 'components.yml#/components/schemas/DmiModuleReadRequestBody'
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 9f192841..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,7 +29,7 @@ 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;
@@ -57,16 +57,19 @@ 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<YangResources> 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);
return new ResponseEntity<>(response, HttpStatus.OK);
}
@@ -163,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/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 dd5e79da..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
@@ -66,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()
@@ -101,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