2 * ============LICENSE_START=======================================================
3 * Copyright (c) 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 com.hazelcast.map.IMap
25 import org.onap.cps.ncmp.api.impl.events.avcsubscription.SubscriptionEventResponseMapper
26 import org.onap.cps.ncmp.api.impl.subscriptions.SubscriptionPersistenceImpl
27 import org.onap.cps.ncmp.api.kafka.MessagingBaseSpec
28 import org.onap.cps.ncmp.api.models.SubscriptionEventResponse
29 import org.onap.cps.utils.JsonObjectMapper
30 import org.springframework.boot.test.context.SpringBootTest
32 @SpringBootTest(classes = [ObjectMapper, JsonObjectMapper])
33 class SubscriptionEventResponseConsumerSpec extends MessagingBaseSpec {
35 IMap<String, Set<String>> mockForwardedSubscriptionEventCache = Mock(IMap<String, Set<String>>)
36 def mockSubscriptionPersistence = Mock(SubscriptionPersistenceImpl)
37 def mockSubscriptionEventResponseMapper = Mock(SubscriptionEventResponseMapper)
39 def objectUnderTest = new SubscriptionEventResponseConsumer(mockForwardedSubscriptionEventCache,
40 mockSubscriptionPersistence, mockSubscriptionEventResponseMapper)
43 def 'Consume Subscription Event Response where all DMIs have responded'() {
44 given: 'a subscription event response with a clientId, subscriptionName and dmiName'
45 def testEventReceived = new SubscriptionEventResponse()
46 testEventReceived.clientId = 'some-client-id'
47 testEventReceived.subscriptionName = 'some-subscription-name'
48 testEventReceived.dmiName = 'some-dmi-name'
49 and: 'notifications are enabled'
50 objectUnderTest.notificationFeatureEnabled = true
51 and: 'subscription model loader is enabled'
52 objectUnderTest.subscriptionModelLoaderEnabled = true
53 when: 'the valid event is consumed'
54 objectUnderTest.consumeSubscriptionEventResponse(testEventReceived)
55 then: 'the forwarded subscription event cache returns only the received dmiName existing for the subscription create event'
56 1 * mockForwardedSubscriptionEventCache.containsKey('some-client-idsome-subscription-name') >> true
57 1 * mockForwardedSubscriptionEventCache.get('some-client-idsome-subscription-name') >> (['some-dmi-name'] as Set)
58 and: 'the forwarded subscription event cache returns an empty Map when the dmiName has been removed'
59 1 * mockForwardedSubscriptionEventCache.get('some-client-idsome-subscription-name') >> ([] as Set)
60 and: 'the subscription event is removed from the map'
61 1 * mockForwardedSubscriptionEventCache.remove('some-client-idsome-subscription-name')
64 def 'Consume Subscription Event Response where another DMI has not yet responded'() {
65 given: 'a subscription event response with a clientId, subscriptionName and dmiName'
66 def testEventReceived = new SubscriptionEventResponse()
67 testEventReceived.clientId = 'some-client-id'
68 testEventReceived.subscriptionName = 'some-subscription-name'
69 testEventReceived.dmiName = 'some-dmi-name'
70 and: 'notifications are enabled'
71 objectUnderTest.notificationFeatureEnabled = true
72 and: 'subscription model loader is enabled'
73 objectUnderTest.subscriptionModelLoaderEnabled = true
74 when: 'the valid event is consumed'
75 objectUnderTest.consumeSubscriptionEventResponse(testEventReceived)
76 then: 'the forwarded subscription event cache returns only the received dmiName existing for the subscription create event'
77 1 * mockForwardedSubscriptionEventCache.containsKey('some-client-idsome-subscription-name') >> true
78 1 * mockForwardedSubscriptionEventCache.get('some-client-idsome-subscription-name') >> (['some-dmi-name', 'non-responded-dmi'] as Set)
79 and: 'the forwarded subscription event cache returns an empty Map when the dmiName has been removed'
80 1 * mockForwardedSubscriptionEventCache.get('some-client-idsome-subscription-name') >> (['non-responded-dmi'] as Set)
81 and: 'the subscription event is not removed from the map'
82 0 * mockForwardedSubscriptionEventCache.remove(_)