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.ncmp
23 import ch.qos.logback.classic.Level
24 import ch.qos.logback.classic.Logger
25 import ch.qos.logback.classic.spi.ILoggingEvent
26 import ch.qos.logback.core.read.ListAppender
27 import com.fasterxml.jackson.databind.ObjectMapper
28 import org.onap.cps.ncmp.impl.datajobs.subscription.client_to_ncmp.DataJobSubscriptionOperationInEvent
29 import org.onap.cps.ncmp.impl.utils.JexParser
30 import org.onap.cps.ncmp.utils.TestUtils
31 import org.slf4j.LoggerFactory
32 import spock.lang.Specification
34 class NcmpInEventConsumerSpec extends Specification {
36 def objectMapper = new ObjectMapper()
38 def mockCmSubscriptionHandler = Mock(CmSubscriptionHandlerImpl)
39 def objectUnderTest = new NcmpInEventConsumer(mockCmSubscriptionHandler)
41 def 'Consuming CREATE cm data job subscription request.'() {
42 given: 'a JSON file for create event'
43 def jsonData = TestUtils.getResourceFileContent(
44 'datajobs/subscription/cmNotificationSubscriptionNcmpInEvent.json')
45 def myEventType = "dataJobCreated"
46 jsonData = jsonData.replace('#myEventType', myEventType)
48 def event = objectMapper.readValue(jsonData, DataJobSubscriptionOperationInEvent)
49 and: 'the list of data node selectors'
50 def dataNodeSelectorList = getDataNodeSelectorsAsXpaths(event)
51 and: 'the other data job event attributes'
52 def dataSelector = getDataSelector(event)
53 when: 'the event is consumed'
54 objectUnderTest.consumeSubscriptionEvent(event)
55 then: 'subscription create request is called'
56 1 * mockCmSubscriptionHandler.createSubscription(dataSelector, "myDataJobId", dataNodeSelectorList)
59 def 'Consuming DELETE cm data job subscription request.'() {
60 given: 'a JSON file for delete event'
61 def jsonData = TestUtils.getResourceFileContent(
62 'datajobs/subscription/cmNotificationSubscriptionNcmpInEvent.json')
63 def myEventType = "dataJobDeleted"
64 jsonData = jsonData.replace('#myEventType', myEventType)
66 def event = objectMapper.readValue(jsonData, DataJobSubscriptionOperationInEvent)
67 when: 'the event is consumed'
68 objectUnderTest.consumeSubscriptionEvent(event)
69 then: 'subscription delete request is called'
70 1 * mockCmSubscriptionHandler.deleteSubscription("myDataJobId")
73 def getDataNodeSelectorsAsXpaths(event) {
74 return JexParser.toXpaths(event.event.dataJob.productionJobDefinition.targetSelector.dataNodeSelector)
77 def getDataSelector(event) {
78 return event.event.dataJob.productionJobDefinition.dataSelector