421f13941d4ab60d96fe1676f907bfad9309b76d
[cps.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2024-2025 OpenInfra Foundation Europe. All rights reserved.
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.datajobs.subscription.dmi
22
23 import org.onap.cps.ncmp.impl.inventory.InventoryPersistence
24 import org.onap.cps.ncmp.impl.inventory.models.YangModelCmHandle
25 import org.onap.cps.ncmp.impl.utils.JexParser
26 import spock.lang.Specification
27
28 class DmiInEventMapperSpec extends Specification {
29
30     def mockInventoryPersistence = Mock(InventoryPersistence)
31
32     def objectUnderTest = new DmiInEventMapper(mockInventoryPersistence)
33
34     def setup() {
35         def yangModelCmHandles = [new YangModelCmHandle(id: 'ch-1', additionalProperties: [new YangModelCmHandle.Property('k1', 'v1')], publicProperties: []),
36                                   new YangModelCmHandle(id: 'ch-2', additionalProperties: [new YangModelCmHandle.Property('k2', 'v2')], publicProperties: [])]
37         mockInventoryPersistence.getYangModelCmHandles(['ch-1', 'ch-2'] as Set) >> yangModelCmHandles
38     }
39
40     def 'Check for Cm Notification Subscription DMI In Event mapping'() {
41         given: 'data job subscription details'
42             def cmHandleIds = ['ch-1', 'ch-2'].asList()
43             def dataNodeSelectors = ['/dataNodeSelector1'].asList()
44             def notificationTypes = []
45             def notificationFilter = ''
46             def dataNodeSelectorAsJsonExpression = JexParser.toJsonExpressionsAsString(dataNodeSelectors)
47         when: 'we try to map the values'
48             def result = objectUnderTest.toDmiInEvent(cmHandleIds, dataNodeSelectors, notificationTypes, notificationFilter)
49         then: 'it contains correct cm handles'
50             assert result.data.cmHandles.cmhandleId.containsAll(cmHandleIds)
51         and: 'correct data node selector'
52             assert result.data.productionJobDefinition.targetSelector.dataNodeSelector == dataNodeSelectorAsJsonExpression
53
54     }
55 }