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.impl.cmnotificationsubscription.dmi
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.impl.cmnotificationsubscription_1_0_0.ncmp_to_dmi.CmHandle
27 import org.onap.cps.ncmp.impl.cmnotificationsubscription_1_0_0.ncmp_to_dmi.Data
28 import org.onap.cps.ncmp.impl.cmnotificationsubscription_1_0_0.ncmp_to_dmi.DmiInEvent
29 import org.onap.cps.ncmp.utils.events.CloudEventMapper
30 import org.onap.cps.utils.JsonObjectMapper
31 import spock.lang.Specification
33 class DmiInEventProducerSpec extends Specification {
35 def mockEventsPublisher = Mock(EventsPublisher)
36 def jsonObjectMapper = new JsonObjectMapper(new ObjectMapper())
38 def objectUnderTest = new DmiInEventProducer(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 dmiInEvent = new DmiInEvent(data: new Data(cmHandles: [new CmHandle(cmhandleId: 'test-1', privateProperties: [:])]))
46 and: 'also we have target topic for dmiPlugin'
47 objectUnderTest.dmiInEventTopic = 'dmiplugin-test-topic'
48 when: 'the event is published'
49 objectUnderTest.publishDmiInEvent(subscriptionId, dmiPluginName, eventType, dmiInEvent)
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 dmiInEventAsCloudEvent = (args[2] as CloudEvent)
57 assert dmiInEventAsCloudEvent.getExtension('correlationid') == subscriptionId + '#' + dmiPluginName
58 assert dmiInEventAsCloudEvent.type == 'subscriptionCreateRequest'
59 assert dmiInEventAsCloudEvent.source.toString() == 'NCMP'
60 assert CloudEventMapper.toTargetEvent(dmiInEventAsCloudEvent, DmiInEvent) == dmiInEvent