2251a33466f7ac97f0674b34ed236a1a9401f5fb
[cps.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2024 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
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  *  SPDX-License-Identifier: Apache-2.0
18  *  ============LICENSE_END=========================================================
19  */
20
21 package org.onap.cps.ncmp.impl.cmnotificationsubscription.ncmp
22
23
24 import org.onap.cps.ncmp.impl.cmnotificationsubscription.models.DmiCmSubscriptionDetails
25 import org.onap.cps.ncmp.impl.cmnotificationsubscription.models.DmiCmSubscriptionPredicate
26 import spock.lang.Specification
27
28 import static org.onap.cps.ncmp.api.data.models.DatastoreType.PASSTHROUGH_OPERATIONAL
29 import static org.onap.cps.ncmp.api.data.models.DatastoreType.PASSTHROUGH_RUNNING
30 import static org.onap.cps.ncmp.impl.cmnotificationsubscription.models.CmSubscriptionStatus.ACCEPTED
31 import static org.onap.cps.ncmp.impl.cmnotificationsubscription.models.CmSubscriptionStatus.PENDING
32 import static org.onap.cps.ncmp.impl.cmnotificationsubscription.models.CmSubscriptionStatus.REJECTED
33
34 class NcmpOutEventMapperSpec extends Specification {
35
36     static Map<String, DmiCmSubscriptionDetails> dmiSubscriptionsPerDmi
37
38     def objectUnderTest = new NcmpOutEventMapper()
39
40     def setup() {
41         def dmiSubscriptionPredicateA = new DmiCmSubscriptionPredicate(['ch-A'] as Set, PASSTHROUGH_RUNNING, ['/a'] as Set)
42         def dmiSubscriptionPredicateB = new DmiCmSubscriptionPredicate(['ch-B'] as Set, PASSTHROUGH_OPERATIONAL, ['/b'] as Set)
43         def dmiSubscriptionPredicateC = new DmiCmSubscriptionPredicate(['ch-C'] as Set, PASSTHROUGH_OPERATIONAL, ['/c'] as Set)
44         dmiSubscriptionsPerDmi = ['dmi-1': new DmiCmSubscriptionDetails([dmiSubscriptionPredicateA], PENDING),
45                                   'dmi-2': new DmiCmSubscriptionDetails([dmiSubscriptionPredicateB], ACCEPTED),
46                                   'dmi-3': new DmiCmSubscriptionDetails([dmiSubscriptionPredicateC], REJECTED)
47         ]
48     }
49
50     def 'Check for Cm Notification Subscription Outgoing event mapping'() {
51         when: 'we try to map the event to send it to client'
52             def result = objectUnderTest.toNcmpOutEvent('test-subscription', dmiSubscriptionsPerDmi)
53         then: 'event is mapped correctly for the subscription'
54             result.data.subscriptionId == 'test-subscription'
55         and: 'the cm handle ids are part of correct list'
56             result.data.pendingTargets == ['ch-A']
57             result.data.acceptedTargets == ['ch-B']
58             result.data.rejectedTargets == ['ch-C']
59     }
60
61     def 'Check for Cm Notification Rejected Subscription Outgoing event mapping'() {
62         when: 'we try to map the event to send it to client'
63             def result = objectUnderTest.toNcmpOutEventForRejectedRequest('test-subscription', ['ch-1', 'ch-2'])
64         then: 'event is mapped correctly for the subscription id'
65             result.data.subscriptionId == 'test-subscription'
66         and: 'the cm handle ids are part of correct list'
67             result.data.withRejectedTargets(['ch-1', 'ch-2'])
68     }
69 }