diff options
author | Toine Siebelink <toine.siebelink@est.tech> | 2024-05-16 08:42:45 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2024-05-16 08:42:45 +0000 |
commit | a89971d5da7bc11f45195fbd3f8e77cb4b02e833 (patch) | |
tree | 610ed263f744496b7179f6fd1b69c55feefaa921 /src/test/groovy/org | |
parent | 4e9a5598fcb194426ef5c8c3cfc055821a3f9ed8 (diff) | |
parent | ee0c3beb8b67baf7509c8bb6c0fda050dfb6d526 (diff) |
Merge "CPS-2181 - #2 Included Module Set Tag as incoming param for Yang Module Resources - DMI"
Diffstat (limited to 'src/test/groovy/org')
-rw-r--r-- | src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy | 41 |
1 files changed, 41 insertions, 0 deletions
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 |