1 package org.onap.cps.ncmp.api.impl.events.cmsubscription
 
   3 import com.fasterxml.jackson.databind.ObjectMapper
 
   4 import io.cloudevents.CloudEvent
 
   5 import org.onap.cps.events.EventsPublisher
 
   6 import org.onap.cps.ncmp.api.impl.events.mapper.CloudEventMapper
 
   7 import org.onap.cps.ncmp.events.cmsubscription_merge1_0_0.ncmp_to_client.CmNotificationSubscriptionNcmpOutEvent
 
   8 import org.onap.cps.ncmp.events.cmsubscription_merge1_0_0.ncmp_to_client.Data
 
   9 import org.onap.cps.utils.JsonObjectMapper
 
  10 import spock.lang.Specification
 
  12 class CmNotificationSubscriptionNcmpOutEventProducerSpec extends Specification {
 
  14     def mockEventsPublisher = Mock(EventsPublisher)
 
  15     def jsonObjectMapper = new JsonObjectMapper(new ObjectMapper())
 
  17     def objectUnderTest = new CmNotificationSubscriptionNcmpOutEventProducer(mockEventsPublisher, jsonObjectMapper)
 
  19     def 'Create and Publish Cm Notification Subscription DMI In Event'() {
 
  20         given: 'a cm subscription response for the client'
 
  21             def subscriptionId = 'test-subscription-id'
 
  22             def eventType = 'subscriptionCreateResponse'
 
  23             def cmNotificationSubscriptionNcmpOutEvent = new CmNotificationSubscriptionNcmpOutEvent(data: new Data(subscriptionId: 'sub-1', acceptedTargets: ['ch-1', 'ch-2']))
 
  24         and: 'also we have target topic for publishing to client'
 
  25             objectUnderTest.cmNotificationSubscriptionNcmpOutEventTopic = 'client-test-topic'
 
  26         when: 'the event is published'
 
  27             objectUnderTest.publishCmNotificationSubscriptionNcmpOutEvent(subscriptionId, eventType, cmNotificationSubscriptionNcmpOutEvent)
 
  28         then: 'the event contains the required attributes'
 
  29             1 * mockEventsPublisher.publishCloudEvent(_, _, _) >> {
 
  32                         assert args[0] == 'client-test-topic'
 
  33                         assert args[1] == subscriptionId
 
  34                         def cmNotificationSubscriptionNcmpOutEventAsCloudEvent = (args[2] as CloudEvent)
 
  35                         assert cmNotificationSubscriptionNcmpOutEventAsCloudEvent.getExtension('correlationid') == subscriptionId
 
  36                         assert cmNotificationSubscriptionNcmpOutEventAsCloudEvent.type == 'subscriptionCreateResponse'
 
  37                         assert cmNotificationSubscriptionNcmpOutEventAsCloudEvent.source.toString() == 'NCMP'
 
  38                         assert CloudEventMapper.toTargetEvent(cmNotificationSubscriptionNcmpOutEventAsCloudEvent, CmNotificationSubscriptionNcmpOutEvent) == cmNotificationSubscriptionNcmpOutEvent