2 * ============LICENSE_START=======================================================
3 * Copyright (c) 2022-2023 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an 'AS IS' BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.cps.ncmp.api.impl.event.avc
23 import com.fasterxml.jackson.databind.ObjectMapper
24 import org.onap.cps.ncmp.api.kafka.MessagingBaseSpec
25 import org.onap.cps.ncmp.event.model.SubscriptionEvent
26 import org.onap.cps.ncmp.utils.TestUtils
27 import org.onap.cps.spi.exceptions.OperationNotYetSupportedException
28 import org.onap.cps.utils.JsonObjectMapper
29 import org.springframework.beans.factory.annotation.Autowired
30 import org.springframework.boot.test.context.SpringBootTest
32 @SpringBootTest(classes = [ObjectMapper, JsonObjectMapper])
33 class SubscriptionEventConsumerSpec extends MessagingBaseSpec {
35 def subscriptionEventForwarder = Mock(SubscriptionEventForwarder)
36 def objectUnderTest = new SubscriptionEventConsumer(subscriptionEventForwarder)
39 JsonObjectMapper jsonObjectMapper
41 def 'Consume and forward valid CM create message'() {
42 given: 'an event with data category CM'
43 def jsonData = TestUtils.getResourceFileContent('avcSubscriptionCreationEvent.json')
44 def testEventSent = jsonObjectMapper.convertJsonString(jsonData, SubscriptionEvent.class)
45 and: 'notifications are enabled'
46 objectUnderTest.notificationFeatureEnabled = true
47 when: 'the valid event is consumed'
48 objectUnderTest.consumeSubscriptionEvent(testEventSent)
49 then: 'the event is forwarded'
50 1 * subscriptionEventForwarder.forwardCreateSubscriptionEvent(testEventSent)
53 def 'Consume valid CM create message where notifications are disabled'() {
54 given: 'an event with data category CM'
55 def jsonData = TestUtils.getResourceFileContent('avcSubscriptionCreationEvent.json')
56 def testEventSent = jsonObjectMapper.convertJsonString(jsonData, SubscriptionEvent.class)
57 and: 'notifications are disabled'
58 objectUnderTest.notificationFeatureEnabled = false
59 when: 'the valid event is consumed'
60 objectUnderTest.consumeSubscriptionEvent(testEventSent)
61 then: 'the event is forwarded'
62 0 * subscriptionEventForwarder.forwardCreateSubscriptionEvent(testEventSent)
65 def 'Consume valid FM message'() {
67 def jsonData = TestUtils.getResourceFileContent('avcSubscriptionCreationEvent.json')
68 def testEventSent = jsonObjectMapper.convertJsonString(jsonData, SubscriptionEvent.class)
69 and: 'dataCategory is set to FM'
70 testEventSent.getEvent().getDataType().setDataCategory("FM")
71 when: 'the valid event is consumed'
72 objectUnderTest.consumeSubscriptionEvent(testEventSent)
73 then: 'no exception is thrown'
75 and: 'No event is forwarded'
76 0 * subscriptionEventForwarder.forwardCreateSubscriptionEvent(*_)
79 def 'Consume event with wrong datastore causes an exception'() {
81 def jsonData = TestUtils.getResourceFileContent('avcSubscriptionCreationEvent.json')
82 def testEventSent = jsonObjectMapper.convertJsonString(jsonData, SubscriptionEvent.class)
83 and: 'datastore is set to a non passthrough datastore'
84 testEventSent.getEvent().getPredicates().setDatastore("operational")
85 when: 'the valid event is consumed'
86 objectUnderTest.consumeSubscriptionEvent(testEventSent)
87 then: 'an operation not yet supported exception is thrown'
88 thrown(OperationNotYetSupportedException)