summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/datajobs/rest/controller/DmiDatajobsRestController.java60
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/notifications/cmsubscription/CmNotificationSubscriptionDmiInEventConsumer.java16
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java14
-rw-r--r--src/main/resources/application.yml6
-rw-r--r--src/test/groovy/org/onap/cps/ncmp/dmi/datajobs/rest/controller/DmiDatajobsRestControllerSpec.groovy69
-rw-r--r--src/test/groovy/org/onap/cps/ncmp/dmi/notifications/async/AsyncTaskExecutorIntegrationSpec.groovy24
-rw-r--r--src/test/groovy/org/onap/cps/ncmp/dmi/notifications/cmsubscription/CmNotificationSubscriptionDmiInEventConsumerSpec.groovy25
-rw-r--r--src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy62
-rw-r--r--src/test/resources/moduleResources.json3
-rw-r--r--src/test/resources/readData.json3
10 files changed, 257 insertions, 25 deletions
diff --git a/src/main/java/org/onap/cps/ncmp/dmi/datajobs/rest/controller/DmiDatajobsRestController.java b/src/main/java/org/onap/cps/ncmp/dmi/datajobs/rest/controller/DmiDatajobsRestController.java
new file mode 100644
index 00000000..bbc1c20d
--- /dev/null
+++ b/src/main/java/org/onap/cps/ncmp/dmi/datajobs/rest/controller/DmiDatajobsRestController.java
@@ -0,0 +1,60 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2024 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.ncmp.dmi.datajobs.rest.controller;
+
+import org.onap.cps.ncmp.dmi.datajobs.model.SubjobReadRequest;
+import org.onap.cps.ncmp.dmi.datajobs.model.SubjobWriteRequest;
+import org.onap.cps.ncmp.dmi.datajobs.rest.api.DmiDatajobApi;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RequestMapping("${rest.api.dmi-base-path}")
+@RestController
+public class DmiDatajobsRestController implements DmiDatajobApi {
+ /**
+ * * This method is not implemented for ONAP DMI plugin.
+ *
+ * @param requestId Identifier for the overall Datajob (required)
+ * @param subjobReadRequest Operation body (optional)
+ * @return (@ code ResponseEntity) response entity
+ */
+ @Override
+ public ResponseEntity<Void> readDataJob(final String requestId,
+ final SubjobReadRequest subjobReadRequest) {
+
+ return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
+ }
+
+ /**
+ * * This method is not implemented for ONAP DMI plugin.
+ *
+ * @param requestId Identifier for the overall Datajob (required)
+ * @param subjobWriteRequest Operation body (optional)
+ * @return (@ code ResponseEntity) response entity
+ */
+ @Override
+ public ResponseEntity<Void> writeDataJob(final String requestId,
+ final SubjobWriteRequest subjobWriteRequest) {
+ return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
+ }
+}
diff --git a/src/main/java/org/onap/cps/ncmp/dmi/notifications/cmsubscription/CmNotificationSubscriptionDmiInEventConsumer.java b/src/main/java/org/onap/cps/ncmp/dmi/notifications/cmsubscription/CmNotificationSubscriptionDmiInEventConsumer.java
index ecfef6f3..3a9838b0 100644
--- a/src/main/java/org/onap/cps/ncmp/dmi/notifications/cmsubscription/CmNotificationSubscriptionDmiInEventConsumer.java
+++ b/src/main/java/org/onap/cps/ncmp/dmi/notifications/cmsubscription/CmNotificationSubscriptionDmiInEventConsumer.java
@@ -38,8 +38,8 @@ import org.springframework.stereotype.Service;
public class CmNotificationSubscriptionDmiInEventConsumer {
- @Value("${app.dmi.avc.subscription-response-topic}")
- private String cmNotificationSubscriptionResponseTopic;
+ @Value("${app.dmi.avc.cm-subscription-dmi-out}")
+ private String cmNotificationSubscriptionDmiOutTopic;
@Value("${dmi.service.name}")
private String dmiName;
private final KafkaTemplate<String, CloudEvent> cloudEventKafkaTemplate;
@@ -49,7 +49,7 @@ public class CmNotificationSubscriptionDmiInEventConsumer {
*
* @param cmNotificationSubscriptionDmiInCloudEvent the event to be consumed
*/
- @KafkaListener(topics = "${app.dmi.avc.subscription-topic}",
+ @KafkaListener(topics = "${app.dmi.avc.cm-subscription-dmi-in}",
containerFactory = "cloudEventConcurrentKafkaListenerContainerFactory")
public void consumeCmNotificationSubscriptionDmiInEvent(
final ConsumerRecord<String, CloudEvent> cmNotificationSubscriptionDmiInCloudEvent) {
@@ -62,10 +62,10 @@ public class CmNotificationSubscriptionDmiInEventConsumer {
final String correlationId = String.valueOf(cmNotificationSubscriptionDmiInCloudEvent.value()
.getExtension("correlationid"));
- if ("subscriptionCreated".equals(subscriptionType)) {
+ if ("subscriptionCreateRequest".equals(subscriptionType)) {
createAndSendCmNotificationSubscriptionDmiOutEvent(subscriptionId, "subscriptionCreateResponse",
correlationId, CmNotificationSubscriptionStatus.ACCEPTED);
- } else if ("subscriptionDeleted".equals(subscriptionType)) {
+ } else if ("subscriptionDeleteRequest".equals(subscriptionType)) {
createAndSendCmNotificationSubscriptionDmiOutEvent(subscriptionId, "subscriptionDeleteResponse",
correlationId, CmNotificationSubscriptionStatus.ACCEPTED);
}
@@ -91,13 +91,13 @@ public class CmNotificationSubscriptionDmiInEventConsumer {
if (cmNotificationSubscriptionStatus.equals(CmNotificationSubscriptionStatus.ACCEPTED)) {
cmNotificationSubscriptionDmiOutEventData.setStatusCode("1");
cmNotificationSubscriptionDmiOutEventData.setStatusMessage("ACCEPTED");
- } else if (cmNotificationSubscriptionStatus.equals(CmNotificationSubscriptionStatus.REJECTED)) {
- cmNotificationSubscriptionDmiOutEventData.setStatusCode("2");
+ } else {
+ cmNotificationSubscriptionDmiOutEventData.setStatusCode("104");
cmNotificationSubscriptionDmiOutEventData.setStatusMessage("REJECTED");
}
cmNotificationSubscriptionDmiOutEvent.setData(cmNotificationSubscriptionDmiOutEventData);
- cloudEventKafkaTemplate.send(cmNotificationSubscriptionResponseTopic, eventKey,
+ cloudEventKafkaTemplate.send(cmNotificationSubscriptionDmiOutTopic, eventKey,
CmNotificationSubscriptionDmiOutEventToCloudEventMapper.toCloudEvent(cmNotificationSubscriptionDmiOutEvent,
subscriptionType, dmiName, correlationId));
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..cad5e726 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
@@ -80,13 +80,13 @@ public class DmiRestController implements DmiPluginApi, DmiPluginInternalApi {
return ResponseEntity.ok(moduleSet);
}
-
@Override
public ResponseEntity<YangResources> retrieveModuleResources(
final String cmHandle,
final ModuleResourcesReadRequest moduleResourcesReadRequest) {
final List<ModuleReference> moduleReferences = convertRestObjectToJavaApiObject(moduleResourcesReadRequest);
final YangResources yangResources = dmiService.getModuleResources(cmHandle, moduleReferences);
+ log.info("Module set tag received: {}", moduleResourcesReadRequest.getModuleSetTag());
return new ResponseEntity<>(yangResources, HttpStatus.OK);
}
@@ -116,6 +116,17 @@ public class DmiRestController implements DmiPluginApi, DmiPluginInternalApi {
@Override
public ResponseEntity<Void> getResourceDataForCmHandleDataOperation(final String topic, final String requestId,
final ResourceDataOperationRequests resourceDataOperationRequests) {
+ log.info("Request Details (for testing purposes)");
+ log.info("Request Id: {}", requestId);
+ log.info("Topic: {}", topic);
+
+ log.info("Details of the first Operation");
+ log.info("Resource Identifier: {}", resourceDataOperationRequests.get(0).getResourceIdentifier());
+ log.info("Module Set Tag: {}", resourceDataOperationRequests.get(0).getCmHandles().get(0).getModuleSetTag());
+ log.info("Operation Id: {}", resourceDataOperationRequests.get(0).getOperationId());
+ log.info("Cm Handles: {}", resourceDataOperationRequests.get(0).getCmHandles());
+ log.info("Options: {}", resourceDataOperationRequests.get(0).getOptions());
+
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}
@@ -139,6 +150,7 @@ public class DmiRestController implements DmiPluginApi, DmiPluginInternalApi {
final String optionsParamInQuery,
final String topicParamInQuery,
final DataAccessRequest dataAccessRequest) {
+ log.info("Module set tag: {}", dataAccessRequest.getModuleSetTag());
if (DatastoreType.PASSTHROUGH_OPERATIONAL == DatastoreType.fromDatastoreName(datastoreName)) {
return dataAccessPassthroughOperational(resourceIdentifier, cmHandle, dataAccessRequest,
optionsParamInQuery, topicParamInQuery);
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index 732f46db..003aa191 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -1,5 +1,5 @@
# ============LICENSE_START=======================================================
-# Copyright (C) 2021-2023 Nordix Foundation
+# Copyright (C) 2021-2024 Nordix Foundation
# Modifications Copyright (C) 2021 Bell Canada.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -72,8 +72,8 @@ app:
topic: ${NCMP_ASYNC_M2M_TOPIC:ncmp-async-m2m}
dmi:
avc:
- subscription-topic: ${DMI_CM_AVC_SUBSCRIPTION:ncmp-dmi-cm-avc-subscription-${dmi.service.name}}
- subscription-response-topic: ${DMI_CM_AVC_SUBSCRIPTION_RESPONSE:dmi-ncmp-cm-avc-subscription}
+ cm-subscription-dmi-in: ${CM_SUBSCRIPTION_DMI_IN_TOPIC:ncmp-dmi-cm-avc-subscription}
+ cm-subscription-dmi-out: ${CM_SUBSCRIPTION_DMI_OUT_TOPIC:dmi-ncmp-cm-avc-subscription}
notification:
async:
diff --git a/src/test/groovy/org/onap/cps/ncmp/dmi/datajobs/rest/controller/DmiDatajobsRestControllerSpec.groovy b/src/test/groovy/org/onap/cps/ncmp/dmi/datajobs/rest/controller/DmiDatajobsRestControllerSpec.groovy
new file mode 100644
index 00000000..c55f53c1
--- /dev/null
+++ b/src/test/groovy/org/onap/cps/ncmp/dmi/datajobs/rest/controller/DmiDatajobsRestControllerSpec.groovy
@@ -0,0 +1,69 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2024 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.ncmp.dmi.datajobs.rest.controller
+
+import org.onap.cps.ncmp.dmi.config.WebSecurityConfig
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.beans.factory.annotation.Value
+import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
+import org.springframework.context.annotation.Import
+import org.springframework.http.HttpStatus
+import org.springframework.security.test.context.support.WithMockUser
+import org.springframework.test.web.servlet.MockMvc
+import spock.lang.Specification
+
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post
+
+@Import(WebSecurityConfig)
+@WebMvcTest(DmiDatajobsRestController.class)
+@WithMockUser
+class DmiDatajobsRestControllerSpec extends Specification{
+
+ @Autowired
+ private MockMvc mvc
+
+ @Value('${rest.api.dmi-base-path}/v1')
+ def basePathV1
+
+ def 'write request should return 501 HTTP Status' () {
+ given: 'URL to write a data job'
+ def getModuleUrl = "${basePathV1}/writeJob/001"
+ when: 'the request is posted'
+ def response = mvc.perform(
+ post(getModuleUrl)
+ .contentType('application/3gpp-json-patch+json')
+ ).andReturn().response
+ then: 'response value is Not Implemented'
+ response.status == HttpStatus.NOT_IMPLEMENTED.value()
+ }
+
+ def 'read request should return 501 HTTP Status' () {
+ given: 'URL to write a data job'
+ def getModuleUrl = "${basePathV1}/readJob/001"
+ when: 'the request is posted'
+ def response = mvc.perform(
+ post(getModuleUrl)
+ .contentType('application/3gpp-json-patch+json')
+ ).andReturn().response
+ then: 'response value is Not Implemented'
+ response.status == HttpStatus.NOT_IMPLEMENTED.value()
+ }
+}
diff --git a/src/test/groovy/org/onap/cps/ncmp/dmi/notifications/async/AsyncTaskExecutorIntegrationSpec.groovy b/src/test/groovy/org/onap/cps/ncmp/dmi/notifications/async/AsyncTaskExecutorIntegrationSpec.groovy
index 7ca2d54c..12ca05cf 100644
--- a/src/test/groovy/org/onap/cps/ncmp/dmi/notifications/async/AsyncTaskExecutorIntegrationSpec.groovy
+++ b/src/test/groovy/org/onap/cps/ncmp/dmi/notifications/async/AsyncTaskExecutorIntegrationSpec.groovy
@@ -23,6 +23,7 @@ package org.onap.cps.ncmp.dmi.notifications.async
import com.fasterxml.jackson.databind.ObjectMapper
import org.onap.cps.ncmp.dmi.api.kafka.MessagingBaseSpec
import org.onap.cps.ncmp.dmi.exception.HttpClientRequestException
+import org.onap.cps.ncmp.dmi.model.DataAccessRequest
import org.onap.cps.ncmp.event.model.DmiAsyncRequestResponseEvent
import org.spockframework.spring.SpringBean
import org.springframework.boot.test.context.SpringBootTest
@@ -31,6 +32,7 @@ import org.springframework.test.annotation.DirtiesContext
import org.testcontainers.spock.Testcontainers
import java.time.Duration
+import java.util.function.Supplier
@SpringBootTest(classes = [AsyncTaskExecutor, DmiAsyncRequestResponseEventProducer])
@Testcontainers
@@ -42,6 +44,7 @@ class AsyncTaskExecutorIntegrationSpec extends MessagingBaseSpec {
new DmiAsyncRequestResponseEventProducer(kafkaTemplate)
def spiedObjectMapper = Spy(ObjectMapper)
+ def mockSupplier = Mock(Supplier)
def objectUnderTest = new AsyncTaskExecutor(cpsAsyncRequestResponseEventProducer)
@@ -83,4 +86,25 @@ class AsyncTaskExecutorIntegrationSpec extends MessagingBaseSpec {
assert event.getEventContent().getResponseCode() == '500'
}
+ def 'Execute an Async Task using asyncTaskExecutor and throw an error'() {
+ given: 'A task to be executed'
+ def requestId = '123456'
+ def operationEnum = DataAccessRequest.OperationEnum.CREATE
+ def timeOut = 100
+ when: 'AsyncTask has been executed'
+ objectUnderTest.executeAsyncTask(taskSupplierForFailingTask(), TEST_TOPIC, requestId, operationEnum, timeOut)
+ def records = kafkaConsumer.poll(Duration.ofMillis(1500))
+ then: 'the record received is the event sent'
+ def record = records.iterator().next()
+ DmiAsyncRequestResponseEvent event = spiedObjectMapper.readValue(record.value(), DmiAsyncRequestResponseEvent)
+ and: 'the status & code matches expected'
+ assert event.getEventContent().getResponseStatus() == 'Internal Server Error'
+ assert event.getEventContent().getResponseCode() == '500'
+
+ }
+
+ def taskSupplierForFailingTask() {
+ return () -> { throw new RuntimeException('original exception message') }
+ }
+
} \ No newline at end of file
diff --git a/src/test/groovy/org/onap/cps/ncmp/dmi/notifications/cmsubscription/CmNotificationSubscriptionDmiInEventConsumerSpec.groovy b/src/test/groovy/org/onap/cps/ncmp/dmi/notifications/cmsubscription/CmNotificationSubscriptionDmiInEventConsumerSpec.groovy
index 47953439..f1f476f6 100644
--- a/src/test/groovy/org/onap/cps/ncmp/dmi/notifications/cmsubscription/CmNotificationSubscriptionDmiInEventConsumerSpec.groovy
+++ b/src/test/groovy/org/onap/cps/ncmp/dmi/notifications/cmsubscription/CmNotificationSubscriptionDmiInEventConsumerSpec.groovy
@@ -47,12 +47,12 @@ import java.time.OffsetDateTime
import java.time.ZoneId
-@SpringBootTest(classes = [CmNotificationSubscriptionDmiInEventConsumer])
@Testcontainers
@DirtiesContext
class CmNotificationSubscriptionDmiInEventConsumerSpec extends MessagingBaseSpec {
def objectMapper = new ObjectMapper()
def testTopic = 'dmi-ncmp-cm-avc-subscription'
+ def testDmiName = 'test-ncmp-dmi'
@SpringBean
CmNotificationSubscriptionDmiInEventConsumer objectUnderTest = new CmNotificationSubscriptionDmiInEventConsumer(cloudEventKafkaTemplate)
@@ -70,36 +70,41 @@ class CmNotificationSubscriptionDmiInEventConsumerSpec extends MessagingBaseSpec
def 'Sends subscription cloud event response successfully.'() {
given: 'an subscription event response'
- objectUnderTest.dmiName = 'test-ncmp-dmi'
- objectUnderTest.cmNotificationSubscriptionResponseTopic = testTopic
+ objectUnderTest.dmiName = testDmiName
+ objectUnderTest.cmNotificationSubscriptionDmiOutTopic = testTopic
def correlationId = 'test-subscriptionId#test-ncmp-dmi'
- def cmSubscriptionDmiOutEventData = new Data(statusCode: '1', statusMessage: 'ACCEPTED')
+ def cmSubscriptionDmiOutEventData = new Data(statusCode: subscriptionStatusCode, statusMessage: subscriptionStatusMessage)
def subscriptionEventResponse =
new CmNotificationSubscriptionDmiOutEvent().withData(cmSubscriptionDmiOutEventData)
and: 'consumer has a subscription'
kafkaConsumer.subscribe([testTopic] as List<String>)
when: 'an event is published'
def eventKey = UUID.randomUUID().toString()
- objectUnderTest.createAndSendCmNotificationSubscriptionDmiOutEvent(eventKey, "subscriptionCreatedStatus", correlationId, CmNotificationSubscriptionStatus.ACCEPTED)
+ objectUnderTest.createAndSendCmNotificationSubscriptionDmiOutEvent(eventKey, "subscriptionCreatedStatus", correlationId, subscriptionAcceptanceType)
and: 'topic is polled'
def records = kafkaConsumer.poll(Duration.ofMillis(1500))
- then: 'poll returns one record'
+ then: 'poll returns one record and close kafkaConsumer'
assert records.size() == 1
def record = records.iterator().next()
+ kafkaConsumer.close()
and: 'the record value matches the expected event value'
def expectedValue = objectMapper.writeValueAsString(subscriptionEventResponse)
assert expectedValue == record.value
assert eventKey == record.key
+ where: 'given #scenario'
+ scenario | subscriptionAcceptanceType | subscriptionStatusCode | subscriptionStatusMessage
+ 'Subscription is Accepted' | CmNotificationSubscriptionStatus.ACCEPTED | '1' | 'ACCEPTED'
+ 'Subscription is Rejected' | CmNotificationSubscriptionStatus.REJECTED | '104' | 'REJECTED'
}
def 'Consume valid message.'() {
given: 'an event'
- objectUnderTest.dmiName = 'test-ncmp-dmi'
+ objectUnderTest.dmiName = testDmiName
def eventKey = UUID.randomUUID().toString()
def timestamp = new Timestamp(1679521929511)
def jsonData = TestUtils.getResourceFileContent('cmNotificationSubscriptionCreationEvent.json')
def subscriptionEvent = objectMapper.readValue(jsonData, CmNotificationSubscriptionDmiInEvent.class)
- objectUnderTest.cmNotificationSubscriptionResponseTopic = testTopic
+ objectUnderTest.cmNotificationSubscriptionDmiOutTopic = testTopic
def cloudEvent = CloudEventBuilder.v1().withId(UUID.randomUUID().toString()).withSource(URI.create('test-ncmp-dmi'))
.withType(subscriptionType)
.withDataSchema(URI.create("urn:cps:" + CmNotificationSubscriptionDmiInEvent.class.getName() + ":1.0.0"))
@@ -119,11 +124,11 @@ class CmNotificationSubscriptionDmiInEventConsumerSpec extends MessagingBaseSpec
def 'Consume invalid message.'() {
given: 'an invalid event body'
- objectUnderTest.dmiName = 'test-ncmp-dmi'
+ objectUnderTest.dmiName = testDmiName
def eventKey = UUID.randomUUID().toString()
def timestamp = new Timestamp(1679521929511)
def invalidJsonBody = "/////"
- objectUnderTest.cmNotificationSubscriptionResponseTopic = testTopic
+ objectUnderTest.cmNotificationSubscriptionDmiOutTopic = testTopic
def cloudEvent = CloudEventBuilder.v1().withId(UUID.randomUUID().toString()).withSource(URI.create('test-ncmp-dmi'))
.withType("subscriptionCreated")
.withDataSchema(URI.create("urn:cps:org.onap.ncmp.dmi.cm.subscription:1.0.0"))
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..a519de7b 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.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,26 @@ 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 loggingMessage = getLoggingMessage(0)
+ assert loggingMessage.contains('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" +
@@ -302,6 +338,19 @@ class DmiRestControllerSpec extends Specification {
resourceIdentifier << ['passthrough-operational', 'passthrough-running']
}
+ def 'PassThrough logs module set tag'(){
+ given: 'Passthrough read URL and request data with a module set tag (parameter)'
+ def readPassThroughUrl ="${basePathV1}/ch/some-cmHandle/data/ds/ncmp-datastore:" +
+ 'passthrough-running?resourceIdentifier=some-resourceIdentifier'
+ def jsonData = TestUtils.getResourceFileContent('readData.json')
+ when: 'the request is posted'
+ mvc.perform(
+ post(readPassThroughUrl).contentType(MediaType.APPLICATION_JSON).content(jsonData))
+ then: 'response status is OK'
+ def loggingMessage = getLoggingMessage(0)
+ assert loggingMessage.contains('module-set-tag-example')
+ }
+
def 'Get resource data for pass-through running with #scenario value in resource identifier param.'() {
given: 'Get resource data url'
def getResourceDataForCmHandleUrl = "${basePathV1}/ch/some-cmHandle/data/ds/ncmp-datastore:passthrough-running" +
@@ -335,12 +384,23 @@ class DmiRestControllerSpec extends Specification {
def resourceDataUrl = "$basePathV1/data?topic=client-topic-name&requestId=some-requestId"
and: 'list of operation details are received into request body'
def dataOperationRequestBody = '[{"operation": "read", "operationId": "14", "datastore": "ncmp-datastore:passthrough-operational", "options": "some options", "resourceIdentifier": "some resourceIdentifier",' +
- ' "cmhandles": [ {"id": "cmHanlde123", "cmHandleProperties": { "myProp`": "some value", "otherProp": "other value"}}]}]'
+ '"cmHandles": [ {"id": "cmHandle123", "moduleSetTag": "module-set-tag1", "cmHandleProperties": { "myProp`": "some value", "otherProp": "other value"}}]}]'
when: 'the dmi resource data for dataOperation api is called.'
def response = mvc.perform(
post(resourceDataUrl).contentType(MediaType.APPLICATION_JSON).content(dataOperationRequestBody)
).andReturn().response
then: 'the resource data operation endpoint returns the not implemented response'
assert response.status == 501
+ and: 'the job details are correctly received (logged)'
+ assert getLoggingMessage(1).contains('some-requestId')
+ assert getLoggingMessage(2).contains('client-topic-name')
+ assert getLoggingMessage(4).contains('some resourceIdentifier')
+ assert getLoggingMessage(5).contains('module-set-tag1')
+ and: 'the operation Id is correctly received (logged)'
+ assert getLoggingMessage(6).contains('14')
+ }
+
+ def getLoggingMessage(int index) {
+ return logger.list[index].formattedMessage
}
} \ 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"
}
diff --git a/src/test/resources/readData.json b/src/test/resources/readData.json
index 9f2b154f..53f6d2ed 100644
--- a/src/test/resources/readData.json
+++ b/src/test/resources/readData.json
@@ -4,5 +4,6 @@
"data": "normal request body",
"cmHandleProperties": {
"some-property": "some-property-value"
- }
+ },
+ "moduleSetTag": "module-set-tag-example"
} \ No newline at end of file