summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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
3 files changed, 15 insertions, 38 deletions
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": [
{