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
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.impl.datajobs.subscription.dmi
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
28 class DmiInEventMapperSpec extends Specification {
30 def mockInventoryPersistence = Mock(InventoryPersistence)
32 def objectUnderTest = new DmiInEventMapper(mockInventoryPersistence)
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
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