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
23 import com.fasterxml.jackson.databind.ObjectMapper
24 import io.cloudevents.CloudEvent
25 import org.onap.cps.events.EventsPublisher
26 import org.onap.cps.ncmp.api.impl.events.mapper.CloudEventMapper
27 import org.onap.cps.ncmp.events.cmnotificationsubscription_merge1_0_0.ncmp_to_dmi.CmNotificationSubscriptionDmiInEvent
28 import org.onap.cps.ncmp.events.cmnotificationsubscription_merge1_0_0.ncmp_to_dmi.Cmhandle
29 import org.onap.cps.ncmp.events.cmnotificationsubscription_merge1_0_0.ncmp_to_dmi.Data
30 import org.onap.cps.utils.JsonObjectMapper
31 import spock.lang.Specification
33 class CmNotificationSubscriptionDmiInEventProducerSpec extends Specification {
35 def mockEventsPublisher = Mock(EventsPublisher)
36 def jsonObjectMapper = new JsonObjectMapper(new ObjectMapper())
38 def objectUnderTest = new CmNotificationSubscriptionDmiInEventProducer(mockEventsPublisher, jsonObjectMapper)
40 def 'Create and Publish Cm Notification Subscription DMI In Event'() {
41 given: 'a cm subscription for a dmi plugin'
42 def subscriptionId = 'test-subscription-id'
43 def dmiPluginName = 'test-dmiplugin'
44 def eventType = 'subscriptionCreateRequest'
45 def cmNotificationSubscriptionDmiInEvent = new CmNotificationSubscriptionDmiInEvent(data: new Data(cmhandles: [new Cmhandle(cmhandleId: 'test-1', privateProperties: [:])]))
46 and: 'also we have target topic for dmiPlugin'
47 objectUnderTest.cmNotificationSubscriptionDmiInEventTopic = 'dmiplugin-test-topic'
48 when: 'the event is published'
49 objectUnderTest.publishCmNotificationSubscriptionDmiInEvent(subscriptionId, dmiPluginName, eventType, cmNotificationSubscriptionDmiInEvent)
50 then: 'the event contains the required attributes'
51 1 * mockEventsPublisher.publishCloudEvent(_, _, _) >> {
54 assert args[0] == 'dmiplugin-test-topic'
55 assert args[1] == subscriptionId
56 def cmNotificationSubscriptionDmiInEventAsCloudEvent = (args[2] as CloudEvent)
57 assert cmNotificationSubscriptionDmiInEventAsCloudEvent.getExtension('correlationid') == subscriptionId + '#' + dmiPluginName
58 assert cmNotificationSubscriptionDmiInEventAsCloudEvent.type == 'subscriptionCreateRequest'
59 assert cmNotificationSubscriptionDmiInEventAsCloudEvent.source.toString() == 'NCMP'
60 assert CloudEventMapper.toTargetEvent(cmNotificationSubscriptionDmiInEventAsCloudEvent, CmNotificationSubscriptionDmiInEvent) == cmNotificationSubscriptionDmiInEvent