diff options
Diffstat (limited to 'src')
3 files changed, 46 insertions, 1 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 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" } |