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.events.avcsubscription
23 import com.fasterxml.jackson.databind.ObjectMapper
24 import org.mapstruct.factory.Mappers
25 import org.onap.cps.ncmp.api.impl.events.EventsPublisher
26 import org.onap.cps.ncmp.api.impl.subscriptions.SubscriptionPersistence
27 import org.onap.cps.ncmp.api.impl.utils.DataNodeBaseSpec
28 import org.onap.cps.ncmp.events.avc.subscription.v1.SubscriptionEventOutcome
29 import org.onap.cps.ncmp.utils.TestUtils
30 import org.onap.cps.utils.JsonObjectMapper
31 import org.spockframework.spring.SpringBean
32 import org.springframework.beans.factory.annotation.Autowired
33 import org.springframework.boot.test.context.SpringBootTest
35 @SpringBootTest(classes = [ObjectMapper, JsonObjectMapper, SubscriptionOutcomeMapper, SubscriptionEventResponseOutcome])
36 class SubscriptionEventResponseOutcomeSpec extends DataNodeBaseSpec {
39 SubscriptionEventResponseOutcome objectUnderTest
42 SubscriptionPersistence mockSubscriptionPersistence = Mock(SubscriptionPersistence)
44 EventsPublisher<SubscriptionEventOutcome> mockSubscriptionEventOutcomePublisher = Mock(EventsPublisher<SubscriptionEventOutcome>)
46 SubscriptionOutcomeMapper subscriptionOutcomeMapper = Mappers.getMapper(SubscriptionOutcomeMapper)
49 JsonObjectMapper jsonObjectMapper
51 def 'Generate response via fetching data nodes from database.'() {
52 given: 'a db call to get data nodes for subscription event'
53 1 * mockSubscriptionPersistence.getDataNodesForSubscriptionEvent() >> [dataNode4]
54 when: 'a response is generated'
55 def result = objectUnderTest.generateResponse('some-client-id', 'some-subscription-name', isFullOutcomeResponse)
56 then: 'the result will have the same values as same as in dataNode4'
57 result.eventType == expectedEventType
58 result.getEvent().getSubscription().getClientID() == 'some-client-id'
59 result.getEvent().getSubscription().getName() == 'some-subscription-name'
60 result.getEvent().getPredicates().getPendingTargets() == ['CMHandle3']
61 result.getEvent().getPredicates().getRejectedTargets() == ['CMHandle1']
62 result.getEvent().getPredicates().getAcceptedTargets() == ['CMHandle2']
63 where: 'the following values are used'
64 scenario | isFullOutcomeResponse || expectedEventType
65 'is full outcome' | true || SubscriptionEventOutcome.EventType.COMPLETE_OUTCOME
66 'is partial outcome' | false || SubscriptionEventOutcome.EventType.PARTIAL_OUTCOME
69 def 'Form subscription outcome message with a list of cm handle id to status mapping'() {
70 given: 'a list of collection including cm handle id to status'
71 def cmHandleIdToStatus = [['PENDING', 'CMHandle5'], ['PENDING', 'CMHandle4'], ['ACCEPTED', 'CMHandle1'], ['REJECTED', 'CMHandle3']]
72 and: 'an outcome event'
73 def jsonData = TestUtils.getResourceFileContent('avcSubscriptionOutcomeEvent.json')
74 def eventOutcome = jsonObjectMapper.convertJsonString(jsonData, SubscriptionEventOutcome.class)
75 eventOutcome.setEventType(expectedEventType)
76 when: 'a subscription outcome message formed'
77 def result = objectUnderTest.formSubscriptionOutcomeMessage(cmHandleIdToStatus, 'SCO-9989752',
78 'cm-subscription-001', isFullOutcomeResponse)
79 result.getEvent().getPredicates().getPendingTargets().sort()
80 then: 'the result will be equal to event outcome'
81 result == eventOutcome
82 where: 'the following values are used'
83 scenario | isFullOutcomeResponse || expectedEventType
84 'is full outcome' | true || SubscriptionEventOutcome.EventType.COMPLETE_OUTCOME
85 'is partial outcome' | false || SubscriptionEventOutcome.EventType.PARTIAL_OUTCOME