aboutsummaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'cps-ncmp-service/src/test')
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/avc/SubscriptionEventResponseConsumerSpec.groovy7
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avc/SubscriptionEventResponseMapperSpec.groovy61
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/subscriptions/SubscriptionPersistenceSpec.groovy48
-rw-r--r--cps-ncmp-service/src/test/resources/avcSubscriptionEventResponse.json9
4 files changed, 115 insertions, 10 deletions
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/avc/SubscriptionEventResponseConsumerSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/avc/SubscriptionEventResponseConsumerSpec.groovy
index a673462008..e9f66892cb 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/avc/SubscriptionEventResponseConsumerSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/avc/SubscriptionEventResponseConsumerSpec.groovy
@@ -22,6 +22,8 @@ package org.onap.cps.ncmp.api.impl.event.avc
import com.fasterxml.jackson.databind.ObjectMapper
import com.hazelcast.map.IMap
+import org.onap.cps.ncmp.api.impl.events.avcsubscription.SubscriptionEventResponseMapper
+import org.onap.cps.ncmp.api.impl.subscriptions.SubscriptionPersistenceImpl
import org.onap.cps.ncmp.api.kafka.MessagingBaseSpec
import org.onap.cps.ncmp.api.models.SubscriptionEventResponse
import org.onap.cps.utils.JsonObjectMapper
@@ -31,8 +33,11 @@ import org.springframework.boot.test.context.SpringBootTest
class SubscriptionEventResponseConsumerSpec extends MessagingBaseSpec {
IMap<String, Set<String>> mockForwardedSubscriptionEventCache = Mock(IMap<String, Set<String>>)
+ def mockSubscriptionPersistence = Mock(SubscriptionPersistenceImpl)
+ def mockSubscriptionEventResponseMapper = Mock(SubscriptionEventResponseMapper)
- def objectUnderTest = new SubscriptionEventResponseConsumer(mockForwardedSubscriptionEventCache)
+ def objectUnderTest = new SubscriptionEventResponseConsumer(mockForwardedSubscriptionEventCache,
+ mockSubscriptionPersistence, mockSubscriptionEventResponseMapper)
def 'Consume Subscription Event Response where all DMIs have responded'() {
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avc/SubscriptionEventResponseMapperSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avc/SubscriptionEventResponseMapperSpec.groovy
new file mode 100644
index 0000000000..7fb817bc9a
--- /dev/null
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avc/SubscriptionEventResponseMapperSpec.groovy
@@ -0,0 +1,61 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (c) 2023 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.api.impl.events.avc
+
+import com.fasterxml.jackson.databind.ObjectMapper
+import org.mapstruct.factory.Mappers
+import org.onap.cps.ncmp.api.impl.events.avcsubscription.SubscriptionEventResponseMapper
+import org.onap.cps.ncmp.api.impl.subscriptions.SubscriptionStatus
+import org.onap.cps.ncmp.api.models.SubscriptionEventResponse
+import org.onap.cps.ncmp.utils.TestUtils
+import org.onap.cps.utils.JsonObjectMapper
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.boot.test.context.SpringBootTest
+import spock.lang.Specification
+
+
+@SpringBootTest(classes = [JsonObjectMapper, ObjectMapper])
+class SubscriptionEventResponseMapperSpec extends Specification {
+
+ SubscriptionEventResponseMapper objectUnderTest = Mappers.getMapper(SubscriptionEventResponseMapper)
+
+ @Autowired
+ JsonObjectMapper jsonObjectMapper
+
+ def 'Map subscription response event to yang model subscription event'() {
+ given: 'a Subscription Response Event'
+ def jsonData = TestUtils.getResourceFileContent('avcSubscriptionEventResponse.json')
+ def testEventToMap = jsonObjectMapper.convertJsonString(jsonData, SubscriptionEventResponse.class)
+ when: 'the event is mapped to a yang model subscription'
+ def result = objectUnderTest.toYangModelSubscriptionEvent(testEventToMap)
+ then: 'the resulting yang model subscription event contains the correct clientId'
+ assert result.clientId == "SCO-9989752"
+ and: 'subscription name'
+ assert result.subscriptionName == "cm-subscription-001"
+ and: 'predicate targets '
+ assert result.predicates.targetCmHandles.cmHandleId == ["CMHandle1", "CMHandle2"]
+ and: 'the status for these targets is set to expected values'
+ assert result.predicates.targetCmHandles.status == [SubscriptionStatus.ACCEPTED, SubscriptionStatus.REJECTED]
+ and: 'the topic is null'
+ assert result.topic == null
+ }
+
+} \ No newline at end of file
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/subscriptions/SubscriptionPersistenceSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/subscriptions/SubscriptionPersistenceSpec.groovy
index dbc8104767..75760091d3 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/subscriptions/SubscriptionPersistenceSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/subscriptions/SubscriptionPersistenceSpec.groovy
@@ -23,6 +23,7 @@ package org.onap.cps.ncmp.api.impl.subscriptions
import com.fasterxml.jackson.databind.ObjectMapper
import org.onap.cps.api.CpsDataService
import org.onap.cps.ncmp.api.impl.yangmodels.YangModelSubscriptionEvent
+import org.onap.cps.spi.model.DataNodeBuilder
import org.onap.cps.utils.JsonObjectMapper
import spock.lang.Specification
@@ -42,17 +43,19 @@ class SubscriptionPersistenceSpec extends Specification {
def 'save a subscription event' () {
given: 'a yang model subscription event'
- def yangModelSubscriptionEvent = new YangModelSubscriptionEvent();
- yangModelSubscriptionEvent.setClientId('some-client-id')
- yangModelSubscriptionEvent.setSubscriptionName('some-subscription-name')
- yangModelSubscriptionEvent.setTagged(true)
- yangModelSubscriptionEvent.setTopic('some-topic')
def predicates = new YangModelSubscriptionEvent.Predicates(datastore: 'some-datastore',
- targetCmHandles: [new YangModelSubscriptionEvent.TargetCmHandle('cmhandle1'), new YangModelSubscriptionEvent.TargetCmHandle('cmhandle2')])
- yangModelSubscriptionEvent.setPredicates(predicates)
- when: 'the yangModelSubscriptionEvent is saved'
+ targetCmHandles: [new YangModelSubscriptionEvent.TargetCmHandle('cmhandle1'),
+ new YangModelSubscriptionEvent.TargetCmHandle('cmhandle2')])
+ def yangModelSubscriptionEvent = new YangModelSubscriptionEvent(clientId: 'some-client-id',
+ subscriptionName: 'some-subscription-name', tagged: true, topic: 'some-topic', predicates: predicates)
+ and: 'a data node that does not exist in db'
+ def dataNodeNonExist = new DataNodeBuilder().withDataspace('NCMP-Admin')
+ .withAnchor('AVC-Subscriptions').withXpath('/subscription-registry').build()
+ and: 'cps data service return non existing data node'
+ mockCpsDataService.getDataNodes(*_) >> [dataNodeNonExist]
+ when: 'the yangModelSubscriptionEvent is saved into db'
objectUnderTest.saveSubscriptionEvent(yangModelSubscriptionEvent)
- then: 'the cpsDataService is called with the correct data'
+ then: 'the cpsDataService save operation is called with the correct data'
1 * mockCpsDataService.saveListElements(SUBSCRIPTION_DATASPACE_NAME, SUBSCRIPTION_ANCHOR_NAME,
SUBSCRIPTION_REGISTRY_PARENT,
'{"subscription":[{' +
@@ -62,4 +65,31 @@ class SubscriptionPersistenceSpec extends Specification {
NO_TIMESTAMP)
}
+ def 'update a subscription event' () {
+ given: 'a yang model subscription event'
+ def predicates = new YangModelSubscriptionEvent.Predicates(datastore: 'some-datastore',
+ targetCmHandles: [new YangModelSubscriptionEvent.TargetCmHandle('cmhandle1'),
+ new YangModelSubscriptionEvent.TargetCmHandle('cmhandle2')])
+ def yangModelSubscriptionEvent = new YangModelSubscriptionEvent(clientId: 'some-client-id',
+ subscriptionName: 'some-subscription-name', tagged: true, topic: 'some-topic', predicates: predicates)
+ and: 'a data node exist in db'
+ def childDataNode = new DataNodeBuilder().withDataspace('NCMP-Admin')
+ .withAnchor('AVC-Subscriptions').withXpath('/subscription-registry/subscription').build()
+ def dataNodeExist = new DataNodeBuilder().withDataspace('NCMP-Admin')
+ .withAnchor('AVC-Subscriptions').withXpath('/subscription-registry')
+ .withChildDataNodes([childDataNode]).build()
+ and: 'cps data service return existing data node'
+ mockCpsDataService.getDataNodes(*_) >> [dataNodeExist]
+ when: 'the yangModelSubscriptionEvent is saved into db'
+ objectUnderTest.saveSubscriptionEvent(yangModelSubscriptionEvent)
+ then: 'the cpsDataService update operation is called with the correct data'
+ 1 * mockCpsDataService.updateDataNodeAndDescendants(SUBSCRIPTION_DATASPACE_NAME, SUBSCRIPTION_ANCHOR_NAME,
+ SUBSCRIPTION_REGISTRY_PARENT,
+ '{"subscription":[{' +
+ '"topic":"some-topic",' +
+ '"predicates":{"datastore":"some-datastore","targetCmHandles":[{"cmHandleId":"cmhandle1","status":"PENDING"},{"cmHandleId":"cmhandle2","status":"PENDING"}]},' +
+ '"clientID":"some-client-id","subscriptionName":"some-subscription-name","isTagged":true}]}',
+ NO_TIMESTAMP)
+ }
+
}
diff --git a/cps-ncmp-service/src/test/resources/avcSubscriptionEventResponse.json b/cps-ncmp-service/src/test/resources/avcSubscriptionEventResponse.json
new file mode 100644
index 0000000000..b054362c93
--- /dev/null
+++ b/cps-ncmp-service/src/test/resources/avcSubscriptionEventResponse.json
@@ -0,0 +1,9 @@
+{
+ "clientId": "SCO-9989752",
+ "subscriptionName": "cm-subscription-001",
+ "dmiName": "ncmp-dmi-plugin",
+ "cmHandleIdToStatus": {
+ "CMHandle1": "ACCEPTED",
+ "CMHandle2": "REJECTED"
+ }
+} \ No newline at end of file