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
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.cmsubscription.mapper
24 import org.onap.cps.ncmp.api.impl.events.cmsubscription.model.DmiCmNotificationSubscriptionPredicate
25 import org.onap.cps.ncmp.api.impl.inventory.InventoryPersistence
26 import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle
27 import spock.lang.Specification
29 import static org.onap.cps.ncmp.api.impl.operations.DatastoreType.PASSTHROUGH_OPERATIONAL
30 import static org.onap.cps.ncmp.api.impl.operations.DatastoreType.PASSTHROUGH_RUNNING
32 class CmNotificationSubscriptionDmiInEventMapperSpec extends Specification {
34 def mockInventoryPersistence = Mock(InventoryPersistence)
36 def objectUnderTest = new CmNotificationSubscriptionDmiInEventMapper(mockInventoryPersistence)
39 def yangModelCmHandles = [new YangModelCmHandle(id: 'ch-1', dmiProperties: [new YangModelCmHandle.Property('k1', 'v1')], publicProperties: []),
40 new YangModelCmHandle(id: 'ch-2', dmiProperties: [new YangModelCmHandle.Property('k2', 'v2')], publicProperties: [])]
41 mockInventoryPersistence.getYangModelCmHandles(['ch-1', 'ch-2'] as Set) >> yangModelCmHandles
44 def 'Check for Cm Notification Subscription DMI In Event mapping'() {
45 given: 'a collection of cm subscription predicates'
46 def dmiCmNotificationSubscriptionPredicates = [new DmiCmNotificationSubscriptionPredicate(['ch-1'].toSet(), PASSTHROUGH_RUNNING, ['/ch-1'].toSet()),
47 new DmiCmNotificationSubscriptionPredicate(['ch-2'].toSet(), PASSTHROUGH_OPERATIONAL, ['/ch-2'].toSet())]
48 when: 'we try to map the values'
49 def result = objectUnderTest.toCmNotificationSubscriptionDmiInEvent(dmiCmNotificationSubscriptionPredicates)
50 then: 'it contains correct cm notification subscription cmhandle object'
51 assert result.data.cmhandles.cmhandleId.containsAll(['ch-1', 'ch-2'])
52 assert result.data.cmhandles.privateProperties.containsAll([['k1': 'v1'], ['k2': 'v2']])
53 and: 'also has the correct dmi cm notification subscription predicates'
54 assert result.data.predicates.targetFilter.containsAll([['ch-1'], ['ch-2']])