summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorniamhcore <niamh.core@est.tech>2021-10-06 09:49:12 +0100
committerniamhcore <niamh.core@est.tech>2021-10-07 11:51:40 +0100
commitacc0f8b83a320b979cb5db23906f4ef3baf5f42c (patch)
tree581a83acb0129de9f061bc0b4fce0ecef83f50c1
parentf0acf5b1a4dd4bb774a81a7a75c48aeb81169fde (diff)
Updating get module schema request body
Issue-ID: CPS-706 Signed-off-by: niamhcore <niamh.core@est.tech> Change-Id: I92d241c4ccde77aaaf8aa5a3903437016edf65d0
-rw-r--r--docs/openapi/components.yml29
-rw-r--r--docs/openapi/openapi.yml6
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java26
-rw-r--r--src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy26
-rw-r--r--src/test/resources/GetModules.json1
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<ModuleSet> getModulesForCmHandle(final String cmHandle,
- final @Valid DataAccessReadRequest body) {
+ public ResponseEntity<ModuleSet> 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<YangResources> 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<ModuleReference> 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<ModuleReference> convertRestObjectToJavaApiObject(
- final DmiModuleReadRequestBody dmiModuleSchemaReadRequestBody) {
+ final ModuleResourcesReadRequest moduleResourcesReadRequest) {
return objectMapper
- .convertValue(dmiModuleSchemaReadRequestBody.getData().getModules(),
+ .convertValue(moduleResourcesReadRequest.getData().getModules(),
new TypeReference<List<ModuleReference>>() {});
}
}
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": [
{