summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordavid.mcweeney <david.mcweeney@est.tech>2024-04-30 10:24:41 +0100
committerdavid.mcweeney <david.mcweeney@est.tech>2024-05-15 13:55:01 +0100
commitee0c3beb8b67baf7509c8bb6c0fda050dfb6d526 (patch)
tree45640f5f997befb8caf6c0c327b981eb234ee7e9
parent676227bc67596dfc01cdc82beec3022bc830fec4 (diff)
CPS-2181 - #2 Included Module Set Tag as incoming param for Yang Module Resources - DMI
Change-Id: I799159798d9c6018a1495c61924111610bbe2978 Signed-off-by: david.mcweeney <david.mcweeney@est.tech> Issue-ID: CPS-2181
-rw-r--r--docs/api/swagger/openapi.yaml1
-rw-r--r--openapi/components.yml5
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java3
-rw-r--r--src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy41
-rw-r--r--src/test/resources/moduleResources.json3
5 files changed, 52 insertions, 1 deletions
diff --git a/docs/api/swagger/openapi.yaml b/docs/api/swagger/openapi.yaml
index 4e3ae897..f3516b5d 100644
--- a/docs/api/swagger/openapi.yaml
+++ b/docs/api/swagger/openapi.yaml
@@ -493,6 +493,7 @@ components:
type: object
ModuleResourcesReadRequest:
example:
+ moduleSetTag: module-set-tag1
data:
modules:
- name: my-name
diff --git a/openapi/components.yml b/openapi/components.yml
index 00d71564..b7f6058b 100644
--- a/openapi/components.yml
+++ b/openapi/components.yml
@@ -101,6 +101,11 @@ components:
ModuleResourcesReadRequest:
type: object
properties:
+ moduleSetTag:
+ type: string
+ description: Module set tag of the given cm handle
+ example: Module-set-tag-1
+ required: false
data:
type: object
properties:
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 2ed1ebd3..1dcc6373 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
@@ -87,6 +87,9 @@ public class DmiRestController implements DmiPluginApi, DmiPluginInternalApi {
final ModuleResourcesReadRequest moduleResourcesReadRequest) {
final List<ModuleReference> moduleReferences = convertRestObjectToJavaApiObject(moduleResourcesReadRequest);
final YangResources yangResources = dmiService.getModuleResources(cmHandle, moduleReferences);
+ if (moduleResourcesReadRequest.getModuleSetTag() != null) {
+ log.info("Module set tag received: {}", moduleResourcesReadRequest.getModuleSetTag());
+ }
return new ResponseEntity<>(yangResources, HttpStatus.OK);
}
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 7b2570b0..a23902fa 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
@@ -21,6 +21,10 @@
package org.onap.cps.ncmp.dmi.rest.controller
+import ch.qos.logback.classic.Level
+import ch.qos.logback.classic.Logger
+import ch.qos.logback.classic.spi.ILoggingEvent
+import ch.qos.logback.core.read.ListAppender
import org.onap.cps.ncmp.dmi.TestUtils
import org.onap.cps.ncmp.dmi.config.WebSecurityConfig
import org.onap.cps.ncmp.dmi.exception.DmiException
@@ -34,6 +38,7 @@ import org.onap.cps.ncmp.dmi.notifications.async.AsyncTaskExecutor
import org.onap.cps.ncmp.dmi.notifications.async.DmiAsyncRequestResponseEventProducer
import org.onap.cps.ncmp.dmi.service.DmiService
import org.onap.cps.ncmp.dmi.service.model.ModuleReference
+import org.slf4j.LoggerFactory
import org.spockframework.spring.SpringBean
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Value
@@ -75,6 +80,17 @@ class DmiRestControllerSpec extends Specification {
@SpringBean
AsyncTaskExecutor asyncTaskExecutor = new AsyncTaskExecutor(cpsAsyncRequestResponseEventProducer)
+ def logger = Spy(ListAppender<ILoggingEvent>)
+
+ void setup() {
+ ((Logger) LoggerFactory.getLogger(DmiRestController.class)).addAppender(logger)
+ logger.start()
+ }
+
+ void cleanup() {
+ ((Logger) LoggerFactory.getLogger(DmiRestController.class)).detachAndStopAllAppenders()
+ }
+
@Value('${rest.api.dmi-base-path}/v1')
def basePathV1
@@ -189,6 +205,27 @@ class DmiRestControllerSpec extends Specification {
response.status == HttpStatus.NOT_FOUND.value()
}
+ def 'Retrieve module resources and ensure module set tag is logged.'() {
+ given: 'URL to get module resources'
+ def getModulesEndpoint = "$basePathV1/ch/some-cm-handle/moduleResources"
+ and: 'request data to get some modules'
+ String jsonData = TestUtils.getResourceFileContent('moduleResources.json')
+ and: 'the DMI service returns the yang resources'
+ def moduleReferences = []
+ def yangResources = new YangResources()
+ def yangResource = new YangResource()
+ yangResources.add(yangResource)
+ mockDmiService.getModuleResources('some-cm-handle', moduleReferences) >> yangResources
+ when: 'the request is posted'
+ mvc.perform(post(getModulesEndpoint)
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(jsonData))
+ then: 'the module set tag is logged'
+ def loggingEvent = getLoggingEvent()
+ assert loggingEvent.level == Level.INFO
+ assert loggingEvent.formattedMessage.contains('Module set tag received: module-set-tag1')
+ }
+
def 'Get resource data for pass-through operational.'() {
given: 'Get resource data url and some request data'
def getResourceDataForCmHandleUrl = "${basePathV1}/ch/some-cmHandle/data/ds/ncmp-datastore:passthrough-operational" +
@@ -343,4 +380,8 @@ class DmiRestControllerSpec extends Specification {
then: 'the resource data operation endpoint returns the not implemented response'
assert response.status == 501
}
+
+ def getLoggingEvent() {
+ return logger.list[0]
+ }
} \ No newline at end of file
diff --git a/src/test/resources/moduleResources.json b/src/test/resources/moduleResources.json
index 57f5aefd..23adfcba 100644
--- a/src/test/resources/moduleResources.json
+++ b/src/test/resources/moduleResources.json
@@ -13,5 +13,6 @@
},
"cmHandleProperties": {
"subsystemId": "system-001"
- }
+ },
+ "moduleSetTag": "module-set-tag1"
}